From steve+comp.lang.python at pearwood.info Thu Mar 1 00:01:30 2012 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 01 Mar 2012 05:01:30 GMT Subject: lang comparison: in-place algorithm for reversing a list in Perl, Python, Lisp References: <85fa5760-68c8-41a2-9116-2489165f7ca1@j5g2000yqm.googlegroups.com> Message-ID: <4f4f02a9$0$1539$c3e8da3$76491128@news.astraweb.com> On Wed, 29 Feb 2012 20:07:49 -0800, Xah Lee wrote: > Here's in-place algorithm for reversing a list: > > # python > # in-place algorithm for reversing a list > > list_a = ["a", "b", "c", "d", "e", "f", "g"] > list_length = len(list_a) > for i in range(list_length/2): > x = list_a[i] > list_a[i] = list_a[ list_length -1 - i] > list_a[ list_length -1 - i] = x > > print list_a This is a good example of code written by somebody not very familiar with Python idioms. You don't need a temporary variable to swap two values in Python. A better way to reverse a list using more Pythonic idioms is: for i in range(len(list_a)//2): list_a[i], list_a[-i-1] = list_a[-i-1], list_a[i] But the best way (even more idiomatic and much, much faster) is this: list_a.reverse() -- Steven From drsalists at gmail.com Thu Mar 1 00:05:06 2012 From: drsalists at gmail.com (Dan Stromberg) Date: Wed, 29 Feb 2012 21:05:06 -0800 Subject: lang comparison: in-place algorithm for reversing a list in Perl, Python, Lisp In-Reply-To: <85fa5760-68c8-41a2-9116-2489165f7ca1@j5g2000yqm.googlegroups.com> References: <85fa5760-68c8-41a2-9116-2489165f7ca1@j5g2000yqm.googlegroups.com> Message-ID: On Wed, Feb 29, 2012 at 8:07 PM, Xah Lee wrote: > fun example. > > in-place algorithm for reversing a list in Perl, Python, Lisp > http://xahlee.org/comp/in-place_algorithm.html > > plain text follows > ---------------------------------------- > > What's ?In-place Algorithm?? > > Xah Lee, 2012-02-29 > > This page tells you what's ?In-place algorithm?, using {python, perl, > emacs lisp} code to illustrate. > > Aren't in-place reversals rather non-functional? > Python > The usual way is list_a.reverse(). This is in place. If you want to be a little weird, you could do this, but it's not in place: list_a = list_a[::-1] If you want to pretend you can't do this the easy ways above, you could do this, which is in place: length = len(list_a) for ind in xrange(length // 2): other=-ind-1 list_a[ind], list_a[other] = list_a[other], list_a[ind] HTH -------------- next part -------------- An HTML attachment was scrubbed... URL: From chiron613 at gmail.com Thu Mar 1 00:07:47 2012 From: chiron613 at gmail.com (Chiron) Date: Thu, 01 Mar 2012 05:07:47 GMT Subject: New Science Discovery: Perl Idiots Remain Idiots After A Decade!New Science Discovery: Perl Idiots Remain Idiots Af References: <0078bbfb-5dfc-48fc-af1a-69de3cf15c3e@b1g2000yqb.googlegroups.com> <87aa41k6x5.fsf@sapphire.mobileactivedefense.com> <4f4ef6c8$27$fuzhry+tra$mr2ice@news.patriot.net> Message-ID: On Wed, 29 Feb 2012 23:10:48 -0500, Shmuel (Seymour J.) Metz wrote: > ROTF,LMAO! You obviously don't have a clue as to what Mathematics means. > Free hint: it doesn't mean Arithmetic. You're as bigoted as Xah Lee, Hmm... maybe, instead of just ridiculing him, you could explain where he is mistaken. Of course, doing that is a *LOT* harder than just calling him a bigot. BTW, I happen to agree with you insofar as this poster not understanding the nature of mathematics. His comment reminds me of the article, "Transgressing the Boundaries: Towards a Transformative Hermeneutics of Quantum Gravity" (http://www.physics.nyu.edu/sokal/transgress_v2/ transgress_v2_singlefile.html). Also known as the "Sokal Hoax." -- Boling's postulate: If you're feeling good, don't worry. You'll get over it. From tjreedy at udel.edu Thu Mar 1 00:24:06 2012 From: tjreedy at udel.edu (Terry Reedy) Date: Thu, 01 Mar 2012 00:24:06 -0500 Subject: Is it necessary to call Tk() when writing a GUI app with Tkinter? In-Reply-To: References: <27603449.17.1330492001624.JavaMail.geo-discussion-forums@vbbfv2> <6e1c521e-14be-4ec0-9ff0-7f23fd9cd3dc@f14g2000yqe.googlegroups.com> Message-ID: On 2/29/2012 10:22 PM, Rick Johnson wrote: I do not know what book the OP is referring to, but the current doc example is http://docs.python.org/py3k/library/tkinter.html#a-simple-hello-world-program My current replacement (see below) can be downloaded from the tracker: http://bugs.python.org/issue14163 > If you want to keep things simple, i would: > > 1. Create the root window explicitly! It already does that. > 2. Bind the command of the button to root.destroy > (command=root.destroy) That works great. My current replacement example is uploaded to the issue http://bugs.python.org/issue14163 > PS: I would highly suggest against using the "from Tkinter import *". > Instead, use "import Tkinter as tk" and prefix all module contents > with "tk.". I have changed the example to do that. I also showed the alternate to initialize a widget. Here is the current version, tested on Windows 3.2.2. import tkinter as tk class Application(tk.Frame): def __init__(self, master=None): tk.Frame.__init__(self, master) self.pack() self.createWidgets() def createWidgets(self): self.hi_there = tk.Button(self) self.hi_there["text"] = "Hello_World\n(click_me)", self.hi_there["command"] = self.say_hi self.hi_there.pack({"side": "top"}) self.QUIT = tk.Button(self, text = "QUIT", fg = "red", command = root.destroy) self.QUIT.pack({"side": "bottom"}) def say_hi(self): print("hi there, everyone!") root = tk.Tk() app = Application(master=root) app.mainloop() There is a minor problem left. The hi_there Button text has underscores because if I use spaces instead, tk surrounds the text with {bra ces}. This seems bizarre. Is there any way to have Button text with spaces and no braces? -- Terry Jan Reedy From tjreedy at udel.edu Thu Mar 1 00:35:00 2012 From: tjreedy at udel.edu (Terry Reedy) Date: Thu, 01 Mar 2012 00:35:00 -0500 Subject: Help needed: dynamically pull data from different levels of a dict In-Reply-To: References: Message-ID: On 2/29/2012 11:04 PM, Peter Rubenstein wrote: > I'd appreciate a bit of help on this problem. I have some data that I've converted to a dict and I want to pull out individual pieces of it. > > Simplified version-- > a={'1':'a', '2':'b', '3':{4:'d'}, '5':{'6': {'7': [ {'8':'e'}, {'9':'f'} ] } } } > > I'd like to be able to code something like: > > data_needed = ['1', '2', '3:4', '5:6:7-8']for val in data_needed: answer=extract_from(a,val) print answer > > And get:abcde > > Problem is I can't figure out what extract_from would look like, such that it would proceed dynamically down to the right level. I'm open to the possibility that I'm not approaching this the right way. > If it helps, one member of my actual dict quoted below. So in real life, something likedata_needed=['name','active-defects', 'admin-status:format', 'description', 'traffic-statistics:input-bps']etc. > > Thanks in advance,Peter > > { 'ge-0/0/0': {'active-alarms': {'interface-alarms': {'alarm-not-present': ''}}, 'active-defects': {'interface-alarms': {'alarm-not-present': ''}}, 'admin-status': {'_text': 'up', 'format': 'Enabled'}, 'current-physical-address': '00:1f:12:c0:e8:00', 'description': 'INFRA:CROSS:ASH-64CB-1B:GE-0/0/0:', 'hardware-physical-address': '00:1f:12:c0:e8:00', 'if-config-flags': {'iff-snmp-traps': '', 'internal-flags': '0x4000'}, 'if-device-flags': {'ifdf-present': '', 'ifdf-running': ''}, 'if-flow-control': 'enabled', 'if-media-flags': {'ifmf-none': ''}, 'interface-flapped': {'_text': '2010-05-23 18:20:36 UTC (92w3d 02:27 ago)', 'seconds': '55909644'}, 'l2pt-error': 'none', 'link-level-type': 'Ethernet', 'local-index': '171', 'logical-interface': {'address-family': [{'address-family-flags': {'ifff-no-redirects': '', 'internal-flags': '0x0'}, 'address-family-name': 'inet', 'interface-address': {'ifa-destination': '207.46.43.2/31', 'ifa-flags': {'ifa f-current-preferred': '', 'ifaf-current-primary': ''}, 'ifa-local': '207.46.43.2'}, 'mtu': '9178'}, {'address-family-flags': {'ifff-mtu-user-conf': '', 'internal-flags': '0x10000000'}, 'address-family-name': 'mpls', 'mtu': '9174'}, {'address-family-flags': {'ifff-none': ''}, 'address-family-name': 'multiservice', 'mtu': 'Unlimited'}], 'description': 'INFRA:CROSS:ASH-64CB-1B:GE-0/0/0.0:', 'encapsulation': 'ENET2', 'if-config-flags': {'iff-snmp-traps': ''}, 'local-index': '67', 'name': 'ge-0/0/0.0', 'snmp-index': '117', 'traffic-statistics': {'input-packets': '46367422526659', 'output-packets': '35670513402384', 'style': 'brief'}}, 'loopback': 'disabled', 'mtu': '9192', 'name': 'ge-0/0/0', 'oper-status': 'up', 'physical-interface-cos-information': {'physical-interface-cos-hw-max-queues': '8', 'physical-interface-cos-use-max-queues': '8'}, 'snmp-index': '116', 'source-filtering': 'disabled', 'speed': '10Gbps', 't raffic-statistics': {'input-bps': '4104358720', 'input-pps': '1059450', 'output-bps': '2323588888', 'output-pps': '537816', 'style': 'brief'}},} -- Terry Jan Reedy From xahlee at gmail.com Thu Mar 1 00:39:37 2012 From: xahlee at gmail.com (Xah Lee) Date: Wed, 29 Feb 2012 21:39:37 -0800 (PST) Subject: lang comparison: in-place algorithm for reversing a list in Perl, Python, Lisp References: <85fa5760-68c8-41a2-9116-2489165f7ca1@j5g2000yqm.googlegroups.com> <4f4f02a9$0$1539$c3e8da3$76491128@news.astraweb.com> Message-ID: <865b899b-8ec7-4650-88d7-153d4e26178d@i6g2000yqe.googlegroups.com> On Feb 29, 9:01?pm, Steven D'Aprano wrote: > You don't need a temporary variable to swap two values in > Python. A better way to reverse a list using more Pythonic idioms is: > > for i in range(len(list_a)//2): > ? ? list_a[i], list_a[-i-1] = list_a[-i-1], list_a[i] forgive me sir, but i haven't been at python for a while. :) i was, actually, refreshing myself of what little polyglot skills i have. Xah From johnjsal at gmail.com Thu Mar 1 00:40:14 2012 From: johnjsal at gmail.com (John Salerno) Date: Wed, 29 Feb 2012 21:40:14 -0800 (PST) Subject: Is it necessary to call Tk() when writing a GUI app with Tkinter? In-Reply-To: References: <27603449.17.1330492001624.JavaMail.geo-discussion-forums@vbbfv2> <6e1c521e-14be-4ec0-9ff0-7f23fd9cd3dc@f14g2000yqe.googlegroups.com> Message-ID: <22943242.772.1330580414345.JavaMail.geo-discussion-forums@ynil17> > Yes, but i think the REAL problem is faulty code logic. Remove the > last line "root.destroy()" and the problem is solved. Obviously the > author does not have an in-depth knowledge of Tkinter. The faulty code is not my own, which is part of the reason I asked the question. The book I'm reading (The Quick Python Book) does not use it, but I saw in the Python docs that it is there, under "tkinter" in the Global Module Docs, "24.1.2.2. A Simple Hello World Program": from tkinter import * class Application(Frame): def say_hi(self): print("hi there, everyone!") def createWidgets(self): self.QUIT = Button(self) self.QUIT["text"] = "QUIT" self.QUIT["fg"] = "red" self.QUIT["command"] = self.quit self.QUIT.pack({"side": "left"}) self.hi_there = Button(self) self.hi_there["text"] = "Hello", self.hi_there["command"] = self.say_hi self.hi_there.pack({"side": "left"}) def __init__(self, master=None): Frame.__init__(self, master) self.pack() self.createWidgets() root = Tk() app = Application(master=root) app.mainloop() root.destroy() From tjreedy at udel.edu Thu Mar 1 00:40:45 2012 From: tjreedy at udel.edu (Terry Reedy) Date: Thu, 01 Mar 2012 00:40:45 -0500 Subject: Is it necessary to call Tk() when writing a GUI app with Tkinter? In-Reply-To: <17153317.324.1330576905540.JavaMail.geo-discussion-forums@yncd8> References: <27603449.17.1330492001624.JavaMail.geo-discussion-forums@vbbfv2> <6e1c521e-14be-4ec0-9ff0-7f23fd9cd3dc@f14g2000yqe.googlegroups.com> <17153317.324.1330576905540.JavaMail.geo-discussion-forums@yncd8> Message-ID: On 2/29/2012 11:41 PM, John Salerno wrote: > window? If you only want the Windows "X" button to close the window, > then is it okay to leave out any call to destroy()? Yes. You must leave it out. > the latter, then where in the code do you put the call to destroy so > it won't conflict with the user closing the window with the X > button? See my other post of a few minutes ago for an example that now works. -- Terry Jan Reedy From johnjsal at gmail.com Thu Mar 1 00:45:28 2012 From: johnjsal at gmail.com (John Salerno) Date: Wed, 29 Feb 2012 21:45:28 -0800 (PST) Subject: Is it necessary to call Tk() when writing a GUI app with Tkinter? In-Reply-To: References: <27603449.17.1330492001624.JavaMail.geo-discussion-forums@vbbfv2> <6e1c521e-14be-4ec0-9ff0-7f23fd9cd3dc@f14g2000yqe.googlegroups.com> <17153317.324.1330576905540.JavaMail.geo-discussion-forums@yncd8> Message-ID: <18841978.1037.1330580728432.JavaMail.geo-discussion-forums@vbgu10> On Wednesday, February 29, 2012 11:40:45 PM UTC-6, Terry Reedy wrote: > On 2/29/2012 11:41 PM, John Salerno wrote: > > > window? If you only want the Windows "X" button to close the window, > > then is it okay to leave out any call to destroy()? > > Yes. You must leave it out. > > > the latter, then where in the code do you put the call to destroy so > > it won't conflict with the user closing the window with the X > > button? > > See my other post of a few minutes ago for an example that now works. > > -- > Terry Jan Reedy When you suggested I create the root frame explicitly, you mean create a Tk object explicitly, as in your example, and then pass that as an argument to the Frame instance? What exactly is the purpose of doing that? Does Tk do some extra work that a simple call to Frame won't do? From johnjsal at gmail.com Thu Mar 1 00:45:28 2012 From: johnjsal at gmail.com (John Salerno) Date: Wed, 29 Feb 2012 21:45:28 -0800 (PST) Subject: Is it necessary to call Tk() when writing a GUI app with Tkinter? In-Reply-To: References: <27603449.17.1330492001624.JavaMail.geo-discussion-forums@vbbfv2> <6e1c521e-14be-4ec0-9ff0-7f23fd9cd3dc@f14g2000yqe.googlegroups.com> <17153317.324.1330576905540.JavaMail.geo-discussion-forums@yncd8> Message-ID: <18841978.1037.1330580728432.JavaMail.geo-discussion-forums@vbgu10> On Wednesday, February 29, 2012 11:40:45 PM UTC-6, Terry Reedy wrote: > On 2/29/2012 11:41 PM, John Salerno wrote: > > > window? If you only want the Windows "X" button to close the window, > > then is it okay to leave out any call to destroy()? > > Yes. You must leave it out. > > > the latter, then where in the code do you put the call to destroy so > > it won't conflict with the user closing the window with the X > > button? > > See my other post of a few minutes ago for an example that now works. > > -- > Terry Jan Reedy When you suggested I create the root frame explicitly, you mean create a Tk object explicitly, as in your example, and then pass that as an argument to the Frame instance? What exactly is the purpose of doing that? Does Tk do some extra work that a simple call to Frame won't do? From driscoll at cs.wisc.edu Thu Mar 1 01:07:21 2012 From: driscoll at cs.wisc.edu (Evan Driscoll) Date: Thu, 01 Mar 2012 00:07:21 -0600 Subject: lang comparison: in-place algorithm for reversing a list in Perl, Python, Lisp In-Reply-To: References: <85fa5760-68c8-41a2-9116-2489165f7ca1@j5g2000yqm.googlegroups.com> Message-ID: <4F4F1219.2070502@cs.wisc.edu> On 2/29/2012 23:05, Dan Stromberg wrote: > > On Wed, Feb 29, 2012 at 8:07 PM, Xah Lee > wrote: > > This page tells you what's ?In-place algorithm?, using {python, perl, > emacs lisp} code to illustrate. > > Aren't in-place reversals rather non-functional? There is one place where they're reasonably idiomatic in Lispy languages, at least by my understanding. That occurs when you are writing a function that returns a list and there is a natural recursive way to build up the answer -- but backwards. The idiom then is to build up a temporary list up backwards, then call an in-place reversal function. (NREVERSE in Common Lisp. I thought there was a reverse! in Scheme, but apparently not.) This doesn't break the external view of a pure function because the list that's being reversed is a fresh, temporary list, which is why this idiom would even fit in pretty well in Scheme. Evan -------------- next part -------------- A non-text attachment was scrubbed... Name: signature.asc Type: application/pgp-signature Size: 552 bytes Desc: OpenPGP digital signature URL: From johnjsal at gmail.com Thu Mar 1 01:14:41 2012 From: johnjsal at gmail.com (John Salerno) Date: Wed, 29 Feb 2012 22:14:41 -0800 (PST) Subject: Is it necessary to call Tk() when writing a GUI app with Tkinter? In-Reply-To: <18841978.1037.1330580728432.JavaMail.geo-discussion-forums@vbgu10> References: <27603449.17.1330492001624.JavaMail.geo-discussion-forums@vbbfv2> <6e1c521e-14be-4ec0-9ff0-7f23fd9cd3dc@f14g2000yqe.googlegroups.com> <17153317.324.1330576905540.JavaMail.geo-discussion-forums@yncd8> <18841978.1037.1330580728432.JavaMail.geo-discussion-forums@vbgu10> Message-ID: <28139175.898.1330582481406.JavaMail.geo-discussion-forums@ynbo36> > What exactly is the purpose of doing that? Does Tk do some extra work that a simple call to Frame won't do? More specifically, what is the benefit of doing: root = tk.Tk() app = Application(master=root) app.mainloop() as opposed to: app = Application() app.mainloop() Also, in the first example, what is the difference between calling app.mainloop() and root.mainloop()? They both seemed to work when I ran them. From johnjsal at gmail.com Thu Mar 1 01:14:41 2012 From: johnjsal at gmail.com (John Salerno) Date: Wed, 29 Feb 2012 22:14:41 -0800 (PST) Subject: Is it necessary to call Tk() when writing a GUI app with Tkinter? In-Reply-To: <18841978.1037.1330580728432.JavaMail.geo-discussion-forums@vbgu10> References: <27603449.17.1330492001624.JavaMail.geo-discussion-forums@vbbfv2> <6e1c521e-14be-4ec0-9ff0-7f23fd9cd3dc@f14g2000yqe.googlegroups.com> <17153317.324.1330576905540.JavaMail.geo-discussion-forums@yncd8> <18841978.1037.1330580728432.JavaMail.geo-discussion-forums@vbgu10> Message-ID: <28139175.898.1330582481406.JavaMail.geo-discussion-forums@ynbo36> > What exactly is the purpose of doing that? Does Tk do some extra work that a simple call to Frame won't do? More specifically, what is the benefit of doing: root = tk.Tk() app = Application(master=root) app.mainloop() as opposed to: app = Application() app.mainloop() Also, in the first example, what is the difference between calling app.mainloop() and root.mainloop()? They both seemed to work when I ran them. From timr at probo.com Thu Mar 1 01:24:14 2012 From: timr at probo.com (Tim Roberts) Date: Wed, 29 Feb 2012 22:24:14 -0800 Subject: pyusb and microchip mcp2210 interface References: Message-ID: jobattle wrote: > >Has anybody out there had any experience in using the PYUSB library with >the new Microchip MCP2210 USB to SPI chip? It appears to the system as a HID device. You don't need to use PyUSB -- it already has a driver. Check libhid -- it has a Python binding. -- Tim Roberts, timr at probo.com Providenza & Boekelheide, Inc. From w_a_x_man at yahoo.com Thu Mar 1 01:37:45 2012 From: w_a_x_man at yahoo.com (WJ) Date: 1 Mar 2012 06:37:45 GMT Subject: lang comparison: in-place algorithm for reversing a list in Perl, Python, Lisp References: <85fa5760-68c8-41a2-9116-2489165f7ca1@j5g2000yqm.googlegroups.com> Message-ID: Xah Lee wrote: > fun example. > > in-place algorithm for reversing a list in Perl, Python, Lisp > http://xahlee.org/comp/in-place_algorithm.html > > plain text follows > ---------------------------------------- > > What's ?In-place Algorithm?? > > Xah Lee, 2012-02-29 > > This page tells you what's ?In-place algorithm?, using {python, perl, > emacs lisp} code to illustrate. > > Here's Wikipedia In-place algorithm excerpt: > > In computer science, an in-place algorithm (or in Latin in situ) is an > algorithm which transforms input using a data structure with a small, > constant amount of extra storage space. The input is usually > overwritten by the output as the algorithm executes. An algorithm > which is not in-place is sometimes called not-in-place or out-of- > place. > > Python > > Here's a python code for reversing a list. Done by creating a new > list, NOT using in-place: > > # python > # reverse a list > > list_a = ["a", "b", "c", "d", "e", "f", "g"] > > list_length = len(list_a) > list_b = [0] * list_length > > for i in range(list_length): > list_b[i] = list_a[list_length -1 - i] > > print list_b > Here's in-place algorithm for reversing a list: > > # python > # in-place algorithm for reversing a list > > list_a = ["a", "b", "c", "d", "e", "f", "g"] > > list_length = len(list_a) > > for i in range(list_length/2): > x = list_a[i] > list_a[i] = list_a[ list_length -1 - i] > list_a[ list_length -1 - i] = x > > print list_a > Perl > > Here's a perl code for reversing a list. Done by creating a new list, > NOT using in-place: > > # perl > > use strict; > use Data::Dumper; > > my @listA = qw(a b c d e f g); > > my $listLength = scalar @listA; > my @listB = (); > > for ( my $i = 0; $i < $listLength; $i++ ) { > $listB[$i] = $listA[ $listLength - 1 - $i]; > } > > print Dumper(\@listB); > > # perl > # in-place algorithm for reversing a list. > > use strict; > use Data::Dumper; > use POSIX; # for ?floor? > > my @listA = qw(a b c d e f g); > > my $listLength = scalar @listA; > > for ( my $i = 0; $i < floor($listLength/2); $i++ ) { > my $x = $listA[$i]; > $listA[$i] = $listA[ $listLength - 1 - $i]; > $listA[ $listLength - 1 - $i] = $x; > } > > print Dumper(\@listA); > __END__ > > emacs lisp > > ;; emacs lisp > ;; reverse a array > > (setq arrayA ["a" "b" "c" "d" "e" "f" "g"]) > > (setq arrayLength (length arrayA)) > > (setq arrayB (make-vector arrayLength 0)) > > (dotimes (i arrayLength ) > (aset arrayB i (aref arrayA (- (1- arrayLength) i)) ) > ) > > (print (format "%S" arrayB)) > ;; emacs lisp > ;; in-place algorithm for reversing a array > > (setq arrayA ["a" "b" "c" "d" "e" "f" "g"]) > > (setq arrayLength (length arrayA)) > > (dotimes (i (floor (/ arrayLength 2))) > (let (x) > (setq x (aref arrayA i)) > (aset arrayA i (aref arrayA (- (1- arrayLength) i))) > (aset arrayA (- (1- arrayLength) i) x) ) ) > > (print (format "%S" arrayA)) > MatzLisp: a = [2,3,5,8] ==>[2, 3, 5, 8] a.reverse! ==>[8, 5, 3, 2] a ==>[8, 5, 3, 2] From johnjsal at gmail.com Thu Mar 1 01:41:53 2012 From: johnjsal at gmail.com (John Salerno) Date: Wed, 29 Feb 2012 22:41:53 -0800 (PST) Subject: Is it necessary to call Tk() when writing a GUI app with Tkinter? In-Reply-To: References: <27603449.17.1330492001624.JavaMail.geo-discussion-forums@vbbfv2> <6e1c521e-14be-4ec0-9ff0-7f23fd9cd3dc@f14g2000yqe.googlegroups.com> <17153317.324.1330576905540.JavaMail.geo-discussion-forums@yncd8> Message-ID: <23675630.870.1330584114032.JavaMail.geo-discussion-forums@ynjc20> > Yes. You must leave it out. Now I'm reading a Tkinter reference at http://infohost.nmt.edu/tcc/help/pubs/tkinter/minimal-app.html and it has this example: #!/usr/local/bin/python from Tkinter import * class Application(Frame): def __init__(self, master=None): Frame.__init__(self, master) self.grid() self.createWidgets() def createWidgets(self): self.quitButton = Button ( self, text='Quit', command=self.quit ) self.quitButton.grid() app = Application() app.master.title("Sample application") app.mainloop() Is this just outdated? I don't understand why it uses quit() instead of destroy(). When I try this in IDLE, quit() just causes the application to hang (I assume because it ends the mainloop without actually closing the application). Or is this just a problem when using IDLE? If the latter, which is preferable, quit or destroy? From johnjsal at gmail.com Thu Mar 1 01:41:53 2012 From: johnjsal at gmail.com (John Salerno) Date: Wed, 29 Feb 2012 22:41:53 -0800 (PST) Subject: Is it necessary to call Tk() when writing a GUI app with Tkinter? In-Reply-To: References: <27603449.17.1330492001624.JavaMail.geo-discussion-forums@vbbfv2> <6e1c521e-14be-4ec0-9ff0-7f23fd9cd3dc@f14g2000yqe.googlegroups.com> <17153317.324.1330576905540.JavaMail.geo-discussion-forums@yncd8> Message-ID: <23675630.870.1330584114032.JavaMail.geo-discussion-forums@ynjc20> > Yes. You must leave it out. Now I'm reading a Tkinter reference at http://infohost.nmt.edu/tcc/help/pubs/tkinter/minimal-app.html and it has this example: #!/usr/local/bin/python from Tkinter import * class Application(Frame): def __init__(self, master=None): Frame.__init__(self, master) self.grid() self.createWidgets() def createWidgets(self): self.quitButton = Button ( self, text='Quit', command=self.quit ) self.quitButton.grid() app = Application() app.master.title("Sample application") app.mainloop() Is this just outdated? I don't understand why it uses quit() instead of destroy(). When I try this in IDLE, quit() just causes the application to hang (I assume because it ends the mainloop without actually closing the application). Or is this just a problem when using IDLE? If the latter, which is preferable, quit or destroy? From steve+comp.lang.python at pearwood.info Thu Mar 1 02:38:08 2012 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 01 Mar 2012 07:38:08 GMT Subject: Is it necessary to call Tk() when writing a GUI app with Tkinter? References: <27603449.17.1330492001624.JavaMail.geo-discussion-forums@vbbfv2> <6e1c521e-14be-4ec0-9ff0-7f23fd9cd3dc@f14g2000yqe.googlegroups.com> <17153317.324.1330576905540.JavaMail.geo-discussion-forums@yncd8> <23675630.870.1330584114032.JavaMail.geo-discussion-forums@ynjc20> Message-ID: <4f4f2760$0$11107$c3e8da3@news.astraweb.com> On Wed, 29 Feb 2012 22:41:53 -0800, John Salerno wrote: >> Yes. You must leave it out. > > Now I'm reading a Tkinter reference at > http://infohost.nmt.edu/tcc/help/pubs/tkinter/minimal-app.html and it > has this example: [...] Could you please stop posting the same message twice? It's very annoying. There is no need to C.C. python-list because comp.lang.python is the mirror of the mailing list. Thank you. -- Steven From johnjsal at gmail.com Thu Mar 1 02:58:37 2012 From: johnjsal at gmail.com (John Salerno) Date: Wed, 29 Feb 2012 23:58:37 -0800 (PST) Subject: Is it necessary to call Tk() when writing a GUI app with Tkinter? In-Reply-To: <4f4f2760$0$11107$c3e8da3@news.astraweb.com> References: <27603449.17.1330492001624.JavaMail.geo-discussion-forums@vbbfv2> <6e1c521e-14be-4ec0-9ff0-7f23fd9cd3dc@f14g2000yqe.googlegroups.com> <17153317.324.1330576905540.JavaMail.geo-discussion-forums@yncd8> <23675630.870.1330584114032.JavaMail.geo-discussion-forums@ynjc20> <4f4f2760$0$11107$c3e8da3@news.astraweb.com> Message-ID: <30160611.9.1330588717114.JavaMail.geo-discussion-forums@ynbo9> On Thursday, March 1, 2012 1:38:08 AM UTC-6, Steven D'Aprano wrote: > On Wed, 29 Feb 2012 22:41:53 -0800, John Salerno wrote: > > >> Yes. You must leave it out. > > > > Now I'm reading a Tkinter reference at > > http://infohost.nmt.edu/tcc/help/pubs/tkinter/minimal-app.html and it > > has this example: > [...] > > Could you please stop posting the same message twice? It's very annoying. > There is no need to C.C. python-list because comp.lang.python is the > mirror of the mailing list. > > > Thank you. > > > > -- > Steven I'm sorry, it's unintentional. The new interface for Google Groups keeps doing weird things and makes double and triple posts. I deleted them from my end, but I guess they are still showing up for everyone else. From ushamovi at gmail.com Thu Mar 1 04:55:53 2012 From: ushamovi at gmail.com (usha chubby) Date: Thu, 1 Mar 2012 01:55:53 -0800 (PST) Subject: its very intersting Message-ID: <5a72545b-2b01-4088-ade1-4422d2dac461@j8g2000yqm.googlegroups.com> : http://123maza.com/46/hibiscus741/ From matt.jones at radiusrecruitment.co.uk Thu Mar 1 05:17:09 2012 From: matt.jones at radiusrecruitment.co.uk (Matt Jones) Date: Thu, 1 Mar 2012 10:17:09 +0000 Subject: Python Developer Job Opportunities Message-ID: <5430F7595299CC4FA07A3750381517D10F3A8838@AMSPRD0302MB110.eurprd03.prod.outlook.com> I have an opportunity for talented Python Developers with Django experience based in the South of the UK. I am recruiting for a funded new venture set up by two successful entrepreneurs who are experienced and well--respected scientists and mathematicians. They're building a new and radical way of learning Maths; an advanced technological platform (iPad / Cloud based) with unique data gathering and analysis capabilities the program will create a world beating, cutting edge product. They are on the hunt for Python developers to build the interface of a brand new cloud hosted web app that will be rolled out on iPad as well as a bespoke CMS, web portal and internal visualization platform. The team are working in brand new, expansive offices (45,000 square feet, free lunch, onsite gym, games room, poker room with casino grade tables, 5-A-Side football pitch). This is an exciting opportunity to become a core member of the development team in a growing company that will be providing a technical challenge in a fantastic working environment all in aid of a good cause. If you would like to discuss the role in more detail please contact me at matt.jones at radiusrecruitment.co.uk I can also provide photos of the office, details on working environment etc. -------------- next part -------------- An HTML attachment was scrubbed... URL: From kiuhnm03.4t.yahoo.it Thu Mar 1 06:00:26 2012 From: kiuhnm03.4t.yahoo.it (Kiuhnm) Date: Thu, 01 Mar 2012 12:00:26 +0100 Subject: New Science Discovery: Perl Idiots Remain Idiots After A Decade!New Science Discovery: Perl Idiots Remain Idiots After A Decade! In-Reply-To: <9dc55d52-3902-4449-87e7-745fb8b911b3@n12g2000yqb.googlegroups.com> References: <0078bbfb-5dfc-48fc-af1a-69de3cf15c3e@b1g2000yqb.googlegroups.com> <4f4e1554$0$1385$4fafbaef@reader2.news.tin.it> <9dc55d52-3902-4449-87e7-745fb8b911b3@n12g2000yqb.googlegroups.com> Message-ID: <4f4f56c8$0$1381$4fafbaef@reader2.news.tin.it> On 3/1/2012 1:02, Xah Lee wrote: > i missed a point in my original post. That is, when the same operator > are adjacent. e.g. ?3 ? 6 ? 5?. > > This is pointed out by Kiuhnm ?kiuhnm03.4t.yahoo.it? and Tim Bradshaw. > Thanks. > > though, i disagree the way they expressed it, or any sense this is > different from math. They did not make up the terminology, if that is what you are saying. The concepts of left and right associativity are well-known and accepted in TCS (Theoretical CS). If you change the terminology, no one will understand you unless you provide your definitions every time (and then they may not accept them). Another way of saying that an operator is left-associative is that its parse tree is a left-tree, i.e. a complete tree where each right child is a leaf. For instance, (use a monospaced font) 1 + 2 + 3 + 4 gives you this left-tree: + + 4 + 3 1 2 while 1**2**3**4 gives you this right-tree: ** 1 ** 2 ** 3 4 Aho, Sethi and Ullman explain it this way in "Compilers: Principles, Techniques and Tools": "We say that the operator + associates to the left because an operand with plus signs on both sides of it is taken by the operator to its left. [...]" And they also show parse trees similar to the ones I wrote above. Kiuhnm From palla74 at gmail.com Thu Mar 1 07:54:54 2012 From: palla74 at gmail.com (Palla) Date: Thu, 1 Mar 2012 04:54:54 -0800 (PST) Subject: EuroPython 2012: Call for Proposal is Open! [Please spread the word] Message-ID: Hi all, I am writing on behalf of EuroPython Staff (www.europython.eu). We are happy to announce that the Call for Proposals is now officially open! DEADLINE FOR PROPOSALS: MARCH 18TH, 23:59:59 CET For those who have never been at EuroPython (or similar conferences) before, the Call for Proposals is the period in which the organizers ask the community to submit proposals for talks to be held at the conference. EuroPython is a conference run by the community for the community: the vast majority of talks that are presented at the conference will be proposed, prepared and given by members of the Python community itself. And not only that: the process that selects the best talks among all the proposals will also be public and fully driven by the community: it's called Community Voting, and will begin right after the Call for Proposals ends. CFP: Talks, Hands-On Trainings and Posters ------------------------------------------ We're looking for proposals on every aspect of Python: programming from novice to advanced levels, applications and frameworks, or how you have been involved in introducing Python into your organisation. There are three different kind of contribution that you can present at EuroPython: - Regular talk. These are standard "talk with slides", allocated in slots of 45, 60 or 90 minutes, depending on your preference and scheduling constraints. A Q&A session is held at the end of the talk. - Hands-on training. These are advanced training sessions for a smaller audience (10-20 people), to dive into the subject with all details. These sessions are 4-hours long, and the audience will be strongly encouraged to bring a laptop to experiment. They should be prepared with less slides and more source code. - Posters. Posters are a graphical way to describe a project or a technology, printed in large format; posters are exhibited at the conference, can be read at any time by participants, and can be discussed face to face with their authors during the poster session. We will take care of printing the posters too, so don't worry about logistics. More details about Call for Proposal are online here: https://ep2012.europython.eu/call-for-proposals/ Don't wait for the last day --------------------------- If possible, please avoid submitting your proposals on the last day. It might sound a strange request, but last year about 80% of the proposals were submitted in the last 72 hours. This creates a few problems for organizers because we can't have a good picture of the size of the conference until that day. Remember that proposals are fully editable at any time, even after the Call for Proposals ends. You just need to login on the website, go to the proposal page (linked from your profile page), and click the Edit button. First-time speakers are especially welcome; EuroPython is a community conference and we are eager to hear about your experience. If you have friends or colleagues who have something valuable to contribute, twist their arms to tell us about it! We are a conference run by the community for the community. Please help to spread the word by distributing this announcement to colleagues, mailing lists, your blog, Web site, and through your social networking connections. All the best, Francesco From rolf.wester at ilt.fraunhofer.de Thu Mar 1 08:07:15 2012 From: rolf.wester at ilt.fraunhofer.de (Rolf Wester) Date: Thu, 01 Mar 2012 14:07:15 +0100 Subject: exec Message-ID: <4f4f7527$1@news.fhg.de> Hi, I would like to define methods using exec like this: class A: def __init__(self): cmd = "def sqr(self, x):\n return x**2\nself.sqr = sqr\n" exec cmd a = A() print a.sqr(a, 2) This works, but I have to call sqr with a.sqr(a, 2), a.sqr(2) does not work (TypeError: sqr() takes exactly 2 arguments (1 given)). Is there a possibility to define methods using exec and getting normal behavior? I would be very appreciative for any help. With kind regards Rolf Wester From jeanmichel at sequans.com Thu Mar 1 08:46:43 2012 From: jeanmichel at sequans.com (Jean-Michel Pichavant) Date: Thu, 01 Mar 2012 14:46:43 +0100 Subject: exec In-Reply-To: <4f4f7527$1@news.fhg.de> References: <4f4f7527$1@news.fhg.de> Message-ID: <4F4F7DC3.4070009@sequans.com> Rolf Wester wrote: > Hi, > > I would like to define methods using exec like this: > > class A: > def __init__(self): > cmd = "def sqr(self, x):\n return x**2\nself.sqr = sqr\n" > exec cmd > a = A() > print a.sqr(a, 2) > > This works, but I have to call sqr with a.sqr(a, 2), a.sqr(2) does not work > (TypeError: sqr() takes exactly 2 arguments (1 given)). > > Is there a possibility to define methods using exec and getting normal behavior? > > I would be very appreciative for any help. > > With kind regards > Rolf Wester > > > I'll try to ignore you are using the exec statement which is an error :o) a.sqr(2) would have worked only if sqr was a *bound* method. print a.sqr to oppose to print a.__init__ > You cannot dynamically bind a method, however you can do the following. cmd = "def sqr(x):\n return x**2\nself.sqr = sqr\n" http://docs.python.org/reference/datamodel.html : "It is also important to note that user-defined functions which are attributes of a class instance are not converted bound methods; this only happens when the function is an attribute of the class. " JM From fpallanti at develer.com Thu Mar 1 09:10:29 2012 From: fpallanti at develer.com (Francesco Pallanti) Date: Thu, 01 Mar 2012 15:10:29 +0100 Subject: EuroPython 2012: Call for Proposal is Open! [Please spread the word] Message-ID: <1330611029.15056.18.camel@bmlab-palla> Hi guys, I'm Francesco and I am writing on behalf of EuroPython Staff (www.europython.eu). We are happy to announce that the Call for Proposals is now officially open! DEADLINE FOR PROPOSALS: MARCH 18TH, 23:59:59 CET For those who have never been at EuroPython (or similar conferences) before, the Call for Proposals is the period in which the organizers ask the community to submit proposals for talks to be held at the conference. Further details about Call for Proposal are online here: http://ep2012.europython.eu/call-for-proposals/ EuroPython is a conference run by the community for the community: the vast majority of talks that are presented at the conference will be proposed, prepared and given by members of the Python community itself. And not only that: the process that selects the best talks among all the proposals will also be public and fully driven by the community: it's called Community Voting, and will begin right after the Call for Proposals ends. CFP: Talks, Hands-On Trainings and Posters ------------------------------------------ We're looking for proposals on every aspect of Python: programming from novice to advanced levels, applications and frameworks, or how you have been involved in introducing Python into your organisation. There are three different kind of contribution that you can present at EuroPython: - Regular talk. These are standard "talk with slides", allocated in slots of 45, 60 or 90 minutes, depending on your preference and scheduling constraints. A Q&A session is held at the end of the talk. - Hands-on training. These are advanced training sessions for a smaller audience (10-20 people), to dive into the subject with all details. These sessions are 4-hours long, and the audience will be strongly encouraged to bring a laptop to experiment. They should be prepared with less slides and more source code. - Posters. Posters are a graphical way to describe a project or a technology, printed in large format; posters are exhibited at the conference, can be read at any time by participants, and can be discussed face to face with their authors during the poster session. We will take care of printing the posters too, so don't worry about logistics. More details about Call for Proposal are online here: http://ep2012.europython.eu/call-for-proposals/ Don't wait for the last day --------------------------- If possible, please avoid submitting your proposals on the last day. It might sound a strange request, but last year about 80% of the proposals were submitted in the last 72 hours. This creates a few problems for organizers because we can't have a good picture of the size of the conference until that day. Remember that proposals are fully editable at any time, even after the Call for Proposals ends. You just need to login on the website, go to the proposal page (linked from your profile page), and click the Edit button. First-time speakers are especially welcome; EuroPython is a community conference and we are eager to hear about your experience. If you have friends or colleagues who have something valuable to contribute, twist their arms to tell us about it! We are a conference run by the community for the community. Please help to spread the word by distributing this announcement to colleagues, mailing lists, your blog, Web site, and through your social networking connections. All the best, -- Francesco Pallanti - fpallanti at develer.com Develer S.r.l. - http://www.develer.com/ .software .hardware .innovation Tel.: +39 055 3984627 - ext.: 215 From arnodel at gmail.com Thu Mar 1 09:13:39 2012 From: arnodel at gmail.com (Arnaud Delobelle) Date: Thu, 1 Mar 2012 14:13:39 +0000 Subject: exec In-Reply-To: <4f4f7527$1@news.fhg.de> References: <4f4f7527$1@news.fhg.de> Message-ID: On 1 March 2012 13:07, Rolf Wester wrote: > Hi, > > I would like to define methods using exec like this: > > class A: > ? ?def __init__(self): > ? ? ? ?cmd = "def sqr(self, x):\n ? ?return x**2\nself.sqr = sqr\n" > ? ? ? ?exec cmd > a = A() > print a.sqr(a, 2) > > This works, but I have to call sqr with a.sqr(a, 2), a.sqr(2) does not work > (TypeError: sqr() takes exactly 2 arguments (1 given)). I'm curious to know your motivation for doing this. -- Arnaud From steve+comp.lang.python at pearwood.info Thu Mar 1 09:21:31 2012 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 01 Mar 2012 14:21:31 GMT Subject: exec References: <4f4f7527$1@news.fhg.de> Message-ID: <4f4f85eb$0$29989$c3e8da3$5496439d@news.astraweb.com> On Thu, 01 Mar 2012 14:07:15 +0100, Rolf Wester wrote: > Hi, > > I would like to define methods using exec like this: > > class A: > def __init__(self): > cmd = "def sqr(self, x):\n return x**2\nself.sqr = sqr\n" > exec cmd > a = A() > print a.sqr(a, 2) That's... nasty, nasty code. I would hate to have to maintain that. I hope you have a VERY good reason for doing it instead of the more obvious: class B: def __init__(self): def sqr(self, x): return x**2 self.sqr = sqr or the even more obvious: class C: def sqr(self, x): return x**2 And I *really* hope that you aren't getting the string to be exec'ed from untrusted users. The world has enough code injection vulnerabilities. If you don't understand what a code injection vulnerability is, or why using exec on untrusted strings is dangerous, stop what you are doing and don't write another line of code until you have read up it. You can start here: http://en.wikipedia.org/wiki/Code_injection https://www.owasp.org/index.php/Injection_Flaws and remember, code injection attacks are now the most frequent attack vector of viruses, worms and malware, ahead of buffer overflow attacks. Class C is, of course, the only one where a.sqr is an actual method, that is, a.sqr(5) works instead of a.sqr(a, 5). You can fix this by doing one of the following: (1) Your function sqr() doesn't actually use self, so why require it? Get rid of it! class A: def __init__(self): # still nasty... cmd = "def sqr(x):\n return x**2" exec cmd self.sqr = sqr # or put this in the cmd string (yuck) class B: def __init__(self): # better, but still weird def sqr(x): return x**2 self.sqr = sqr (2) Perhaps you actually do need access to self. So turn the function into a proper method. from types import MethodType class A: def __init__(self): # still nasty... cmd = "def sqr(self, x):\n return x**2\n" exec cmd self.sqr = MethodType(sqr, self) class B: def __init__(self): def sqr(self, x): return x**2 self.sqr = MethodType(sqr, self) (3) My guess is that there is probably some sort of closure-based solution that will work, or delegation, or composition. But given the toy example you have shown, I don't know what that might be. If you explain what you are actually doing, perhaps someone can suggest a better solution. -- Steven From rweikusat at mssgmbh.com Thu Mar 1 09:39:25 2012 From: rweikusat at mssgmbh.com (Rainer Weikusat) Date: Thu, 01 Mar 2012 14:39:25 +0000 Subject: lang comparison: in-place algorithm for reversing a list in Perl, Python, Lisp References: <85fa5760-68c8-41a2-9116-2489165f7ca1@j5g2000yqm.googlegroups.com> Message-ID: <87obsg1j36.fsf@sapphire.mobileactivedefense.com> Xah Lee writes: [...] > # perl > # in-place algorithm for reversing a list. > > use strict; > use Data::Dumper; > use POSIX; # for ?floor? > > my @listA = qw(a b c d e f g); > > my $listLength = scalar @listA; > > for ( my $i = 0; $i < floor($listLength/2); $i++ ) { > my $x = $listA[$i]; > $listA[$i] = $listA[ $listLength - 1 - $i]; > $listA[ $listLength - 1 - $i] = $x; > } > > print Dumper(\@listA); Better algorithm for that (expects an array reference as first argument) sub rev { my $a = $_[0]; my ($n0, $n1, $x); $n0 = 0; $n1 = $#$a; while ($n0 < $n1) { $x = $a->[$n0]; $a->[$n0] = $a->[$n1]; $a->[$n1] = $x; ++$n0; --$n1; } } NB: The fact that a sufficiently sophisticated compiler might be able to fix this automatically emphasizes the deficiencies of the original attempt, it doesn't excuse them. From rweikusat at mssgmbh.com Thu Mar 1 09:40:58 2012 From: rweikusat at mssgmbh.com (Rainer Weikusat) Date: Thu, 01 Mar 2012 14:40:58 +0000 Subject: New Science Discovery: Perl Idiots Remain Idiots After A Decade!New Science Discovery: Perl Idiots Remain Idiots Af References: <0078bbfb-5dfc-48fc-af1a-69de3cf15c3e@b1g2000yqb.googlegroups.com> <87aa41k6x5.fsf@sapphire.mobileactivedefense.com> <4f4ef6c8$27$fuzhry+tra$mr2ice@news.patriot.net> Message-ID: <87k4341j0l.fsf@sapphire.mobileactivedefense.com> Shmuel (Seymour J.) Metz writes: > In <87aa41k6x5.fsf at sapphire.mobileactivedefense.com>, on 02/29/2012 > at 03:15 PM, Rainer Weikusat said: > >>'mathematics' (an essentially outdated write-only programming >>language dating back to the times when humans had to perform >>computations themselves) > > ROTF,LMAO! You obviously don't have a clue as to what Mathematics > means. Free hint: it doesn't mean Arithmetic. You obviously don't have any sense of humour. But don't let this trouble you. From spamtrap at library.lspace.org.invalid Thu Mar 1 10:07:15 2012 From: spamtrap at library.lspace.org.invalid (Shmuel Metz (Seymour J.)) Date: Thu, 01 Mar 2012 10:07:15 -0500 Subject: New Science Discovery: Perl Detracters Remain Idiots After A Decade! References: <0078bbfb-5dfc-48fc-af1a-69de3cf15c3e@b1g2000yqb.googlegroups.com> <4f4ef5d2$26$fuzhry+tra$mr2ice@news.patriot.net> Message-ID: <4f4f90a3$38$fuzhry+tra$mr2ice@news.patriot.net> In , on 03/01/2012 at 04:52 AM, Chiron said: >Yes. That (the mathematically defined way) is a particular way, is >it not? No. There is no "the mathematically defined way". >However, I wasn't specifically referring to infix/postfix/prefix or >anything of that nature. I wasn't limiting my comment to lisp >notation in particular, since what I said applies to any language. No, it doesn't. >I was referring to the placement of parentheses (or other >groupings) to indicate to *humans* what the intended sequence >of events was. Operator precedence has the same purpose, and was around long before computers. Quite often expressions exploiting operator precedence are easier *for humans* to read than expressions involving deeply nested parentheses. >Mathematically, Your exposure to Mathematics is too limited. >and in any language with which I am familiar, Your exposure to computer languages is too limited. >the sequence: 2 + 6 / 3 will yield 4. Try it in APL. >Whenever there is *any* possibility of ambiguity, I see no reason >not to clarify. Even if doing so makes it harder to read? Since you keep referring to Mathematics, I will point out that it is rare in Mathematics for anybody to publish a complete proof. Minor steps are almost always omitted to make for easier reading, and ambiguous shortcuts are used in the expectation that the reader will understand what is meant. >Back in the days when the way you wrote your code affected how it >was compiled, That would be the present. >it made sense to rely heavily on language-specific >features, thus saving a few bytes. Those optimizations involved adding extraneous parentheses, not omitting redundant parentheses. >A few extra variables, if they help clarity, aren't going to hurt >anything. And if they harm clarity? >Let the machine do the grunt work. That's exactly what languages with operator precedence do. >Pamper your readers (which in a few weeks or months might be you) >and show exactly what you had in mind. The two goals conflict. >That's all I'm saying. No; you're saying to use redundant parentheses, which conflicts with other things you're saying. -- Shmuel (Seymour J.) Metz, SysProg and JOAT Unsolicited bulk E-mail subject to legal action. I reserve the right to publicly post or ridicule any abusive E-mail. Reply to domain Patriot dot net user shmuel+news to contact me. Do not reply to spamtrap at library.lspace.org From spamtrap at library.lspace.org.invalid Thu Mar 1 10:13:11 2012 From: spamtrap at library.lspace.org.invalid (Shmuel Metz (Seymour J.)) Date: Thu, 01 Mar 2012 10:13:11 -0500 Subject: New Science Discovery: Perl Idiots Remain Idiots After A Decade!New Science Discovery: Perl Idiots Remain Idiots Af References: <0078bbfb-5dfc-48fc-af1a-69de3cf15c3e@b1g2000yqb.googlegroups.com> <87aa41k6x5.fsf@sapphire.mobileactivedefense.com> <4f4ef6c8$27$fuzhry+tra$mr2ice@news.patriot.net> Message-ID: <4f4f9207$39$fuzhry+tra$mr2ice@news.patriot.net> In , on 03/01/2012 at 05:07 AM, Chiron said: >Hmm... maybe, instead of just ridiculing him, I'm treating him as he treats others. >BTW, I happen to agree with you insofar as this poster not >understanding the nature of mathematics. His comment reminds me of >the article, "Transgressing the Boundaries: Towards a >Transformative Hermeneutics of Quantum Gravity" A brilliant piece of work. I greatly enjoyed it and the reaction to its disclosure. -- Shmuel (Seymour J.) Metz, SysProg and JOAT Unsolicited bulk E-mail subject to legal action. I reserve the right to publicly post or ridicule any abusive E-mail. Reply to domain Patriot dot net user shmuel+news to contact me. Do not reply to spamtrap at library.lspace.org From marek.lipert at gmail.com Thu Mar 1 10:41:19 2012 From: marek.lipert at gmail.com (Marek Lipert) Date: Thu, 01 Mar 2012 16:41:19 +0100 Subject: SSL and os.system/Popen Message-ID: Hi! I have a problem with SSL and threaded os.system (rewritten to Popen but still not working). First - the set-up: I am using windows 2003 server with current python 2.6. When new connection comes to my server-side application, i do accept, and then: self.client = ssl.wrap_socket(self.socket,certfile="server.crt",keyfile="server.key",ss l_version=ssl.PROTOCOL_TLSv1,server_side=True) It works flawlessly UNLESS another therad of this same application runs simultanously os.system (or Popen) on an external exe file (which does not do a thing in a directory where my server is) I then get an error [Errno 336265218] _ssl.c:337: error:140B0002:SSL routines:SSL_CTX_use_PrivateKey_file:system lib I suspect it has something to do with filesystem locking, but why? The application is run by administrator and certificate files are marked as 'full control' and all other security properties in windows (for everyone, not just administrator). I would appreciate your help. Cheers, Mark From rolf.wester at ilt.fraunhofer.de Thu Mar 1 10:58:41 2012 From: rolf.wester at ilt.fraunhofer.de (Rolf Wester) Date: Thu, 01 Mar 2012 16:58:41 +0100 Subject: exec In-Reply-To: <4f4f7527$1@news.fhg.de> References: <4f4f7527$1@news.fhg.de> Message-ID: <4f4f9d55$1@news.fhg.de> Hi, thanks for your replies so far. The reason to use exec is just laziness. I have quite a lot of classes representing material data and every class has a number of parameters. The parameter are Magnitude objects (they have a value and a unit and overloaded special functions to correctly handle the units). I want to have getter functions that either return the Magnitude object or just the value: iron = Iron() iron.rho(0) => value iron.rho() => Magnitude object def rho(self, uf=1): if uf == 1: return self._rho else: return self._rho.val And because this would mean quite a lot of writing I tried to do it with exec. With kind regards Rolf Wester From phd at phdru.name Thu Mar 1 11:08:40 2012 From: phd at phdru.name (Oleg Broytman) Date: Thu, 1 Mar 2012 20:08:40 +0400 Subject: SQLObject 1.2.2 Message-ID: <20120301160840.GD3441@iskra.aviel.ru> Hello! I'm pleased to announce version 1.2.2, a bugfix release of branch 1.2 of SQLObject. What is SQLObject ================= SQLObject is an object-relational mapper. Your database tables are described as classes, and rows are instances of those classes. SQLObject is meant to be easy to use and quick to get started with. SQLObject supports a number of backends: MySQL, PostgreSQL, SQLite, Firebird, Sybase, MSSQL and MaxDB (also known as SAPDB). Where is SQLObject ================== Site: http://sqlobject.org Development: http://sqlobject.org/devel/ Mailing list: https://lists.sourceforge.net/mailman/listinfo/sqlobject-discuss Archives: http://news.gmane.org/gmane.comp.python.sqlobject Download: http://pypi.python.org/pypi/SQLObject/1.2.2 News and changes: http://sqlobject.org/News.html What's New ========== * A bug was fixed in SQLiteConnection - clear _threadPool on close(). For a more complete list, please see the news: http://sqlobject.org/News.html Oleg. -- Oleg Broytman http://phdru.name/ phd at phdru.name Programmers don't die, they just GOSUB without RETURN. From michael at stroeder.com Thu Mar 1 11:26:03 2012 From: michael at stroeder.com (=?ISO-8859-1?Q?Michael_Str=F6der?=) Date: Thu, 01 Mar 2012 17:26:03 +0100 Subject: exec In-Reply-To: <4f4f9d55$1@news.fhg.de> References: <4f4f7527$1@news.fhg.de> <4f4f9d55$1@news.fhg.de> Message-ID: Rolf Wester wrote: > The reason to use exec is just laziness. The worst reason for using it. So I hope you carefully read Steven's comment and get rid of exec() for anything serious: <4f4f85eb$0$29989$c3e8da3$5496439d at news.astraweb.com> Ciao, Michael. From peter216 at gmail.com Thu Mar 1 11:56:16 2012 From: peter216 at gmail.com (Peter Rubenstein) Date: Thu, 1 Mar 2012 11:56:16 -0500 Subject: Help needed: dynamically pull data from different levels of a dict In-Reply-To: References: Message-ID: Thanks, Chris. That's the algorithm I was looking for. And I will be converting most of this data to objects. Thanks again. -----Original Message----- From: Chris Rebert [mailto:clp2 at rebertia.com] Sent: Wednesday, February 29, 2012 11:44 PM Subject: Re: Help needed: dynamically pull data from different levels of a dict On Wed, Feb 29, 2012 at 7:56 PM, Peter Rubenstein wrote: > Hi, > > I'd appreciate a bit of help on this problem. I have some data that > I've converted to a dict and I want to pull out individual pieces of it. > > Simplified version-- > > a={'1':'a', '2':'b', '3':{4:'d'}, '5':{'6': {'7': [ {'8':'e'}, > {'9':'f'} ] } } } > > I'd like to be able to code something like: > > data_needed = ['1', '2', '3:4', '5:6:7-8'] for val in data_needed: > answer=extract_from(a,val) > print answer > > And get: > a > b > c "c" apparently sprung completely out of thin air... > d > e > > Problem is I can't figure out what extract_from would look like, such > that it would proceed dynamically down to the right level. I'm open > to the possibility that I'm not approaching this the right way. data_needed = ['1', '2', ('3', '4'), ('5', '6', '7', 0, '8')] def extract_from(mapping, key_path): current = mapping for key in key_path: current = current[key] return current I would perhaps try and restructure the data into something less generic than nested dicts & lists, e.g. objects. You then might be able to introduce helper querying methods. I would also be worried about Law of Demeter violations, but fortunately your concrete example doesn't reach any deeper than 2 levels. Cheers, Chris -- http://chrisrebert.com From __peter__ at web.de Thu Mar 1 12:14:54 2012 From: __peter__ at web.de (Peter Otten) Date: Thu, 01 Mar 2012 18:14:54 +0100 Subject: exec References: <4f4f7527$1@news.fhg.de> <4f4f9d55$1@news.fhg.de> Message-ID: Rolf Wester wrote: > The reason to use exec is just laziness. I have quite a lot of classes > representing material data and every class has a number of parameters. > The parameter are Magnitude objects (they have a value and a unit and > overloaded special functions to correctly handle the units). I want to > have getter functions that either return the Magnitude object or just the > value: > > iron = Iron() > iron.rho(0) => value > iron.rho() => Magnitude object > > def rho(self, uf=1): > if uf == 1: > return self._rho > else: > return self._rho.val > > And because this would mean quite a lot of writing I tried to do it with > exec. Make the Magnitude class callable then: >>> class Magnitude(object): ... def __init__(self, value): ... self.value = value ... def __call__(self, uf=1): ... if uf == 1: ... return self ... return self.value ... >>> class Iron(object): ... def __init__(self): ... self.rho = Magnitude(42) ... >>> iron = Iron() >>> iron.rho() <__main__.Magnitude object at 0x7fb94062be10> >>> iron.rho(0) 42 From rolf.wester at ilt.fraunhofer.de Thu Mar 1 12:23:58 2012 From: rolf.wester at ilt.fraunhofer.de (Rolf Wester) Date: Thu, 01 Mar 2012 18:23:58 +0100 Subject: exec In-Reply-To: References: <4f4f7527$1@news.fhg.de> <4f4f9d55$1@news.fhg.de> Message-ID: <4f4fb151$1@news.fhg.de> Thank you, that really made things much easier and admittedly much less nasty too. Regards Rolf On 01/03/12 18:14, Peter Otten wrote: > Rolf Wester wrote: > >> The reason to use exec is just laziness. I have quite a lot of classes >> representing material data and every class has a number of parameters. >> The parameter are Magnitude objects (they have a value and a unit and >> overloaded special functions to correctly handle the units). I want to >> have getter functions that either return the Magnitude object or just the >> value: >> >> iron = Iron() >> iron.rho(0) => value >> iron.rho() => Magnitude object >> >> def rho(self, uf=1): >> if uf == 1: >> return self._rho >> else: >> return self._rho.val >> >> And because this would mean quite a lot of writing I tried to do it with >> exec. > > Make the Magnitude class callable then: > >>>> class Magnitude(object): > ... def __init__(self, value): > ... self.value = value > ... def __call__(self, uf=1): > ... if uf == 1: > ... return self > ... return self.value > ... >>>> class Iron(object): > ... def __init__(self): > ... self.rho = Magnitude(42) > ... >>>> iron = Iron() >>>> iron.rho() > <__main__.Magnitude object at 0x7fb94062be10> >>>> iron.rho(0) > 42 > > From nikunjbadjatya at gmail.com Thu Mar 1 12:39:28 2012 From: nikunjbadjatya at gmail.com (Nikunj Badjatya) Date: Thu, 1 Mar 2012 23:09:28 +0530 Subject: HELP ! Popen.terminate() - WindowsError: [Error 5] Access is denied Message-ID: Howdy All, Py ver - 3.2, Windows-XP . Logged in as user with admin privileges. >From my main python program, I am running powershell program using subprocess.Popen(....). Now I have created a signal_handler() function in main python script which will handle CTRL-C ( This works fine ). Now when I put "proc.terminate()" in my signal_handler() function to terminate the subprocess created as well, It is giving me "WindowsError: [Error 5] Access is denied" error. I have tried with os.kill() also, same error. Tried with Popen.kill() also same error. Have googled a bit but couldn't understand them. In general, How to kill a subprocesses created from a python program.? If that subprocess also creates a new process from itself, how can I kill all child processes from my main python script.? Any ideas.?? Thanks, Nikunj -------------- next part -------------- An HTML attachment was scrubbed... URL: From ramit.prasad at jpmorgan.com Thu Mar 1 13:15:55 2012 From: ramit.prasad at jpmorgan.com (Prasad, Ramit) Date: Thu, 1 Mar 2012 18:15:55 +0000 Subject: HELP ! Popen.terminate() - WindowsError: [Error 5] Access is denied In-Reply-To: References: Message-ID: <5B80DD153D7D744689F57F4FB69AF47416B26E@SCACMX008.exchad.jpmchase.net> > Now when I put "proc.terminate()" in my signal_handler() function to > terminate the subprocess created as well, > It is giving me "WindowsError: [Error 5] Access is denied" error. > I have tried with os.kill() also, same error. Tried with Popen.kill() also > same error. Have googled a bit but couldn't understand them. > > In general, How to kill a subprocesses created from a python program.? If > that subprocess also creates a new process from itself, how can I kill all > child processes from my main python script.? I have not tested this, but you could get the pid by doing Popen.pid and then killing it from the command line by doing "taskkill /PID [pid]". This is all dependant on the users ability to kill the task in the first place. If that does not work then the problem is probably not Python but Windows. You could test by running your program and doing the taskkill in a separate command prompt. Hope that helps, Ramit Ramit Prasad | JPMorgan Chase Investment Bank | Currencies Technology 712 Main Street | Houston, TX 77002 work phone: 713 - 216 - 5423 -- This email is confidential and subject to important disclaimers and conditions including on offers for the purchase or sale of securities, accuracy and completeness of information, viruses, confidentiality, legal privilege, and legal entity disclaimers, available at http://www.jpmorgan.com/pages/disclosures/email. From spamtrap at library.lspace.org.invalid Thu Mar 1 16:11:35 2012 From: spamtrap at library.lspace.org.invalid (Shmuel Metz (Seymour J.)) Date: Thu, 01 Mar 2012 16:11:35 -0500 Subject: New Science Discovery: Perl Idiots Remain Idiots After A Decade!New Science Discovery: Perl Idiots Remain Idiots Af References: <0078bbfb-5dfc-48fc-af1a-69de3cf15c3e@b1g2000yqb.googlegroups.com> <87aa41k6x5.fsf@sapphire.mobileactivedefense.com> <4f4ef6c8$27$fuzhry+tra$mr2ice@news.patriot.net> <87k4341j0l.fsf@sapphire.mobileactivedefense.com> Message-ID: <4f4fe607$4$fuzhry+tra$mr2ice@news.patriot.net> In <87k4341j0l.fsf at sapphire.mobileactivedefense.com>, on 03/01/2012 at 02:40 PM, Rainer Weikusat said: >You obviously don't have any sense of humour. Certainly I do; I laugh at pretentious loons with delusions of adequacy. -- Shmuel (Seymour J.) Metz, SysProg and JOAT Unsolicited bulk E-mail subject to legal action. I reserve the right to publicly post or ridicule any abusive E-mail. Reply to domain Patriot dot net user shmuel+news to contact me. Do not reply to spamtrap at library.lspace.org From jeanpierreda at gmail.com Thu Mar 1 16:58:13 2012 From: jeanpierreda at gmail.com (Devin Jeanpierre) Date: Thu, 1 Mar 2012 16:58:13 -0500 Subject: New Science Discovery: Perl Idiots Remain Idiots After A Decade!New Science Discovery: Perl Idiots Remain Idiots Af In-Reply-To: References: <0078bbfb-5dfc-48fc-af1a-69de3cf15c3e@b1g2000yqb.googlegroups.com> <87aa41k6x5.fsf@sapphire.mobileactivedefense.com> <4f4ef6c8$27$fuzhry+tra$mr2ice@news.patriot.net> Message-ID: On Thu, Mar 1, 2012 at 12:07 AM, Chiron wrote: > On Wed, 29 Feb 2012 23:10:48 -0500, Shmuel (Seymour J.) Metz wrote: > >> ROTF,LMAO! You obviously don't have a clue as to what Mathematics means. >> Free hint: it doesn't mean Arithmetic. You're as bigoted as Xah Lee, > > > Hmm... maybe, instead of just ridiculing him, you could explain where he > is mistaken. ?Of course, doing that is a *LOT* harder than just calling > him a bigot. I agree. Perhaps this is a good primer: http://www.maa.org/devlin/LockhartsLament.pdf -- Devin From xahlee at gmail.com Thu Mar 1 17:04:10 2012 From: xahlee at gmail.com (Xah Lee) Date: Thu, 1 Mar 2012 14:04:10 -0800 (PST) Subject: lang comparison: in-place algorithm for reversing a list in Perl,Python, Lisp References: <85fa5760-68c8-41a2-9116-2489165f7ca1@j5g2000yqm.googlegroups.com> <20120229231658.89@kylheku.com> <20120301064937.505@kylheku.com> Message-ID: <8e769add-e63c-4a74-bb7e-ddd36c04a415@vs5g2000pbc.googlegroups.com> On Mar 1, 7:04?am, Kaz Kylheku wrote: lisp: (floor (/ x y)) --[rewrite]--> (floor x y) Thanks for this interesting point. I don't think it's a good lang design, more of a lang quirk. similarly, in Python 2.x, x/y will work when both x and y are integers. Also, x//y works too, but that // is just perlish unreadable syntax quirk. similarly, in perl, either one require POSIX; floor(x/y); the require POSIX instead of Math is a quirk. But even, floor should really be builtin. or using a perl hack int(x/y) all of the above are quirks. They rely on computer engineering by- products (such as int), or rely on the lang's idiosyncrasy. One easy way to measure it is whether a programer can read and understand a program without having to delve into its idiosyncrasies. Problem with these lang idioms is that it's harder to understand, and whatever advantage/optimization they provide is microscopic and temporary. best is really floor(x/y). idiomatic programing, is a bad thing. It was spread by perl, of course, in the 1990s. Idiomatic lang, i.e. lang with huge number of bizarre idioms, such as perl, is the worst. Xah From rweikusat at mssgmbh.com Thu Mar 1 17:14:35 2012 From: rweikusat at mssgmbh.com (Rainer Weikusat) Date: Thu, 01 Mar 2012 22:14:35 +0000 Subject: lang comparison: in-place algorithm for reversing a list in Perl, Python, Lisp References: <85fa5760-68c8-41a2-9116-2489165f7ca1@j5g2000yqm.googlegroups.com> <20120229231658.89@kylheku.com> <20120301064937.505@kylheku.com> <8e769add-e63c-4a74-bb7e-ddd36c04a415@vs5g2000pbc.googlegroups.com> Message-ID: <87zkc0oto4.fsf@sapphire.mobileactivedefense.com> Xah Lee writes: [...] > similarly, in perl, either one > require POSIX; floor(x/y); > the require POSIX instead of Math is a quirk. But even, floor should > really be builtin. > or > using a perl hack > int(x/y) > > all of the above are quirks. They rely on computer engineering by- > products (such as int), Integral numbers are not 'a computer engineering byproduct'. > or rely on the lang's idiosyncrasy. One easy way to measure it is > whether a programer can read and understand a program without having > to delve into its idiosyncrasies. Problem with these lang idioms is > that it's harder to understand, and whatever advantage/optimization > they provide is microscopic and temporary. It's hard to understand for someone who knows only mathematical idiosyncrasies and who is also convinced that this should really be more than enough for a lifetime. But that's not some kind of 'natural knowledge' people just happen to have but systematically drilled into pupils from a very early age, despite most of them won't ever have any use for any of it insofar it goes beyond + - * /. [...] > idiomatic programing, is a bad thing. If you have to use something (like a particular programming language) but you resent learning how to use it and rather make lofty excuses, chances are that you are rather a lazy f*cker than a great philosopher ... From anikom15 at gmail.com Thu Mar 1 19:46:52 2012 From: anikom15 at gmail.com (Westley =?iso-8859-1?Q?Mart=EDnez?=) Date: Thu, 1 Mar 2012 16:46:52 -0800 Subject: New Science Discovery: Perl Idiots Remain Idiots After A Decade!New Science Discovery: Perl Idiots Remain Idiots After A Decade! In-Reply-To: <0078bbfb-5dfc-48fc-af1a-69de3cf15c3e@b1g2000yqb.googlegroups.com> References: <0078bbfb-5dfc-48fc-af1a-69de3cf15c3e@b1g2000yqb.googlegroups.com> Message-ID: <20120302004652.GA30734@kubrick> First of all: http://www.youtube.com/watch?v=z5jKMEB4hHE On Wed, Feb 29, 2012 at 12:09:16AM -0800, Xah Lee wrote: > Now, let me tell you what operator precedence is. First of all, let's > limit ourselfs to discuss operators that are so-called binary > operators, which, in our context, basically means single symbol > operator that takes it's left and right side as operands. Now, each > symbol have a ?precedence?, or in other words, the set of operators > has a order. (one easy way to think of this is that, suppose you have > n symbols, then you give each a number, from 1 to n, as their order) > So, when 2 symbols are placed side by side such as ?3 ? 6 ? 5?, the > symbol with higher precedence wins. Another easy way to think of this > is that each operator has a stickiness level. The higher its level, it > more sticky it is. You're absolutely correct. > the problem with the perl explanations is that it's one misleading > confusion ball. It isn't about ?left/right associativity?. It isn't > about ?evaluates from left to right or right to left?. Worse, the word > ?associativity? is a math term that describe a property of algebra > that has nothing to do with operator precedence, yet is easily > confused with because it is a property about order of evaluation. (for > example, the addition function is associative, meaning: ?(3+6)+5 = > 3+(6+5)?.) You're not getting it. Math is a language. Perl is a language. They have different rules for grammar. In Perl, C, Python, Java, and pretty much all procedural-based languages, operations are evaluated in two steps: the precedence /and/ the associativity. Each level of precedence has its own associativity, either left-to-right or right-to-left. You can see this in table 2-1 in The C Programming Language. Whatever math does or what you think math does has nothing to do with the way Perl evaluates expressions. From rantingrickjohnson at gmail.com Thu Mar 1 21:35:44 2012 From: rantingrickjohnson at gmail.com (Rick Johnson) Date: Thu, 1 Mar 2012 18:35:44 -0800 (PST) Subject: Is it necessary to call Tk() when writing a GUI app with Tkinter? References: <27603449.17.1330492001624.JavaMail.geo-discussion-forums@vbbfv2> <6e1c521e-14be-4ec0-9ff0-7f23fd9cd3dc@f14g2000yqe.googlegroups.com> <17153317.324.1330576905540.JavaMail.geo-discussion-forums@yncd8> Message-ID: On Feb 29, 10:41?pm, John Salerno wrote: > I'm not sure I understand which method you are advocating. It > sounded like you said calling Tk() explicitly is a bug. I am saying just the opposite: Allowing the module "Tkinter" to implicitly create a root window IF the programmer was too lazy to create a root window himself is ridiculous, confusing, and inconsistent; therefor it's a BUG! Observe: INCORRECT: import Tkinter as tk b = tk.Button(master=None, text='Sloppy Coder') b.pack() b.mainloop() CORRECT: import Tkinter as tk root = tk.Tk() b = tk.Button(root, text='Smart Coder') b.pack() root.mainloop() IMO, only the widget "Tkinter.Tk" should have the method mainloop! If you call w.mainloop() and "w" is NOT an instance of Tkinter.Tk, then an error should be raised; I decided to raise a LazyCoderError in MY version of the Tkinter module just to drive the point home. > I certainly would never create widgets without first creating a > master frame, You really have no choice otherwise. Each and every widget requires a parent argument (or parent=None, which will then create and use the Tkinter._default_root; BUG!). The fact that Tkinter "magically" creates the root window for you does not negate the fact that every widget requires a parent. This is why i think the official version of Tkinter is flawed. And the fix is very simple actually. > but is creating a Frame object enough, or should I create a Tk > object and *then* a Frame object? No matter what, you MUST create an instance of Tkinter.Tk to be the "root" window of your GUI application. After that, you can nest as many frames, toplevels, and blah widgets under that root window as you so desire. Actually you don't even need a "frame", you can pack widgets directly into a Toplevel or Tk widget. EXAMPLE 1: (this works, but is flawed!) root = tk.Tk() b = tk.Button(master=None, text='Sloppy Coder') b.pack() root.mainloop() EXAMPLE 2: (This is how to write code!) root = tk.Tk() widgetframe = tk.Frame(root) b = tk.Button(master=None, text='Sloppy Coder') b.pack() root.mainloop() EXAMPLE 3: (OOP style) class App(tk.Tk): def __init__(self): tk.Tk.__init__(self) # something should happen here to justify using OOP # or here class AppFrame(tk.Frame): def __init__(self, master, **kw): tk.Frame.__init__(self, master, **kw) self.createWidgets() def createWidgets(self): b = tk.Button(master=None, text='Push Me') b.pack() if __name__ == '__main__': app = App() frame = AppFrame(app) frame.pack() app.mainloop() > Also, at what point do you include the destroy method in your > program, assuming you do not have a widget that will close the > window? If you only want the Windows "X" button to close the window, > then is it okay to leave out any call to destroy()? Yes. GUI destruction should (almost always) be controlled by the user. In certain circumstances you will want to force destruction, or intercept a users request for destruction so you can do something first (cleanup, sanity checks, etc...). > Or should always explicitly destroy it just as I explicitly created > a Tk instance? NO, you should create the root and then allow the user to decide when to destroy the GUI. Always remember the phrase: "User Driven Events" when coding a GUI! > If the latter, then where in the code do you put the call to destroy > so it won't conflict with the user closing the window with the X > button? In the "very special" cases where you need to destory the GUI, make sure no code can run AFTER you destroy the root window. Whoever wrote that example was obviously too lazy to run the code and check for errors or subtle bugs. From rantingrickjohnson at gmail.com Thu Mar 1 21:49:08 2012 From: rantingrickjohnson at gmail.com (Rick Johnson) Date: Thu, 1 Mar 2012 18:49:08 -0800 (PST) Subject: Is it necessary to call Tk() when writing a GUI app with Tkinter? References: <27603449.17.1330492001624.JavaMail.geo-discussion-forums@vbbfv2> <6e1c521e-14be-4ec0-9ff0-7f23fd9cd3dc@f14g2000yqe.googlegroups.com> Message-ID: <3d0bf288-fa5d-48e5-9529-db92d420a915@1g2000yqv.googlegroups.com> On Feb 29, 11:24?pm, Terry Reedy wrote: > On 2/29/2012 10:22 PM, Rick Johnson wrote: > > PS: I would highly suggest against using the "from Tkinter import *". > > Instead, use "import Tkinter as tk" and prefix all module contents > > with "tk.". > > I have changed the example to do that. I also showed the alternate to > initialize a widget. Here is the current version, tested on Windows 3.2.2. > > import tkinter as tk > > class Application(tk.Frame): > ? ? ?def __init__(self, master=None): > ? ? ? ? ?tk.Frame.__init__(self, master) > ? ? ? ? ?self.pack() With all due respect, I would also recommend against "self packing" a widget. And i can speak from experience on this issue. There was a time when i was self-packing lots of custom compund widgets; then i realized later the shortcomings of such action; what if you need to use the grid or place geometry mangers instead? So remove the self.pack line and add a line to the bottom: > root = tk.Tk() > app = Application(master=root) > app.pack() # <-- added this line > app.mainloop() > There is a minor problem left. The hi_there Button text has underscores > because if I use spaces instead, tk surrounds the text with {bra ces}. > This seems bizarre. Is there any way to have Button text with spaces and > no braces? Not sure what is happening on your end, but i don't see any braces. In any event, here is a slightly modified version of your code that follows PEP8 and removes some inconsistencies. ## START CODE ## # Python < 3.0 import Tkinter as tk from Tkconstants import TOP, BOTTOM from tkMessageBox import showinfo class Application(tk.Frame): def __init__(self, master=None): tk.Frame.__init__(self, master) self.createWidgets() def createWidgets(self): self.hi_there = tk.Button(self) self.hi_there["text"] = "Hello_World\n(click_me)" self.hi_there["command"] = self.say_hi self.hi_there.pack() # !!! self.qbutton = tk.Button(self, text="Close Application", fg="red", command=root.destroy) self.qbutton.pack() # !!! def say_hi(self): showinfo('Modal Dialog', "hi there, everyone!", parent=self) print("hi there, everyone!") if __name__ == '__main__': root = tk.Tk() app = Application(master=root) app.pack() app.mainloop() ## END CODE ## From rantingrickjohnson at gmail.com Thu Mar 1 21:53:12 2012 From: rantingrickjohnson at gmail.com (Rick Johnson) Date: Thu, 1 Mar 2012 18:53:12 -0800 (PST) Subject: Is it necessary to call Tk() when writing a GUI app with Tkinter? References: <27603449.17.1330492001624.JavaMail.geo-discussion-forums@vbbfv2> <6e1c521e-14be-4ec0-9ff0-7f23fd9cd3dc@f14g2000yqe.googlegroups.com> <22943242.772.1330580414345.JavaMail.geo-discussion-forums@ynil17> Message-ID: On Feb 29, 11:40?pm, John Salerno wrote: > The faulty code is not my own, which is part of the reason I asked > the question. The book I'm reading (The Quick Python Book) does not > use it, but I saw in the Python docs that it is there, under > "tkinter" in the Global Module Docs, "24.1.2.2. A Simple Hello World > Program": Book authors and Doc authors are not always the most well informed; as we have witnessed by this very thread! > from tkinter import * don't do that! > class Application(Frame): > ? ? def say_hi(self): > ? ? ? ? print("hi there, everyone!") > > ? ? def createWidgets(self): > ? ? ? ? self.QUIT = Button(self) > ? ? ? ? self.QUIT["text"] = "QUIT" > ? ? ? ? self.QUIT["fg"] = "red" > ? ? ? ? self.QUIT["command"] = self.quit > > ? ? ? ? self.QUIT.pack({"side": "left"}) don't do that either! Widgets take optional keyword arguments now so stop passing in dictionaries. self.quit.pack(side=tk.LEFT) Obviously these tutorials are more like: "What NOT to do when coding Tkinter GUIs!" No wonder everyone hates Tkinter. :-) From rantingrickjohnson at gmail.com Thu Mar 1 21:55:18 2012 From: rantingrickjohnson at gmail.com (Rick Johnson) Date: Thu, 1 Mar 2012 18:55:18 -0800 (PST) Subject: Is it necessary to call Tk() when writing a GUI app with Tkinter? References: <27603449.17.1330492001624.JavaMail.geo-discussion-forums@vbbfv2> <6e1c521e-14be-4ec0-9ff0-7f23fd9cd3dc@f14g2000yqe.googlegroups.com> <17153317.324.1330576905540.JavaMail.geo-discussion-forums@yncd8> <18841978.1037.1330580728432.JavaMail.geo-discussion-forums@vbgu10> <28139175.898.1330582481406.JavaMail.geo-discussion-forums@ynbo36> Message-ID: On Mar 1, 12:14?am, John Salerno wrote: > > What exactly is the purpose of doing that? Does Tk do some extra work that a simple call to Frame won't do? > > More specifically, what is the benefit of doing: > > root = tk.Tk() > app = Application(master=root) > app.mainloop() > > as opposed to: > > app = Application() > app.mainloop() > > Also, in the first example, what is the difference between calling app.mainloop() and root.mainloop()? They both seemed to work when I ran them. I tell you what. Just keep coding Tkinter GUIs like these broken docs tell you to, than after you become proficient you will understand. You will say: "That Rick really knew what he was talking about after all!" From rantingrickjohnson at gmail.com Thu Mar 1 22:02:37 2012 From: rantingrickjohnson at gmail.com (Rick Johnson) Date: Thu, 1 Mar 2012 19:02:37 -0800 (PST) Subject: Is it necessary to call Tk() when writing a GUI app with Tkinter? References: <27603449.17.1330492001624.JavaMail.geo-discussion-forums@vbbfv2> <6e1c521e-14be-4ec0-9ff0-7f23fd9cd3dc@f14g2000yqe.googlegroups.com> <3d0bf288-fa5d-48e5-9529-db92d420a915@1g2000yqv.googlegroups.com> Message-ID: On Mar 1, 8:49?pm, Rick Johnson wrote: > On Feb 29, 11:24?pm, Terry Reedy wrote: > > > On 2/29/2012 10:22 PM, Rick Johnson wrote: > > > PS: I would highly suggest against using the "from Tkinter import *". > > > Instead, use "import Tkinter as tk" and prefix all module contents > > > with "tk.". > > > I have changed the example to do that. I also showed the alternate to > > initialize a widget. Here is the current version, tested on Windows 3.2.2. > > > import tkinter as tk > > > class Application(tk.Frame): > > ? ? ?def __init__(self, master=None): > > ? ? ? ? ?tk.Frame.__init__(self, master) > > ? ? ? ? ?self.pack() > > With all due respect, I would also recommend against "self packing" a > widget. And i can speak from experience on this issue. There was a > time when i was self-packing lots of custom compund widgets; then i > realized later the shortcomings of such action; what if you need to > use the grid or place geometry mangers instead? So remove the > self.pack line and add a line to the bottom: > > > root = tk.Tk() > > app = Application(master=root) > > app.pack() # <-- added this line > > app.mainloop() > > There is a minor problem left. The hi_there Button text has underscores > > because if I use spaces instead, tk surrounds the text with {bra ces}. > > This seems bizarre. Is there any way to have Button text with spaces and > > no braces? > > Not sure what is happening on your end, but i don't see any braces. In > any event, here is a slightly modified version of your code that > follows PEP8 and removes some inconsistencies. > > ## START CODE ## > # Python < 3.0 > import Tkinter as tk > from Tkconstants import TOP, BOTTOM > from tkMessageBox import showinfo > > class Application(tk.Frame): > ? ? ?def __init__(self, master=None): > ? ? ? ? ?tk.Frame.__init__(self, master) > ? ? ? ? ?self.createWidgets() > > ? ? ?def createWidgets(self): > ? ? ? ? ?self.hi_there = tk.Button(self) > ? ? ? ? ?self.hi_there["text"] = "Hello_World\n(click_me)" > ? ? ? ? ?self.hi_there["command"] = self.say_hi > ? ? ? ? ?self.hi_there.pack() # !!! > ? ? ? ? ?self.qbutton = tk.Button(self, text="Close Application", > ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? fg="red", command=root.destroy) > ? ? ? ? ?self.qbutton.pack() # !!! > > ? ? ?def say_hi(self): > ? ? ? ? ?showinfo('Modal Dialog', "hi there, everyone!", parent=self) > ? ? ? ? ?print("hi there, everyone!") > > if __name__ == '__main__': > ? ? root = tk.Tk() > ? ? app = Application(master=root) > ? ? app.pack() > ? ? app.mainloop() > ## END CODE ## Opps, i just realized that "App" is actually a Tkinter.Frame and not a Tkinter.Toplevel. So the line: showinfo('Modal Dialog', "hi there, everyone!", parent=self) ...is broken. Since we don't have a reference to the root window from inside the scope of this Frame class, we can use "self.winfo_toplevel()" to fetch a reference. showinfo('Modal Dialog', "hi there, everyone!", parent=self.winfo_toplevel()) ...ahhh! That should work perfectly now! From johnjsal at gmail.com Thu Mar 1 22:15:21 2012 From: johnjsal at gmail.com (John Salerno) Date: Thu, 1 Mar 2012 19:15:21 -0800 (PST) Subject: Is it necessary to call Tk() when writing a GUI app with Tkinter? In-Reply-To: References: <27603449.17.1330492001624.JavaMail.geo-discussion-forums@vbbfv2> <6e1c521e-14be-4ec0-9ff0-7f23fd9cd3dc@f14g2000yqe.googlegroups.com> <17153317.324.1330576905540.JavaMail.geo-discussion-forums@yncd8> Message-ID: <6008330.241.1330658121340.JavaMail.geo-discussion-forums@ynlt17> > EXAMPLE 1: (this works, but is flawed!) > root = tk.Tk() > b = tk.Button(master=None, text='Sloppy Coder') > b.pack() > root.mainloop() > > EXAMPLE 2: (This is how to write code!) > root = tk.Tk() > widgetframe = tk.Frame(root) > b = tk.Button(master=None, text='Sloppy Coder') > b.pack() > root.mainloop() > > EXAMPLE 3: (OOP style) > class App(tk.Tk): > def __init__(self): > tk.Tk.__init__(self) > # something should happen here to justify using OOP > # or here > > class AppFrame(tk.Frame): > def __init__(self, master, **kw): > tk.Frame.__init__(self, master, **kw) > self.createWidgets() > > def createWidgets(self): > b = tk.Button(master=None, text='Push Me') > b.pack() > > if __name__ == '__main__': > app = App() > frame = AppFrame(app) > frame.pack() > app.mainloop() Why is the master argument for Button set to None? Shouldn't it be the Frame object? And shouldn't it also have self as the first argument? From rantingrickjohnson at gmail.com Thu Mar 1 22:19:55 2012 From: rantingrickjohnson at gmail.com (Rick Johnson) Date: Thu, 1 Mar 2012 19:19:55 -0800 (PST) Subject: Is it necessary to call Tk() when writing a GUI app with Tkinter? References: <27603449.17.1330492001624.JavaMail.geo-discussion-forums@vbbfv2> <6e1c521e-14be-4ec0-9ff0-7f23fd9cd3dc@f14g2000yqe.googlegroups.com> <17153317.324.1330576905540.JavaMail.geo-discussion-forums@yncd8> <6008330.241.1330658121340.JavaMail.geo-discussion-forums@ynlt17> Message-ID: <4eb739df-c642-4bbf-a155-9ed150e3acaf@s13g2000yqe.googlegroups.com> On Mar 1, 9:15?pm, John Salerno wrote: > > EXAMPLE 1: (this works, but is flawed!) > > ?root = tk.Tk() > > ?b = tk.Button(master=None, text='Sloppy Coder') > > ?b.pack() > > ?root.mainloop() > > > EXAMPLE 2: (This is how to write code!) > > ?root = tk.Tk() > > ?widgetframe = tk.Frame(root) > > ?b = tk.Button(master=None, text='Sloppy Coder') > > ?b.pack() > > ?root.mainloop() > > > EXAMPLE 3: (OOP style) > > ?class App(tk.Tk): > > ? ? ?def __init__(self): > > ? ? ? ? ?tk.Tk.__init__(self) > > ? ? ? ? ?# something should happen here to justify using OOP > > ? ? ?# or here > > > ?class AppFrame(tk.Frame): > > ? ? ?def __init__(self, master, **kw): > > ? ? ? ? ?tk.Frame.__init__(self, master, **kw) > > ? ? ? ? ?self.createWidgets() > > > ? ? ?def createWidgets(self): > > ? ? ? ? ?b = tk.Button(master=None, text='Push Me') > > ? ? ? ? ?b.pack() > > > ?if __name__ == '__main__': > > ? ? ?app = App() > > ? ? ?frame = AppFrame(app) > > ? ? ?frame.pack() > > ? ? ?app.mainloop() > > Why is the master argument for Button set to None? Shouldn't it be the Frame object? And shouldn't it also have self as the first argument? Hmm, it seems as though i am the latest victim of the "copy/paste error"! Oh well, if you were going to absorb my teachings, you would have absorbed them by now. I am moving on unless a new subject needs explaining. From tjreedy at udel.edu Thu Mar 1 22:43:22 2012 From: tjreedy at udel.edu (Terry Reedy) Date: Thu, 01 Mar 2012 22:43:22 -0500 Subject: Is it necessary to call Tk() when writing a GUI app with Tkinter? In-Reply-To: <3d0bf288-fa5d-48e5-9529-db92d420a915@1g2000yqv.googlegroups.com> References: <27603449.17.1330492001624.JavaMail.geo-discussion-forums@vbbfv2> <6e1c521e-14be-4ec0-9ff0-7f23fd9cd3dc@f14g2000yqe.googlegroups.com> <3d0bf288-fa5d-48e5-9529-db92d420a915@1g2000yqv.googlegroups.com> Message-ID: On 3/1/2012 9:49 PM, Rick Johnson wrote: > On Feb 29, 11:24 pm, Terry Reedy wrote: >> There is a minor problem left. The hi_there Button text has underscores >> because if I use spaces instead, tk surrounds the text with {bra ces}. >> This seems bizarre. Is there any way to have Button text with spaces and >> no braces? > > Not sure what is happening on your end, but i don't see any braces. Are you saying that if you change "Hello_World\n(click_me)" to "Hello World\n(click me)", you see Hello World (click me) as I expected, instead of {Hellow World (click me)} as I do see? What OS are you running? And what tk version? (I have 8.5.9 in Win7) -- Terry Jan Reedy From alec.taylor6 at gmail.com Thu Mar 1 23:55:38 2012 From: alec.taylor6 at gmail.com (Alec Taylor) Date: Fri, 2 Mar 2012 15:55:38 +1100 Subject: Spacing and timing for comparing algorithms and data-structures Message-ID: What would you recommend I use to compare data-structures and algorithms on space and time? (runtime) Thanks for all suggestions, Alec Taylor From cs at zip.com.au Fri Mar 2 00:15:47 2012 From: cs at zip.com.au (Cameron Simpson) Date: Fri, 2 Mar 2012 16:15:47 +1100 Subject: this afternoon's duck typing exercise ... Message-ID: <20120302051547.GA26249@cskk.homeip.net> Sorry, little technical content here, just a newly hatched programmer: duck typing, an intro http://www.flickr.com/photos/cskk/6799351990/in/photostream/ duck typing, resting after the demo http://www.flickr.com/photos/cskk/6945461405/in/photostream/ Cheers, -- Cameron Simpson DoD#743 http://www.cskk.ezoshosting.com/cs/ There is hopeful symbolism in the fact that flags do not wave in a vacuum. - Arthur C. Clarke From johnjsal at gmail.com Fri Mar 2 00:22:55 2012 From: johnjsal at gmail.com (John Salerno) Date: Thu, 1 Mar 2012 21:22:55 -0800 (PST) Subject: Is it necessary to call Tk() when writing a GUI app with Tkinter? In-Reply-To: <4eb739df-c642-4bbf-a155-9ed150e3acaf@s13g2000yqe.googlegroups.com> References: <27603449.17.1330492001624.JavaMail.geo-discussion-forums@vbbfv2> <6e1c521e-14be-4ec0-9ff0-7f23fd9cd3dc@f14g2000yqe.googlegroups.com> <17153317.324.1330576905540.JavaMail.geo-discussion-forums@yncd8> <6008330.241.1330658121340.JavaMail.geo-discussion-forums@ynlt17> <4eb739df-c642-4bbf-a155-9ed150e3acaf@s13g2000yqe.googlegroups.com> Message-ID: <1510171.280.1330665781888.JavaMail.geo-discussion-forums@vbux23> > Hmm, it seems as though i am the latest victim of the "copy/paste > error"! Oh well, if you were going to absorb my teachings, you would > have absorbed them by now. I am moving on unless a new subject needs > explaining. Well, I've certainly absorbed your recommendation to always create the root explicitly, but you still haven't really explained WHY. Telling me that I will eventually find out as I become more proficient isn't very helpful. I like being explicit, so I will create the Tk option like you suggest (although I don't see the need to subclass it first), but I also like knowing WHY I do what I do, so it would help to have some reason why it's better to create the root explicitly rather than allow Tkinter to do it. From steve+comp.lang.python at pearwood.info Fri Mar 2 00:35:18 2012 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 02 Mar 2012 05:35:18 GMT Subject: this afternoon's duck typing exercise ... References: Message-ID: <4f505c16$0$29989$c3e8da3$5496439d@news.astraweb.com> On Fri, 02 Mar 2012 16:15:47 +1100, Cameron Simpson wrote: > Sorry, little technical content here, just a newly hatched programmer: > > duck typing, an intro > http://www.flickr.com/photos/cskk/6799351990/in/photostream/ I love it! Excellent! -- Steven From luke.leighton at gmail.com Fri Mar 2 00:42:13 2012 From: luke.leighton at gmail.com (lkcl) Date: Thu, 1 Mar 2012 21:42:13 -0800 (PST) Subject: GUIs - a modest proposal Message-ID: <5ba38955-0ae8-4471-8701-dbe358deb3d3@eb6g2000vbb.googlegroups.com> folks hi, apologies for picking this up so late - it's only when i find these things through random searches that i encounter the occasional post. At some point wayyyy in the distant past, g4b wrote: > On the subject of the gui discussion mentioned here last year, > which you get lead to if you read around in the pyjamas docs, > I have to admit, since I know both development types (gwt, wx, qt) > and (django, jquery), I have to state the fact, that pyjamas should > also consider bonding with native javascript library developments. ah. right. you're either referring to pyjampiler (in the pyjs world) or to a vunnderbarr hidden iframe trick (in the pyjd world) where the execution results of a random javascript function has to store its results in the iframe (in JSON format) in order for the python world to monitor it, pick it up, decode it and pretend that nothing weird happened. the former actually got taken to an extreme by a group who embedded the pyjs 0.5 compiler into their application environment, i keep forgetting what it's called. but yes, they just put an "@decorator" in front of functions in the django source code, automatic recompile server-side, absolutely superb approach. > I was just looking at pyquery, a python implementation of jquery, > which could easily backbone jquery itself on the python end. you _what_??? pyquery? bizarre! you mean this? http://pypi.python.org/pypi/pyquery > Now this is not pyjamas' task, but the pyjs compiler could be used, > so that jquery code could be written for both languages. with a bit of coordination between the projects? yes, quite likely. $ however isn't a valid python variable name. but i get the point. > Long story short: if you could write jquery in python which actually > compiles into jquery in javascript, and even runs on python itself, > you could deploy widgets natively from python in django, > and dont have to leave python to improve webapplications with its native strengths. oh i see what you mean - compiling into jquery. yes, that would take care of the $ problem. that actually wouldn't be too hard to do, either. it'd also make an extremely neat GSoC project. l. From clp2 at rebertia.com Fri Mar 2 00:44:05 2012 From: clp2 at rebertia.com (Chris Rebert) Date: Thu, 1 Mar 2012 21:44:05 -0800 Subject: Spacing and timing for comparing algorithms and data-structures In-Reply-To: References: Message-ID: On Thu, Mar 1, 2012 at 8:55 PM, Alec Taylor wrote: > What would you recommend I use to compare data-structures and > algorithms on space and time? (runtime) For the latter metric, one of the profiling modules: http://docs.python.org/library/debug.html I'd start with timeit and go from there: http://docs.python.org/library/timeit.html For the former metric, you can write your own memory use measurement utility function on top of: http://docs.python.org/library/sys.html#sys.getsizeof Or there is doubtless some Unix tool(s) you could use to get a more crude measure of the total memory used by the Python interpreter process. Cheers, Chris -- http://rebertia.com From johnjsal at gmail.com Fri Mar 2 01:00:21 2012 From: johnjsal at gmail.com (John Salerno) Date: Thu, 1 Mar 2012 22:00:21 -0800 (PST) Subject: Is this the proper way to use a class method? Message-ID: <4136337.363.1330668021961.JavaMail.geo-discussion-forums@ynjd19> This is purely for fun and learning, so I know there are probably better ways of creating a chess program. Right now I'm just curious about my specific question, but I'd love to hear any other advice as well. Basically, I'm wondering if I'm using the class method properly with the move method. The reason I did it this way is because every chess piece will obviously have its own move method, yet they will all need to mark the piece as moved, so I figure that's best written once in the superclass. This works, but doing it this way seems weird, since the point of a class method is that it can be called by the class itself, even before instances have been created. Yet the way I've implemented it, it is necessarily tied to being called on an instance. Is this wrong? Is there a better way to do what I'm doing with move? Also, do I need the @classmethod decorator? The book I'm reading says to use it (and @staticmethod), but the following code works without it. Thanks. class ChessPiece: def __init__(self, position, label, has_moved): try: self.position = (position[0], int(position[1])) except TypeError: self.position = position self.label = label self.has_moved = has_moved def move(cls, self): self.has_moved = True class Pawn(ChessPiece): def __init__(self, position=None, label=1, has_moved=False): super().__init__(position, label, has_moved) def move(self): super().move(self) self.position = (chr(ord(self.position[0]) + 1), self.position[1] + 1) From clp2 at rebertia.com Fri Mar 2 01:25:11 2012 From: clp2 at rebertia.com (Chris Rebert) Date: Thu, 1 Mar 2012 22:25:11 -0800 Subject: Is this the proper way to use a class method? In-Reply-To: <4136337.363.1330668021961.JavaMail.geo-discussion-forums@ynjd19> References: <4136337.363.1330668021961.JavaMail.geo-discussion-forums@ynjd19> Message-ID: On Thu, Mar 1, 2012 at 10:00 PM, John Salerno wrote: > This is purely for fun and learning, so I know there are probably better ways of creating a chess program. Right now I'm just curious about my specific question, but I'd love to hear any other advice as well. > > Basically, I'm wondering if I'm using the class method properly with the move method. Unfortunately, no. > The reason I did it this way is because every chess piece will obviously have its own move method, yet they will all need to mark the piece as moved, so I figure that's best written once in the superclass. Right, but why not just a regular instance method? The method in question doesn't operate upon *the class itself* at all (which is the raison d'etre of classmethods); it instead operates upon an instance. A staticmethod would be slightly less weird, but really, it should just be an instance method. > This works, but doing it this way seems weird, since the point of a class method is that it can be called by the class itself, even before instances have been created. Yet the way I've implemented it, it is necessarily tied to being called on an instance. Is this wrong? Is there a better way to do what I'm doing with move? Just make it a normal instance method (i.e. remove the `cls` argument). > Also, do I need the @classmethod decorator? The book I'm reading says to use it (and @staticmethod), but the following code works without it. That's just a coincidence. Your supercall is ought to be: super().move() In contrast, super().move(self) calls the superclass instance method `move` with 2 arguments, both `self`, which just happens to work given your move() method, inside which `cls` isn't actually a class like it ought to be. > class ChessPiece: > > ? ?def __init__(self, position, label, has_moved): > ? ? ? ?try: > ? ? ? ? ? ?self.position = (position[0], int(position[1])) > ? ? ? ?except TypeError: > ? ? ? ? ? ?self.position = position > ? ? ? ?self.label = label > ? ? ? ?self.has_moved = has_moved > > ? ?def move(cls, self): > ? ? ? ?self.has_moved = True > > > class Pawn(ChessPiece): > > ? ?def __init__(self, position=None, label=1, has_moved=False): > ? ? ? ?super().__init__(position, label, has_moved) > > ? ?def move(self): > ? ? ? ?super().move(self) > ? ? ? ?self.position = (chr(ord(self.position[0]) + 1), self.position[1] + 1) Cheers, Chris From rosuav at gmail.com Fri Mar 2 01:41:22 2012 From: rosuav at gmail.com (Chris Angelico) Date: Fri, 2 Mar 2012 17:41:22 +1100 Subject: this afternoon's duck typing exercise ... In-Reply-To: <20120302051547.GA26249@cskk.homeip.net> References: <20120302051547.GA26249@cskk.homeip.net> Message-ID: On Fri, Mar 2, 2012 at 4:15 PM, Cameron Simpson wrote: > Sorry, little technical content here, just a newly hatched programmer: > > ?duck typing, an intro > ?http://www.flickr.com/photos/cskk/6799351990/in/photostream/ > > ?duck typing, resting after the demo > ?http://www.flickr.com/photos/cskk/6945461405/in/photostream/ You may want to keep that away from your friendly local python, it might not survive the integration. Excellent non-technical explanation of a highly technical topic. ChrisA From rosuav at gmail.com Fri Mar 2 02:11:29 2012 From: rosuav at gmail.com (Chris Angelico) Date: Fri, 2 Mar 2012 18:11:29 +1100 Subject: lang comparison: in-place algorithm for reversing a list in Perl,Python, Lisp In-Reply-To: <8e769add-e63c-4a74-bb7e-ddd36c04a415@vs5g2000pbc.googlegroups.com> References: <85fa5760-68c8-41a2-9116-2489165f7ca1@j5g2000yqm.googlegroups.com> <20120229231658.89@kylheku.com> <20120301064937.505@kylheku.com> <8e769add-e63c-4a74-bb7e-ddd36c04a415@vs5g2000pbc.googlegroups.com> Message-ID: On Fri, Mar 2, 2012 at 9:04 AM, Xah Lee wrote: > One easy > way to measure it is whether a programer can read and understand a > program without having to delve into its idiosyncrasies. Neither the behavior of ints nor the behavior of IEEE floating point is a "quirk" or an "idiosyncracy". These are data types with well-defined semantics, and you need to understand them to use them. The fact that dividing two positive integers and producing (or casting to) a third integer rounds the result down is just as much a part of the definition as is two's complement negatives, which most people can safely ignore because they "just work" the way you expect. Learn what you're working with, if you expect to get decent results from it. ChrisA From johnjsal at gmail.com Fri Mar 2 02:16:54 2012 From: johnjsal at gmail.com (John Salerno) Date: Thu, 1 Mar 2012 23:16:54 -0800 (PST) Subject: Is this the proper way to use a class method? In-Reply-To: References: <4136337.363.1330668021961.JavaMail.geo-discussion-forums@ynjd19> Message-ID: <21646224.4.1330672614560.JavaMail.geo-discussion-forums@ynt13> > That's just a coincidence. Your supercall is ought to be: super().move() > In contrast, super().move(self) calls the superclass instance method > `move` with 2 arguments, both `self`, which just happens to work given > your move() method, inside which `cls` isn't actually a class like it > ought to be. Thank you! This is the whole reason I tried using a class method in the first place. I was getting an error that said my move method only takes one argument, but I was passing in two. But if I make the super call as super().move(), how does that work? The move method in the superclass takes an argument, and if I just do super().move(), isn't it the subclass that's getting passed to it? How does the superclass move method know what 'self' is if it doesn't get passed to it as I did originally? From johnjsal at gmail.com Fri Mar 2 02:16:54 2012 From: johnjsal at gmail.com (John Salerno) Date: Thu, 1 Mar 2012 23:16:54 -0800 (PST) Subject: Is this the proper way to use a class method? In-Reply-To: References: <4136337.363.1330668021961.JavaMail.geo-discussion-forums@ynjd19> Message-ID: <21646224.4.1330672614560.JavaMail.geo-discussion-forums@ynt13> > That's just a coincidence. Your supercall is ought to be: super().move() > In contrast, super().move(self) calls the superclass instance method > `move` with 2 arguments, both `self`, which just happens to work given > your move() method, inside which `cls` isn't actually a class like it > ought to be. Thank you! This is the whole reason I tried using a class method in the first place. I was getting an error that said my move method only takes one argument, but I was passing in two. But if I make the super call as super().move(), how does that work? The move method in the superclass takes an argument, and if I just do super().move(), isn't it the subclass that's getting passed to it? How does the superclass move method know what 'self' is if it doesn't get passed to it as I did originally? From w_a_x_man at yahoo.com Fri Mar 2 02:17:34 2012 From: w_a_x_man at yahoo.com (WJ) Date: 2 Mar 2012 07:17:34 GMT Subject: lang comparison: in-place algorithm for reversing a list in Perl, Python, Lisp References: <85fa5760-68c8-41a2-9116-2489165f7ca1@j5g2000yqm.googlegroups.com> Message-ID: Xah Lee wrote: > fun example. > > in-place algorithm for reversing a list in Perl, Python, Lisp > http://xahlee.org/comp/in-place_algorithm.html > > plain text follows > ---------------------------------------- > > What's ?In-place Algorithm?? > > Xah Lee, 2012-02-29 > > This page tells you what's ?In-place algorithm?, using {python, perl, > emacs lisp} code to illustrate. > > Here's Wikipedia In-place algorithm excerpt: > > In computer science, an in-place algorithm (or in Latin in situ) is an > algorithm which transforms input using a data structure with a small, > constant amount of extra storage space. The input is usually > overwritten by the output as the algorithm executes. An algorithm > which is not in-place is sometimes called not-in-place or out-of- > place. > > Python > > Here's a python code for reversing a list. Done by creating a new > list, NOT using in-place: > > # python > # reverse a list > > list_a = ["a", "b", "c", "d", "e", "f", "g"] > > list_length = len(list_a) > list_b = [0] * list_length > > for i in range(list_length): > list_b[i] = list_a[list_length -1 - i] > > print list_b > Here's in-place algorithm for reversing a list: > > # python > # in-place algorithm for reversing a list > > list_a = ["a", "b", "c", "d", "e", "f", "g"] > > list_length = len(list_a) > > for i in range(list_length/2): > x = list_a[i] > list_a[i] = list_a[ list_length -1 - i] > list_a[ list_length -1 - i] = x > > print list_a > Perl > > Here's a perl code for reversing a list. Done by creating a new list, > NOT using in-place: > > # perl > > use strict; > use Data::Dumper; > > my @listA = qw(a b c d e f g); > > my $listLength = scalar @listA; > my @listB = (); > > for ( my $i = 0; $i < $listLength; $i++ ) { > $listB[$i] = $listA[ $listLength - 1 - $i]; > } > > print Dumper(\@listB); > > # perl > # in-place algorithm for reversing a list. > > use strict; > use Data::Dumper; > use POSIX; # for ?floor? > > my @listA = qw(a b c d e f g); > > my $listLength = scalar @listA; > > for ( my $i = 0; $i < floor($listLength/2); $i++ ) { > my $x = $listA[$i]; > $listA[$i] = $listA[ $listLength - 1 - $i]; > $listA[ $listLength - 1 - $i] = $x; > } > > print Dumper(\@listA); > __END__ > > emacs lisp > > ;; emacs lisp > ;; reverse a array > > (setq arrayA ["a" "b" "c" "d" "e" "f" "g"]) > > (setq arrayLength (length arrayA)) > > (setq arrayB (make-vector arrayLength 0)) > > (dotimes (i arrayLength ) > (aset arrayB i (aref arrayA (- (1- arrayLength) i)) ) > ) > > (print (format "%S" arrayB)) > ;; emacs lisp > ;; in-place algorithm for reversing a array > > (setq arrayA ["a" "b" "c" "d" "e" "f" "g"]) > > (setq arrayLength (length arrayA)) > > (dotimes (i (floor (/ arrayLength 2))) > (let (x) > (setq x (aref arrayA i)) > (aset arrayA i (aref arrayA (- (1- arrayLength) i))) > (aset arrayA (- (1- arrayLength) i) x) ) ) > > (print (format "%S" arrayA)) > > Xah NewLisp: > (setq lst '(2 3 5 8)) (2 3 5 8) > (reverse lst) (8 5 3 2) > lst (8 5 3 2) From __peter__ at web.de Fri Mar 2 02:26:13 2012 From: __peter__ at web.de (Peter Otten) Date: Fri, 02 Mar 2012 08:26:13 +0100 Subject: exec References: <4f4f7527$1@news.fhg.de> <4f4f9d55$1@news.fhg.de> Message-ID: Prasad, Ramit wrote: > Hi Peter, > > >>> class Magnitude(object): > > ... def __init__(self, value): > ... self.value = value > ... def __call__(self, uf=1): > ... if uf == 1: > ... return self > ... return self.value > ... > > >>> class Iron(object): > > ... def __init__(self): > ... self.rho = Magnitude(42) > ... > > > Why did you make uf=1 instead of None? > > ... def __call__(self, uf=None): > ... if uf is None: That's a design decision of the OP. I suggested an improvement of the implementation and left the interface alone. From chiron613 at gmail.com Fri Mar 2 02:27:58 2012 From: chiron613 at gmail.com (Chiron) Date: Fri, 02 Mar 2012 07:27:58 GMT Subject: New Science Discovery: Perl Idiots Remain Idiots After A Decade!New Science Discovery: Perl Idiots Remain Idiots After A Decade! References: <0078bbfb-5dfc-48fc-af1a-69de3cf15c3e@b1g2000yqb.googlegroups.com> Message-ID: <2E_3r.4452$HX7.1864@newsfe11.iad> On Wed, 29 Feb 2012 00:09:16 -0800, Xah Lee wrote: Xah, you won't grow even an inch taller by cutting others down. -- I joined scientology at a garage sale!! From ian.g.kelly at gmail.com Fri Mar 2 03:04:22 2012 From: ian.g.kelly at gmail.com (Ian Kelly) Date: Fri, 2 Mar 2012 01:04:22 -0700 Subject: Is this the proper way to use a class method? In-Reply-To: <21646224.4.1330672614560.JavaMail.geo-discussion-forums@ynt13> References: <4136337.363.1330668021961.JavaMail.geo-discussion-forums@ynjd19> <21646224.4.1330672614560.JavaMail.geo-discussion-forums@ynt13> Message-ID: On Fri, Mar 2, 2012 at 12:16 AM, John Salerno wrote: >> That's just a coincidence. Your supercall is ought to be: super().move() >> In contrast, super().move(self) calls the superclass instance method >> `move` with 2 arguments, both `self`, which just happens to work given >> your move() method, inside which `cls` isn't actually a class like it >> ought to be. > > Thank you! This is the whole reason I tried using a class method in the first place. I was getting an error that said my move method only takes one argument, but I was passing in two. > > But if I make the super call as super().move(), how does that work? The move method in the superclass takes an argument, and if I just do super().move(), isn't it the subclass that's getting passed to it? The self that gets passed into the superclass.move() or the subclass.move() is the exact same object in either case. There is no "up-casting" (or any casting at all, for that matter) in Python. > How does the superclass move method know what 'self' is if it doesn't get passed to it as I did originally? super() called without arguments is equivalent to super(, self) -- it collects the value of self from the current stack frame. So self is able to be passed in because the super object implicitly knows what self is. Cheers, Ian From clp2 at rebertia.com Fri Mar 2 03:08:17 2012 From: clp2 at rebertia.com (Chris Rebert) Date: Fri, 2 Mar 2012 00:08:17 -0800 Subject: Is this the proper way to use a class method? In-Reply-To: <21646224.4.1330672614560.JavaMail.geo-discussion-forums@ynt13> References: <4136337.363.1330668021961.JavaMail.geo-discussion-forums@ynjd19> <21646224.4.1330672614560.JavaMail.geo-discussion-forums@ynt13> Message-ID: On Thu, Mar 1, 2012 at 11:16 PM, John Salerno wrote: >> That's just a coincidence. Your supercall is ought to be: super().move() >> In contrast, super().move(self) calls the superclass instance method >> `move` with 2 arguments, both `self`, which just happens to work given >> your move() method, inside which `cls` isn't actually a class like it >> ought to be. > > Thank you! This is the whole reason I tried using a class method in the first place. I was getting an error that said my move method only takes one argument, but I was passing in two. > > But if I make the super call as super().move(), how does that work? The move method in the superclass takes an argument, and if I just do super().move(), isn't it the subclass that's getting passed to it? The instance of the subclass (i.e. what Pawn.move() considers `self`) gets passed to it. > How does the superclass move method know what 'self' is if it doesn't get passed to it as I did originally? Oh, but it does get passed, just implicitly. `super()` basically grabs `self` magically from its caller, and uses it to bind method calls on the magical object returned by `super()`. `super().move()` ends up being, in this particular case, equivalent to: ChessPiece.move(self) which is incidentally how one would write this without using super(). Here is a useful[1] "identity" to ponder: x.y(z) === type(x).y(x, z) Cheers, Chris -- [1]: In the sense of a useful lie[2]; it's far from completely accurate; it (at the least) ignores metaclasses, overridings of __getattribute__(), and a third thing that's difficult to clearly put into words. [2]: http://c2.com/cgi/wiki?UsefulLie [3] [3]: Yes, my footnotes have footnotes. http://rebertia.com From xahlee at gmail.com Fri Mar 2 06:30:29 2012 From: xahlee at gmail.com (Xah Lee) Date: Fri, 2 Mar 2012 03:30:29 -0800 (PST) Subject: lang comparison: in-place algorithm for reversing a list in Perl,Python, Lisp References: <85fa5760-68c8-41a2-9116-2489165f7ca1@j5g2000yqm.googlegroups.com> <20120229231658.89@kylheku.com> <20120301064937.505@kylheku.com> <8e769add-e63c-4a74-bb7e-ddd36c04a415@vs5g2000pbc.googlegroups.com> Message-ID: Xah Lee wrote: ?? One easy way to measure it is whether a programer can read and understand a program without having to delve into its idiosyncrasies. ?? Chris Angelico wrote: ?Neither the behavior of ints nor the behavior of IEEE floating point is a "quirk" or an "idiosyncracy". ?? they are computer engineering by-products. Are quirks and idiosyncracies. Check out a advanced lang such as Mathematica. There, one can learn how the mathematical concept of integer or real number are implemented in a computer language, without lots by-products of comp engineering as in vast majority of langs (all those that chalks up to some IEEEEEEE. (which, sadly, includes C, C++, java, perl, python, lisp, and almost all. (lisp idiots speak of the jargon ?number tower? instead IEEEE.) (part of the reason almost all langs stick to some IEEEEEEEE stuff is because it's kinda standard, and everyone understand it, in the sense that unix RFC (aka really fucking common) is wide-spread because its free yet technically worst. (in a sense, when everybody's stupid, there arise a cost to not be stupid.)))). Xah From xahlee at gmail.com Fri Mar 2 08:12:20 2012 From: xahlee at gmail.com (Xah Lee) Date: Fri, 2 Mar 2012 05:12:20 -0800 (PST) Subject: New Science Discovery: Perl Idiots Remain Idiots After A Decade!New Science Discovery: Perl Idiots Remain Idiots After A Decade! References: <0078bbfb-5dfc-48fc-af1a-69de3cf15c3e@b1g2000yqb.googlegroups.com> <4f4e1554$0$1385$4fafbaef@reader2.news.tin.it> <9dc55d52-3902-4449-87e7-745fb8b911b3@n12g2000yqb.googlegroups.com> <4f4f56c8$0$1381$4fafbaef@reader2.news.tin.it> Message-ID: On Mar 1, 3:00?am, Kiuhnm wrote: > They did not make up the terminology, if that is what you are saying. > The concepts of left and right associativity are well-known and accepted > in TCS (Theoretical CS). > Aho, Sethi and Ullman explain it this way in "Compilers: Principles, > Techniques and Tools": > "We say that the operator + associates to the left because an operand > with plus signs on both sides of it is taken by the operator to its > left. [...]" > And they also show parse trees similar to the ones I wrote above. how do they explain when 2 operators are adjacent e.g. ?3 ? 6 ? 5 ?? do you happen to know some site that shows the relevant page i can have a look? thanks. Xah On Mar 1, 3:00?am, Kiuhnm wrote: > On 3/1/2012 1:02, Xah Lee wrote: > > > i missed a point in my original post. That is, when the same operator > > are adjacent. e.g. ?3 ? 6 ? 5?. > > > This is pointed out by Kiuhnm ?kiuhnm03.4t.yahoo.it? and Tim Bradshaw. > > Thanks. > > > though, i disagree the way they expressed it, or any sense this is > > different from math. > > They did not make up the terminology, if that is what you are saying. > The concepts of left and right associativity are well-known and accepted > in TCS (Theoretical CS). > > If you change the terminology, no one will understand you unless you > provide your definitions every time (and then they may not accept them). > > Another way of saying that an operator is left-associative is that its > parse tree is a left-tree, i.e. a complete tree where each right child > is a leaf. > For instance, (use a monospaced font) > ? ?1 + 2 + 3 + 4 > gives you this left-tree: > ? ? ? ?+ > ? ? ?+ ? 4 > ? ?+ ? 3 > ? 1 2 > while 1**2**3**4 > gives you this right-tree: > ? ?** > 1 ? ?** > ? ? 2 ? ?** > ? ? ? ? 3 ?4 > > Aho, Sethi and Ullman explain it this way in "Compilers: Principles, > Techniques and Tools": > "We say that the operator + associates to the left because an operand > with plus signs on both sides of it is taken by the operator to its > left. [...]" > And they also show parse trees similar to the ones I wrote above. > > Kiuhnm From kiuhnm03.4t.yahoo.it Fri Mar 2 09:15:08 2012 From: kiuhnm03.4t.yahoo.it (Kiuhnm) Date: Fri, 02 Mar 2012 15:15:08 +0100 Subject: New Science Discovery: Perl Idiots Remain Idiots After A Decade!New Science Discovery: Perl Idiots Remain Idiots After A Decade! In-Reply-To: References: <0078bbfb-5dfc-48fc-af1a-69de3cf15c3e@b1g2000yqb.googlegroups.com> <4f4e1554$0$1385$4fafbaef@reader2.news.tin.it> <9dc55d52-3902-4449-87e7-745fb8b911b3@n12g2000yqb.googlegroups.com> <4f4f56c8$0$1381$4fafbaef@reader2.news.tin.it> Message-ID: <4f50d5ea$0$1383$4fafbaef@reader2.news.tin.it> On 3/2/2012 14:12, Xah Lee wrote: > On Mar 1, 3:00 am, Kiuhnm wrote: >> They did not make up the terminology, if that is what you are saying. >> The concepts of left and right associativity are well-known and accepted >> in TCS (Theoretical CS). > > >> Aho, Sethi and Ullman explain it this way in "Compilers: Principles, >> Techniques and Tools": >> "We say that the operator + associates to the left because an operand >> with plus signs on both sides of it is taken by the operator to its >> left. [...]" >> And they also show parse trees similar to the ones I wrote above. > > how do they explain when 2 operators are adjacent e.g. ?3 ? 6 ? 5 ?? The same way you do, I guess. An operand that has operators on both sides is operand of the operator of higher precedence. For instance, in 3 * 4 + 6 4 is operand of * but not of +. Indeed, the operands of + are 3*4 and 6. > do you happen to know some site that shows the relevant page i can > have a look? Nope, sorry. Kiuhnm From chiron613 at gmail.com Fri Mar 2 09:17:18 2012 From: chiron613 at gmail.com (Chiron) Date: Fri, 02 Mar 2012 14:17:18 GMT Subject: New Science Discovery: Perl Idiots Remain Idiots After A Decade!New Science Discovery: Perl Idiots Remain Idiots Af References: <0078bbfb-5dfc-48fc-af1a-69de3cf15c3e@b1g2000yqb.googlegroups.com> <87aa41k6x5.fsf@sapphire.mobileactivedefense.com> <4f4ef6c8$27$fuzhry+tra$mr2ice@news.patriot.net> <4f4f9207$39$fuzhry+tra$mr2ice@news.patriot.net> Message-ID: On Thu, 01 Mar 2012 10:13:11 -0500, Shmuel (Seymour J.) Metz wrote: > In , on 03/01/2012 > at 05:07 AM, Chiron said: > >>Hmm... maybe, instead of just ridiculing him, > > I'm treating him as he treats others. OK. > >>BTW, I happen to agree with you insofar as this poster not understanding >> the nature of mathematics. His comment reminds me of the article, >>"Transgressing the Boundaries: Towards a Transformative Hermeneutics of >>Quantum Gravity" > > A brilliant piece of work. I greatly enjoyed it and the reaction to its > disclosure. What always gets me is how so many people criticized Sokal for doing it, instead of soundly condemning the editor for not bothering to verify what Sokal said. It's like the kid points out that the emperor has no clothes, so they shoot the kid. Of course, in real life, that's exactly what would happen, so I guess I shouldn't be too surprised... -- It is a hard matter, my fellow citizens, to argue with the belly, since it has no ears. -- Marcus Porcius Cato From spamtrap at library.lspace.org.invalid Fri Mar 2 10:53:30 2012 From: spamtrap at library.lspace.org.invalid (Shmuel Metz (Seymour J.)) Date: Fri, 02 Mar 2012 10:53:30 -0500 Subject: New Science Discovery: Perl Detractors Remain Idiots After A Decade! References: <0078bbfb-5dfc-48fc-af1a-69de3cf15c3e@b1g2000yqb.googlegroups.com> <87aa41k6x5.fsf@sapphire.mobileactivedefense.com> <4f4ef6c8$27$fuzhry+tra$mr2ice@news.patriot.net> <4f4f9207$39$fuzhry+tra$mr2ice@news.patriot.net> Message-ID: <4f50ecfa$2$fuzhry+tra$mr2ice@news.patriot.net> In , on 03/02/2012 at 02:17 PM, Chiron said: >What always gets me is how so many people criticized Sokal for doing >it, Google for Omerta. It's common for whistle blowers to be chastised or even persecuted. I agree that the criticism of Prof Sokal was outrageous, but it was also predictable. -- Shmuel (Seymour J.) Metz, SysProg and JOAT Unsolicited bulk E-mail subject to legal action. I reserve the right to publicly post or ridicule any abusive E-mail. Reply to domain Patriot dot net user shmuel+news to contact me. Do not reply to spamtrap at library.lspace.org From mark at markroseman.com Fri Mar 2 12:57:34 2012 From: mark at markroseman.com (Mark Roseman) Date: Fri, 02 Mar 2012 10:57:34 -0700 Subject: Is it necessary to call Tk() when writing a GUI app with Tkinter? References: <27603449.17.1330492001624.JavaMail.geo-discussion-forums@vbbfv2> <6e1c521e-14be-4ec0-9ff0-7f23fd9cd3dc@f14g2000yqe.googlegroups.com> <22943242.772.1330580414345.JavaMail.geo-discussion-forums@ynil17> Message-ID: Rick Johnson wrote: > Book authors and Doc authors are not always the most well informed; as > we have witnessed by this very thread! Obviously these tutorials are more > like: "What NOT to do when coding Tkinter GUIs!" No wonder everyone hates Tkinter. :-) Indeed. One of the things that motivated me to write the tutorial at http://www.tkdocs.com is the rather poor state (in terms of being out of date, incorrect, or demonstrating poor practices) of most Tkinter documentation. Call it self-serving, but I think the Tkinter world would be a happier place if everyone just pointed to TkDocs. ;-) To your point about explicit root, etc. I'll make the general observation that lots of different things work in a given situation, which is just fine for quick little hacky things. If people are doing anything more than a throwaway however, they'd be better served by spending a bit of time learning the conceptual underpinnings (e.g. http://www.tkdocs.com/tutorial/concepts.html) after which the "right" thing to do will be more obvious. Mark From johnjsal at gmail.com Fri Mar 2 13:51:41 2012 From: johnjsal at gmail.com (John Salerno) Date: Fri, 2 Mar 2012 10:51:41 -0800 (PST) Subject: Is this the proper way to use a class method? In-Reply-To: References: <4136337.363.1330668021961.JavaMail.geo-discussion-forums@ynjd19> <21646224.4.1330672614560.JavaMail.geo-discussion-forums@ynt13> Message-ID: <18263375.25.1330714301799.JavaMail.geo-discussion-forums@vbdj6> > Oh, but it does get passed, just implicitly. `super()` basically grabs > `self` magically from its caller, and uses it to bind method calls on > the magical object returned by `super()`. Thanks again, now I understand :) From johnjsal at gmail.com Fri Mar 2 13:51:41 2012 From: johnjsal at gmail.com (John Salerno) Date: Fri, 2 Mar 2012 10:51:41 -0800 (PST) Subject: Is this the proper way to use a class method? In-Reply-To: References: <4136337.363.1330668021961.JavaMail.geo-discussion-forums@ynjd19> <21646224.4.1330672614560.JavaMail.geo-discussion-forums@ynt13> Message-ID: <18263375.25.1330714301799.JavaMail.geo-discussion-forums@vbdj6> > Oh, but it does get passed, just implicitly. `super()` basically grabs > `self` magically from its caller, and uses it to bind method calls on > the magical object returned by `super()`. Thanks again, now I understand :) From spdollyshikha4 at gmail.com Fri Mar 2 13:52:42 2012 From: spdollyshikha4 at gmail.com (shikha panghal) Date: Sat, 3 Mar 2012 00:22:42 +0530 Subject: decompilation Message-ID: Hi Please decoplile the .pyc code ,as i have lost my .py code. Thanks, Shikha -------------- next part -------------- An HTML attachment was scrubbed... URL: -------------- next part -------------- A non-text attachment was scrubbed... Name: hangman322.pyc Type: application/octet-stream Size: 6605 bytes Desc: not available URL: From johnjsal at gmail.com Fri Mar 2 13:53:58 2012 From: johnjsal at gmail.com (John Salerno) Date: Fri, 2 Mar 2012 10:53:58 -0800 (PST) Subject: Is it necessary to call Tk() when writing a GUI app with Tkinter? In-Reply-To: References: <27603449.17.1330492001624.JavaMail.geo-discussion-forums@vbbfv2> <6e1c521e-14be-4ec0-9ff0-7f23fd9cd3dc@f14g2000yqe.googlegroups.com> <22943242.772.1330580414345.JavaMail.geo-discussion-forums@ynil17> Message-ID: <14334956.332.1330714438657.JavaMail.geo-discussion-forums@vbux23> > Indeed. One of the things that motivated me to write the tutorial at > http://www.tkdocs.com is the rather poor state (in terms of being out of > date, incorrect, or demonstrating poor practices) of most Tkinter > documentation. > > Call it self-serving, but I think the Tkinter world would be a happier > place if everyone just pointed to TkDocs. ;-) > > To your point about explicit root, etc. I'll make the general > observation that lots of different things work in a given situation, > which is just fine for quick little hacky things. If people are doing > anything more than a throwaway however, they'd be better served by > spending a bit of time learning the conceptual underpinnings (e.g. > http://www.tkdocs.com/tutorial/concepts.html) after which the "right" > thing to do will be more obvious. > > Mark Nice. I shall be spending some time at your website. I actually like wxPython, but I decided to learn a little Tkinter because it's already included and would be an easier and quicker option for small interfaces. From chiron613 at gmail.com Fri Mar 2 14:06:06 2012 From: chiron613 at gmail.com (Chiron) Date: Fri, 02 Mar 2012 19:06:06 GMT Subject: New Science Discovery: Perl Detractors Remain Idiots After A Decade! References: <0078bbfb-5dfc-48fc-af1a-69de3cf15c3e@b1g2000yqb.googlegroups.com> <87aa41k6x5.fsf@sapphire.mobileactivedefense.com> <4f4ef6c8$27$fuzhry+tra$mr2ice@news.patriot.net> <4f4f9207$39$fuzhry+tra$mr2ice@news.patriot.net> <4f50ecfa$2$fuzhry+tra$mr2ice@news.patriot.net> Message-ID: On Fri, 02 Mar 2012 10:53:30 -0500, Shmuel (Seymour J.) Metz wrote: > In , on 03/02/2012 > at 02:17 PM, Chiron said: > >>What always gets me is how so many people criticized Sokal for doing it, > > Google for Omerta. It's common for whistle blowers to be chastised or > even persecuted. I agree that the criticism of Prof Sokal was > outrageous, but it was also predictable. Yeah, omerta... I'm familiar with it. Talk and you're dead, and they put a canary in your mouth (well, some folks do, anyway). But of course you're right - it's a milder form of omerta. It's just so misguided. Kill the messenger. Imprison the whistle-blower. -- Imitation is the sincerest form of plagiarism. From scavanau at cisco.com Fri Mar 2 15:09:16 2012 From: scavanau at cisco.com (Sean Cavanaugh (scavanau)) Date: Fri, 2 Mar 2012 12:09:16 -0800 Subject: Python - CGI-BIN - Apache Timeout Problem Message-ID: <6FC169072CBFF3409B6E74F50175A4650497A3F9@xmb-sjc-215.amer.cisco.com> Hello List, Would appreciate some insight/help, ran out of ideas... BRIEF OVERVIEW: I am trying to create a simple webserver gui wrapper for a set of scripts I developed to test some of our firewalls here at Cisco. Being that the total amount of engineer that will ever probably use this is 4 people and my limited python experience I just decided to do a quick cgi-bin solution. I control the machine with the webserver on em0 where I do my fw testing on em1/em2. Browser goes to http://webserver/main.py -> main.py executes a script->tests.py ->test.py imports my engine v6tester_main.py which is a series of functions I wrote. tests.py kicks of whatever test main.py wanted. THE PROBLEM: When I execute the scripts from the command line (#python main.py) it generates it fine (albeit slowly), it prints all the html code out including the script. The 'core' part of the script dumbed down to the lowest level is-> proc = subprocess.Popen(['/usr/local/bin/python', 'tests.py'], stdout=subprocess.PIPE) output = proc.stdout.read() print output proc.stdout.close() When I open main.py and execute the script it just hangs... it seems to execute the script (I see pcap fires on the interface that I am testing on the firewall) but its not executing correctly... or loading the entire webpage...the webpage keeps chugging along and eventually gives me an error timeout. I know it's not a permissions issue or setup issue b/c I did a proof of concept where I just fired one simple pcap and it works fine (reported back just like it would if I ran it on the command line).. it has something to do with either the amount of prints out the script is doing, or the timing. I see no problems except the timeout (nothing in logs: /var/log/http-error.log). My script takes about 8 secounds to run. It does use threading but I wouldn't think that would mess it up. BTW: I posted here if this helps anyone: http://stackoverflow.com/questions/9524758/cgi-bin-timing-timeout-on-fre ebsd-apache22 Thanks in advance for any ideas. I can include the whole main.py if that would help. ============================ Sean Cavanaugh Cisco Systems -------------- next part -------------- An HTML attachment was scrubbed... URL: From clp2 at rebertia.com Fri Mar 2 15:11:12 2012 From: clp2 at rebertia.com (Chris Rebert) Date: Fri, 2 Mar 2012 12:11:12 -0800 Subject: decompilation In-Reply-To: References: Message-ID: On Fri, Mar 2, 2012 at 10:52 AM, shikha panghal wrote: > Hi > > Please decoplile the .pyc code ,as i have lost my .py code. Your best shot would be: http://www.crazy-compilers.com/decompyle/ Cheers, Chris From arnodel at gmail.com Fri Mar 2 15:18:56 2012 From: arnodel at gmail.com (Arnaud Delobelle) Date: Fri, 2 Mar 2012 20:18:56 +0000 Subject: decompilation In-Reply-To: References: Message-ID: On 2 March 2012 18:52, shikha panghal wrote: > Hi > > Please decoplile the .pyc code ,as i have lost my .py code. Aha, a customer! I've written a module for this: unpyc3 (http://code.google.com/p/unpyc3/) Here it is in action: Python 3.2.1 (v3.2.1:ac1f7e5c0510, Jul 9 2011, 01:03:53) [GCC 4.2.1 (Apple Inc. build 5666) (dot 3)] on darwin Type "help", "copyright", "credits" or "license" for more information. >>> import unpyc3 >>> import hangman322 >>> code = unpyc3.decompile(hangman322) >>> print(code) import random def readFile(fileName): file = open(fileName) lineList = file.readlines() file.close() return lineList def initialize(fileName): try: lineList = readFile(fileName) except: print('Oops! ' + filename + ' was not a valid file.') return len_d = len(lineList) word_length = [0]*len_d for i in range(len_d): if lineList[i][-1] == '\n': word_length[i] = len(lineList[i]) - 1 else: word_length[i] = len(lineList[i]) tabulate = [0]*25 for i in range(len_d): if word_length[i] >= 24: tabulate[24] = tabulate[24] + 1 else: tabulate[word_length[i]] = tabulate[word_length[i]] + 1 words = [None]*25 for i in range(2, 24): words[i] = [None]*tabulate[i] k = 0 for j in range(len_d): if word_length[j] == i: words[i][k] = lineList[j] k = k + 1 for i in range(24, 25): words[i] = [None]*tabulate[i] k = 0 for j in range(len_d): if word_length[j] >= i: words[i][k] = lineList[j] k = k + 1 return words def wordsOfLength(n, source_file): words = initialize(source_file) return words[n] def getUserStringInput(L, prompt): replyInList = False while not replyInList: reply = input(prompt) replyInList = reply in L if not replyInList: print('That reply is invalid. Try again.') return reply def intListToStringList(L): L2 = ['']*len(L) for i in range(len(L)): L2[i] = str(L[i]) return L2 def getNewLetterGuess(availableLetters): letterString = '' for j in range(26): if availableLetters[j]: letterString = letterString + chr(65 + j) + ' ' else: letterString = letterString + ' ' validChar = False print(letterString) while not validChar: reply = input('Guess! > ') if len(reply) == 1: validChar = True letterIndex = ord(reply) - 65 if letterIndex > 25: letterIndex = letterIndex - 32 while letterIndex > 25 or not availableLetters[letterIndex]: print('This is an invalid choice. Please try again!') validChar = False print(letterString) while not validChar: reply = input('Guess! > ') if len(reply) == 1: validChar = True letterIndex = ord(reply) - 65 if letterIndex > 25: letterIndex = letterIndex - 32 guess = chr(97 + letterIndex) availableLetters[letterIndex] = False return guess, availableLetters def getWordFamilyCounter(L, n, guess): wordFamilyCounter = [0]*2**n familyIndexList = [-1]*len(L) for k in range(len(L)): w = list(L[k]) ct = 0 for k2 in range(n): if w[k2] == guess: ct = ct + 2**k2 familyIndexList[k] = ct wordFamilyCounter[ct] = wordFamilyCounter[ct] + 1 return wordFamilyCounter, familyIndexList def extractLargestFamily(L, familyIndexList, wordFamilyCounter): bestFamily = wordFamilyCounter.index(max(wordFamilyCounter)) boolist = [False]*len(L) for k3 in range(len(L)): if familyIndexList[k3] == bestFamily: boolist[k3] = True j2 = 0 smallList = [' ']*sum(boolist) for k4 in range(len(L)): if boolist[k4]: smallList[j2] = L[k4] j2 = j2 + 1 return smallList def updatePatternList(patternList, guess, bestFamily): n = len(patternList) for k6 in range(n): if bestFamily//2 == bestFamily/2: pass else: patternList[k6] = guess + ' ' bestFamily = bestFamily >> 1 return patternList def pickWordFrom(L): index = random.randint(0, len(L) - 1) return L[index] def play(): reply = getUserStringInput(intListToStringList(list(range(2, 21))), 'How long should I make your word?!!? (2 to 20) > ') n = int(reply) patternList = ['_ ']*n print(''.join(patternList)) L = wordsOfLength(n, 'dictionary.txt') reply = getUserStringInput(intListToStringList(list(range(1, 27))), 'How many guesses will you need? > ') m = int(reply) availableLetters = [True]*26 for i in range(m): guess, availableLetters = getNewLetterGuess(availableLetters) wordFamilyCounter, familyIndexList = getWordFamilyCounter(L, n, guess) bestFamily = wordFamilyCounter.index(max(wordFamilyCounter)) if bestFamily == 0: print('Letter not in word.') else: print('Letter is in word!!!') L = extractLargestFamily(L, familyIndexList, wordFamilyCounter) patternList = updatePatternList(patternList, guess, bestFamily) print(''.join(patternList)) if '_ ' not in patternList: break if '_ ' not in patternList: print('SURELY you must be CHEATING, but you guessed my word in ' + str(i + 1) + ' tries!!!') else: bogusWord = pickWordFrom(L) print('You lose. The word was: ' + bogusWord) >>> I haven't actually checked if this code runs :) -- Arnaud From tjreedy at udel.edu Fri Mar 2 15:19:31 2012 From: tjreedy at udel.edu (Terry Reedy) Date: Fri, 02 Mar 2012 15:19:31 -0500 Subject: Is it necessary to call Tk() when writing a GUI app with Tkinter? In-Reply-To: References: <27603449.17.1330492001624.JavaMail.geo-discussion-forums@vbbfv2> <6e1c521e-14be-4ec0-9ff0-7f23fd9cd3dc@f14g2000yqe.googlegroups.com> <3d0bf288-fa5d-48e5-9529-db92d420a915@1g2000yqv.googlegroups.com> Message-ID: On 3/1/2012 10:43 PM, Terry Reedy wrote: >> Not sure what is happening on your end, but i don't see any braces. > > Are you saying that if you change "Hello_World\n(click_me)" to > "Hello World\n(click me)", you see > > Hello World > (click me) > > as I expected, instead of > > {Hellow World > (click me)} > > as I do see? What OS are you running? And what tk version? (I have 8.5.9 > in Win7) The problem was another subtle bug in the current example": self.hi_there["text"] = "Hello", The spurious comma at the end makes the value of the 'text' attribute a one-elememt tuple and not just a string. I presume tcl-based tk handles that in the manner appropriate for the tcl equivalent. I believe tcl uses spaces rather than commas to separate items, so the braces serve as 'quotes' to indicate that the contents are one item, not three. Removing the comma solves the problem. -- Terry Jan Reedy From clp2 at rebertia.com Fri Mar 2 15:22:41 2012 From: clp2 at rebertia.com (Chris Rebert) Date: Fri, 2 Mar 2012 12:22:41 -0800 Subject: Python - CGI-BIN - Apache Timeout Problem In-Reply-To: <6FC169072CBFF3409B6E74F50175A4650497A3F9@xmb-sjc-215.amer.cisco.com> References: <6FC169072CBFF3409B6E74F50175A4650497A3F9@xmb-sjc-215.amer.cisco.com> Message-ID: On Fri, Mar 2, 2012 at 12:09 PM, Sean Cavanaugh (scavanau) wrote: > THE PROBLEM: > > When I execute the scripts from the command line (#python main.py) it > generates it fine (albeit slowly), it prints all the html code out including > the script.? The ?core? part of the script dumbed down to the lowest level > is-> > > ??????? proc = subprocess.Popen(['/usr/local/bin/python', 'tests.py'], > stdout=subprocess.PIPE) > ??????? output = proc.stdout.read() Note the red warning box about possible deadlock with .stdout.read() and friends: http://docs.python.org/library/subprocess.html#popen-objects > ??????? print output > ??????? proc.stdout.close() As the docs advise, try using .communicate() [http://docs.python.org/library/subprocess.html#subprocess.Popen.communicate ] instead: proc = subprocess.Popen(?) out, err = proc.communicate() print out > When I open main.py and execute the script it just hangs? it seems to > execute the script (I see pcap fires on the interface that I am testing on > the firewall) but its not executing correctly? or loading the entire > webpage?the webpage keeps chugging along and eventually gives me an error > timeout. The hanging makes me suspect that the aforementioned deadlock is occurring. Cheers, Chris -- http://chrisrebert.com From mwilson at the-wire.com Fri Mar 2 15:52:24 2012 From: mwilson at the-wire.com (Mel Wilson) Date: Fri, 02 Mar 2012 15:52:24 -0500 Subject: Is it necessary to call Tk() when writing a GUI app with Tkinter? References: <27603449.17.1330492001624.JavaMail.geo-discussion-forums@vbbfv2> <6e1c521e-14be-4ec0-9ff0-7f23fd9cd3dc@f14g2000yqe.googlegroups.com> <3d0bf288-fa5d-48e5-9529-db92d420a915@1g2000yqv.googlegroups.com> Message-ID: Terry Reedy wrote: > The problem was another subtle bug in the current example": > self.hi_there["text"] = "Hello", > > The spurious comma at the end makes the value of the 'text' attribute a > one-elememt tuple and not just a string. I presume tcl-based tk handles > that in the manner appropriate for the tcl equivalent. I believe tcl > uses spaces rather than commas to separate items, so the braces serve as > 'quotes' to indicate that the contents are one item, not three. Removing > the comma solves the problem. That looks like it. Tcl is the 'LISP of strings' Composite-object things like indexing work on space-separated strings. Mel. From scavanau at cisco.com Fri Mar 2 16:05:29 2012 From: scavanau at cisco.com (Sean Cavanaugh (scavanau)) Date: Fri, 2 Mar 2012 13:05:29 -0800 Subject: Python - CGI-BIN - Apache Timeout Problem In-Reply-To: References: <6FC169072CBFF3409B6E74F50175A4650497A3F9@xmb-sjc-215.amer.cisco.com> Message-ID: <6FC169072CBFF3409B6E74F50175A4650497A426@xmb-sjc-215.amer.cisco.com> Hey Chris, Thanks for your quick reply! I switched my code to-> proc = subprocess.Popen(['/usr/local/bin/python', 'tests.py'], stdout=subprocess.PIPE) out, err = proc.communicate() print out proc.stdout.close() It still dead locked. Interestingly enough When I did a #python tests.py on the command line even that was taking awhile to print out to the command line so I decided to restart my webserver... wow from mucking before something must have been running in the background still. I got the script down to 2 seconds or so... Now it still works but faster when I do #python main.py it generates all the text to the command line but the website still hangs when I go to http://webserver/main.py... I am not sure what is going wrong... no error in the /var/log except for the eventual timeout after a couple minutes goes by. -S -----Original Message----- From: chris at rebertia.com [mailto:chris at rebertia.com] On Behalf Of Chris Rebert Sent: Friday, March 02, 2012 3:23 PM To: Sean Cavanaugh (scavanau) Cc: python-list at python.org Subject: Re: Python - CGI-BIN - Apache Timeout Problem On Fri, Mar 2, 2012 at 12:09 PM, Sean Cavanaugh (scavanau) wrote: > THE PROBLEM: > > When I execute the scripts from the command line (#python main.py) it > generates it fine (albeit slowly), it prints all the html code out including > the script.? The ?core? part of the script dumbed down to the lowest level > is-> > > ??????? proc = subprocess.Popen(['/usr/local/bin/python', 'tests.py'], > stdout=subprocess.PIPE) > ??????? output = proc.stdout.read() Note the red warning box about possible deadlock with .stdout.read() and friends: http://docs.python.org/library/subprocess.html#popen-objects > ??????? print output > ??????? proc.stdout.close() As the docs advise, try using .communicate() [http://docs.python.org/library/subprocess.html#subprocess.Popen.communicate ] instead: proc = subprocess.Popen(?) out, err = proc.communicate() print out > When I open main.py and execute the script it just hangs? it seems to > execute the script (I see pcap fires on the interface that I am testing on > the firewall) but its not executing correctly? or loading the entire > webpage?the webpage keeps chugging along and eventually gives me an error > timeout. The hanging makes me suspect that the aforementioned deadlock is occurring. Cheers, Chris -- http://chrisrebert.com From scavanau at cisco.com Fri Mar 2 16:43:11 2012 From: scavanau at cisco.com (Sean Cavanaugh (scavanau)) Date: Fri, 2 Mar 2012 13:43:11 -0800 Subject: Python - CGI-BIN - Apache Timeout Problem In-Reply-To: References: <6FC169072CBFF3409B6E74F50175A4650497A3F9@xmb-sjc-215.amer.cisco.com> Message-ID: <6FC169072CBFF3409B6E74F50175A4650497A445@xmb-sjc-215.amer.cisco.com> Hey All, So maybe this part is important (after doing some troubleshooting) hopefully not everyone has beers in hand already since its Friday :-) The way the code works if you want to send through the firewall (i.e. SERVER->FIREWALL->SERVER) I split the process into two threads. One is listening on the egress, then I send on the ingress. The main waits until the thread finishes (it times out after 2 seconds). I had to do this b/c scapy (the library I used) won't let me send pcaps while I receive them. This lets me see packets on both sides (i.e. did that sort of internet traffic go through the firewall). The reason I think this could be a problem is when I ran a test where I sent to the firewall (rather than through it) and my program does not need to thread the webserver works fine...... Suggestions anyone? -S -----Original Message----- From: chris at rebertia.com [mailto:chris at rebertia.com] On Behalf Of Chris Rebert Sent: Friday, March 02, 2012 3:23 PM To: Sean Cavanaugh (scavanau) Cc: python-list at python.org Subject: Re: Python - CGI-BIN - Apache Timeout Problem On Fri, Mar 2, 2012 at 12:09 PM, Sean Cavanaugh (scavanau) wrote: > THE PROBLEM: > > When I execute the scripts from the command line (#python main.py) it > generates it fine (albeit slowly), it prints all the html code out including > the script.? The ?core? part of the script dumbed down to the lowest level > is-> > > ??????? proc = subprocess.Popen(['/usr/local/bin/python', 'tests.py'], > stdout=subprocess.PIPE) > ??????? output = proc.stdout.read() Note the red warning box about possible deadlock with .stdout.read() and friends: http://docs.python.org/library/subprocess.html#popen-objects > ??????? print output > ??????? proc.stdout.close() As the docs advise, try using .communicate() [http://docs.python.org/library/subprocess.html#subprocess.Popen.communicate ] instead: proc = subprocess.Popen(?) out, err = proc.communicate() print out > When I open main.py and execute the script it just hangs? it seems to > execute the script (I see pcap fires on the interface that I am testing on > the firewall) but its not executing correctly? or loading the entire > webpage?the webpage keeps chugging along and eventually gives me an error > timeout. The hanging makes me suspect that the aforementioned deadlock is occurring. Cheers, Chris -- http://chrisrebert.com From kliateni at gmail.com Fri Mar 2 16:57:12 2012 From: kliateni at gmail.com (Karim) Date: Fri, 02 Mar 2012 22:57:12 +0100 Subject: decompilation In-Reply-To: References: Message-ID: <4F514238.9060900@gmail.com> Le 02/03/2012 21:18, Arnaud Delobelle a ?crit : > On 2 March 2012 18:52, shikha panghal wrote: >> Hi >> >> Please decoplile the .pyc code ,as i have lost my .py code. > Aha, a customer! I've written a module for this: unpyc3 > (http://code.google.com/p/unpyc3/) > > Here it is in action: > > > Python 3.2.1 (v3.2.1:ac1f7e5c0510, Jul 9 2011, 01:03:53) > [GCC 4.2.1 (Apple Inc. build 5666) (dot 3)] on darwin > Type "help", "copyright", "credits" or "license" for more information. >>>> import unpyc3 >>>> import hangman322 >>>> code = unpyc3.decompile(hangman322) >>>> print(code) > import random > > def readFile(fileName): > file = open(fileName) > lineList = file.readlines() > file.close() > return lineList > > def initialize(fileName): > try: > lineList = readFile(fileName) > except: > print('Oops! ' + filename + ' was not a valid file.') > return > len_d = len(lineList) > word_length = [0]*len_d > for i in range(len_d): > if lineList[i][-1] == '\n': > word_length[i] = len(lineList[i]) - 1 > else: > word_length[i] = len(lineList[i]) > tabulate = [0]*25 > for i in range(len_d): > if word_length[i]>= 24: > tabulate[24] = tabulate[24] + 1 > else: > tabulate[word_length[i]] = tabulate[word_length[i]] + 1 > words = [None]*25 > for i in range(2, 24): > words[i] = [None]*tabulate[i] > k = 0 > for j in range(len_d): > if word_length[j] == i: > words[i][k] = lineList[j] > k = k + 1 > for i in range(24, 25): > words[i] = [None]*tabulate[i] > k = 0 > for j in range(len_d): > if word_length[j]>= i: > words[i][k] = lineList[j] > k = k + 1 > return words > > def wordsOfLength(n, source_file): > words = initialize(source_file) > return words[n] > > def getUserStringInput(L, prompt): > replyInList = False > while not replyInList: > reply = input(prompt) > replyInList = reply in L > if not replyInList: > print('That reply is invalid. Try again.') > return reply > > def intListToStringList(L): > L2 = ['']*len(L) > for i in range(len(L)): > L2[i] = str(L[i]) > return L2 > > def getNewLetterGuess(availableLetters): > letterString = '' > for j in range(26): > if availableLetters[j]: > letterString = letterString + chr(65 + j) + ' ' > else: > letterString = letterString + ' ' > validChar = False > print(letterString) > while not validChar: > reply = input('Guess!> ') > if len(reply) == 1: > validChar = True > letterIndex = ord(reply) - 65 > if letterIndex> 25: > letterIndex = letterIndex - 32 > while letterIndex> 25 or not availableLetters[letterIndex]: > print('This is an invalid choice. Please try again!') > validChar = False > print(letterString) > while not validChar: > reply = input('Guess!> ') > if len(reply) == 1: > validChar = True > letterIndex = ord(reply) - 65 > if letterIndex> 25: > letterIndex = letterIndex - 32 > guess = chr(97 + letterIndex) > availableLetters[letterIndex] = False > return guess, availableLetters > > def getWordFamilyCounter(L, n, guess): > wordFamilyCounter = [0]*2**n > familyIndexList = [-1]*len(L) > for k in range(len(L)): > w = list(L[k]) > ct = 0 > for k2 in range(n): > if w[k2] == guess: > ct = ct + 2**k2 > familyIndexList[k] = ct > wordFamilyCounter[ct] = wordFamilyCounter[ct] + 1 > return wordFamilyCounter, familyIndexList > > def extractLargestFamily(L, familyIndexList, wordFamilyCounter): > bestFamily = wordFamilyCounter.index(max(wordFamilyCounter)) > boolist = [False]*len(L) > for k3 in range(len(L)): > if familyIndexList[k3] == bestFamily: > boolist[k3] = True > j2 = 0 > smallList = [' ']*sum(boolist) > for k4 in range(len(L)): > if boolist[k4]: > smallList[j2] = L[k4] > j2 = j2 + 1 > return smallList > > def updatePatternList(patternList, guess, bestFamily): > n = len(patternList) > for k6 in range(n): > if bestFamily//2 == bestFamily/2: > pass > else: > patternList[k6] = guess + ' ' > bestFamily = bestFamily>> 1 > return patternList > > def pickWordFrom(L): > index = random.randint(0, len(L) - 1) > return L[index] > > def play(): > reply = getUserStringInput(intListToStringList(list(range(2, > 21))), 'How long should I make your word?!!? (2 to 20)> ') > n = int(reply) > patternList = ['_ ']*n > print(''.join(patternList)) > L = wordsOfLength(n, 'dictionary.txt') > reply = getUserStringInput(intListToStringList(list(range(1, > 27))), 'How many guesses will you need?> ') > m = int(reply) > availableLetters = [True]*26 > for i in range(m): > guess, availableLetters = getNewLetterGuess(availableLetters) > wordFamilyCounter, familyIndexList = getWordFamilyCounter(L, n, guess) > bestFamily = wordFamilyCounter.index(max(wordFamilyCounter)) > if bestFamily == 0: > print('Letter not in word.') > else: > print('Letter is in word!!!') > L = extractLargestFamily(L, familyIndexList, wordFamilyCounter) > patternList = updatePatternList(patternList, guess, bestFamily) > print(''.join(patternList)) > if '_ ' not in patternList: > break > if '_ ' not in patternList: > print('SURELY you must be CHEATING, but you guessed my word in > ' + str(i + 1) + ' tries!!!') > else: > bogusWord = pickWordFrom(L) > print('You lose. The word was: ' + bogusWord) > > I haven't actually checked if this code runs :) > Great code (unpy3) Arnaud! pretty well built. Cheers Karim From johnjsal at gmail.com Fri Mar 2 17:16:46 2012 From: johnjsal at gmail.com (John Salerno) Date: Fri, 2 Mar 2012 14:16:46 -0800 (PST) Subject: Is it necessary to call Tk() when writing a GUI app with Tkinter? In-Reply-To: References: <27603449.17.1330492001624.JavaMail.geo-discussion-forums@vbbfv2> <6e1c521e-14be-4ec0-9ff0-7f23fd9cd3dc@f14g2000yqe.googlegroups.com> <17153317.324.1330576905540.JavaMail.geo-discussion-forums@yncd8> Message-ID: <11188032.247.1330726606861.JavaMail.geo-discussion-forums@ynbq18> > After that, you can nest as > many frames, toplevels, and blah widgets under that root window as you > so desire. Actually you don't even need a "frame", you can pack > widgets directly into a Toplevel or Tk widget. This is interesting. I completely understand your point about always calling (and using) the instance of Tk as the root. Given that, what is the point of creating a Frame object at all? I tried NOT doing it, like you said, and it seemed to work fine with my simple example. But is there a benefit to using a Frame object to group the widgets together? Or is it cleaner to just use the Tk object? From jbeard565 at gmail.com Fri Mar 2 17:46:13 2012 From: jbeard565 at gmail.com (Jeff Beardsley) Date: Fri, 2 Mar 2012 14:46:13 -0800 (PST) Subject: A possible change to decimal.Decimal? Message-ID: <15610330.329.1330728373676.JavaMail.geo-discussion-forums@ynlw24> HISTORY: In using python 2.7.2 for awhile on a web project (apache/wsgi web.py), I discovered a problem in using decimal.Decimal. A short search revealed that many other people have been having the problem as well, in their own apache/wsgi implementations (django, mostly), but I found no real solutions among the posts I read. So I did some experimentation of my own. The following code will break unexpectedly on standard python2.7 (and earlier) because of the way that isinstance fails after reload() (which is called by both of the above web frameworks). This is the error: TypeError("Cannot convert %r to Decimal" % value) THE TEST CODE import decimal from decimal import Decimal #this works Decimal(Decimal()) reload(decimal) #this fails before patching, but works fine afterwards Decimal(Decimal()) THE SOLUTION: So, looking into decimal.py I discovered lots if statements using isinstance, and have slightly rearranged the code inside __new__() to mostly remove their use, and for my purposes totally fixes the problem within wsgi. I am not an official python dev, so would appreciate it if someone who *IS* could just look this over, improve it if necessary, and get it (or some variation) submitted into the library. Below is a patch for use against python-2.7.2 PATCH: *** decimal.py 2012-03-02 16:42:51.285964007 -0600 --- /usr/lib/python2.7/decimal.py 2012-03-02 14:36:01.238976461 -0600 *************** *** 535,608 **** # and the Decimal constructor still deal with tuples of # digits. self = object.__new__(cls) ! # From a string ! # REs insist on real strings, so we can too. ! if isinstance(value, basestring): ! m = _parser(value.strip()) ! if m is None: ! if context is None: ! context = getcontext() ! return context._raise_error(ConversionSyntax, ! "Invalid literal for Decimal: %r" % value) ! ! if m.group('sign') == "-": ! self._sign = 1 ! else: ! self._sign = 0 ! intpart = m.group('int') ! if intpart is not None: ! # finite number ! fracpart = m.group('frac') or '' ! exp = int(m.group('exp') or '0') ! self._int = str(int(intpart+fracpart)) ! self._exp = exp - len(fracpart) ! self._is_special = False ! else: ! diag = m.group('diag') ! if diag is not None: ! # NaN ! self._int = str(int(diag or '0')).lstrip('0') ! if m.group('signal'): ! self._exp = 'N' ! else: ! self._exp = 'n' ! else: ! # infinity ! self._int = '0' ! self._exp = 'F' ! self._is_special = True ! return self ! ! # From an integer ! if isinstance(value, (int,long)): ! if value >= 0: ! self._sign = 0 ! else: ! self._sign = 1 ! self._exp = 0 ! self._int = str(abs(value)) ! self._is_special = False return self ! # From another decimal ! if isinstance(value, Decimal): self._exp = value._exp self._sign = value._sign self._int = value._int self._is_special = value._is_special return self # From an internal working value ! if isinstance(value, _WorkRep): self._sign = value.sign self._int = str(value.int) self._exp = int(value.exp) self._is_special = False return self # tuple/list conversion (possibly from as_tuple()) if isinstance(value, (list,tuple)): if len(value) != 3: raise ValueError('Invalid tuple size in creation of Decimal ' --- 535,582 ---- # and the Decimal constructor still deal with tuples of # digits. self = object.__new__(cls) ! # Note about isinstance -- Decimal has been a victim of the ! # isinstance builtin failing after module reload in some ! # environments (e.g. web.py, django) under apache/wsgi, which ! # I determined to be the reason Decimal was causing so many ! # problems in my web deployment. I have re-organized the ! # following code to remove use of isinstance except on ! # native types (int, long, float, list, tuple), since those ! # seem not to break in this regard. -- jdb ! ! # First, assume it's another Decimal or similar(having _exp, ! # _sign, _int and _is_special. Obviously, having these ! # implies it's at least an attempt to represent Decimal ! try: ! self._exp = value._exp ! self._sign = value._sign ! self._int = value._int ! self._is_special = value._is_special return self + except: pass ! # Or it's a float ! try: ! value = Decimal.from_float(value) self._exp = value._exp self._sign = value._sign self._int = value._int self._is_special = value._is_special return self + except: pass # From an internal working value ! try: self._sign = value.sign self._int = str(value.int) self._exp = int(value.exp) self._is_special = False return self + except: pass # tuple/list conversion (possibly from as_tuple()) if isinstance(value, (list,tuple)): if len(value) != 3: raise ValueError('Invalid tuple size in creation of Decimal ' *************** *** 645,661 **** raise ValueError("The third value in the tuple must " "be an integer, or one of the " "strings 'F', 'n', 'N'.") return self ! if isinstance(value, float): ! value = Decimal.from_float(value) ! self._exp = value._exp ! self._sign = value._sign ! self._int = value._int ! self._is_special = value._is_special return self raise TypeError("Cannot convert %r to Decimal" % value) # @classmethod, but @decorator is not valid Python 2.3 syntax, so # don't use it (see notes on Py2.3 compatibility at top of file) --- 619,666 ---- raise ValueError("The third value in the tuple must " "be an integer, or one of the " "strings 'F', 'n', 'N'.") return self ! # From a string, or anything representable as a string ! try: ! value = str(value) ! m = _parser(value.strip()) ! if m is None: ! if context is None: ! context = getcontext() ! return context._raise_error(ConversionSyntax, ! "Invalid literal for Decimal: %r" % value) ! ! if m.group('sign') == "-": ! self._sign = 1 ! else: ! self._sign = 0 ! intpart = m.group('int') ! if intpart is not None: ! # finite number ! fracpart = m.group('frac') or '' ! exp = int(m.group('exp') or '0') ! self._int = str(int(intpart+fracpart)) ! self._exp = exp - len(fracpart) ! self._is_special = False ! else: ! diag = m.group('diag') ! if diag is not None: ! # NaN ! self._int = str(int(diag or '0')).lstrip('0') ! if m.group('signal'): ! self._exp = 'N' ! else: ! self._exp = 'n' ! else: ! # infinity ! self._int = '0' ! self._exp = 'F' ! self._is_special = True return self + except: pass raise TypeError("Cannot convert %r to Decimal" % value) # @classmethod, but @decorator is not valid Python 2.3 syntax, so # don't use it (see notes on Py2.3 compatibility at top of file) From ethan at stoneleaf.us Fri Mar 2 18:49:39 2012 From: ethan at stoneleaf.us (Ethan Furman) Date: Fri, 02 Mar 2012 15:49:39 -0800 Subject: A possible change to decimal.Decimal? In-Reply-To: <15610330.329.1330728373676.JavaMail.geo-discussion-forums@ynlw24> References: <15610330.329.1330728373676.JavaMail.geo-discussion-forums@ynlw24> Message-ID: <4F515C93.6080201@stoneleaf.us> Jeff Beardsley wrote: > HISTORY: > > In using python 2.7.2 for awhile on a web project (apache/wsgi web.py), I discovered a problem in using decimal.Decimal. A short search revealed that many other people have been having the problem as well, in their own apache/wsgi implementations (django, mostly), but I found no real solutions among the posts I read. So I did some experimentation of my own. > > The following code will break unexpectedly on standard python2.7 (and earlier) because of the way that isinstance fails after reload() (which is called by both of the above web frameworks). > > This is the error: TypeError("Cannot convert %r to Decimal" % value) > > THE TEST CODE > > import decimal > from decimal import Decimal > > #this works > Decimal(Decimal()) > > reload(decimal) > > #this fails before patching, but works fine afterwards > Decimal(Decimal()) > Patching decimal.py to make it work with reload() is probably not going to happen. What you should be doing is: import decimal from decimal import Decimal reload(decimal) Decimal = decimal.Decimal # (rebind 'Decimal' to the reloaded code) ~Ethan~ From jbeard565 at gmail.com Fri Mar 2 19:18:29 2012 From: jbeard565 at gmail.com (Jeff Beardsley) Date: Fri, 2 Mar 2012 18:18:29 -0600 Subject: A possible change to decimal.Decimal? In-Reply-To: <4F515C93.6080201@stoneleaf.us> References: <15610330.329.1330728373676.JavaMail.geo-discussion-forums@ynlw24> <4F515C93.6080201@stoneleaf.us> Message-ID: The problem with that though is: I am not the one calling reload(). That is actually being called for me by web.py (or django, or some other framework, take your pick). More than that, I believe it's called (or caused, anyway) by something happening in WSGI under apache. (And I don't really want to start digging around in there either) The patch in this case is very limited in scope, and all it inflicts on the subject code inside of decimal.Decimal.__new__(), is better programming practices. --jeff On Fri, Mar 2, 2012 at 5:49 PM, Ethan Furman wrote: > Jeff Beardsley wrote: > >> HISTORY: >> In using python 2.7.2 for awhile on a web project (apache/wsgi web.py), I >> discovered a problem in using decimal.Decimal. A short search revealed >> that many other people have been having the problem as well, in their own >> apache/wsgi implementations (django, mostly), but I found no real solutions >> among the posts I read. So I did some experimentation of my own. >> >> The following code will break unexpectedly on standard python2.7 (and >> earlier) because of the way that isinstance fails after reload() (which is >> called by both of the above web frameworks). >> >> This is the error: TypeError("Cannot convert %r to Decimal" % value) >> >> THE TEST CODE >> >> import decimal >> from decimal import Decimal >> >> #this works >> Decimal(Decimal()) >> >> reload(decimal) >> >> #this fails before patching, but works fine afterwards >> Decimal(Decimal()) >> >> > Patching decimal.py to make it work with reload() is probably not going to > happen. > > What you should be doing is: > > import decimal > from decimal import Decimal > > reload(decimal) > Decimal = decimal.Decimal # (rebind 'Decimal' to the reloaded code) > > ~Ethan~ > -------------- next part -------------- An HTML attachment was scrubbed... URL: From johnjsal at gmail.com Fri Mar 2 20:48:53 2012 From: johnjsal at gmail.com (John Salerno) Date: Fri, 2 Mar 2012 17:48:53 -0800 (PST) Subject: How do you use the widgets in tkinter.ttk if you want to "import tkinter as tk"? Message-ID: <29015333.101.1330739333318.JavaMail.geo-discussion-forums@vbbgt10> According to the Python docs, the way to use tkinter.ttk is this: from tkinter import * from tkinter.ttk import * But what if I don't like this import method and prefer to do: import tkinter as tk How then do I utilize tkinter.ttk using the same name? Or is that not possible? Will I have to use to separate names, like this: import tkinter as tk import tkinter.ttk as ttk Is that the only way? From wang93117 at gmail.com Fri Mar 2 21:45:32 2012 From: wang93117 at gmail.com (gwang) Date: Fri, 2 Mar 2012 18:45:32 -0800 (PST) Subject: Unable to install xmldiff package on WIndows7 References: Message-ID: On Jan 3, 11:47?am, hisan wrote: > Hi All > > i have downloaded "xmldiff-0.6.10" from their official site (http://www.logilab.org/859). > I have tried installing the same on my 32 bit Windows 7 OS using the > command "setup.py install" but below exceptions are thrown in the > console. > please help me out in installing this package on Windows > > Exceptions thrown while installing > > C:\Users\santosh\Downloads\xmldiff-0.6.10>setup.py build > running build > running build_py > package init file '.\test\__init__.py' not found (or not a regular > file) > package init file '.\test\__init__.py' not found (or not a regular > file) > running build_ext > building 'xmldiff.maplookup' extension > gcc -mno-cygwin -mdll -O -Wall -ID:\Python26\include -ID:\Python26\PC - > c extensions/maplookup.c -o b > uild\temp.win32-2.6\Release\extensions\maplookup.o > error: command 'gcc' failed: No such file or directory edit maplookup.c and comment away the line : #include . At least that's what worked for me. From tjreedy at udel.edu Fri Mar 2 21:47:30 2012 From: tjreedy at udel.edu (Terry Reedy) Date: Fri, 02 Mar 2012 21:47:30 -0500 Subject: How do you use the widgets in tkinter.ttk if you want to "import tkinter as tk"? In-Reply-To: <29015333.101.1330739333318.JavaMail.geo-discussion-forums@vbbgt10> References: <29015333.101.1330739333318.JavaMail.geo-discussion-forums@vbbgt10> Message-ID: On 3/2/2012 8:48 PM, John Salerno wrote: > According to the Python docs, the way to use tkinter.ttk is this: > > from tkinter import * > from tkinter.ttk import * I suppose the 'advantage' of this is that it will replace tk widgets with equivalent ttk widgets, if they exist and have the same name. I believe one has to program them differently, however, so the replacement cannot be transparent and one mush know anyway what gets replaced and what not. > But what if I don't like this import method and prefer to do: > > import tkinter as tk > > How then do I utilize tkinter.ttk using the same name? > Or is that not possible? Will I have to use to separate names, like this: No. One name for one object. > import tkinter as tk > import tkinter.ttk as ttk Yes -- Terry Jan Reedy From ben+python at benfinney.id.au Fri Mar 2 22:34:35 2012 From: ben+python at benfinney.id.au (Ben Finney) Date: Sat, 03 Mar 2012 14:34:35 +1100 Subject: How do you use the widgets in tkinter.ttk if you want to "import tkinter as tk"? References: <29015333.101.1330739333318.JavaMail.geo-discussion-forums@vbbgt10> Message-ID: <87hay6nyr8.fsf@benfinney.id.au> Terry Reedy writes: > On 3/2/2012 8:48 PM, John Salerno wrote: > > from tkinter import * > > from tkinter.ttk import * > > I suppose the 'advantage' of this is that it will replace tk widgets > with equivalent ttk widgets, if they exist and have the same name. I > believe one has to program them differently, however, so the > replacement cannot be transparent and one mush know anyway what gets > replaced and what not. Yes, and one mush is exactly what one gets when clobbering the namespace with ?from foo import *? :-) -- \ ?We are human only to the extent that our ideas remain humane.? | `\ ?_Breakfast of Champions_, Kurt Vonnegut | _o__) | Ben Finney From Joshua.R.English at gmail.com Fri Mar 2 23:47:14 2012 From: Joshua.R.English at gmail.com (Josh English) Date: Fri, 2 Mar 2012 20:47:14 -0800 (PST) Subject: Udacity CS 101 In-Reply-To: References: <28556790.1352.1330204852864.JavaMail.geo-discussion-forums@pbgq3> Message-ID: <12911798.131.1330750034248.JavaMail.geo-discussion-forums@pbqn3> On Monday, February 27, 2012 6:37:25 PM UTC-8, Ray Clark wrote: > > You have to remember that this course assumes no prior computer > programming knowledge. > > I agree, it is starting out very basic. Give it some more time. > These guys have PhDs from MIT and/or have taught at Stanford. They > know what they are doing. It seems to me that they're not starting with good Python practices, really, or even the terminology I'd expect. From johnjsal at gmail.com Sat Mar 3 00:06:02 2012 From: johnjsal at gmail.com (John Salerno) Date: Fri, 2 Mar 2012 21:06:02 -0800 (PST) Subject: How do you use the widgets in tkinter.ttk if you want to "import tkinter as tk"? In-Reply-To: References: <29015333.101.1330739333318.JavaMail.geo-discussion-forums@vbbgt10> Message-ID: <409450.255.1330751162956.JavaMail.geo-discussion-forums@vbkl3> > I suppose the 'advantage' of this is that it will replace tk widgets > with equivalent ttk widgets, if they exist and have the same name. I > believe one has to program them differently, however, so the replacement > cannot be transparent and one mush know anyway what gets replaced and > what not. Grr, sounds like a pain if I want to use the new widgets. Does this cause conflict with someone who isn't running 8.5, or will they still see the older widgets as normal? I'm tempted just to go back to wxPython. Two sets of widgets in Tkinter is a little annoying. From johnjsal at gmail.com Sat Mar 3 00:06:02 2012 From: johnjsal at gmail.com (John Salerno) Date: Fri, 2 Mar 2012 21:06:02 -0800 (PST) Subject: How do you use the widgets in tkinter.ttk if you want to "import tkinter as tk"? In-Reply-To: References: <29015333.101.1330739333318.JavaMail.geo-discussion-forums@vbbgt10> Message-ID: <409450.255.1330751162956.JavaMail.geo-discussion-forums@vbkl3> > I suppose the 'advantage' of this is that it will replace tk widgets > with equivalent ttk widgets, if they exist and have the same name. I > believe one has to program them differently, however, so the replacement > cannot be transparent and one mush know anyway what gets replaced and > what not. Grr, sounds like a pain if I want to use the new widgets. Does this cause conflict with someone who isn't running 8.5, or will they still see the older widgets as normal? I'm tempted just to go back to wxPython. Two sets of widgets in Tkinter is a little annoying. From dreamingforward at gmail.com Sat Mar 3 01:12:04 2012 From: dreamingforward at gmail.com (dreamingforward at gmail.com) Date: Fri, 2 Mar 2012 22:12:04 -0800 (PST) Subject: A 'Python like' language In-Reply-To: References: <40645d8f$0$10775$afc38c87@news.easynet.co.uk> <30985729.0403291959.2dafe546@posting.google.com> Message-ID: <15871005.273.1330755124745.JavaMail.geo-discussion-forums@pbboi9> On Tuesday, March 30, 2004 12:31:35 AM UTC-7, Mark Hahn wrote: > > --Take advantage of iterators early on for return values to avoid > > things like having both dict.items() and dict.iteritems(). > > Interestiong idea. Generators are fully supported so I could do this now. > So gens would have to be allowed absolutely everywhere lists are allowed (is > trhis possible?). Or are you thinking the user should type > List(dict.items()) ? No, the former. Most of the time you never really use a full, naked list anyway, generally only for documentation purposes. > > --Choose "{:}" syntax for empty dict creation to reserve "{}" for > > sets. (Or: use "{}" for both, and do automatic "set-to-dict > > Also cool. Maybe <> for sets? Prothon doesn't support <> as != so it is > free. I strongly suggest the standard (in math anyway) syntax for set notation. It shouldn't be hard to parse whether code syntax is referring to a set vs. dict. > > --Functions that return multiple, but unique, values should return a > > set, not a list, to communicate same (ex: dict.keys(), dir(), etc.). > > Also cool. This is something that still hasn't really been implemented in PythonV3. > > --Dict should inherit from Set. > > Also cool (I feel like the credits of Holy Grail saying Also wik). An alternative is to create a named association type, similar to the ABC programming language, denoted by the colon. "name": []. A dict then would simply be a set of these. Having a compound type would come in handy in several other ways too. > > --With prothon's "immutability" bit and other considerations, does the > > language need both tuples AND lists? > > I like this a lot. Tuples are already implemented internally as lists. I think, in fact, that the object model could be more unified. Under such a new object model, the worries about having a full library becomes rather pointless, as the new model will require a revamping of everything. > More like a few dollars. This is really good stuff. Can I talk you into > hanging out on the Prothon list now and then, at least until we get the core > language sorted out? Haha, a little late, but consider this a restart. From no.email at nospam.invalid Sat Mar 3 01:22:30 2012 From: no.email at nospam.invalid (Paul Rubin) Date: Fri, 02 Mar 2012 22:22:30 -0800 Subject: A 'Python like' language References: <40645d8f$0$10775$afc38c87@news.easynet.co.uk> <30985729.0403291959.2dafe546@posting.google.com> <15871005.273.1330755124745.JavaMail.geo-discussion-forums@pbboi9> Message-ID: <7xaa3y8aqh.fsf@ruckus.brouhaha.com> dreamingforward at gmail.com writes: >> hanging out on the Prothon list now and then, at least until we get >> the core language sorted out? > > Haha, a little late, but consider this a restart. It wasn't til I saw the word "Prothon" that I scrolled back and saw you were responding to a thread from 2004. Prothon was pretty cool in some ways but I think it's been inactive for a very long time. I don't see much point to developing a "slightly improved but incompatible Python-like language" anyway though. Why make superficial changes that break working code and mentally overload programmers? Python is a relatively mature language by now, so it shouldn't be messed with unless the changes produce drastic benefits, not minor ones. From arpitasaha244 at gmail.com Sat Mar 3 01:27:51 2012 From: arpitasaha244 at gmail.com (arpita saha) Date: Fri, 2 Mar 2012 22:27:51 -0800 (PST) Subject: EARN RS.2.5 PER CLICK INDIAN SITE 100%REAL JOIN AND GET RS.100 INSTANTLY........... CLICK HERE TO REGISTER FOR FREE: Message-ID: http://www.indyarocks.com/blogs/blog_visiterview_main.php?ouid=NjQ2NzMwNg= PROCEDUE:---- 1)REGISTER BY COPYING THE LINK INTO YOUR BROWSER GIVEN ABOVE AND VERIFY THE GIVEN EMAIL FOR CONFIRMATION. 2)LOGIN BY USING THE USERNAME AND PASSWORD. 3)U WILL FIND 2 LINKS THERE VIEW ADS &MY ACCOUNT... a) view job details - http://www.onlineearnfree32.weebly.com/ 4)CLICK ON THE VIEW ADS LINK, U WILL FIND SOME ADS CLICK ON EACH LINK TO OPEN A NEW WINDOW........ ................................IMPORTANT: { FOLLOW WITHOUT FAIL }.............................. 1) SIMPLE JOBS. BASIC KNOWLEDGE OF COMPUTER AND INTERNET IS ENOUGH. SUITABLE FOR HOUSE WIVES,STUDENTS,WORKERS, RETIRED PERSONS & YOUTHS. b)Just signup for free at- http://onlineearnfree32.weebly.com/ Thanks ?? From dreamingforward at gmail.com Sat Mar 3 01:46:29 2012 From: dreamingforward at gmail.com (dreamingforward at gmail.com) Date: Fri, 2 Mar 2012 22:46:29 -0800 (PST) Subject: A 'Python like' language In-Reply-To: References: <40645d8f$0$10775$afc38c87@news.easynet.co.uk> <30985729.0403291959.2dafe546@posting.google.com> Message-ID: <1933683.115.1330757189443.JavaMail.geo-discussion-forums@pbcvy9> On Tuesday, March 30, 2004 6:01:01 AM UTC-7, Gerrit wrote: > > > --Dict should inherit from Set. > > > > Also cool (I feel like the credits of Holy Grail saying Also wik). > > I have read (in c.l.py) that in Smalltalk, a Dict is a Set of Associates > or something similar. I don't know Smalltalk, but I like this idea of a > Set. Yeah, I like this too. I take it from the ABC language. The thing that's relevant (and apropos to Paul Rubin's objection), is that when unifying models, you have to decide "where the decimal point is" from which all the different dimensions that the language is encoding and silently tracking can pivot around. The ":" of a compound is a sort of decimal point. Then the task is finding a formalism in which to define and incorporate all the relavent dimensions into one. The result will be necessarily recursive, revolving around the notions of the "atomic" versus the "group" and the transition rules that govern them. mark (aka zipher) From dreamingforward at gmail.com Sat Mar 3 01:46:29 2012 From: dreamingforward at gmail.com (dreamingforward at gmail.com) Date: Fri, 2 Mar 2012 22:46:29 -0800 (PST) Subject: A 'Python like' language In-Reply-To: References: <40645d8f$0$10775$afc38c87@news.easynet.co.uk> <30985729.0403291959.2dafe546@posting.google.com> Message-ID: <1933683.115.1330757189443.JavaMail.geo-discussion-forums@pbcvy9> On Tuesday, March 30, 2004 6:01:01 AM UTC-7, Gerrit wrote: > > > --Dict should inherit from Set. > > > > Also cool (I feel like the credits of Holy Grail saying Also wik). > > I have read (in c.l.py) that in Smalltalk, a Dict is a Set of Associates > or something similar. I don't know Smalltalk, but I like this idea of a > Set. Yeah, I like this too. I take it from the ABC language. The thing that's relevant (and apropos to Paul Rubin's objection), is that when unifying models, you have to decide "where the decimal point is" from which all the different dimensions that the language is encoding and silently tracking can pivot around. The ":" of a compound is a sort of decimal point. Then the task is finding a formalism in which to define and incorporate all the relavent dimensions into one. The result will be necessarily recursive, revolving around the notions of the "atomic" versus the "group" and the transition rules that govern them. mark (aka zipher) From cookfitz at gmail.com Sat Mar 3 06:42:25 2012 From: cookfitz at gmail.com (nac) Date: Sat, 3 Mar 2012 03:42:25 -0800 (PST) Subject: RotatingFileHandler Fails Message-ID: The RotatingFileHandler running on win 7 64-bit; py 2.7 is failing when the script launches a process using subprocess.Popen. Works fine if the subprocess is not launched The exception thrown Traceback (most recent call last): File "C:\Python27\lib\logging\handlers.py", line 78, in emit self.doRollover() File "C:\Python27\lib\logging\handlers.py", line 141, in doRollover os.rename(self.baseFilename, dfn) WindowsError: [Error 32] The process cannot access the file because it is being used by another process Anyone have an idea how to fix this? import os, sys import logging import logging.handlers import subprocess def chomp(s): "remove trailing carriage return" if s[-1:]=='\n': return s[:-1] else: return s logging.basicConfig(level=logging.DEBUG, format='%(asctime)s % (name)-2s %(levelname)-8s %(threadName)-12s %(message)s') q5Logger = logging.getLogger('Q5') logFileHandler = logging.handlers.RotatingFileHandler(filename='c:\ \logger\\q5.log', mode= 'a', maxBytes=100, backupCount=5) logFileHandler.setFormatter(logging.Formatter('%(asctime)s %(name)-2s % (levelname)-8s %(threadName)-12s %(message)s')) logFileHandler.setLevel(logging.DEBUG) q5Logger.addHandler(logFileHandler) progOutput = subprocess.Popen(r'dir *.*', shell=True, bufsize=1000, stdout=subprocess.PIPE).stdout line = progOutput.readline() while (line) != "": q5Logger.info( chomp(line)) line = progOutput.readline() rc = progOutput.close() From mwilson at the-wire.com Sat Mar 3 07:07:31 2012 From: mwilson at the-wire.com (Mel Wilson) Date: Sat, 03 Mar 2012 07:07:31 -0500 Subject: A 'Python like' language References: <40645d8f$0$10775$afc38c87@news.easynet.co.uk> <30985729.0403291959.2dafe546@posting.google.com> <15871005.273.1330755124745.JavaMail.geo-discussion-forums@pbboi9> <7xaa3y8aqh.fsf@ruckus.brouhaha.com> Message-ID: Paul Rubin wrote: > dreamingforward at gmail.com writes: >>> hanging out on the Prothon list now and then, at least until we get >>> the core language sorted out? >> >> Haha, a little late, but consider this a restart. > > It wasn't til I saw the word "Prothon" that I scrolled back and saw you > were responding to a thread from 2004. Prothon was pretty cool in some > ways but I think it's been inactive for a very long time. I don't see > much point to developing a "slightly improved but incompatible > Python-like language" anyway though. Why make superficial changes that > break working code and mentally overload programmers? Python is a > relatively mature language by now, so it shouldn't be messed with unless > the changes produce drastic benefits, not minor ones. A website still exists, but I don't see signs of a new language; looks like a watering hole for some techies. Prothon looked interesting as long as it promised to be about Python that used prototypes instead of classes to organize objects. What happened, though, was that it turned into a crusade to remove every Python wart that a bunch of people could imagine. The band of developers might have had the steam for the new object model, but they didn't have the steam to do everything. Mel. From mondalmousumi83 at gmail.com Sat Mar 3 09:30:03 2012 From: mondalmousumi83 at gmail.com (Mousumi Mondal) Date: Sat, 3 Mar 2012 06:30:03 -0800 (PST) Subject: easy earn money Message-ID: <26477972.867.1330785003730.JavaMail.geo-discussion-forums@pbbms5> money-internet-money.weebly.com money-internet-money.weebly.com money-internet-money.weebly.com money-internet-money.weebly.com money-internet-money.weebly.com money-internet-money.weebly.com money-internet-money.weebly.com money-internet-money.weebly.com From skip at pobox.com Sat Mar 3 10:47:03 2012 From: skip at pobox.com (skip at pobox.com) Date: Sat, 3 Mar 2012 09:47:03 -0600 (CST) Subject: Looking for people to take over some packages Message-ID: <20120303154703.96B1D2D1D239@montanaro.dyndns.org> I'm shifting life gears, trying to get away from the computer more during my hours away from work. As part of that, I'm looking to get out of the package authorship/maintenance business. Currently, I am officially listed as the "maintainer" (I use that term loosely - I really do very little at this time) of the following packages on PyPI (http://pypi.python.org/): bsddb185 lockfile spambayes tb Some time ago Ben Finney offered to take over lockfile. He doesn't want to horse around with Google Code and I don't want to learn how to use git/github just to make the existing code available to him. Perhaps someone with both Google Code and Github accounts can facilitate the exchange. Taking over the SpamBayes package probably implies a committment to greater involvement in the SpamBayes project (so be careful before you volunteer). It's worth poking around http://www.spambayes.org/. Bsddb185 is just a repackaging of the old bsddb185 module which got dropped from the Python core some years ago. It probably gets very little use, but last I looked, there were still some systems which used that versy of Berkeley DB. Tb provides a couple alternate traceback formatting functions. The compact_traceback function is an adaptation of the one generated by asyncore. The verbose_traceback function includes local variable values in the trace. If you have any interest in helping with any of these, let me know. -- Skip Montanaro - skip at pobox.com - http://www.smontanaro.net/ From anthra.norell at bluewin.ch Sat Mar 3 11:10:39 2012 From: anthra.norell at bluewin.ch (Frederic Rentsch) Date: Sat, 03 Mar 2012 17:10:39 +0100 Subject: How to read image data into Tkinter Canvas? Message-ID: <1330791039.2281.172.camel@hatchbox-one> Hi, Familiarizing myself with Tkinter I'm stuck trying to fill a Canvas with an image. I believe the class I need is PhotoImage rather than BitmapImage. But I have no luck with either. The PhotoImage doc lists available handlers for writing GIF and PPM files. It doesn't say anything about reading. I would assume that any widely used image format would activate the appropriate handler automatically. To work with formats other than GIF and PPM the doc recommends to resort to the Image module (PIL). This approach also failed. I did manage to read a GIF file into PhotoImage, which seems to let my code off the hook. And I have made sure beyond any doubt that my image files exist and open with PIL. I must be doing something wrong and will much appreciate any help. Frederic --------------------------------------------------------------------- Here's what happens: First trial with PhotoImage: . . . canvas = Canvas (root) picture = PhotoImage (file = "/home/fr/temp/wandbild.bmp") image = canvas.create_image (10, 10, anchor = NW, image = picture) . . . Traceback (most recent call last): File "tk2.py", line 23, in picture = PhotoImage (file = "/home/fr/temp/wandbild.bmp") File "/usr/lib/python2.6/lib-tk/Tkinter.py", line 3288, in __init__ Image.__init__(self, 'photo', name, cnf, master, **kw) File "/usr/lib/python2.6/lib-tk/Tkinter.py", line 3244, in __init__ self.tk.call(('image', 'create', imgtype, name,) + options) _tkinter.TclError: couldn't recognize data in image file "/home/fr/temp/wandbild.bmp" --------------------------------------------------------------------- Second trial with BitmapImage: . . . picture = BitmapImage (file = "/home/fr/temp/wandbild.bmp") . . . Traceback (most recent call last): File "tk2.py", line 22, in picture = BitmapImage (file = "/home/fr/temp/wandbild.bmp") File "/usr/lib/python2.6/lib-tk/Tkinter.py", line 3347, in __init__ Image.__init__(self, 'bitmap', name, cnf, master, **kw) File "/usr/lib/python2.6/lib-tk/Tkinter.py", line 3244, in __init__ self.tk.call(('image', 'create', imgtype, name,) + options) _tkinter.TclError: format error in bitmap data --------------------------------------------------------------------- Third trial with Image.open: . . . picture = Image.open ("/home/fr/temp/wandbild.bmp") print picture image = canvas.create_image (10, 10, anchor = NW, image = picture) . . . Traceback (most recent call last): File "tk2.py", line 24, in image = canvas.create_image (10, 10, anchor = NW, image = picture) File "/usr/lib/python2.6/lib-tk/Tkinter.py", line 2159, in create_image return self._create('image', args, kw) File "/usr/lib/python2.6/lib-tk/Tkinter.py", line 2150, in _create *(args + self._options(cnf, kw)))) _tkinter.TclError: image "" doesn't exist --------------------------------------------------------------------- Same thing happens with JPG files. As I said, GIF works into PhotoImage, but that's the only format I managed. From rmorgan466 at gmail.com Sat Mar 3 12:13:06 2012 From: rmorgan466 at gmail.com (Rita) Date: Sat, 3 Mar 2012 12:13:06 -0500 Subject: python library to generate restructured text Message-ID: Hello, I am using sqlite3 modules to get data out of a table. I would like to dump the table into a restructured-text (docutil) format. I was wondering if there was a library which would accomplish this. -- --- Get your facts first, then you can distort them as you please.-- -------------- next part -------------- An HTML attachment was scrubbed... URL: From emekamicro at gmail.com Sat Mar 3 12:28:58 2012 From: emekamicro at gmail.com (Emeka) Date: Sat, 3 Mar 2012 18:28:58 +0100 Subject: Udacity CS 101 In-Reply-To: <12911798.131.1330750034248.JavaMail.geo-discussion-forums@pbqn3> References: <28556790.1352.1330204852864.JavaMail.geo-discussion-forums@pbgq3> <12911798.131.1330750034248.JavaMail.geo-discussion-forums@pbqn3> Message-ID: Well, I checked unit 2 out the other day. It is indeed of poor standard and to some extend a waste of time for me. However, I see it as another way of having fun. On Sat, Mar 3, 2012 at 5:47 AM, Josh English wrote: > On Monday, February 27, 2012 6:37:25 PM UTC-8, Ray Clark wrote: > > > > You have to remember that this course assumes no prior computer > > programming knowledge. > > > > I agree, it is starting out very basic. Give it some more time. > > These guys have PhDs from MIT and/or have taught at Stanford. They > > know what they are doing. > > It seems to me that they're not starting with good Python practices, > really, or even the terminology I'd expect. > -- > http://mail.python.org/mailman/listinfo/python-list > -- *Satajanus Nig. Ltd * -------------- next part -------------- An HTML attachment was scrubbed... URL: From steve+comp.lang.python at pearwood.info Sat Mar 3 12:36:52 2012 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 03 Mar 2012 17:36:52 GMT Subject: Building Python with non-standard tcl/tk support Message-ID: <4f5256b4$0$29989$c3e8da3$5496439d@news.astraweb.com> I'm trying to re-build Python 3.2 with support for TCL/TK 8.5, but when I run "make" I get this message: Failed to build these modules: _tkinter and after installing 3.2 I still have this: >>> import _tkinter >>> _tkinter.TK_VERSION '8.4' What do I need to do to have Python 3.2 use tcl/tk 8.5? I have installed tcl/tk 8.5.11 from source, and the binaries are here: /usr/local/lib/libtcl8.5.so /usr/local/lib/libtk8.5.so In the Python 3.2 source, I do the usual: ./configure make sudo make altinstall (altinstall to avoid nuking the system Python) -- Steven From anikom15 at gmail.com Sat Mar 3 13:17:40 2012 From: anikom15 at gmail.com (Westley =?iso-8859-1?Q?Mart=EDnez?=) Date: Sat, 3 Mar 2012 10:17:40 -0800 Subject: Building Python with non-standard tcl/tk support In-Reply-To: <4f5256b4$0$29989$c3e8da3$5496439d@news.astraweb.com> References: <4f5256b4$0$29989$c3e8da3$5496439d@news.astraweb.com> Message-ID: <20120303181740.GA4587@kubrick> On Sat, Mar 03, 2012 at 05:36:52PM +0000, Steven D'Aprano wrote: > I'm trying to re-build Python 3.2 with support for TCL/TK 8.5, but when I > run "make" I get this message: > > Failed to build these modules: > _tkinter > > and after installing 3.2 I still have this: > > >>> import _tkinter > >>> _tkinter.TK_VERSION > '8.4' > > > What do I need to do to have Python 3.2 use tcl/tk 8.5? > > > I have installed tcl/tk 8.5.11 from source, and the binaries are here: > > /usr/local/lib/libtcl8.5.so > /usr/local/lib/libtk8.5.so > > > In the Python 3.2 source, I do the usual: > > ./configure > make > sudo make altinstall > > > (altinstall to avoid nuking the system Python) That's all you should have to do, but on my system the Tk libraries are in /usr/lib not /usr/local/lib. So try doing ./configure --prefix=/usr/local or try setting LDFLAGS to "-L/usr/local/lib". From ben+python at benfinney.id.au Sat Mar 3 16:43:47 2012 From: ben+python at benfinney.id.au (Ben Finney) Date: Sun, 04 Mar 2012 08:43:47 +1100 Subject: Adopting =?utf-8?B?4oCYbG9ja2ZpbGXigJk=?= (was: Looking for people to take over some packages) References: Message-ID: <874nu5nywc.fsf@benfinney.id.au> skip at pobox.com writes: > Some time ago Ben Finney offered to take over lockfile. That offer is still open. (Though I would appreciate ongoing development help from people who use non-Linux operating systems, since file locking works differently there and I don't have the resources to test on those.) > He doesn't want to horse around with Google Code and I don't want to > learn how to use git/github just to make the existing code available > to him. Perhaps someone with both Google Code and Github accounts can > facilitate the exchange. I don't see a need to horse around with Git either :-) It's currently in Subversion, right? Can you not export the VCS history from Google Code's Subversion repository to a ?fastimport? stream? Maybe someone with experience on that site can help us. > If you have any interest in helping with any of these, let me know. Thanks for the responsible move to seek adoption for these projects. -- \ ?I'd take the awe of understanding over the awe of ignorance | `\ any day.? ?Douglas Adams | _o__) | Ben Finney From steve+comp.lang.python at pearwood.info Sat Mar 3 19:50:53 2012 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 04 Mar 2012 00:50:53 GMT Subject: Building Python with non-standard tcl/tk support References: <4f5256b4$0$29989$c3e8da3$5496439d@news.astraweb.com> Message-ID: <4f52bc6d$0$29989$c3e8da3$5496439d@news.astraweb.com> On Sat, 03 Mar 2012 10:17:40 -0800, Westley Mart?nez wrote: > On Sat, Mar 03, 2012 at 05:36:52PM +0000, Steven D'Aprano wrote: >> I'm trying to re-build Python 3.2 with support for TCL/TK 8.5, but when >> I run "make" I get this message: >> >> Failed to build these modules: >> _tkinter >> >> and after installing 3.2 I still have this: >> >> >>> import _tkinter >> >>> _tkinter.TK_VERSION >> '8.4' >> >> >> What do I need to do to have Python 3.2 use tcl/tk 8.5? >> >> >> I have installed tcl/tk 8.5.11 from source, and the binaries are here: >> >> /usr/local/lib/libtcl8.5.so >> /usr/local/lib/libtk8.5.so >> >> >> In the Python 3.2 source, I do the usual: >> >> ./configure >> make >> sudo make altinstall >> >> >> (altinstall to avoid nuking the system Python) > > That's all you should have to do, but on my system the Tk libraries are > in /usr/lib not /usr/local/lib. So try doing ./configure > --prefix=/usr/local or try setting LDFLAGS to "-L/usr/local/lib". Thanks, but that doesn't work. "make" still says it failed to build _tkinter, and after "make altinstall" it still picks up tck/tkl 8.4. Okay, now I'm making progress... if I remove the previously existing _tkinter in lib-dynload, and re-run "make", I get something new: building '_tkinter' extension gcc -pthread -fPIC -fno-strict-aliasing -DNDEBUG -g -fwrapv -O3 -Wall - Wstrict-prototypes -DWITH_APPINIT=1 -I/usr/X11/include -IInclude -I. -I./ Include -I/usr/local/include -I/tmp/Python-3.2.2 -c /tmp/Python-3.2.2/ Modules/_tkinter.c -o build/temp.linux-i686-3.2/tmp/Python-3.2.2/Modules/ _tkinter.o gcc -pthread -fPIC -fno-strict-aliasing -DNDEBUG -g -fwrapv -O3 -Wall - Wstrict-prototypes -DWITH_APPINIT=1 -I/usr/X11/include -IInclude -I. -I./ Include -I/usr/local/include -I/tmp/Python-3.2.2 -c /tmp/Python-3.2.2/ Modules/tkappinit.c -o build/temp.linux-i686-3.2/tmp/Python-3.2.2/Modules/ tkappinit.o gcc -pthread -shared build/temp.linux-i686-3.2/tmp/Python-3.2.2/Modules/ _tkinter.o build/temp.linux-i686-3.2/tmp/Python-3.2.2/Modules/tkappinit.o -L/usr/X11/lib -L/usr/local/lib -ltk8.5 -ltcl8.5 -lX11 -o build/lib.linux- i686-3.2/_tkinter.cpython-32m.so *** WARNING: renaming "_tkinter" since importing it failed: libtk8.5.so: cannot open shared object file: No such file or directory Failed to build these modules: _tkinter -- Steven From anikom15 at gmail.com Sat Mar 3 20:06:39 2012 From: anikom15 at gmail.com (Westley =?iso-8859-1?Q?Mart=EDnez?=) Date: Sat, 3 Mar 2012 17:06:39 -0800 Subject: Building Python with non-standard tcl/tk support In-Reply-To: <4f52bc6d$0$29989$c3e8da3$5496439d@news.astraweb.com> References: <4f5256b4$0$29989$c3e8da3$5496439d@news.astraweb.com> <4f52bc6d$0$29989$c3e8da3$5496439d@news.astraweb.com> Message-ID: <20120304010639.GA26758@kubrick> On Sun, Mar 04, 2012 at 12:50:53AM +0000, Steven D'Aprano wrote: > Okay, now I'm making progress... if I remove the previously existing > _tkinter in lib-dynload, and re-run "make", I get something new: > > building '_tkinter' extension > gcc -pthread -fPIC -fno-strict-aliasing -DNDEBUG -g -fwrapv -O3 -Wall - > Wstrict-prototypes -DWITH_APPINIT=1 -I/usr/X11/include -IInclude -I. -I./ > Include -I/usr/local/include -I/tmp/Python-3.2.2 -c /tmp/Python-3.2.2/ > Modules/_tkinter.c -o build/temp.linux-i686-3.2/tmp/Python-3.2.2/Modules/ > _tkinter.o > gcc -pthread -fPIC -fno-strict-aliasing -DNDEBUG -g -fwrapv -O3 -Wall - > Wstrict-prototypes -DWITH_APPINIT=1 -I/usr/X11/include -IInclude -I. -I./ > Include -I/usr/local/include -I/tmp/Python-3.2.2 -c /tmp/Python-3.2.2/ > Modules/tkappinit.c -o build/temp.linux-i686-3.2/tmp/Python-3.2.2/Modules/ > tkappinit.o > gcc -pthread -shared build/temp.linux-i686-3.2/tmp/Python-3.2.2/Modules/ > _tkinter.o build/temp.linux-i686-3.2/tmp/Python-3.2.2/Modules/tkappinit.o > -L/usr/X11/lib -L/usr/local/lib -ltk8.5 -ltcl8.5 -lX11 -o build/lib.linux- > i686-3.2/_tkinter.cpython-32m.so > *** WARNING: renaming "_tkinter" since importing it failed: libtk8.5.so: > cannot open shared object file: No such file or directory > > Failed to build these modules: > _tkinter Verify that libtk8.5.so exists in /usr/local/lib and verify you have read permission. You could try to write a Tk C program (or find one) and try building that with cc -L/usr/X11/lib -L/usr/local/lib -ltk8.5 -ltcl8.5 -lX11 . If that works then your Tk libraries are installed properly and something is wonky with your Python build. From steve+comp.lang.python at pearwood.info Sat Mar 3 21:39:18 2012 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 04 Mar 2012 02:39:18 GMT Subject: Building Python with non-standard tcl/tk support References: <4f5256b4$0$29989$c3e8da3$5496439d@news.astraweb.com> <4f52bc6d$0$29989$c3e8da3$5496439d@news.astraweb.com> Message-ID: <4f52d5d6$0$29989$c3e8da3$5496439d@news.astraweb.com> On Sat, 03 Mar 2012 17:06:39 -0800, Westley Mart?nez wrote: > On Sun, Mar 04, 2012 at 12:50:53AM +0000, Steven D'Aprano wrote: >> Okay, now I'm making progress... if I remove the previously existing >> _tkinter in lib-dynload, and re-run "make", I get something new: >> >> building '_tkinter' extension >> gcc -pthread -fPIC -fno-strict-aliasing -DNDEBUG -g -fwrapv -O3 -Wall - >> Wstrict-prototypes -DWITH_APPINIT=1 -I/usr/X11/include -IInclude -I. >> -I./ Include -I/usr/local/include -I/tmp/Python-3.2.2 -c >> /tmp/Python-3.2.2/ Modules/_tkinter.c -o >> build/temp.linux-i686-3.2/tmp/Python-3.2.2/Modules/ _tkinter.o >> gcc -pthread -fPIC -fno-strict-aliasing -DNDEBUG -g -fwrapv -O3 -Wall - >> Wstrict-prototypes -DWITH_APPINIT=1 -I/usr/X11/include -IInclude -I. >> -I./ Include -I/usr/local/include -I/tmp/Python-3.2.2 -c >> /tmp/Python-3.2.2/ Modules/tkappinit.c -o >> build/temp.linux-i686-3.2/tmp/Python-3.2.2/Modules/ tkappinit.o >> gcc -pthread -shared >> build/temp.linux-i686-3.2/tmp/Python-3.2.2/Modules/ _tkinter.o >> build/temp.linux-i686-3.2/tmp/Python-3.2.2/Modules/tkappinit.o >> -L/usr/X11/lib -L/usr/local/lib -ltk8.5 -ltcl8.5 -lX11 -o >> build/lib.linux- i686-3.2/_tkinter.cpython-32m.so >> *** WARNING: renaming "_tkinter" since importing it failed: >> libtk8.5.so: cannot open shared object file: No such file or directory >> >> Failed to build these modules: >> _tkinter > > Verify that libtk8.5.so exists in /usr/local/lib and verify you have > read permission. [steve at ando ~]$ ls -l /usr/local/lib/*tk*.so -r-xr-xr-x 1 root root 1233986 Mar 4 04:01 /usr/local/lib/libtk8.5.so [steve at ando ~]$ ls -l /usr/local/lib/*tcl*.so -r-xr-xr-x 1 root root 1133948 Mar 4 03:55 /usr/local/lib/libtcl8.5.so -- Steven From rantingrickjohnson at gmail.com Sat Mar 3 23:27:43 2012 From: rantingrickjohnson at gmail.com (Rick Johnson) Date: Sat, 3 Mar 2012 20:27:43 -0800 (PST) Subject: Is it necessary to call Tk() when writing a GUI app with Tkinter? References: <27603449.17.1330492001624.JavaMail.geo-discussion-forums@vbbfv2> <6e1c521e-14be-4ec0-9ff0-7f23fd9cd3dc@f14g2000yqe.googlegroups.com> <17153317.324.1330576905540.JavaMail.geo-discussion-forums@yncd8> <11188032.247.1330726606861.JavaMail.geo-discussion-forums@ynbq18> Message-ID: On Mar 2, 4:16?pm, John Salerno wrote: > what is the point of creating a Frame object at all? I tried NOT > doing it, like you said, and it seemed to work fine with my simple > example. But is there a benefit to using a Frame object to group the > widgets together? Or is it cleaner to just use the Tk object? You will no doubt need to use frames to group widgets from time to time. My previous point was simply: "don't use frames superfluously!". Here is an example of creating a custom compound widget by sub- classing frame (psst: this widget already exists in the Tix extension. ## START CODE ## import Tkinter as tk from Tkconstants import LEFT, YES, X, N class LabelEntry(tk.Frame): def __init__(self, master, text='LE', **kw): tk.Frame.__init__(self, master, **kw) self.label = tk.Label(self, text=text, font=('Courier New', 12)) self.label.pack(side=LEFT) self.entry = tk.Entry(self) self.entry.pack(side=LEFT, fill=X, expand=YES) def get(self): return self.entry.get() def set(self, arg): self.entry.delete(0, 'end') self.entry.set(arg) if __name__ == '__main__': root = tk.Tk() for blah in (' Name:', 'Address:', ' Phone:'): w = LabelEntry(root, text=blah) w.pack(fill=X, expand=YES, anchor=N, padx=5, pady=5) root.mainloop() ## END CODE ## From gdamjan at gmail.com Sun Mar 4 00:38:44 2012 From: gdamjan at gmail.com (Damjan Georgievski) Date: Sun, 04 Mar 2012 06:38:44 +0100 Subject: The original command python line Message-ID: <4obb29-os3.ln1@archaeopteryx.softver.org.mk> How can I get the *really* original command line that started my python interpreter? Werkzeug has a WSGI server which reloads itself when files are changed on disk. It uses `args = [sys.executable] + sys.argv` to kind of recreate the command line, and the uses subprocess.call to run that command line. BUT that's problematic as, when you run:: python -m mypackage --config sys.argv printed in mypackage/__main__.py will be:: ['/full/path/to/mypackage/__main__.py', '--config'] so you get:: python /full/path/to/mypackage/__main__.py --config instead of:: python -m mypackage --config the difference in the 2 cases is what the current package is, and whether you can use relative imports. -- damjan From clp2 at rebertia.com Sun Mar 4 00:48:58 2012 From: clp2 at rebertia.com (Chris Rebert) Date: Sat, 3 Mar 2012 21:48:58 -0800 Subject: The original command python line In-Reply-To: <4obb29-os3.ln1@archaeopteryx.softver.org.mk> References: <4obb29-os3.ln1@archaeopteryx.softver.org.mk> Message-ID: On Sat, Mar 3, 2012 at 9:38 PM, Damjan Georgievski wrote: > How can I get the *really* original command line that started my python > interpreter? > > Werkzeug has a WSGI server which reloads itself when files are changed > on disk. It uses `args = [sys.executable] + sys.argv` to kind of > recreate the command line, and the uses subprocess.call to run that > command line. > > BUT that's problematic as, when you run:: > > ? ? ? ?python -m mypackage --config > > sys.argv printed in mypackage/__main__.py will be:: > > ? ? ? ?['/full/path/to/mypackage/__main__.py', '--config'] > > so you get:: > > ? ? ? ?python /full/path/to/mypackage/__main__.py --config > > instead of:: > > ? ? ? ?python -m mypackage --config > > > the difference in the 2 cases is what the current package is, and > whether you can use relative imports. On Linux, you can read from: /proc//cmdline to get the null-delimited "command line". Sidenote: Consensus generally seems to be that relative imports are a bad idea. Cheers, Chris From gdamjan at gmail.com Sun Mar 4 00:52:26 2012 From: gdamjan at gmail.com (Damjan Georgievski) Date: Sun, 04 Mar 2012 06:52:26 +0100 Subject: The original python command line In-Reply-To: <4obb29-os3.ln1@archaeopteryx.softver.org.mk> References: <4obb29-os3.ln1@archaeopteryx.softver.org.mk> Message-ID: > How can I get the *really* original command line that started my python > interpreter? > > Werkzeug has a WSGI server which reloads itself when files are changed > on disk. It uses `args = [sys.executable] + sys.argv` to kind of > recreate the command line, and the uses subprocess.call to run that > command line. > > BUT that's problematic as, when you run:: > > python -m mypackage --config > > sys.argv printed in mypackage/__main__.py will be:: > > ['/full/path/to/mypackage/__main__.py', '--config'] > > so you get:: > > python /full/path/to/mypackage/__main__.py --config > > instead of:: > > python -m mypackage --config > > > the difference in the 2 cases is what the current package is, and > whether you can use relative imports. BTW, the same thing happens in Python 3.2.2. To reproduce:: mkdir /tmp/X cd /tmp/X mkdir mypackage touch mypackage/__init__.py mypackage/dummy.py cat < mypackage/__main__.py from __future__ import print_function, absolute_import import os, sys, subprocess def rerun(): new_environ = os.environ.copy() new_environ['TEST_CHILD'] = 'true' args = [sys.executable] + sys.argv subprocess.call(args, env=new_environ) if os.environ.get('TEST_CHILD') != 'true': Role = 'Parent' rerun() else: Role = 'Child' try: from . import dummy except: print('Exception in %s' % Role) else: print('Success in %s' % Role) EOF Both:: python2 -m mypackage or:: python3 -m mypackage will print:: Exception in Child Success in Parent From clp2 at rebertia.com Sun Mar 4 00:57:42 2012 From: clp2 at rebertia.com (Chris Rebert) Date: Sat, 3 Mar 2012 21:57:42 -0800 Subject: The original command python line In-Reply-To: References: <4obb29-os3.ln1@archaeopteryx.softver.org.mk> Message-ID: On Sat, Mar 3, 2012 at 9:48 PM, Chris Rebert wrote: > On Sat, Mar 3, 2012 at 9:38 PM, Damjan Georgievski wrote: >> How can I get the *really* original command line that started my python >> interpreter? > On Linux, you can read from: > ? ?/proc//cmdline > to get the null-delimited "command line". After some further searching: psutil offers `Process.cmdline` cross-platform; see http://code.google.com/p/psutil/wiki/Documentation Cheers, Chris From gdamjan at gmail.com Sun Mar 4 01:20:28 2012 From: gdamjan at gmail.com (Damjan Georgievski) Date: Sun, 04 Mar 2012 07:20:28 +0100 Subject: The original command python line In-Reply-To: References: <4obb29-os3.ln1@archaeopteryx.softver.org.mk> Message-ID: >>> How can I get the *really* original command line that started my python >>> interpreter? > >> On Linux, you can read from: >> /proc//cmdline >> to get the null-delimited "command line". > > After some further searching: > psutil offers `Process.cmdline` cross-platform; > see http://code.google.com/p/psutil/wiki/Documentation Indeed, changing for args = psutil.Process(os.getpid()).cmdline in the above example does solve the problem, at least in Linux. > Sidenote: Consensus generally seems to be that relative imports are a bad idea. How come? I'm using explicit relative imports, I thought they were the new thing? -- damjan From jeanpierreda at gmail.com Sun Mar 4 02:19:25 2012 From: jeanpierreda at gmail.com (Devin Jeanpierre) Date: Sun, 4 Mar 2012 02:19:25 -0500 Subject: The original command python line In-Reply-To: References: <4obb29-os3.ln1@archaeopteryx.softver.org.mk> Message-ID: On Sun, Mar 4, 2012 at 1:20 AM, Damjan Georgievski wrote: > How come? > I'm using explicit relative imports, I thought they were the new thing? Explicit relative imports are fine. Implicit relative imports can create multiple module objects for the same source file, which breaks things like exception handling (because exception types are unequal if they're from different classes, even if the different classes come from two executions of the same source code). -- Devin From frank at chagford.com Sun Mar 4 03:15:57 2012 From: frank at chagford.com (Frank Millman) Date: Sun, 4 Mar 2012 10:15:57 +0200 Subject: Trying to understand 'import' a bit better Message-ID: Hi all I have been using 'import' for ages without particularly thinking about it - it just works. Now I am having to think about it a bit harder, and I realise it is a bit more complicated than I had realised - not *that* complicated, but there are some subtleties. I don't know the correct terminology, but I want to distinguish between the following two scenarios - 1. A python 'program', that is self contained, has some kind of startup, invokes certain functionality, and then closes. 2. A python 'library', that exposes functionality to other python programs, but relies on the other program to invoke its functionality. The first scenario has the following characteristics - - it can consist of a single script or a number of modules - if the latter, the modules can all be in the same directory, or in one or more sub-directories - if they are in sub-directories, the sub-directory must contain __init__.py, and is referred to as a sub-package - the startup script will normally be in the top directory, and will be executed directly by the user When python executes a script, it automatically places the directory containing the script into 'sys.path'. Therefore the script can import a top-level module using 'import ', and a sub-package module using 'import .'. The second scenario has similar characteristics, except it will not have a startup script. In order for a python program to make use of the library, it has to import it. In order for python to find it, the directory containing it has to be in sys.path. In order for python to recognise the directory as a valid container, it has to contain __init__.py, and is referred to as a package. To access a module of the package, the python program must use 'import .' (or 'from import '), and to access a sub-package module it must use 'import ... So far so uncontroversial (I hope). The subtlety arises when the package wants to access its own modules. Instead of using 'import ' it must use 'import .'. This is because the directory containing the package is in sys.path, but the package itself is not. It is possible to insert the package directory name into sys.path as well, but as was pointed out recently, this is dangerous, because you can end up with the same module imported twice under different names, with potentially disastrous consequences. Therefore, as I see it, if you are developing a project using scenario 1 above, and then want to change it to scenario 2, you have to go through the entire project and change all import references by prepending the package name. Have I got this right? Frank Millman From web.elektro.net at gmail.com Sun Mar 4 04:03:56 2012 From: web.elektro.net at gmail.com (Sirotin Roman) Date: Sun, 4 Mar 2012 16:03:56 +0700 Subject: Jython callable. How? Message-ID: Hi. How exactly jython decides is object callable or not? I defined __call__ method but interpreter says it's still not callable. BTW, my code works in cpython From arnodel at gmail.com Sun Mar 4 05:17:59 2012 From: arnodel at gmail.com (Arnaud Delobelle) Date: Sun, 4 Mar 2012 10:17:59 +0000 Subject: Jython callable. How? In-Reply-To: References: Message-ID: On Mar 4, 2012 9:04 AM, "Sirotin Roman" wrote: > > Hi. > How exactly jython decides is object callable or not? I defined > __call__ method but interpreter says it's still not callable. > BTW, my code works in cpython It will help if you show us the code. -- Arnaud -------------- next part -------------- An HTML attachment was scrubbed... URL: From steve+comp.lang.python at pearwood.info Sun Mar 4 05:26:04 2012 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 04 Mar 2012 10:26:04 GMT Subject: Jython callable. How? References: Message-ID: <4f53433c$0$29989$c3e8da3$5496439d@news.astraweb.com> On Sun, 04 Mar 2012 16:03:56 +0700, Sirotin Roman wrote: > Hi. > How exactly jython decides is object callable or not? I defined __call__ > method but interpreter says it's still not callable. BTW, my code works > in cpython Works for me. steve at runes:~$ jython *sys-package-mgr*: processing modified jar, '/usr/share/java/servlet- api-2.5.jar' Jython 2.5.1+ (Release_2_5_1, Aug 4 2010, 07:18:19) [OpenJDK Client VM (Sun Microsystems Inc.)] on java1.6.0_18 Type "help", "copyright", "credits" or "license" for more information. >>> >>> class Test: ... def __call__(self): ... return 42 ... >>> >>> x = Test() >>> x() 42 Perhaps if you show us what you actually do, and what happens, we might be able to tell you what is happening. Please COPY AND PASTE the full traceback. -- Steven From petr.jakes.tpc at gmail.com Sun Mar 4 05:28:16 2012 From: petr.jakes.tpc at gmail.com (Petr Jakes) Date: Sun, 4 Mar 2012 02:28:16 -0800 (PST) Subject: How to convert simple B/W graphic to the dot matrix for the LED display/sign Message-ID: <94052541-e1e0-43b6-b434-59e79518cf4a@q18g2000yqh.googlegroups.com> I would like to convert simple B/W graphic to the 432x64 pixel matrix. It is intended to display this graphic on the one color LED matrix sign/display (432 LEDs width, 64 LEDs height). I am experimenting with the PIL, but I did not find solution there. It will be really helpful If somebody here can show me the direction to go? Regards Petr From bv4bv4bv4 at gmail.com Sun Mar 4 05:44:27 2012 From: bv4bv4bv4 at gmail.com (BV BV) Date: Sun, 4 Mar 2012 02:44:27 -0800 (PST) Subject: IF JESUS WAS GOD !!!!!!!!!!!! Message-ID: <7a3d9843-436e-40ce-84fc-b22df4aca010@w32g2000vbt.googlegroups.com> IF JESUS WAS GOD If Jesus was GOD, then why in Mark 12:29 Jesus said "Here, O Israel: The Lord our God is one Lord." The words "our God" indicate that Jesus had a higher God over him, a stronger God than him. Jesus didn't say "Your God". He said "our God" which includes Jesus as the creation of GOD. If Jesus was GOD, then why in John 20:17 Jesus said I ascend to my God and your God? This tells us that we and Jesus have a common GOD. If Jesus was GOD, then why in John 8:28 Jesus said "I do nothing of myself"? Can't GOD do anything he wills? If Jesus was GOD, then why in John 14:28 Jesus said "My Father (GOD) is greater than I"?If Jesus was GOD, then why in Luke 23:46 Jesus said "Father (GOD), into thy hands I commend my spirit"? If Jesus was GOD, then why in Matthew 19:16 Jesus said "Why call me good, there is none good but One, that is GOD"? If Jesus was GOD, then why in Matthew 26:39 Jesus begged his GOD to have mercy on him and to pass the cup to death (kill Jesus in another words) before Jesus goes through the pain of crucifixion? Also see: Jesus's crucifixion in Islam If Jesus was GOD, then why in John 18:38 he didn't reply when he was asked about the truth? If Jesus was GOD, then why in Matthew 24:36 Jesus told his followers that no one (including Jesus) knows when the judgment day will come, only GOD knows? If Jesus was GOD, then why in Isiah 11:2-3 GOD had put the spirit of fearing GOD in Jesus? If Jesus was GOD, then why in John 5:31 Jesus told his followers that if he (Jesus) bears witness of himself, then his record is not true? If Jesus was GOD, then why in John 5:30 Jesus told his followers that he can't do a single thing of his own initiative? If Jesus was GOD, then why in John 5:36-38 Jesus said that GOD had assigned him (Jesus) work and GOD is a witness on Jesus? If Jesus was GOD, then why in John 5:32 Jesus told his followers that they have never seen GOD at anytime nor ever heard his voice? If Jesus was GOD, then why did he pray to his GOD in Luke 5:16? If Jesus was GOD, then why in Matthew 26:39 Jesus fell on his face and prayed to his GOD? The "God" Title: How come Christians take the "God" (theos in Greek) title literally with Jesus in Isiah 9:6 and they don't take it literally for the rest of the prophets and people who were called Gods ? The Prophets who were called "God" in the Bible are as follows: Prophet Moses in Exodus 7:1 The Devil in Corinthians 4:4 (the word for God in this verse is theos in Greek, the same used for Jesus that was translated as "God") Multiple Prophets in Psalms 82:6 King David in Psalm 45:3 Note: The only unique title given to GOD in the Bible that was not given to others at all are Jehova, GOD, and GOD LORD. "God", "Most Mighty" and "Almighty One" are titles that were given to Jesus, other Prophets and to Satan himself in the Bible. Very important note: Did you know that in the languages of Arabic and Hebrew the father of the house can be called the God of the house? Jesus was the God (father or leader) of his people and their father according to Isiah 9:6. Jesus being the leader and the king, it is normal for him to be called the father of his people (Father in Isiah 9:6), and because he is their father he automatically becomes their God. My father is my God in Arabic and Hebrew. The "Son" Title: How come Christians take the "God's Son" title literally with Jesus and they don't take it literally for the rest of the prophets and people who were called the Sons of God? In John 3:16 Jesus was called God's only Begotten Son. In Exodus 4:22 "Thus saith Jehova, Isreal is my son, even my firstborn." Isreal was called God's First Son. In Jeremiah 31:9 "I am a father to Isreal, and Ephraim is my firstborn." Ephraim is God's First Son and First Born.In Psalm 2:7 "... Jehova had said onto me (David), thou art my Son; this day have I begotten thee." David was called God's Begotten Son. Were Jesus's Miracle's Unique? If Jesus is believed to be GOD because he could do miracles, he could heal leprosy, he could cause blind men to see, or raise the dead, then what about the others who performed the same miracles? Elisha and Elijah fed a hundred people with twenty barley loaves and a few ears of corn (2 Kings 4:44). [Elisha told Naaman, who was a leper, to wash in the river Jordan (2 Kings 5:14) and he was healed. Elisha caused a blind man to see in (2 Kings 6:17,20). Elijah and Elisha raised the dead in (1 Kings 17:22, and 2 Kings 4:34). Even Elisha's dead bones restored a dead body in (2 Kings 13:21). Indeed Jesus had prophesied that people will worship him uselessly and will believe in doctrines not made by GOD but by men "But in vain they do worship me, teaching for doctrines the commandments of men. (Matthew 15:9)" In Matthew 15:9 above, we see Jesus warning that Trinity (the bogus lie) will dominate, and people will take Jesus as GOD and worship him, which is a total sin according to what Jesus said !! Allah Almighty (GOD) in the Noble Quran (The Muslims' Holy Scripture) states in Verse 5:72 "They do blaspheme who say: 'God is Christ the son of Mary.' But said Christ: 'O Children of Isreal ! worship God, my Lord and your Lord.' " Also in Noble Verse 5:73 "They do blaspheme who say God is one of three in a Trinity: for there is no god except One God. If they desist not from their word (of blasphemy), verily a grievous penalty will befall the blasphemers among them." And also in Noble Verse 4:171 "O People of the Book! Commit no excesses in your religion: Nor say of God aught but the truth. Christ Jesus the son of Mary was (no more than) an apostle of God, ..." The Point that I am trying to prove: Muslims believe that Prophet Jesus peace be upon him is a messenger from God. He was sent from God Almighty to deliver God's words to his people. Jesus was never God, nor ever claimed to be God. Jesus was a humble wonderful human being just like the rest of the Prophets and Messengers of God. Muslims also believe that Jesus was never crucified, nor ever died on the cross, nor ever wanted to die on the cross, nor ever was sent to earth to die on the cross . For more information about Islam http://www.islam-guide.com http://www.islamhouse.com/s/9661 http://www.thisistruth.org http://www.quran-m.com/firas/en1 http://kaheel7.com/eng http://www.knowmuhammad.com http://www.rasoulallah.net/v2/index.aspx?lang=e http://imanway1.com/eng http://www.todayislam.com http://www.thekeytoislam.com http://www.islamland.com http://www.discoverislam.com http://www.thetruereligion.org http://www.beconvinced.com http://islamtomorrow.com http://www.usc.edu/dept/MSA/quran http://www.quranforall.org http://www.quranexplorer.com/quran http://www.prophetmuhammed.org http://chatislamonline.org/en/ http://www.dar-us-salam.com http://youtubeislam.com From steve+comp.lang.python at pearwood.info Sun Mar 4 05:54:42 2012 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 04 Mar 2012 10:54:42 GMT Subject: How to convert simple B/W graphic to the dot matrix for the LED display/sign References: <94052541-e1e0-43b6-b434-59e79518cf4a@q18g2000yqh.googlegroups.com> Message-ID: <4f5349f2$0$29989$c3e8da3$5496439d@news.astraweb.com> On Sun, 04 Mar 2012 02:28:16 -0800, Petr Jakes wrote: > I would like to convert simple B/W graphic to the 432x64 pixel matrix. > It is intended to display this graphic on the one color LED matrix > sign/display (432 LEDs width, 64 LEDs height). I am experimenting with > the PIL, but I did not find solution there. > > It will be really helpful If somebody here can show me the direction to > go? What file format is the graphic in? How big is it? What file format do you want it to be? -- Steven From drakefjustin at gmail.com Sun Mar 4 05:58:50 2012 From: drakefjustin at gmail.com (Justin Drake) Date: Sun, 4 Mar 2012 10:58:50 +0000 Subject: Porting Python to an embedded system Message-ID: I am working with an ARM Cortex M3 on which I need to port Python (without operating system). What would be my best approach? I just need the core Python and basic I/O. From A.Lloyd.Flanagan at gmail.com Sun Mar 4 07:37:05 2012 From: A.Lloyd.Flanagan at gmail.com (A. Lloyd Flanagan) Date: Sun, 4 Mar 2012 04:37:05 -0800 (PST) Subject: A possible change to decimal.Decimal? In-Reply-To: References: <15610330.329.1330728373676.JavaMail.geo-discussion-forums@ynlw24> Message-ID: <6422978.686.1330864625195.JavaMail.geo-discussion-forums@vbgu10> On Friday, March 2, 2012 6:49:39 PM UTC-5, Ethan Furman wrote: > Jeff Beardsley wrote: > > HISTORY: ... > > What you should be doing is: > > import decimal > from decimal import Decimal > > reload(decimal) > Decimal = decimal.Decimal # (rebind 'Decimal' to the reloaded code) > > ~Ethan~ Agree that's how the import should be done. On the other hand, removing gratuitous use of isinstance() is generally a Good Thing. From A.Lloyd.Flanagan at gmail.com Sun Mar 4 07:37:05 2012 From: A.Lloyd.Flanagan at gmail.com (A. Lloyd Flanagan) Date: Sun, 4 Mar 2012 04:37:05 -0800 (PST) Subject: A possible change to decimal.Decimal? In-Reply-To: References: <15610330.329.1330728373676.JavaMail.geo-discussion-forums@ynlw24> Message-ID: <6422978.686.1330864625195.JavaMail.geo-discussion-forums@vbgu10> On Friday, March 2, 2012 6:49:39 PM UTC-5, Ethan Furman wrote: > Jeff Beardsley wrote: > > HISTORY: ... > > What you should be doing is: > > import decimal > from decimal import Decimal > > reload(decimal) > Decimal = decimal.Decimal # (rebind 'Decimal' to the reloaded code) > > ~Ethan~ Agree that's how the import should be done. On the other hand, removing gratuitous use of isinstance() is generally a Good Thing. From petr.jakes.tpc at gmail.com Sun Mar 4 07:47:55 2012 From: petr.jakes.tpc at gmail.com (Petr Jakes) Date: Sun, 4 Mar 2012 04:47:55 -0800 (PST) Subject: How to convert simple B/W graphic to the dot matrix for the LED display/sign References: <94052541-e1e0-43b6-b434-59e79518cf4a@q18g2000yqh.googlegroups.com> <4f5349f2$0$29989$c3e8da3$5496439d@news.astraweb.com> Message-ID: > What file format is the graphic in? How big is it? > > What file format do you want it to be? > Now, I am able to create the png file with the resolution 432x64 using PIL (using draw.text method for example). I would like to get the 432x64 True/False (Black/White) lookup table from this file, so I can switch LEDs ON/OFF accordingly. -- Petr From stefan_ml at behnel.de Sun Mar 4 08:00:54 2012 From: stefan_ml at behnel.de (Stefan Behnel) Date: Sun, 04 Mar 2012 14:00:54 +0100 Subject: Porting Python to an embedded system In-Reply-To: References: Message-ID: Justin Drake, 04.03.2012 11:58: > I am working with an ARM Cortex M3 on which I need to port Python > (without operating system). What would be my best approach? I just > need the core Python and basic I/O. The "without operating system" bit should prove problematic. Can't you just install Linux on it? Stefan From jeanpierreda at gmail.com Sun Mar 4 08:40:07 2012 From: jeanpierreda at gmail.com (Devin Jeanpierre) Date: Sun, 4 Mar 2012 08:40:07 -0500 Subject: Porting Python to an embedded system In-Reply-To: References: Message-ID: On Sun, Mar 4, 2012 at 5:58 AM, Justin Drake wrote: > I am working with an ARM Cortex M3 on which I need to port Python > (without operating system). What would be my best approach? I just > need the core Python and basic I/O. How much time are you willing to budget to this? Porting something to bare metal is not a small task. It's probably only worth it if you're doing it for academic purposes. I expect for anything real-world it'd be faster to do whatever it is you want to do using something that already runs on the bare metal. (e.g. http://armpit.sourceforge.net/ for Scheme). There used to be Flux OSKit ( http://www.cs.utah.edu/flux/oskit/ ) for porting languages to bare metal, but it doesn't support ARM and it's been dead a while. If you're really set on this, I'd try to see if there's something similar out there, somewhere. 'cause writing an OS from scratch would suck. -- Devin From duane.kaufman at gmail.com Sun Mar 4 08:56:15 2012 From: duane.kaufman at gmail.com (TheSeeker) Date: Sun, 4 Mar 2012 05:56:15 -0800 (PST) Subject: Porting Python to an embedded system In-Reply-To: References: Message-ID: <25340636.264.1330869375770.JavaMail.geo-discussion-forums@ynne2> On Sunday, March 4, 2012 4:58:50 AM UTC-6, Justin Drake wrote: > I am working with an ARM Cortex M3 on which I need to port Python > (without operating system). What would be my best approach? I just > need the core Python and basic I/O. The python-on-a-chip project (p14p) (http://code.google.com/p/python-on-a-chip/) might be something worth looking into. Thanks, Duane From duane.kaufman at gmail.com Sun Mar 4 08:56:15 2012 From: duane.kaufman at gmail.com (TheSeeker) Date: Sun, 4 Mar 2012 05:56:15 -0800 (PST) Subject: Porting Python to an embedded system In-Reply-To: References: Message-ID: <25340636.264.1330869375770.JavaMail.geo-discussion-forums@ynne2> On Sunday, March 4, 2012 4:58:50 AM UTC-6, Justin Drake wrote: > I am working with an ARM Cortex M3 on which I need to port Python > (without operating system). What would be my best approach? I just > need the core Python and basic I/O. The python-on-a-chip project (p14p) (http://code.google.com/p/python-on-a-chip/) might be something worth looking into. Thanks, Duane From maxerickson at gmail.com Sun Mar 4 09:09:23 2012 From: maxerickson at gmail.com (Max Erickson) Date: Sun, 4 Mar 2012 14:09:23 +0000 (UTC) Subject: How to convert simple B/W graphic to the dot matrix for the LED display/sign References: <94052541-e1e0-43b6-b434-59e79518cf4a@q18g2000yqh.googlegroups.com> <4f5349f2$0$29989$c3e8da3$5496439d@news.astraweb.com> Message-ID: Petr Jakes wrote: > >> What file format is the graphic in? How big is it? >> >> What file format do you want it to be? >> > > Now, I am able to create the png file with the resolution 432x64 > using PIL (using draw.text method for example). > > I would like to get the 432x64 True/False (Black/White) lookup > table from this file, so I can switch LEDs ON/OFF accordingly. > > -- > Petr > The convert and load methods are one way to do it: >>> import Image >>> im=Image.new('L', (100,100)) >>> im=im.convert('1') >>> px=im.load() >>> px[0,0] 0 That's the numeral one in the argument to convert. The load method returns a pixel access object. Max From web.elektro.net at gmail.com Sun Mar 4 09:14:46 2012 From: web.elektro.net at gmail.com (Sirotin Roman) Date: Sun, 4 Mar 2012 21:14:46 +0700 Subject: Jython callable. How? In-Reply-To: <4f53433c$0$29989$c3e8da3$5496439d@news.astraweb.com> References: <4f53433c$0$29989$c3e8da3$5496439d@news.astraweb.com> Message-ID: > Perhaps if you show us what you actually do, and what happens, we might > be able to tell you what is happening. Please COPY AND PASTE the full > traceback. Here is my code: # Trying to make callable staticmethod class sm(staticmethod): def __call__(self, *args, **kwargs): """ I know here is one more potential problem, because object passed instead of real class """ return self.__get__(None, object)(*args, **kwargs) issubclass(sm, Callable) class Foo(object): @sm def bar(): print("ololo") print("inside", bar, callable(bar), bar()) if __name__=="__main__": print("class outise", Foo.bar, callable(Foo.bar), Foo.bar()) f = Foo() print("instance outside", f.bar, callable(f.bar), f.bar()) cpython output: ololo ('inside', <__main__.sm object at 0xb72b404c>, True, None) ololo ('class outise', , True, None) ololo ('instance outside', , True, None) jython output: Traceback (most recent call last): File "sm.py", line 17, in class Foo(object): File "sm.py", line 23, in Foo print("inside", bar, callable(bar), bar()) TypeError: 'staticmethod' object is not callable From invalid at invalid.invalid Sun Mar 4 09:34:44 2012 From: invalid at invalid.invalid (Grant Edwards) Date: Sun, 4 Mar 2012 14:34:44 +0000 (UTC) Subject: The original command python line References: <4obb29-os3.ln1@archaeopteryx.softver.org.mk> Message-ID: On 2012-03-04, Chris Rebert wrote: > On Sat, Mar 3, 2012 at 9:38 PM, Damjan Georgievski wrote: >> How can I get the *really* original command line that started my python >> interpreter? > On Linux, you can read from: > /proc//cmdline > to get the null-delimited "command line". And if what you want is your own command line, you can replace with self: /proc/self/cmdline -- Grant From youssef.mahdia at hotmail.com Sun Mar 4 10:34:10 2012 From: youssef.mahdia at hotmail.com (youssef.mahdia at hotmail.com) Date: Sun, 4 Mar 2012 07:34:10 -0800 (PST) Subject: AttributeError: 'module' object has no attribute 'logger' Message-ID: hi all, when installing sage, there is a problem with emacs.py so, this screen appeared after rynning ./sage ---------------------------------------------------------------------- | Sage Version 4.4.2, Release Date: 2010-05-19 | | Type notebook() for the GUI, and license() for information. | ---------------------------------------------------------------------- Traceback (most recent call last): File "/home/zid/sage/local/bin/sage-ipython", line 18, in import IPython File "/usr/lib/python2.7/dist-packages/IPython/__init__.py", line 58, in __import__(name,glob,loc,[]) File "/usr/lib/python2.7/dist-packages/IPython/ipstruct.py", line 17, in from IPython.genutils import list2dict2 File "/usr/lib/python2.7/dist-packages/IPython/genutils.py", line 114, in import IPython.rlineimpl as readline File "/usr/lib/python2.7/dist-packages/IPython/rlineimpl.py", line 18, in from pyreadline import * File "/usr/local/lib/python2.7/dist-packages/pyreadline-2.0_dev1- py2.7.egg/pyreadline/__init__.py", line 11, in from . import unicode_helper, logger, clipboard, lineeditor, modes, console File "/usr/local/lib/python2.7/dist-packages/pyreadline-2.0_dev1- py2.7.egg/pyreadline/modes/__init__.py", line 3, in from . import emacs, notemacs, vi File "/usr/local/lib/python2.7/dist-packages/pyreadline-2.0_dev1- py2.7.egg/pyreadline/modes/emacs.py", line 11, in import pyreadline.logger as logger AttributeError: 'module' object has no attribute 'logger' any one can help me pleaseeee regards Zid From ethan at stoneleaf.us Sun Mar 4 10:38:58 2012 From: ethan at stoneleaf.us (Ethan Furman) Date: Sun, 04 Mar 2012 07:38:58 -0800 Subject: A possible change to decimal.Decimal? In-Reply-To: <6422978.686.1330864625195.JavaMail.geo-discussion-forums@vbgu10> References: <15610330.329.1330728373676.JavaMail.geo-discussion-forums@ynlw24> <6422978.686.1330864625195.JavaMail.geo-discussion-forums@vbgu10> Message-ID: <4F538C92.7070203@stoneleaf.us> A. Lloyd Flanagan wrote: > On Friday, March 2, 2012 6:49:39 PM UTC-5, Ethan Furman wrote: >> Jeff Beardsley wrote: >>> HISTORY: > ... >> What you should be doing is: >> >> import decimal >> from decimal import Decimal >> >> reload(decimal) >> Decimal = decimal.Decimal # (rebind 'Decimal' to the reloaded code) >> >> ~Ethan~ > > Agree that's how the import should be done. On the other hand, removing gratuitous use of isinstance() is generally a Good Thing. Gratuitous use? How is it gratuitous for an class to check that one of its arguments is its own type? class Frizzy(object): def __add__(self, other): if not isinstance(other, Frizzy): return NotImplemented do_stuff_with(self, other) This is exactly what isinstance() is for, and this is how it is being used in Decimal.__init__(). ~Ethan~ From ethan at stoneleaf.us Sun Mar 4 10:44:01 2012 From: ethan at stoneleaf.us (Ethan Furman) Date: Sun, 04 Mar 2012 07:44:01 -0800 Subject: A possible change to decimal.Decimal? In-Reply-To: References: <15610330.329.1330728373676.JavaMail.geo-discussion-forums@ynlw24> <4F515C93.6080201@stoneleaf.us> Message-ID: <4F538DC1.6050600@stoneleaf.us> Jeff Beardsley wrote: > The problem with that though: I am not calling reload(), except to > recreate the error as implemented by the web frameworks. > > I am also unlikely to get a patch accepted into several different > projects, where this is ONE project, and it's a simple change Simple -- maybe. Appropriate -- no. It is unfortunate that those frameworks have that bug, but it is not up to Decimal to fix it for them. ~Ethan~ From scavanau at cisco.com Sun Mar 4 13:07:57 2012 From: scavanau at cisco.com (Sean Cavanaugh (scavanau)) Date: Sun, 4 Mar 2012 10:07:57 -0800 Subject: Python - CGI-BIN - Apache Timeout Problem In-Reply-To: References: <6FC169072CBFF3409B6E74F50175A4650497A3F9@xmb-sjc-215.amer.cisco.com> Message-ID: <6FC169072CBFF3409B6E74F50175A4650497A566@xmb-sjc-215.amer.cisco.com> Thanks Chris, I isolated it using logging import logging logging.basicConfig(filename="test3.log", level=logging.INFO) then logging.info('sniffer got to point A') and going through my code until I isolated the problem to a function with scapy called sniff. For some reason this function operates very weirdly on FreeBSD9. I have already submitted an email to the scapy mailing list. Going to try to replicate this on Fedora but I doubt I will see this problem. Even from the command line the sniff() function is not working correctly on FreeBSD 9. -S -----Original Message----- From: chris at rebertia.com [mailto:chris at rebertia.com] On Behalf Of Chris Rebert Sent: Friday, March 02, 2012 3:23 PM To: Sean Cavanaugh (scavanau) Cc: python-list at python.org Subject: Re: Python - CGI-BIN - Apache Timeout Problem On Fri, Mar 2, 2012 at 12:09 PM, Sean Cavanaugh (scavanau) wrote: > THE PROBLEM: > > When I execute the scripts from the command line (#python main.py) it > generates it fine (albeit slowly), it prints all the html code out including > the script.? The ?core? part of the script dumbed down to the lowest level > is-> > > ??????? proc = subprocess.Popen(['/usr/local/bin/python', 'tests.py'], > stdout=subprocess.PIPE) > ??????? output = proc.stdout.read() Note the red warning box about possible deadlock with .stdout.read() and friends: http://docs.python.org/library/subprocess.html#popen-objects > ??????? print output > ??????? proc.stdout.close() As the docs advise, try using .communicate() [http://docs.python.org/library/subprocess.html#subprocess.Popen.communicate ] instead: proc = subprocess.Popen(?) out, err = proc.communicate() print out > When I open main.py and execute the script it just hangs? it seems to > execute the script (I see pcap fires on the interface that I am testing on > the firewall) but its not executing correctly? or loading the entire > webpage?the webpage keeps chugging along and eventually gives me an error > timeout. The hanging makes me suspect that the aforementioned deadlock is occurring. Cheers, Chris -- http://chrisrebert.com From bookman23 at comcast.net Sun Mar 4 14:20:54 2012 From: bookman23 at comcast.net (Scott V) Date: Sun, 4 Mar 2012 14:20:54 -0500 Subject: python25.dll Message-ID: <3236F50616DD4E4A85E3747922B9EE19@ScottPC> I don't know if anyone has sent this in before. > I loaded the current version of Python on my computer to learn the > programming and, I believe, it helps my Blender to work. Anyway, > occassionally, I get an error on the screen, before I have started running > programs, that states "python25.dll" will not load or does not exist. > I have removed Python from my system to stop this error. > Anything else I can do? This is XP system. > Scott *I loaded version 3.2, so not sure why the python25 was in there. ___________________________________________ Amazon: Check out my over 800 items for sale on Amazon at: http://www.amazon.com/shops/bookman236 "I believe that everything happens for a reason. People change so that you can learn to let go, things go wrong so that you appreciate them when they're right, you believe lies so you eventually learn to trust no one but yourself, and sometimes good things fall apart so better things can fall together." -Marilyn Monroe -------------- next part -------------- An HTML attachment was scrubbed... URL: From chris at simplistix.co.uk Sun Mar 4 17:34:47 2012 From: chris at simplistix.co.uk (Chris Withers) Date: Sun, 04 Mar 2012 22:34:47 +0000 Subject: Adopting =?UTF-8?B?4oCYbG9ja2ZpbGXigJk=?= In-Reply-To: <874nu5nywc.fsf@benfinney.id.au> References: <874nu5nywc.fsf@benfinney.id.au> Message-ID: <4F53EE07.7090006@simplistix.co.uk> On 03/03/2012 21:43, Ben Finney wrote: > I don't see a need to horse around with Git either :-) It's currently in > Subversion, right? Can you not export the VCS history from Google Code's > Subversion repository to a ?fastimport? stream? Maybe someone with > experience on that site can help us. What's wrong with a "git svn clone svn-url-here" ? Chris -- Simplistix - Content Management, Batch Processing & Python Consulting - http://www.simplistix.co.uk From johnjsal at gmail.com Sun Mar 4 18:07:41 2012 From: johnjsal at gmail.com (John Salerno) Date: Sun, 4 Mar 2012 15:07:41 -0800 (PST) Subject: Is this the right location to launch IDLE? Message-ID: <1902734.303.1330902461168.JavaMail.geo-discussion-forums@yncd8> I'm trying to get Notepad++ to launch IDLE and run the currently open file in IDLE, but all my attempts have failed so far. I'm wondering, am I even using the IDLE path correctly? I'm using this: "C:\Python32\Lib\idlelib\idle.pyw" "$(FULL_CURRENT_PATH)" (That last part puts in the full path to the open file.) Is this not the proper way to launch IDLE with an argument? It actually does open up IDLE, but the file doesn't seem to have been loaded, because when I try to use variables or functions from the file, IDLE acts as if it doesn't know what I'm referring to. Thanks. From antgoodlife at gmail.com Sun Mar 4 19:20:44 2012 From: antgoodlife at gmail.com (Antgoodlife) Date: Sun, 4 Mar 2012 16:20:44 -0800 (PST) Subject: Parse cisco's "show ip route" output in Python 2.7 Message-ID: Hi All, Long time reader, first time poster. I'm trying to parse the output of the SHOW IP ROUTE command from a cisco router (It's a 3800 Series IOS 12.4 although almost all should have same output format) and put it into a CSV format to import into a database or spreadsheet. While we of course have Static / Connected routes, we also have lots of dynamic routing coming in via OSPF, BGP, RIP, etc... The output of the command is easy enough for me to get into text files via parimiko (on that, does this module or equivalent work on Python 3 yet?) .. it's just tough to present the data into a csv or tabbed format. To me, although I've done similar things in the past, it's a fairly brutal output format to parse up. I was about to post some sample input, but I am even having a hard time sanitizing the IP's for use on this forum (Any utility for that?) as it's filled with IP addresses that I cannot share. I'd love some python module if anyone has an idea where I can get it? Perl does seem to have something similar : http://cpansearch.perl.org/src/MARKPF/Cisco-ShowIPRoute-Parser-1.02/Parser.pm however, I'd like to keep it in python... Mainly, did someone already do this so I don't have to reinvent this wheel (which probably won't roll straight)? Thanks in advance, and hopefully I've given enough information.. I've been trying to parse it for about 9 hours... but the script get's worse and worse as I keep finding flaws in my logic. From drsalists at gmail.com Sun Mar 4 19:47:46 2012 From: drsalists at gmail.com (Dan Stromberg) Date: Sun, 4 Mar 2012 16:47:46 -0800 Subject: Parse cisco's "show ip route" output in Python 2.7 In-Reply-To: References: Message-ID: I've done little with Ciscos, but what if you use individual things like "show ip ospf", "show ip rip database", etc. instead of "show ip route". Does that makes things a little more consistent? Often big problems are simpler if we can divide them into smaller, more manageable subproblems. On Sun, Mar 4, 2012 at 4:20 PM, Antgoodlife wrote: > Hi All, > > Long time reader, first time poster. I'm trying to parse the output > of the SHOW IP ROUTE command from a cisco router (It's a 3800 Series > IOS 12.4 although almost all should have same output format) and put > it into a CSV format to import into a database or spreadsheet. > While we of course have Static / Connected routes, we also have lots > of dynamic routing coming in via OSPF, BGP, RIP, etc... > > The output of the command is easy enough for me to get into text files > via parimiko (on that, does this module or equivalent work on Python 3 > yet?) .. it's just tough to present the data into a csv or tabbed > format. > > To me, although I've done similar things in the past, it's a fairly > brutal output format to parse up. I was about to post some sample > input, but I am even having a hard time sanitizing the IP's for use on > this forum (Any utility for that?) as it's filled with IP addresses > that I cannot share. I'd love some python module if anyone has an > idea where I can get it? > > Perl does seem to have something similar : > > http://cpansearch.perl.org/src/MARKPF/Cisco-ShowIPRoute-Parser-1.02/Parser.pm > however, I'd like to keep it in python... > > Mainly, did someone already do this so I don't have to reinvent this > wheel (which probably won't roll straight)? > > Thanks in advance, and hopefully I've given enough information.. I've > been trying to parse it for about 9 hours... but the script get's > worse and worse as I keep finding flaws in my logic. > -- > http://mail.python.org/mailman/listinfo/python-list > -------------- next part -------------- An HTML attachment was scrubbed... URL: From rantingrickjohnson at gmail.com Sun Mar 4 20:39:27 2012 From: rantingrickjohnson at gmail.com (Rick Johnson) Date: Sun, 4 Mar 2012 17:39:27 -0800 (PST) Subject: How do you use the widgets in tkinter.ttk if you want to "import tkinter as tk"? References: <29015333.101.1330739333318.JavaMail.geo-discussion-forums@vbbgt10> Message-ID: <7a170522-2fcb-4334-8d55-f71b1ffb4475@b1g2000yqb.googlegroups.com> On Mar 2, 11:06?pm, John Salerno wrote: > I'm tempted just to go back to wxPython. Two sets of widgets in Tkinter is a little annoying. Your complaint is justified. The Tkinter API is a disgrace. IDLE's source is just as bad. Luckily i have not made the jump to py3000 full- time yet, but when i do, i think the first item on my to-do list will be to hack this hideous tk+ttk+blah+blah into something more friendly. Heck, maybe i'll even release it! From nad at acm.org Sun Mar 4 20:41:50 2012 From: nad at acm.org (Ned Deily) Date: Sun, 04 Mar 2012 17:41:50 -0800 Subject: [FIXED] Re: Can't get tilde character with IDLE 3.2.2 on French Mac Lion References: Message-ID: A followup to a thread in 2011-12. In article , Ned Deily wrote: > In article , > Franck Ditter wrote: > > In article , > > Ned Deily wrote: > > > In article , > > > Franck Ditter wrote: > > > > All is in the subject. I'm starting to use Python with Idle 3.2.2 > > > > on MacOS-X Lion (French). I can't get "Option-N space" to provide > > > > the ~ char. > > > > I tried to go into the Keys preferences but I can't find "Option-N > > > > space" > > > > to modify its meaning. Its actual behavior is to merge lines of a > > > > paragraph. > > > You are likely running into a current problem in the OS X Cocoa version > > > of Tcl/Tk 8.5 as included with Lion and as shipped by ActiveState. > > > Previously, if you tried to type composite characters, like Option N, > > > the Cocoa Tcl/Tk would crash. Pending a real fix, a patch was made to > > > Tcl/Tk 8.5 to discard composite characters rather than crash. You > > > should be able to get a tilde by using the post-composite keyboard > > > sequence: try typing "space" followed by "Shift-Option-N". > > > > > > http://sourceforge.net/tracker/index.php?func=detail&aid=2907388&group_id= > > > 12 > > > 997&atid=112997 > > Nope, "space" followed by "Shift-Option-N" gives a greek iota... > > I tried other combinations, unsuccessfully. > > IDLE 3 (French) seems to be unusable as we use many ~ in web applications > > :-( > > Should we hope a fix soon, or leave IDLE ? > > Yes, I see now that that won't work with the French input method. > Unfortunately, there is nothing that IDLE or Python can do to workaround > the issue as the problem is in Cocoa Tcl/Tk and I don't know that any > fix is being worked on. Good news! A fix for Cocoa Tcl/Tk 8.5 for improved handling of Mac OS X input methods was recently applied and has now been released in the latest ActiveState Tcl release (8.5.11.1) available here: http://www.activestate.com/activetcl/downloads It appears to fix the tilde problem and other similar problems with composite characters, like Option-U + vowel to form "umlauted" vowels in the U.S. input method. Many thanks to Adrian Robert, Kevin Walzer, and the ActiveState team for addressing this nasty problem. If you install ActiveState Tcl 8.5.x, it will automatically be used by the python.org 2.7.x, 3.2.x, and 3.3.x 64-bit/32-bit Pythons for OS X 10.6 and 10.7. It will *not* be used by the Apple-supplied system Pythons or by 32-bit-only python.org Pythons. More details here: http://www.python.org/download/mac/tcltk/ -- Ned Deily, nad at acm.org From nad at acm.org Sun Mar 4 20:45:38 2012 From: nad at acm.org (Ned Deily) Date: Sun, 04 Mar 2012 17:45:38 -0800 Subject: Buffering in Wing and IDLE 3 References: Message-ID: In article , Kevin Walzer wrote: > On 2/1/12 3:01 PM, Terry Reedy wrote: > > On 2/1/2012 10:17 AM, Franck Ditter wrote: > > > >> I would prefer to use IDLE but as we are in France, the Python team > >> does not seem to be aware that the ~ and others are not available > >> on MacOS-X here (probably the same in Europe)... > > > > We are quite aware of the problem but cannot directly do anything about > > it as the problem is with tcl/tk and Apple. A couple of days ago, Kevin > > Walzer wrote on an IDLE-sig post "I'm currently reviewing an updated > > patch to address the problem. When I commit the patch, it will go into > > both Tk's trunk and in the Cocoa 8.5 backport, and eventually be > > available through ActiveState's distribution." > > > And it's been committed: > > http://core.tcl.tk/tk/info/9844fe10b9 ... and released in ActiveState 8.5.11.1 http://www.activestate.com/activetcl/downloads -- Ned Deily, nad at acm.org From kw at codebykevin.com Sun Mar 4 20:58:23 2012 From: kw at codebykevin.com (Kevin Walzer) Date: Sun, 04 Mar 2012 20:58:23 -0500 Subject: How do you use the widgets in tkinter.ttk if you want to "import tkinter as tk"? In-Reply-To: References: <29015333.101.1330739333318.JavaMail.geo-discussion-forums@vbbgt10> Message-ID: On 3/3/12 12:06 AM, John Salerno wrote: >> I suppose the 'advantage' of this is that it will replace tk widgets >> with equivalent ttk widgets, if they exist and have the same name. I >> believe one has to program them differently, however, so the replacement >> cannot be transparent and one mush know anyway what gets replaced and >> what not. > > Grr, sounds like a pain if I want to use the new widgets. Does this cause conflict with someone who isn't running 8.5, or will they still see the older widgets as normal? > > I'm tempted just to go back to wxPython. Two sets of widgets in Tkinter is a little annoying. The new widgets are not a drop-in replacement for the traditional Tk widgets. They can be used with 8.4 if the "tile" Tk extension is installed. This is how the ttk widgets were first deployed; they didn't enter Tk's core until 8.5. -- Kevin Walzer Code by Kevin http://www.codebykevin.com From anikom15 at gmail.com Sun Mar 4 21:04:34 2012 From: anikom15 at gmail.com (Westley =?iso-8859-1?Q?Mart=EDnez?=) Date: Sun, 4 Mar 2012 18:04:34 -0800 Subject: How do you use the widgets in tkinter.ttk if you want to "import tkinter as tk"? In-Reply-To: <7a170522-2fcb-4334-8d55-f71b1ffb4475@b1g2000yqb.googlegroups.com> References: <29015333.101.1330739333318.JavaMail.geo-discussion-forums@vbbgt10> <7a170522-2fcb-4334-8d55-f71b1ffb4475@b1g2000yqb.googlegroups.com> Message-ID: <20120305020434.GA31058@kubrick> On Sun, Mar 04, 2012 at 05:39:27PM -0800, Rick Johnson wrote: > On Mar 2, 11:06?pm, John Salerno wrote: > > I'm tempted just to go back to wxPython. Two sets of widgets in Tkinter is a little annoying. > > Your complaint is justified. The Tkinter API is a disgrace. IDLE's > source is just as bad. Luckily i have not made the jump to py3000 full- > time yet, but when i do, i think the first item on my to-do list will > be to hack this hideous tk+ttk+blah+blah into something more > friendly. > > Heck, maybe i'll even release it! Make sure not to write it from scratch! From dihedral88888 at googlemail.com Sun Mar 4 21:14:31 2012 From: dihedral88888 at googlemail.com (88888 Dihedral) Date: Sun, 4 Mar 2012 18:14:31 -0800 (PST) Subject: Porting Python to an embedded system In-Reply-To: References: Message-ID: <30499939.3531.1330913671419.JavaMail.geo-discussion-forums@pbjv6> On Sunday, March 4, 2012 6:58:50 PM UTC+8, Justin Drake wrote: > I am working with an ARM Cortex M3 on which I need to port Python > (without operating system). What would be my best approach? I just > need the core Python and basic I/O. Sounds like the JVM law suites in ANDROINDS did stimulate a lot jobs to use other VM-BYTECODE based programming languages. I suggest that one can use tiny linux or MU-linux which is even smaller than Linux and then install a slimmer customized python not the same as the fatter one used in PC. From dihedral88888 at googlemail.com Sun Mar 4 21:14:31 2012 From: dihedral88888 at googlemail.com (88888 Dihedral) Date: Sun, 4 Mar 2012 18:14:31 -0800 (PST) Subject: Porting Python to an embedded system In-Reply-To: References: Message-ID: <30499939.3531.1330913671419.JavaMail.geo-discussion-forums@pbjv6> On Sunday, March 4, 2012 6:58:50 PM UTC+8, Justin Drake wrote: > I am working with an ARM Cortex M3 on which I need to port Python > (without operating system). What would be my best approach? I just > need the core Python and basic I/O. Sounds like the JVM law suites in ANDROINDS did stimulate a lot jobs to use other VM-BYTECODE based programming languages. I suggest that one can use tiny linux or MU-linux which is even smaller than Linux and then install a slimmer customized python not the same as the fatter one used in PC. From drsalists at gmail.com Sun Mar 4 21:21:22 2012 From: drsalists at gmail.com (Dan Stromberg) Date: Sun, 4 Mar 2012 18:21:22 -0800 Subject: Porting Python to an embedded system In-Reply-To: References: Message-ID: You might check out pymite. http://wiki.python.org/moin/PyMite Oh, but I'm now realizing that's part of the python on a chip project, so in a way it's already been mentioned. Anyway, PyMite, I gather, is a tiny python for microcontrollers. On Sun, Mar 4, 2012 at 2:58 AM, Justin Drake wrote: > I am working with an ARM Cortex M3 on which I need to port Python > (without operating system). What would be my best approach? I just > need the core Python and basic I/O. > -- > http://mail.python.org/mailman/listinfo/python-list > -------------- next part -------------- An HTML attachment was scrubbed... URL: From clp2 at rebertia.com Sun Mar 4 21:53:57 2012 From: clp2 at rebertia.com (Chris Rebert) Date: Sun, 4 Mar 2012 18:53:57 -0800 Subject: Is this the right location to launch IDLE? In-Reply-To: <1902734.303.1330902461168.JavaMail.geo-discussion-forums@yncd8> References: <1902734.303.1330902461168.JavaMail.geo-discussion-forums@yncd8> Message-ID: On Sun, Mar 4, 2012 at 3:07 PM, John Salerno wrote: > I'm trying to get Notepad++ to launch IDLE and run the currently open file in IDLE, but all my attempts have failed so far. I'm wondering, am I even using the IDLE path correctly? I'm using this: > > "C:\Python32\Lib\idlelib\idle.pyw" "$(FULL_CURRENT_PATH)" > > (That last part puts in the full path to the open file.) > > Is this not the proper way to launch IDLE with an argument? Correct. According to IDLE's USAGE message, you want the "-r" option, which would make your desired command: "C:\Python32\Lib\idlelib\idle.pyw" -r "$(FULL_CURRENT_PATH)" > It actually does open up IDLE, but the file doesn't seem to have been loaded, because when I try to use variables or functions from the file, IDLE acts as if it doesn't know what I'm referring to. Cheers, Chris -- http://rebertia.com From johnjsal at gmail.com Sun Mar 4 22:51:18 2012 From: johnjsal at gmail.com (John Salerno) Date: Sun, 4 Mar 2012 19:51:18 -0800 (PST) Subject: Is this the right location to launch IDLE? In-Reply-To: <1902734.303.1330902461168.JavaMail.geo-discussion-forums@yncd8> References: <1902734.303.1330902461168.JavaMail.geo-discussion-forums@yncd8> Message-ID: <676893.2385.1330919478888.JavaMail.geo-discussion-forums@vbux23> Unfortunately neither method worked. Adding "-r" to the path created this error when I tried it: >>> *** Error in script or command! Traceback (most recent call last): File "C:\Users\John\Documents\Python Scripts\chess_pieces.py", line 1 ???class ChessPiece: ^ SyntaxError: invalid character in identifier >>> Although there really is no error in the file, and running it directly from within IDLE doesn't cause this problem. Adding the "pythonw.exe" part to the beginning also gave this error, but when I remove the "-r", then it just opens IDLE as normal, but without having loaded the Notepad++ file. I just know there has to be a way to do this, but perhaps it's more of an NP++ problem. I posted on their forums but no one responded. I thought I might see if the problem lies with calling IDLE, but apparently it's a Windows/NP++ thing... From clp2 at rebertia.com Sun Mar 4 23:07:19 2012 From: clp2 at rebertia.com (Chris Rebert) Date: Sun, 4 Mar 2012 20:07:19 -0800 Subject: Is this the right location to launch IDLE? In-Reply-To: <676893.2385.1330919478888.JavaMail.geo-discussion-forums@vbux23> References: <1902734.303.1330902461168.JavaMail.geo-discussion-forums@yncd8> <676893.2385.1330919478888.JavaMail.geo-discussion-forums@vbux23> Message-ID: On Sun, Mar 4, 2012 at 7:51 PM, John Salerno wrote: > Unfortunately neither method worked. Adding "-r" to the path created this error when I tried it: > >>>> > *** Error in script or command! > > Traceback (most recent call last): > ?File "C:\Users\John\Documents\Python Scripts\chess_pieces.py", line 1 > ? ????class ChessPiece: That would be a Notepad++ problem. That "???" gibberish is what you get when a Unicode BOM (Byte Order Mark) character is encoded as UTF-8 but decoded as ISO-8859-1 or CP-1252. A BOM is not recommended for UTF-8 text; there should be some setting in Notepad++ to suppress it. Cheers, Chris From johnjsal at gmail.com Mon Mar 5 00:00:50 2012 From: johnjsal at gmail.com (John Salerno) Date: Sun, 4 Mar 2012 21:00:50 -0800 (PST) Subject: Is this the right location to launch IDLE? In-Reply-To: References: <1902734.303.1330902461168.JavaMail.geo-discussion-forums@yncd8> <676893.2385.1330919478888.JavaMail.geo-discussion-forums@vbux23> Message-ID: <23665576.3009.1330923650131.JavaMail.geo-discussion-forums@ynjd19> > That would be a Notepad++ problem. That "???" gibberish is what you > get when a Unicode BOM (Byte Order Mark) character is encoded as UTF-8 > but decoded as ISO-8859-1 or CP-1252. A BOM is not recommended for > UTF-8 text; there should be some setting in Notepad++ to suppress it. You are my new hero! :) It works perfectly now! I set the default for files to be UTF-8 without BOM, and I also checked the option that said "Apply to opened ANSI files." Is that okay? Thank you!!! From johnjsal at gmail.com Mon Mar 5 00:00:50 2012 From: johnjsal at gmail.com (John Salerno) Date: Sun, 4 Mar 2012 21:00:50 -0800 (PST) Subject: Is this the right location to launch IDLE? In-Reply-To: References: <1902734.303.1330902461168.JavaMail.geo-discussion-forums@yncd8> <676893.2385.1330919478888.JavaMail.geo-discussion-forums@vbux23> Message-ID: <23665576.3009.1330923650131.JavaMail.geo-discussion-forums@ynjd19> > That would be a Notepad++ problem. That "???" gibberish is what you > get when a Unicode BOM (Byte Order Mark) character is encoded as UTF-8 > but decoded as ISO-8859-1 or CP-1252. A BOM is not recommended for > UTF-8 text; there should be some setting in Notepad++ to suppress it. You are my new hero! :) It works perfectly now! I set the default for files to be UTF-8 without BOM, and I also checked the option that said "Apply to opened ANSI files." Is that okay? Thank you!!! From k.sahithi2862 at gmail.com Mon Mar 5 00:32:18 2012 From: k.sahithi2862 at gmail.com (SAHITHI) Date: Sun, 4 Mar 2012 21:32:18 -0800 (PST) Subject: HOT LINKS FOR YOUTH ONLY Message-ID: TOP DATING TIPS TO ENCOURAGE WOMEN FOR DATING http://datingsitesdatingtips.blogspot.in/ HOT LINKS FOR YOUTH ONLY NAYANTHARA HOT WALLPAPERS http://actressimages-9.blogspot.in/2012/01/nayanthara.html ANU SMRUTHI LATEST HOT STILLS http://actressimages-9.blogspot.in/2012/02/anu-smirthi-stills.html AISHWARYA RAI LATEST HOT PICS http://actressimages-9.blogspot.in/2012/01/aishwarya-rai.html KATRINA KAIF HOT MAGAZINES PHOTOS http://actressimages-9.blogspot.in/2012/01/katrina-kaif-magazine-photos.html TRISHA HOT BEAUTIFUL IMAGES http://actressimages-9.blogspot.in/2012/01/trisha-krishnan.html HOT MALLIKA SHERAWAT PHOTOS http://actressimages-9.blogspot.in/2012/01/mallika-sherawat.html FOR LATEST MOVIE UPDATED LINKS RACHA MOVIE LATEST STILLS http://actressgallery-kalyani.blogspot.com/2012/03/racha-movie-stills.html KAJAL HOT IN BINAMI VELAKOTLU MOVIE http://actressgallery-kalyani.blogspot.com/2012/03/binami-velakotlu-movie-stills.html ADHINAYAKUDU MOVIE LATEST HOT STILLS http://actressgallery-kalyani.blogspot.in/2012/03/adhinayakudu-movie-stills.html Bhale Tammudu Movie Hot Latest Stills http://actressgallery-kalyani.blogspot.in/2012/03/bhale-thammudu-movie-stills.html TAMANNA RAM Endukante Premante Movie Latest Stills http://actressgallery-kalyani.blogspot.com/2012/03/endukante-premanta-movie-stills.html LOVELY MOVIE LATEST ROMANTIC STILLS http://actressgallery-kalyani.blogspot.in/2011/12/lovely-movie-stills.html ILEANA LATEST HOT PHOTOSHOOT http://actressgallery-kalyani.blogspot.in/2012/01/ileana-latest-stills.html ACTREESS SUPRIYA SHAILJA LATEST STILLS http://actressgallery-kalyani.blogspot.in/2012/02/supriya-shailja-stills.html SHEELA LATEST HOT STILLS http://actressgallery-kalyani.blogspot.com/2012/01/sheela-latest-stills.html KATRINA KAIF ITEM SONG STILLS http://actressgallery-kalyani.blogspot.com/2012/01/katrina-kaif-item-song-stills.html RITU KAUR LATEST PHOTO STILLS http://actressgallery-kalyani.blogspot.com/2012/01/ritu-kaur-stills.html SHRUTI HASSAN HOT IN 3 MOVIE http://actressgallery-kalyani.blogspot.com/2011/11/shruti-hassan-in-3-movie.html HOT KATRINA KAIF PHOTOS http://actressgallery-kalyani.blogspot.com/2011/09/katrina-kaif.html AISHWARYA RAI HOT HQ PHOTO STILLS http://actressgallery-kalyani.blogspot.com/2011/09/aishwarya-rai.html ASIN HOT PHOTO GALLERY http://actressgallery-kalyani.blogspot.com/2011/09/asin.html From johnjsal at gmail.com Mon Mar 5 00:53:45 2012 From: johnjsal at gmail.com (John Salerno) Date: Sun, 4 Mar 2012 21:53:45 -0800 (PST) Subject: How do you use the widgets in tkinter.ttk if you want to "import tkinter as tk"? In-Reply-To: <7a170522-2fcb-4334-8d55-f71b1ffb4475@b1g2000yqb.googlegroups.com> References: <29015333.101.1330739333318.JavaMail.geo-discussion-forums@vbbgt10> <7a170522-2fcb-4334-8d55-f71b1ffb4475@b1g2000yqb.googlegroups.com> Message-ID: <16833339.2794.1330926825621.JavaMail.geo-discussion-forums@vbai14> On Sunday, March 4, 2012 7:39:27 PM UTC-6, Rick Johnson wrote: > On Mar 2, 11:06?pm, John Salerno wrote: > > I'm tempted just to go back to wxPython. Two sets of widgets in Tkinter is a little annoying. > > Your complaint is justified. The Tkinter API is a disgrace. IDLE's > source is just as bad. Luckily i have not made the jump to py3000 full- > time yet, but when i do, i think the first item on my to-do list will > be to hack this hideous tk+ttk+blah+blah into something more > friendly. > > Heck, maybe i'll even release it! Well, after reading about the themed widgets and using them a bit, they definitely seem a lot cleaner than the old ones. Just comparing the attributes of the new and old widgets is a big difference. Much more streamlined. From johnjsal at gmail.com Mon Mar 5 02:12:38 2012 From: johnjsal at gmail.com (John Salerno) Date: Sun, 4 Mar 2012 23:12:38 -0800 (PST) Subject: Tkinter: Why aren't my widgets expanding when I resize the window? Message-ID: <32271364.3080.1330931558529.JavaMail.geo-discussion-forums@ynjd19> I can't seem to wrap my head around all the necessary arguments for making a widget expand when a window is resized. I've been following along with a tutorial and I feel like I'm doing everything it said, but I must be missing something. Here's what I have. What I expect is that when I resize the main window, I should be able to see the AppFrame's border stretch out, but it remains in the original position. Is there something wrong with the sticky argument, maybe? The tutorial I'm reading says they can be strings, but it also uses what appears to be a tuple of constants like this: sticky=(N, S, E, W) -- but that didn't work either. import tkinter as tk import tkinter.ttk as ttk class AppFrame(ttk.Frame): def __init__(self, parent, **kwargs): super().__init__(parent, **kwargs) self.grid(row=0, column=0, sticky='nsew') self.columnconfigure(0, weight=1) self.rowconfigure(0, weight=1) self.create_widgets() def create_widgets(self): entry = ttk.Entry(self) entry.grid(row=0, column=1, sticky='nsew') #entry.columnconfigure(0, weight=1) #entry.rowconfigure(0, weight=1) label = ttk.Label(self, text='Name:') label.grid(row=0, column=0, sticky='nsew') root = tk.Tk() root.title('Test Application') frame = AppFrame(root, borderwidth=15, relief='sunken') root.mainloop() From georg at python.org Mon Mar 5 02:54:06 2012 From: georg at python.org (Georg Brandl) Date: Mon, 05 Mar 2012 08:54:06 +0100 Subject: [RELEASED] Python 3.3.0 alpha 1 Message-ID: <4F54711E.2020006@python.org> On behalf of the Python development team, I'm happy to announce the first alpha release of Python 3.3.0. This is a preview release, and its use is not recommended in production settings. Python 3.3 includes a range of improvements of the 3.x series, as well as easier porting between 2.x and 3.x. Major new features in the 3.3 release series are: * PEP 380, Syntax for Delegating to a Subgenerator ("yield from") * PEP 393, Flexible String Representation (doing away with the distinction between "wide" and "narrow" Unicode builds) * PEP 409, Suppressing Exception Context * PEP 3151, Reworking the OS and IO exception hierarchy * The new "packaging" module, building upon the "distribute" and "distutils2" projects and deprecating "distutils" * The new "lzma" module with LZMA/XZ support * PEP 3155, Qualified name for classes and functions * PEP 414, explicit Unicode literals to help with porting * The new "faulthandler" module that helps diagnosing crashes * Wrappers for many more POSIX functions in the "os" and "signal" modules, as well as other useful functions such as "sendfile()" For a more extensive list of changes in 3.3.0, see http://docs.python.org/3.3/whatsnew/3.3.html To download Python 3.3.0 visit: http://www.python.org/download/releases/3.3.0/ Please consider trying Python 3.3.0a1 with your code and reporting any bugs you may notice to: http://bugs.python.org/ Enjoy! -- Georg Brandl, Release Manager georg at python.org (on behalf of the entire python-dev team and 3.3's contributors) From chris at simplistix.co.uk Mon Mar 5 03:30:59 2012 From: chris at simplistix.co.uk (Chris Withers) Date: Mon, 05 Mar 2012 08:30:59 +0000 Subject: xlutils 1.5.0 released! Message-ID: <4F5479C3.2020708@simplistix.co.uk> Hi All, I'm pleased to announce the release of xlutils 1.5.0, featuring the following changes: - Now takes advantage of "ragged rows" optimisation in xlrd 0.7.3 - Add support for PANE records to xlutils.copy, which means that zoom factors are now copied. The full change log is here: http://www.simplistix.co.uk/software/python/xlutils/changes Now, the other big change for this release is that development has moved to GitHub: https://github.com/cjw296/xlutils All the details of where to find mailing lists, issue trackers, and the like for xlutils can be found here: http://www.simplistix.co.uk/software/python/xlutils cheers, Chris -- Simplistix - Content Management, Batch Processing & Python Consulting - http://www.simplistix.co.uk From jeanmichel at sequans.com Mon Mar 5 05:27:50 2012 From: jeanmichel at sequans.com (Jean-Michel Pichavant) Date: Mon, 05 Mar 2012 11:27:50 +0100 Subject: RotatingFileHandler Fails In-Reply-To: References: Message-ID: <4F549526.10402@sequans.com> nac wrote: > The RotatingFileHandler running on win 7 64-bit; py 2.7 is failing > when the script launches a process using subprocess.Popen. Works fine > if the subprocess is not launched > > The exception thrown > Traceback (most recent call last): > File "C:\Python27\lib\logging\handlers.py", line 78, in emit > self.doRollover() > File "C:\Python27\lib\logging\handlers.py", line 141, in doRollover > os.rename(self.baseFilename, dfn) > WindowsError: [Error 32] The process cannot access the file because it > is being used by another process > > Anyone have an idea how to fix this? > > > import os, sys > import logging > import logging.handlers > import subprocess > > def chomp(s): > "remove trailing carriage return" > if s[-1:]=='\n': return s[:-1] > else: return s > > logging.basicConfig(level=logging.DEBUG, format='%(asctime)s % > (name)-2s %(levelname)-8s %(threadName)-12s %(message)s') > q5Logger = logging.getLogger('Q5') > logFileHandler = logging.handlers.RotatingFileHandler(filename='c:\ > \logger\\q5.log', mode= 'a', maxBytes=100, backupCount=5) > logFileHandler.setFormatter(logging.Formatter('%(asctime)s %(name)-2s % > (levelname)-8s %(threadName)-12s %(message)s')) > logFileHandler.setLevel(logging.DEBUG) > q5Logger.addHandler(logFileHandler) > > progOutput = subprocess.Popen(r'dir *.*', shell=True, bufsize=1000, > stdout=subprocess.PIPE).stdout > line = progOutput.readline() > while (line) != "": > q5Logger.info( chomp(line)) > line = progOutput.readline() > rc = progOutput.close() > I don't think you can open a file from 2 different processes, hence the error message. The only exception would be that one of them opens it in read only mode which won't happen for log file. You cannot fix it, it is the operand system that blocks the operation. Using thread may allow you to log into the same file, but could bring a bunch of other problems. I know some ppl use a log server, your processes using a socket (client) logger. You could do that on your local machine. There's a tutorial on that in the logging documentation. JM From jeanmichel at sequans.com Mon Mar 5 05:40:26 2012 From: jeanmichel at sequans.com (Jean-Michel Pichavant) Date: Mon, 05 Mar 2012 11:40:26 +0100 Subject: Trying to understand 'import' a bit better In-Reply-To: References: Message-ID: <4F54981A.30401@sequans.com> Frank Millman wrote: > Hi all > > I have been using 'import' for ages without particularly thinking about it - > it just works. > > Now I am having to think about it a bit harder, and I realise it is a bit > more complicated than I had realised - not *that* complicated, but there are > some subtleties. > > I don't know the correct terminology, but I want to distinguish between the > following two scenarios - > > 1. A python 'program', that is self contained, has some kind of startup, > invokes certain functionality, and then closes. > > 2. A python 'library', that exposes functionality to other python programs, > but relies on the other program to invoke its functionality. > > The first scenario has the following characteristics - > - it can consist of a single script or a number of modules > - if the latter, the modules can all be in the same directory, or in one > or more sub-directories > - if they are in sub-directories, the sub-directory must contain > __init__.py, and is referred to as a sub-package > - the startup script will normally be in the top directory, and will be > executed directly by the user > > When python executes a script, it automatically places the directory > containing the script into 'sys.path'. Therefore the script can import a > top-level module using 'import ', and a sub-package module using > 'import .'. > > The second scenario has similar characteristics, except it will not have a > startup script. In order for a python program to make use of the library, it > has to import it. In order for python to find it, the directory containing > it has to be in sys.path. In order for python to recognise the directory as > a valid container, it has to contain __init__.py, and is referred to as a > package. > > To access a module of the package, the python program must use 'import > .' (or 'from import '), and to access a > sub-package module it must use 'import ... > > So far so uncontroversial (I hope). > > The subtlety arises when the package wants to access its own modules. > Instead of using 'import ' it must use 'import .'. > This is because the directory containing the package is in sys.path, but the > package itself is not. It is possible to insert the package directory name > into sys.path as well, but as was pointed out recently, this is dangerous, > because you can end up with the same module imported twice under different > names, with potentially disastrous consequences. > > Therefore, as I see it, if you are developing a project using scenario 1 > above, and then want to change it to scenario 2, you have to go through the > entire project and change all import references by prepending the package > name. > > Have I got this right? > > Frank Millman > > > > I think you got it right. It happened to me as well, I guess it's a classic for program being promoted into a library. JM From jeanmichel at sequans.com Mon Mar 5 05:56:51 2012 From: jeanmichel at sequans.com (Jean-Michel Pichavant) Date: Mon, 05 Mar 2012 11:56:51 +0100 Subject: AttributeError: 'module' object has no attribute 'logger' In-Reply-To: References: Message-ID: <4F549BF3.7020707@sequans.com> youssef.mahdia at hotmail.com wrote: > hi all, when installing sage, there is a problem with emacs.py > so, this screen appeared after rynning ./sage > ---------------------------------------------------------------------- > | Sage Version 4.4.2, Release Date: 2010-05-19 | > | Type notebook() for the GUI, and license() for information. | > ---------------------------------------------------------------------- > Traceback (most recent call last): > File "/home/zid/sage/local/bin/sage-ipython", line 18, in > import IPython > File "/usr/lib/python2.7/dist-packages/IPython/__init__.py", line > 58, in > __import__(name,glob,loc,[]) > File "/usr/lib/python2.7/dist-packages/IPython/ipstruct.py", line > 17, in > from IPython.genutils import list2dict2 > File "/usr/lib/python2.7/dist-packages/IPython/genutils.py", line > 114, in > import IPython.rlineimpl as readline > File "/usr/lib/python2.7/dist-packages/IPython/rlineimpl.py", line > 18, in > from pyreadline import * > File "/usr/local/lib/python2.7/dist-packages/pyreadline-2.0_dev1- > py2.7.egg/pyreadline/__init__.py", line 11, in > from . import unicode_helper, logger, clipboard, lineeditor, > modes, console > File "/usr/local/lib/python2.7/dist-packages/pyreadline-2.0_dev1- > py2.7.egg/pyreadline/modes/__init__.py", line 3, in > from . import emacs, notemacs, vi > File "/usr/local/lib/python2.7/dist-packages/pyreadline-2.0_dev1- > py2.7.egg/pyreadline/modes/emacs.py", line 11, in > import pyreadline.logger as logger > AttributeError: 'module' object has no attribute 'logger' > > > > any one can help me pleaseeee > > regards > Zid > > > > > You probably have the wrong version of pyreadline. Try to install the last stable 1.7.1 or look for emacs.py requirement for the pyreadline version. Non constructive solution : use vim :o) JM From rantingrickjohnson at gmail.com Mon Mar 5 08:09:07 2012 From: rantingrickjohnson at gmail.com (Rick Johnson) Date: Mon, 5 Mar 2012 05:09:07 -0800 (PST) Subject: Tkinter: Why aren't my widgets expanding when I resize the window? References: <32271364.3080.1330931558529.JavaMail.geo-discussion-forums@ynjd19> Message-ID: On Mar 5, 1:12?am, John Salerno wrote: > I can't seem to wrap my head around all the necessary arguments > for making a widget expand when a window is resized. You will need to configure the root columns and rows also because the configurations DO NOT propagate up the widget hierarchy! Actually, for this example, I would recommend using the "pack" geometry manager on the frame. Only use grid when you need to use grid. Never use any functionality superfluously! Also, you should explicitly pack the frame from OUTSIDE frame.__init__()! ## START CODE ## import tkinter as tk import tkinter.ttk as ttk from tkinter.constants import BOTH, YES class AppFrame(ttk.Frame): def __init__(self, parent, **kwargs): super().__init__(parent, **kwargs) self._create_widgets() def _create_widgets(self): entry = ttk.Entry(self) entry.grid(row=0, column=1, sticky='nsew') label = ttk.Label(self, text='Name:') label.grid(row=0, column=0, sticky='nsew') root = tk.Tk() root.title('Test Application') frame = AppFrame(root, borderwidth=15, relief='sunken') frame.pack(fill=BOTH, expand=YES) root.mainloop() ## END CODE ## > Is there something wrong with the sticky argument, maybe? The > tutorial I'm reading says they can be strings, but it also uses what > appears to be a tuple of constants like this: sticky=(N, S, E, W) -- > but that didn't work either. I always use either: sticky='nswe' sticky=N+S+W+E From ned at nedbatchelder.com Mon Mar 5 08:27:08 2012 From: ned at nedbatchelder.com (Ned Batchelder) Date: Mon, 05 Mar 2012 08:27:08 -0500 Subject: [Python-Dev] [RELEASED] Python 3.3.0 alpha 1 In-Reply-To: <4F54711E.2020006@python.org> References: <4F54711E.2020006@python.org> Message-ID: <4F54BF2C.7000107@nedbatchelder.com> On 3/5/2012 2:54 AM, Georg Brandl wrote: > On behalf of the Python development team, I'm happy to announce the > first alpha release of Python 3.3.0. > > This is a preview release, and its use is not recommended in > production settings. > > Python 3.3 includes a range of improvements of the 3.x series, as well > as easier > porting between 2.x and 3.x. Major new features in the 3.3 release > series are: > > * PEP 380, Syntax for Delegating to a Subgenerator ("yield from") > * PEP 393, Flexible String Representation (doing away with the > distinction between "wide" and "narrow" Unicode builds) > * PEP 409, Suppressing Exception Context > * PEP 3151, Reworking the OS and IO exception hierarchy > * The new "packaging" module, building upon the "distribute" and > "distutils2" projects and deprecating "distutils" > * The new "lzma" module with LZMA/XZ support > * PEP 3155, Qualified name for classes and functions > * PEP 414, explicit Unicode literals to help with porting > * The new "faulthandler" module that helps diagnosing crashes > * Wrappers for many more POSIX functions in the "os" and "signal" > modules, as well as other useful functions such as "sendfile()" > > For a more extensive list of changes in 3.3.0, see > > http://docs.python.org/3.3/whatsnew/3.3.html > The 3.3 whatsnews page doesn't seem to mention PEP 414 or Unicode literals at all. --Ned. > To download Python 3.3.0 visit: > > http://www.python.org/download/releases/3.3.0/ > > Please consider trying Python 3.3.0a1 with your code and reporting any > bugs you may notice to: > > http://bugs.python.org/ > > > Enjoy! > > -- > Georg Brandl, Release Manager > georg at python.org > (on behalf of the entire python-dev team and 3.3's contributors) > _______________________________________________ > Python-Dev mailing list > Python-Dev at python.org > http://mail.python.org/mailman/listinfo/python-dev > Unsubscribe: > http://mail.python.org/mailman/options/python-dev/ned%40nedbatchelder.com > From petr.jakes.tpc at gmail.com Mon Mar 5 08:53:01 2012 From: petr.jakes.tpc at gmail.com (Petr Jakes) Date: Mon, 5 Mar 2012 05:53:01 -0800 (PST) Subject: How to convert simple B/W graphic to the dot matrix for the LED display/sign References: <94052541-e1e0-43b6-b434-59e79518cf4a@q18g2000yqh.googlegroups.com> <4f5349f2$0$29989$c3e8da3$5496439d@news.astraweb.com> Message-ID: <24a8132d-1e90-4c77-9bac-309a41395cb6@y17g2000yqg.googlegroups.com> > >>> import Image > >>> im=Image.new('L', (100,100)) > >>> im=im.convert('1') > >>> px=im.load() > >>> px[0,0] Thanks, load() method works great. One more question. Finally, I would like to store array in the database. What is the best way to store arrays? Petr From duncan.booth at invalid.invalid Mon Mar 5 11:08:01 2012 From: duncan.booth at invalid.invalid (Duncan Booth) Date: 5 Mar 2012 16:08:01 GMT Subject: [RELEASED] Python 3.3.0 alpha 1 References: Message-ID: Georg Brandl wrote: > For a more extensive list of changes in 3.3.0, see > > http://docs.python.org/3.3/whatsnew/3.3.html > So far as I can see the what's new don't mention that hash randomisation is enabled by default in Python 3.3. I think it would be worth adding something about that. Also the what's new doesn't mention PEP 414 although the release page does. -- Duncan Booth http://kupuguy.blogspot.com From phd at phdru.name Mon Mar 5 12:30:49 2012 From: phd at phdru.name (Oleg Broytman) Date: Mon, 5 Mar 2012 21:30:49 +0400 Subject: A Crypto Juniper $9$ secrets library In-Reply-To: References: Message-ID: <20120305173049.GA11270@iskra.aviel.ru> Hello! On Sun, Mar 04, 2012 at 10:16:05PM +0100, Julio G?mez wrote: > I have developed a Python library which encrypt/decrypt Juniper $9$ secrets. Thank you and welcome to the community! > I would like it is part of the common Python libraries and be able to > install it through APT, YUM, RPM... depending on the system. [skip] > Could you tell me the process I have to follow to publish the library? Let me give you some advice. First, there is Python Package Index - http://pypi.python.org/pypi - a central repository of python software. On the first page you can find all necessary information - how to register a user, how to register a package, how to register a release. The site also provides file hosting service so you can upload you releases. But you can host anywhere and only publish links to your preferred hosting. Some people just publish links to their mercurial or git repositories. Documentation uploaded to the site will be published at http://packages.python.org/ . It is also very important to send good release announcements. Please read the following introductory articles: http://en.wikipedia.org/wiki/Announcement_%28computing%29 http://perlbuzz.com/2009/03/how-to-write-an-announcement.html Read the archives of the python announcements mailing list: http://mail.python.org/pipermail/python-announce-list/ or http://groups.google.com/group/comp.lang.python.announce/topics Oleg. -- Oleg Broytman http://phdru.name/ phd at phdru.name Programmers don't die, they just GOSUB without RETURN. From johnjsal at gmail.com Mon Mar 5 12:31:09 2012 From: johnjsal at gmail.com (John Salerno) Date: Mon, 5 Mar 2012 09:31:09 -0800 (PST) Subject: Tkinter: Why aren't my widgets expanding when I resize the window? In-Reply-To: References: <32271364.3080.1330931558529.JavaMail.geo-discussion-forums@ynjd19> Message-ID: <19872402.359.1330968669581.JavaMail.geo-discussion-forums@ynnj12> > You will need to configure the root columns and rows also because the > configurations DO NOT propagate up the widget hierarchy! Actually, for > this example, I would recommend using the "pack" geometry manager on > the frame. Only use grid when you need to use grid. Never use any > functionality superfluously! Also, you should explicitly pack the > frame from OUTSIDE frame.__init__()! Ok, so use pack when putting the frame into the root, since that's all that goes into the root directly. But just out of curiosity, what did I do wrong with using grid? How would it work with grid? > from tkinter.constants import BOTH, YES > I always use either: > > sticky='nswe' > sticky=N+S+W+E This is something I'm not too thrilled with. I don't like importing things piecemeal. I suppose I could do: import tkinter.constants as tkc (or something like that) and qualify each constant. Seems like more work, but it just seems better than having to manage each constant that I need in the import list. Also, N+S+E+W and (N, S, E, W) don't seem to work unless qualified, so that's four more constants I'd have to explicitly import. And (tk.N, tk.S, tk.E, tk.W) is just horrible to look at. From rantingrickjohnson at gmail.com Mon Mar 5 14:03:23 2012 From: rantingrickjohnson at gmail.com (Rick Johnson) Date: Mon, 5 Mar 2012 11:03:23 -0800 (PST) Subject: Tkinter: Why aren't my widgets expanding when I resize the window? References: <32271364.3080.1330931558529.JavaMail.geo-discussion-forums@ynjd19> <19872402.359.1330968669581.JavaMail.geo-discussion-forums@ynnj12> Message-ID: <01a0499e-616f-4395-95d2-b6e54e03bc79@i5g2000yqo.googlegroups.com> On Mar 5, 11:31?am, John Salerno wrote: > Ok, so use pack when putting the frame into the root, since that's > all that goes into the root directly. But just out of curiosity, > what did I do wrong with using grid? How would it work with grid? If you read my post carefully, i said: "You need to use columnconfigure and rowconfigure on ROOT!". Here is the solution; although, not the correct code you should use because pack is perfect for this: ## START CODE ## import tkinter as tk import tkinter.ttk as ttk class AppFrame(ttk.Frame): def __init__(self, parent, **kwargs): super().__init__(parent, **kwargs) self.create_widgets() def create_widgets(self): entry = ttk.Entry(self) entry.grid(row=0, column=1, sticky='nsew') label = ttk.Label(self, text='Name:') label.grid(row=0, column=0, sticky='nsew') root = tk.Tk() root.title('Test Application') root.columnconfigure(0, weight=1) root.rowconfigure(0, weight=1) frame = AppFrame(root, borderwidth=15, relief='sunken') frame.grid(row=0, column=0, sticky='nsew') root.mainloop() ## END CODE ## > I don't like importing things piecemeal. I suppose I could do: So you prefer to pollute? How bout we just auto import the whole Python stdlib so you can save a few keystrokes? > import tkinter.constants as tkc (or something like that) > > and qualify each constant. Seems like more work, but it just seems > better than having to manage each constant that I need in the import > list. Then do "from tkinter.constants import *". I have no complaints against import all the constants during testing/building, however, you should be a professional and import only the constants you are going to use. > Also, N+S+E+W and (N, S, E, W) don't seem to work unless qualified, Of course not, you never imported them! How could that code possibly work? > so that's four more constants I'd have to explicitly import. And > (tk.N, tk.S, tk.E, tk.W) is just horrible to look at. Wah! Stop whining and act like a professional! You complain about qualifying constants but you happily type "self" until your fingers bleed without even a whimper??? Look, either import ONLY the constants you need, or qualify each constant with a module name/variable; that is the choices available to a professional. Or, just be lazy and pollute your namespace. FYI: Lazy coders get what they deserve in the end. From rowen at uw.edu Mon Mar 5 14:45:56 2012 From: rowen at uw.edu (Russell E. Owen) Date: Mon, 05 Mar 2012 11:45:56 -0800 Subject: Is it necessary to call Tk() when writing a GUI app with Tkinter? References: <27603449.17.1330492001624.JavaMail.geo-discussion-forums@vbbfv2> <6e1c521e-14be-4ec0-9ff0-7f23fd9cd3dc@f14g2000yqe.googlegroups.com> <3d0bf288-fa5d-48e5-9529-db92d420a915@1g2000yqv.googlegroups.com> Message-ID: In article <3d0bf288-fa5d-48e5-9529-db92d420a915 at 1g2000yqv.googlegroups.com>, Rick Johnson wrote: > On Feb 29, 11:24?pm, Terry Reedy wrote: > > On 2/29/2012 10:22 PM, Rick Johnson wrote: > > > > PS: I would highly suggest against using the "from Tkinter import *". > > > Instead, use "import Tkinter as tk" and prefix all module contents > > > with "tk.". > > > > I have changed the example to do that. I also showed the alternate to > > initialize a widget. Here is the current version, tested on Windows 3.2.2. > > > > import tkinter as tk > > > > class Application(tk.Frame): > > ? ? ?def __init__(self, master=None): > > ? ? ? ? ?tk.Frame.__init__(self, master) > > ? ? ? ? ?self.pack() > > With all due respect, I would also recommend against "self packing" a > widget. And i can speak from experience on this issue. There was a > time when i was self-packing lots of custom compund widgets; then i > realized later the shortcomings of such action; what if you need to > use the grid or place geometry mangers instead? So remove the > self.pack line and add a line to the bottom: > > > root = tk.Tk() > > app = Application(master=root) > > app.pack() # <-- added this line > > app.mainloop() I agree. Application is simply another widget, like Entry or Canvas. its contents should be packed or gridded (as appropriate) into itself, but the user should then pack or grid the Application widget as appropriate. That makes the code much more reusable. -- Russell From bob at brasko.net Mon Mar 5 15:36:39 2012 From: bob at brasko.net (Bob) Date: Mon, 5 Mar 2012 15:36:39 -0500 Subject: Error with co_filename when loading modules from zip file Message-ID: <20120305203639.GA13154@brasko> Hi, I'm using a program that distributes python in a zip file and ran into an issue with the logging package. It seems to return the wrong filename/line number when loading python from a zip file. Please help! I'm using python31, and have copied the lib directory to /home/user/python3.1 and have created a zip of that directory and placed it in /home/user/python3.1/python31.zip The logging package gets the filename and line number of the calling function by looking at two variables, the filename of the frame in the stack trace and the variable logging._srcfile. The comparison is done in logging/__init__.py:findCaller. In the situation above, when I run, PYTHONPATH=/home/user/python3.1 ./myexe run.py I see filename=/home/user/python3.1/logging/__init__.py _srcfile=/home/user/python3.1/logging/__init__.py Here, filename and _srcfile are the same, so the logger correctly outputs the filename of run.py. When I run, PYTHONPATH=/home/user/python3.1/python31.zip ./myexe run.py I see filename=/home/user/python3.1/logging/__init__.py _srcfile=/home/user/python3.1/python31.zip/logging/__init__.py Here, filename and _srcfile are different, so the logger incorrectly outputs the filename of /home/user/python3.1/logging/__init__.py I've noticed this: - the filename seems to be set when you compile the module - it seems to be set when you load the module (even after moving it) - it does not seem to get set when you load the module from the pyc in the zip file! I've tried putting only the pyc files, only the py files and both in the zip file. Any help? Thanks, Bob run.py: import logging class Handler(logging.Handler): def __init__(self): logging.Handler.__init__(self) def emit(self, record): print('message: ' + record.msg) print('filename: ' + record.pathname) print('line: ' + str(record.lineno)) logging.getLogger().addHandler(Handler()) logging.error('hi') From chris at simplistix.co.uk Mon Mar 5 16:56:34 2012 From: chris at simplistix.co.uk (Chris Withers) Date: Mon, 05 Mar 2012 21:56:34 +0000 Subject: xlutils 1.5.1 released! Message-ID: <4F553692.1070009@simplistix.co.uk> Hi All, xlutils 1.5.1 is out, fixing the usual embarrassing mistake I make when I move projects from Subversion to Git that results in some required non-.py files being omitted. All the details of where to find mailing lists, issue trackers, and the like for xlutils can be found here: http://www.simplistix.co.uk/software/python/xlutils cheers, Chris -- Simplistix - Content Management, Batch Processing & Python Consulting - http://www.simplistix.co.uk From johnjsal at gmail.com Mon Mar 5 17:07:05 2012 From: johnjsal at gmail.com (John Salerno) Date: Mon, 5 Mar 2012 14:07:05 -0800 (PST) Subject: Tkinter: Why aren't my widgets expanding when I resize the window? In-Reply-To: <01a0499e-616f-4395-95d2-b6e54e03bc79@i5g2000yqo.googlegroups.com> References: <32271364.3080.1330931558529.JavaMail.geo-discussion-forums@ynjd19> <19872402.359.1330968669581.JavaMail.geo-discussion-forums@ynnj12> <01a0499e-616f-4395-95d2-b6e54e03bc79@i5g2000yqo.googlegroups.com> Message-ID: <20757474.2202.1330985225312.JavaMail.geo-discussion-forums@ynlt17> > > I don't like importing things piecemeal. I suppose I could do: > > So you prefer to pollute? How bout we just auto import the whole > Python stdlib so you can save a few keystrokes? > > so that's four more constants I'd have to explicitly import. And > > (tk.N, tk.S, tk.E, tk.W) is just horrible to look at. > > Wah! > > Stop whining and act like a professional! You complain about > qualifying constants but you happily type "self" until your fingers > bleed without even a whimper??? > > Look, either import ONLY the constants you need, or qualify each > constant with a module name/variable; that is the choices available to > a professional. Or, just be lazy and pollute your namespace. > > FYI: Lazy coders get what they deserve in the end. How exactly am I being lazy and polluting the namespace? I never said I wanted to use the "*" import method, if that's what you are (wrongly) assuming. I said it seems cleaner and, to me, LESS lazy to import the whole module as "import tkinter.constants as tkc" and qualify everything. It's certainly more explicit than importing constants on an as-needed basis, having an ever-increasing list of constants, and referring to them unqualified in the code. Yes, I complain that tk.N, tk.S, etc. is ugly to look at, but I'm saying it seems like a better way than using them unqualified, unless maybe there is yet another, better way. As far as using "self" all the time, how do you know I never "whimpered" about it? The first time I learned about it I DIDN'T like it, because it seemed like a lot of unnecessary typing, but eventually I came to accept it because 1) you HAVE to do it, unlike the various options for referring to these constants, and 2) I began to like the explicitness of qualifying everything with "self." You are very helpful, but you sure like to throw around the term "lazy" a little too unabashedly. I never said I wanted to import with "*", which you seem to think I want to do. I LIKE qualifying things, which is the reason I didn't care so much for your method of importing the constants by name. From info at egenix.com Mon Mar 5 17:11:22 2012 From: info at egenix.com (eGenix Team: M.-A. Lemburg) Date: Mon, 05 Mar 2012 23:11:22 +0100 Subject: ANN: Python Meeting =?ISO-8859-1?Q?D=FCsseldorf_-_03=2E04=2E?= =?ISO-8859-1?Q?2012?= Message-ID: <4F553A0A.2070602@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 Ein Treffen von Python Enthusiasten und Interessierten in ungezwungener Atmosph?re. Dienstag, 03.04.2012, 18:00 Uhr Clara Schumann Raum DJH D?sseldorf http://python-meeting-duesseldorf.de/ Diese Nachricht k?nnen Sie auch online lesen: http://www.egenix.com/company/news/Python-Meeting-Duesseldorf-2012-04-03 ________________________________________________________________________ EINLEITUNG Das Python Meeting D?sseldorf ist eine neue lokale Veranstaltung in D?sseldorf, die sich an Python Begeisterte in der Region wendet. Wir starten bei den Treffen mit einer kurzen Einleitung und gehen dann zu einer Reihe Kurzvortr?gen (Lightning Talks) ?ber, bei denen die Anwesenden ?ber neue Projekte, interessante Probleme und sonstige Aktivit?ten rund um Python berichten k?nnen. Anschlie?end geht es in eine Gastst?tte, um die Gespr?che zu vertiefen. 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/ ________________________________________________________________________ ORT F?r das Python Meeting D?sseldorf haben wir den Clara Schumann Raum in der modernen Jugendherberge D?sseldorf angemietet: Jugendherberge D?sseldorf D?sseldorfer Str. 1 40545 D?sseldorf Telefon: +49 211 557310 http://www.duesseldorf.jugendherberge.de Die Jugendherberge verf?gt ?ber eine kostenpflichtige Tiefgarage (EUR 2,50 pro Stunde, maximal EUR 10,00). Es ist aber auch m?glich per Bus und Bahn anzureisen. Der Raum befindet sich im 1.OG links. ________________________________________________________________________ PROGRAMM Das Python Meeting D?sseldorf nutzt eine Mischung aus Open Space und Lightning Talks: Die Treffen starten mit einer kurzen Einleitung. Danach geht es weiter mit einer Lightning Talk Session, in der die Anwesenden Kurzvortr?ge von f?nf Minuten halten k?nnen. Hieraus ergeben sich dann meisten viele Ansatzpunkte f?r Diskussionen, die dann den Rest der verf?gbaren Zeit in Anspruch nehmen k?nnen. F?r 19:45 Uhr haben wir in einem nahegelegenen Restaurant Pl?tze reserviert, damit auch das leibliche Wohl nicht zu kurz kommt. 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. Da Tagungsraum, Beamer, Internet und Getr?nke Kosten produzieren, bitten wir die Teilnehmer um einen Beitrag in H?he von EUR 10,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://python-meeting-duesseldorf.de/ Mit freundlichen Gr??en, -- Marc-Andre Lemburg eGenix.com Professional Python Services directly from the Source (#1, Mar 05 2012) >>> Python/Zope Consulting and Support ... http://www.egenix.com/ >>> mxODBC.Zope.Database.Adapter ... http://zope.egenix.com/ >>> mxODBC, mxDateTime, mxTextTools ... http://python.egenix.com/ ________________________________________________________________________ 2012-02-13: Released eGenix pyOpenSSL 0.13 http://egenix.com/go26 2012-02-09: Released mxODBC.Zope.DA 2.0.2 http://egenix.com/go25 2012-02-06: Released eGenix mx Base 3.2.3 http://egenix.com/go24 ::: Try our new 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 vinay_sajip at yahoo.co.uk Mon Mar 5 17:22:55 2012 From: vinay_sajip at yahoo.co.uk (Vinay Sajip) Date: Mon, 5 Mar 2012 14:22:55 -0800 (PST) Subject: Error with co_filename when loading modules from zip file References: Message-ID: On Mar 5, 8:36?pm, Bob wrote: > The logging package gets the filename and line number > of the calling function by looking at two variables, the filename > of the frame in the stack trace and the variable logging._srcfile. > The comparison is done in logging/__init__.py:findCaller. > The _srcfile is computed in logging/__init__.py - can you see which of the paths it takes when computing _srcfile? > I've tried putting only the pyc files, only the py files > and both in the zip file. I think the filename info might be stored in the .pyc from when you ran it outside the .zip. If you delete all .pyc files and only have .py in the .zip, what happens? Regards, Vinay Sajip From python.list at tim.thechases.com Mon Mar 5 20:10:41 2012 From: python.list at tim.thechases.com (Tim Chase) Date: Mon, 05 Mar 2012 19:10:41 -0600 Subject: State of Python+OpenAL? Message-ID: <4F556411.9030304@tim.thechases.com> Hunting around to see if there's any existing work to get 3d audio in Python, I encountered two packages (pyopenal[1] & alpy[2]), but both seem sparsely documented if at all and somewhat abandoned. Has anybody used either, or have any pointers on getting up to speed on either? Thanks, -tkc [1] http://home.gna.org/oomadness/en/pyopenal/ https://github.com/forrestv/pyopenal [2] http://www.stolk.org/alpy/ From steve+comp.lang.python at pearwood.info Mon Mar 5 20:10:50 2012 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 06 Mar 2012 01:10:50 GMT Subject: Tkinter: Why aren't my widgets expanding when I resize the window? References: <32271364.3080.1330931558529.JavaMail.geo-discussion-forums@ynjd19> <19872402.359.1330968669581.JavaMail.geo-discussion-forums@ynnj12> <01a0499e-616f-4395-95d2-b6e54e03bc79@i5g2000yqo.googlegroups.com> <20757474.2202.1330985225312.JavaMail.geo-discussion-forums@ynlt17> Message-ID: <4f55641a$0$29989$c3e8da3$5496439d@news.astraweb.com> On Mon, 05 Mar 2012 14:07:05 -0800, John Salerno quoted: >> Wah! >> >> Stop whining and act like a professional! You complain about qualifying >> constants but you happily type "self" until your fingers bleed without >> even a whimper??? John, it is polite to leave attributions in place when you quote somebody. I don't know who you are quoting above, but given the obnoxious tone and the fact that this is about Tkinter, I'm guessing it is RantingRick, a.k.a. Rick Johnson. Rick is a notorious troll, and you'll probably save yourself a lot of grief if you pay no attention to him. It's not so much that his advice is *always* bad, but that you'll spend so many hours sifting through the piles of bad advice, unprofessional language, and annoying self- aggrandisement for the occasional nugget of gold that it just isn't worth it. Which is a pity, because I gather that Rick actually does know Tkinter well. But dealing with him is like wrestling with a pig: "I learned long ago, never to wrestle with a pig. You get dirty, and besides, the pig likes it." -- George Bernard Shaw -- Steven From xahlee at gmail.com Mon Mar 5 20:11:09 2012 From: xahlee at gmail.com (Xah Lee) Date: Mon, 5 Mar 2012 17:11:09 -0800 (PST) Subject: are int, float, long, double, side-effects of computer engineering? Message-ID: <5aaded58-af09-41dc-9afd-56d7b7ced239@d7g2000pbl.googlegroups.com> some additional info i thought is relevant. are int, float, long, double, side-effects of computer engineering? Xah Lee wrote: ?? One easy way to measure it is whether a programer can read and understand a program without having to delve into its idiosyncrasies. ?? Chris Angelico wrote: ?Neither the behavior of ints nor the behavior of IEEE floating point is a "quirk" or an "idiosyncracy". ?? they are computer engineering by-products. Are quirks and idiosyncracies. Check out a advanced lang such as Mathematica. There, one can learn how the mathematical concept of integer or real number are implemented in a computer language, without lots by-products of comp engineering as in vast majority of langs (all those that chalks up to some IEEEEEEE. (which, sadly, includes C, C++, perl, python, lisp, and almost all. (Common/Scheme lisp idiots speak of the jargon ?number tower? instead IEEEE.) (part of the reason almost all langs stick to some IEEEEEEEE stuff is because it's kinda standard, and everyone understand it, in the sense that unix RFC (aka really fucking common) is wide-spread because its free yet technically worst. (in a sense, when everybody's stupid, there arise a cost to not be stupid.)))). A friend asked: ?Can you enlighten us as to Mathematica's way of handling numbers, either by a post or a link to suitable documentation? ?? what i meant to point out is that Mathematica deals with numbers at a high-level human way. That is, one doesn't think in terms of float, long, int, double. These words are never mentioned. Instead, you have concepts of machine precision, accuracy. The lang automatically handle the translation to hardware, and invoking exact value or infinite precision as required or requested. in most lang's doc, words like int, long, double, float are part of the lang, and it's quick to mention IEEE. Then you have the wide- spread overflow issue in your lang. In M, the programer only need to think in terms of math, i.e. Real number, Integer, complex number, precision, accuracy, etc. this is what i meat that most lang deals with computer engineering by- products, and i wished them to be higher level like M. http://reference.wolfram.com/mathematica/guide/PrecisionAndAccuracyControl.html Xah From johnjsal at gmail.com Mon Mar 5 20:53:29 2012 From: johnjsal at gmail.com (John Salerno) Date: Mon, 5 Mar 2012 17:53:29 -0800 (PST) Subject: Tkinter: Why aren't my widgets expanding when I resize the window? In-Reply-To: <4f55641a$0$29989$c3e8da3$5496439d@news.astraweb.com> References: <32271364.3080.1330931558529.JavaMail.geo-discussion-forums@ynjd19> <19872402.359.1330968669581.JavaMail.geo-discussion-forums@ynnj12> <01a0499e-616f-4395-95d2-b6e54e03bc79@i5g2000yqo.googlegroups.com> <20757474.2202.1330985225312.JavaMail.geo-discussion-forums@ynlt17> <4f55641a$0$29989$c3e8da3$5496439d@news.astraweb.com> Message-ID: <25803773.4638.1330998809513.JavaMail.geo-discussion-forums@vbw15> On Monday, March 5, 2012 7:10:50 PM UTC-6, Steven D'Aprano wrote: > On Mon, 05 Mar 2012 14:07:05 -0800, John Salerno quoted: > > >> Wah! > >> > >> Stop whining and act like a professional! You complain about qualifying > >> constants but you happily type "self" until your fingers bleed without > >> even a whimper??? > > John, it is polite to leave attributions in place when you quote > somebody. I don't know who you are quoting above, but given the obnoxious > tone and the fact that this is about Tkinter, I'm guessing it is > RantingRick, a.k.a. Rick Johnson. > > Rick is a notorious troll, and you'll probably save yourself a lot of > grief if you pay no attention to him. It's not so much that his advice is > *always* bad, but that you'll spend so many hours sifting through the > piles of bad advice, unprofessional language, and annoying self- > aggrandisement for the occasional nugget of gold that it just isn't worth > it. > > Which is a pity, because I gather that Rick actually does know Tkinter > well. But dealing with him is like wrestling with a pig: > > "I learned long ago, never to wrestle with a pig. You get dirty, and > besides, the pig likes it." -- George Bernard Shaw > > > -- > Steven Thank you. Sorry about the attribution. That was my fault because I was trying to cite just the relevant bits, and I cut off the header too. From breamoreboy at yahoo.co.uk Mon Mar 5 20:58:22 2012 From: breamoreboy at yahoo.co.uk (Mark Lawrence) Date: Tue, 06 Mar 2012 01:58:22 +0000 Subject: Tkinter: Why aren't my widgets expanding when I resize the window? In-Reply-To: <4f55641a$0$29989$c3e8da3$5496439d@news.astraweb.com> References: <32271364.3080.1330931558529.JavaMail.geo-discussion-forums@ynjd19> <19872402.359.1330968669581.JavaMail.geo-discussion-forums@ynnj12> <01a0499e-616f-4395-95d2-b6e54e03bc79@i5g2000yqo.googlegroups.com> <20757474.2202.1330985225312.JavaMail.geo-discussion-forums@ynlt17> <4f55641a$0$29989$c3e8da3$5496439d@news.astraweb.com> Message-ID: On 06/03/2012 01:10, Steven D'Aprano wrote: > Which is a pity, because I gather that Rick actually does know Tkinter > well. +1. Please Rick less of the Dark Side. :) -- Cheers. Mark Lawrence. From bob at brasko.net Mon Mar 5 21:14:08 2012 From: bob at brasko.net (Bob Rossi) Date: Mon, 5 Mar 2012 21:14:08 -0500 Subject: Error with co_filename when loading modules from zip file In-Reply-To: References: Message-ID: <20120306021408.GB13154@brasko> On Mon, Mar 05, 2012 at 02:22:55PM -0800, Vinay Sajip wrote: > On Mar 5, 8:36?pm, Bob wrote: > > > The logging package gets the filename and line number > > of the calling function by looking at two variables, the filename > > of the frame in the stack trace and the variable logging._srcfile. > > The comparison is done in logging/__init__.py:findCaller. > > > > The _srcfile is computed in logging/__init__.py - can you see which of > the paths it takes when computing _srcfile? Yes, it's this one, elif __file__[-4:].lower() in ['.pyc', '.pyo']: _srcfile = __file__[:-4] + '.py' _srcfile I beleive is correct. It's filename that isn't IMHO. > > I've tried putting only the pyc files, only the py files > > and both in the zip file. > > I think the filename info might be stored in the .pyc from when you > ran it outside the .zip. If you delete all .pyc files and only > have .py in the .zip, what happens? Nice one. I tried putting only pyc file, only py files and both in the zip. But I never tried putting the py files in the zip and deleting the pyc files. That makes it work as I'm guessing it has to recompile the python bytecode, making the filename and _srcfile match. The problem with this approach, is that it's less efficient to store the pyc files, since I've got to recompile them on startup, right? I found this issue, http://bugs.python.org/issue6811 and this related patch, http://hg.python.org/cpython/rev/5deb2094f033 that I think might address this issue. Although that's using 3.3 which isn't released yet. This is probably an issue that could be addressed in the logging library. Comparing the compiled in filename (which is determined at compile time) and the source file name (which is determined at module load time) doesn't seem to play well when you are moving the interpreter around in a zip file. I don't think one would expect it to. One solution would be to look to see if the filename ends in pythonNM[.zip]/logging/__init__.py Any suggestions? Thanks, Bob From breamoreboy at yahoo.co.uk Mon Mar 5 21:14:30 2012 From: breamoreboy at yahoo.co.uk (Mark Lawrence) Date: Tue, 06 Mar 2012 02:14:30 +0000 Subject: are int, float, long, double, side-effects of computer engineering? In-Reply-To: <5aaded58-af09-41dc-9afd-56d7b7ced239@d7g2000pbl.googlegroups.com> References: <5aaded58-af09-41dc-9afd-56d7b7ced239@d7g2000pbl.googlegroups.com> Message-ID: On 06/03/2012 01:11, Xah Lee wrote: > some additional info i thought is relevant. > > are int, float, long, double, side-effects of computer engineering? > Whatever you're taking please can I have some? Is it available via an NHS prescription or do I have to go private, or do I go down the pub and get it illegally? -- Cheers. Mark Lawrence. From cookfitz at gmail.com Mon Mar 5 21:17:58 2012 From: cookfitz at gmail.com (nac) Date: Mon, 5 Mar 2012 18:17:58 -0800 (PST) Subject: RotatingFileHandler Fails References: Message-ID: <64b7d1bb-21b0-4c72-aa93-692504201f7e@j8g2000yqm.googlegroups.com> On Mar 5, 4:27?am, Jean-Michel Pichavant wrote: > nac wrote: > > The RotatingFileHandler running on win 7 64-bit; py 2.7 is failing > > when the script launches a process using subprocess.Popen. Works fine > > if the subprocess is not launched > > > The exception thrown > > Traceback (most recent call last): > > ? File "C:\Python27\lib\logging\handlers.py", line 78, in emit > > ? ? self.doRollover() > > ? File "C:\Python27\lib\logging\handlers.py", line 141, in doRollover > > ? ? os.rename(self.baseFilename, dfn) > > WindowsError: [Error 32] The process cannot access the file because it > > is being used by another process > > > Anyone have an idea how to fix this? > > > import os, sys > > import logging > > import logging.handlers > > import subprocess > > > def chomp(s): > > ? ? ? "remove trailing carriage return" > > ? ? ? if s[-1:]=='\n': return s[:-1] > > ? ? ? else: return s > > > logging.basicConfig(level=logging.DEBUG, format='%(asctime)s % > > (name)-2s %(levelname)-8s %(threadName)-12s %(message)s') > > q5Logger = logging.getLogger('Q5') > > logFileHandler = logging.handlers.RotatingFileHandler(filename='c:\ > > \logger\\q5.log', mode= 'a', maxBytes=100, backupCount=5) > > logFileHandler.setFormatter(logging.Formatter('%(asctime)s %(name)-2s % > > (levelname)-8s %(threadName)-12s %(message)s')) > > logFileHandler.setLevel(logging.DEBUG) > > q5Logger.addHandler(logFileHandler) > > > progOutput = subprocess.Popen(r'dir *.*', shell=True, bufsize=1000, > > stdout=subprocess.PIPE).stdout > > line = progOutput.readline() > > while (line) != "": > > ? ? ? q5Logger.info( chomp(line)) > > ? ? ? line = progOutput.readline() > > rc = progOutput.close() > > I don't think you can open a file from 2 different processes, hence the > error message. The only exception would be that one of them opens it in > read only mode which won't happen for log file. > > You cannot fix it, it is the operand system that blocks the operation. > Using thread may allow you to log into the same file, but could bring a > bunch of other problems. > > I know some ppl use a log server, your processes using a socket (client) > logger. You could do that on your local machine. There's a tutorial on > that in the logging documentation. > > JM Thanks for taking the time to look at the problem. In case you are interested I was able to get this to work with the code at URL below. Seemed to work because the subprocess I am running is not actually using the log file but the OS make it inherit a handle to the log file. The code below disables that inheritance. Do you see any problems with the approach? http://bugs.python.org/file14420/NTSafeLogging.py From rantingrickjohnson at gmail.com Mon Mar 5 21:20:36 2012 From: rantingrickjohnson at gmail.com (Rick Johnson) Date: Mon, 5 Mar 2012 18:20:36 -0800 (PST) Subject: Tkinter: Why aren't my widgets expanding when I resize the window? References: <32271364.3080.1330931558529.JavaMail.geo-discussion-forums@ynjd19> <19872402.359.1330968669581.JavaMail.geo-discussion-forums@ynnj12> <01a0499e-616f-4395-95d2-b6e54e03bc79@i5g2000yqo.googlegroups.com> <20757474.2202.1330985225312.JavaMail.geo-discussion-forums@ynlt17> <4f55641a$0$29989$c3e8da3$5496439d@news.astraweb.com> Message-ID: <29142434-eeaf-4c94-8d64-f1f2d4cb500e@t15g2000yqi.googlegroups.com> On Mar 5, 7:10?pm, Steven D'Aprano wrote: > John, it is polite to leave attributions in place when you quote > somebody. I don't know who you are quoting above, > [...] > Which is a pity, because I gather that Rick actually does know Tkinter > well. My, my. Between your ad hominem attacks, FUD, wild assumptions, and veiled insults you did manage to get ONE small sentence of truthful content to propagate up; congratulations! Excuse me whist i toss my cookies! > But dealing with him is like wrestling with a pig: And there it is again. We can't admit Rick is correct without insulting him. But Steven, when have you EVER dealt with me on a professional level? When have you EVER offered a helping hand to one of my issues? For example: I can remember asking you to explain the new .format method of Py3000 and you said: "Sorry, too busy!". But you where not too busy to troll-up the list! WHEN have you ever admitted (without insulting me first) that i am in fact an asset to this community? Do you think this community will ever be a homogeneous block? And if so, would that be a good thing? I have an idea: How about YOU stop clinging to some archaic ideal of what YOU *think* this community *should* be, and instead, start opening up your mind to diverse personalities and diverse ideas. Heck, maybe you'll learn something new, "old dog". Remember how much you ranted about diversity in evolution? And now you have the AUDACITY to preach the opposite just to suit your own selfish argument. You are as hollow as a politician Steven. Nothing that you say can be taken seriously because it is just more propaganda and lies. And one more thing, If ANYONE on this list deserves "thespian of the year" award, it is you my friend! Between your comeo appearances as "Devils Advocate", "Sammy the Strawman Stuffer", "Snarky Detractor", and the ever-present "Troll Slayer" (saving damsels in distress from the trolls of c.l.p) -- i'd say you have the nomination won by a landslide! From breamoreboy at yahoo.co.uk Mon Mar 5 21:33:03 2012 From: breamoreboy at yahoo.co.uk (Mark Lawrence) Date: Tue, 06 Mar 2012 02:33:03 +0000 Subject: Tkinter: Why aren't my widgets expanding when I resize the window? In-Reply-To: <29142434-eeaf-4c94-8d64-f1f2d4cb500e@t15g2000yqi.googlegroups.com> References: <32271364.3080.1330931558529.JavaMail.geo-discussion-forums@ynjd19> <19872402.359.1330968669581.JavaMail.geo-discussion-forums@ynnj12> <01a0499e-616f-4395-95d2-b6e54e03bc79@i5g2000yqo.googlegroups.com> <20757474.2202.1330985225312.JavaMail.geo-discussion-forums@ynlt17> <4f55641a$0$29989$c3e8da3$5496439d@news.astraweb.com> <29142434-eeaf-4c94-8d64-f1f2d4cb500e@t15g2000yqi.googlegroups.com> Message-ID: On 06/03/2012 02:20, Rick Johnson wrote: > On Mar 5, 7:10 pm, Steven D'Aprano +comp.lang.pyt... at pearwood.info> wrote: > >> John, it is polite to leave attributions in place when you quote >> somebody. I don't know who you are quoting above, >> [...] >> Which is a pity, because I gather that Rick actually does know Tkinter >> well. > > My, my. Between your ad hominem attacks, FUD, wild assumptions, and > veiled insults you did manage to get ONE small sentence of truthful > content to propagate up; congratulations! Excuse me whist i toss my > cookies! > >> But dealing with him is like wrestling with a pig: > > And there it is again. We can't admit Rick is correct without > insulting him. > > But Steven, when have you EVER dealt with me on a professional level? > When have you EVER offered a helping hand to one of my issues? For > example: I can remember asking you to explain the new .format method > of Py3000 and you said: "Sorry, too busy!". But you where not too busy > to troll-up the list! WHEN have you ever admitted (without insulting > me first) that i am in fact an asset to this community? Do you think > this community will ever be a homogeneous block? And if so, would that > be a good thing? > > I have an idea: How about YOU stop clinging to some archaic ideal of > what YOU *think* this community *should* be, and instead, start > opening up your mind to diverse personalities and diverse ideas. Heck, > maybe you'll learn something new, "old dog". Remember how much you > ranted about diversity in evolution? And now you have the AUDACITY to > preach the opposite just to suit your own selfish argument. You are as > hollow as a politician Steven. Nothing that you say can be taken > seriously because it is just more propaganda and lies. > > And one more thing, If ANYONE on this list deserves "thespian of the > year" award, it is you my friend! Between your comeo appearances as > "Devils Advocate", "Sammy the Strawman Stuffer", "Snarky Detractor", > and the ever-present "Troll Slayer" (saving damsels in distress from > the trolls of c.l.p) -- i'd say you have the nomination won by a > landslide! > There is no need for this. You (as I've stated in another reply) seem to know what you're talking about WRT tkinter so please stick with the Light rather than the Dark Side. -- Cheers. Mark Lawrence. From bob at brasko.net Mon Mar 5 21:40:07 2012 From: bob at brasko.net (Bob Rossi) Date: Mon, 5 Mar 2012 21:40:07 -0500 Subject: Error with co_filename when loading modules from zip file In-Reply-To: References: Message-ID: <20120306024006.GE13154@brasko> On Mon, Mar 05, 2012 at 02:22:55PM -0800, Vinay Sajip wrote: > On Mar 5, 8:36?pm, Bob wrote: > > > The logging package gets the filename and line number > > of the calling function by looking at two variables, the filename > > of the frame in the stack trace and the variable logging._srcfile. > > The comparison is done in logging/__init__.py:findCaller. > > > > The _srcfile is computed in logging/__init__.py - can you see which of > the paths it takes when computing _srcfile? > > > I've tried putting only the pyc files, only the py files > > and both in the zip file. > > I think the filename info might be stored in the .pyc from when you > ran it outside the .zip. If you delete all .pyc files and only > have .py in the .zip, what happens? Darn it, this was reported in 2007 http://bugs.python.org/issue1180193 and it was mentioned the logging package was effected. Yikes. Any resolutions? Bob From rantingrickjohnson at gmail.com Mon Mar 5 21:56:12 2012 From: rantingrickjohnson at gmail.com (Rick Johnson) Date: Mon, 5 Mar 2012 18:56:12 -0800 (PST) Subject: Tkinter: Why aren't my widgets expanding when I resize the window? References: <32271364.3080.1330931558529.JavaMail.geo-discussion-forums@ynjd19> <19872402.359.1330968669581.JavaMail.geo-discussion-forums@ynnj12> <01a0499e-616f-4395-95d2-b6e54e03bc79@i5g2000yqo.googlegroups.com> <20757474.2202.1330985225312.JavaMail.geo-discussion-forums@ynlt17> <4f55641a$0$29989$c3e8da3$5496439d@news.astraweb.com> <29142434-eeaf-4c94-8d64-f1f2d4cb500e@t15g2000yqi.googlegroups.com> Message-ID: <69af9e72-270f-4ba9-a24c-dfc81a965afd@k29g2000yqc.googlegroups.com> On Mar 5, 8:33?pm, Mark Lawrence wrote: > please stick with the > Light rather than the Dark Side. You're correct. I need to ignore these negative distractions. Thanks for re-focusing the conversation. From breamoreboy at yahoo.co.uk Mon Mar 5 22:09:16 2012 From: breamoreboy at yahoo.co.uk (Mark Lawrence) Date: Tue, 06 Mar 2012 03:09:16 +0000 Subject: Tkinter: Why aren't my widgets expanding when I resize the window? In-Reply-To: <69af9e72-270f-4ba9-a24c-dfc81a965afd@k29g2000yqc.googlegroups.com> References: <32271364.3080.1330931558529.JavaMail.geo-discussion-forums@ynjd19> <19872402.359.1330968669581.JavaMail.geo-discussion-forums@ynnj12> <01a0499e-616f-4395-95d2-b6e54e03bc79@i5g2000yqo.googlegroups.com> <20757474.2202.1330985225312.JavaMail.geo-discussion-forums@ynlt17> <4f55641a$0$29989$c3e8da3$5496439d@news.astraweb.com> <29142434-eeaf-4c94-8d64-f1f2d4cb500e@t15g2000yqi.googlegroups.com> <69af9e72-270f-4ba9-a24c-dfc81a965afd@k29g2000yqc.googlegroups.com> Message-ID: On 06/03/2012 02:56, Rick Johnson wrote: > On Mar 5, 8:33 pm, Mark Lawrence wrote: >> please stick with the >> Light rather than the Dark Side. > > You're correct. I need to ignore these negative distractions. Thanks > for re-focusing the conversation. No problem, but as I've often stated in the past my normal professional fee applies which is two (2) pints of Ringwood Old Thumper or equivalent should you ever be in my neck of the woods. :) http://www.ringwoodbrewery.co.uk/beers/beer.aspx?bid=3 -- Cheers. Mark Lawrence. From anikom15 at gmail.com Mon Mar 5 22:17:37 2012 From: anikom15 at gmail.com (Westley =?iso-8859-1?Q?Mart=EDnez?=) Date: Mon, 5 Mar 2012 19:17:37 -0800 Subject: are int, float, long, double, side-effects of computer engineering? In-Reply-To: <5aaded58-af09-41dc-9afd-56d7b7ced239@d7g2000pbl.googlegroups.com> References: <5aaded58-af09-41dc-9afd-56d7b7ced239@d7g2000pbl.googlegroups.com> Message-ID: <20120306031736.GA30612@kubrick> On Mon, Mar 05, 2012 at 05:11:09PM -0800, Xah Lee wrote: > some additional info i thought is relevant. > > are int, float, long, double, side-effects of computer engineering? > > Xah Lee wrote: > ?? One easy way to measure it is whether a programer can read and > understand a program without having to delve into its idiosyncrasies. > ?? > > Chris Angelico wrote: > ?Neither the behavior of ints nor the behavior of IEEE floating point > is a "quirk" or an "idiosyncracy". ?? > > they are computer engineering by-products. Are quirks and > idiosyncracies. Check out a advanced lang such as Mathematica. There, > one can learn how the mathematical concept of integer or real number > are implemented in a computer language, without lots by-products of > comp engineering as in vast majority of langs (all those that chalks > up to some IEEEEEEE. (which, sadly, includes C, C++, perl, python, > lisp, and almost all. (Common/Scheme lisp idiots speak of the jargon > ?number tower? instead IEEEE.) (part of the reason almost all langs > stick to some IEEEEEEEE stuff is because it's kinda standard, and > everyone understand it, in the sense that unix RFC (aka really fucking > common) is wide-spread because its free yet technically worst. (in a > sense, when everybody's stupid, there arise a cost to not be > stupid.)))). > > > A friend asked: ?Can you enlighten us as to Mathematica's way of > handling numbers, either by a post or a link to suitable > documentation? ?? > > what i meant to point out is that Mathematica deals with numbers at a > high-level human way. That is, one doesn't think in terms of float, > long, int, double. These words are never mentioned. Instead, you have > concepts of machine precision, accuracy. The lang automatically handle > the translation to hardware, and invoking exact value or infinite > precision as required or requested. > > in most lang's doc, words like int, long, double, float are part of > the lang, and it's quick to mention IEEE. Then you have the wide- > spread overflow issue in your lang. In M, the programer only need to > think in terms of math, i.e. Real number, Integer, complex number, > precision, accuracy, etc. > > this is what i meat that most lang deals with computer engineering by- > products, and i wished them to be higher level like M. > > http://reference.wolfram.com/mathematica/guide/PrecisionAndAccuracyControl.html Try Fortran. From timr at probo.com Tue Mar 6 00:26:21 2012 From: timr at probo.com (Tim Roberts) Date: Mon, 05 Mar 2012 21:26:21 -0800 Subject: are int, float, long, double, side-effects of computer engineering? References: <5aaded58-af09-41dc-9afd-56d7b7ced239@d7g2000pbl.googlegroups.com> Message-ID: Xah Lee wrote: > >some additional info i thought is relevant. > >are int, float, long, double, side-effects of computer engineering? Of course they are. Such concepts violate the purity of a computer language's abstraction of the underlying hardware. We accept that violation because of performance reasons. There are, as you point out, languages that do maintain the purity of the abstraction, but that purity is ALWAYS at the expense of performance. I would also point out pre-emptively that there is nothing inherently wrong with asking us to accept an impure abstraction in exchange for performance. It is a performance choice that we choose to make. -- Tim Roberts, timr at probo.com Providenza & Boekelheide, Inc. From xahlee at gmail.com Tue Mar 6 01:34:46 2012 From: xahlee at gmail.com (Xah Lee) Date: Mon, 5 Mar 2012 22:34:46 -0800 (PST) Subject: are int, float, long, double, side-effects of computer engineering? References: <5aaded58-af09-41dc-9afd-56d7b7ced239@d7g2000pbl.googlegroups.com> Message-ID: On Mar 5, 9:26?pm, Tim Roberts wrote: > Xah Lee wrote: > > >some additional info i thought is relevant. > > >are int, float, long, double, side-effects of computer engineering? > > Of course they are. ?Such concepts violate the purity of a computer > language's abstraction of the underlying hardware. ?We accept that > violation because of performance reasons. ?There are, as you point out, > languages that do maintain the purity of the abstraction, but that purity > is ALWAYS at the expense of performance. > > I would also point out pre-emptively that there is nothing inherently wrong > with asking us to accept an impure abstraction in exchange for performance. > It is a performance choice that we choose to make. while what you said is true, but the problem is that 99.99% of programers do NOT know this. They do not know Mathematica. They've never seen a language with such feature. The concept is alien. This is what i'd like to point out and spread awareness. also, argument about raw speed and fine control vs automatic management, rots with time. Happened with auto memory management, managed code, compilers, auto type conversion, auto extension of array, auto type system, dynamic/scripting languages, etc. i'd share this these talks: ?Programing Language: Steve Yegge on Dynamic Languages? http://xahlee.org/comp/Steve_Yegge_on_dynamic_languages.html ?Guy Steele on Parallel Programing: Get rid of cons!? http://xahlee.org/comp/Guy_Steele_parallel_computing.html ?Ocaml Use in Industry (Janestreet Talk by Yaron Minsky)? http://xahlee.org/comp/Yaron_Minsky_Janestreet_talk.html ?Stephen Wolfram: The Background and Vision of Mathematica ? http://xahlee.blogspot.com/2011/10/stephen-wolfram-background-and-vision.html Xah From russ.paielli at gmail.com Tue Mar 6 03:02:22 2012 From: russ.paielli at gmail.com (Russ P.) Date: Tue, 6 Mar 2012 00:02:22 -0800 (PST) Subject: are int, float, long, double, side-effects of computer engineering? References: <5aaded58-af09-41dc-9afd-56d7b7ced239@d7g2000pbl.googlegroups.com> Message-ID: <10cca95e-69a5-4c36-9eb4-564b738cc158@x5g2000pbl.googlegroups.com> On Mar 5, 10:34?pm, Xah Lee wrote: > On Mar 5, 9:26?pm, Tim Roberts wrote: > > > Xah Lee wrote: > > > >some additional info i thought is relevant. > > > >are int, float, long, double, side-effects of computer engineering? > > > Of course they are. ?Such concepts violate the purity of a computer > > language's abstraction of the underlying hardware. ?We accept that > > violation because of performance reasons. ?There are, as you point out, > > languages that do maintain the purity of the abstraction, but that purity > > is ALWAYS at the expense of performance. > > > I would also point out pre-emptively that there is nothing inherently wrong > > with asking us to accept an impure abstraction in exchange for performance. > > It is a performance choice that we choose to make. > > while what you said is true, but the problem is that 99.99% of > programers do NOT know this. They do not know Mathematica. They've > never seen a language with such feature. The concept is alien. This is > what i'd like to point out and spread awareness. I seriously doubt that. I think most decent programmers are well aware of the limitations of floating point math. If properly used, double- precision arithmetic is more than adequate for the vast majority of practical scientific and engineering problems. > also, argument about raw speed and fine control vs automatic > management, rots with time. Happened with auto memory management, > managed code, compilers, auto type conversion, auto extension of > array, auto type system, dynamic/scripting languages, etc. First of all, "dynamic/scripting languages" are still a long, long way from being "fast enough" for computationally intensive applications. Secondly, nothing is stopping anyone from writing a library to implement rational numbers or infinite-precision arithmetic in python (or just about any other language). They are just not needed for most applications. From seomurthy at gmail.com Tue Mar 6 04:14:18 2012 From: seomurthy at gmail.com (Murthy) Date: Tue, 6 Mar 2012 01:14:18 -0800 (PST) Subject: Free Computer Hacking Tips Message-ID: <8326f9db-3cf6-48ab-b225-ed23193bfd8a@z5g2000pbu.googlegroups.com> Free Computer Hacking Tips - http://computertipzz.blogspot.com From chiron613.no.spam. at no.spam.please.gmail.com Tue Mar 6 05:00:44 2012 From: chiron613.no.spam. at no.spam.please.gmail.com (Chiron) Date: Tue, 06 Mar 2012 10:00:44 GMT Subject: are int, float, long, double, side-effects of computer engineering? References: <5aaded58-af09-41dc-9afd-56d7b7ced239@d7g2000pbl.googlegroups.com> Message-ID: On Mon, 05 Mar 2012 17:11:09 -0800, Xah Lee wrote: Yes. Why do you ask? Is this not obvious? Was this a rhetorical question? -- A girl with a future avoids the man with a past. -- Evan Esar, "The Humor of Humor" From chiron613.no.spam. at no.spam.please.gmail.com Tue Mar 6 05:10:11 2012 From: chiron613.no.spam. at no.spam.please.gmail.com (Chiron) Date: Tue, 06 Mar 2012 10:10:11 GMT Subject: are int, float, long, double, side-effects of computer engineering? References: <5aaded58-af09-41dc-9afd-56d7b7ced239@d7g2000pbl.googlegroups.com> Message-ID: <7ol5r.29957$zD5.14377@newsfe12.iad> On Mon, 05 Mar 2012 22:34:46 -0800, Xah Lee wrote: > while what you said is true, but the problem is that 99.99% of > programers do NOT know this. They do not know Mathematica. They've never > seen a Could you please offer some evidence to support this claim? Most of the programmers I've ever run into, were quite familiar with the notion that many aspects of their languages were artifacts of hardware limitations. You don't need Mathematica to figure out that (10.0 * 0.1) - 1.0 doesn't often equal 0.0. The moment you try such comparisons with floats, you figure it out. Oh, granted - the *first* time you try it, you might spend days trying to understand what's wrong. But having done that, you will never, ever fail to understand about the evils of computer engineering. Anyway, most programmers probably get burned like this early on, if they forget that numeric representations in most languages are inaccurate. They don't need Mathematica to help them understand. BTW, for those who don't have access to Mathematica, I highly recommend sagemath. I have no way of making a comparison between the two (I have no access to Mathematica), but sagemath is mature, useful, and fast. -- You will be singled out for promotion in your work. From vinay_sajip at yahoo.co.uk Tue Mar 6 05:38:50 2012 From: vinay_sajip at yahoo.co.uk (Vinay Sajip) Date: Tue, 6 Mar 2012 02:38:50 -0800 (PST) Subject: Error with co_filename when loading modules from zip file References: Message-ID: <6c8fd85f-b489-450e-82a4-ee01b231a09f@n12g2000yqb.googlegroups.com> On Mar 6, 2:40?am, Bob Rossi wrote: > Darn it, this was reported in 2007 > ?http://bugs.python.org/issue1180193 > and it was mentioned the logging package was effected. > > Yikes. > I will think about this, but don't expect any quick resolution :-( I think the right fix would be not in the logging package, but in the module loading machinery (as mentioned on that issue). I wouldn't worry about the performance aspect - once the logging package is loaded, there's no performance impact. That's a tiny one- off hit which you will probably not notice at all. Regards, Vinay Sajip From ndbecker2 at gmail.com Tue Mar 6 07:34:34 2012 From: ndbecker2 at gmail.com (Neal Becker) Date: Tue, 06 Mar 2012 07:34:34 -0500 Subject: pickle/unpickle class which has changed Message-ID: What happens if I pickle a class, and later unpickle it where the class now has added some new attributes? From xahlee at gmail.com Tue Mar 6 08:11:40 2012 From: xahlee at gmail.com (Xah Lee) Date: Tue, 6 Mar 2012 05:11:40 -0800 (PST) Subject: a interesting Parallel Programing Problem: asciify-string Message-ID: <210c7726-b189-4824-8560-d5ad25ac7583@9g2000pbn.googlegroups.com> here's a interesting problem that we are discussing at comp.lang.lisp. ?Parallel Programing Problem: asciify-string? http://xahlee.org/comp/parallel_programing_exercise_asciify-string.html here's the plain text. Code example is emacs lisp, but the problem is general. for a bit python relevancy? is there any python compiler that's parallel-algorithm aware? ----------------------------------------------- Parallel Programing Problem: asciify-string Here's a interesting parallel programing problem. Problem Description The task is to change this function so it's parallelable. (code example in emacs lisp) (defun asciify-string (inputStr) "Make Unicode string into equivalent ASCII ones." (setq inputStr (replace-regexp-in-string "?\\|?\\|?\\|?" "a" inputStr)) (setq inputStr (replace-regexp-in-string "?\\|?\\|?\\|?" "e" inputStr)) (setq inputStr (replace-regexp-in-string "?\\|?\\|?\\|?" "i" inputStr)) (setq inputStr (replace-regexp-in-string "?\\|?\\|?\\|?" "o" inputStr)) (setq inputStr (replace-regexp-in-string "?\\|?\\|?\\|?" "u" inputStr)) inputStr ) Here's a more general description of the problem. You are given a Unicode text file that's a few peta bytes. For certain characters in the file, they need to be changed to different char. (For example of practical application, see: IDN homograph attack ? Duplicate characters in Unicode.) One easy solution is to simply use regex, as the above sample code, to search thru the file sequentially, and perform the transfrom of a particular set of chars, then repeat for each char chat needs to be changed. But your task is to use a algorithm parallelizable. That is, in a parallel-algorithm aware language (e.g. Fortress), the compiler will automatically span the computation to multiple processors. Refer to Guy Steele's video talk if you haven't seen already. See: Guy Steele on Parallel Programing. Solution Suggestions A better way to write it for parallel programing, is to map a char- transform function to each char in the string. Here's a pseudo-code in lisp by Helmut Eller: (defun asciify-char (c) (case c ((? ? ? ?) ?a) ((? ? ? ?) ?e) ((? ? ? ?) ?i) ((? ? ? ?) ?o) ((? ? ? ?) ?u) (t c))) (defun asciify-string (string) (map 'string #'asciify-string string)) One problem with this is that the function ?asciify-char? itself is sequential, and not 100% parallelizable. (we might assume here that there are billions of chars in Unicode that needs to be transformed) It would be a interesting small project, if someone actually use a parallel-algorithm-aware language to work on this problem, and report on the break-point of file-size of parallel-algorithm vs sequential- algorithm. Anyone would try it? Perhaps in Fortress, Erlang, Ease, Alice, X10, or other? Is the Clojure parallel aware? Xah From bob at brasko.net Tue Mar 6 08:41:32 2012 From: bob at brasko.net (Bob Rossi) Date: Tue, 6 Mar 2012 08:41:32 -0500 Subject: Error with co_filename when loading modules from zip file In-Reply-To: <6c8fd85f-b489-450e-82a4-ee01b231a09f@n12g2000yqb.googlegroups.com> References: <6c8fd85f-b489-450e-82a4-ee01b231a09f@n12g2000yqb.googlegroups.com> Message-ID: <20120306134131.GA14891@brasko> On Tue, Mar 06, 2012 at 02:38:50AM -0800, Vinay Sajip wrote: > On Mar 6, 2:40?am, Bob Rossi wrote: > > > Darn it, this was reported in 2007 > > ?http://bugs.python.org/issue1180193 > > and it was mentioned the logging package was effected. > > > > Yikes. > > > > I will think about this, but don't expect any quick resolution :-( I > think the right fix would be not in the logging package, but in the > module loading machinery (as mentioned on that issue). > > I wouldn't worry about the performance aspect - once the logging > package is loaded, there's no performance impact. That's a tiny one- > off hit which you will probably not notice at all. OK. Do you know where the bytecode gets stored when you load a py file from a zip? My program can potentially run for hours, from an embedded context, and could call into the logger and other py files over and over. Are the bytecode files stored in RAM one time, or recomputed each time they are needed? Thanks, Bob From roy at panix.com Tue Mar 6 08:49:33 2012 From: roy at panix.com (Roy Smith) Date: Tue, 06 Mar 2012 08:49:33 -0500 Subject: are int, float, long, double, side-effects of computer engineering? References: <5aaded58-af09-41dc-9afd-56d7b7ced239@d7g2000pbl.googlegroups.com> <7ol5r.29957$zD5.14377@newsfe12.iad> Message-ID: [intentionally violating the followup-to header] In article <7ol5r.29957$zD5.14377 at newsfe12.iad>, Chiron wrote: > On Mon, 05 Mar 2012 22:34:46 -0800, Xah Lee wrote: > > > while what you said is true, but the problem is that 99.99% of > > programers do NOT know this. They do not know Mathematica. They've never > > seen a > > Could you please offer some evidence to support this claim? Most of the > programmers I've ever run into, were quite familiar with the notion that > many aspects of their languages were artifacts of hardware limitations. While I doubt Xah's claim that 99.99% of programmers are unaware of this, oddly enough, we ran across an instance of this just yesterday. We have a test problem we give to job candidates: > Write a program that counts the number of times the subsequence "1, 2, 3" > appears in the first 100,000 digits of pi. Note "subsequence" does not imply > consecutive digits. For example, "1, 2, 3" appears in "3.141592653" twice. > You may use Google or the link above to find the digits of pi. Please include > the correct count when submitting your application. We had a candidate submit a solution in Python which ran in O(n) time. The algorithm was essentially correct, but unfortunately, he used a numpy.array to hold some counters, and suffered integer overflow. Had he used regular python lists, he would have been fine. What's unclear (at the moment) is whether he falls into Xah's camp of people who are unaware of such issues (unlikely, IMHO). Possibly he just didn't realize that the numbers in this problem might get big enough to overflow a 32-bit int. Or had been lulled into a false sense of security knowing that python does arbitrary precision integer math and didn't realize that doesn't extend to numpy. From __peter__ at web.de Tue Mar 6 08:52:11 2012 From: __peter__ at web.de (Peter Otten) Date: Tue, 06 Mar 2012 14:52:11 +0100 Subject: pickle/unpickle class which has changed References: Message-ID: Neal Becker wrote: > What happens if I pickle a class, and later unpickle it where the class > now has added some new attributes? - If the added attributes' values are immutable, provide defaults as class attributes. - Implement an appropriate __setstate__() method. The easiest would be # untested def __setstate__(self, state): self.__dict__.update(newattr1=42, newattr2=[]) self.__dict__.update(state) From steve+comp.lang.python at pearwood.info Tue Mar 6 08:55:12 2012 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 06 Mar 2012 13:55:12 GMT Subject: pickle/unpickle class which has changed References: Message-ID: <4f561740$0$29989$c3e8da3$5496439d@news.astraweb.com> On Tue, 06 Mar 2012 07:34:34 -0500, Neal Becker wrote: > What happens if I pickle a class, and later unpickle it where the class > now has added some new attributes? Why don't you try it? py> import pickle py> class C: ... a = 23 ... py> c = C() py> pickled = pickle.dumps(c) py> C.b = 42 # add a new class attribute py> d = pickle.loads(pickled) py> d.a 23 py> d.b 42 Unless you mean something different from this, adding attributes to the class is perfectly fine. But... why are you dynamically adding attributes to the class? Isn't that rather unusual? -- Steven From __peter__ at web.de Tue Mar 6 08:59:48 2012 From: __peter__ at web.de (Peter Otten) Date: Tue, 06 Mar 2012 14:59:48 +0100 Subject: Error with co_filename when loading modules from zip file References: <6c8fd85f-b489-450e-82a4-ee01b231a09f@n12g2000yqb.googlegroups.com> <20120306134131.GA14891@brasko> Message-ID: Bob Rossi wrote: > On Tue, Mar 06, 2012 at 02:38:50AM -0800, Vinay Sajip wrote: >> On Mar 6, 2:40 am, Bob Rossi wrote: >> >> > Darn it, this was reported in 2007 >> > http://bugs.python.org/issue1180193 >> > and it was mentioned the logging package was effected. >> > >> > Yikes. >> > >> >> I will think about this, but don't expect any quick resolution :-( I >> think the right fix would be not in the logging package, but in the >> module loading machinery (as mentioned on that issue). >> >> I wouldn't worry about the performance aspect - once the logging >> package is loaded, there's no performance impact. That's a tiny one- >> off hit which you will probably not notice at all. > > OK. > > Do you know where the bytecode gets stored when you load a py > file from a zip? > > My program can potentially run for hours, from an embedded context, > and could call into the logger and other py files over and over. > > Are the bytecode files stored in RAM one time, or recomputed each > time they are needed? The bytecode is generated once when the module is loaded and kept as part of the module object in the sys.modules cache unless you explicitly reload() the module. For a long-running program the compilation overhead is negligable. From __peter__ at web.de Tue Mar 6 09:28:16 2012 From: __peter__ at web.de (Peter Otten) Date: Tue, 06 Mar 2012 15:28:16 +0100 Subject: pickle/unpickle class which has changed References: <4f561740$0$29989$c3e8da3$5496439d@news.astraweb.com> Message-ID: Steven D'Aprano wrote: > On Tue, 06 Mar 2012 07:34:34 -0500, Neal Becker wrote: > >> What happens if I pickle a class, and later unpickle it where the class >> now has added some new attributes? > > Why don't you try it? > > py> import pickle > py> class C: > ... a = 23 > ... > py> c = C() > py> pickled = pickle.dumps(c) > py> C.b = 42 # add a new class attribute > py> d = pickle.loads(pickled) > py> d.a > 23 > py> d.b > 42 > > > Unless you mean something different from this, adding attributes to the > class is perfectly fine. > > But... why are you dynamically adding attributes to the class? Isn't that > rather unusual? The way I understand the problem is that an apparently backwards-compatible change like adding a third dimension to a point with an obvious default breaks when you restore an "old" instance in a script with the "new" implementation: >>> import pickle >>> class P(object): ... def __init__(self, x, y): ... self.x = x ... self.y = y ... def r2(self): ... return self.x*self.x + self.y*self.y ... >>> p = P(2, 3) >>> p.r2() 13 >>> s = pickle.dumps(p) >>> class P(object): ... def __init__(self, x, y, z=0): ... self.x = x ... self.y = y ... self.z = z ... def r2(self): ... return self.x*self.x + self.y*self.y + self.z*self.z ... >>> p = P(2, 3) >>> p.r2() 13 >>> pickle.loads(s).r2() Traceback (most recent call last): File "", line 1, in File "", line 7, in r2 AttributeError: 'P' object has no attribute 'z' By default pickle doesn't invoke __init__() and updates __dict__ directly. As pointed out in my previous post one way to fix the problem is to implement a __setstate__() method: >>> class P(object): ... def __init__(self, x, y, z=0): ... self.x = x ... self.y = y ... self.z = z ... def r2(self): ... return self.x*self.x + self.y*self.y + self.z*self.z ... def __setstate__(self, state): ... self.__dict__["z"] = 42 # stupid default ... self.__dict__.update(state) ... >>> pickle.loads(s).r2() 1777 This keeps working with pickles of the new implementation of P: >>> q = P(3, 4, 5) >>> pickle.loads(pickle.dumps(q)).r2() 50 From queency3 at yahoo.com Tue Mar 6 10:32:37 2012 From: queency3 at yahoo.com (queency jones) Date: Tue, 6 Mar 2012 07:32:37 -0800 (PST) Subject: python simple web server Message-ID: <1331047957.90396.YahooMailClassic@web162001.mail.bf1.yahoo.com> hello pythonist i'm developing using the simple / basic http server i got very bad performance regarding to request time . 9 sec for each request replay. i tried to test this with this: python -m SimpleHTTPServer 8080 but no better. any sugestions ? that i can use ? my final goal is to serv 5 people on the lan network only . can't i stick with the python server ? -------------- next part -------------- An HTML attachment was scrubbed... URL: From dreadpiratejeff at gmail.com Tue Mar 6 11:09:23 2012 From: dreadpiratejeff at gmail.com (J) Date: Tue, 6 Mar 2012 11:09:23 -0500 Subject: Help me with weird logging problem Message-ID: Hi, I'm trying to add a couple log handlers to a program. The end goal is to log things at INFO or above to console, and if a -v option is set to ALSO log everything at DEBUG or above to a file. However, while I DO get the log file created, and log messages are appearing there, Debug messages are not... Here's some sample code that is essentially the guts of the logging setup right now, based on what I read in the docs: #!/usr/bin/python import logging import sys verbose = True # Set up the logger console_format = '%(levelname)-8s %(message)s' console_handler = logging.StreamHandler() console_handler.setFormatter(logging.Formatter(console_format)) console_handler.setLevel(logging.INFO) logger = logging.getLogger() logger.addHandler(console_handler) if verbose: verbose_format = '%(asctime)s %(levelname)-8s %(message)s' verbose_handler = logging.FileHandler('testlog.log') verbose_handler.setLevel(logging.DEBUG) verbose_handler.setFormatter(logging.Formatter(verbose_format)) logger.addHandler(verbose_handler) logging.debug("Setting log level to DEBUG for verbosity") logging.info("INFO event logged") logging.warning("WARNING event logged") logging.error("ERROR event logged") logging.critical("CRITICAL event logged") logging.debug("DEBUG event logged") When I run this I get the following console and log file output: bladernr at klaatu:~/development/cert-submit-script-improvements/bin$ ./logtest.py WARNING WARNING event logged ERROR ERROR event logged CRITICAL CRITICAL event logged bladernr at klaatu:~/development/cert-submit-script-improvements/bin$ cat testlog.log 2012-03-06 11:05:40,297 WARNING WARNING event logged 2012-03-06 11:05:40,297 ERROR ERROR event logged 2012-03-06 11:05:40,298 CRITICAL CRITICAL event logged So I AM getting logging, but I am not getting the DEBUG level logs in the log file, nor am I getting INFO level logs on console. Any idea what I'm doing wrong? From vinay_sajip at yahoo.co.uk Tue Mar 6 11:19:53 2012 From: vinay_sajip at yahoo.co.uk (Vinay Sajip) Date: Tue, 6 Mar 2012 08:19:53 -0800 (PST) Subject: Help me with weird logging problem References: Message-ID: On Mar 6, 4:09?pm, J wrote: > > Any idea what I'm doing wrong? Levels can be set on loggers as well as handlers, and you're only setting levels on the handlers. The default level on the root logger is WARNING. A logger checks its level first, and only if the event passes that test will it be passed to the handlers (which will also perform level tests). So, a logger.setLevel(logging.DEBUG) should be all you need to add before logging anything. Regards, Vinay Sajip From jcea at jcea.es Tue Mar 6 11:28:56 2012 From: jcea at jcea.es (Jesus Cea) Date: Tue, 06 Mar 2012 17:28:56 +0100 Subject: Monthly Python Meeting in Madrid (Spain) Message-ID: <4F563B48.6040901@jcea.es> -----BEGIN PGP SIGNED MESSAGE----- Hash: SHA1 Next Thursday, 8th March. - -- Jesus Cea Avion _/_/ _/_/_/ _/_/_/ jcea at jcea.es - http://www.jcea.es/ _/_/ _/_/ _/_/ _/_/ _/_/ jabber / xmpp:jcea at jabber.org _/_/ _/_/ _/_/_/_/_/ . _/_/ _/_/ _/_/ _/_/ _/_/ "Things are not so easy" _/_/ _/_/ _/_/ _/_/ _/_/ _/_/ "My name is Dump, Core Dump" _/_/_/ _/_/_/ _/_/ _/_/ "El amor es poner tu felicidad en la felicidad de otro" - Leibniz -----BEGIN PGP SIGNATURE----- Version: GnuPG v1.4.10 (GNU/Linux) Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org/ iQCVAwUBT1Y7SJlgi5GaxT1NAQKOmQQAmRSz5Kk1ZAE5iEBiUiB5XRKVVntPfcA1 FflzHu2ZawULVlcnLMj2mh6USzOSqrRqz5mFZA9RFQWjeN6s1wa/x8hUytUFH90t BirdqeLjzZMoU1eyRlGggSjqR+VLDqqpxFq8aWbKDC3+t5u+UmZMjvHQo0zBGbcZ CDcITqWR2Ds= =e495 -----END PGP SIGNATURE----- From ndbecker2 at gmail.com Tue Mar 6 11:29:16 2012 From: ndbecker2 at gmail.com (Neal Becker) Date: Tue, 06 Mar 2012 11:29:16 -0500 Subject: pickle/unpickle class which has changed References: <4f561740$0$29989$c3e8da3$5496439d@news.astraweb.com> Message-ID: Peter Otten wrote: > Steven D'Aprano wrote: > >> On Tue, 06 Mar 2012 07:34:34 -0500, Neal Becker wrote: >> >>> What happens if I pickle a class, and later unpickle it where the class >>> now has added some new attributes? >> >> Why don't you try it? >> >> py> import pickle >> py> class C: >> ... a = 23 >> ... >> py> c = C() >> py> pickled = pickle.dumps(c) >> py> C.b = 42 # add a new class attribute >> py> d = pickle.loads(pickled) >> py> d.a >> 23 >> py> d.b >> 42 >> >> >> Unless you mean something different from this, adding attributes to the >> class is perfectly fine. >> >> But... why are you dynamically adding attributes to the class? Isn't that >> rather unusual? > > The way I understand the problem is that an apparently backwards-compatible > change like adding a third dimension to a point with an obvious default > breaks when you restore an "old" instance in a script with the "new" > implementation: > >>>> import pickle >>>> class P(object): > ... def __init__(self, x, y): > ... self.x = x > ... self.y = y > ... def r2(self): > ... return self.x*self.x + self.y*self.y > ... >>>> p = P(2, 3) >>>> p.r2() > 13 >>>> s = pickle.dumps(p) >>>> class P(object): > ... def __init__(self, x, y, z=0): > ... self.x = x > ... self.y = y > ... self.z = z > ... def r2(self): > ... return self.x*self.x + self.y*self.y + self.z*self.z > ... >>>> p = P(2, 3) >>>> p.r2() > 13 >>>> pickle.loads(s).r2() > Traceback (most recent call last): > File "", line 1, in > File "", line 7, in r2 > AttributeError: 'P' object has no attribute 'z' > > By default pickle doesn't invoke __init__() and updates __dict__ directly. > As pointed out in my previous post one way to fix the problem is to > implement a __setstate__() method: > >>>> class P(object): > ... def __init__(self, x, y, z=0): > ... self.x = x > ... self.y = y > ... self.z = z > ... def r2(self): > ... return self.x*self.x + self.y*self.y + self.z*self.z > ... def __setstate__(self, state): > ... self.__dict__["z"] = 42 # stupid default > ... self.__dict__.update(state) > ... >>>> pickle.loads(s).r2() > 1777 > > This keeps working with pickles of the new implementation of P: > >>>> q = P(3, 4, 5) >>>> pickle.loads(pickle.dumps(q)).r2() > 50 So if in my new class definition there are now some new attributes, and if I did not add a __setstate__ to set the new attributes, I guess then when unpickled the instance of the class will simply lack those attributes? From dreadpiratejeff at gmail.com Tue Mar 6 12:03:16 2012 From: dreadpiratejeff at gmail.com (J) Date: Tue, 6 Mar 2012 12:03:16 -0500 Subject: Help me with weird logging problem In-Reply-To: References: Message-ID: On Tue, Mar 6, 2012 at 11:19, Vinay Sajip wrote: > On Mar 6, 4:09?pm, J wrote: >> >> Any idea what I'm doing wrong? > > Levels can be set on loggers as well as handlers, and you're only > setting levels on the handlers. The default level on the root logger > is WARNING. A logger checks its level first, and only if the event > passes that test will it be passed to the handlers (which will also > perform level tests). > > So, a logger.setLevel(logging.DEBUG) should be all you need to add > before logging anything. > > Regards, > > Vinay Sajip > -- > http://mail.python.org/mailman/listinfo/python-list Thank you very much, Vinay :) I thought it was something simple like that I had overlooked or misunderstood. Cheers, Jeff From __peter__ at web.de Tue Mar 6 12:10:53 2012 From: __peter__ at web.de (Peter Otten) Date: Tue, 06 Mar 2012 18:10:53 +0100 Subject: pickle/unpickle class which has changed References: <4f561740$0$29989$c3e8da3$5496439d@news.astraweb.com> Message-ID: Neal Becker wrote: > Peter Otten wrote: > >> Steven D'Aprano wrote: >> >>> On Tue, 06 Mar 2012 07:34:34 -0500, Neal Becker wrote: >>> >>>> What happens if I pickle a class, and later unpickle it where the class >>>> now has added some new attributes? >>> >>> Why don't you try it? >>> >>> py> import pickle >>> py> class C: >>> ... a = 23 >>> ... >>> py> c = C() >>> py> pickled = pickle.dumps(c) >>> py> C.b = 42 # add a new class attribute >>> py> d = pickle.loads(pickled) >>> py> d.a >>> 23 >>> py> d.b >>> 42 >>> >>> >>> Unless you mean something different from this, adding attributes to the >>> class is perfectly fine. >>> >>> But... why are you dynamically adding attributes to the class? Isn't >>> that rather unusual? >> >> The way I understand the problem is that an apparently >> backwards-compatible change like adding a third dimension to a point with >> an obvious default breaks when you restore an "old" instance in a script >> with the "new" implementation: >> >>>>> import pickle >>>>> class P(object): >> ... def __init__(self, x, y): >> ... self.x = x >> ... self.y = y >> ... def r2(self): >> ... return self.x*self.x + self.y*self.y >> ... >>>>> p = P(2, 3) >>>>> p.r2() >> 13 >>>>> s = pickle.dumps(p) >>>>> class P(object): >> ... def __init__(self, x, y, z=0): >> ... self.x = x >> ... self.y = y >> ... self.z = z >> ... def r2(self): >> ... return self.x*self.x + self.y*self.y + self.z*self.z >> ... >>>>> p = P(2, 3) >>>>> p.r2() >> 13 >>>>> pickle.loads(s).r2() >> Traceback (most recent call last): >> File "", line 1, in >> File "", line 7, in r2 >> AttributeError: 'P' object has no attribute 'z' >> >> By default pickle doesn't invoke __init__() and updates __dict__ >> directly. As pointed out in my previous post one way to fix the problem >> is to implement a __setstate__() method: >> >>>>> class P(object): >> ... def __init__(self, x, y, z=0): >> ... self.x = x >> ... self.y = y >> ... self.z = z >> ... def r2(self): >> ... return self.x*self.x + self.y*self.y + self.z*self.z >> ... def __setstate__(self, state): >> ... self.__dict__["z"] = 42 # stupid default >> ... self.__dict__.update(state) >> ... >>>>> pickle.loads(s).r2() >> 1777 >> >> This keeps working with pickles of the new implementation of P: >> >>>>> q = P(3, 4, 5) >>>>> pickle.loads(pickle.dumps(q)).r2() >> 50 > > So if in my new class definition there are now some new attributes, and if > I did not add a __setstate__ to set the new attributes, I guess then when > unpickled the instance of the class will simply lack those attributes? I don't know. If you don't trust the demo try it yourself with the actual code you have. Throwing in obj = pickle.load(...) print vars(obj) should help. From reader at calvinkim.org Tue Mar 6 16:29:10 2012 From: reader at calvinkim.org (Calvin Kim) Date: Tue, 06 Mar 2012 16:29:10 -0500 Subject: are int, float, long, double, side-effects of computer engineering? In-Reply-To: References: <5aaded58-af09-41dc-9afd-56d7b7ced239@d7g2000pbl.googlegroups.com> Message-ID: <4F5681A6.9090707@calvinkim.org> On 03/06/2012 01:34 AM, Xah Lee wrote: > while what you said is true, but the problem is that 99.99% of > programers do NOT know this. They do not know Mathematica. They've > never seen a language with such feature. The concept is alien. This is > what i'd like to point out and spread awareness. > I can see your point. But that's not simply true. In my case and many others, such issue was addressed during first week of introductory programming classes. I was naively thought "computer = precision" and I was stunned to find out the inaccuracy of computer calculations. But as you experienced, I also stumble upon some people (specially Java only programmers) who were not aware of it. > also, argument about raw speed and fine control vs automatic > management, rots with time. Happened with auto memory management, > managed code, compilers, auto type conversion, auto extension of > array, auto type system, dynamic/scripting languages, etc. Maybe it's because I'm not in scientific community, that I learned to live with such side-effects. Because 99.99% of computer users and programmers can afford to, and willing to lose such small inaccuracy billion times in exchange for some performance increase and convenience. Although NASA may not accept my application for their projects for Mars mission after this posting. From johnjsal at gmail.com Tue Mar 6 17:43:34 2012 From: johnjsal at gmail.com (John Salerno) Date: Tue, 6 Mar 2012 14:43:34 -0800 (PST) Subject: What's the best way to write this regular expression? Message-ID: <12783654.1174.1331073814011.JavaMail.geo-discussion-forums@yner4> I sort of have to work with what the website gives me (as you'll see below), but today I encountered an exception to my RE. Let me just give all the specific information first. The point of my script is to go to the specified URL and extract song information from it. This is my RE: song_pattern = re.compile(r'([0-9]{1,2}:[0-9]{2} [a|p].m.).*?(.*?).*?(.*?)', re.DOTALL) This is how the website is formatted: 4:25 p.m.
  • 4:21 p.m.
  • 4:19 p.m.
    Moe Bandy
  • 4:15 p.m.
    Reba McEntire
  • There's something of a pattern, although it's not always perfect. The time is listed first, and then the song information in tags. However, in this particular case, you can see that for the 4:25pm entry, "AP TX SOC CPAS TRF" is extracted for the song title, and then the RE skips to the next entry in order to find the next tags, which is actually the name of the next song in the list, instead of being the artist as normal. (Of course, I have no idea what AP TX SOC CPAS TRF is anyway. Usually the website doesn't list commercials or anomalies like that.) So my first question is basic: am I even extracting the information properly? It works almost all the time, but because the website is such a mess, I pretty much have to rely on the tags being in the proper places (as they were NOT in this case!). The second question is, to fix the above problem, would it be sufficient to rewrite my RE so that it has to find all of the specified information, i.e. a time followed by two entries, BEFORE it moves on to finding the next time? I think that would have caused it to skip the 4:25 entry above, and only extract entries that have a time followed by two entries (song and artist). If this is possible, how do I rewrite it so that it has to match all the conditions without skipping over the next time entry in order to do so? Thanks. From clp2 at rebertia.com Tue Mar 6 17:52:10 2012 From: clp2 at rebertia.com (Chris Rebert) Date: Tue, 6 Mar 2012 14:52:10 -0800 Subject: What's the best way to write this regular expression? In-Reply-To: <12783654.1174.1331073814011.JavaMail.geo-discussion-forums@yner4> References: <12783654.1174.1331073814011.JavaMail.geo-discussion-forums@yner4> Message-ID: On Tue, Mar 6, 2012 at 2:43 PM, John Salerno wrote: > I sort of have to work with what the website gives me (as you'll see below), but today I encountered an exception to my RE. Let me just give all the specific information first. The point of my script is to go to the specified URL and extract song information from it. > > This is my RE: > > song_pattern = re.compile(r'([0-9]{1,2}:[0-9]{2} [a|p].m.).*?(.*?).*?(.*?)', re.DOTALL) I would advise against using regular expressions to "parse" HTML: http://stackoverflow.com/questions/1732348/regex-match-open-tags-except-xhtml-self-contained-tags lxml is a popular choice for parsing HTML in Python: http://lxml.de Cheers, Chris From johnjsal at gmail.com Tue Mar 6 18:02:42 2012 From: johnjsal at gmail.com (John Salerno) Date: Tue, 6 Mar 2012 15:02:42 -0800 (PST) Subject: What's the best way to write this regular expression? In-Reply-To: References: <12783654.1174.1331073814011.JavaMail.geo-discussion-forums@yner4> Message-ID: <15622243.3244.1331074963027.JavaMail.geo-discussion-forums@yncc26> On Tuesday, March 6, 2012 4:52:10 PM UTC-6, Chris Rebert wrote: > On Tue, Mar 6, 2012 at 2:43 PM, John Salerno wrote: > > I sort of have to work with what the website gives me (as you'll see below), but today I encountered an exception to my RE. Let me just give all the specific information first. The point of my script is to go to the specified URL and extract song information from it. > > > > This is my RE: > > > > song_pattern = re.compile(r'([0-9]{1,2}:[0-9]{2} [a|p].m.).*?(.*?).*?(.*?)', re.DOTALL) > > I would advise against using regular expressions to "parse" HTML: > http://stackoverflow.com/questions/1732348/regex-match-open-tags-except-xhtml-self-contained-tags > > lxml is a popular choice for parsing HTML in Python: http://lxml.de > > Cheers, > Chris Thanks, that was an interesting read :) Anything that allows me NOT to use REs is welcome news, so I look forward to learning about something new! :) From johnjsal at gmail.com Tue Mar 6 18:02:42 2012 From: johnjsal at gmail.com (John Salerno) Date: Tue, 6 Mar 2012 15:02:42 -0800 (PST) Subject: What's the best way to write this regular expression? In-Reply-To: References: <12783654.1174.1331073814011.JavaMail.geo-discussion-forums@yner4> Message-ID: <15622243.3244.1331074963027.JavaMail.geo-discussion-forums@yncc26> On Tuesday, March 6, 2012 4:52:10 PM UTC-6, Chris Rebert wrote: > On Tue, Mar 6, 2012 at 2:43 PM, John Salerno wrote: > > I sort of have to work with what the website gives me (as you'll see below), but today I encountered an exception to my RE. Let me just give all the specific information first. The point of my script is to go to the specified URL and extract song information from it. > > > > This is my RE: > > > > song_pattern = re.compile(r'([0-9]{1,2}:[0-9]{2} [a|p].m.).*?(.*?).*?(.*?)', re.DOTALL) > > I would advise against using regular expressions to "parse" HTML: > http://stackoverflow.com/questions/1732348/regex-match-open-tags-except-xhtml-self-contained-tags > > lxml is a popular choice for parsing HTML in Python: http://lxml.de > > Cheers, > Chris Thanks, that was an interesting read :) Anything that allows me NOT to use REs is welcome news, so I look forward to learning about something new! :) From johnjsal at gmail.com Tue Mar 6 18:05:39 2012 From: johnjsal at gmail.com (John Salerno) Date: Tue, 6 Mar 2012 15:05:39 -0800 (PST) Subject: What's the best way to write this regular expression? In-Reply-To: References: <12783654.1174.1331073814011.JavaMail.geo-discussion-forums@yner4> Message-ID: <28285433.1413.1331075139309.JavaMail.geo-discussion-forums@ynbq18> > Anything that allows me NOT to use REs is welcome news, so I look forward to learning about something new! :) I should ask though...are there alternatives already bundled with Python that I could use? Now that you mention it, I remember something called HTMLParser (or something like that) and I have no idea why I never looked into that before I messed with REs. Thanks. From johnjsal at gmail.com Tue Mar 6 18:05:39 2012 From: johnjsal at gmail.com (John Salerno) Date: Tue, 6 Mar 2012 15:05:39 -0800 (PST) Subject: What's the best way to write this regular expression? In-Reply-To: References: <12783654.1174.1331073814011.JavaMail.geo-discussion-forums@yner4> Message-ID: <28285433.1413.1331075139309.JavaMail.geo-discussion-forums@ynbq18> > Anything that allows me NOT to use REs is welcome news, so I look forward to learning about something new! :) I should ask though...are there alternatives already bundled with Python that I could use? Now that you mention it, I remember something called HTMLParser (or something like that) and I have no idea why I never looked into that before I messed with REs. Thanks. From johnjsal at gmail.com Tue Mar 6 18:25:40 2012 From: johnjsal at gmail.com (John Salerno) Date: Tue, 6 Mar 2012 15:25:40 -0800 (PST) Subject: What's the best way to write this regular expression? In-Reply-To: <28285433.1413.1331075139309.JavaMail.geo-discussion-forums@ynbq18> References: <12783654.1174.1331073814011.JavaMail.geo-discussion-forums@yner4> <28285433.1413.1331075139309.JavaMail.geo-discussion-forums@ynbq18> Message-ID: <10944614.4302.1331076340313.JavaMail.geo-discussion-forums@ynne2> On Tuesday, March 6, 2012 5:05:39 PM UTC-6, John Salerno wrote: > > Anything that allows me NOT to use REs is welcome news, so I look forward to learning about something new! :) > > I should ask though...are there alternatives already bundled with Python that I could use? Now that you mention it, I remember something called HTMLParser (or something like that) and I have no idea why I never looked into that before I messed with REs. > > Thanks. Also, I just noticed Beautiful Soup, which seems appropriate. I suppose any will do, but knowing the pros and cons would help with a decision. From johnjsal at gmail.com Tue Mar 6 18:33:38 2012 From: johnjsal at gmail.com (John Salerno) Date: Tue, 6 Mar 2012 15:33:38 -0800 (PST) Subject: What's the best way to write this regular expression? In-Reply-To: <28285433.1413.1331075139309.JavaMail.geo-discussion-forums@ynbq18> References: <12783654.1174.1331073814011.JavaMail.geo-discussion-forums@yner4> <28285433.1413.1331075139309.JavaMail.geo-discussion-forums@ynbq18> Message-ID: <28368927.1236.1331076818291.JavaMail.geo-discussion-forums@yner4> On Tuesday, March 6, 2012 5:05:39 PM UTC-6, John Salerno wrote: > > Anything that allows me NOT to use REs is welcome news, so I look forward to learning about something new! :) > > I should ask though...are there alternatives already bundled with Python that I could use? Now that you mention it, I remember something called HTMLParser (or something like that) and I have no idea why I never looked into that before I messed with REs. > > Thanks. ::sigh:: I'm having some trouble with the new Google Groups interface. It seems to double post, and in this case didn't post at all. If it did already, I apologize. I'll try to figure out what's happening, or just switch to a real newsgroup program. Anyway, my question was about Beautiful Soup. I read on the doc page that BS uses a parser, which html.parser and lxml are. So I'm guessing the difference between them is that the parser is a little more "low level," whereas BS offers a higher level approach to using them? Is BS easier to write code with, while still using the power of lxml? From johnjsal at gmail.com Tue Mar 6 18:33:38 2012 From: johnjsal at gmail.com (John Salerno) Date: Tue, 6 Mar 2012 15:33:38 -0800 (PST) Subject: What's the best way to write this regular expression? In-Reply-To: <28285433.1413.1331075139309.JavaMail.geo-discussion-forums@ynbq18> References: <12783654.1174.1331073814011.JavaMail.geo-discussion-forums@yner4> <28285433.1413.1331075139309.JavaMail.geo-discussion-forums@ynbq18> Message-ID: <28368927.1236.1331076818291.JavaMail.geo-discussion-forums@yner4> On Tuesday, March 6, 2012 5:05:39 PM UTC-6, John Salerno wrote: > > Anything that allows me NOT to use REs is welcome news, so I look forward to learning about something new! :) > > I should ask though...are there alternatives already bundled with Python that I could use? Now that you mention it, I remember something called HTMLParser (or something like that) and I have no idea why I never looked into that before I messed with REs. > > Thanks. ::sigh:: I'm having some trouble with the new Google Groups interface. It seems to double post, and in this case didn't post at all. If it did already, I apologize. I'll try to figure out what's happening, or just switch to a real newsgroup program. Anyway, my question was about Beautiful Soup. I read on the doc page that BS uses a parser, which html.parser and lxml are. So I'm guessing the difference between them is that the parser is a little more "low level," whereas BS offers a higher level approach to using them? Is BS easier to write code with, while still using the power of lxml? From ian.g.kelly at gmail.com Tue Mar 6 18:35:32 2012 From: ian.g.kelly at gmail.com (Ian Kelly) Date: Tue, 6 Mar 2012 16:35:32 -0700 Subject: What's the best way to write this regular expression? In-Reply-To: <28285433.1413.1331075139309.JavaMail.geo-discussion-forums@ynbq18> References: <12783654.1174.1331073814011.JavaMail.geo-discussion-forums@yner4> <28285433.1413.1331075139309.JavaMail.geo-discussion-forums@ynbq18> Message-ID: On Tue, Mar 6, 2012 at 4:05 PM, John Salerno wrote: >> Anything that allows me NOT to use REs is welcome news, so I look forward to learning about something new! :) > > I should ask though...are there alternatives already bundled with Python that I could use? Now that you mention it, I remember something called HTMLParser (or something like that) and I have no idea why I never looked into that before I messed with REs. HTMLParser is pretty basic, although it may be sufficient for your needs. It just converts an html document into a stream of start tags, end tags, and text, with no guarantee that the tags will actually correspond in any meaningful way. lxml can be used to output an actual hierarchical structure that may be easier to manipulate and extract data from. Cheers, Ian From johnjsal at gmail.com Tue Mar 6 18:39:42 2012 From: johnjsal at gmail.com (John Salerno) Date: Tue, 6 Mar 2012 17:39:42 -0600 Subject: What's the best way to write this regular expression? In-Reply-To: References: <12783654.1174.1331073814011.JavaMail.geo-discussion-forums@yner4> <28285433.1413.1331075139309.JavaMail.geo-discussion-forums@ynbq18> Message-ID: Thanks. I'm thinking the choice might be between lxml and Beautiful Soup, but since BS uses lxml as a parser, I'm trying to figure out the difference between them. I don't necessarily need the simplest (html.parser), but I want to choose one that is simple enough yet powerful enough that I won't have to learn another method later. On Tue, Mar 6, 2012 at 5:35 PM, Ian Kelly wrote: > On Tue, Mar 6, 2012 at 4:05 PM, John Salerno wrote: >>> Anything that allows me NOT to use REs is welcome news, so I look forward to learning about something new! :) >> >> I should ask though...are there alternatives already bundled with Python that I could use? Now that you mention it, I remember something called HTMLParser (or something like that) and I have no idea why I never looked into that before I messed with REs. > > HTMLParser is pretty basic, although it may be sufficient for your > needs. ?It just converts an html document into a stream of start tags, > end tags, and text, with no guarantee that the tags will actually > correspond in any meaningful way. ?lxml can be used to output an > actual hierarchical structure that may be easier to manipulate and > extract data from. > > Cheers, > Ian From steve+comp.lang.python at pearwood.info Tue Mar 6 18:44:07 2012 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 06 Mar 2012 23:44:07 GMT Subject: What's the best way to write this regular expression? References: <12783654.1174.1331073814011.JavaMail.geo-discussion-forums@yner4> Message-ID: <4f56a146$0$29989$c3e8da3$5496439d@news.astraweb.com> On Tue, 06 Mar 2012 15:05:39 -0800, John Salerno wrote: >> Anything that allows me NOT to use REs is welcome news, so I look >> forward to learning about something new! :) > > I should ask though...are there alternatives already bundled with Python > that I could use? Now that you mention it, I remember something called > HTMLParser (or something like that) and I have no idea why I never > looked into that before I messed with REs. import htmllib help(htmllib) The help is pretty minimal and technical, you might like to google on a tutorial or two: https://duckduckgo.com/html/?q=python%20htmllib%20tutorial Also, you're still double-posting. -- Steven From johnjsal at gmail.com Tue Mar 6 18:57:15 2012 From: johnjsal at gmail.com (John Salerno) Date: Tue, 6 Mar 2012 15:57:15 -0800 (PST) Subject: What's the best way to write this regular expression? In-Reply-To: <4f56a146$0$29989$c3e8da3$5496439d@news.astraweb.com> References: <12783654.1174.1331073814011.JavaMail.geo-discussion-forums@yner4> <4f56a146$0$29989$c3e8da3$5496439d@news.astraweb.com> Message-ID: <9496185.1483.1331078235707.JavaMail.geo-discussion-forums@ynbo9> > Also, you're still double-posting. Grr. I just reported it to Google, but I think if I start to frequent the newsgroup again I'll have to switch to Thunderbird, or perhaps I'll just try switching back to the old Google Groups interface. I think the issue is the new interface. Sorry. From ramit.prasad at jpmorgan.com Tue Mar 6 19:04:23 2012 From: ramit.prasad at jpmorgan.com (Prasad, Ramit) Date: Wed, 7 Mar 2012 00:04:23 +0000 Subject: What's the best way to write this regular expression? In-Reply-To: <9496185.1483.1331078235707.JavaMail.geo-discussion-forums@ynbo9> References: <12783654.1174.1331073814011.JavaMail.geo-discussion-forums@yner4> <4f56a146$0$29989$c3e8da3$5496439d@news.astraweb.com> <9496185.1483.1331078235707.JavaMail.geo-discussion-forums@ynbo9> Message-ID: <5B80DD153D7D744689F57F4FB69AF474193A88@SCACMX008.exchad.jpmchase.net> > > > Also, you're still double-posting. > > Grr. I just reported it to Google, but I think if I start to frequent the > newsgroup again I'll have to switch to Thunderbird, or perhaps I'll just > try switching back to the old Google Groups interface. I think the issue is > the new interface. > > Sorry. Oddly, I see no double posting for this thread on my end (email list). Ramit Ramit Prasad | JPMorgan Chase Investment Bank | Currencies Technology 712 Main Street | Houston, TX 77002 work phone: 713 - 216 - 5423 -- This email is confidential and subject to important disclaimers and conditions including on offers for the purchase or sale of securities, accuracy and completeness of information, viruses, confidentiality, legal privilege, and legal entity disclaimers, available at http://www.jpmorgan.com/pages/disclosures/email. From gelonida at gmail.com Tue Mar 6 19:22:46 2012 From: gelonida at gmail.com (Gelonida N) Date: Wed, 07 Mar 2012 01:22:46 +0100 Subject: pickle/unpickle class which has changed In-Reply-To: References: Message-ID: Hi Peter, A related question. Is there anyhing like a built in signature which would help to detect, that one tries to unpickle an object whose byte code has changed? The idea is to distinguish old and new pickled data and start some 'migration code' fi required The only thing, that I thought about so far was adding an explicit version number to each class in order to detect such situations. On 03/06/2012 02:52 PM, Peter Otten wrote: > Neal Becker wrote: > >> What happens if I pickle a class, and later unpickle it where the class >> now has added some new attributes? > > - If the added attributes' values are immutable, provide defaults as class > attributes. > > - Implement an appropriate __setstate__() method. The easiest would be > > # untested > def __setstate__(self, state): > self.__dict__.update(newattr1=42, newattr2=[]) > self.__dict__.update(state) > From anikom15 at gmail.com Tue Mar 6 19:53:43 2012 From: anikom15 at gmail.com (Westley =?iso-8859-1?Q?Mart=EDnez?=) Date: Tue, 6 Mar 2012 16:53:43 -0800 Subject: are int, float, long, double, side-effects of computer engineering? In-Reply-To: <4F5681A6.9090707@calvinkim.org> References: <5aaded58-af09-41dc-9afd-56d7b7ced239@d7g2000pbl.googlegroups.com> <4F5681A6.9090707@calvinkim.org> Message-ID: <20120307005343.GA9144@kubrick> On Tue, Mar 06, 2012 at 04:29:10PM -0500, Calvin Kim wrote: > On 03/06/2012 01:34 AM, Xah Lee wrote: > >while what you said is true, but the problem is that 99.99% of > >programers do NOT know this. They do not know Mathematica. They've > >never seen a language with such feature. The concept is alien. This is > >what i'd like to point out and spread awareness. > > > I can see your point. But that's not simply true. In my case and > many others, such issue was addressed during first week of > introductory programming classes. I was naively thought "computer = > precision" and I was stunned to find out the inaccuracy of computer > calculations. > > But as you experienced, I also stumble upon some people (specially > Java only programmers) who were not aware of it. > > >also, argument about raw speed and fine control vs automatic > >management, rots with time. Happened with auto memory management, > >managed code, compilers, auto type conversion, auto extension of > >array, auto type system, dynamic/scripting languages, etc. > Maybe it's because I'm not in scientific community, that I learned > to live with such side-effects. Because 99.99% of computer users and > programmers can afford to, and willing to lose such small inaccuracy > billion times in exchange for some performance increase and > convenience. Although NASA may not accept my application for their > projects for Mars mission after this posting. Also remember that double precision is not the maximum. There exist standards for triple and quadruple precision formats, as well as other extended formats. From tjreedy at udel.edu Tue Mar 6 20:04:35 2012 From: tjreedy at udel.edu (Terry Reedy) Date: Tue, 06 Mar 2012 20:04:35 -0500 Subject: What's the best way to write this regular expression? In-Reply-To: <28285433.1413.1331075139309.JavaMail.geo-discussion-forums@ynbq18> References: <12783654.1174.1331073814011.JavaMail.geo-discussion-forums@yner4> <28285433.1413.1331075139309.JavaMail.geo-discussion-forums@ynbq18> Message-ID: On 3/6/2012 6:05 PM, John Salerno wrote: >> Anything that allows me NOT to use REs is welcome news, so I look >> forward to learning about something new! :) > > I should ask though...are there alternatives already bundled with > Python that I could use? lxml is +- upward compatible with xml.etree in the stdlib. -- Terry Jan Reedy From tjreedy at udel.edu Tue Mar 6 20:06:34 2012 From: tjreedy at udel.edu (Terry Reedy) Date: Tue, 06 Mar 2012 20:06:34 -0500 Subject: What's the best way to write this regular expression? In-Reply-To: <9496185.1483.1331078235707.JavaMail.geo-discussion-forums@ynbo9> References: <12783654.1174.1331073814011.JavaMail.geo-discussion-forums@yner4> <4f56a146$0$29989$c3e8da3$5496439d@news.astraweb.com> <9496185.1483.1331078235707.JavaMail.geo-discussion-forums@ynbo9> Message-ID: On 3/6/2012 6:57 PM, John Salerno wrote: >> Also, you're still double-posting. > > Grr. I just reported it to Google, but I think if I start to frequent > the newsgroup again I'll have to switch to Thunderbird, or perhaps > I'll just try switching back to the old Google Groups interface. I > think the issue is the new interface. I am not seeing the double posting, but I use Thunderbird + the news.gmane.org mirrors of python-list and others. -- Terry Jan Reedy From roy at panix.com Tue Mar 6 20:26:11 2012 From: roy at panix.com (Roy Smith) Date: Tue, 06 Mar 2012 20:26:11 -0500 Subject: What's the best way to write this regular expression? References: <12783654.1174.1331073814011.JavaMail.geo-discussion-forums@yner4> Message-ID: In article <12783654.1174.1331073814011.JavaMail.geo-discussion-forums at yner4>, John Salerno wrote: > I sort of have to work with what the website gives me (as you'll see below), > but today I encountered an exception to my RE. Let me just give all the > specific information first. The point of my script is to go to the specified > URL and extract song information from it. Rule #1: Don't try to parse XML, HTML, or any other kind of ML with regular expressions. Rule #2: Use a dedicated ML parser. I like lxml (http://lxml.de/). There's other possibilities. Rule #3: If in doubt, see rule #1. From songofacandy at gmail.com Tue Mar 6 21:47:25 2012 From: songofacandy at gmail.com (INADA Naoki) Date: Tue, 6 Mar 2012 18:47:25 -0800 (PST) Subject: Why this recursive import fails? Message-ID: <2509610.10.1331088445839.JavaMail.geo-discussion-forums@pbcpw7> I have 4 py files like below. Two __init__.py is empty file. $ find foo -name "*.py" foo/lib/lib.py foo/lib/__init__.py foo/__init__.py foo/foo.py $ cat foo/lib/lib.py from __future__ import absolute_import print('lib.py', __name__) from .. import foo #import foo.foo $ cat foo/foo.py from __future__ import absolute_import print('foo.py', __name__) from .lib import lib #import foo.lib.lib Then, importing foo.foo or foo.lib.lib fails unexpectedly. # `from .. import foo` success but `from .lib import lib` fails. $ python -c "import foo.lib.lib" ('lib.py', 'foo.lib.lib') ('foo.py', 'foo.foo') Traceback (most recent call last): File "", line 1, in File "foo/lib/lib.py", line 3, in from .. import foo File "foo/foo.py", line 3, in from .lib import lib ImportError: cannot import name lib # `from .lib import lib` success but `from .. import foo` fails. $ python -c "import foo.foo" ('foo.py', 'foo.foo') ('lib.py', 'foo.lib.lib') Traceback (most recent call last): File "", line 1, in File "foo/foo.py", line 3, in from .lib import lib File "foo/lib/lib.py", line 3, in from .. import foo ImportError: cannot import name foo I can run both with absolute import. What's wrong about my relative import? From rustompmody at gmail.com Tue Mar 6 22:25:03 2012 From: rustompmody at gmail.com (rusi) Date: Tue, 6 Mar 2012 19:25:03 -0800 (PST) Subject: are int, float, long, double, side-effects of computer engineering? References: <5aaded58-af09-41dc-9afd-56d7b7ced239@d7g2000pbl.googlegroups.com> Message-ID: <8a3cd8d4-26d2-4cdf-b66d-43895a0bcd1e@qb4g2000pbb.googlegroups.com> On Mar 6, 6:11?am, Xah Lee wrote: > some additional info i thought is relevant. > > are int, float, long, double, side-effects of computer engineering? It is a bit naive for computer scientists to club integers and reals as mathematicians do given that for real numbers, even equality is undecidable! Mostly when a system like mathematica talks of real numbers it means computable real numbers which is a subset of mathematical real numbers (and of course a superset of floats) See http://en.wikipedia.org/wiki/Computable_number#Can_computable_numbers_be_used_instead_of_the_reals.3F From nospam at nospam.com Tue Mar 6 22:29:16 2012 From: nospam at nospam.com (Javier) Date: Wed, 7 Mar 2012 03:29:16 +0000 (UTC) Subject: Tools for refactoring/obfuscation Message-ID: I am looking for an automated tool for refactoring/obfuscation. Something that changes names of functions, variables, or which would merge all the functions of various modules in a single module. The closest I have seen is http://bicyclerepair.sourceforge.net/ Does somebody know of something that can work from the command line or simple data structures/text files?, like a python dictionary of functions {"old":"new",...} From bugzilla-mail-box at yandex.ru Tue Mar 6 22:29:55 2012 From: bugzilla-mail-box at yandex.ru (bugzilla-mail-box at yandex.ru) Date: Wed, 07 Mar 2012 13:29:55 +1000 Subject: Get tkinter text to the clipboard Message-ID: <222651331090995@web26.yandex.ru> How can I get something from tkinter gui to another program ? tkinter on python 3.2 on kde4 From jagteraho2006 at gmail.com Tue Mar 6 23:06:37 2012 From: jagteraho2006 at gmail.com (amar Singh) Date: Tue, 6 Mar 2012 20:06:37 -0800 (PST) Subject: help: confused about python flavors.... Message-ID: <948f80c1-877a-4a74-8adc-9d4ae702574f@l1g2000vbc.googlegroups.com> Hi, I am confused between plain python, numpy, scipy, pylab, matplotlib. I have high familiarity with matlab, but the computer I use does not have it. So moving to python. What should I use? and the best way to use it. I will be running matlab-like scripts sometimes on the shell prompt and sometimes on the command line. Please help. Thanks in advance. From steve+comp.lang.python at pearwood.info Wed Mar 7 01:24:54 2012 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 07 Mar 2012 06:24:54 GMT Subject: help: confused about python flavors.... References: <948f80c1-877a-4a74-8adc-9d4ae702574f@l1g2000vbc.googlegroups.com> Message-ID: <4f56ff36$0$29975$c3e8da3$5496439d@news.astraweb.com> On Tue, 06 Mar 2012 20:06:37 -0800, amar Singh wrote: > Hi, > > I am confused between plain python, numpy, scipy, pylab, matplotlib. Python is a programming language. It comes standard with many libraries for doing basic mathematics, web access, email, etc. Numpy is a library for doing scientific numerical maths work and fast processing of numeric arrays. Scipy is another library for scientific work. It is separate from, but uses, Numpy. Matplotlib is a project for making graphing and plotting of numeric data easy in Python. Pylab is a project to be Python's version of Matlab: it intends to be an integrated bundle of Python the programming language, Numpy, Scipy, and Matplotlib all in one easy-to-use application. > I have high familiarity with matlab, but the computer I use does not > have it. So moving to python. > What should I use? and the best way to use it. I will be running > matlab-like scripts sometimes on the shell prompt and sometimes on the > command line. Pylab is intended to be the closest to Matlab, but I don't know how close it is. Also, Pylab is NOT compatible with Matlab: its aim is to be an alternative to Matlab, not to be a clone. So it cannot run Matlab scripts. You might also like to look at Sage: http://www.sagemath.org/ Sage is a Python project aimed to be an alternative to Mathematica. Ultimately, you will have to look at the packages, see their features, perhaps try them for a while (they are all free software, so the only cost is your time), and decide for yourself which one meets your needs. We can't answer that, because we don't know what you need. -- Steven From johnjsal at gmail.com Wed Mar 7 02:02:51 2012 From: johnjsal at gmail.com (John Salerno) Date: Tue, 6 Mar 2012 23:02:51 -0800 (PST) Subject: What's the best way to write this regular expression? References: <12783654.1174.1331073814011.JavaMail.geo-discussion-forums@yner4> Message-ID: <0c1a1890-dc80-41b6-abea-f90324dd7d75@2g2000yqk.googlegroups.com> After a bit of reading, I've decided to use Beautiful Soup 4, with lxml as the parser. I considered simply using lxml to do all the work, but I just got lost in the documentation and tutorials. I couldn't find a clear explanation of how to parse an HTML file and then navigate its structure. The Beautiful Soup 4 documentation was very clear, and BS4 itself is so simple and Pythonic. And best of all, since version 4 no longer does the parsing itself, you can choose your own parser, and it works with lxml, so I'll still be using lxml, but with a nice, clean overlay for navigating the tree structure. Thanks for the advice! From pytomtom at gmail.com Wed Mar 7 02:58:34 2012 From: pytomtom at gmail.com (q q) Date: Wed, 7 Mar 2012 15:58:34 +0800 Subject: Help: how to protect the module 'sys' and 'os' Message-ID: Hi~ alls, I have to limit somebody modify the attr of 'sys'&'os'? e.g. you can't append sys.path. Someone has a good method? now my way: modified the source code of python ,"_PyObject_GenericSetAttrWithDict", because if you want to reset the value, you need to invoke this function. --- best regards pytom -------------- next part -------------- An HTML attachment was scrubbed... URL: From __peter__ at web.de Wed Mar 7 03:04:31 2012 From: __peter__ at web.de (Peter Otten) Date: Wed, 07 Mar 2012 09:04:31 +0100 Subject: pickle/unpickle class which has changed References: Message-ID: Gelonida N wrote: > Is there anyhing like a built in signature which would help to detect, > that one tries to unpickle an object whose byte code has changed? No. The only thing that is stored is the "protocol", the format used to store the data. > The idea is to distinguish old and new pickled data and start some > 'migration code' fi required > The only thing, that I thought about so far was adding an explicit > version number to each class in order to detect such situations. If you know in advance that your class will undergo significant changes you may also consider storing more stable data in a file format that can easily be modified, e. g. json. From nagle at animats.com Wed Mar 7 03:25:52 2012 From: nagle at animats.com (John Nagle) Date: Wed, 07 Mar 2012 00:25:52 -0800 Subject: "Decoding unicode is not supported" in unusual situation Message-ID: <4f571b94$0$12037$742ec2ed@news.sonic.net> I'm getting line 79, in tounicode return(unicode(s, errors='replace')) TypeError: decoding Unicode is not supported from this, under Python 2.7: def tounicode(s) : if type(s) == unicode : return(s) return(unicode(s, errors='replace')) That would seem to be impossible. But it's not. "s" is generated from the "suds" SOAP client. The documentation for "suds" says: "Suds leverages python meta programming to provide an intuative API for consuming web services. Runtime objectification of types defined in the WSDL is provided without class generation." I think that somewhere in "suds", they subclass the "unicode" type. That's almost too cute. The proper test is isinstance(s,unicode) John Nagle From songofacandy at gmail.com Wed Mar 7 03:28:53 2012 From: songofacandy at gmail.com (INADA Naoki) Date: Wed, 7 Mar 2012 00:28:53 -0800 (PST) Subject: Why this recursive import fails? In-Reply-To: <2509610.10.1331088445839.JavaMail.geo-discussion-forums@pbcpw7> References: <2509610.10.1331088445839.JavaMail.geo-discussion-forums@pbcpw7> Message-ID: <2133223.6.1331108933985.JavaMail.geo-discussion-forums@pbnt10> I found it is a bug http://bugs.python.org/issue13187 From __peter__ at web.de Wed Mar 7 03:39:21 2012 From: __peter__ at web.de (Peter Otten) Date: Wed, 07 Mar 2012 09:39:21 +0100 Subject: Get tkinter text to the clipboard References: <222651331090995@web26.yandex.ru> Message-ID: bugzilla-mail-box at yandex.ru wrote: > How can I get something from tkinter gui to another program ? > tkinter on python 3.2 on kde4 How about import tkinter root = tkinter.Tk() root.clipboard_clear() root.clipboard_append("whatever") From breamoreboy at yahoo.co.uk Wed Mar 7 04:15:50 2012 From: breamoreboy at yahoo.co.uk (Mark Lawrence) Date: Wed, 07 Mar 2012 09:15:50 +0000 Subject: help: confused about python flavors.... In-Reply-To: <4f56ff36$0$29975$c3e8da3$5496439d@news.astraweb.com> References: <948f80c1-877a-4a74-8adc-9d4ae702574f@l1g2000vbc.googlegroups.com> <4f56ff36$0$29975$c3e8da3$5496439d@news.astraweb.com> Message-ID: On 07/03/2012 06:24, Steven D'Aprano wrote: > On Tue, 06 Mar 2012 20:06:37 -0800, amar Singh wrote: > >> Hi, >> >> I am confused between plain python, numpy, scipy, pylab, matplotlib. > > Python is a programming language. It comes standard with many libraries > for doing basic mathematics, web access, email, etc. > > Numpy is a library for doing scientific numerical maths work and fast > processing of numeric arrays. > > Scipy is another library for scientific work. It is separate from, but > uses, Numpy. > > Matplotlib is a project for making graphing and plotting of numeric data > easy in Python. > > Pylab is a project to be Python's version of Matlab: it intends to be an > integrated bundle of Python the programming language, Numpy, Scipy, and > Matplotlib all in one easy-to-use application. > > >> I have high familiarity with matlab, but the computer I use does not >> have it. So moving to python. >> What should I use? and the best way to use it. I will be running >> matlab-like scripts sometimes on the shell prompt and sometimes on the >> command line. > > Pylab is intended to be the closest to Matlab, but I don't know how close > it is. Also, Pylab is NOT compatible with Matlab: its aim is to be an > alternative to Matlab, not to be a clone. So it cannot run Matlab scripts. > > You might also like to look at Sage: > > http://www.sagemath.org/ > > Sage is a Python project aimed to be an alternative to Mathematica. > > > Ultimately, you will have to look at the packages, see their features, > perhaps try them for a while (they are all free software, so the only > cost is your time), and decide for yourself which one meets your needs. > We can't answer that, because we don't know what you need. > > Matplotlib is excellent, it has an extensive pile of docs and examples, and the mailing list is extremely helpful. -- Cheers. Mark Lawrence. From devdixit1996 at gmail.com Wed Mar 7 04:46:59 2012 From: devdixit1996 at gmail.com (Dev Dixit) Date: Wed, 7 Mar 2012 15:16:59 +0530 Subject: Project Message-ID: Please, tell me how to develop project on "how people intract with social networing sites". From julianhu at 163.com Wed Mar 7 04:56:00 2012 From: julianhu at 163.com (=?GBK?B?uvq+/g==?=) Date: Wed, 7 Mar 2012 17:56:00 +0800 (CST) Subject: deal with cookie in python 2.3 Message-ID: <60ec6b6.155da.135ec9632a9.Coremail.julianhu@163.com> Dear All, right now I use python to capture data from a internal website. The website uses cookie to store authorization data. But there is no HttpCookieProcessor in python 2.3? Is there anybody know, how to deal with cookie in python 2.3? and could give me a sample code? thanks a lot Julian -------------- next part -------------- An HTML attachment was scrubbed... URL: From deets at web.de Wed Mar 7 05:20:33 2012 From: deets at web.de (Diez B. Roggisch) Date: Wed, 07 Mar 2012 11:20:33 +0100 Subject: "Decoding unicode is not supported" in unusual situation References: <4f571b94$0$12037$742ec2ed@news.sonic.net> Message-ID: John Nagle writes: > I think that somewhere in "suds", they subclass the "unicode" type. > That's almost too cute. > > The proper test is > > isinstance(s,unicode) Woot, you finally discovered polymorphism - congratulations! Diez From no.email at nospam.invalid Wed Mar 7 05:36:02 2012 From: no.email at nospam.invalid (Paul Rubin) Date: Wed, 07 Mar 2012 02:36:02 -0800 Subject: What's the best way to write this regular expression? References: <12783654.1174.1331073814011.JavaMail.geo-discussion-forums@yner4> <0c1a1890-dc80-41b6-abea-f90324dd7d75@2g2000yqk.googlegroups.com> Message-ID: <7x7gywofzh.fsf@ruckus.brouhaha.com> John Salerno writes: > The Beautiful Soup 4 documentation was very clear, and BS4 itself is > so simple and Pythonic. And best of all, since version 4 no longer > does the parsing itself, you can choose your own parser, and it works > with lxml, so I'll still be using lxml, but with a nice, clean overlay > for navigating the tree structure. I haven't used BS4 but have made good use of earlier versions. Main thing to understand is that an awful lot of HTML in the real world is malformed and will break an XML parser or anything that expects syntactically invalid HTML. People tend to write HTML that works well enough to render decently in browsers, whose parsers therefore have to be tolerant of bad errors. Beautiful Soup also tries to make sense of crappy, malformed, HTML. Partly as a result, it's dog slow compared to any serious XML parser. But it works very well if you don't mind the low speed. From fabiofz at gmail.com Wed Mar 7 05:38:49 2012 From: fabiofz at gmail.com (Fabio Zadrozny) Date: Wed, 7 Mar 2012 07:38:49 -0300 Subject: Error importing __init__ declared variable from another package In-Reply-To: References: Message-ID: On Wed, Feb 29, 2012 at 1:38 AM, Jason Veldicott wrote: >> > Hi, >> > >> > I have a simple configuration of modules as beneath, but an import error >> > is reported: >> > >> > /engine >> > ? ?(__init__ is empty here) >> > ? ?engine.py >> > /sim >> > ? ?__init__.py >> > >> > >> > The module engine.py imports a variable instantiated in sim.__init__ as >> > follows: >> > >> > ? ?from sim import var_name >> > ? ?var_name.func() >> > >> > The following error messaged is received on the func() call above >> > (Eclipse >> > PyDev): >> > >> > "undefined variable from import: func" >> Are you rephrasing or is this really the error message? If so run your >> program again on the command-line. Then please cut and paste the error >> message together with the traceback. >> > Any idea why this is causing an error? >> What version of Python are you using? >> What does sim/__init__.py contain? > > > > Thanks Peter. > > I'm using Python 2.6, but it works at the command line. ?The error only > appears in Eclipse as a red cross in the margin. ?The exact error msg, as > appears in a floating text caption on mouse over, is as I mentioned > (capitalised). > > Perhaps it is some issue in PyDev, maybe related to the version of Python > I'm using. > > I'm in the process of trying to solve another related import problem, and > wished to resolve this one in the hope that it might shed light on the > other.?But as it works beside the error icon appearing, I might just ignore > it and spare the trouble of precise identification of cause. Please report that as a bug in the PyDev sf tracker (please attach a sample project where this problem can be reproduced). Cheers, Fabio From praveen.patil.external at airbus.com Wed Mar 7 06:06:14 2012 From: praveen.patil.external at airbus.com (PATIL, Praveen (L&T)) Date: Wed, 7 Mar 2012 12:06:14 +0100 Subject: Need help in wx.ListBox edit Message-ID: <17690_1331118378_4F57412A_17690_6341_1_1120F6C19DDA9B4397B57F8CBBD2349204D57AD190@DE0-MAILMBX-P21.res.airbus.corp> Hi , I am using wxWidget for GUI programming. I need help in editing text appended in wx.ListBox(). Which wx API's do I need to use ? I would like to edit text on mouse double click event . Thanks in advance. Praveen. The information in this e-mail is confidential. The contents may not be disclosed or used by anyone other than the addressee. Access to this e-mail by anyone else is unauthorised. If you are not the intended recipient, please notify Airbus immediately and delete this e-mail. Airbus cannot accept any responsibility for the accuracy or completeness of this e-mail as it has been sent over public networks. If you have any concerns over the content of this message or its Accuracy or Integrity, please contact Airbus immediately. All outgoing e-mails from Airbus are checked using regularly updated virus scanning software but you should take whatever measures you deem to be appropriate to ensure that this message and any attachments are virus free. -------------- next part -------------- An HTML attachment was scrubbed... URL: From ben+python at benfinney.id.au Wed Mar 7 06:18:50 2012 From: ben+python at benfinney.id.au (Ben Finney) Date: Wed, 07 Mar 2012 22:18:50 +1100 Subject: "Decoding unicode is not supported" in unusual situation References: <4f571b94$0$12037$742ec2ed@news.sonic.net> Message-ID: <8762egmzfp.fsf@benfinney.id.au> deets at web.de (Diez B. Roggisch) writes: > John Nagle writes: > > > I think that somewhere in "suds", they subclass the "unicode" type. > > That's almost too cute. > > > > The proper test is > > > > isinstance(s,unicode) > > Woot, you finally discovered polymorphism - congratulations! If by ?discovered? you mean ?broke?. John, polymorphism entails that it *doesn't matter* whether the object inherits from any particular type; it only matters whether the object behaves correctly. So rather than testing whether the object inherits from ?unicode?, test whether it behaves how you expect ? preferably by just using it as though it does behave that way. -- \ Lucifer: ?Just sign the Contract, sir, and the Piano is yours.? | `\ Ray: ?Sheesh! This is long! Mind if I sign it now and read it | _o__) later?? ?http://www.achewood.com/ | Ben Finney From steve+comp.lang.python at pearwood.info Wed Mar 7 06:42:53 2012 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 07 Mar 2012 11:42:53 GMT Subject: "Decoding unicode is not supported" in unusual situation References: <4f571b94$0$12037$742ec2ed@news.sonic.net> <8762egmzfp.fsf@benfinney.id.au> Message-ID: <4f5749bc$0$29989$c3e8da3$5496439d@news.astraweb.com> On Wed, 07 Mar 2012 22:18:50 +1100, Ben Finney wrote: > deets at web.de (Diez B. Roggisch) writes: > >> John Nagle writes: >> >> > I think that somewhere in "suds", they subclass the "unicode" type. >> > That's almost too cute. >> > >> > The proper test is >> > >> > isinstance(s,unicode) >> >> Woot, you finally discovered polymorphism - congratulations! > > If by ?discovered? you mean ?broke?. > > John, polymorphism entails that it *doesn't matter* whether the object > inherits from any particular type; it only matters whether the object > behaves correctly. > > So rather than testing whether the object inherits from ?unicode?, test > whether it behaves how you expect ? preferably by just using it as > though it does behave that way. I must admit that I can't quite understand John Nagle's original post, so I could be wrong, but I *think* that both you and Diez have misunderstood the nature of John's complaint. I *think* he is complaining that some other library -- suds? -- has a broken test for Unicode, by using: if type(s) is unicode: ... instead of if isinstance(s, unicode): ... Consequently, when the library passes a unicode *subclass* to the tounicode function, the "type() is unicode" test fails. That's a bad bug. It's arguable that the library shouldn't even use isinstance, but that's an argument for another day. -- Steven From arun.sathyan at ust-global.com Wed Mar 7 08:20:22 2012 From: arun.sathyan at ust-global.com (arun1) Date: Wed, 7 Mar 2012 05:20:22 -0800 (PST) Subject: RotatingFileHandler Fails In-Reply-To: <64b7d1bb-21b0-4c72-aa93-692504201f7e@j8g2000yqm.googlegroups.com> References: <64b7d1bb-21b0-4c72-aa93-692504201f7e@j8g2000yqm.googlegroups.com> Message-ID: <1331126422785-4554381.post@n6.nabble.com> Hi nac, NTSafeLogging.py is working fine without any errors, but its not rotating the log files as rotatingfilehandler does. Do you have any working sample with NTSafeLogging which rotates the log file. logging issue with subprocess.Popen can be solved using this code import threading lock = threading.RLock() def acquire_lock(): lock.acquire() def release_lock(): lock.release() call the acquire_lock() at the begining of method and release_lock() at the end -- View this message in context: http://python.6.n6.nabble.com/RotatingFileHandler-Fails-tp4542769p4554381.html Sent from the Python - python-list mailing list archive at Nabble.com. From 88.janaki at gmail.com Wed Mar 7 08:44:18 2012 From: 88.janaki at gmail.com (janaki rajamani) Date: Wed, 7 Mar 2012 19:14:18 +0530 Subject: GUI components in python Message-ID: Hi I am stuck with the brain workshop software implemented using python. The code involves a lot of GUI elements and i am familar only with the basic python programming. I would like to know whether there are built in classes to support GUI elements or arethey project dependant. -- janaki -------------- next part -------------- An HTML attachment was scrubbed... URL: From alec.taylor6 at gmail.com Wed Mar 7 09:25:44 2012 From: alec.taylor6 at gmail.com (Alec Taylor) Date: Thu, 8 Mar 2012 01:25:44 +1100 Subject: Porting the 2-3 heap data-structure library from C to Python Message-ID: I am planning to port the 2-3 heap data-structure as described by Professor Tadao Takaoka in Theory of 2-3 Heaps published in 1999 and available in PDF: http://www.cosc.canterbury.ac.nz/tad.takaoka/2-3heaps.pdf The source-code used has been made available: http://www.cosc.canterbury.ac.nz/research/RG/alg/ttheap.h http://www.cosc.canterbury.ac.nz/research/RG/alg/ttheap.c I plan on wrapping it in a class. This tutorial I used to just test out calling C within Python (http://richizo.wordpress.com/2009/01/25/calling-c-functions-inside-python/) and it seems to work, but this might not be the recommended method. Any best practices for how best to wrap the 2-3 heap data-structure from C to Python? Thanks for all suggestions, Alec Taylor From stefan_ml at behnel.de Wed Mar 7 09:52:27 2012 From: stefan_ml at behnel.de (Stefan Behnel) Date: Wed, 07 Mar 2012 15:52:27 +0100 Subject: Porting the 2-3 heap data-structure library from C to Python In-Reply-To: References: Message-ID: Alec Taylor, 07.03.2012 15:25: > I am planning to port the 2-3 heap data-structure as described by > Professor Tadao Takaoka in Theory of 2-3 Heaps published in 1999 and > available in PDF: > http://www.cosc.canterbury.ac.nz/tad.takaoka/2-3heaps.pdf > > The source-code used has been made available: > http://www.cosc.canterbury.ac.nz/research/RG/alg/ttheap.h > http://www.cosc.canterbury.ac.nz/research/RG/alg/ttheap.c > > I plan on wrapping it in a class. > > This tutorial I used to just test out calling C within Python > (http://richizo.wordpress.com/2009/01/25/calling-c-functions-inside-python/) > and it seems to work, but this might not be the recommended method. > > Any best practices for how best to wrap the 2-3 heap data-structure > from C to Python? For data structures, where performance tends to matter, it's usually best to start with Cython right away, instead of using ctypes. http://cython.org/ Here's a tutorial for wrapping a C library with it: http://docs.cython.org/src/tutorial/clibraries.html Stefan From gslindstrom at gmail.com Wed Mar 7 09:52:48 2012 From: gslindstrom at gmail.com (Greg Lindstrom) Date: Wed, 7 Mar 2012 08:52:48 -0600 Subject: Python 3.2 and MS Outlook Message-ID: Is there documentation showing how to read from a Microsoft Outlook server using Python 3.2. I've done it with 2.x, but can't find anything to help me with 3.2. Thanks, --greg -------------- next part -------------- An HTML attachment was scrubbed... URL: From arun.sathyan at ust-global.com Wed Mar 7 10:33:33 2012 From: arun.sathyan at ust-global.com (arun1) Date: Wed, 7 Mar 2012 07:33:33 -0800 (PST) Subject: RotatingFileHandler Fails In-Reply-To: <64b7d1bb-21b0-4c72-aa93-692504201f7e@j8g2000yqm.googlegroups.com> References: <64b7d1bb-21b0-4c72-aa93-692504201f7e@j8g2000yqm.googlegroups.com> Message-ID: <1331134413226-4554781.post@n6.nabble.com> Hi, Actually NonInheritedRotatingFileHandler is rotating the log files but some times it falis and showing I/O errors while the log file limit reaches the given size. Thanks Arun -- View this message in context: http://python.6.n6.nabble.com/RotatingFileHandler-Fails-tp4542769p4554781.html Sent from the Python - python-list mailing list archive at Nabble.com. From hniksic at xemacs.org Wed Mar 7 10:48:18 2012 From: hniksic at xemacs.org (Hrvoje Niksic) Date: Wed, 07 Mar 2012 16:48:18 +0100 Subject: Porting the 2-3 heap data-structure library from C to Python References: Message-ID: <87boo89zul.fsf@xemacs.org> Alec Taylor writes: > The source-code used has been made available: > http://www.cosc.canterbury.ac.nz/research/RG/alg/ttheap.h > http://www.cosc.canterbury.ac.nz/research/RG/alg/ttheap.c > > I plan on wrapping it in a class. You should get acquainted with the Python/C API, which is the standard way of extending Python with high-performance (and/or system-specific) C code. See "Extending and Embedding" and "Python/C API" sections at http://docs.python.org/. There is also a mailing list for help with the C API, see http://mail.python.org/mailman/listinfo/capi-sig for details. From stefan_ml at behnel.de Wed Mar 7 11:18:06 2012 From: stefan_ml at behnel.de (Stefan Behnel) Date: Wed, 07 Mar 2012 17:18:06 +0100 Subject: Porting the 2-3 heap data-structure library from C to Python In-Reply-To: <87boo89zul.fsf@xemacs.org> References: <87boo89zul.fsf@xemacs.org> Message-ID: Hrvoje Niksic, 07.03.2012 16:48: > Alec Taylor writes: > >> The source-code used has been made available: >> http://www.cosc.canterbury.ac.nz/research/RG/alg/ttheap.h >> http://www.cosc.canterbury.ac.nz/research/RG/alg/ttheap.c >> >> I plan on wrapping it in a class. > > You should get acquainted with the Python/C API If it proves necessary, yes. > which is the standard way of extending Python with high-performance > (and/or system-specific) C code. Well, it's *one* way. Certainly not the easiest way, neither the most portable and you'll have a hard time making it the fastest. Stefan From jagteraho2006 at gmail.com Wed Mar 7 12:16:27 2012 From: jagteraho2006 at gmail.com (amar Singh) Date: Wed, 7 Mar 2012 09:16:27 -0800 (PST) Subject: help: confused about python flavors.... References: <948f80c1-877a-4a74-8adc-9d4ae702574f@l1g2000vbc.googlegroups.com> Message-ID: <485b6397-ab31-444c-b803-73ad952d98fc@eb6g2000vbb.googlegroups.com> On Mar 7, 9:41?am, Dennis Lee Bieber wrote: > On Tue, 6 Mar 2012 20:06:37 -0800 (PST), amar Singh > declaimed the following in > gmane.comp.python.general: > > > Hi, > > > I am confused between plain python, numpy, scipy, pylab, matplotlib. > > > I have high familiarity with matlab, but the computer I use does not > > have it. So moving to python. > > What should I use? and the best way to use it. I will be running > > matlab-like scripts sometimes on the shell prompt and sometimes on the > > command line. > > ? ? ? ? If Matlab compatibility is a high constraint, I'll speak heresy and > suggest you might look at Octavehttp://en.wikipedia.org/wiki/GNU_Octave > > ? ? ? ? Python is stand-alone programming/scripting language. Numpy is an > extension package adding array/matrix math operations but the syntax > won't be a direct match to Matlab; Scipy is an extension package that, > well, extends Numpy. Matplotlib is a separate package for graphical > plotting of array data. {simplistic explanation} > > -- > ? ? ? ? Wulfraed ? ? ? ? ? ? ? ? Dennis Lee Bieber ? ? ? ? AF6VN > ? ? ? ? wlfr... at ix.netcom.com ? ?HTTP://wlfraed.home.netcom.com/ Thanks everyone for helping me on this. From gordon at panix.com Wed Mar 7 12:18:23 2012 From: gordon at panix.com (John Gordon) Date: Wed, 7 Mar 2012 17:18:23 +0000 (UTC) Subject: Project References: Message-ID: In Dev Dixit writes: > Please, tell me how to develop project on "how people intract with > social networing sites". First you need a more detailed description of exactly what you want. -- 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 nareshgbhat at gmail.com Wed Mar 7 12:43:13 2012 From: nareshgbhat at gmail.com (Naresh Bhat) Date: Wed, 7 Mar 2012 23:13:13 +0530 Subject: Python-2.6.1 ctypes test cases failing Message-ID: Hi All, I have the following setup Kernel version: linux-2.6.32.41 Python Version: Python-2.6.1 Hardware target: MIPS 64bit I am just trying to run python test cases, Observed that on my MIPS 64bit system only _ctypes related test cases are failing. Is there any available patch for this issue ?? Only _ctypes test cases are failing: ============================ root at cavium-octeonplus:~# root at cavium-octeonplus:~# python /usr/lib32/python2.6/test/test_ctypes.py ..................... .................................. test_doubleresult (ctypes.test.test_functions.FunctionTestCase) ... FAIL test_floatresult (ctypes.test.test_functions.FunctionTestCase) ... FAIL test_intresult (ctypes.test.test_functions.FunctionTestCase) ... FAIL test_longdoubleresult (ctypes.test.test_functions.FunctionTestCase) ... FAIL test_longlongresult (ctypes.test.test_functions.FunctionTestCase) ... FAIL test_wchar_parm (ctypes.test.test_functions.FunctionTestCase) ... FAIL test_wchar_result (ctypes.test.test_functions.FunctionTestCase) ... FAIL test_longdouble (ctypes.test.test_callbacks.Callbacks) ... FAIL test_integrate (ctypes.test.test_callbacks.SampleCallbacksTestCase) ... FAIL test_wchar_parm (ctypes.test.test_as_parameter.AsParamPropertyWrapperTestCase) ... FAIL test_wchar_parm (ctypes.test.test_as_parameter.AsParamWrapperTestCase) ... FAIL test_wchar_parm (ctypes.test.test_as_parameter.BasicWrapTestCase) ... FAIL test_qsort (ctypes.test.test_libc.LibTest) ... FAIL test_sqrt (ctypes.test.test_libc.LibTest) ... FAIL test_double (ctypes.test.test_cfuncs.CFunctions) ... FAIL test_double_plus (ctypes.test.test_cfuncs.CFunctions) ... FAIL test_float (ctypes.test.test_cfuncs.CFunctions) ... FAIL test_float_plus (ctypes.test.test_cfuncs.CFunctions) ... FAIL test_longdouble (ctypes.test.test_cfuncs.CFunctions) ... FAIL test_longdouble_plus (ctypes.test.test_cfuncs.CFunctions) ... FAIL --Thanks and Regards "For things to change, we must change" -Naresh Bhat From rodrick.brown at gmail.com Wed Mar 7 13:06:38 2012 From: rodrick.brown at gmail.com (Rodrick Brown) Date: Wed, 7 Mar 2012 13:06:38 -0500 Subject: Project In-Reply-To: References: Message-ID: <9C02C81E-BD8F-41DD-803E-F5EDC274A1EF@gmail.com> Pay a smart developer! Sent from my iPhone On Mar 7, 2012, at 4:46 AM, Dev Dixit wrote: > Please, tell me how to develop project on "how people intract with > social networing sites". > -- > http://mail.python.org/mailman/listinfo/python-list From ramit.prasad at jpmorgan.com Wed Mar 7 14:05:23 2012 From: ramit.prasad at jpmorgan.com (Prasad, Ramit) Date: Wed, 7 Mar 2012 19:05:23 +0000 Subject: are int, float, long, double, side-effects of computer engineering? In-Reply-To: References: <5aaded58-af09-41dc-9afd-56d7b7ced239@d7g2000pbl.googlegroups.com> <4F5681A6.9090707@calvinkim.org> Message-ID: <5B80DD153D7D744689F57F4FB69AF474194791@SCACMX008.exchad.jpmchase.net> Dennis Lee Bieber wrote: > It wouldn't surprise me to find out that modern CompSci degrees > don't even discuss machine representation of numbers. As a fairly recent graduate, I can assure you that they still do. Well, I should say at least my school did since I cannot speak for every other school. Ramit Ramit Prasad | JPMorgan Chase Investment Bank | Currencies Technology 712 Main Street | Houston, TX 77002 work phone: 713 - 216 - 5423 -- This email is confidential and subject to important disclaimers and conditions including on offers for the purchase or sale of securities, accuracy and completeness of information, viruses, confidentiality, legal privilege, and legal entity disclaimers, available at http://www.jpmorgan.com/pages/disclosures/email. From nagle at animats.com Wed Mar 7 14:25:47 2012 From: nagle at animats.com (John Nagle) Date: Wed, 07 Mar 2012 11:25:47 -0800 Subject: "Decoding unicode is not supported" in unusual situation In-Reply-To: <4f5749bc$0$29989$c3e8da3$5496439d@news.astraweb.com> References: <4f571b94$0$12037$742ec2ed@news.sonic.net> <8762egmzfp.fsf@benfinney.id.au> <4f5749bc$0$29989$c3e8da3$5496439d@news.astraweb.com> Message-ID: <4f57b63f$0$11986$742ec2ed@news.sonic.net> On 3/7/2012 3:42 AM, Steven D'Aprano wrote: > I *think* he is complaining that some other library -- suds? -- has a > broken test for Unicode, by using: > > if type(s) is unicode: ... > > instead of > > if isinstance(s, unicode): ... > > Consequently, when the library passes a unicode *subclass* to the > tounicode function, the "type() is unicode" test fails. That's a bad bug. No, that was my bug. The library bug, if any, is that you can't apply unicode(s, errors='replace') to a Unicode string. TypeError("Decoding unicode is not supported") is raised. However unicode(s) will accept Unicode input. The Python documentation ("http://docs.python.org/library/functions.html#unicode") does not mention this. It is therefore necessary to check the type before calling "unicode", or catch the undocumented TypeError exception afterward. John Nagle From tjreedy at udel.edu Wed Mar 7 14:25:59 2012 From: tjreedy at udel.edu (Terry Reedy) Date: Wed, 07 Mar 2012 14:25:59 -0500 Subject: Python-2.6.1 ctypes test cases failing In-Reply-To: References: Message-ID: On 3/7/2012 12:43 PM, Naresh Bhat wrote: > Hi All, > > I have the following setup > > Kernel version: linux-2.6.32.41 > Python Version: Python-2.6.1 > Hardware target: MIPS 64bit > > I am just trying to run python test cases, Observed that on my MIPS > 64bit system only _ctypes related test cases are failing. > > Is there any available patch for this issue ?? There have been patches to ctypes since 2.6.1. At minimum, you should be using the latest version of 2.6. Even better, perhaps, would be the latest version of 2.7, since it contain patches applied after 2.6 went to security fixes only. -- Terry Jan Reedy From pkleiweg at xs4all.nl Wed Mar 7 14:41:46 2012 From: pkleiweg at xs4all.nl (Peter Kleiweg) Date: Wed, 7 Mar 2012 20:41:46 +0100 Subject: sys.stdout.detach() results in ValueError Message-ID: I want to write out some binary data to stdout in Python3. I thought the way to do this was to call detach on sys.stdout. But apparently, you can't. Here is a minimal script: #!/usr/bin/env python3.1 import sys fp = sys.stdout.detach() Not yet using fp in any way, this script gives the following error: Exception ValueError: 'underlying buffer has been detached' in Same in Python 3.1.4 and Python 3.2.2 So, what do I do if I want to send binary data to stdout? -- Peter Kleiweg http://pkleiweg.home.xs4all.nl/ From wanderer at dialup4less.com Wed Mar 7 14:49:49 2012 From: wanderer at dialup4less.com (Wanderer) Date: Wed, 7 Mar 2012 11:49:49 -0800 (PST) Subject: Python recursive tree, linked list thingy Message-ID: I have a list of defective CCD pixels and I need to find clusters where a cluster is a group of adjacent defective pixels. This seems to me to be a classic linked list tree search.I take a pixel from the defective list and check if an adjacent pixel is in the list. If it is I add the pixel to the cluster and remove it from the defective list. I then check an adjacent pixel of the new pixel and so on down the branch until I don't find a defective pixel. The I move up to the previous pixel and check the next adjacent pixel and so on until I'm back at the head I can't find any more defective adjacent pixels. How do you handle this sort of thing in Python? From ian.g.kelly at gmail.com Wed Mar 7 15:03:52 2012 From: ian.g.kelly at gmail.com (Ian Kelly) Date: Wed, 7 Mar 2012 13:03:52 -0700 Subject: Python recursive tree, linked list thingy In-Reply-To: References: Message-ID: On Wed, Mar 7, 2012 at 12:49 PM, Wanderer wrote: > I have a list of defective CCD pixels and I need to find clusters > where a cluster is a group of adjacent defective pixels. This seems to > me to be a classic linked list tree search.I take a pixel from the > defective list and check if an adjacent pixel is in the list. If it is > I add the pixel to the cluster and remove it from the defective list. > I then check an adjacent pixel of the new pixel and so on down the > branch until I don't find a defective pixel. The I move up to the > previous pixel and check the next adjacent pixel ?and so on until I'm > back at the head I can't find any more defective adjacent pixels. How > do you handle this sort of thing in Python? A set of defective pixels would be the probable choice, since it offers efficient membership testing. From ramit.prasad at jpmorgan.com Wed Mar 7 15:03:57 2012 From: ramit.prasad at jpmorgan.com (Prasad, Ramit) Date: Wed, 7 Mar 2012 20:03:57 +0000 Subject: Project In-Reply-To: References: Message-ID: <5B80DD153D7D744689F57F4FB69AF474195563@SCACMX008.exchad.jpmchase.net> > > Please, tell me how to develop project on "how people intract with > > social networing sites". > > This sounds more like a social sciences study than anything > programming related... > > And since I don't do such sites, it may be intractable... Or he could be wanting to know how to use something like Facebook API, but with such a vague description it is hard to say. Even harder to be interested in helping since that is such a broad scope. Ramit Ramit Prasad | JPMorgan Chase Investment Bank | Currencies Technology 712 Main Street | Houston, TX 77002 work phone: 713 - 216 - 5423 -- This email is confidential and subject to important disclaimers and conditions including on offers for the purchase or sale of securities, accuracy and completeness of information, viruses, confidentiality, legal privilege, and legal entity disclaimers, available at http://www.jpmorgan.com/pages/disclosures/email. From python at mrabarnett.plus.com Wed Mar 7 15:12:21 2012 From: python at mrabarnett.plus.com (MRAB) Date: Wed, 07 Mar 2012 20:12:21 +0000 Subject: Python recursive tree, linked list thingy In-Reply-To: References: Message-ID: <4F57C125.5020903@mrabarnett.plus.com> On 07/03/2012 19:49, Wanderer wrote: > I have a list of defective CCD pixels and I need to find clusters > where a cluster is a group of adjacent defective pixels. This seems to > me to be a classic linked list tree search.I take a pixel from the > defective list and check if an adjacent pixel is in the list. If it is > I add the pixel to the cluster and remove it from the defective list. > I then check an adjacent pixel of the new pixel and so on down the > branch until I don't find a defective pixel. The I move up to the > previous pixel and check the next adjacent pixel and so on until I'm > back at the head I can't find any more defective adjacent pixels. How > do you handle this sort of thing in Python? Something like this could work: clusters = [] while defective_set: to_do = {defective_set.pop()} done = set() while to_do: pixel = to_do.pop() neighbours = {n for n in defective_set if are_adjacent(n, pixel)} defective_set -= neighbours to_do |= neighbours done.add(pixel) clusters.append(done) From news at blinne.net Wed Mar 7 15:17:34 2012 From: news at blinne.net (Alexander Blinne) Date: Wed, 07 Mar 2012 21:17:34 +0100 Subject: Python recursive tree, linked list thingy In-Reply-To: References: Message-ID: <4f57c25d$0$6580$9b4e6d93@newsspool3.arcor-online.net> Am 07.03.2012 20:49, schrieb Wanderer: > I have a list of defective CCD pixels and I need to find clusters > where a cluster is a group of adjacent defective pixels. This seems to > me to be a classic linked list tree search.I take a pixel from the > defective list and check if an adjacent pixel is in the list. If it is > I add the pixel to the cluster and remove it from the defective list. > I then check an adjacent pixel of the new pixel and so on down the > branch until I don't find a defective pixel. The I move up to the > previous pixel and check the next adjacent pixel and so on until I'm > back at the head I can't find any more defective adjacent pixels. How > do you handle this sort of thing in Python? I'd do something like (code not tested): defective_list = [(x1, y1), (x2, y2), ...] #list of coordinates of #defective pixel #build one cluster: cluster_start = defective_list.pop() #starting point buf = [] #buffer for added pixels buf.push(cluster_start) cluster = [] cluster.push(cluster_start) while len(buf)>0: i = buf.pop() for b, d in itertools.product(xrange(2), [-1,1]): #4 neighbours j = list(i) j[b] += d j = tuple(j) if outside_lcd(j) or j in cluster or j not in defective_list: continue defective_list.remove(j) cluster.push(j) buf.push(j) return cluster and repeat it until defective_list is empty. From ian.g.kelly at gmail.com Wed Mar 7 15:27:46 2012 From: ian.g.kelly at gmail.com (Ian Kelly) Date: Wed, 7 Mar 2012 13:27:46 -0700 Subject: Python recursive tree, linked list thingy In-Reply-To: References: Message-ID: On Wed, Mar 7, 2012 at 1:03 PM, Ian Kelly wrote: > A set of defective pixels would be the probable choice, since it > offers efficient membership testing. Some actual code, using a recursive generator: def get_cluster(defective, pixel): yield pixel (row, column) = pixel for adjacent in [(row - 1, column), (row, column - 1), (row, column + 1), (row + 1, column)]: if adjacent in defective: defective.remove(adjacent) for cluster_pixel in get_cluster(defective, adjacent): yield cluster_pixel defective = {(327, 415), (180, 97), (326, 415), (42, 15), (180, 98), (325, 414), (325, 415)} clusters = [] while defective: pixel = defective.pop() clusters.append(list(get_cluster(defective, pixel))) from pprint import pprint pprint(clusters) Cheers, Ian From johnjsal at gmail.com Wed Mar 7 15:39:22 2012 From: johnjsal at gmail.com (John Salerno) Date: Wed, 7 Mar 2012 12:39:22 -0800 (PST) Subject: What's the best way to write this regular expression? References: <12783654.1174.1331073814011.JavaMail.geo-discussion-forums@yner4> Message-ID: Ok, first major roadblock. I have no idea how to install Beautiful Soup or lxml on Windows! All I can find are .tar files. Based on what I've read, I can use the easy_setup module to install these types of files, but when I went to download the setuptools package, it only seemed to support Python 2.7. I'm using 3.2. Is 2.7 just the minimum version it requires? It didn't say something like "2.7+", so I wasn't sure, and I don't want to start installing a bunch of stuff that will clog up my directories and not even work. What's the best way for me to install these two packages? I've also seen a reference to using setup.py...is that a separate package too, or is that something that comes with Python by default? Thanks. From pkleiweg at xs4all.nl Wed Mar 7 15:57:03 2012 From: pkleiweg at xs4all.nl (Peter Kleiweg) Date: Wed, 7 Mar 2012 21:57:03 +0100 Subject: what is best method to set sys.stdout to utf-8? Message-ID: In Python 3, there seem to be two ways to set sys.stdout to utf-8 after the script has started: sys.stdout = codecs.getwriter('utf-8')(sys.stdout.detach()) sys.stdout = io.TextIOWrapper(sys.stdout.detach(), encoding='utf-8') I guess the second is better. At start-up, type(sys.stdout) is , and it's also after using the second method. After using the first method, type(sys.stdout) is changed to . Should I always use the second method? -- Peter Kleiweg http://pkleiweg.home.xs4all.nl/ From ian.g.kelly at gmail.com Wed Mar 7 16:01:16 2012 From: ian.g.kelly at gmail.com (Ian Kelly) Date: Wed, 7 Mar 2012 14:01:16 -0700 Subject: What's the best way to write this regular expression? In-Reply-To: References: <12783654.1174.1331073814011.JavaMail.geo-discussion-forums@yner4> Message-ID: On Wed, Mar 7, 2012 at 1:39 PM, John Salerno wrote: > Ok, first major roadblock. I have no idea how to install Beautiful > Soup or lxml on Windows! All I can find are .tar files. Based on what > I've read, I can use the easy_setup module to install these types of > files, but when I went to download the setuptools package, it only > seemed to support Python 2.7. I'm using 3.2. Is 2.7 just the minimum > version it requires? It didn't say something like "2.7+", so I wasn't > sure, and I don't want to start installing a bunch of stuff that will > clog up my directories and not even work. There is a fork of setuptools called "distribute" that supports Python 3. > What's the best way for me to install these two packages? I've also > seen a reference to using setup.py...is that a separate package too, > or is that something that comes with Python by default? setup.py is a file that should be included at the top-level of the .tar files you downloaded. Generally, to install something in that manner, you would navigate to that top-level folder and run "python setup.py install". If you have multiple Python versions installed and want to install the package for a specific version, then you would use that version of Python to run the setup.py file. From shane.neeley at gmail.com Wed Mar 7 16:02:43 2012 From: shane.neeley at gmail.com (Shane Neeley) Date: Wed, 7 Mar 2012 13:02:43 -0800 (PST) Subject: Python site-packages permission denied? Message-ID: <5849344.1361.1331154163099.JavaMail.geo-discussion-forums@pbls8> What do I need to do to successfully install a package onto python so that I can use it as a module? I have tried in terminal in the correct directory "python2.7 ./setup.py install" but it says permission denied. Shanes-MacBook-Pro:seisen-urllib2_file-cf4c4c8 chimpsarehungry$ python2.7.1 ./setup.py install -bash: python2.7.1: command not found Shanes-MacBook-Pro:seisen-urllib2_file-cf4c4c8 chimpsarehungry$ python ./setup.py install running install running build running build_py running install_lib copying build/lib/urllib2_file.py -> /Library/Python/2.7/site-packages error: /Library/Python/2.7/site-packages/urllib2_file.py: Permission denied Shanes-MacBook-Pro:seisen-urllib2_file-cf4c4c8 chimpsarehungry$ From johnjsal at gmail.com Wed Mar 7 16:11:17 2012 From: johnjsal at gmail.com (John Salerno) Date: Wed, 7 Mar 2012 15:11:17 -0600 Subject: What's the best way to write this regular expression? In-Reply-To: References: <12783654.1174.1331073814011.JavaMail.geo-discussion-forums@yner4> Message-ID: On Wed, Mar 7, 2012 at 3:01 PM, Ian Kelly wrote: > There is a fork of setuptools called "distribute" that supports Python 3. Thanks, I guess I'll give this a try tonight! > setup.py is a file that should be included at the top-level of the > .tar files you downloaded. ?Generally, to install something in that > manner, you would navigate to that top-level folder and run "python > setup.py install". ?If you have multiple Python versions installed and > want to install the package for a specific version, then you would use > that version of Python to run the setup.py file. The only files included in the .tar.gz file is a .tar file of the same name. So I guess the setup option doesn't exist for these particular packages. I'll try "distribute" tonight when I have some time to mess with all of this. So much work just to get a 3rd party module installed! From someone at someplace.invalid Wed Mar 7 16:22:52 2012 From: someone at someplace.invalid (HoneyMonster) Date: Wed, 7 Mar 2012 21:22:52 +0000 (UTC) Subject: Project References: Message-ID: On Wed, 07 Mar 2012 13:06:38 -0500, Rodrick Brown wrote: > Pay a smart developer! What? For homework? From benjamin.kaplan at case.edu Wed Mar 7 16:27:26 2012 From: benjamin.kaplan at case.edu (Benjamin Kaplan) Date: Wed, 7 Mar 2012 16:27:26 -0500 Subject: What's the best way to write this regular expression? In-Reply-To: References: <12783654.1174.1331073814011.JavaMail.geo-discussion-forums@yner4> Message-ID: On Wed, Mar 7, 2012 at 4:11 PM, John Salerno wrote: > > On Wed, Mar 7, 2012 at 3:01 PM, Ian Kelly wrote: > > > There is a fork of setuptools called "distribute" that supports Python > > 3. > > Thanks, I guess I'll give this a try tonight! > > > setup.py is a file that should be included at the top-level of the > > .tar files you downloaded. ?Generally, to install something in that > > manner, you would navigate to that top-level folder and run "python > > setup.py install". ?If you have multiple Python versions installed and > > want to install the package for a specific version, then you would use > > that version of Python to run the setup.py file. > > The only files included in the .tar.gz file is a .tar file of the same > name. So I guess the setup option doesn't exist for these particular > packages. I'll try "distribute" tonight when I have some time to mess > with all of this. > > So much work just to get a 3rd party module installed! > -- It's because your extraction program is weird. Gzip is a compression algorithm that operates on a single file. Tar is an archive format that combines multiple files into a single file. When we say "extract the .tar.gz", what we mean is both uncompress the tar file and then extract everything out of that. A lot of programs will do that in one step. If you look inside the tar file, you should find the setup.py. From clp2 at rebertia.com Wed Mar 7 16:30:24 2012 From: clp2 at rebertia.com (Chris Rebert) Date: Wed, 7 Mar 2012 13:30:24 -0800 Subject: Python site-packages permission denied? In-Reply-To: <5849344.1361.1331154163099.JavaMail.geo-discussion-forums@pbls8> References: <5849344.1361.1331154163099.JavaMail.geo-discussion-forums@pbls8> Message-ID: On Wed, Mar 7, 2012 at 1:02 PM, Shane Neeley wrote: > What do I need to do to successfully install a package onto python so that I can use it as a module? > > I have tried in terminal in the correct directory "python2.7 ./setup.py install" but it says permission denied. > > Shanes-MacBook-Pro:seisen-urllib2_file-cf4c4c8 chimpsarehungry$ python2.7.1 ./setup.py install > -bash: python2.7.1: command not found > Shanes-MacBook-Pro:seisen-urllib2_file-cf4c4c8 chimpsarehungry$ python ./setup.py install > running install > running build > running build_py > running install_lib > copying build/lib/urllib2_file.py -> /Library/Python/2.7/site-packages > error: /Library/Python/2.7/site-packages/urllib2_file.py: Permission denied > Shanes-MacBook-Pro:seisen-urllib2_file-cf4c4c8 chimpsarehungry$ You generally shouldn't mess with Mac OS X's system copies of Python. Typically, one installs a separate copy using MacPorts, Fink, or whatever, and uses that instead. In any case, you generally need to `sudo` when installing stuff system-wide. Cheers, Chris From ramit.prasad at jpmorgan.com Wed Mar 7 16:31:03 2012 From: ramit.prasad at jpmorgan.com (Prasad, Ramit) Date: Wed, 7 Mar 2012 21:31:03 +0000 Subject: What's the best way to write this regular expression? In-Reply-To: References: <12783654.1174.1331073814011.JavaMail.geo-discussion-forums@yner4> Message-ID: <5B80DD153D7D744689F57F4FB69AF47419567C@SCACMX008.exchad.jpmchase.net> > The only files included in the .tar.gz file is a .tar file of the same > name. gz stands for gzip and is a form of compression (like rar/zip ). tar stands for a tape archive. It is basically a box that holds the files. So you need to "unzip" and then "open the box". Normally programs like WinZip / WinRar / 7-zip will do both in one step so you do not need to. Not sure what program you are using... Ramit Ramit Prasad | JPMorgan Chase Investment Bank | Currencies Technology 712 Main Street | Houston, TX 77002 work phone: 713 - 216 - 5423 -- This email is confidential and subject to important disclaimers and conditions including on offers for the purchase or sale of securities, accuracy and completeness of information, viruses, confidentiality, legal privilege, and legal entity disclaimers, available at http://www.jpmorgan.com/pages/disclosures/email. From ramit.prasad at jpmorgan.com Wed Mar 7 16:32:32 2012 From: ramit.prasad at jpmorgan.com (Prasad, Ramit) Date: Wed, 7 Mar 2012 21:32:32 +0000 Subject: Project In-Reply-To: References: Message-ID: <5B80DD153D7D744689F57F4FB69AF474195695@SCACMX008.exchad.jpmchase.net> > > Pay a smart developer! > > What? For homework? Sure why not? Smart developers could use extra money ;) Ramit Ramit Prasad | JPMorgan Chase Investment Bank | Currencies Technology 712 Main Street | Houston, TX 77002 work phone: 713 - 216 - 5423 -- This email is confidential and subject to important disclaimers and conditions including on offers for the purchase or sale of securities, accuracy and completeness of information, viruses, confidentiality, legal privilege, and legal entity disclaimers, available at http://www.jpmorgan.com/pages/disclosures/email. From ian.g.kelly at gmail.com Wed Mar 7 16:34:59 2012 From: ian.g.kelly at gmail.com (Ian Kelly) Date: Wed, 7 Mar 2012 14:34:59 -0700 Subject: What's the best way to write this regular expression? In-Reply-To: References: <12783654.1174.1331073814011.JavaMail.geo-discussion-forums@yner4> Message-ID: On Wed, Mar 7, 2012 at 2:11 PM, John Salerno wrote: > The only files included in the .tar.gz file is a .tar file of the same > name. So I guess the setup option doesn't exist for these particular > packages. The setup.py file (as well as the other files) would be inside the .tar file. Unlike a Windows zip file, which does both archival and compression, Unix files are typically archived and compressed in two separate steps: "tar" denotes the archival format, and "gz" denotes the compression format. Some decompression programs are smart enough to recognize the .tar file and automatically extract it when decompressing. Others require you to decompress the .gz and extract the .tar separately -- it sounds like yours is one of the latter. From johnjsal at gmail.com Wed Mar 7 16:44:28 2012 From: johnjsal at gmail.com (John Salerno) Date: Wed, 7 Mar 2012 15:44:28 -0600 Subject: What's the best way to write this regular expression? In-Reply-To: References: <12783654.1174.1331073814011.JavaMail.geo-discussion-forums@yner4> Message-ID: On Wed, Mar 7, 2012 at 3:34 PM, Ian Kelly wrote: > The setup.py file (as well as the other files) would be inside the > .tar file. ?Unlike a Windows zip file, which does both archival and > compression, Unix files are typically archived and compressed in two > separate steps: "tar" denotes the archival format, and "gz" denotes > the compression format. ?Some decompression programs are smart enough > to recognize the .tar file and automatically extract it when > decompressing. ?Others require you to decompress the .gz and extract > the .tar separately -- it sounds like yours is one of the latter. Ah, I see now. After opening the gz file, there was a tar file inside, and then I just opened that file (I use 7zip for these types) and there was a whole host of stuff inside. I didn't realize the tar file itself was an archive, I thought it was the module! ::blush:: Maybe I don't need to mess with the "distribute" utility then, if I can just run the setup file. I'll try that first and see what happens. Thanks. From ben+python at benfinney.id.au Wed Mar 7 16:48:58 2012 From: ben+python at benfinney.id.au (Ben Finney) Date: Thu, 08 Mar 2012 08:48:58 +1100 Subject: "Decoding unicode is not supported" in unusual situation References: <4f571b94$0$12037$742ec2ed@news.sonic.net> <8762egmzfp.fsf@benfinney.id.au> <4f5749bc$0$29989$c3e8da3$5496439d@news.astraweb.com> <4f57b63f$0$11986$742ec2ed@news.sonic.net> Message-ID: <871up4m69h.fsf@benfinney.id.au> John Nagle writes: > The library bug, if any, is that you can't apply > > unicode(s, errors='replace') > > to a Unicode string. TypeError("Decoding unicode is not supported") is > raised. However > > unicode(s) > > will accept Unicode input. I think that's a Python bug. If the latter succeeds as a no-op, the former should also succeed as a no-op. Neither should ever get any errors when ?s? is a ?unicode? object already. > The Python documentation > ("http://docs.python.org/library/functions.html#unicode") does not > mention this. It is therefore necessary to check the type before > calling "unicode", or catch the undocumented TypeError exception > afterward. Yes, this check should not be necessary; calling the ?unicode? constructor with an object that's already an instance of ?unicode? should just return the object as-is, IMO. It shouldn't matter that you've specified how decoding errors are to be handled, because in that case no decoding happens anyway. Care to report that bug to , John? -- \ ?Those who write software only for pay should go hurt some | `\ other field.? ?Erik Naggum, in _gnu.misc.discuss_ | _o__) | Ben Finney From ben+python at benfinney.id.au Wed Mar 7 16:50:25 2012 From: ben+python at benfinney.id.au (Ben Finney) Date: Thu, 08 Mar 2012 08:50:25 +1100 Subject: Project References: Message-ID: <87wr6wkrmm.fsf@benfinney.id.au> Dev Dixit writes: > Please, tell me how to develop project on "how people intract with > social networing sites". Step one: collect data. Step two: ??? Step three: project! -- \ ?Try to become not a man of success, but try rather to become a | `\ man of value.? ?Albert Einstein | _o__) | Ben Finney From russ.paielli at gmail.com Wed Mar 7 17:02:14 2012 From: russ.paielli at gmail.com (Russ P.) Date: Wed, 7 Mar 2012 14:02:14 -0800 (PST) Subject: are int, float, long, double, side-effects of computer engineering? References: <5aaded58-af09-41dc-9afd-56d7b7ced239@d7g2000pbl.googlegroups.com> <8a3cd8d4-26d2-4cdf-b66d-43895a0bcd1e@qb4g2000pbb.googlegroups.com> Message-ID: <7a32aa69-e1c7-4129-be11-70ae461b34b8@od7g2000pbb.googlegroups.com> On Mar 6, 7:25?pm, rusi wrote: > On Mar 6, 6:11?am, Xah Lee wrote: > > > some additional info i thought is relevant. > > > are int, float, long, double, side-effects of computer engineering? > > It is a bit naive for computer scientists to club integers and reals > as mathematicians do given that for real numbers, even equality is > undecidable! > Mostly when a system like mathematica talks of real numbers it means > computable real numbers which is a subset of mathematical real numbers > (and of course a superset of floats) > > Seehttp://en.wikipedia.org/wiki/Computable_number#Can_computable_numbers... I might add that Mathematica is designed mainly for symbolic computation, whereas IEEE floating point numbers are intended for numerical computation. Those are two very different endeavors. I played with Mathematica a bit several years ago, and I know it can do numerical computation too. I wonder if it resorts to IEEE floating point numbers when it does. From driscoll at cs.wisc.edu Wed Mar 7 17:02:42 2012 From: driscoll at cs.wisc.edu (Evan Driscoll) Date: Wed, 07 Mar 2012 16:02:42 -0600 Subject: What's the best way to write this regular expression? In-Reply-To: <5B80DD153D7D744689F57F4FB69AF47419567C@SCACMX008.exchad.jpmchase.net> References: <12783654.1174.1331073814011.JavaMail.geo-discussion-forums@yner4> <5B80DD153D7D744689F57F4FB69AF47419567C@SCACMX008.exchad.jpmchase.net> Message-ID: <4F57DB02.8040700@cs.wisc.edu> On 01/-10/-28163 01:59 PM, Prasad, Ramit wrote: > gz stands for gzip and is a form of compression (like rar/zip ). > tar stands for a tape archive. It is basically a box that holds the > files. So you need to "unzip" and then "open the box". > > Normally programs like WinZip / WinRar / 7-zip will do both in one step > so you do not need to. Not sure what program you are using... I'm not sure what 7-zip you're referring to, because I use 7-zip and it's always been a two-step process for me... (Though I can't say I've looked through the preferences dialog for a "extract .tar.gz files in one go" setting.) Evan From mining.facts at googlemail.com Wed Mar 7 17:02:51 2012 From: mining.facts at googlemail.com (Christian) Date: Wed, 7 Mar 2012 14:02:51 -0800 (PST) Subject: BitSet &Redis Message-ID: <399c9d09-8e20-4db6-8f5b-bc7f3e683329@k24g2000yqe.googlegroups.com> I play around with redis. Isn't it possible to handle BitSet with Python "as" in Java? BitSet users = BitSet.valueOf(redis.get(key.getBytes())); all.or(users); System.out.println(all.cardinality()) I try something with the struct and bitstring libs , but haven't any success. Even the follow snippet didn't work, beacause bitset[0] isn't approriate. bitset = r.get('bytestringFromRedis') x = "{0:b}".format(ord(bitset[0])) Thanks in advance Christian From d at davea.name Wed Mar 7 17:14:35 2012 From: d at davea.name (Dave Angel) Date: Wed, 07 Mar 2012 17:14:35 -0500 Subject: sys.stdout.detach() results in ValueError In-Reply-To: References: Message-ID: <4F57DDCB.50209@davea.name> On 03/07/2012 02:41 PM, Peter Kleiweg wrote: > I want to write out some binary data to stdout in Python3. I > thought the way to do this was to call detach on sys.stdout. But > apparently, you can't. Here is a minimal script: > > #!/usr/bin/env python3.1 > import sys > fp = sys.stdout.detach() > > Not yet using fp in any way, this script gives the following error: > > Exception ValueError: 'underlying buffer has been detached' in > > Same in Python 3.1.4 and Python 3.2.2 > > So, what do I do if I want to send binary data to stdout? > > > sys.stdout.write( some_binary_data ) Why should you need to do some funny manipulation? If you have some other unstated motivation, better ask a clearer question. -- DaveA From pkleiweg at xs4all.nl Wed Mar 7 17:35:46 2012 From: pkleiweg at xs4all.nl (Peter Kleiweg) Date: Wed, 7 Mar 2012 23:35:46 +0100 Subject: sys.stdout.detach() results in ValueError In-Reply-To: References: Message-ID: Dave Angel schreef op de 7e dag van de lentemaand van het jaar 2012: > On 03/07/2012 02:41 PM, Peter Kleiweg wrote: > > I want to write out some binary data to stdout in Python3. I > > thought the way to do this was to call detach on sys.stdout. But > > apparently, you can't. Here is a minimal script: > > > > #!/usr/bin/env python3.1 > > import sys > > fp = sys.stdout.detach() > > > > Not yet using fp in any way, this script gives the following error: > > > > Exception ValueError: 'underlying buffer has been detached' in > > > > Same in Python 3.1.4 and Python 3.2.2 > > > > So, what do I do if I want to send binary data to stdout? > > > > > > > > sys.stdout.write( some_binary_data ) TypeError: must be str, not bytes -- Peter Kleiweg http://pkleiweg.home.xs4all.nl/ From steve+comp.lang.python at pearwood.info Wed Mar 7 18:26:37 2012 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 07 Mar 2012 23:26:37 GMT Subject: "Decoding unicode is not supported" in unusual situation References: <4f571b94$0$12037$742ec2ed@news.sonic.net> <8762egmzfp.fsf@benfinney.id.au> <4f5749bc$0$29989$c3e8da3$5496439d@news.astraweb.com> <4f57b63f$0$11986$742ec2ed@news.sonic.net> <871up4m69h.fsf@benfinney.id.au> Message-ID: <4f57eeac$0$29989$c3e8da3$5496439d@news.astraweb.com> On Thu, 08 Mar 2012 08:48:58 +1100, Ben Finney wrote: > John Nagle writes: > >> The library bug, if any, is that you can't apply >> >> unicode(s, errors='replace') >> >> to a Unicode string. TypeError("Decoding unicode is not supported") is >> raised. However >> >> unicode(s) >> >> will accept Unicode input. > > I think that's a Python bug. If the latter succeeds as a no-op, the > former should also succeed as a no-op. Neither should ever get any > errors when ?s? is a ?unicode? object already. No. The semantics of the unicode function (technically: a type constructor) are well-defined, and there are two distinct behaviours: unicode(obj) is analogous to str(obj), and it attempts to convert obj to a unicode string by calling obj.__unicode__, if it exists, or __str__ if it doesn't. No encoding or decoding is attempted in the event that obj is a unicode instance. unicode(obj, encoding, errors) is explicitly stated in the docs as decoding obj if EITHER of encoding or errors is given, AND that obj must be either an 8-bit string (bytes) or a buffer object. It is true that u''.decode() will succeed, in Python 2, but the fact that unicode objects have a decode method at all is IMO a bug. It has also been corrected in Python 3, where (unicode) str objects no longer have a decode method, and bytes objects no longer have an encode method. >> The Python documentation >> ("http://docs.python.org/library/functions.html#unicode") does not >> mention this. Yes it does. It is is the SECOND sentence, immediately after the summary line: unicode([object[, encoding[, errors]]]) Return the Unicode string version of object using one of the following modes: If encoding and/or errors are given, unicode() will decode the object which can either be an 8-bit string or a character buffer using the codec for encoding. ... Admittedly, it doesn't *explicitly* state that TypeError will be raised, but what other exception kind would you expect when you supply an argument of the wrong type? >> It is therefore necessary to check the type before >> calling "unicode", or catch the undocumented TypeError exception >> afterward. > > Yes, this check should not be necessary; calling the ?unicode? > constructor with an object that's already an instance of ?unicode? > should just return the object as-is, IMO. It shouldn't matter that > you've specified how decoding errors are to be handled, because in that > case no decoding happens anyway. I don't believe that it is the job of unicode() to Do What I Mean, but only to Do What I Say. If I *explicitly* tell unicode() to decode the argument (by specifying either the codec or the error handler or both) then it should not double-guess me and ignore the extra parameters. End-user applications may, with care, try to be smart and DWIM, but library functions should be dumb and should do what they are told. -- Steven From tjreedy at udel.edu Wed Mar 7 19:03:41 2012 From: tjreedy at udel.edu (Terry Reedy) Date: Wed, 07 Mar 2012 19:03:41 -0500 Subject: "Decoding unicode is not supported" in unusual situation In-Reply-To: <4f57eeac$0$29989$c3e8da3$5496439d@news.astraweb.com> References: <4f571b94$0$12037$742ec2ed@news.sonic.net> <8762egmzfp.fsf@benfinney.id.au> <4f5749bc$0$29989$c3e8da3$5496439d@news.astraweb.com> <4f57b63f$0$11986$742ec2ed@news.sonic.net> <871up4m69h.fsf@benfinney.id.au> <4f57eeac$0$29989$c3e8da3$5496439d@news.astraweb.com> Message-ID: On 3/7/2012 6:26 PM, Steven D'Aprano wrote: > On Thu, 08 Mar 2012 08:48:58 +1100, Ben Finney wrote: > >> John Nagle writes: >> >>> The library bug, if any, is that you can't apply >>> >>> unicode(s, errors='replace') >>> >>> to a Unicode string. TypeError("Decoding unicode is not supported") is >>> raised. However >>> >>> unicode(s) >>> >>> will accept Unicode input. >> >> I think that's a Python bug. If the latter succeeds as a no-op, the >> former should also succeed as a no-op. Neither should ever get any >> errors when ?s? is a ?unicode? object already. > No. The semantics of the unicode function (technically: a type > constructor) are well-defined, and there are two distinct behaviours: > > unicode(obj) > > is analogous to str(obj), and it attempts to convert obj to a unicode > string by calling obj.__unicode__, if it exists, or __str__ if it > doesn't. No encoding or decoding is attempted in the event that obj is a > unicode instance. > > unicode(obj, encoding, errors) > > is explicitly stated in the docs as decoding obj if EITHER of encoding or > errors is given, AND that obj must be either an 8-bit string (bytes) or a > buffer object. > > It is true that u''.decode() will succeed, in Python 2, but the fact that > unicode objects have a decode method at all is IMO a bug. It has also I believe that is because in Py 2, codecs and .encode/.decode were used for same type recoding like base64, uu coding. That was simplified in Py3 so that 'decoding' is bytes to string and 'encoding' is string to bytes, and base64, etc, are only done in their separate modules and not also duplicated in the codecs machinery. > been corrected in Python 3, where (unicode) str objects no longer have a > decode method, and bytes objects no longer have an encode method. > > >>> The Python documentation >>> ("http://docs.python.org/library/functions.html#unicode") does not >>> mention this. > > Yes it does. It is is the SECOND sentence, immediately after the summary > line: > > unicode([object[, encoding[, errors]]]) > Return the Unicode string version of object using one of the > following modes: > > If encoding and/or errors are given, unicode() will decode the object > which can either be an 8-bit string or a character buffer using the > codec for encoding. ... > > > Admittedly, it doesn't *explicitly* state that TypeError will be raised, > but what other exception kind would you expect when you supply an > argument of the wrong type? What you have correctly pointed out is that there is no discrepancy between doc and behavior and hence no bug for the purpose of the tracker. Thanks. >>> It is therefore necessary to check the type before >>> calling "unicode", or catch the undocumented TypeError exception >>> afterward. >> >> Yes, this check should not be necessary; calling the ?unicode? >> constructor with an object that's already an instance of ?unicode? >> should just return the object as-is, IMO. It shouldn't matter that >> you've specified how decoding errors are to be handled, because in that >> case no decoding happens anyway. > > I don't believe that it is the job of unicode() to Do What I Mean, but > only to Do What I Say. If I *explicitly* tell unicode() to decode the > argument (by specifying either the codec or the error handler or both) > then it should not double-guess me and ignore the extra parameters. > > End-user applications may, with care, try to be smart and DWIM, but > library functions should be dumb and should do what they are told. -- Terry Jan Reedy From tjreedy at udel.edu Wed Mar 7 19:10:25 2012 From: tjreedy at udel.edu (Terry Reedy) Date: Wed, 07 Mar 2012 19:10:25 -0500 Subject: sys.stdout.detach() results in ValueError In-Reply-To: References: Message-ID: On 3/7/2012 5:35 PM, Peter Kleiweg wrote: > Dave Angel schreef op de 7e dag van de lentemaand van het jaar 2012: > >> On 03/07/2012 02:41 PM, Peter Kleiweg wrote: >>> I want to write out some binary data to stdout in Python3. I >>> thought the way to do this was to call detach on sys.stdout. But >>> apparently, you can't. Here is a minimal script: >>> >>> #!/usr/bin/env python3.1 >>> import sys >>> fp = sys.stdout.detach() >>> >>> Not yet using fp in any way, this script gives the following error: >>> >>> Exception ValueError: 'underlying buffer has been detached' in >>> >>> Same in Python 3.1.4 and Python 3.2.2 >>> >>> So, what do I do if I want to send binary data to stdout? >>> >>> >>> >> >> sys.stdout.write( some_binary_data ) > > TypeError: must be str, not bytes Right, you can only send binary data to file opened in binary mode. The default sys.stdout is in text mode. I am pretty sure that remains true even if stdout is redirected. (You did not mention your OS.) You would have to open such a file and make sys.stdout point to it. sys.stdout = my_binary_file. But why do that? Just open the file and write to it directly without the above. -- Terry Jan Reedy From tjreedy at udel.edu Wed Mar 7 19:12:59 2012 From: tjreedy at udel.edu (Terry Reedy) Date: Wed, 07 Mar 2012 19:12:59 -0500 Subject: what is best method to set sys.stdout to utf-8? In-Reply-To: References: Message-ID: On 3/7/2012 3:57 PM, Peter Kleiweg wrote: > > In Python 3, there seem to be two ways to set sys.stdout to > utf-8 after the script has started: > > sys.stdout = codecs.getwriter('utf-8')(sys.stdout.detach()) > > sys.stdout = io.TextIOWrapper(sys.stdout.detach(), encoding='utf-8') > > I guess the second is better. At start-up, type(sys.stdout) is > , and it's also after using the > second method. > > After using the first method, type(sys.stdout) is changed to > . > > Should I always use the second method? I would. The io module is more recent an partly replaces codecs. The latter remains for back compatibility and whatever it can do that io cannot. -- Terry Jan Reedy From gelonida at gmail.com Wed Mar 7 19:16:33 2012 From: gelonida at gmail.com (Gelonida N) Date: Thu, 08 Mar 2012 01:16:33 +0100 Subject: pickle/unpickle class which has changed In-Reply-To: References: Message-ID: On 03/07/2012 09:04 AM, Peter Otten wrote: > Gelonida N wrote: > If you know in advance that your class will undergo significant changes you > may also consider storing more stable data in a file format that can easily > be modified, e. g. json. > Good point, that's what I'm partially doing. I just wondered whether there were already some kind of pre-existing data migration tools / concepts / helpers like for example south for Django or whether I had to roll my own migration scheme for persistent non DB data. From metolone at gmail.com Wed Mar 7 19:41:36 2012 From: metolone at gmail.com (Mark Tolonen) Date: Wed, 7 Mar 2012 16:41:36 -0800 (PST) Subject: sys.stdout.detach() results in ValueError References: Message-ID: <483e3ddf-6452-411c-a9c2-5e9318a1a34e@d7g2000pbl.googlegroups.com> On Mar 7, 4:10?pm, Terry Reedy wrote: > On 3/7/2012 5:35 PM, Peter Kleiweg wrote: > > > > > > > > > > > Dave Angel schreef op de 7e dag van de lentemaand van het jaar 2012: > > >> On 03/07/2012 02:41 PM, Peter Kleiweg wrote: > >>> I want to write out some binary data to stdout in Python3. I > >>> thought the way to do this was to call detach on sys.stdout. But > >>> apparently, you can't. Here is a minimal script: > > >>> ? ? ? #!/usr/bin/env python3.1 > >>> ? ? ? import sys > >>> ? ? ? fp = sys.stdout.detach() > > >>> Not yet using fp in any way, this script gives the following error: > > >>> ? ? ? Exception ValueError: 'underlying buffer has been detached' in > > >>> Same in Python 3.1.4 and Python 3.2.2 > > >>> So, what do I do if I want to send binary data to stdout? > > >> sys.stdout.write( ?some_binary_data ) > > > TypeError: must be str, not bytes > > Right, you can only send binary data to file opened in binary mode. The > default sys.stdout is in text mode. I am pretty sure that remains true > even if stdout is redirected. (You did not mention your OS.) You would > have to open such a file and make sys.stdout point to it. > sys.stdout = my_binary_file. > But why do that? Just open the file and write to it directly without the > above. > > -- > Terry Jan Reedy Write binary data to sys.stdout.buffer. -Mark From skippy.hammond at gmail.com Wed Mar 7 20:35:52 2012 From: skippy.hammond at gmail.com (Mark Hammond) Date: Thu, 08 Mar 2012 12:35:52 +1100 Subject: Python 3.2 and MS Outlook In-Reply-To: References: Message-ID: <4F580CF8.2030500@gmail.com> On Thursday, 8 March 2012 1:52:48 AM, Greg Lindstrom wrote: > Is there documentation showing how to read from a Microsoft Outlook > server using Python 3.2. I've done it with 2.x, but can't find > anything to help me with 3.2. What problems are you having in 3.2? It should be exactly the same - except, obviously, for the general differences between 2 and 3 (ie, any differences should not be due to needing to talk to Outlook and would exist regardless of the job at hand) Mark From ben+python at benfinney.id.au Wed Mar 7 21:18:14 2012 From: ben+python at benfinney.id.au (Ben Finney) Date: Thu, 08 Mar 2012 13:18:14 +1100 Subject: "Decoding unicode is not supported" in unusual situation References: <4f571b94$0$12037$742ec2ed@news.sonic.net> <8762egmzfp.fsf@benfinney.id.au> <4f5749bc$0$29989$c3e8da3$5496439d@news.astraweb.com> <4f57b63f$0$11986$742ec2ed@news.sonic.net> <871up4m69h.fsf@benfinney.id.au> <4f57eeac$0$29989$c3e8da3$5496439d@news.astraweb.com> Message-ID: <87sjhjltsp.fsf@benfinney.id.au> Steven D'Aprano writes: > On Thu, 08 Mar 2012 08:48:58 +1100, Ben Finney wrote: > > I think that's a Python bug. If the latter succeeds as a no-op, the > > former should also succeed as a no-op. Neither should ever get any > > errors when ?s? is a ?unicode? object already. > > No. The semantics of the unicode function (technically: a type > constructor) are well-defined, and there are two distinct behaviours: That is documented, right. Thanks for drawing my attention to it. > > Yes, this check should not be necessary; calling the ?unicode? > > constructor with an object that's already an instance of ?unicode? > > should just return the object as-is, IMO. It shouldn't matter that > > you've specified how decoding errors are to be handled, because in > > that case no decoding happens anyway. > > I don't believe that it is the job of unicode() to Do What I Mean, but > only to Do What I Say. If I *explicitly* tell unicode() to decode the > argument (by specifying either the codec or the error handler or both) That's where I disagree. Specifying what to do in the case of decoding errors is *not* explicitly requesting to decode. The decision of whether to decode is up to the object, not the caller. Specifying an error handler *in case* decoding errors happen is not the same as specifying that decoding must happen. In other words: I think specifying an encoding is saying ?decode this?, but I don't think the same is true of specifying an error handler. > End-user applications may, with care, try to be smart and DWIM, but > library functions should be dumb and should do what they are told. Agreed, and I think this is compatible with my position. -- \ ?Creativity can be a social contribution, but only in so far as | `\ society is free to use the results.? ?Richard M. Stallman | _o__) | Ben Finney From kreena567 at gmail.com Wed Mar 7 22:27:37 2012 From: kreena567 at gmail.com (reena k) Date: Wed, 7 Mar 2012 19:27:37 -0800 (PST) Subject: PPC Form Filling Jobs Message-ID: <041298d0-a500-448c-a2e8-afe1df6df962@s10g2000pbo.googlegroups.com> http://internetjobs4u.weebly.com From benjamin at python.org Wed Mar 7 22:49:25 2012 From: benjamin at python.org (Benjamin Peterson) Date: Thu, 8 Mar 2012 03:49:25 +0000 (UTC) Subject: sys.stdout.detach() results in ValueError References: Message-ID: Peter Kleiweg xs4all.nl> writes: > Not yet using fp in any way, this script gives the following error: > > Exception ValueError: 'underlying buffer has been detached' in You're probably using print() or some such which tries to write to sys.stdout. It's safest to just write to sys.stdout.buffer rather than using detach. From rustompmody at gmail.com Wed Mar 7 23:13:36 2012 From: rustompmody at gmail.com (rusi) Date: Wed, 7 Mar 2012 20:13:36 -0800 (PST) Subject: BitSet &Redis References: <399c9d09-8e20-4db6-8f5b-bc7f3e683329@k24g2000yqe.googlegroups.com> Message-ID: <0561f35c-d95e-4ed7-a11a-896afc3808c2@gj7g2000pbc.googlegroups.com> On Mar 8, 3:02?am, Christian wrote: > I play around with redis. Isn't it ?possible to handle BitSet with > Python "as" in Java? > > BitSet users = BitSet.valueOf(redis.get(key.getBytes())); > all.or(users); > System.out.println(all.cardinality()) > > I try something with the struct and bitstring libs , but haven't any > success. Even the follow snippet didn't work, beacause > bitset[0] isn't approriate. > > bitset = r.get('bytestringFromRedis') > x = ?"{0:b}".format(ord(bitset[0])) > > Thanks in advance > Christian Redis I dont know. As for bitset, sets in python should give you whatever bitset in java does See http://docs.python.org/library/sets.html From rosuav at gmail.com Thu Mar 8 00:03:34 2012 From: rosuav at gmail.com (Chris Angelico) Date: Thu, 8 Mar 2012 16:03:34 +1100 Subject: What's the best way to write this regular expression? In-Reply-To: References: <12783654.1174.1331073814011.JavaMail.geo-discussion-forums@yner4> Message-ID: On Thu, Mar 8, 2012 at 7:39 AM, John Salerno wrote: > it only > seemed to support Python 2.7. I'm using 3.2. Is 2.7 just the minimum > version it requires? It didn't say something like "2.7+", so I wasn't > sure, and I don't want to start installing a bunch of stuff that will > clog up my directories and not even work. Just to clarify: Python 2 and Python 3 are quite different. If something requires Python 2.7, you cannot assume that it will work with Python 3.2; anything that supports both branches will usually list the minimum version of each (eg "2.7 or 3.3"). ChrisA From nad at acm.org Thu Mar 8 00:47:37 2012 From: nad at acm.org (Ned Deily) Date: Wed, 07 Mar 2012 21:47:37 -0800 Subject: Python site-packages permission denied? References: <5849344.1361.1331154163099.JavaMail.geo-discussion-forums@pbls8> Message-ID: In article , Chris Rebert wrote: > You generally shouldn't mess with Mac OS X's system copies of Python. > Typically, one installs a separate copy using MacPorts, Fink, or > whatever, and uses that instead. I don't understand what you mean by "mess with". Certainly one should not attempt alter standard library modules provided with the system Python but adding additional packages is fully supported. Apple conveniently provides a special directory in user-controlled space (/Library/Python) as the default location for Distutils-based installs. They even provide versions of easy_install for the system Pythons. -- Ned Deily, nad at acm.org From shane.neeley at gmail.com Thu Mar 8 01:07:51 2012 From: shane.neeley at gmail.com (Shane Neeley) Date: Wed, 7 Mar 2012 22:07:51 -0800 (PST) Subject: Help with MultipartPostHandler Message-ID: <1270164.221.1331186871710.JavaMail.geo-discussion-forums@pbjv6> Hi Python Google Group! I hope someone could help me and then one day when I am good I can contribute to the forum as well. Does anyone know what is wrong with my syntax here as I am trying to submit this form using MultipartPostHandler that I installed? import MultipartPostHandler, urllib2 params = { 'Run_Number' : 'NONE', 'MAX_FILE_SIZE' : '2000000', 'submitForm' : 'Submit' } opener.open("http://consurf.tau.ac.il/index_full_form_PROT.php", params) From timr at probo.com Thu Mar 8 01:11:45 2012 From: timr at probo.com (Tim Roberts) Date: Wed, 07 Mar 2012 22:11:45 -0800 Subject: Biologist new to cgi in python References: <28641624.970.1331139509579.JavaMail.geo-discussion-forums@pbcgw3> Message-ID: Shane Neeley wrote: > >Here is the function I am using to insert the variable file text inside the >url. Is it even possible to include the upload command in the url? No. You are trying to simulate a "GET" request, but files can only be uploaded via a "POST" request of type multiport/form-data. There is a module called "poster" that can do the appropriate encoding for you: http://stackoverflow.com/questions/680305/using-multipartposthandler-to-post-form-data-with-python -- Tim Roberts, timr at probo.com Providenza & Boekelheide, Inc. From bugzilla-mail-box at yandex.ru Thu Mar 8 01:14:21 2012 From: bugzilla-mail-box at yandex.ru (bugzilla-mail-box at yandex.ru) Date: Thu, 08 Mar 2012 16:14:21 +1000 Subject: Get tkinter text to the clipboard Message-ID: <38861331187261@web143.yandex.ru> > How about > > import tkinter > root = tkinter.Tk() > > root.clipboard_clear() > root.clipboard_append("whatever") > that works, thank you From moky.math at gmail.com Thu Mar 8 01:45:32 2012 From: moky.math at gmail.com (Laurent Claessens) Date: Thu, 08 Mar 2012 07:45:32 +0100 Subject: what is best method to set sys.stdout to utf-8? In-Reply-To: References: Message-ID: <4F58558C.3000706@gmail.com> > I would. The io module is more recent an partly replaces codecs. The > latter remains for back compatibility and whatever it can do that io cannot. I've a naive question : what is wrong with the following system ? class MyStdOut(object): def __init__(self): self.old_stdout=sys.stdout def write(self,x): try: if isinstance(x,unicode): x=x.encode("utf8") except (UnicodeEncodeError,UnicodeDecodeError): sys.stderr.write("This should not happen !") raise self.old_stdout.write(x) sys.stdout=MyStdOut() ... well ... a part of the fact that it is much longer ? Laurent Claessens From moky.math at gmail.com Thu Mar 8 01:45:32 2012 From: moky.math at gmail.com (Laurent Claessens) Date: Thu, 08 Mar 2012 07:45:32 +0100 Subject: what is best method to set sys.stdout to utf-8? In-Reply-To: References: Message-ID: <4F58558C.3000706@gmail.com> > I would. The io module is more recent an partly replaces codecs. The > latter remains for back compatibility and whatever it can do that io cannot. I've a naive question : what is wrong with the following system ? class MyStdOut(object): def __init__(self): self.old_stdout=sys.stdout def write(self,x): try: if isinstance(x,unicode): x=x.encode("utf8") except (UnicodeEncodeError,UnicodeDecodeError): sys.stderr.write("This should not happen !") raise self.old_stdout.write(x) sys.stdout=MyStdOut() ... well ... a part of the fact that it is much longer ? Laurent Claessens From johnjsal at gmail.com Thu Mar 8 02:25:18 2012 From: johnjsal at gmail.com (John Salerno) Date: Wed, 7 Mar 2012 23:25:18 -0800 (PST) Subject: What's the best way to write this regular expression? References: <12783654.1174.1331073814011.JavaMail.geo-discussion-forums@yner4> Message-ID: <6497ecaf-c165-40be-9d6c-3c8fa6963861@p13g2000yqd.googlegroups.com> On Mar 7, 11:03?pm, Chris Angelico wrote: > On Thu, Mar 8, 2012 at 7:39 AM, John Salerno wrote: > > it only > > seemed to support Python 2.7. I'm using 3.2. Is 2.7 just the minimum > > version it requires? It didn't say something like "2.7+", so I wasn't > > sure, and I don't want to start installing a bunch of stuff that will > > clog up my directories and not even work. > > Just to clarify: Python 2 and Python 3 are quite different. If > something requires Python 2.7, you cannot assume that it will work > with Python 3.2; anything that supports both branches will usually > list the minimum version of each (eg "2.7 or 3.3"). > > ChrisA That's why I asked first, because I got the feeling it did NOT support Python 3 :) From johnjsal at gmail.com Thu Mar 8 02:26:28 2012 From: johnjsal at gmail.com (John Salerno) Date: Wed, 7 Mar 2012 23:26:28 -0800 (PST) Subject: What's the best way to write this regular expression? References: <12783654.1174.1331073814011.JavaMail.geo-discussion-forums@yner4> <5B80DD153D7D744689F57F4FB69AF47419567C@SCACMX008.exchad.jpmchase.net> Message-ID: <7d80b224-8f51-48c7-8224-6323e282a13e@x17g2000yqj.googlegroups.com> On Mar 7, 4:02?pm, Evan Driscoll wrote: > On 01/-10/-28163 01:59 PM, Prasad, Ramit wrote: > > > gz stands for gzip and is a form of compression (like rar/zip ). > > tar stands for a tape archive. It is basically a box that holds the > > files. So you need to "unzip" and then "open the box". > > > Normally programs like WinZip / WinRar / 7-zip will do both in one step > > so you do not need to. Not sure what program you are using... > > I'm not sure what 7-zip you're referring to, because I use 7-zip and > it's always been a two-step process for me... > > (Though I can't say I've looked through the preferences dialog for a > "extract .tar.gz files in one go" setting.) > > Evan Same here, because that's what I used. I looked through the settings but didn't see anything. What seems to happen is that 7-Zip recognizes the .gz extension and opens that automatically. But then that simply opens up another window with the .tar file in it, which you have to then open again. From riko at despammed.com Thu Mar 8 04:12:16 2012 From: riko at despammed.com (Enrico Franchi) Date: Thu, 8 Mar 2012 10:12:16 +0100 Subject: Python recursive tree, linked list thingy References: Message-ID: <1kgmufu.fmcyhya6u0awN%riko@despammed.com> Wanderer wrote: > How > do you handle this sort of thing in Python? I believe that the best thing to do is a Union-Find algorithm. Depending on the exact nature of your problem, you may also want to check out the Hoshen-Kopelman Algorithm. Although the algorithm itself is rather efficient, it was born in the context of percolation, that is to say with the assumption that the "broken" (or colored) cells are much more likely than in your context. -- -riko http://www.enrico-franchi.org/ http://rik0-techtemple.blogspot.com/ From robert.kern at gmail.com Thu Mar 8 05:40:08 2012 From: robert.kern at gmail.com (Robert Kern) Date: Thu, 08 Mar 2012 10:40:08 +0000 Subject: Python recursive tree, linked list thingy In-Reply-To: <1kgmufu.fmcyhya6u0awN%riko@despammed.com> References: <1kgmufu.fmcyhya6u0awN%riko@despammed.com> Message-ID: On 3/8/12 9:12 AM, Enrico Franchi wrote: > Wanderer wrote: > >> How >> do you handle this sort of thing in Python? > > I believe that the best thing to do is a Union-Find algorithm. Another term this problem is finding the "connected components". Here is some code from Stefan van der Walt for this: http://mentat.za.net/source/connected_components.tar.bz2 http://mentat.za.net/cgi-bin/hgwebdir.cgi/ccomp -- Robert Kern "I have come to believe that the whole world is an enigma, a harmless enigma that is made terrible by our own mad attempt to interpret it as though it had an underlying truth." -- Umberto Eco From steve+comp.lang.python at pearwood.info Thu Mar 8 06:34:39 2012 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 08 Mar 2012 11:34:39 GMT Subject: Python site-packages permission denied? References: <5849344.1361.1331154163099.JavaMail.geo-discussion-forums@pbls8> Message-ID: <4f58994f$0$29989$c3e8da3$5496439d@news.astraweb.com> On Wed, 07 Mar 2012 21:47:37 -0800, Ned Deily wrote: > In article > , > Chris Rebert wrote: >> You generally shouldn't mess with Mac OS X's system copies of Python. >> Typically, one installs a separate copy using MacPorts, Fink, or >> whatever, and uses that instead. > > I don't understand what you mean by "mess with". Certainly one should > not attempt alter standard library modules provided with the system > Python but adding additional packages is fully supported. I read Chris as making a general comment that one should be cautious about making changes to the system copy of Python, advice that holds for all OSes not just OS-X. > Apple > conveniently provides a special directory in user-controlled space > (/Library/Python) as the default location for Distutils-based installs. > They even provide versions of easy_install for the system Pythons. Perhaps so, but it seems to have the permissions messed up, or some other problem, because the OP can't write to it. His error is: copying build/lib/urllib2_file.py -> /Library/Python/2.7/site-packages error: /Library/Python/2.7/site-packages/urllib2_file.py: Permission denied I note also that Chris' final comment was: "In any case, you generally need to `sudo` when installing stuff system- wide." which is probably the solution the OP is looking for. -- Steven From ran.hrl at gmail.com Thu Mar 8 06:42:44 2012 From: ran.hrl at gmail.com (Ran Harel) Date: Thu, 8 Mar 2012 13:42:44 +0200 Subject: Memory leak involving traceback objects Message-ID: I have the same problem with python 2.6.2. I have upgraded to 2.7.1 and the leak is gone. -------------- next part -------------- An HTML attachment was scrubbed... URL: From ndbecker2 at gmail.com Thu Mar 8 09:23:26 2012 From: ndbecker2 at gmail.com (Neal Becker) Date: Thu, 08 Mar 2012 09:23:26 -0500 Subject: cython + scons + c++ Message-ID: Is there a version of cython.py, pyext.py that will work with c++? I asked this question some time ago, but never got an answer. I tried the following code, but it doesn't work correctly. If the commented lines are uncommented, the gcc command is totally mangled. Although it did build my 1 test extension OK, I didn't use any libstdc++ - I suspect it won't link correctly in general because it doesn't seem to treat the code as c++ (treats it as c code). cyenv = Environment(PYEXT_USE_DISTUTILS=True) cyenv.Tool("pyext") cyenv.Tool("cython") import numpy cyenv.Append(PYEXTINCPATH=[numpy.get_include()]) cyenv.Replace(CYTHONFLAGS=['--cplus']) #cyenv.Replace(CXXFILESUFFIX='.cpp') #cyenv.Replace(CYTHONCFILESUFFIX='.cpp') From stefan_ml at behnel.de Thu Mar 8 09:59:38 2012 From: stefan_ml at behnel.de (Stefan Behnel) Date: Thu, 08 Mar 2012 15:59:38 +0100 Subject: cython + scons + c++ In-Reply-To: References: Message-ID: Neal Becker, 08.03.2012 15:23: > Is there a version of cython.py, pyext.py that will work with c++? > > I asked this question some time ago, but never got an answer. > > I tried the following code, but it doesn't work correctly. If the commented > lines are uncommented, the gcc command is totally mangled. > > Although it did build my 1 test extension OK, I didn't use any libstdc++ - I > suspect it won't link correctly in general because it doesn't seem to treat the > code as c++ (treats it as c code). > > cyenv = Environment(PYEXT_USE_DISTUTILS=True) > cyenv.Tool("pyext") > cyenv.Tool("cython") > import numpy > > cyenv.Append(PYEXTINCPATH=[numpy.get_include()]) > cyenv.Replace(CYTHONFLAGS=['--cplus']) > #cyenv.Replace(CXXFILESUFFIX='.cpp') > #cyenv.Replace(CYTHONCFILESUFFIX='.cpp') I don't use Scons, so I don't know if running the compiler at a command line level is the best way to do it in that build system. But I know that some people on the Cython users mailing list use it, so you may want to ask over there. https://groups.google.com/group/cython-users Stefan From hyperboogie at gmail.com Thu Mar 8 10:25:06 2012 From: hyperboogie at gmail.com (hyperboogie) Date: Thu, 8 Mar 2012 07:25:06 -0800 (PST) Subject: newb __init__ inheritance Message-ID: <1c6db866-6fa3-4de5-96de-51d6720a1300@x17g2000yqj.googlegroups.com> Hello everyone. This is my first post in this group. I started learning python a week ago from the "dive into python" e- book and thus far all was clear. However today while reading chapter 5 about objects and object orientation I ran into something that confused me. it says here: http://www.diveintopython.net/object_oriented_framework/defining_classes.html#fileinfo.class.example "__init__ methods are optional, but when you define one, you must remember to explicitly call the ancestor's __init__ method (if it defines one). This is more generally true: whenever a descendant wants to extend the behavior of the ancestor, the descendant method must explicitly call the ancestor method at the proper time, with the proper arguments. " However later on in the chapter: http://www.diveintopython.net/object_oriented_framework/userdict.html it says: "Methods are defined solely by their name, and there can be only one method per class with a given name. So if a descendant class has an __init__ method, it always overrides the ancestor __init__ method, even if the descendant defines it with a different argument list. And the same rule applies to any other method. " My question is if __init__ in the descendant class overrides __init__ in the parent class how can I call the parent's __init__ from the descendant class - I just overrode it didn't I? Am I missing something more fundamental here? Thanks From awilliam at whitemice.org Thu Mar 8 10:44:15 2012 From: awilliam at whitemice.org (Adam Tauno Williams) Date: Thu, 08 Mar 2012 10:44:15 -0500 Subject: Can't get around HTTP/401 response using SUDS Message-ID: <1331221455.3087.14.camel@linux-dauq.site> SUDS version 0.4 pn x86_64 Python 2.7 I'm having a bear of a time getting HTTP Basic Authentication to work for a SOAP request via suds. Also using an HTTP proxy server. In WireShark I just see a request - GET http://...../services/services/JobService-0.0.1?wsdl HTTP/1.1 Accept-Encoding: identity Host: ....... Connection: close User-Agent: Python-urllib/2.7 This doesn't contain any authentication credentials so the response is HTTP/401, and the client doesn't retry with credentials. The response does come from the remote as I can see there is a WWW-Authenticate header and it is from an Apache Tomcat server - so it makes it through the proxy server. Code ================ url = 'http://....../services/services/JobService-0.0.1?wsdl' proxy = urllib2.ProxyHandler({'http': 'http://.....:3128'}) transport = suds.transport.http.HttpAuthenticated() transport.urlopener = urllib2.build_opener(proxy) client = suds.client.Client(url, transport=transport, username='******', password='********') .... I've tried the above as well as the method described at It has the same problem. Back Trace ================ Traceback (most recent call last): File "etrace.py", line 30, in client = suds.client.Client(url, transport=transport, username='*******', password='*****') File "/usr/local/lib/python2.7/site-packages/suds-0.4-py2.7.egg/suds/client.py", line 112, in __init__ self.wsdl = reader.open(url) File "/usr/local/lib/python2.7/site-packages/suds-0.4-py2.7.egg/suds/reader.py", line 152, in open d = self.fn(url, self.options) File "/usr/local/lib/python2.7/site-packages/suds-0.4-py2.7.egg/suds/wsdl.py", line 136, in __init__ d = reader.open(url) File "/usr/local/lib/python2.7/site-packages/suds-0.4-py2.7.egg/suds/reader.py", line 79, in open d = self.download(url) File "/usr/local/lib/python2.7/site-packages/suds-0.4-py2.7.egg/suds/reader.py", line 95, in download fp = self.options.transport.open(Request(url)) File "/usr/local/lib/python2.7/site-packages/suds-0.4-py2.7.egg/suds/transport/http.py", line 173, in open return HttpTransport.open(self, request) File "/usr/local/lib/python2.7/site-packages/suds-0.4-py2.7.egg/suds/transport/http.py", line 64, in open raise TransportError(str(e), e.code, e.fp) suds.transport.TransportError: HTTP Error 401: Unauthorized -- System & Network Administrator [ LPI & NCLA ] OpenGroupware Developer Adam Tauno Williams From d at davea.name Thu Mar 8 10:44:58 2012 From: d at davea.name (Dave Angel) Date: Thu, 08 Mar 2012 10:44:58 -0500 Subject: cython + scons + c++ In-Reply-To: References: Message-ID: <4F58D3FA.3030401@davea.name> On 03/08/2012 09:23 AM, Neal Becker wrote: > Is there a version of cython.py, pyext.py that will work with c++? > > I asked this question some time ago, but never got an answer. > > I tried the following code, but it doesn't work correctly. If the commented > lines are uncommented, the gcc command is totally mangled. > > Although it did build my 1 test extension OK, I didn't use any libstdc++ - I > suspect it won't link correctly in general because it doesn't seem to treat the > code as c++ (treats it as c code). > > cyenv = Environment(PYEXT_USE_DISTUTILS=True) > cyenv.Tool("pyext") > cyenv.Tool("cython") > import numpy > > cyenv.Append(PYEXTINCPATH=[numpy.get_include()]) > cyenv.Replace(CYTHONFLAGS=['--cplus']) > #cyenv.Replace(CXXFILESUFFIX='.cpp') > #cyenv.Replace(CYTHONCFILESUFFIX='.cpp') > > I don't know anything about writing c/c++ code with Python. I have plenty of experience with each, but not together. But the usual C++ answer is to use an extern "C" declaration for any function you need to be visible to the outside world. It prevents the usual C++ name mangling. (It therefore also prevents function overloading and can't generally be used on class member functions) -- DaveA From wanderer at dialup4less.com Thu Mar 8 11:12:56 2012 From: wanderer at dialup4less.com (Wanderer) Date: Thu, 8 Mar 2012 08:12:56 -0800 (PST) Subject: Python recursive tree, linked list thingy References: Message-ID: <72acc0ba-49f3-49a2-abad-3bacaa015586@n9g2000pbb.googlegroups.com> On Mar 7, 3:27?pm, Ian Kelly wrote: > On Wed, Mar 7, 2012 at 1:03 PM, Ian Kelly wrote: > > A set of defective pixels would be the probable choice, since it > > offers efficient membership testing. > > Some actual code, using a recursive generator: > > def get_cluster(defective, pixel): > ? ? yield pixel > ? ? (row, column) = pixel > ? ? for adjacent in [(row - 1, column), (row, column - 1), > ? ? ? ? ? ? ? ? ? ? ?(row, column + 1), (row + 1, column)]: > ? ? ? ? if adjacent in defective: > ? ? ? ? ? ? defective.remove(adjacent) > ? ? ? ? ? ? for cluster_pixel in get_cluster(defective, adjacent): > ? ? ? ? ? ? ? ? yield cluster_pixel > > defective = {(327, 415), (180, 97), (326, 415), (42, 15), > ? ? ? ? ? ? ?(180, 98), (325, 414), (325, 415)} > clusters = [] > > while defective: > ? ? pixel = defective.pop() > ? ? clusters.append(list(get_cluster(defective, pixel))) > > from pprint import pprint > pprint(clusters) > > Cheers, > Ian This works for me and I can modify it to look for column defects also. It also shows I know less about Python then I thought I did. I had to read up on generators and iterators to understand the code. Thanks From maarten.sneep at knmi.nl Thu Mar 8 11:30:17 2012 From: maarten.sneep at knmi.nl (Maarten) Date: Thu, 8 Mar 2012 08:30:17 -0800 (PST) Subject: newb __init__ inheritance In-Reply-To: <1c6db866-6fa3-4de5-96de-51d6720a1300@x17g2000yqj.googlegroups.com> References: <1c6db866-6fa3-4de5-96de-51d6720a1300@x17g2000yqj.googlegroups.com> Message-ID: <13988849.1044.1331224217273.JavaMail.geo-discussion-forums@ynnk21> On Thursday, March 8, 2012 4:25:06 PM UTC+1, hyperboogie wrote: > My question is if __init__ in the descendant class overrides __init__ > in the parent class how can I call the parent's __init__ from the > descendant class - I just overrode it didn't I? > > Am I missing something more fundamental here? No, you're not. However, you can explicitly call the __init__() method of a particular class. Hard-coding the class gives you: class A(object): def __init__(self): print("In A") class B(A): def __init__(self): A.__init__(self) print("In B") Alternatively you can figure out the parent class with a call to super: class C(A): def __init__(self): super(self.__class__, self).__init__() print("In C") a = A() (prints "In A") b = B() (prints "In A", "In B" on two lines) c = C() (prints "In A", "In C" on two lines) Hope this helps. Maarten From __peter__ at web.de Thu Mar 8 12:03:25 2012 From: __peter__ at web.de (Peter Otten) Date: Thu, 08 Mar 2012 18:03:25 +0100 Subject: newb __init__ inheritance References: <1c6db866-6fa3-4de5-96de-51d6720a1300@x17g2000yqj.googlegroups.com> <13988849.1044.1331224217273.JavaMail.geo-discussion-forums@ynnk21> Message-ID: Maarten wrote: > Alternatively you can figure out the parent class with a call to super: This is WRONG: > super(self.__class__, self).__init__() You have to name the current class explicitly. Consider: >> class A(object): ... def __init__(self): ... print "in a" ... >>> class B(A): ... def __init__(self): ... print "in b" ... super(self.__class__, self).__init__() # wrong ... >>> class C(B): pass ... >>> Can you figure out what C() will print? Try it out if you can't. The corrected code: >>> class B(A): ... def __init__(self): ... print "in b" ... super(B, self).__init__() ... >>> class C(B): pass ... >>> C() in b in a <__main__.C object at 0x7fcfafd52b10> In Python 3 you can call super() with no args; super().__init__() do the right thing there. From ethan at stoneleaf.us Thu Mar 8 12:34:20 2012 From: ethan at stoneleaf.us (Ethan Furman) Date: Thu, 08 Mar 2012 09:34:20 -0800 Subject: newb __init__ inheritance In-Reply-To: <1c6db866-6fa3-4de5-96de-51d6720a1300@x17g2000yqj.googlegroups.com> References: <1c6db866-6fa3-4de5-96de-51d6720a1300@x17g2000yqj.googlegroups.com> Message-ID: <4F58ED9C.2010603@stoneleaf.us> hyperboogie wrote: > Hello everyone. > > This is my first post in this group. > I started learning python a week ago from the "dive into python" e- > book and thus far all was clear. > However today while reading chapter 5 about objects and object > orientation I ran into something that confused me. > it says here: > http://www.diveintopython.net/object_oriented_framework/defining_classes.html#fileinfo.class.example > > "__init__ methods are optional, but when you define one, you must > remember to explicitly call the ancestor's __init__ method (if it > defines one). This is more generally true: whenever a descendant wants > to extend the behavior of the ancestor, the descendant method must > explicitly call the ancestor method at the proper time, with the > proper arguments. " > > However later on in the chapter: > http://www.diveintopython.net/object_oriented_framework/userdict.html > > it says: > "Methods are defined solely by their name, and there can be only one > method per class with a given name. So if a descendant class has an > __init__ method, it always overrides the ancestor __init__ method, > even if the descendant defines it with a different argument list. And > the same rule applies to any other method. " > > My question is if __init__ in the descendant class overrides __init__ > in the parent class how can I call the parent's __init__ from the > descendant class - I just overrode it didn't I? > > Am I missing something more fundamental here? > Thanks An excellent question. What you subclass you are creating a new, different class. class A(object): def __init__(self): print("this is class A's __init__") def method1(self, value): print(value) class B(A): def __init__(self): print("this is class B's __init__") test = B() test.method1('42') When it says that the subclass overrides methods of the same name, it means that if it finds the method in the subclass, it will stop looking and use the one it found. So in the example above when Python creates test it will find __init__ in B and so won't bother looking in A for it. However, when looking for 'method1' Python does not find it in B, and so looks in A for it and, finding it there, uses that as B's method1. If you want B's __init__ to also call A's __init__, you have to so explicity: def __init__(self): A.__init__(self) or def __init__(self): super(B, self).__init__() or with Python 3 def __init__(self): super().__init__() ~Ethan~ From awilliam at whitemice.org Thu Mar 8 13:21:42 2012 From: awilliam at whitemice.org (Adam Tauno Williams) Date: Thu, 08 Mar 2012 13:21:42 -0500 Subject: GUI components in python In-Reply-To: References: Message-ID: <1331230902.3087.22.camel@linux-dauq.site> On Wed, 2012-03-07 at 19:14 +0530, janaki rajamani wrote: > I am stuck with the brain workshop software implemented using python. > The code involves a lot of GUI elements and i am familar only with the > basic python programming. > I would like to know whether there are built in classes to support GUI > elements or arethey project dependant. There are wrappers for various GUI toolkits/technologies such as PyGTK for using Gtk in Python. These wrappers often provide quite a bit of assistance and tools for working with that technology. You need to ask more specifically to get a more useful answer? -- System & Network Administrator [ LPI & NCLA ] OpenGroupware Developer Adam Tauno Williams -------------- next part -------------- A non-text attachment was scrubbed... Name: signature.asc Type: application/pgp-signature Size: 198 bytes Desc: This is a digitally signed message part URL: From ramit.prasad at jpmorgan.com Thu Mar 8 14:00:42 2012 From: ramit.prasad at jpmorgan.com (Prasad, Ramit) Date: Thu, 8 Mar 2012 19:00:42 +0000 Subject: GUI components in python In-Reply-To: <1331230902.3087.22.camel@linux-dauq.site> References: <1331230902.3087.22.camel@linux-dauq.site> Message-ID: <5B80DD153D7D744689F57F4FB69AF474196E66@SCACMX008.exchad.jpmchase.net> > > I am stuck with the brain workshop software implemented using python. > > The code involves a lot of GUI elements and i am familar only with the > > basic python programming. > > I would like to know whether there are built in classes to support GUI > > elements or arethey project dependant. > > There are wrappers for various GUI toolkits/technologies such as PyGTK > for using Gtk in Python. These wrappers often provide quite a bit of > assistance and tools for working with that technology. > > You need to ask more specifically to get a more useful answer? The TKinter library ships with Python. So I guess that would be the "built-in" classes. Usually though the UI is project dependent and there are several frameworks depending on the features you want. This may help list some of the frameworks and help you choose: http://www.awaretek.com/toolkits.html Ramit Ramit Prasad | JPMorgan Chase Investment Bank | Currencies Technology 712 Main Street | Houston, TX 77002 work phone: 713 - 216 - 5423 -- This email is confidential and subject to important disclaimers and conditions including on offers for the purchase or sale of securities, accuracy and completeness of information, viruses, confidentiality, legal privilege, and legal entity disclaimers, available at http://www.jpmorgan.com/pages/disclosures/email. From franck at ditter.org Thu Mar 8 14:15:09 2012 From: franck at ditter.org (Franck Ditter) Date: Thu, 08 Mar 2012 20:15:09 +0100 Subject: Buffering in Wing and IDLE 3 References: Message-ID: In article , Ned Deily wrote: > http://www.activestate.com/activetcl/downloads GREAT ! It seems to work. At least, I can now get the ~ char in France from within IDLE. A big step for manking :-) Thanks folks, franck From johnjsal at gmail.com Thu Mar 8 16:33:17 2012 From: johnjsal at gmail.com (John Salerno) Date: Thu, 8 Mar 2012 13:33:17 -0800 (PST) Subject: What's the best way to write this regular expression? References: <12783654.1174.1331073814011.JavaMail.geo-discussion-forums@yner4> Message-ID: <03dd4256-0881-44e8-bb27-38f23ce66267@h20g2000yqd.googlegroups.com> Alright, I'm simply lost about how to install these modules. I extracted the folders from the .tar.gz files and then went into those folders in my command prompt. I typed: C:\Python32\python setup.py install and for a while something was happening (I was doing the lxml one) and then it stopped with an error that it couldn't find a file. So I have no idea. Next I installed the "distribute" module, which seemed to install okay. But now I don't understand how to use easy_install. Where do I call it from? What do I do with the .tar.gz files at this point? The instructions for lxml say to run this command: easy_install --allow-hosts=lxml.de,*.python.org lxml but WHERE do I run it? I tried it in the Python directory, and then further in the lxml site-packages directory, but it doesn't work. What do I do with it? Where do I put the .tar files? From johnjsal at gmail.com Thu Mar 8 16:40:18 2012 From: johnjsal at gmail.com (John Salerno) Date: Thu, 8 Mar 2012 13:40:18 -0800 (PST) Subject: What's the best way to write this regular expression? References: <12783654.1174.1331073814011.JavaMail.geo-discussion-forums@yner4> <03dd4256-0881-44e8-bb27-38f23ce66267@h20g2000yqd.googlegroups.com> Message-ID: <21519dbf-4097-4780-874d-41d76f6453e0@x17g2000yqj.googlegroups.com> On Mar 8, 3:33?pm, John Salerno wrote: > Alright, I'm simply lost about how to install these modules. I > extracted the folders from the .tar.gz files and then went into those > folders in my command prompt. I typed: > > C:\Python32\python setup.py install > > and for a while something was happening (I was doing the lxml one) and > then it stopped with an error that it couldn't find a file. So I have > no idea. > > Next I installed the "distribute" module, which seemed to install > okay. But now I don't understand how to use easy_install. Where do I > call it from? What do I do with the .tar.gz files at this point? The > instructions for lxml say to run this command: > > easy_install --allow-hosts=lxml.de,*.python.org lxml > > but WHERE do I run it? I tried it in the Python directory, and then > further in the lxml site-packages directory, but it doesn't work. What > do I do with it? Where do I put the .tar files? Well, after a bit of experimentation, I got it to run, but I seem to have run into the same error as when I used setup.py: http://i271.photobucket.com/albums/jj138/JohnJSal/lxml_error.png Now I have no idea what to do. From johnjsal at gmail.com Thu Mar 8 16:52:39 2012 From: johnjsal at gmail.com (John Salerno) Date: Thu, 8 Mar 2012 13:52:39 -0800 (PST) Subject: What's the best way to write this regular expression? References: <12783654.1174.1331073814011.JavaMail.geo-discussion-forums@yner4> <03dd4256-0881-44e8-bb27-38f23ce66267@h20g2000yqd.googlegroups.com> <21519dbf-4097-4780-874d-41d76f6453e0@x17g2000yqj.googlegroups.com> Message-ID: <75bf9c09-5d24-457f-94c0-96221f0553b2@h20g2000yqd.googlegroups.com> On Mar 8, 3:40?pm, John Salerno wrote: > Now I have no idea what to do. Hmph, I suppose I should have more patience. I realized that the easy_install for lxml only tried to install a binary version, which doesn't exist for the version it found (the latest, 2.3.3). I just had to look through the previous versions and find the one with a binary installation for Windows (2.3) and it was as simple as a single click to install! And the easy_install method did work for Beautiful Soup, so I should be all set now! From gordon at panix.com Thu Mar 8 16:54:46 2012 From: gordon at panix.com (John Gordon) Date: Thu, 8 Mar 2012 21:54:46 +0000 (UTC) Subject: What's the best way to write this regular expression? References: <12783654.1174.1331073814011.JavaMail.geo-discussion-forums@yner4> <03dd4256-0881-44e8-bb27-38f23ce66267@h20g2000yqd.googlegroups.com> <21519dbf-4097-4780-874d-41d76f6453e0@x17g2000yqj.googlegroups.com> Message-ID: In <21519dbf-4097-4780-874d-41d76f6453e0 at x17g2000yqj.googlegroups.com> John Salerno writes: > Well, after a bit of experimentation, I got it to run, but I seem to > have run into the same error as when I used setup.py: > http://i271.photobucket.com/albums/jj138/JohnJSal/lxml_error.png > Now I have no idea what to do. The first error on that screen is that "xslt-config" is not found as a command. Try a web search for "xslt-config not found", there seemed to be some helpful results. -- 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 toby at tobiah.org Thu Mar 8 16:55:06 2012 From: toby at tobiah.org (Tobiah) Date: Thu, 08 Mar 2012 13:55:06 -0800 Subject: Finding MIME type for a data stream Message-ID: <%U96r.32867$082.25394@newsfe04.iad> I'm pulling image data from a database blob, and serving it from a web2py app. I have to send the correct Content-Type header, so I need to detect the image type. Everything that I've found on the web so far, needs a file name on the disk, but I only have the data. It looks like the 'magic' package might be of use, but I can't find any documentation for it. Also, it seems like image/png works for other types of image data, while image/foo does not, yet I'm afraid that not every browser will play along as nicely. Thanks! Tobiah From d at davea.name Thu Mar 8 17:11:26 2012 From: d at davea.name (Dave Angel) Date: Thu, 08 Mar 2012 17:11:26 -0500 Subject: Finding MIME type for a data stream In-Reply-To: <%U96r.32867$082.25394@newsfe04.iad> References: <%U96r.32867$082.25394@newsfe04.iad> Message-ID: <4F592E8E.7080708@davea.name> On 03/08/2012 04:55 PM, Tobiah wrote: > I'm pulling image data from a database blob, and serving > it from a web2py app. I have to send the correct > Content-Type header, so I need to detect the image type. > > Everything that I've found on the web so far, needs a file > name on the disk, but I only have the data. > > It looks like the 'magic' package might be of use, but > I can't find any documentation for it. > > Also, it seems like image/png works for other types > of image data, while image/foo does not, yet I'm afraid > that not every browser will play along as nicely. > > Thanks! > > Tobiah First step, ask the authors of the database what format of data this blob is in. Failing that, write the same data locally as a binary file, and see what application can open it. Or if you're on a Linux system, run file on it. "file" can identify most data formats (not just images) just by looking at the data. That assumes, of course, that there's any consistency in the data coming out of the database. What happens if next time this blob is an Excel spreadsheet? -- DaveA From d at davea.name Thu Mar 8 17:19:57 2012 From: d at davea.name (Dave Angel) Date: Thu, 08 Mar 2012 17:19:57 -0500 Subject: What's the best way to write this regular expression? In-Reply-To: <21519dbf-4097-4780-874d-41d76f6453e0@x17g2000yqj.googlegroups.com> References: <12783654.1174.1331073814011.JavaMail.geo-discussion-forums@yner4> <03dd4256-0881-44e8-bb27-38f23ce66267@h20g2000yqd.googlegroups.com> <21519dbf-4097-4780-874d-41d76f6453e0@x17g2000yqj.googlegroups.com> Message-ID: <4F59308D.4000403@davea.name> On 03/08/2012 04:40 PM, John Salerno wrote: > > http://i271.photobucket.com/albums/jj138/JohnJSal/lxml_error.png > Nothing to do with Python, but you'd save us all a lot of space and bandwidth if you learned how to copy/paste from a Windows cmd window. If you're just doing it rarely, you can right click on the top bar to get a menu. I think you want "mark". Then you select the text you'd like to put in the clipboard. Alternatively, you can put the console in quick-edit mode (I think it's called, it's been a long time since I ran Windows). That's an option you set on one cmd window, and it sticks for future windows. In quick-edit, you just right-click-drag on the cmd window to select a rectangle of text. Then you can Ctrl-V to paste it into email, or into a text editor, or wherever else you need it. Hard to imagine not using this mode, or its Linux equivalent, which is always available. If that wasn't clear enough, or it doesn't work for you, somebody will explain it better. Or ask me, and I'll launch a VirtualBox with Windows to get you going. -- DaveA From nagle at animats.com Thu Mar 8 17:23:50 2012 From: nagle at animats.com (John Nagle) Date: Thu, 08 Mar 2012 14:23:50 -0800 Subject: "Decoding unicode is not supported" in unusual situation In-Reply-To: <87sjhjltsp.fsf@benfinney.id.au> References: <4f571b94$0$12037$742ec2ed@news.sonic.net> <8762egmzfp.fsf@benfinney.id.au> <4f5749bc$0$29989$c3e8da3$5496439d@news.astraweb.com> <4f57b63f$0$11986$742ec2ed@news.sonic.net> <871up4m69h.fsf@benfinney.id.au> <4f57eeac$0$29989$c3e8da3$5496439d@news.astraweb.com> <87sjhjltsp.fsf@benfinney.id.au> Message-ID: <4f593178$0$11963$742ec2ed@news.sonic.net> On 3/7/2012 6:18 PM, Ben Finney wrote: > Steven D'Aprano writes: > >> On Thu, 08 Mar 2012 08:48:58 +1100, Ben Finney wrote: >>> I think that's a Python bug. If the latter succeeds as a no-op, the >>> former should also succeed as a no-op. Neither should ever get any >>> errors when ?s? is a ?unicode? object already. >> >> No. The semantics of the unicode function (technically: a type >> constructor) are well-defined, and there are two distinct behaviours: Right. The real problem is that Python 2.7 doesn't have distinct "str" and "bytes" types. type(bytes() returns "str" is assumed to be ASCII 0..127, but that's not enforced. "bytes" and "str" should have been distinct types, but that would have broken much old code. If they were distinct, then constructors could distinguish between string type conversion (which requires no encoding information) and byte stream decoding. So it's possible to get junk characters in a "str", and they won't convert to Unicode. I've had this happen with databases which were supposed to be ASCII, but occasionally a non-ASCII character would slip through. This is all different in Python 3.x, where "str" is Unicode and "bytes" really are a distinct type. John Nagle From johnjsal at gmail.com Thu Mar 8 17:25:21 2012 From: johnjsal at gmail.com (John Salerno) Date: Thu, 8 Mar 2012 16:25:21 -0600 Subject: What's the best way to write this regular expression? In-Reply-To: <4F59308D.4000403@davea.name> References: <12783654.1174.1331073814011.JavaMail.geo-discussion-forums@yner4> <03dd4256-0881-44e8-bb27-38f23ce66267@h20g2000yqd.googlegroups.com> <21519dbf-4097-4780-874d-41d76f6453e0@x17g2000yqj.googlegroups.com> <4F59308D.4000403@davea.name> Message-ID: Thanks, I had no idea about either option, since I don't use the command prompt very much. Needless to say, the Linux console is much nicer :) On Thu, Mar 8, 2012 at 4:19 PM, Dave Angel wrote: > On 03/08/2012 04:40 PM, John Salerno wrote: >> >> >> http://i271.photobucket.com/albums/jj138/JohnJSal/lxml_error.png >> > > Nothing to do with Python, but you'd save us all a lot of space and > bandwidth if you learned how to copy/paste from a Windows cmd window. > > If you're just doing it rarely, you can right click on the top bar to get a > menu. ?I think you want "mark". ?Then you select the text you'd like to put > in the clipboard. > > Alternatively, you can put the console in quick-edit mode (I think it's > called, it's been a long time since I ran Windows). ?That's an option you > set on one cmd window, and it sticks for future windows. > > In quick-edit, you just right-click-drag on the cmd window to select a > rectangle of text. ?Then you can Ctrl-V to paste it into email, or into a > text editor, or wherever else you need it. ?Hard to imagine not using this > mode, or its Linux equivalent, which is always available. > > If that wasn't clear enough, or it doesn't work for you, somebody will > explain it better. ?Or ask me, and I'll launch a VirtualBox with Windows to > get you going. > > -- > > DaveA > From toby at tobiah.org Thu Mar 8 17:28:15 2012 From: toby at tobiah.org (Tobiah) Date: Thu, 08 Mar 2012 14:28:15 -0800 Subject: Finding MIME type for a data stream In-Reply-To: References: <%U96r.32867$082.25394@newsfe04.iad> Message-ID: <3oa6r.31449$L12.8825@newsfe23.iad> On 03/08/2012 02:11 PM, Dave Angel wrote: > On 03/08/2012 04:55 PM, Tobiah wrote: >> I'm pulling image data from a database blob, and serving >> it from a web2py app. I have to send the correct >> Content-Type header, so I need to detect the image type. >> >> Everything that I've found on the web so far, needs a file >> name on the disk, but I only have the data. >> >> It looks like the 'magic' package might be of use, but >> I can't find any documentation for it. >> >> Also, it seems like image/png works for other types >> of image data, while image/foo does not, yet I'm afraid >> that not every browser will play along as nicely. >> >> Thanks! >> >> Tobiah > > First step, ask the authors of the database what format of data this > blob is in. > > Failing that, write the same data locally as a binary file, and see what > application can open it. Or if you're on a Linux system, run file on > it. "file" can identify most data formats (not just images) just by > looking at the data. > > That assumes, of course, that there's any consistency in the data coming > out of the database. What happens if next time this blob is an Excel > spreadsheet? > I should simplify my question. Let's say I have a string that contains image data called 'mystring'. I want to do mime_type = some_magic(mystring) and get back 'image/jpg' or 'image/png' or whatever is appropriate for the image data. Thanks! Tobiah From toby at tobiah.org Thu Mar 8 17:34:39 2012 From: toby at tobiah.org (Tobiah) Date: Thu, 08 Mar 2012 14:34:39 -0800 Subject: Finding MIME type for a data stream In-Reply-To: References: <%U96r.32867$082.25394@newsfe04.iad> Message-ID: <3ua6r.9176$fT5.6230@newsfe02.iad> Also, I realize that I could write the data to a file and then use one of the modules that want a file path. I would prefer not to do that. Thanks From ethan at stoneleaf.us Thu Mar 8 17:52:22 2012 From: ethan at stoneleaf.us (Ethan Furman) Date: Thu, 08 Mar 2012 14:52:22 -0800 Subject: What's the best way to write this regular expression? In-Reply-To: <4F59308D.4000403@davea.name> References: <12783654.1174.1331073814011.JavaMail.geo-discussion-forums@yner4> <03dd4256-0881-44e8-bb27-38f23ce66267@h20g2000yqd.googlegroups.com> <21519dbf-4097-4780-874d-41d76f6453e0@x17g2000yqj.googlegroups.com> <4F59308D.4000403@davea.name> Message-ID: <4F593826.9080807@stoneleaf.us> Dave Angel wrote: > On 03/08/2012 04:40 PM, John Salerno wrote: >> >> http://i271.photobucket.com/albums/jj138/JohnJSal/lxml_error.png >> > > Nothing to do with Python, but you'd save us all a lot of space and > bandwidth if you learned how to copy/paste from a Windows cmd window. On Windows XP it is: Mouse ----- Right-click on title bar Left-click on Edit Left-click on Mark Right-click and drag to select desired text to copy text to clipboard Keyboard -------- - e k or arrows to move cursor, to select text to copy text to clipboard ~Ethan~ From d at davea.name Thu Mar 8 17:56:36 2012 From: d at davea.name (Dave Angel) Date: Thu, 08 Mar 2012 17:56:36 -0500 Subject: Finding MIME type for a data stream In-Reply-To: <3oa6r.31449$L12.8825@newsfe23.iad> References: <%U96r.32867$082.25394@newsfe04.iad> <3oa6r.31449$L12.8825@newsfe23.iad> Message-ID: <4F593924.7020301@davea.name> On 03/08/2012 05:28 PM, Tobiah wrote: > > > > I should simplify my question. Let's say I have a string > that contains image data called 'mystring'. > > I want to do > > mime_type = some_magic(mystring) > > and get back 'image/jpg' or 'image/png' or whatever is > appropriate for the image data. > > Thanks! > > Tobiah I have to assume you're talking python 2, since in python 3, strings cannot generally contain image data. In python 2, characters are pretty much interchangeable with bytes. Anyway, I don't know any way in the standard lib to distinguish arbitrary image formats. (There very well could be one.) The file program I referred to was an external utility, which you could run with the multiprocessing module. if you're looking for a specific, small list of file formats, you could make yourself a signature list. Most (not all) formats distinguish themselves in the first few bytes. For example, a standard zip file starts with "PK" for Phil Katz. A Windows exe starts with "MZ" for Mark Zbikowsky. And I believe a jpeg file starts hex(d8) (ff) (e0) (ff) If you'd like to see a list of available modules, help() is your friend. You can start with help("modules") to see quite a long list. And I was surprised how many image related things already are there. So maybe there's something I don't know about that could help. -- DaveA From ramit.prasad at jpmorgan.com Thu Mar 8 17:58:44 2012 From: ramit.prasad at jpmorgan.com (Prasad, Ramit) Date: Thu, 8 Mar 2012 22:58:44 +0000 Subject: "Decoding unicode is not supported" in unusual situation In-Reply-To: <4f593178$0$11963$742ec2ed@news.sonic.net> References: <4f571b94$0$12037$742ec2ed@news.sonic.net> <8762egmzfp.fsf@benfinney.id.au> <4f5749bc$0$29989$c3e8da3$5496439d@news.astraweb.com> <4f57b63f$0$11986$742ec2ed@news.sonic.net> <871up4m69h.fsf@benfinney.id.au> <4f57eeac$0$29989$c3e8da3$5496439d@news.astraweb.com> <87sjhjltsp.fsf@benfinney.id.au> <4f593178$0$11963$742ec2ed@news.sonic.net> Message-ID: <5B80DD153D7D744689F57F4FB69AF474197494@SCACMX008.exchad.jpmchase.net> > Right. The real problem is that Python 2.7 doesn't have distinct > "str" and "bytes" types. type(bytes() returns > "str" is assumed to be ASCII 0..127, but that's not enforced. > "bytes" and "str" should have been distinct types, but > that would have broken much old code. If they were distinct, then > constructors could distinguish between string type conversion > (which requires no encoding information) and byte stream decoding. > > So it's possible to get junk characters in a "str", and they > won't convert to Unicode. I've had this happen with databases which > were supposed to be ASCII, but occasionally a non-ASCII character > would slip through. bytes and str are just aliases for each other. >>> id( bytes ) 505366496 >>> id( str ) 505366496 >>> type( bytes ) >>> type( str ) >>> bytes == str True >>> bytes is str True And I do not think they were ever intended to be just ASCII because chr() takes 0 - 256 (non-inclusive) and returns a str. Ramit Ramit Prasad | JPMorgan Chase Investment Bank | Currencies Technology 712 Main Street | Houston, TX 77002 work phone: 713 - 216 - 5423 -- > -----Original Message----- > From: python-list-bounces+ramit.prasad=jpmorgan.com at python.org > [mailto:python-list-bounces+ramit.prasad=jpmorgan.com at python.org] On Behalf > Of John Nagle > Sent: Thursday, March 08, 2012 4:24 PM > To: python-list at python.org > Subject: Re: "Decoding unicode is not supported" in unusual situation > > On 3/7/2012 6:18 PM, Ben Finney wrote: > > Steven D'Aprano writes: > > > >> On Thu, 08 Mar 2012 08:48:58 +1100, Ben Finney wrote: > >>> I think that's a Python bug. If the latter succeeds as a no-op, the > >>> former should also succeed as a no-op. Neither should ever get any > >>> errors when ?s? is a ?unicode? object already. > >> > >> No. The semantics of the unicode function (technically: a type > >> constructor) are well-defined, and there are two distinct behaviours: > > > This is all different in Python 3.x, where "str" is Unicode and > "bytes" really are a distinct type. > > John Nagle > -- > http://mail.python.org/mailman/listinfo/python-list This email is confidential and subject to important disclaimers and conditions including on offers for the purchase or sale of securities, accuracy and completeness of information, viruses, confidentiality, legal privilege, and legal entity disclaimers, available at http://www.jpmorgan.com/pages/disclosures/email. From ramit.prasad at jpmorgan.com Thu Mar 8 18:02:59 2012 From: ramit.prasad at jpmorgan.com (Prasad, Ramit) Date: Thu, 8 Mar 2012 23:02:59 +0000 Subject: What's the best way to write this regular expression? In-Reply-To: References: <12783654.1174.1331073814011.JavaMail.geo-discussion-forums@yner4> <03dd4256-0881-44e8-bb27-38f23ce66267@h20g2000yqd.googlegroups.com> <21519dbf-4097-4780-874d-41d76f6453e0@x17g2000yqj.googlegroups.com> <4F59308D.4000403@davea.name> Message-ID: <5B80DD153D7D744689F57F4FB69AF4741974AA@SCACMX008.exchad.jpmchase.net> > > Alternatively, you can put the console in quick-edit mode (I think it's > > called, it's been a long time since I ran Windows). That's an option you > > set on one cmd window, and it sticks for future windows. > > > > In quick-edit, you just right-click-drag on the cmd window to select a > > rectangle of text. Then you can Ctrl-V to paste it into email, or into a > > text editor, or wherever else you need it. Hard to imagine not using > this > > mode, or its Linux equivalent, which is always available. Actually in quick-edit mode (XP and higher) you just select with left click and then hit enter which copies it to the clipboard. If you also enable insert mode (not sure if this is Win7 specific) you can even right click to paste into the console, just like Linux. > Needless to say, the Linux console is much nicer :) True. Ramit Ramit Prasad | JPMorgan Chase Investment Bank | Currencies Technology 712 Main Street | Houston, TX 77002 work phone: 713 - 216 - 5423 -- This email is confidential and subject to important disclaimers and conditions including on offers for the purchase or sale of securities, accuracy and completeness of information, viruses, confidentiality, legal privilege, and legal entity disclaimers, available at http://www.jpmorgan.com/pages/disclosures/email. From rafadurancastaneda at gmail.com Thu Mar 8 18:03:08 2012 From: rafadurancastaneda at gmail.com (=?ISO-8859-1?Q?Rafael_Dur=E1n_Casta=F1eda?=) Date: Fri, 09 Mar 2012 00:03:08 +0100 Subject: Can't get around HTTP/401 response using SUDS In-Reply-To: <1331221455.3087.14.camel@linux-dauq.site> References: <1331221455.3087.14.camel@linux-dauq.site> Message-ID: <4F593AAC.30604@gmail.com> El 08/03/12 16:44, Adam Tauno Williams escribi?: > SUDS version 0.4 pn x86_64 Python 2.7 > > I'm having a bear of a time getting HTTP Basic Authentication to work > for a SOAP request via suds. Also using an HTTP proxy server. > > In WireShark I just see a request - > GET http://...../services/services/JobService-0.0.1?wsdl HTTP/1.1 > Accept-Encoding: identity > Host: ....... > Connection: close > User-Agent: Python-urllib/2.7 > > This doesn't contain any authentication credentials so the response is > HTTP/401, and the client doesn't retry with credentials. The response > does come from the remote as I can see there is a WWW-Authenticate > header and it is from an Apache Tomcat server - so it makes it through > the proxy server. > > Code > ================ > url = 'http://....../services/services/JobService-0.0.1?wsdl' > proxy = urllib2.ProxyHandler({'http': 'http://.....:3128'}) > transport = suds.transport.http.HttpAuthenticated() > transport.urlopener = urllib2.build_opener(proxy) > client = suds.client.Client(url, transport=transport, > username='******', password='********') > .... > > I've tried the above as well as the method described at > It has the same problem. > > > Back Trace > ================ > Traceback (most recent call last): > File "etrace.py", line 30, in > client = suds.client.Client(url, transport=transport, > username='*******', password='*****') > File > "/usr/local/lib/python2.7/site-packages/suds-0.4-py2.7.egg/suds/client.py", line 112, in __init__ > self.wsdl = reader.open(url) > File > "/usr/local/lib/python2.7/site-packages/suds-0.4-py2.7.egg/suds/reader.py", line 152, in open > d = self.fn(url, self.options) > File > "/usr/local/lib/python2.7/site-packages/suds-0.4-py2.7.egg/suds/wsdl.py", line 136, in __init__ > d = reader.open(url) > File > "/usr/local/lib/python2.7/site-packages/suds-0.4-py2.7.egg/suds/reader.py", line 79, in open > d = self.download(url) > File > "/usr/local/lib/python2.7/site-packages/suds-0.4-py2.7.egg/suds/reader.py", line 95, in download > fp = self.options.transport.open(Request(url)) > File > "/usr/local/lib/python2.7/site-packages/suds-0.4-py2.7.egg/suds/transport/http.py", line 173, in open > return HttpTransport.open(self, request) > File > "/usr/local/lib/python2.7/site-packages/suds-0.4-py2.7.egg/suds/transport/http.py", line 64, in open > raise TransportError(str(e), e.code, e.fp) > suds.transport.TransportError: HTTP Error 401: Unauthorized > When I've got issues like yours, I usually try using a console client (telnet/curl/wget,...) adding all needed headers/data manually so I'm totally sure the request is OK, if everything goes Ok you know your python code need to be reviewed but when you are under proxies you can find a lot of not python related issues (bad gateways, using proxy when it shouldn't or vice-versa, requests changed by proxy,....). wireshark can be very useful but in situations like this I usually prefer tcpflow output, I think the request/response flow showed is really useful, but that's a personal preference. HTH, bye From d at davea.name Thu Mar 8 18:23:06 2012 From: d at davea.name (Dave Angel) Date: Thu, 08 Mar 2012 18:23:06 -0500 Subject: What's the best way to write this regular expression? In-Reply-To: <5B80DD153D7D744689F57F4FB69AF4741974AA@SCACMX008.exchad.jpmchase.net> References: <12783654.1174.1331073814011.JavaMail.geo-discussion-forums@yner4> <03dd4256-0881-44e8-bb27-38f23ce66267@h20g2000yqd.googlegroups.com> <21519dbf-4097-4780-874d-41d76f6453e0@x17g2000yqj.googlegroups.com> <4F59308D.4000403@davea.name> <5B80DD153D7D744689F57F4FB69AF4741974AA@SCACMX008.exchad.jpmchase.net> Message-ID: <4F593F5A.7050107@davea.name> On 03/08/2012 06:02 PM, Prasad, Ramit wrote: > Actually in quick-edit mode (XP and higher) you just select with > left click and then hit enter which copies it to the clipboard. > If you also enable insert mode (not sure if this is Win7 specific) > you can even right click to paste into the console, just like > Linux. > >> Needless to say, the Linux console is much nicer :) > True. > > I was confusing the left-mouse-drag and the right-click. You are correct about both the copying and the pasting, and they do both work from XP onwards. As I said, I haven't used Windows much in quite a while. -- DaveA From toby at tobiah.org Thu Mar 8 18:40:13 2012 From: toby at tobiah.org (Tobiah) Date: Thu, 08 Mar 2012 15:40:13 -0800 Subject: Finding MIME type for a data stream In-Reply-To: References: <%U96r.32867$082.25394@newsfe04.iad> <3oa6r.31449$L12.8825@newsfe23.iad> Message-ID: > I have to assume you're talking python 2, since in python 3, strings > cannot generally contain image data. In python 2, characters are pretty > much interchangeable with bytes. Yeah, python 2 > if you're looking for a specific, small list of file formats, you could > make yourself a signature list. Most (not all) formats distinguish > themselves in the first few bytes. Yeah, maybe I'll just do that. I'm alowing users to paste images into a rich-text editor, so I'm pretty much looking at .png, .gif, or .jpg. Those should be pretty easy to distinguish by looking at the first few bytes. Pasting images may sound weird, but I'm using a jquery widget called cleditor that takes image data from the clipboard and replaces it with inline base64 data. The html from the editor ends up as an email, and the inline images cause the emails to be tossed in the spam folder for most people. So I'm parsing the emails, storing the image data, and replacing the inline images with an img tag that points to a web2py app that takes arguments that tell it which image to pull from the database. Now that I think of it, I could use php to detect the image type, and store that in the database. Not quite as clean, but that would work. Tobiah From irmen.NOSPAM at xs4all.nl Thu Mar 8 21:12:42 2012 From: irmen.NOSPAM at xs4all.nl (Irmen de Jong) Date: Fri, 09 Mar 2012 03:12:42 +0100 Subject: Finding MIME type for a data stream In-Reply-To: <3ua6r.9176$fT5.6230@newsfe02.iad> References: <%U96r.32867$082.25394@newsfe04.iad> <3ua6r.9176$fT5.6230@newsfe02.iad> Message-ID: <4f596718$0$6847$e4fe514c@news2.news.xs4all.nl> On 8-3-2012 23:34, Tobiah wrote: > Also, I realize that I could write the data to a file > and then use one of the modules that want a file path. > I would prefer not to do that. > > Thanks > Use StringIO then, instead of a file on disk Irmen From joncle at googlemail.com Thu Mar 8 21:31:22 2012 From: joncle at googlemail.com (Jon Clements) Date: Thu, 8 Mar 2012 18:31:22 -0800 (PST) Subject: Finding MIME type for a data stream In-Reply-To: References: <%U96r.32867$082.25394@newsfe04.iad> <3oa6r.31449$L12.8825@newsfe23.iad> Message-ID: <30829846.74.1331260282202.JavaMail.geo-discussion-forums@vbai14> On Thursday, 8 March 2012 23:40:13 UTC, Tobiah wrote: > > I have to assume you're talking python 2, since in python 3, strings > > cannot generally contain image data. In python 2, characters are pretty > > much interchangeable with bytes. > > Yeah, python 2 > > > > if you're looking for a specific, small list of file formats, you could > > make yourself a signature list. Most (not all) formats distinguish > > themselves in the first few bytes. > > Yeah, maybe I'll just do that. I'm alowing users to paste > images into a rich-text editor, so I'm pretty much looking > at .png, .gif, or .jpg. Those should be pretty easy to > distinguish by looking at the first few bytes. > > Pasting images may sound weird, but I'm using a jquery > widget called cleditor that takes image data from the > clipboard and replaces it with inline base64 data. > The html from the editor ends up as an email, and the > inline images cause the emails to be tossed in the > spam folder for most people. So I'm parsing the > emails, storing the image data, and replacing the > inline images with an img tag that points to a > web2py app that takes arguments that tell it which > image to pull from the database. > > Now that I think of it, I could use php to detect the > image type, and store that in the database. Not quite > as clean, but that would work. > > Tobiah Something like the following might be worth a go: (untested) from PIL import Image img = Image.open(StringIO(blob)) print img.format HTH Jon. PIL: http://www.pythonware.com/library/pil/handbook/image.htm From wuwei23 at gmail.com Thu Mar 8 22:38:51 2012 From: wuwei23 at gmail.com (alex23) Date: Thu, 8 Mar 2012 19:38:51 -0800 (PST) Subject: What's the best way to write this regular expression? References: <12783654.1174.1331073814011.JavaMail.geo-discussion-forums@yner4> Message-ID: <9796cdc0-7322-4d1b-b513-a51fb8bc5e62@lf20g2000pbb.googlegroups.com> John Salerno wrote: > So much work just to get a 3rd party module installed! "New! Try out the beta release of Beautiful Soup 4. (Last updated February 28, 2012) easy_install beautifulsoup4 or pip install beautifulsoup4 or download a tarball." http://www.crummy.com/software/BeautifulSoup/ Worked fine under both Python 2.7 & 3.2 using pip. From johnjsal at gmail.com Thu Mar 8 22:52:48 2012 From: johnjsal at gmail.com (John Salerno) Date: Thu, 8 Mar 2012 19:52:48 -0800 (PST) Subject: What's the best way to write this regular expression? In-Reply-To: <9796cdc0-7322-4d1b-b513-a51fb8bc5e62@lf20g2000pbb.googlegroups.com> References: <12783654.1174.1331073814011.JavaMail.geo-discussion-forums@yner4> <9796cdc0-7322-4d1b-b513-a51fb8bc5e62@lf20g2000pbb.googlegroups.com> Message-ID: <11016571.151.1331265168696.JavaMail.geo-discussion-forums@yneo2> On Thursday, March 8, 2012 9:38:51 PM UTC-6, alex23 wrote: > John Salerno wrote: > > So much work just to get a 3rd party module installed! > > "New! Try out the beta release of Beautiful Soup 4. (Last updated > February 28, 2012) > easy_install beautifulsoup4 or pip install beautifulsoup4 or download > a tarball." > > http://www.crummy.com/software/BeautifulSoup/ > > Worked fine under both Python 2.7 & 3.2 using pip. Yeah, but first I had to figure out how to install easy_install :) From hackingkk at gmail.com Thu Mar 8 23:27:16 2012 From: hackingkk at gmail.com (hackingKK) Date: Fri, 09 Mar 2012 09:57:16 +0530 Subject: GUI components in python In-Reply-To: References: Message-ID: <4F5986A4.8060006@gmail.com> Hi Janaki, Python will mostly use either the pygtk library or pyqt library for any rich and production quality GUI. So you must try figuring out if either of these 2 libraries are used. Other than this, there is tkinter which i guess comes with Python as default. Happy hacking. Krishnakant. On 07/03/12 19:14, janaki rajamani wrote: > Hi > > I am stuck with the brain workshop software implemented using python. > The code involves a lot of GUI elements and i am familar only with the > basic python programming. > I would like to know whether there are built in classes to support GUI > elements or arethey project dependant. > From jagteraho2006 at gmail.com Thu Mar 8 23:40:57 2012 From: jagteraho2006 at gmail.com (amar Singh) Date: Thu, 8 Mar 2012 20:40:57 -0800 (PST) Subject: how to get plots made faster Message-ID: <5415ca7c-ccc4-4ec3-a118-4674e54038a7@b18g2000vbz.googlegroups.com> The following is the part of my code which is running faster locally and more slowly remotely via ssh on the same machine. Note I am trying to generate a multi-page report. ## create plots and write to a pdf file from scipy import * import matplotlib.pyplot as plt from matplotlib.backends.backend_pdf import PdfPages # open a multi-page pdf file pp = PdfPages('history_plot.pdf') F=loadtxt('hist.dat',comments='%') t=F[:,0] E=F[:,13] plt.plot(t,E) h1=plt.ylabel('Energy', fontsize=16) h1=plt.xlabel('Time', fontsize=16) pp.savefig() plt.clf() VdotB=F[:,14] plt.plot(t,VdotB) pp.savefig() pp.close() From breamoreboy at yahoo.co.uk Fri Mar 9 01:01:23 2012 From: breamoreboy at yahoo.co.uk (Mark Lawrence) Date: Fri, 09 Mar 2012 06:01:23 +0000 Subject: how to get plots made faster In-Reply-To: <5415ca7c-ccc4-4ec3-a118-4674e54038a7@b18g2000vbz.googlegroups.com> References: <5415ca7c-ccc4-4ec3-a118-4674e54038a7@b18g2000vbz.googlegroups.com> Message-ID: On 09/03/2012 04:40, amar Singh wrote: > The following is the part of my code which is running faster locally > and more slowly remotely via ssh on the same machine. Note I am trying > to generate a multi-page report. > > > ## create plots and write to a pdf file > from scipy import * > import matplotlib.pyplot as plt > from matplotlib.backends.backend_pdf import PdfPages > > # open a multi-page pdf file > pp = PdfPages('history_plot.pdf') > > F=loadtxt('hist.dat',comments='%') > > > t=F[:,0] > E=F[:,13] > > plt.plot(t,E) > > h1=plt.ylabel('Energy', fontsize=16) > h1=plt.xlabel('Time', fontsize=16) > pp.savefig() > > plt.clf() > VdotB=F[:,14] > plt.plot(t,VdotB) > > pp.savefig() > pp.close() I can't help directly but you may be better off asking on the matplotlib users mailing list see https://lists.sourceforge.net/lists/listinfo/matplotlib-users -- Cheers. Mark Lawrence. From torriem at gmail.com Fri Mar 9 01:33:58 2012 From: torriem at gmail.com (Michael Torrie) Date: Thu, 08 Mar 2012 23:33:58 -0700 Subject: GUI components in python In-Reply-To: References: Message-ID: <4F59A456.4070703@gmail.com> On 03/07/2012 06:44 AM, janaki rajamani wrote: > Hi > > I am stuck with the brain workshop software implemented using python. > The code involves a lot of GUI elements and i am familar only with the > basic python programming. > I would like to know whether there are built in classes to support GUI > elements or arethey project dependant. brain workshop appears to use the pyglet library: http://www.pyglet.org/ From jkn_gg at nicorp.f9.co.uk Fri Mar 9 05:45:13 2012 From: jkn_gg at nicorp.f9.co.uk (jkn) Date: Fri, 9 Mar 2012 02:45:13 -0800 (PST) Subject: What's the best way to write this regular expression? References: <12783654.1174.1331073814011.JavaMail.geo-discussion-forums@yner4> <03dd4256-0881-44e8-bb27-38f23ce66267@h20g2000yqd.googlegroups.com> <21519dbf-4097-4780-874d-41d76f6453e0@x17g2000yqj.googlegroups.com> <4F59308D.4000403@davea.name> Message-ID: <304e2797-20c3-4333-b4a0-a53cedbd1c24@w5g2000vbv.googlegroups.com> Also unrelated to the OP, but a far superior Commnad line interface to Windows is the (unhelpfully-named) 'console' program: http://sourceforge.net/projects/console/ This has tabbed windows, preset directory navigation, good copy/paste facilities, the ability to configure different shells, etc etc. Well worth a look. HTH J^n From __peter__ at web.de Fri Mar 9 05:50:04 2012 From: __peter__ at web.de (Peter Otten) Date: Fri, 09 Mar 2012 11:50:04 +0100 Subject: Finding MIME type for a data stream References: <%U96r.32867$082.25394@newsfe04.iad> Message-ID: Tobiah wrote: > I'm pulling image data from a database blob, and serving > it from a web2py app. I have to send the correct > Content-Type header, so I need to detect the image type. > > Everything that I've found on the web so far, needs a file > name on the disk, but I only have the data. > > It looks like the 'magic' package might be of use, but > I can't find any documentation for it. After some try-and-error and a look into example.py: >>> m = magic.open(magic.MAGIC_MIME_TYPE) >>> m.load() 0 >>> sample = open("tmp.png").read() >>> m.buffer(sample) 'image/png' From neilc at norwich.edu Fri Mar 9 08:23:21 2012 From: neilc at norwich.edu (Neil Cerutti) Date: 9 Mar 2012 13:23:21 GMT Subject: "Decoding unicode is not supported" in unusual situation References: <4f571b94$0$12037$742ec2ed@news.sonic.net> <8762egmzfp.fsf@benfinney.id.au> <4f5749bc$0$29989$c3e8da3$5496439d@news.astraweb.com> <4f57b63f$0$11986$742ec2ed@news.sonic.net> <871up4m69h.fsf@benfinney.id.au> <4f57eeac$0$29989$c3e8da3$5496439d@news.astraweb.com> <87sjhjltsp.fsf@benfinney.id.au> <4f593178$0$11963$742ec2ed@news.sonic.net> Message-ID: <9ruei9FnpgU3@mid.individual.net> On 2012-03-08, John Nagle wrote: > So it's possible to get junk characters in a "str", and they > won't convert to Unicode. I've had this happen with databases > which were supposed to be ASCII, but occasionally a non-ASCII > character would slip through. Perhaps encode and then decode, rather than try to encode a non-encoded str. -- Neil Cerutti From jg07024 at gmail.com Fri Mar 9 09:11:34 2012 From: jg07024 at gmail.com (John Graves) Date: Sat, 10 Mar 2012 03:11:34 +1300 Subject: A Plausible Promise of Abundant Educational Resources Message-ID: Dear Python-List: If you find Wikipedia useful and can see the value of collaborating on a project which could make learning material as freely and spectacularly available as Wikipedia does reference material[1], please read on. Background: In November 2009, I began learning Python with the objective of trying to understand the following research question in my PhD research study of open source software development: "We have built Wikipedia and other big, successful open source projects. How can we do it again (and again)?" The critical issue for me was how to start a project which would grow to self-sustainability. So for over two years now, my research method has been to try to actually start such a project. I failed. Over and over. The data collection period for my study ended. Before I could start writing up my PhD, however, I saw an answer provided in February 2012 by the founder of Craigslist, on Quora. When asked, "How did Craigslist gain its initial traction?"[2], Craig Newmark, Customer Service Rep & Founder wrote: - from beginning, did something simple and useful - from beginning, began cycle: -- asked for community feedback -- did something about it -- repeat, forever -- got lucky with simple site design So I have now tried to take what started as a horribly over ambitious desktop application[3], combined with an equally inept Android mobile application (done in Java)[4] and boiled down the core text-to-speech functionality into something "simple and useful" which runs on the web. The project is now called SlideSpeech[5] and it does a couple of pretty interesting things. Interesting enough to attract venture capital. The Future: As of 23 February 2012, SlideSpeech Limited is a company. But it is still an open source software development research project with a Pythonic heart. I can now pay for development of some professional quality software by people who know much more Java and Python than I do. Perhaps this will help the project reach self-sustainability, although, as Derek Sivers points out in a memorable TED talk[6], just initiating or leading a project like this is not what makes it a success: there must be joiners and followers for a project with a plausible promise to grow to realise its potential. The followers are the real heroes. Now Peter Diamandis just gave a TED talk entitled, "Abundance is our future"[7] which everyone should watch. He talks of 3 billion people coming on-line this decade. I want SlideSpeech to be useful and helpful to those people. Not to make money from them but to help foster a global conversation and global distribution of knowledge. We should all share in Educational Abundance. Diamandis says, "we're going to hit 70 percent penetration of cellphones in the developing world by the end of 2013." SlideSpeech can plausibly promise to deliver free, interactive learning material to smart phones anywhere on the planet this year. The current working prototype does this today. In its simplest form, the system works like this: 1) you start in your presentation software, adding a voice over script in the speaker notes of each slide 2) you upload your presentation to SlideSpeech 3) on the SlideSpeech server (which can be your own PC, running Python, made viewable to the world using PageKite[8]), the presentation is "decomposed" into slide images and text scripts. The scripts are fed into a text-to-speech engine. The resulting audio files are wrapped in HTML with their corresponding slide image files. Finally, a link to access the HTML is e-mailed back to you 4) you open the link on your mobile phone's web browser and the presentation you were writing just moments before "delivers itself" on your phone ... or on any smart phone, tablet or web browser, anywhere. No need to organise a venue, send invitations or get people to actually physically show up to see and hear your talk. You can just forward the e-mail. Cooler still, 5) if you have a native application play the script using the phone's text-to-speech engine, you don't have to download audio (or video), so you save 75% of the bandwidth. Multiplied by billions of people, multiplied by the number of downloads[9], that is a huge savings. The compression of content into the simple combination of images and text-to-speech scripts allows SlideSpeech to realise part of the One Laptop Per Child vision using "talking" smart phones and tablets. Students can learn on their own. Current prices on the cheapest Android 2.2 gear which can deliver SlideSpeech content here in Auckland, New Zealand are under NZ$150. A Revolution in Learning: Think of SlideSpeech as a platform like Khan Academy[10] with the exercises integrated into the presentation. The scripts can be created and improved collaboratively, like Wikipedia articles, or cloned and customised for particular audiences. Unlike Khan Academy videos, the text of SlideSpeech presentations is search-able and machine-translatable. With presentation feedback built into the system[11], a newly created presentation can be distributed and then dynamically critiqued and revised, so later viewers see the corrected and improved version. It is remarkable how quickly changes can be made, especially in contrast to the feedback cycle a typical instructor goes through to improve their teaching. These ideas and technologies are not new. Text-to-speech, in particular, has been around for a long time. Lately, however, the voices have become "Avatar-quality"[12]. These ideas are disruptive. The current working prototypes of SlideSpeech may appear to work poorly, underperforming relative to established products, but as Clayton Christensen explains[13], having the ability to meet an underlying need in a radically different way transforms industries. I like to make an analogy with trains and cars. Current educational systems are like trains: everyone has to go between the same fixed destinations at the same fixed times, like it or not. SlideSpeech-based learning is like having a car: you get to go learn whatever you want, whenever you want, wherever you are, at your own pace (which is sometimes very, very fast!). Content is King: Having lots of content available will accelerate the adoption of SlideSpeech above all else. Over the coming weeks, as the system matures, you can start preparing by authoring presentations with speaker notes. Once the system is fully available on-line, or downloadable to your PC, you can drop your presentations in and get out "self-delivering" talks in HTML or even video format, voiced by a wide selection of computer voices in English and in many other languages. Please feel free to jump in with suggestions, contributions or forks of the code repositories listed below. Let's make Educational Abundance happen with Python this year. Exponentially yours, John Graves PhD Student AUT University Auckland, New Zealand Founder and CEO SlideSpeech [1] The English language version of Wikipedia has 50 times as many words as *Encyclop?dia Britannica * http://en.wikipedia.org/wiki/Wikipedia:Size_comparisons [2] http://www.quora.com/How-did-Craigslist-gain-its-initial-traction [3] http://code.google.com/p/open-allure-ds/ [4] http://code.google.com/p/wiki-to-speech/ [5] http://code.google.com/p/slidespeech/ [6] http://www.ted.com/talks/derek_sivers_how_to_start_a_movement.html [7] http://www.ted.com/talks/peter_diamandis_abundance_is_our_future.html [8] http://pagekite.net [9] average for Wikipedia is about one article per person per day (18.1 billion pages / 482 million unique visitors in January 2012) http://stats.wikimedia.org/reportcard/ [10] http://khanacademy.org [11] http://code.google.com/p/slidespeech/wiki/WorkflowDiagrams [12] I particularly like Loquendo's Veena, Indian English voice http://www.loquendo.com/en/demo-center/tts-demo/english/ [13] http://en.wikipedia.org/wiki/Disruptive_technology -------------- next part -------------- An HTML attachment was scrubbed... URL: From rboothroyd8 at gmail.com Fri Mar 9 10:10:19 2012 From: rboothroyd8 at gmail.com (Richard Boothroyd) Date: Fri, 9 Mar 2012 07:10:19 -0800 (PST) Subject: converting from tcl/tkl to python Message-ID: Hi there, First, I am not a developer so go easy on my ignorance ;-). Our company designs and develops hearing aid audibility fitting equipment. (www.audioscan.com). Our current software GUI is all based on TCL/TKL and we are running into issues on developing a "prettier" GUI in an effort to modernize some of our equipment. My understanding is that Python is a much better GUI tool than TCL/TKL so I'd appreciate any insight on this assumption. Also I'm wondering what kind of effort and expertise it would take to convert from TCL/ TKL to Python. Let me know what further info you may require. Also, if there is anyone out there that has specific expertise in performing this conversion please contact me. Thanks Richard Boothroyd General Manager Audioscan From reader at calvinkim.org Fri Mar 9 10:46:41 2012 From: reader at calvinkim.org (Calvin Kim) Date: Fri, 09 Mar 2012 10:46:41 -0500 Subject: A Plausible Promise of Abundant Educational Resources In-Reply-To: References: Message-ID: <4F5A25E1.10503@calvinkim.org> Google search for slidespeech returns with a warning, "This site may harm your computer." From rodperson at rodperson.com Fri Mar 9 10:58:47 2012 From: rodperson at rodperson.com (Rod Person) Date: Fri, 9 Mar 2012 10:58:47 -0500 Subject: converting from tcl/tkl to python In-Reply-To: References: Message-ID: <20120309105847.00003316@unknown> On Fri, 9 Mar 2012 07:10:19 -0800 (PST) Richard Boothroyd wrote: > Hi there, > > First, I am not a developer so go easy on my ignorance ;-). Our > company designs and develops hearing aid audibility fitting equipment. > (www.audioscan.com). Our current software GUI is all based on TCL/TKL > and we are running into issues on developing a "prettier" GUI in an > effort to modernize some of our equipment. Have you looked at Tile? It a theme-able widget set for Tk. http://wiki.tcl.tk/11075 As for python, the default GUI toolkit for Python is Tk, but there are bindings that allow you to use WxWidgets, Qt and GTK. -- Rod Person http://www.rodperson.com rodperson at rodperson.com 'Silence is a fence around wisdom' From kw at codebykevin.com Fri Mar 9 10:59:09 2012 From: kw at codebykevin.com (Kevin Walzer) Date: Fri, 09 Mar 2012 10:59:09 -0500 Subject: converting from tcl/tkl to python In-Reply-To: References: Message-ID: On 3/9/12 10:10 AM, Richard Boothroyd wrote: > First, I am not a developer so go easy on my ignorance ;-). Our > company designs and develops hearing aid audibility fitting equipment. > (www.audioscan.com). Our current software GUI is all based on TCL/TKL > and we are running into issues on developing a "prettier" GUI in an > effort to modernize some of our equipment. > > My understanding is that Python is a much better GUI tool than TCL/TKL > so I'd appreciate any insight on this assumption. Also I'm wondering > what kind of effort and expertise it would take to convert from TCL/ > TKL to Python. Let me know what further info you may require. > First, don't assume that Tcl/Tk is not up to the job. I took a look at some of your software screenshots at your website and noticed that you are using the "classic" Tk widgets, which, while functional, are a bit dated in their appearance. Tcl/Tk 8.5 has added a separate group of widgets called the ttk (for "themed Tk") widgets that are fully native in appearance on Windows/Mac and much improved in their appearance on Linux/Unix. Here's a screenshot of a Tcl/Tk app using the ttk widgets on Windows: http://sourceforge.net/p/windowstoolset/screenshot/screenshot.png If modernizing the UI is all you need to do, a careful update of your code using the themed Tk widgets will take you a long way, with far less work and cost than porting your code to Python. Having said this, if you are seeing other issues with Tcl (lack of support for certain libraries/API's, code is becoming unmanagable, etc.) and you have concluded that Python is a superior choice overall, then there are a number of different routes you can take: 1. Python's built-in GUI toolkit is a wrapper for Tk called Tkinter. Recent versions of Python support the themed Tk widgets as well as the classic Tk widgets. Doing a port of your code from Tcl/Tk to Python will be somewhat simpler if you use Python's Tkinter library, because the general layout will be similar. However, there are no automated tools for mapping Tk to Tkinter that I am aware of--you will have to do a rewrite of your code. 2. Python also has bindings for many other UI toolkits, including wxWidgets (a very nice cross-platform toolkit that has native UI bindings), Qt, Gtk, and others. If you prefer a different design/toolkit/API, these may be worth a look. However, if you opt for one of these toolkits and Python, then you are essentially starting from scratch with your software--it will be a complete rewrite not just in the programming language but also in the UI design as well. That will take a great deal of additional time and cost. To sum up: a rewrite of your software in Python will amount a major-to-complete overhaul of the code base, depending on how you approach the UI design--and this will involve significant cost and time. This may make sense if you feel you have reached the end of the line with Tcl and your desire for a different language is for reasons in addition to the look and feel of the UI. However, if your software and its code is otherwise satisfactory and you need simply to update the UI design, that can be done in Tcl at far less cost using the ttk widgets. Hope this helps, Kevin -- Kevin Walzer Code by Kevin http://www.codebykevin.com From toby at tobiah.org Fri Mar 9 11:35:42 2012 From: toby at tobiah.org (Tobiah) Date: Fri, 09 Mar 2012 08:35:42 -0800 Subject: Finding MIME type for a data stream In-Reply-To: <4f596718$0$6847$e4fe514c@news2.news.xs4all.nl> References: <%U96r.32867$082.25394@newsfe04.iad> <3ua6r.9176$fT5.6230@newsfe02.iad> <4f596718$0$6847$e4fe514c@news2.news.xs4all.nl> Message-ID: On 03/08/2012 06:12 PM, Irmen de Jong wrote: > On 8-3-2012 23:34, Tobiah wrote: >> Also, I realize that I could write the data to a file >> and then use one of the modules that want a file path. >> I would prefer not to do that. >> >> Thanks >> > > Use StringIO then, instead of a file on disk > > Irmen > Nice. Thanks. From toby at tobiah.org Fri Mar 9 11:40:39 2012 From: toby at tobiah.org (Tobiah) Date: Fri, 09 Mar 2012 08:40:39 -0800 Subject: Finding MIME type for a data stream In-Reply-To: References: <%U96r.32867$082.25394@newsfe04.iad> <3oa6r.31449$L12.8825@newsfe23.iad> Message-ID: On 03/08/2012 06:04 PM, Dennis Lee Bieber wrote: > On Thu, 08 Mar 2012 15:40:13 -0800, Tobiah declaimed > the following in gmane.comp.python.general: > > >> Pasting images may sound weird, but I'm using a jquery >> widget called cleditor that takes image data from the >> clipboard and replaces it with inline base64 data. > > In Windows, I'd expect "device independent bitmap" to be the result > of a clipboard image... This jquery editor seems to detect the image data and translate it into an inline image like: I'm curious to know if anyone with ElementTree 1.3 has gotten the parent XPath to work? According to http://effbot.org/zone/element-xpath.htm, you should be able to do >>> import xml.etree.ElementTree as et >>> et.VERSION '1.3.0' ... >>> elem.find('..') >>> but that always return None for me. Has anyone else seen this particular XPath work? Am I just doing something wrong? Thanks for you help! Jason PS. In case you're wondering, yes I know that lxml supports parent points and, yes, I'm aware of http://effbot.org/zone/element.htm#accessing-parents. I'm really wondering if the mentioned XPath is broken or something. From skawaii at gmail.com Fri Mar 9 12:47:47 2012 From: skawaii at gmail.com (Jason Cooper) Date: Fri, 9 Mar 2012 09:47:47 -0800 (PST) Subject: Does ElementTree's Parent XPath actually work? In-Reply-To: <20999038.134.1331313844881.JavaMail.geo-discussion-forums@pbnt10> References: <20999038.134.1331313844881.JavaMail.geo-discussion-forums@pbnt10> Message-ID: <10963798.786.1331315267484.JavaMail.geo-discussion-forums@pbcmk6> On Friday, March 9, 2012 12:24:04 PM UTC-5, Jason Cooper wrote: > I'm curious to know if anyone with ElementTree 1.3 has gotten the parent XPath to work? According to http://effbot.org/zone/element-xpath.htm, you should be able to do > > >>> import xml.etree.ElementTree as et > >>> et.VERSION > '1.3.0' > ... > >>> elem.find('..') > >>> > > but that always return None for me. Has anyone else seen this particular XPath work? Am I just doing something wrong? > > Thanks for you help! > Jason > > PS. In case you're wondering, yes I know that lxml supports parent points and, yes, I'm aware of http://effbot.org/zone/element.htm#accessing-parents. I'm really wondering if the mentioned XPath is broken or something. Looks like I may have figured out my own answer. I just noticed that using '..' when searching on the tree (as opposed to the element) works as expected. Makes sense after I stepped back and recalled that the elements don't contain pointers to their parents. The tree, on the other hand, can see all. From toby at tobiah.org Fri Mar 9 12:53:30 2012 From: toby at tobiah.org (Tobiah) Date: Fri, 09 Mar 2012 09:53:30 -0800 Subject: Finding MIME type for a data stream In-Reply-To: <30829846.74.1331260282202.JavaMail.geo-discussion-forums@vbai14> References: <%U96r.32867$082.25394@newsfe04.iad> <3oa6r.31449$L12.8825@newsfe23.iad> <30829846.74.1331260282202.JavaMail.geo-discussion-forums@vbai14> Message-ID: > Something like the following might be worth a go: > (untested) > > from PIL import Image > img = Image.open(StringIO(blob)) > print img.format > This worked quite nicely. I didn't see a list of all returned formats though in the docs. The one image I had returned PNG So I'm doing: mime_type = "image/%s" % img.format.lower() I'm hoping that will work for any image type. Thanks, Tobiah From nagle at animats.com Fri Mar 9 13:11:58 2012 From: nagle at animats.com (John Nagle) Date: Fri, 09 Mar 2012 10:11:58 -0800 Subject: "Decoding unicode is not supported" in unusual situation In-Reply-To: References: <4f571b94$0$12037$742ec2ed@news.sonic.net> <8762egmzfp.fsf@benfinney.id.au> <4f5749bc$0$29989$c3e8da3$5496439d@news.astraweb.com> <4f57b63f$0$11986$742ec2ed@news.sonic.net> <871up4m69h.fsf@benfinney.id.au> <4f57eeac$0$29989$c3e8da3$5496439d@news.astraweb.com> <87sjhjltsp.fsf@benfinney.id.au> <4f593178$0$11963$742ec2ed@news.sonic.net> Message-ID: <4f5a47f0$0$11979$742ec2ed@news.sonic.net> On 3/8/2012 2:58 PM, Prasad, Ramit wrote: >> Right. The real problem is that Python 2.7 doesn't have distinct >> "str" and "bytes" types. type(bytes() returns >> "str" is assumed to be ASCII 0..127, but that's not enforced. >> "bytes" and "str" should have been distinct types, but >> that would have broken much old code. If they were distinct, then >> constructors could distinguish between string type conversion >> (which requires no encoding information) and byte stream decoding. >> >> So it's possible to get junk characters in a "str", and they >> won't convert to Unicode. I've had this happen with databases which >> were supposed to be ASCII, but occasionally a non-ASCII character >> would slip through. > > bytes and str are just aliases for each other. That's true in Python 2.7, but not in 3.x. From 2.6 forward, "bytes" and "str" were slowly being separated. See PEP 358. Some of the problems in Python 2.7 come from this ambiguity. Logically, "unicode" of "str" should be a simple type conversion from ASCII to Unicode, while "unicode" of "bytes" should require an encoding. But because of the bytes/str ambiguity in Python 2.6/2.7, the behavior couldn't be type-based. John Nagle From mark at markroseman.com Fri Mar 9 15:36:01 2012 From: mark at markroseman.com (Mark Roseman) Date: Fri, 09 Mar 2012 13:36:01 -0700 Subject: converting from tcl/tkl to python References: Message-ID: Hi Richard, I would strongly second the advice that Kevin provided: rewriting is a substantial step not to be taken lightly. If a mere facelift is desired, migrating to the more modern tools provided in recent versions of Tcl/Tk may well meet your needs at a fraction of the cost/effort. For additional information, you can point your technical people at http://www.tkdocs.com. Mark From invalid at invalid.invalid Fri Mar 9 15:54:48 2012 From: invalid at invalid.invalid (Grant Edwards) Date: Fri, 9 Mar 2012 20:54:48 +0000 (UTC) Subject: converting from tcl/tkl to python References: Message-ID: On 2012-03-09, Kevin Walzer wrote: > Having said this, if you are seeing other issues with Tcl (lack of > support for certain libraries/API's, code is becoming unmanagable, etc.) > and you have concluded that Python is a superior choice overall, then > there are a number of different routes you can take: > > 1. Python's built-in GUI toolkit is a wrapper for Tk called Tkinter. > Recent versions of Python support the themed Tk widgets as well as the > classic Tk widgets. Doing a port of your code from Tcl/Tk to Python will > be somewhat simpler if you use Python's Tkinter library, because the > general layout will be similar. However, there are no automated tools > for mapping Tk to Tkinter that I am aware of--you will have to do a > rewrite of your code. If you _do_ decide a rewrite of your code is in order, trying to "convert" your existing code will mostly likey produce a mess. Python and Tcl are very different languages. Trying to write a Tcl program in Python won't work very well. The right thing to do is to carefully figure out what the requirements are (you should probably even write them down). Then sit down with a blank slate and design/build/grow/write a Python application. Evaluating and choosing a GUI framework (Tk, Wx, Gtk, Qt, etc.) can take quite a bit of time, so remember to allow for that. If you decide to skip that step and stick with Tk, then you've got a bit of head start since you know how Tk works (assuming the API for the newer themed widgets isn't too much different than the old widgets). -- Grant Edwards grant.b.edwards Yow! Give them RADAR-GUIDED at SKEE-BALL LANES and gmail.com VELVEETA BURRITOS!! From ethan at stoneleaf.us Fri Mar 9 17:10:18 2012 From: ethan at stoneleaf.us (Ethan Furman) Date: Fri, 09 Mar 2012 14:10:18 -0800 Subject: stackoverflow question Message-ID: <4F5A7FCA.6030109@stoneleaf.us> Hey all! I posted a question/answer on SO earlier, but there seems to be some confusion around either the question or the answer (judging from the comments). http://stackoverflow.com/q/9638921/208880 If anyone here is willing to take a look at it and let me know if I did not write it well, I would appreciate the feedback. Here's the question text: ------------------------ I'm writing a metaclass to do some cool stuff, and part of its processing is to check that certain attributes exist when the class is created. Some of these are mutable, and would normally be set in `__init__`, but since `__init__` isn't run until the instance is created the metaclass won't know that the attribute *will* be created, and raises an error. I could do something like: class Test(meta=Meta): mutable = None def __init__(self): self.mutable = list() But that isn't very elegant, and also violates DRY. What I need is some way to have: class Test(metaclass=Meta): mutable = list() t1 = Test() t2 = Test() t1.mutable.append('one') t2.mutable.append('two') t1.mutable # prints ['one'] t2.mutable # prints ['two'] Any ideas on how this can be accomplished? Also, the metaclass doing the checking doesn't care what type of object the attribute is, only that it is there. --------------------------- and the answer text: ------------------- There are a couple ways to do this: 1. Have the metaclass check all the attributes, and if they are one of the mutables (`list`, `dict`, `set`, etc.) replace the attribute with a descriptor that will activate on first access and update the instance with a fresh copy of the mutable. 2. Provide the descriptor from (1) as a decorator to be used when writing the class. I prefer (2) is it gives complete control to the class author, and simplifies those cases where the class-level mutable attribute *should* be shared amongst all the instances. Here's the decorator-descriptor: class ReplaceMutable: def __init__(self, func): self.func = func def __call__(self): return self def __get__(self, instance, owner): if instance is None: return self result = self.func() setattr(instance, self.func.__name__, result) return result and the test class: class Test: @ReplaceMutable def mutable(): return list() t1 = Test() t2 = Test() t1.mutable.append('one') t2.mutable.append('two') print(t1.mutable) print(t2.mutable) How it works: Just like `property`, `ReplaceMutable` is a descriptor object with the same name as the attribute it is replacing. Unlike `property`, it does not define `__set__` nor `__delete__`, so when code tries to rebind the name (`mutable` in the test above) in the instance Python will allow it to do so. This is the same idea behind caching descriptors. `ReplaceMutable` is decorating a function (with the name of the desired attribute) that simply returns whatever the instance level attribute should be initialized with (an empty `list` in the example above). So the first time the attribute is looked up on an instance it will not be found in the instance dictionary and Python will activate the descriptor; the descriptor then calls the function to retrieve the initial object/data/whatever, stores it in the instance, and then returns it. The next time that attribute is accessed *on that instance* it will be in the instance dictionary, and that is what will be used. ----------------------------------- Thanks, ~Ethan~ From businessmother at hotmail.com Fri Mar 9 17:38:48 2012 From: businessmother at hotmail.com (businessmother at hotmail.com) Date: Fri, 9 Mar 2012 14:38:48 -0800 (PST) Subject: TIME SENSITIVE] Please Open Immediately! Message-ID: <9567e466-be65-4d58-88ac-f628a85ff2ca@h20g2000yqd.googlegroups.com> TIME SENSITIVE] Please Open Immediately! http://signup.wazzub.info/?lrRef=c18fbd9 Dear partners, Sometimes it is most important to act fast. Imagine a project that has the potential to become the next GooTwitFaceuPon and you have the advantage to be one of the first to join ? BEFORE OFFICIAL PRE-LAUNCH. F*R*E*E Forever (NO FEES) + NO AUTOSHIPS + NO JOBS TO DO +NOTHING TO SELL + NOTHING TO BUY + NOTHING TO DOWNLOAD = THE PERFECT OPPORTUNITY But you have to be fast: the earlier you pre-register without any costs, the more money you can make just by inviting other F*R*E*E members. My recommendation: Step 1 ? go here and sign up: http://signup.wazzub.info/?lrRef=c18fbd9c Step 2 ? read all the important facts at: www.wazzub.info/facts.htm Step 3 ? read ?How Is W.A.Z.Z.U.B Different? www.wazzub.info/difference.htm Step 4 ? invite your friends and partners to become a part in this success story Hurry up, act now! Accept my positive vibrations of Succe$$ and Happiness :-) Together we activate the power of "We"! Thank you, From tjreedy at udel.edu Fri Mar 9 18:16:32 2012 From: tjreedy at udel.edu (Terry Reedy) Date: Fri, 09 Mar 2012 18:16:32 -0500 Subject: stackoverflow question In-Reply-To: <4F5A7FCA.6030109@stoneleaf.us> References: <4F5A7FCA.6030109@stoneleaf.us> Message-ID: On 3/9/2012 5:10 PM, Ethan Furman wrote: > Hey all! > > I posted a question/answer on SO earlier, but there seems to be some > confusion around either the question or the answer (judging from the > comments). > > http://stackoverflow.com/q/9638921/208880 > > If anyone here is willing to take a look at it and let me know if I did > not write it well, I would appreciate the feedback > > Here's the question text: > ------------------------ > I'm writing a metaclass to do some cool stuff, and part of its > processing is to check that certain attributes exist when the class is > created. Some of these are mutable, and would normally be set in > `__init__`, but since `__init__` isn't run until the instance is created > the metaclass won't know that the attribute *will* be created, and > raises an error. a. Create an instance and see if it has the attribute. Then delete it. b. Put such tests in unit tests. c. Check the code object to see if the attribute will be created. > I could do something like: > > class Test(meta=Meta): > mutable = None > def __init__(self): > self.mutable = list() > > But that isn't very elegant, and also violates DRY. It works. It is a standard idiom for default values that are conditionally masked with an instance value. > > What I need is some way to have: > > class Test(metaclass=Meta): > mutable = list() > > t1 = Test() > t2 = Test() > t1.mutable.append('one') > t2.mutable.append('two') > t1.mutable # prints ['one'] > t2.mutable # prints ['two'] > > Any ideas on how this can be accomplished? Rewrite the __init__ code object ;-). -- Terry Jan Reedy From steve+comp.lang.python at pearwood.info Fri Mar 9 19:57:50 2012 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 10 Mar 2012 00:57:50 GMT Subject: "Decoding unicode is not supported" in unusual situation References: <4f571b94$0$12037$742ec2ed@news.sonic.net> <8762egmzfp.fsf@benfinney.id.au> <4f5749bc$0$29989$c3e8da3$5496439d@news.astraweb.com> <4f57b63f$0$11986$742ec2ed@news.sonic.net> <871up4m69h.fsf@benfinney.id.au> <4f57eeac$0$29989$c3e8da3$5496439d@news.astraweb.com> <87sjhjltsp.fsf@benfinney.id.au> <4f593178$0$11963$742ec2ed@news.sonic.net> <4f5a47f0$0$11979$742ec2ed@news.sonic.net> Message-ID: <4f5aa70e$0$30002$c3e8da3$5496439d@news.astraweb.com> On Fri, 09 Mar 2012 10:11:58 -0800, John Nagle wrote: > On 3/8/2012 2:58 PM, Prasad, Ramit wrote: >>> Right. The real problem is that Python 2.7 doesn't have distinct >>> "str" and "bytes" types. type(bytes() returns "str" is >>> assumed to be ASCII 0..127, but that's not enforced. "bytes" and "str" >>> should have been distinct types, but that would have broken much old >>> code. If they were distinct, then constructors could distinguish >>> between string type conversion (which requires no encoding >>> information) and byte stream decoding. >>> >>> So it's possible to get junk characters in a "str", and they >>> won't convert to Unicode. I've had this happen with databases which >>> were supposed to be ASCII, but occasionally a non-ASCII character >>> would slip through. >> >> bytes and str are just aliases for each other. > > That's true in Python 2.7, but not in 3.x. From 2.6 forward, > "bytes" and "str" were slowly being separated. See PEP 358. Some of the > problems in Python 2.7 come from this ambiguity. Logically, "unicode" of > "str" should be a simple type conversion from ASCII to Unicode, while > "unicode" of "bytes" should require an encoding. But because of the > bytes/str ambiguity in Python 2.6/2.7, the behavior couldn't be > type-based. This demonstrates a gross confusion about both Unicode and Python. John, I honestly don't mean to be rude here, but if you actually believe that (rather than merely expressing yourself poorly), then it seems to me that you are desperately misinformed about Unicode and are working on the basis of some serious misapprehensions about the nature of strings. I recommend you start with this: http://www.joelonsoftware.com/articles/Unicode.html In Python 2.6/2.7, there is no ambiguity between str/bytes. The two names are aliases for each other. The older name, "str", is a misnomer, since it *actually* refers to bytes (and always has, all the way back to the earliest days of Python). At best, it could be read as "byte string" or "8-bit string", but the emphasis should always be on the *bytes*. str is NOT "assumed to be ASCII 0..127", and it never has been. Python's str prior to version 3.0 has *always* been bytes, it just never used that name. For example, in Python 2.4, help(chr) explicitly supports characters with ordinal 0...255: Help on built-in function chr in module __builtin__: chr(...) chr(i) -> character Return a string of one character with ordinal i; 0 <= i < 256. I can go all the way back to Python 0.9, which was so primitive it didn't even accept "" as string delimiters, and the str type was still based on bytes, with explicit support for non-ASCII values: steve at runes:~/Downloads/python-0.9.1$ ./python0.9.1 >>> print 'This is *not* ASCII \xCA see the non-ASCII byte.' This is *not* ASCII ? see the non-ASCII byte. Any conversion from bytes (including Python 2 strings) to Unicode is ALWAYS a decoding operation. It can't possibly be anything else. If you think that it can be, you don't understand the relationship between strings, Unicode and bytes. -- Steven From timr at probo.com Sat Mar 10 02:39:35 2012 From: timr at probo.com (Tim Roberts) Date: Fri, 09 Mar 2012 23:39:35 -0800 Subject: PyUSB available for current versions of Windows? References: <4f5a3b5f$0$11993$742ec2ed@news.sonic.net> Message-ID: John Nagle wrote: > I want to enumerate the available USB devices. All I really >need is the serial number of the USB devices available to PySerial. >... >(When you plug in a USB device on Windows, it's assigned the next >available COM port number. On a reboot, the numbers are reassigned. >So if you have multiple USB serial ports, there's a problem.) You can use the SetupDi APIs to enumerate the list of USB devices, but that won't tell you what COM port they were assigned to. You can look at the source code for USBView, which is available in the Windows driver kit. It can enumerate the hubs and ports and even fetch their descriptors (by talking to the USB hub and host controller drivers), but again it won't tell you what COM port was assigned. > PyUSB can supposedly do this, but the documentation is misleading. >It makes a big point of being "100% Python", but that's because it's >just glue code to a platform-specific "back end" provided by someone >else. Of course it is. You can't access devices in Windows without a kernel driver. > There's an old Windows back-end at >"http://www.craftedge.com/products/libusb.html", but it was written for >Windows XP, and can supposedly be run in "compatibility mode" on Windows >Vista. Current versions of Windows, who knows? It's not open source, and >it comes from someone who sells paper-cutting machines for crafters. It IS open source. They are shipping libusb-win32 -- exactly the same library you reference below. Until Microsoft released WinUSB, libusb-win32 was the ONLY generic USB driver available on Windows. It runs just fine on Windows 7. >There's another Windows back end at > https://sourceforge.net/apps/trac/libusb-win32/wiki >but it involves installing a low-level driver in Windows. It's the same backend. A driver is required in order to access devices on Windows. It's required on Linux as well, but Linux happens to include a generic USB driver in the kernel. A more modern generic USB driver and library is available at http://www.libusb.org. There is a Python binding for it. >I especially like the instruction "Close all applications which use USB >devices before installing." Does this include the keyboard and mouse? No, that's just being overly cautious. Libusb-Win32 can act as a filter driver, inserting itself into an existing USB stack, but to do so the device stack you are filtering must be idle. -- Tim Roberts, timr at probo.com Providenza & Boekelheide, Inc. From meerad41 at gmail.com Sat Mar 10 05:00:30 2012 From: meerad41 at gmail.com (meeradevi) Date: Sat, 10 Mar 2012 02:00:30 -0800 (PST) Subject: view this wonderful Message-ID: http://123maza.com/46/flower816/ From ejjyrex at gmail.com Sat Mar 10 05:21:46 2012 From: ejjyrex at gmail.com (ejjy) Date: Sat, 10 Mar 2012 02:21:46 -0800 (PST) Subject: steps to solve bugs Message-ID: Hi, I am currently learning python and I would like to solve some easy bugs for my own practice. I am confused over following the steps explained in the Python website, though I have the appropriate software necessities. Kindly some one please tell me in a more practical and easy way. Thanks. Regards, Ejaj From news at schwertberger.de Sat Mar 10 06:20:37 2012 From: news at schwertberger.de (Dietmar Schwertberger) Date: Sat, 10 Mar 2012 12:20:37 +0100 Subject: PyUSB available for current versions of Windows? In-Reply-To: <4f5a3b5f$0$11993$742ec2ed@news.sonic.net> References: <4f5a3b5f$0$11993$742ec2ed@news.sonic.net> Message-ID: Am 09.03.2012 18:18, schrieb John Nagle: > I want to enumerate the available USB devices. All I really > need is the serial number of the USB devices available to PySerial. > (When you plug in a USB device on Windows, it's assigned the next > available COM port number. On a reboot, the numbers are reassigned. > So if you have multiple USB serial ports, there's a problem.) You can get the required information using Windows Management Instrumentation (WMI). See e.g. here for serial port information: http://www.activexperts.com/admin/scripts/wmi/python/0358/ I'm using code like this to find my USB CDC devices from the device description: import win32com.client strComputer = "." objWMIService = win32com.client.Dispatch("WbemScripting.SWbemLocator") objSWbemServices = objWMIService.ConnectServer(strComputer,"root\cimv2") colItems = objSWbemServices.ExecQuery("SELECT Description,DeviceID FROM Win32_SerialPort") COM_ports = [] for objItem in colItems: print objItem.Description,objItem.DeviceID if objItem.Description == "USB CDC Simple IO HC9S08JSxx": COM_ports.append( objItem.DeviceID ) On some PCs the query took some seconds. Regards, Dietmar From ahsanbagwan at gmail.com Sat Mar 10 07:34:35 2012 From: ahsanbagwan at gmail.com (sl33k) Date: Sat, 10 Mar 2012 04:34:35 -0800 (PST) Subject: Invalid syntax error Message-ID: <46758542-1bd6-43fe-8e80-bcf14b7d88d8@pi6g2000pbc.googlegroups.com> I'm trying project euler problem 3 and I've hit the wall with this error. What could be the problem here? l=[] >>> num=600851475143 >>> i=1 >>> while i<=num: ... if num%i==0: ... l.append(i) ... i+=1 ... print max(l) File "", line 5 print max(l) ^ SyntaxError: invalid syntax From amit.pureenergy at gmail.com Sat Mar 10 07:43:01 2012 From: amit.pureenergy at gmail.com (Amit Sethi) Date: Sat, 10 Mar 2012 18:13:01 +0530 Subject: Invalid syntax error In-Reply-To: <46758542-1bd6-43fe-8e80-bcf14b7d88d8@pi6g2000pbc.googlegroups.com> References: <46758542-1bd6-43fe-8e80-bcf14b7d88d8@pi6g2000pbc.googlegroups.com> Message-ID: Its an indentation error -- A-M-I-T S|S From bahamutzero8825 at gmail.com Sat Mar 10 07:46:28 2012 From: bahamutzero8825 at gmail.com (Andrew Berg) Date: Sat, 10 Mar 2012 06:46:28 -0600 Subject: Invalid syntax error In-Reply-To: <46758542-1bd6-43fe-8e80-bcf14b7d88d8@pi6g2000pbc.googlegroups.com> References: <46758542-1bd6-43fe-8e80-bcf14b7d88d8@pi6g2000pbc.googlegroups.com> Message-ID: <4F5B4D24.5050108@gmail.com> On 3/10/2012 6:34 AM, sl33k wrote: > I'm trying project euler problem 3 and I've hit the wall with this > error. What could be the problem here? > > l=[] >>>> num=600851475143 >>>> i=1 >>>> while i<=num: > ... if num%i==0: > ... l.append(i) > ... i+=1 > ... print max(l) > File "", line 5 > print max(l) > ^ > SyntaxError: invalid syntax > > You must be using Python 3. Along with many, many other changes, Python 3 uses a print function instead of a print statement. If you want to follow along with the problems, use the version of Python it uses (2.7 is probably safe if there isn't a version specified). -- CPython 3.2.2 | Windows NT 6.1.7601.17640 From vlastimil.brom at gmail.com Sat Mar 10 07:54:02 2012 From: vlastimil.brom at gmail.com (Vlastimil Brom) Date: Sat, 10 Mar 2012 13:54:02 +0100 Subject: Invalid syntax error In-Reply-To: <46758542-1bd6-43fe-8e80-bcf14b7d88d8@pi6g2000pbc.googlegroups.com> References: <46758542-1bd6-43fe-8e80-bcf14b7d88d8@pi6g2000pbc.googlegroups.com> Message-ID: 2012/3/10 sl33k : > I'm trying project euler problem 3 and I've hit the wall with this > error. What could be the problem here? > > ?l=[] >>>> num=600851475143 >>>> i=1 >>>> while i<=num: > ... ? ? if num%i==0: > ... ? ? ? ? l.append(i) > ... ? ? i+=1 > ... print max(l) > ?File "", line 5 > ? ?print max(l) > ? ? ? ?^ > SyntaxError: invalid syntax > > > -- > http://mail.python.org/mailman/listinfo/python-list Hi, if you are using python 3, you'd (most likely) need to adapt the code written for python 2. see: http://docs.python.org/py3k/whatsnew/3.0.html#print-is-a-function hth, vbr From liuerfire at gmail.com Sat Mar 10 08:00:22 2012 From: liuerfire at gmail.com (liuerfire Wang) Date: Sat, 10 Mar 2012 05:00:22 -0800 (PST) Subject: Invalid syntax error In-Reply-To: <46758542-1bd6-43fe-8e80-bcf14b7d88d8@pi6g2000pbc.googlegroups.com> References: <46758542-1bd6-43fe-8e80-bcf14b7d88d8@pi6g2000pbc.googlegroups.com> Message-ID: <19487693.1432.1331384422933.JavaMail.geo-discussion-forums@pbcgj3> ? 2012?3?10????UTC+8??8?34?35??sl33k??? > I'm trying project euler problem 3 and I've hit the wall with this > error. What could be the problem here? > > l=[] > >>> num=600851475143 > >>> i=1 > >>> while i<=num: > ... if num%i==0: > ... l.append(i) > ... i+=1 > ... print max(l) > File "", line 5 > print max(l) > ^ > SyntaxError: invalid syntax It is a indentation error. It should be like: >>> while i<=num: ... if num%i==0: ... l.append(i) ... i+=1 ... >>> print max(l) From ahsanbagwan at gmail.com Sat Mar 10 08:00:35 2012 From: ahsanbagwan at gmail.com (Ahsan) Date: Sat, 10 Mar 2012 18:30:35 +0530 Subject: Invalid syntax error In-Reply-To: References: <46758542-1bd6-43fe-8e80-bcf14b7d88d8@pi6g2000pbc.googlegroups.com> Message-ID: Just checked my version. Its showing 2.6.5. >>> sys.version '2.6.5 (r265:79063, Apr 16 2010, 13:09:56) \n[GCC 4.4.3]' -------------- next part -------------- An HTML attachment was scrubbed... URL: From sam.drpython at gmail.com Sat Mar 10 08:10:01 2012 From: sam.drpython at gmail.com (Sam Sam) Date: Sat, 10 Mar 2012 18:40:01 +0530 Subject: No subject Message-ID: How to change the color of source browser in DrPython? -------------- next part -------------- An HTML attachment was scrubbed... URL: From gd.usenet at spamfence.net Sat Mar 10 08:17:06 2012 From: gd.usenet at spamfence.net (=?ISO-8859-1?Q?G=FCnther?= Dietrich) Date: Sat, 10 Mar 2012 14:17:06 +0100 Subject: Invalid syntax error References: <46758542-1bd6-43fe-8e80-bcf14b7d88d8@pi6g2000pbc.googlegroups.com> Message-ID: In article <46758542-1bd6-43fe-8e80-bcf14b7d88d8 at pi6g2000pbc.googlegroups.com>, sl33k wrote: >I'm trying project euler problem 3 and I've hit the wall with this >error. What could be the problem here? > > l=[] >>>> num=600851475143 >>>> i=1 >>>> while i<=num: >... if num%i==0: >... l.append(i) >... i+=1 >... print max(l) > File "", line 5 > print max(l) > ^ >SyntaxError: invalid syntax You have to insert an empty line after the end of the while loop (before the print command), so that the interpreter can run and finish the loop before it is to print the result. Best regards, G?nther From jpwagner at mweb.co.za Sat Mar 10 08:20:50 2012 From: jpwagner at mweb.co.za (Johannes Wagner) Date: Sat, 10 Mar 2012 15:20:50 +0200 Subject: nmea Message-ID: can any1 help me on how to get python to read nmea data? From awilliam at whitemice.org Sat Mar 10 08:36:03 2012 From: awilliam at whitemice.org (Adam Tauno Williams) Date: Sat, 10 Mar 2012 08:36:03 -0500 Subject: Can't get around HTTP/401 response using SUDS [SOLVED] In-Reply-To: <4F593AAC.30604@gmail.com> References: <1331221455.3087.14.camel@linux-dauq.site> <4F593AAC.30604@gmail.com> Message-ID: <1331386563.3103.3.camel@linux-dauq.site> On Fri, 2012-03-09 at 00:03 +0100, Rafael Dur?n Casta?eda wrote: > El 08/03/12 16:44, Adam Tauno Williams escribi?: > > SUDS version 0.4 pn x86_64 Python 2.7 > > I'm having a bear of a time getting HTTP Basic Authentication to work > > for a SOAP request via suds. Also using an HTTP proxy server. > > In WireShark I just see a request - > > GET http://...../services/services/JobService-0.0.1?wsdl HTTP/1.1 > > Accept-Encoding: identity > > Host: ....... > > Connection: close > > User-Agent: Python-urllib/2.7 > > This doesn't contain any authentication credentials so the response is > > HTTP/401, and the client doesn't retry with credentials. The response > > does come from the remote as I can see there is a WWW-Authenticate > > header and it is from an Apache Tomcat server - so it makes it through > > the proxy server. > > Code > > ================ > > url = 'http://....../services/services/JobService-0.0.1?wsdl' > > proxy = urllib2.ProxyHandler({'http': 'http://.....:3128'}) > > transport = suds.transport.http.HttpAuthenticated() > > transport.urlopener = urllib2.build_opener(proxy) > > client = suds.client.Client(url, transport=transport, > > username='******', password='********') > > .... > > "/usr/local/lib/python2.7/site-packages/suds-0.4-py2.7.egg/suds/transport/http.py", line 64, in open > > raise TransportError(str(e), e.code, e.fp) > > suds.transport.TransportError: HTTP Error 401: Unauthorized > When I've got issues like yours, I usually try using a console client > (telnet/curl/wget,...) adding all needed headers/data manually so I'm > totally sure the request is OK, if everything goes Ok you know your > python code need to be reviewed but when you are under proxies you can > find a lot of not python related issues (bad gateways, using proxy when > it shouldn't or vice-versa, requests changed by proxy,....). Nope, proxy works perfectly [for hundreds of clients]. The problem turned out to be that SUDS uses the specified transport for SOAP requests/operations. When requesting the WSDL in order to built the client interface it doesn't use the transport. So either download the service description to a local file and use that or just use urllib2 to retrieve the WSDL to a buffer (outside of SUDS). Once the client is created the requests work with authentication and via the proxy with no issues. > wireshark can be very useful but in situations like this I usually > prefer tcpflow output, I think the request/response flow showed is > really useful, but that's a personal preference. Wireshark does the same thing; you just select a packet in the stream and then select "follow conversation". -- System & Network Administrator [ LPI & NCLA ] OpenGroupware Developer Adam Tauno Williams From roy at panix.com Sat Mar 10 09:05:24 2012 From: roy at panix.com (Roy Smith) Date: Sat, 10 Mar 2012 09:05:24 -0500 Subject: nmea References: Message-ID: In article , "Johannes Wagner" wrote: > can any1 help me on how to get python to read nmea data? I assume you're talking about National Marine Electronics Association, i.e. the protocol GPSs use to talk to plotters and the like? A quick google search for "nmea python" found a bunch of good hits. This one looks like it's probably where you want to start. http://blog.scaryclam.co.uk/2011/07/22/pynmea-a-python-nmea-library/ From gelonida at gmail.com Sat Mar 10 09:48:48 2012 From: gelonida at gmail.com (Gelonida N) Date: Sat, 10 Mar 2012 15:48:48 +0100 Subject: How to know that two pyc files contain the same code Message-ID: Hi, I want to know whether two .pyc files are identical. With identical I mean whether they contain the same byte code. Unfortunately it seems, that .pyc files contain also something like the time stamp of the related source file. So though two pyc files contain the same byte code, they will not be byte identical. One option, that I found is to use python -m unpyclib.application -d filename.pyc and check whether the results are identical. However even this will fail if the files were not compiled under the same absolute path name as the source filename is contained twice (at least for my trivial example) in the disassemblers output. Thanks a lot for any other idea. From gelonida at gmail.com Sat Mar 10 09:49:36 2012 From: gelonida at gmail.com (Gelonida N) Date: Sat, 10 Mar 2012 15:49:36 +0100 Subject: How to know that two pyc files contain the same code Message-ID: Hi, I want to know whether two .pyc files are identical. With identical I mean whether they contain the same byte code. Unfortunately it seems, that .pyc files contain also something like the time stamp of the related source file. So though two pyc files contain the same byte code, they will not be byte identical. One option, that I found is to use python -m unpyclib.application -d filename.pyc and check whether the results are identical. However even this will fail if the files were not compiled under the same absolute path name as the source filename is contained twice (at least for my trivial example) in the disassemblers output. Thanks a lot for any other idea. From bl0ckedusersoft at gmail.com Sat Mar 10 10:08:18 2012 From: bl0ckedusersoft at gmail.com (Bl0ckeduser) Date: Sat, 10 Mar 2012 10:08:18 -0500 Subject: How to know that two pyc files contain the same code In-Reply-To: References: Message-ID: Gelonida N wrote: > Hi, > > I want to know whether two .pyc files are identical. > > With identical I mean whether they contain the same byte code. > > Unfortunately it seems, that .pyc files contain also something like the > time stamp of the related source file. > > So though two pyc files contain the same byte code, they will not be > byte identical. > > One option, that I found is to use > python -m unpyclib.application -d filename.pyc and check whether the > results are identical. > > > However even this will fail if the files were not compiled under the > same absolute path name as the source filename is contained twice (at > least for my trivial example) in the disassemblers output. > > > Thanks a lot for any other idea. > Try using the disassembler code here: http://nedbatchelder.com/blog/200804/the_structure_of_pyc_files.html and removing from it the parts which print out the timestamp and the absolute path. (Two different lines in the source). That seems to work for me. From __peter__ at web.de Sat Mar 10 11:21:00 2012 From: __peter__ at web.de (Peter Otten) Date: Sat, 10 Mar 2012 17:21 +0100 Subject: How to know that two pyc files contain the same code References: Message-ID: Gelonida N wrote: > I want to know whether two .pyc files are identical. > > With identical I mean whether they contain the same byte code. > > Unfortunately it seems, that .pyc files contain also something like the > time stamp of the related source file. > > So though two pyc files contain the same byte code, they will not be > byte identical. > > One option, that I found is to use > python -m unpyclib.application -d filename.pyc and check whether the > results are identical. Or you could just strip off the first 8 (may be version-dependent) bytes before you compare the file contents. > However even this will fail if the files were not compiled under the > same absolute path name as the source filename is contained twice (at > least for my trivial example) in the disassemblers output. That's another problem. If you are OK with likelihood you can replace the filename of the old code with that of the new one before you compare. From ethan at stoneleaf.us Sat Mar 10 11:56:58 2012 From: ethan at stoneleaf.us (Ethan Furman) Date: Sat, 10 Mar 2012 08:56:58 -0800 Subject: stackoverflow question In-Reply-To: References: <4F5A7FCA.6030109@stoneleaf.us> Message-ID: <4F5B87DA.5040401@stoneleaf.us> Terry Reedy wrote: Thanks for the review, Terry! > On 3/9/2012 5:10 PM, Ethan Furman wrote: >> >> http://stackoverflow.com/q/9638921/208880 >> >> If anyone here is willing to take a look at it and let me know if I did >> not write it well, I would appreciate the feedback >> >> Here's the question text: >> ------------------------ >> I'm writing a metaclass to do some cool stuff, and part of its >> processing is to check that certain attributes exist when the class is >> created. Some of these are mutable, and would normally be set in >> `__init__`, but since `__init__` isn't run until the instance is created >> the metaclass won't know that the attribute *will* be created, and >> raises an error. > > a. Create an instance and see if it has the attribute. Then delete it. If the class takes any arguments, I won't be able to create instances of it. > b. Put such tests in unit tests. Always a good idea -- but this is the responsibility of the class author (who may not be me ;). > c. Check the code object to see if the attribute will be created. I have no idea how to do this -- pointers? >> I could do something like: >> >> class Test(meta=Meta): >> mutable = None >> def __init__(self): >> self.mutable = list() >> >> But that isn't very elegant, and also violates DRY. > > It works. It is a standard idiom for default values that are > conditionally masked with an instance value. >> >> What I need is some way to have: >> >> class Test(metaclass=Meta): >> mutable = list() >> >> t1 = Test() >> t2 = Test() >> t1.mutable.append('one') >> t2.mutable.append('two') >> t1.mutable # prints ['one'] >> t2.mutable # prints ['two'] >> >> Any ideas on how this can be accomplished? > > Rewrite the __init__ code object ;-). Ouch. Can that be done in a cross-implementation way? Any pointers? Still, I'm not sure I'd want to go this route, anyway, as it makes it more difficult to get an actual class-wide mutable (rare though they are). Thanks again for your feedback, I really appreciate it. ~Ethan~ From ian.g.kelly at gmail.com Sat Mar 10 12:07:08 2012 From: ian.g.kelly at gmail.com (Ian Kelly) Date: Sat, 10 Mar 2012 10:07:08 -0700 Subject: Invalid syntax error In-Reply-To: References: <46758542-1bd6-43fe-8e80-bcf14b7d88d8@pi6g2000pbc.googlegroups.com> Message-ID: On Sat, Mar 10, 2012 at 6:17 AM, G?nther Dietrich wrote: > In article > <46758542-1bd6-43fe-8e80-bcf14b7d88d8 at pi6g2000pbc.googlegroups.com>, > ?sl33k wrote: > >>I'm trying project euler problem 3 and I've hit the wall with this >>error. What could be the problem here? >> >> l=[] >>>>> num=600851475143 >>>>> i=1 >>>>> while i<=num: >>... ? ? if num%i==0: >>... ? ? ? ? l.append(i) >>... ? ? i+=1 >>... print max(l) >> ?File "", line 5 >> ? ?print max(l) >> ? ? ? ?^ >>SyntaxError: invalid syntax > > You have to insert an empty line after the end of the while loop (before > the print command), so that the interpreter can run and finish the loop > before it is to print the result. Note that this only applies to the interactive interpreter, to help it identify when to terminate the block and pass on to the compiler. When running a script, the extra blank lines are unnecessary, and indentation alone identifies the blocks. From meerad41 at gmail.com Sat Mar 10 12:36:54 2012 From: meerad41 at gmail.com (meeradevi) Date: Sat, 10 Mar 2012 09:36:54 -0800 (PST) Subject: fetching pretty girls world Message-ID: http://123maza.com/46/flower816/ From cjw at ncf.ca Sat Mar 10 12:58:55 2012 From: cjw at ncf.ca (Colin J. Williams) Date: Sat, 10 Mar 2012 12:58:55 -0500 Subject: newb __init__ inheritance In-Reply-To: <1c6db866-6fa3-4de5-96de-51d6720a1300@x17g2000yqj.googlegroups.com> References: <1c6db866-6fa3-4de5-96de-51d6720a1300@x17g2000yqj.googlegroups.com> Message-ID: On 08/03/2012 10:25 AM, hyperboogie wrote: > Hello everyone. > > This is my first post in this group. > I started learning python a week ago from the "dive into python" e- > book and thus far all was clear. > However today while reading chapter 5 about objects and object > orientation I ran into something that confused me. > it says here: > http://www.diveintopython.net/object_oriented_framework/defining_classes.html#fileinfo.class.example > > "__init__ methods are optional, but when you define one, you must > remember to explicitly call the ancestor's __init__ method (if it > defines one). This is more generally true: whenever a descendant wants > to extend the behavior of the ancestor, the descendant method must > explicitly call the ancestor method at the proper time, with the > proper arguments. " > > However later on in the chapter: > http://www.diveintopython.net/object_oriented_framework/userdict.html > > it says: > "Methods are defined solely by their name, and there can be only one > method per class with a given name. So if a descendant class has an > __init__ method, it always overrides the ancestor __init__ method, > even if the descendant defines it with a different argument list. And > the same rule applies to any other method. " > > My question is if __init__ in the descendant class overrides __init__ > in the parent class how can I call the parent's __init__ from the > descendant class - I just overrode it didn't I? > > Am I missing something more fundamental here? > Thanks The mro function [Method Resolution Order]is not too well advertised in the docs. This should illustrate its usage: #!/usr/bin/env python class A(): def __init__(self): z= 1 def ringA(self): print ('aaa') def ringB(self): print('bbb') class B(A): def __init__(self): z= 2 def ringB(self): print('BBB') a= A() b= B() b.ringB() b.ringA() b.__class__.mro()[1].ringB(b) z= 1 def main(): pass if __name__ == '__main__': main() I'm not sure that the class initialization is required. Good luck, Colin W. From tjreedy at udel.edu Sat Mar 10 13:00:03 2012 From: tjreedy at udel.edu (Terry Reedy) Date: Sat, 10 Mar 2012 13:00:03 -0500 Subject: stackoverflow question In-Reply-To: <4F5B87DA.5040401@stoneleaf.us> References: <4F5A7FCA.6030109@stoneleaf.us> <4F5B87DA.5040401@stoneleaf.us> Message-ID: <4F5B96A3.2010906@udel.edu> On 3/10/2012 11:56 AM, Ethan Furman wrote: >>> I'm writing a metaclass to do some cool stuff, and part of its >>> processing is to check that certain attributes exist when the class is >>> created. Some of these are mutable, and would normally be set in >>> `__init__`, but since `__init__` isn't run until the instance is created >>> the metaclass won't know that the attribute *will* be created, and >>> raises an error. >> c. Check the code object to see if the attribute will be created. > > I have no idea how to do this -- pointers? Capture output of dis.dis(targetclass.__init__) by temporarily setting sys.stdout to StringIO object. (There is tracker issue to make lines available to a program without doing this.) >>> from dis import dis >>> def f(self): self.attr = 1 >>> dis(f) 2 0 LOAD_CONST 1 (1) 3 LOAD_FAST 0 (self) 6 STORE_ATTR 0 (attr) 9 LOAD_CONST 0 (None) 12 RETURN_VALUE Look for STORE_ATTR line with target attribute name. If you want to check for wacko code that does setattr(self, 'attr', value), try it in 'f' and dis again. Anything to do with code objects (and dis module) is implementation and version specific --- Terry Jan Reedy From miki.tebeka at gmail.com Sat Mar 10 13:27:17 2012 From: miki.tebeka at gmail.com (Miki Tebeka) Date: Sat, 10 Mar 2012 10:27:17 -0800 (PST) Subject: steps to solve bugs In-Reply-To: References: Message-ID: <2972152.114.1331404037861.JavaMail.geo-discussion-forums@ynll40> Greetings, > I am confused over following the steps > explained in the Python website, Are you talking about http://docs.python.org/devguide/? > Kindly some one please tell me in a more > practical and easy way. Can you tell in more details what are the problems you face? This will help us help you more. All the best, -- Miki From cosmius at gmail.com Sat Mar 10 14:33:36 2012 From: cosmius at gmail.com (Cosmia Luna) Date: Sat, 10 Mar 2012 11:33:36 -0800 (PST) Subject: How to re-implement the crypt.crypt function? Message-ID: <28304124.1374.1331408016748.JavaMail.geo-discussion-forums@yncd8> I'm not searching for a full solution and only want to know how to use hashlib to create a equivalent string like crypt.crypt('123456', '$6$ds41p/9VMA.BHH0U') returns the string below. '$6$ds41p/9VMA.BHH0U$yv25s7jLxTRKLDNjIvT0Qc2jbcqdFRi5.PftO3cveTvjK49JhwCarIowOfrrNPD/PpYT3n6oNDIbjAONh8RXt1' I tried: from hashlib import sha512 from base64 import b64encode, b64decode salt='ds41p/9VMA.BHH0U' pwd='123456' b64encode( sha512(pwd+salt).digest(), altchars='./' ) b64encode( sha512(salt+pwd).digest(), altchars='./' ) b64encode( sha512( pwd + b64decode(salt, altchars='./') ).digest(), altchars='./') b64encode( sha512( b64decode(salt, altchars='./') + pwd ).digest(), altchars='./') of course none of the four returns the value I want, 'yv25s7jLxTRKLDNjIvT0Qc2jbcqdFRi5.PftO3cveTvjK49JhwCarIowOfrrNPD/PpYT3n6oNDIbjAONh8RXt1', how can I get the value? I can't use crypt.crypt because of the consideration of cross-platform. Thanks, Cosmia From angrybaldguy at gmail.com Sat Mar 10 15:03:25 2012 From: angrybaldguy at gmail.com (Owen Jacobson) Date: Sat, 10 Mar 2012 15:03:25 -0500 Subject: stackoverflow question References: Message-ID: <2012031015032562036-angrybaldguy@gmailcom> On 2012-03-09 22:10:18 +0000, Ethan Furman said: > Hey all! > > I posted a question/answer on SO earlier, but there seems to be some > confusion around either the question or the answer (judging from the > comments). > > http://stackoverflow.com/q/9638921/208880 > > If anyone here is willing to take a look at it and let me know if I did > not write it well, I would appreciate the feedback. > > > Here's the question text: > ------------------------ > I'm writing a metaclass to do some cool stuff, and part of its > processing is to check that certain attributes exist when the class is > created. Some of these are mutable, and would normally be set in > `__init__`, but since `__init__` isn't run until the instance is > created the metaclass won't know that the attribute *will* be created, > and raises an error. I could do something like: > > class Test(meta=Meta): > mutable = None > def __init__(self): > self.mutable = list() > > But that isn't very elegant, and also violates DRY. > > What I need is some way to have: > > class Test(metaclass=Meta): > mutable = list() > > t1 = Test() > t2 = Test() > t1.mutable.append('one') > t2.mutable.append('two') > t1.mutable # prints ['one'] > t2.mutable # prints ['two'] > > Any ideas on how this can be accomplished? > > Also, the metaclass doing the checking doesn't care what type of object > the attribute is, only that it is there. > --------------------------- Why check what you can ensure? The __init__ function your metaclass passes to type() doesn't have to be the __init__ method your metaclass received. Consider the following: >>> import functools as f >>> >>> def make_init(real_init): >>> """Define an __init__ method that ensures ``self.mutable`` is set. If the >>> passed ``real_init`` function later replaces ``self.mutable``, that value >>> is preserved; otherwise, ``self.mutable`` is set to a new, empty list. >>> >>> Arguments to the generated ``__init__`` method are passed to the original >>> ``real_init`` unchanged. >>> """ >>> def __init__(self, *args, **kwargs): >>> self.mutable = list() >>> if real_init is not None: >>> return real_init(self, *args, **kwargs) >>> if real_init is not None: >>> f.update_wrapper(__init__, real_init) >>> return __init__ >>> >>> class Meta(type): >>> def __new__(meta, name, parents, attributes): >>> attributes['__init__'] = make_init(attributes.get('__init__', None)) >>> return type.__new__(Meta, name, parents, attributes) >>> >>> class C(object): >>> __metaclass__ = Meta >>> >>> a, b = C(), C() >>> >>> a.mutable.append(3) >>> b.mutable.append(5) >>> >>> a.mutable [3] >>> b.mutable [5] All instances of classes whose metaclass is Meta will, guaranteed, have an instance field named 'mutable'. Its value is a list created at instance creation time, unless the instance's __init__ provides a different value. What've I missed? -o From roy at panix.com Sat Mar 10 15:15:46 2012 From: roy at panix.com (Roy Smith) Date: Sat, 10 Mar 2012 15:15:46 -0500 Subject: How to re-implement the crypt.crypt function? References: <28304124.1374.1331408016748.JavaMail.geo-discussion-forums@yncd8> Message-ID: In article <28304124.1374.1331408016748.JavaMail.geo-discussion-forums at yncd8>, Cosmia Luna wrote: > I'm not searching for a full solution and only want to know how to use > hashlib to create a equivalent string like > > crypt.crypt('123456', '$6$ds41p/9VMA.BHH0U') returns the string below. > > '$6$ds41p/9VMA.BHH0U$yv25s7jLxTRKLDNjIvT0Qc2jbcqdFRi5.PftO3cveTvjK49JhwCarIowO > frrNPD/PpYT3n6oNDIbjAONh8RXt1' > [...] > I can't use crypt.crypt because of the > consideration of cross-platform. Just out of curiosity, why do you want to do this? The python crypt module uses the crypt library supplied by the operating system (which is why it only works on unix). The algorithm implemented is a modification of DES, i.e. a salt string is used to change some of the tables used in the DES computation. It goes back to the ancient days of unix. By today's standards, the algorithm isn't considered very strong. The only place I'm aware that uses it is unix password files, and even there many (most?) systems have replaced it with something stronger such as SHA1. Maybe Apache .htaccess files? I don't know what your use case is, but unless you're doing something silly like trying to execute a dictionary attack against a unix password file, it's almost certain that you'd do better to just use SHA1. From lists at cheimes.de Sat Mar 10 15:16:52 2012 From: lists at cheimes.de (Christian Heimes) Date: Sat, 10 Mar 2012 21:16:52 +0100 Subject: How to re-implement the crypt.crypt function? In-Reply-To: <28304124.1374.1331408016748.JavaMail.geo-discussion-forums@yncd8> References: <28304124.1374.1331408016748.JavaMail.geo-discussion-forums@yncd8> Message-ID: Am 10.03.2012 20:33, schrieb Cosmia Luna: > I'm not searching for a full solution and only want to know how to use hashlib to create a equivalent string like If you chance your mind and choose to use a full solution, then I highly recommend passlib [1]. It has an implementation of SHA-512 crypt as indicated by the number 6 in the header of your string. By the way "$6$ds41p/9VMA.BHH0U" is *not* the salt. Just "ds41p/9VMA.BHH0U" is the salt, 6 is a hash identifier. Christian [1] http://packages.python.org/passlib/ From lists at cheimes.de Sat Mar 10 15:36:42 2012 From: lists at cheimes.de (Christian Heimes) Date: Sat, 10 Mar 2012 21:36:42 +0100 Subject: How to re-implement the crypt.crypt function? In-Reply-To: References: <28304124.1374.1331408016748.JavaMail.geo-discussion-forums@yncd8> Message-ID: Am 10.03.2012 21:15, schrieb Roy Smith: > By today's standards, the algorithm isn't considered very strong. The > only place I'm aware that uses it is unix password files, and even there > many (most?) systems have replaced it with something stronger such as > SHA1. Maybe Apache .htaccess files? The algorithm with identifier 6 is a SHA-512 crypt algorithm with a lengthy salt (IIRC up to 1024 bits) and 40,000 rounds of SHA-512. It's the default algorithm on modern Linux machines and believed to be very secure. The large salt makes a rainbow table attack impossible and the 40,000 rounds require a lot of CPU time, even on modern systems. Christian From roy at panix.com Sat Mar 10 15:41:12 2012 From: roy at panix.com (Roy Smith) Date: Sat, 10 Mar 2012 15:41:12 -0500 Subject: How to re-implement the crypt.crypt function? References: <28304124.1374.1331408016748.JavaMail.geo-discussion-forums@yncd8> Message-ID: In article , Christian Heimes wrote: > Am 10.03.2012 21:15, schrieb Roy Smith: > > By today's standards, the algorithm isn't considered very strong. The > > only place I'm aware that uses it is unix password files, and even there > > many (most?) systems have replaced it with something stronger such as > > SHA1. Maybe Apache .htaccess files? > > The algorithm with identifier 6 is a SHA-512 crypt algorithm with a > lengthy salt (IIRC up to 1024 bits) and 40,000 rounds of SHA-512. It's > the default algorithm on modern Linux machines and believed to be very > secure. > > The large salt makes a rainbow table attack impossible and the 40,000 > rounds require a lot of CPU time, even on modern systems. But is that what crypt.crypt() does? I though it implemented the old-style triple-DES. From lists at cheimes.de Sat Mar 10 16:07:46 2012 From: lists at cheimes.de (Christian Heimes) Date: Sat, 10 Mar 2012 22:07:46 +0100 Subject: How to re-implement the crypt.crypt function? In-Reply-To: References: <28304124.1374.1331408016748.JavaMail.geo-discussion-forums@yncd8> Message-ID: Am 10.03.2012 21:41, schrieb Roy Smith: > But is that what crypt.crypt() does? I though it implemented the > old-style triple-DES. Python's crypt module is an interface to the OS' crypt() function. On some systems the crypt() function supports additional algorithms. You can read it up in the notes section of crypt(3): http://linux.die.net/man/3/crypt Christian From ethan at stoneleaf.us Sat Mar 10 17:21:55 2012 From: ethan at stoneleaf.us (Ethan Furman) Date: Sat, 10 Mar 2012 14:21:55 -0800 Subject: stackoverflow question In-Reply-To: <2012031015032562036-angrybaldguy@gmailcom> References: <2012031015032562036-angrybaldguy@gmailcom> Message-ID: <4F5BD403.8080709@stoneleaf.us> Owen Jacobson wrote: > On 2012-03-09 22:10:18 +0000, Ethan Furman said: > >> Hey all! >> >> I posted a question/answer on SO earlier, but there seems to be some >> confusion around either the question or the answer (judging from the >> comments). >> >> http://stackoverflow.com/q/9638921/208880 >> >> If anyone here is willing to take a look at it and let me know if I >> did not write it well, I would appreciate the feedback. >> >> >> Here's the question text: >> ------------------------ >> I'm writing a metaclass to do some cool stuff, and part of its >> processing is to check that certain attributes exist when the class is >> created. Some of these are mutable, and would normally be set in >> `__init__`, but since `__init__` isn't run until the instance is >> created the metaclass won't know that the attribute *will* be created, >> and raises an error. I could do something like: >> >> class Test(meta=Meta): >> mutable = None >> def __init__(self): >> self.mutable = list() >> >> But that isn't very elegant, and also violates DRY. >> >> What I need is some way to have: >> >> class Test(metaclass=Meta): >> mutable = list() >> >> t1 = Test() >> t2 = Test() >> t1.mutable.append('one') >> t2.mutable.append('two') >> t1.mutable # prints ['one'] >> t2.mutable # prints ['two'] >> >> Any ideas on how this can be accomplished? >> >> Also, the metaclass doing the checking doesn't care what type of >> object the attribute is, only that it is there. >> --------------------------- > > Why check what you can ensure? The __init__ function your metaclass > passes to type() doesn't have to be the __init__ method your metaclass > received. Consider the following: > >>>> import functools as f >>>> >>>> def make_init(real_init): >>>> """Define an __init__ method that ensures ``self.mutable`` is >>>> set. If the >>>> passed ``real_init`` function later replaces ``self.mutable``, >>>> that value >>>> is preserved; otherwise, ``self.mutable`` is set to a new, empty >>>> list. >>>> >>>> Arguments to the generated ``__init__`` method are passed to the >>>> original >>>> ``real_init`` unchanged. >>>> """ >>>> def __init__(self, *args, **kwargs): >>>> self.mutable = list() >>>> if real_init is not None: >>>> return real_init(self, *args, **kwargs) >>>> if real_init is not None: >>>> f.update_wrapper(__init__, real_init) >>>> return __init__ >>>> >>>> class Meta(type): >>>> def __new__(meta, name, parents, attributes): >>>> attributes['__init__'] = >>>> make_init(attributes.get('__init__', None)) >>>> return type.__new__(Meta, name, parents, attributes) >>>> >>>> class C(object): >>>> __metaclass__ = Meta >>>> >>>> a, b = C(), C() >>>> >>>> a.mutable.append(3) >>>> b.mutable.append(5) >>>> >>>> a.mutable > [3] >>>> b.mutable > [5] > > All instances of classes whose metaclass is Meta will, guaranteed, have > an instance field named 'mutable'. Its value is a list created at > instance creation time, unless the instance's __init__ provides a > different value. The idea is good. The devil is in the details, as usual. How is the metaclass going to know: 1) which attributes to replace 2) what to replace them with? ~Ethan~ From cjw at ncf.ca Sat Mar 10 17:47:41 2012 From: cjw at ncf.ca (Colin J. Williams) Date: Sat, 10 Mar 2012 17:47:41 -0500 Subject: newb __init__ inheritance In-Reply-To: References: <1c6db866-6fa3-4de5-96de-51d6720a1300@x17g2000yqj.googlegroups.com> Message-ID: On 10/03/2012 12:58 PM, Colin J. Williams wrote: > On 08/03/2012 10:25 AM, hyperboogie wrote: >> Hello everyone. >> [snip] > main() > I'm not sure that the class initialization is required. > > Good luck, > > Colin W. When I wrote earlier, I wondered about the need for initialization. With Version 2, both __new__ and __init__ were required, not in the example below, using version 3.2: #!/usr/bin/env python class A(): def ringA(self): print ('aaa') def ringB(self): print('bbb') class B(A): def __init__(self:) def ringB(self): print('BBB') a= A() b= B() b.ringB() b.ringA() b.__class__.mro()[0].ringB(22) # 22 is used for the ringB attribute # Trial and error shows that any # non-Null,including None for the # argument gives the same result z= 1 def main(): pass if __name__ == '__main__': main() Colin W. From steve+comp.lang.python at pearwood.info Sat Mar 10 17:52:04 2012 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 10 Mar 2012 22:52:04 GMT Subject: How to know that two pyc files contain the same code References: Message-ID: <4f5bdb14$0$29891$c3e8da3$5496439d@news.astraweb.com> On Sat, 10 Mar 2012 15:48:48 +0100, Gelonida N wrote: > Hi, > > I want to know whether two .pyc files are identical. > > With identical I mean whether they contain the same byte code. Define "identical" and "the same". If I compile these two files: # file ham.py x = 23 def func(): a = 23 return a + 19 # file = spam.py def func(): return 42 tmp = 19 x = 4 + tmp del tmp do you expect spam.pyc and ham.pyc to count as "the same"? -- Steven From hniksic at xemacs.org Sat Mar 10 20:03:47 2012 From: hniksic at xemacs.org (Hrvoje Niksic) Date: Sun, 11 Mar 2012 02:03:47 +0100 Subject: Porting the 2-3 heap data-structure library from C to Python References: <87boo89zul.fsf@xemacs.org> Message-ID: <87399gne30.fsf@xemacs.org> Stefan Behnel writes: >> which is the standard way of extending Python with high-performance >> (and/or system-specific) C code. > > Well, it's *one* way. Certainly not the easiest way, neither the most > portable and you'll have a hard time making it the fastest. I didn't say it was easy, but standard, in the sense of documented in Python documentation. Python/C is as portable as Python itself, and as fast as the platform allows. I understand your desire to promote Cython, but please stop resorting to FUD in doing so. From rosuav at gmail.com Sat Mar 10 20:15:11 2012 From: rosuav at gmail.com (Chris Angelico) Date: Sun, 11 Mar 2012 12:15:11 +1100 Subject: How to know that two pyc files contain the same code In-Reply-To: <4f5bdb14$0$29891$c3e8da3$5496439d@news.astraweb.com> References: <4f5bdb14$0$29891$c3e8da3$5496439d@news.astraweb.com> Message-ID: On Sun, Mar 11, 2012 at 9:52 AM, Steven D'Aprano wrote: > On Sat, 10 Mar 2012 15:48:48 +0100, Gelonida N wrote: > Define "identical" and "the same". > > If I compile these two files: > > > # file ham.py > x = 23 > def func(): > ? ?a = 23 > ? ?return a + 19 > > > > # file = spam.py > def func(): > ? ?return 42 > > tmp = 19 > x = 4 + tmp > del tmp > > > do you expect spam.pyc and ham.pyc to count as "the same"? They do not contain the same code. They may contain code which has the same effect, but it is not the same code. I don't think Python has the level of aggressive optimization that would make these compile to the same bytecode, but if it did, then they would _become identical_ per the OP's description - that they contain identical bytecode. In fact, I think the OP defined it quite clearly. ChrisA From tjreedy at udel.edu Sat Mar 10 21:17:06 2012 From: tjreedy at udel.edu (Terry Reedy) Date: Sat, 10 Mar 2012 21:17:06 -0500 Subject: Porting the 2-3 heap data-structure library from C to Python In-Reply-To: <87399gne30.fsf@xemacs.org> References: <87boo89zul.fsf@xemacs.org> <87399gne30.fsf@xemacs.org> Message-ID: On 3/10/2012 8:03 PM, Hrvoje Niksic wrote: > Stefan Behnel writes: > >>> which is the standard way of extending Python with high-performance >>> (and/or system-specific) C code. >> >> Well, it's *one* way. Certainly not the easiest way, neither the most >> portable and you'll have a hard time making it the fastest. > > I didn't say it was easy, but standard, in the sense of documented in > Python documentation. Python/C is as portable as Python itself, and as Python is portable because a *lot* of work has gone and continues to go into making it so. And because it sticks with the lowest common denominator of C89. There is much system or compiler specific code in #ifdefs. There are over 60 buildbots for testing patches on various hardware-os-compiler-(python)version combinations. Perhaps once a week something does not work on one of them. The patch gets revised. It happened just today. Apple is changing compilers for the Mac; Python initially did not build with the new compiler. Some people had to do some work so there would continue to be Python on the Mac. So I can imagine that Cython *might* shield one from some of the very real portability problems. > fast as the platform allows. I understand your desire to promote > Cython, but please stop resorting to FUD in doing so. You admitted it might be easier. Portability is plausible. So I think that a bit harsh. -- Terry Jan Reedy From jpokorny at redhat.com Sat Mar 10 21:29:55 2012 From: jpokorny at redhat.com (Jan =?iso-8859-1?Q?Pokorn=FD?=) Date: Sun, 11 Mar 2012 03:29:55 +0100 Subject: [RFC] PEP 3143: supplementary group list concerns Message-ID: <20120311022955.GA31434@redhat.com> Hello, in the light of a recent spot in Python Paste [1], I've come across the python-daemon [2] implementation and found it also lacks support for supplementary groups. First, I just wanted to post a patch to the author, but realized the broader context of PEP 3143 that would probably deserve revisiting at the first place. As the target Python version seems not to be decided yet, I see a space for it. If the spirit of solution [2] was to be followed (i.e., initialize this list with all groups of which user derived from `uid` is a member + group derived from `gid` (regardless if `uid`/`gid` is explicit), no change of the PEP would be necessary. This fact of intented handling of supplementary groups under the hood still could be mentioned so the users and authors of compatible interfaces are aware of this "detail". Another way (in the spirit of systemd [3]) is to extend the interface with an option (named, e.g., supplementary_groups) for optional specification of supplemental groups. The default would be something as in the previous paragraph. To be honest, I am not sure how consistently is the concept of supplementary groups used across various *nixes. POSIX seems to admit variances, e.g. (via [4]): ----v---- The System Interfaces volume of IEEE Std 1003.1-2001 does not specify whether the effective group ID of a process is included in its supplementary group list. ----^---- But I believe this should be addressed before the PEP in question is brought into effect. [2] http://groups.google.com/group/paste-users/browse_thread/thread/2aa651ba331c2471 [3] http://0pointer.de/public/systemd-man/systemd.exec.html [4] http://pubs.opengroup.org/onlinepubs/000095399/utilities/newgrp.html Regards, Jan From gelonida at gmail.com Sun Mar 11 00:30:00 2012 From: gelonida at gmail.com (Gelonida N) Date: Sun, 11 Mar 2012 06:30:00 +0100 Subject: How to know that two pyc files contain the same code In-Reply-To: <4f5bdb14$0$29891$c3e8da3$5496439d@news.astraweb.com> References: <4f5bdb14$0$29891$c3e8da3$5496439d@news.astraweb.com> Message-ID: Hi Steven, On 03/10/2012 11:52 PM, Steven D'Aprano wrote: > > On Sat, 10 Mar 2012 15:48:48 +0100, Gelonida N wrote: > > >> >> Hi, >> >> >> >> I want to know whether two .pyc files are identical. >> >> >> >> With identical I mean whether they contain the same byte code. > > > > Define "identical" and "the same". Indeed! Identical is not that simple to define and depends on the context. One definition of identical, that would suit me at the moment would be: If I have two .pyc files, which were the result of a compilation of two identical .py files, then I would like to treat these two .pyc files as identical, even if they were compiled at different times (absolutely necessary) and with a different absolute path (would be nice) Above definition of identical byte code would also mean, that any error message about errors in a given line number would be identical for both .pyc files > > > > If I compile these two files: > > > > > > # file ham.py > > x = 23 > > def func(): > > a = 23 > > return a + 19 > > > > > > > > # file = spam.py > > def func(): > > return 42 > > > > tmp = 19 > > x = 4 + tmp > > del tmp > > > > > > do you expect spam.pyc and ham.pyc to count as "the same"? > > For most pythons I would not expect, that ham.py and spam.py would result in the same byte code and would thus not even have the same performance, I agree, though that an efficient compiler might generate the same byte code, though I wonder if an optimizing compiler would/should be allowed to optimize away the global variable tmp, as it would be visible (though only for a short time) in a multithreading environment. If the byte code were different in two .pyc files. then I would like to have them treated as different .pyc files. If by coincidence, the generated btye code were the same, then I wouldn't mind, if they were treated as identical, but I wouldn't insist. Up to my knowledge Python (or at least C-python) stores line numbers in the .pyc files, so that it can report exact line numbers refering to the originating source code in case of an exception or for back traces So there is the choice to say, that two pyc files with exactly the same byte code would be treated identical if white spaces / line numbers of their sources were different or the choice to say, that they are different. Being conservative I'd treat them as different. Ideally I'd like to be able depending on my use case to distinguish following cases. a) .pyc files with identical byte code b) .pyc files with identical byte code AND source code line numbers c) same as b) AND identical source file names. From angrybaldguy at gmail.com Sun Mar 11 00:48:44 2012 From: angrybaldguy at gmail.com (Owen Jacobson) Date: Sun, 11 Mar 2012 00:48:44 -0500 Subject: stackoverflow question References: <2012031015032562036-angrybaldguy@gmailcom> Message-ID: <2012031100484474709-angrybaldguy@gmailcom> On 2012-03-10 22:21:55 +0000, Ethan Furman said: > Owen Jacobson wrote: >> On 2012-03-09 22:10:18 +0000, Ethan Furman said: >> >>> Hey all! >>> >>> I posted a question/answer on SO earlier, but there seems to be some >>> confusion around either the question or the answer (judging from the >>> comments). >>> >>> http://stackoverflow.com/q/9638921/208880 >>> >>> If anyone here is willing to take a look at it and let me know if I did >>> not write it well, I would appreciate the feedback. >>> >>> >>> Here's the question text: >>> ------------------------ >>> I'm writing a metaclass to do some cool stuff, and part of its >>> processing is to check that certain attributes exist when the class is >>> created. Some of these are mutable, and would normally be set in >>> `__init__`, but since `__init__` isn't run until the instance is >>> created the metaclass won't know that the attribute *will* be created, >>> and raises an error. I could do something like: >>> >>> class Test(meta=Meta): >>> mutable = None >>> def __init__(self): >>> self.mutable = list() >>> >>> But that isn't very elegant, and also violates DRY. >>> >>> What I need is some way to have: >>> >>> class Test(metaclass=Meta): >>> mutable = list() >>> >>> t1 = Test() >>> t2 = Test() >>> t1.mutable.append('one') >>> t2.mutable.append('two') >>> t1.mutable # prints ['one'] >>> t2.mutable # prints ['two'] >>> >>> Any ideas on how this can be accomplished? >>> >>> Also, the metaclass doing the checking doesn't care what type of object >>> the attribute is, only that it is there. >>> --------------------------- >> >> Why check what you can ensure? The __init__ function your metaclass >> passes to type() doesn't have to be the __init__ method your metaclass >> received. [? __init__-generation technique elided ?] >> All instances of classes whose metaclass is Meta will, guaranteed, have >> an instance field named 'mutable'. Its value is a list created at >> instance creation time, unless the instance's __init__ provides a >> different value. > > The idea is good. The devil is in the details, as usual. How is the > metaclass going to know: > > 1) which attributes to replace > 2) what to replace them with? I can think of at least three techniques; others are certainly possible: 1. As with the example code, the list is hard-coded in the metaclass's source code. 2. The list (or, rather, a dictionary) is drawn from a class attribute of the class being created: class Foo(object): mandatory_fields = {'mutable': list, 'more_stuff': str} __metaclass__ = IntrospectingMetaclass 3. A metaclass-returning factory produces new metaclasses on demand, each of which has a dict of mandatory fields baked into it. (This is a hybrid of the two approaches, and can easily have some messy side effects on your app's type ecology if used carelessly.) Of course, you can also treat this the other way around: instead of enforcing that instances have specific fields, you could have users of those instances be aware that the field might not exist, and wrap access to the field in a try/except NameError block or use getattr to read the attribute. What's appropriate really depends on how you plan to use this metaclass, and on the nature of the higher-level problem to which "I know, I'll use metaclasses" is your answer. How about telling us a slightly broader story about your problem? -o From shanhameed87 at gmail.com Sun Mar 11 01:10:09 2012 From: shanhameed87 at gmail.com (Shahul Hameed) Date: Sat, 10 Mar 2012 22:10:09 -0800 (PST) Subject: open this mail surprise 4 u Message-ID: <1d213c9e-3fbe-45a6-b126-ce804ef599f5@pi6g2000pbc.googlegroups.com> http://123maza.com/46/flower816/ From nagle at animats.com Sun Mar 11 01:12:49 2012 From: nagle at animats.com (John Nagle) Date: Sat, 10 Mar 2012 22:12:49 -0800 Subject: "Decoding unicode is not supported" in unusual situation In-Reply-To: <4f5aa70e$0$30002$c3e8da3$5496439d@news.astraweb.com> References: <4f571b94$0$12037$742ec2ed@news.sonic.net> <8762egmzfp.fsf@benfinney.id.au> <4f5749bc$0$29989$c3e8da3$5496439d@news.astraweb.com> <4f57b63f$0$11986$742ec2ed@news.sonic.net> <871up4m69h.fsf@benfinney.id.au> <4f57eeac$0$29989$c3e8da3$5496439d@news.astraweb.com> <87sjhjltsp.fsf@benfinney.id.au> <4f593178$0$11963$742ec2ed@news.sonic.net> <4f5a47f0$0$11979$742ec2ed@news.sonic.net> <4f5aa70e$0$30002$c3e8da3$5496439d@news.astraweb.com> Message-ID: <4f5c4262$0$11961$742ec2ed@news.sonic.net> On 3/9/2012 4:57 PM, Steven D'Aprano wrote: > On Fri, 09 Mar 2012 10:11:58 -0800, John Nagle wrote: > This demonstrates a gross confusion about both Unicode and Python. John, > I honestly don't mean to be rude here, but if you actually believe that > (rather than merely expressing yourself poorly), then it seems to me that > you are desperately misinformed about Unicode and are working on the > basis of some serious misapprehensions about the nature of strings. > > In Python 2.6/2.7, there is no ambiguity between str/bytes. The two names > are aliases for each other. The older name, "str", is a misnomer, since > it *actually* refers to bytes (and always has, all the way back to the > earliest days of Python). At best, it could be read as "byte string" or > "8-bit string", but the emphasis should always be on the *bytes*. There's an inherent ambiguity in that "bytes" and "str" are really the same type in Python 2.6/2.7. That's a hack for backwards compatibility, and it goes away in 3.x. The notes for PEP 358 admit this. It's implicit in allowing unicode(s) with no encoding, on type "str", that there is an implicit assumption that s is ASCII. Arguably, "unicode()" should have required an encoding in all cases. Or "str" and "bytes" should have been made separate types in Python 2.7, in which case unicode() of a str would be a safe ASCII to Unicode translation, and unicode() of a bytes object would require an encoding. But that would break too much old code. So we have an ambiguity and a hack. "While Python 2 also has a unicode string type, the fundamental ambiguity of the core string type, coupled with Python 2's default behavior of supporting automatic coercion from 8-bit strings to unicode objects when the two are combined, often leads to UnicodeErrors" - PEP 404 John Nagle From steve+comp.lang.python at pearwood.info Sun Mar 11 03:06:53 2012 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 11 Mar 2012 07:06:53 GMT Subject: How to know that two pyc files contain the same code References: <4f5bdb14$0$29891$c3e8da3$5496439d@news.astraweb.com> Message-ID: <4f5c4f0d$0$29891$c3e8da3$5496439d@news.astraweb.com> On Sun, 11 Mar 2012 12:15:11 +1100, Chris Angelico wrote: > On Sun, Mar 11, 2012 at 9:52 AM, Steven D'Aprano > wrote: >> On Sat, 10 Mar 2012 15:48:48 +0100, Gelonida N wrote: Define >> "identical" and "the same". >> >> If I compile these two files: >> >> >> # file ham.py >> x = 23 >> def func(): >> ? ?a = 23 >> ? ?return a + 19 >> >> >> >> # file = spam.py >> def func(): >> ? ?return 42 >> >> tmp = 19 >> x = 4 + tmp >> del tmp >> >> >> do you expect spam.pyc and ham.pyc to count as "the same"? > > They do not contain the same code. They may contain code which has the > same effect, but it is not the same code. To me, they do: they contain a function "func" which takes no arguments and returns 42, and a global "x" initialised to 23. Everything else is an implementation detail. I'm not being facetious. One should be asking what is the *purpose* of this question -- is it to detect when two pyc files contain the same *interface*, or to determine if they were generated from identical source code files (and if the later, do comments and whitespace matter)? What if one merely changed the order of definition? Instead of: def foo(): pass def bar(): pass one had this? def bar(): pass def foo(): pass It depends on why the OP cares if they are "identical". I can imagine use- cases where the right solution is to forget ideas about identical code, and just checksum the files (ignoring any timestamps). -- Steven From stefan_ml at behnel.de Sun Mar 11 03:41:17 2012 From: stefan_ml at behnel.de (Stefan Behnel) Date: Sun, 11 Mar 2012 08:41:17 +0100 Subject: Porting the 2-3 heap data-structure library from C to Python In-Reply-To: <87399gne30.fsf@xemacs.org> References: <87boo89zul.fsf@xemacs.org> <87399gne30.fsf@xemacs.org> Message-ID: Hrvoje Niksic, 11.03.2012 02:03: > Stefan Behnel writes: >>> which is the standard way of extending Python with high-performance >>> (and/or system-specific) C code. >> >> Well, it's *one* way. Certainly not the easiest way, neither the most >> portable and you'll have a hard time making it the fastest. > > I didn't say it was easy, but standard, in the sense of documented in > Python documentation. Python/C is as portable as Python itself, and as > fast as the platform allows. Only if you know how to do it right and have the discipline to do a lot of cross-platform testing, benchmarking and tuning. Not everyone wants to invest that much time into details that are unrelated to the problem at hand. And why should they, when other people (who have gained some experience in it) have already done if for them and continue to do that, so that they don't need to care and can get it for free? > I understand your desire to promote > Cython, but please stop resorting to FUD in doing so. I can't see it being FUD (although arguably promotion) to tell people that "we write C so you don't have to". It's certainly not FUD that it's easier (and IMHO also more fun) to write good Python code than good C code. Quite the contrary, telling new users to go straight for writing C code and using CPython's C-API natively is like asking them why (the heck!) they are using Python in the first place, when they can just dive into the beautiful world of C. I don't think that's the ideal attitude for this list. Stefan From cosmius at gmail.com Sun Mar 11 06:10:19 2012 From: cosmius at gmail.com (Cosmia Luna) Date: Sun, 11 Mar 2012 03:10:19 -0700 (PDT) Subject: How to re-implement the crypt.crypt function? In-Reply-To: References: <28304124.1374.1331408016748.JavaMail.geo-discussion-forums@yncd8> Message-ID: <17753159.3543.1331460619089.JavaMail.geo-discussion-forums@ynnk21> On Sunday, March 11, 2012 4:16:52 AM UTC+8, Christian Heimes wrote: > Am 10.03.2012 20:33, schrieb Cosmia Luna: > > I'm not searching for a full solution and only want to know how to use hashlib to create a equivalent string like > > If you chance your mind and choose to use a full solution, then I highly > recommend passlib [1]. It has an implementation of SHA-512 crypt as > indicated by the number 6 in the header of your string. > > By the way "$6$ds41p/9VMA.BHH0U" is *not* the salt. Just > "ds41p/9VMA.BHH0U" is the salt, 6 is a hash identifier. > > Christian > > [1] http://packages.python.org/passlib/ PassLib works for me. What I want is passlib.context, I need it in consideration of forward compatibility. Thanks a lot. But I still want to know how it is implemented, I read passlib's source but I found he/she re-implemented hashlib, which I can't understand. Now I knows that the encoding is hash64 instead of base64, but I can't know that. PassLib is too difficult for me. Anyone knows the accurate process? Cosmia From cosmius at gmail.com Sun Mar 11 06:10:19 2012 From: cosmius at gmail.com (Cosmia Luna) Date: Sun, 11 Mar 2012 03:10:19 -0700 (PDT) Subject: How to re-implement the crypt.crypt function? In-Reply-To: References: <28304124.1374.1331408016748.JavaMail.geo-discussion-forums@yncd8> Message-ID: <17753159.3543.1331460619089.JavaMail.geo-discussion-forums@ynnk21> On Sunday, March 11, 2012 4:16:52 AM UTC+8, Christian Heimes wrote: > Am 10.03.2012 20:33, schrieb Cosmia Luna: > > I'm not searching for a full solution and only want to know how to use hashlib to create a equivalent string like > > If you chance your mind and choose to use a full solution, then I highly > recommend passlib [1]. It has an implementation of SHA-512 crypt as > indicated by the number 6 in the header of your string. > > By the way "$6$ds41p/9VMA.BHH0U" is *not* the salt. Just > "ds41p/9VMA.BHH0U" is the salt, 6 is a hash identifier. > > Christian > > [1] http://packages.python.org/passlib/ PassLib works for me. What I want is passlib.context, I need it in consideration of forward compatibility. Thanks a lot. But I still want to know how it is implemented, I read passlib's source but I found he/she re-implemented hashlib, which I can't understand. Now I knows that the encoding is hash64 instead of base64, but I can't know that. PassLib is too difficult for me. Anyone knows the accurate process? Cosmia From hyperboogie at gmail.com Sun Mar 11 06:18:26 2012 From: hyperboogie at gmail.com (hyperboogie) Date: Sun, 11 Mar 2012 03:18:26 -0700 (PDT) Subject: newb __init__ inheritance References: <1c6db866-6fa3-4de5-96de-51d6720a1300@x17g2000yqj.googlegroups.com> Message-ID: <2feb13ca-f83b-4843-995f-ee77e7505ecd@db5g2000vbb.googlegroups.com> On Mar 11, 12:47?am, "Colin J. Williams" wrote: > On 10/03/2012 12:58 PM, Colin J. Williams wrote:> On 08/03/2012 10:25 AM, hyperboogie wrote: > >> Hello everyone. > > [snip] > > main() > > I'm not sure that the class initialization is required. > > > Good luck, > > > Colin W. > > When I wrote earlier, I wondered about the need for initialization. > > With Version 2, both __new__ and __init__ were required, not in the > example below, using version 3.2: > #!/usr/bin/env python > > class A(): > > ? ?def ringA(self): > ? ? ?print ('aaa') > > ? ?def ringB(self): > ? ? ?print('bbb') > > class B(A): > ? ?def __init__(self:) > ? ?def ringB(self): > ? ? ?print('BBB') > > a= A() > b= B() > b.ringB() > b.ringA() > b.__class__.mro()[0].ringB(22) ? # ?22 is used for the ringB attribute > ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? # ?Trial and error shows that any > ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? # ?non-Null,including None for the > ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? # ?argument gives the same result > z= 1 > def main(): > ? ? ?pass > > if __name__ == '__main__': > ? ? ?main() > > Colin W. thank you everyone... Still things are not working as expected... what am I doing wrong? I'm working with python2 and have the following issues: 1. mro is not an attribute/function 2. inheritance is not working as expected: # cat test.py #!/usr/bin/python class A(): def __init__(self): z=1 print "in A.__init__ z=", z def funcA(self): print "in funcA - class A" def funcB(self): print "in funcB - class A, z= ", z class B(A): def __init__(self): A.__init__(self) print "in B.__init__ z=", z def funcB(self): print "in funcB - class B, z= ", z a=A() b=B() b.funcB() b.funcA() # ./test.py in A.__init__ z= 1 # This must be the __init__ from the instantiation of a in A.__init__ z= 1 # This must be the B.__init__ calling A.__init__ in B.__init__ z= # Why isn't this working? z should have been inherited from "A" right? Traceback (most recent call last): File "./test.py", line 23, in b=B() File "./test.py", line 17, in __init__ print "in B.__init__ z=", z NameError: global name 'z' is not defined # From clp2 at rebertia.com Sun Mar 11 06:38:27 2012 From: clp2 at rebertia.com (Chris Rebert) Date: Sun, 11 Mar 2012 03:38:27 -0700 Subject: newb __init__ inheritance In-Reply-To: <2feb13ca-f83b-4843-995f-ee77e7505ecd@db5g2000vbb.googlegroups.com> References: <1c6db866-6fa3-4de5-96de-51d6720a1300@x17g2000yqj.googlegroups.com> <2feb13ca-f83b-4843-995f-ee77e7505ecd@db5g2000vbb.googlegroups.com> Message-ID: On Sun, Mar 11, 2012 at 3:18 AM, hyperboogie wrote: > thank you everyone... > Still things are not working as expected... what am I doing wrong? > # cat test.py > #!/usr/bin/python > > class A(): You should be subclassing `object`, but that's a minor point which isn't the cause of your problem. > ? def __init__(self): > ? ? ?z=1 This creates a *local variable* named "z". You want an *attribute* named "z", so you should be doing: self.z = 1 instead. Same problem elsewhere; you must *always* explicitly use `self` when referencing an attribute of the current object. Python != Java or C++. Cheers, Chris From hyperboogie at gmail.com Sun Mar 11 06:56:28 2012 From: hyperboogie at gmail.com (hyperboogie) Date: Sun, 11 Mar 2012 03:56:28 -0700 (PDT) Subject: newb __init__ inheritance In-Reply-To: References: <1c6db866-6fa3-4de5-96de-51d6720a1300@x17g2000yqj.googlegroups.com> <2feb13ca-f83b-4843-995f-ee77e7505ecd@db5g2000vbb.googlegroups.com> Message-ID: <18769501.3541.1331463388634.JavaMail.geo-discussion-forums@ynkz21> On Sunday, March 11, 2012 12:38:27 PM UTC+2, Chris Rebert wrote: > On Sun, Mar 11, 2012 at 3:18 AM, hyperboogie wrote: > > > thank you everyone... > > Still things are not working as expected... what am I doing wrong? > > > # cat test.py > > #!/usr/bin/python > > > > class A(): > > You should be subclassing `object`, but that's a minor point which > isn't the cause of your problem. > > > ? def __init__(self): > > ? ? ?z=1 > > This creates a *local variable* named "z". You want an *attribute* > named "z", so you should be doing: > self.z = 1 > instead. Same problem elsewhere; you must *always* explicitly use > `self` when referencing an attribute of the current object. Python != > Java or C++. > > Cheers, > Chris Thanks ... works great now. Two last questions: 1. What do you mean by "subclassing `object`"? 2. Is the mro function available only on python3? From hyperboogie at gmail.com Sun Mar 11 06:56:28 2012 From: hyperboogie at gmail.com (hyperboogie) Date: Sun, 11 Mar 2012 03:56:28 -0700 (PDT) Subject: newb __init__ inheritance In-Reply-To: References: <1c6db866-6fa3-4de5-96de-51d6720a1300@x17g2000yqj.googlegroups.com> <2feb13ca-f83b-4843-995f-ee77e7505ecd@db5g2000vbb.googlegroups.com> Message-ID: <18769501.3541.1331463388634.JavaMail.geo-discussion-forums@ynkz21> On Sunday, March 11, 2012 12:38:27 PM UTC+2, Chris Rebert wrote: > On Sun, Mar 11, 2012 at 3:18 AM, hyperboogie wrote: > > > thank you everyone... > > Still things are not working as expected... what am I doing wrong? > > > # cat test.py > > #!/usr/bin/python > > > > class A(): > > You should be subclassing `object`, but that's a minor point which > isn't the cause of your problem. > > > ? def __init__(self): > > ? ? ?z=1 > > This creates a *local variable* named "z". You want an *attribute* > named "z", so you should be doing: > self.z = 1 > instead. Same problem elsewhere; you must *always* explicitly use > `self` when referencing an attribute of the current object. Python != > Java or C++. > > Cheers, > Chris Thanks ... works great now. Two last questions: 1. What do you mean by "subclassing `object`"? 2. Is the mro function available only on python3? From clp2 at rebertia.com Sun Mar 11 07:37:55 2012 From: clp2 at rebertia.com (Chris Rebert) Date: Sun, 11 Mar 2012 04:37:55 -0700 Subject: newb __init__ inheritance In-Reply-To: <18769501.3541.1331463388634.JavaMail.geo-discussion-forums@ynkz21> References: <1c6db866-6fa3-4de5-96de-51d6720a1300@x17g2000yqj.googlegroups.com> <2feb13ca-f83b-4843-995f-ee77e7505ecd@db5g2000vbb.googlegroups.com> <18769501.3541.1331463388634.JavaMail.geo-discussion-forums@ynkz21> Message-ID: On Sun, Mar 11, 2012 at 3:56 AM, hyperboogie wrote: > On Sunday, March 11, 2012 12:38:27 PM UTC+2, Chris Rebert wrote: >> On Sun, Mar 11, 2012 at 3:18 AM, hyperboogie wrote: >> >> > thank you everyone... >> > Still things are not working as expected... what am I doing wrong? >> >> > # cat test.py >> > #!/usr/bin/python >> > >> > class A(): >> >> You should be subclassing `object`, but that's a minor point which >> isn't the cause of your problem. >> >> > ? def __init__(self): >> > ? ? ?z=1 >> >> This creates a *local variable* named "z". You want an *attribute* >> named "z", so you should be doing: >> ? ? self.z = 1 >> instead. Same problem elsewhere; you must *always* explicitly use >> `self` when referencing an attribute of the current object. Python != >> Java or C++. >> >> Cheers, >> Chris > > Thanks ... works great now. > Two last questions: > > 1. What do you mean by "subclassing `object`"? Your classes should (ultimately) subclass the built-in class named "object". In your case: class A(object): # ?rest same as before? This ensures that your classes are new-style rather than old-style (the latter is deprecated); see: http://docs.python.org/glossary.html#term-new-style-class > 2. Is the mro function available only on python3? There's never been an mro function. Perhaps you mean the __mro__ attribute of classes (e.g. `B.__mro__`), which is available in Python 2.2+ and Python 3? Cheers, Chris From ian.g.kelly at gmail.com Sun Mar 11 07:40:53 2012 From: ian.g.kelly at gmail.com (Ian Kelly) Date: Sun, 11 Mar 2012 05:40:53 -0600 Subject: newb __init__ inheritance In-Reply-To: <18769501.3541.1331463388634.JavaMail.geo-discussion-forums@ynkz21> References: <1c6db866-6fa3-4de5-96de-51d6720a1300@x17g2000yqj.googlegroups.com> <2feb13ca-f83b-4843-995f-ee77e7505ecd@db5g2000vbb.googlegroups.com> <18769501.3541.1331463388634.JavaMail.geo-discussion-forums@ynkz21> Message-ID: On Sun, Mar 11, 2012 at 4:56 AM, hyperboogie wrote: > 1. What do you mean by "subclassing `object`"? In Python 2 there are two different types of classes: classic classes, which are retained for backward compatibility, and new-style classes, which were introduced in Python 2.2. Classic classes are the default. In order to get a new-style class (strongly recommended), your class must inherit directly or indirectly from object. In the following, A and B are classic classes, whereas C and D are new-style classes: class A: pass class B(A): pass class C(object): pass class D(C): pass In Python 3, classic classes have been removed, and so all four of the classes above would be new-style. > 2. Is the mro function available only on python3? No, but it is available only on new-style classes. If you try it on a classic class, you'll get an AttributeError. Cheers, Ian From ian.g.kelly at gmail.com Sun Mar 11 07:52:48 2012 From: ian.g.kelly at gmail.com (Ian Kelly) Date: Sun, 11 Mar 2012 05:52:48 -0600 Subject: newb __init__ inheritance In-Reply-To: References: <1c6db866-6fa3-4de5-96de-51d6720a1300@x17g2000yqj.googlegroups.com> <2feb13ca-f83b-4843-995f-ee77e7505ecd@db5g2000vbb.googlegroups.com> <18769501.3541.1331463388634.JavaMail.geo-discussion-forums@ynkz21> Message-ID: On Sun, Mar 11, 2012 at 5:40 AM, Ian Kelly wrote: >> 2. Is the mro function available only on python3? > > No, but it is available only on new-style classes. ?If you try it on a > classic class, you'll get an AttributeError. And by the way, you probably shouldn't call the mro method directly. That method is provided so that it can be overridden in order to customize the MRO at class creation. The proper (and faster) way to look up the MRO for a class is using the __mro__ attribute, which stores the result of the mro method when the class is initialized. http://docs.python.org/library/stdtypes.html?highlight=mro#class.__mro__ Cheers, Ian From __peter__ at web.de Sun Mar 11 08:12:25 2012 From: __peter__ at web.de (Peter Otten) Date: Sun, 11 Mar 2012 13:12:25 +0100 Subject: newb __init__ inheritance References: <1c6db866-6fa3-4de5-96de-51d6720a1300@x17g2000yqj.googlegroups.com> <2feb13ca-f83b-4843-995f-ee77e7505ecd@db5g2000vbb.googlegroups.com> <18769501.3541.1331463388634.JavaMail.geo-discussion-forums@ynkz21> Message-ID: Ian Kelly wrote: > On Sun, Mar 11, 2012 at 5:40 AM, Ian Kelly wrote: >>> 2. Is the mro function available only on python3? >> >> No, but it is available only on new-style classes. If you try it on a >> classic class, you'll get an AttributeError. > > And by the way, you probably shouldn't call the mro method directly. > That method is provided so that it can be overridden in order to > customize the MRO at class creation. The proper (and faster) way to > look up the MRO for a class is using the __mro__ attribute, which > stores the result of the mro method when the class is initialized. > > http://docs.python.org/library/stdtypes.html?highlight=mro#class.__mro__ Is it a good idea to use mro() or __mro__ at all? Are there common use cases that cannot be addressed with super()? From steve+comp.lang.python at pearwood.info Sun Mar 11 10:37:54 2012 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 11 Mar 2012 14:37:54 GMT Subject: Why are some unicode error handlers "encode only"? Message-ID: <4f5cb8c2$0$29891$c3e8da3$5496439d@news.astraweb.com> At least two standard error handlers are documented as working for encoding only: xmlcharrefreplace backslashreplace See http://docs.python.org/library/codecs.html#codec-base-classes and http://docs.python.org/py3k/library/codecs.html Why is this? I don't see why they shouldn't work for decoding as well. Consider this example using Python 3.2: >>> b"aaa--\xe9z--\xe9!--bbb".decode("cp932") Traceback (most recent call last): File "", line 1, in UnicodeDecodeError: 'cp932' codec can't decode bytes in position 9-10: illegal multibyte sequence The two bytes b'\xe9!' is an illegal multibyte sequence for CP-932 (also known as MS-KANJI or SHIFT-JIS). Is there some reason why this shouldn't or can't be supported? # This doesn't actually work. b"aaa--\xe9z--\xe9!--bbb".decode("cp932", "backslashreplace") => r'aaa--?--\xe9\x21--bbb' and similarly for xmlcharrefreplace. -- Steven From rantingrickjohnson at gmail.com Sun Mar 11 11:22:38 2012 From: rantingrickjohnson at gmail.com (Rick Johnson) Date: Sun, 11 Mar 2012 08:22:38 -0700 (PDT) Subject: How to know that two pyc files contain the same code References: <4f5bdb14$0$29891$c3e8da3$5496439d@news.astraweb.com> <4f5c4f0d$0$29891$c3e8da3$5496439d@news.astraweb.com> Message-ID: <90223b79-6a21-448a-945f-c5569a46b9d3@v7g2000yqb.googlegroups.com> On Mar 11, 2:06?am, Steven D'Aprano wrote: > I'm not being facetious. [...] Just in case anybody does not know already: the "D'A" in "Steven D'Aprano" stands for "Devils Advocate"; his real name is "Steven Prano". From search at bluelinetalent.com Sun Mar 11 12:00:01 2012 From: search at bluelinetalent.com (Blue Line Talent) Date: Sun, 11 Mar 2012 09:00:01 -0700 (PDT) Subject: Software Engineer - Storage, Python, C++, Java - Broomfield, CO Message-ID: <74c28456-5467-48e8-88a9-e5649358373a@to5g2000pbc.googlegroups.com> Blue Line Talent is looking for a mid-level software engineer with experience in a combination of Python, C/C++ and/or Java. Experience developing middleware is helpful. The Engineer will join an exciting start-up environment in a newly established location. This is an outstanding opportunity for a high performing software engineer with 3-5 years experience. Must love coding, variety. For this position most of the work is being done in Python now but they expect this SW Engineer will also use increasing amounts of C/C++ and Java. The languages experience isn't as important as finding a really sharp Software Engineer who loves programming (not just design) and would be well suited for the diversity of a start-up environment. Position Title: Software Engineer - Storage Work Location: Broomfield/Flatirons area, CO The Employer: ? A strongly positioned Storage Solutions Software company ? Fully funded and established start-up company with excellent opportunities for growth and advancement ? Comprehensive benefits package Description: ? Full life-cycle software design, development, implementation, test and maintenance. ? Develop, test, and maintain infrastructure-oriented software in Python with some work in C/C++ and Java ? Middleware development - bridge between Linux Kernel and GUI ? Source code control Experience Profile: ? BS in Computer Science or an applicable engineering subject and 3-5+ years of related software engineering experience ? 2+ years software engineering for complex storage solutions ? Loves programming ? Experience developing middleware ? Experience programming in Python (or C/C++ and/or Java) ? Software Engineering experience in a Linux environment. ? Experience with near-real time software development. ? Stable employment history of direct employment Helpful/Preferred: ? Experience in a start-up environment ? Experience with real-time software development. (exposure to embedded software is helpful) ? Enjoys diversity of tasks ? Experience with GUI ? Experience with C/C++ and/or Java ? Experience with various Windows and Linux OS environments ? Exposure to storage subsystems such as Fibre Channel, iSCSI, SAS, SATA, RAID, Snapshot, Replication, NAS, SAN, etc. ? MS in Computer Science, or related degree Please apply at www.bluelinetalent.com/active_jobs NOTES: ? Direct hire with comprehensive benefits ? Local candidates please - no relocation assistance provided ? Not available for Corp-to-Corp, no third parties please Ron Levis Principal, Talent Acquisition Mgr Blue Line Talent, LLC www.bluelinetalent.com www.linkedin.com/in/ronlevis (invitations are welcome) Moderator, Colorado IT Community on LinkedIn Groups Blue Line Talent is a member-owner of NPA, The Worldwide Recruiting Network, your connection to premier independent recruiting firms located throughout Europe, Asia, Australia, Africa and the Americas. From walter at livinglogic.de Sun Mar 11 12:10:12 2012 From: walter at livinglogic.de (=?UTF-8?B?V2FsdGVyIETDtnJ3YWxk?=) Date: Sun, 11 Mar 2012 17:10:12 +0100 Subject: Why are some unicode error handlers "encode only"? In-Reply-To: <4f5cb8c2$0$29891$c3e8da3$5496439d@news.astraweb.com> References: <4f5cb8c2$0$29891$c3e8da3$5496439d@news.astraweb.com> Message-ID: <4F5CCE64.8050501@livinglogic.de> On 11.03.12 15:37, Steven D'Aprano wrote: > At least two standard error handlers are documented as working for > encoding only: > > xmlcharrefreplace > backslashreplace > > See http://docs.python.org/library/codecs.html#codec-base-classes > > and http://docs.python.org/py3k/library/codecs.html > > Why is this? I don't see why they shouldn't work for decoding as well. Because xmlcharrefreplace and backslashreplace are *error* handlers. However the bytes sequence b'〹' does *not* contain any bytes that are not decodable for e.g. the ASCII codec. So there are no errors to handle. > Consider this example using Python 3.2: > >>>> b"aaa--\xe9z--\xe9!--bbb".decode("cp932") > Traceback (most recent call last): > File "", line 1, in > UnicodeDecodeError: 'cp932' codec can't decode bytes in position 9-10: > illegal multibyte sequence > > The two bytes b'\xe9!' is an illegal multibyte sequence for CP-932 (also > known as MS-KANJI or SHIFT-JIS). Is there some reason why this shouldn't > or can't be supported? The byte sequence b'\xe9!' however is not something that would have been produced by the backslashreplace error handler. b'\\xe9!' (a sequence containing 5 bytes) would have been (and this probably would decode without any problems with the cp932 codec). > # This doesn't actually work. > b"aaa--\xe9z--\xe9!--bbb".decode("cp932", "backslashreplace") > => r'aaa--?--\xe9\x21--bbb' > > and similarly for xmlcharrefreplace. This would require a postprocess step *after* the bytes have been decoded. This is IMHO out of scope for Python's codec machinery. Servus, Walter From chris at simplistix.co.uk Sun Mar 11 12:20:03 2012 From: chris at simplistix.co.uk (Chris Withers) Date: Sun, 11 Mar 2012 09:20:03 -0700 Subject: Software Engineer - In-Reply-To: <74c28456-5467-48e8-88a9-e5649358373a@to5g2000pbc.googlegroups.com> References: <74c28456-5467-48e8-88a9-e5649358373a@to5g2000pbc.googlegroups.com> Message-ID: <4F5CD0B3.1090501@simplistix.co.uk> On 11/03/2012 09:00, Blue Line Talent wrote: > Blue Line Talent is looking for a mid-level software engineer with > experience in a combination of Please don't spam this list with jobs, use the Python job board instead: http://www.python.org/community/jobs/ cheers, Chris -- Simplistix - Content Management, Batch Processing & Python Consulting - http://www.simplistix.co.uk From tjreedy at udel.edu Sun Mar 11 13:10:33 2012 From: tjreedy at udel.edu (Terry Reedy) Date: Sun, 11 Mar 2012 13:10:33 -0400 Subject: Why are some unicode error handlers "encode only"? In-Reply-To: <4f5cb8c2$0$29891$c3e8da3$5496439d@news.astraweb.com> References: <4f5cb8c2$0$29891$c3e8da3$5496439d@news.astraweb.com> Message-ID: On 3/11/2012 10:37 AM, Steven D'Aprano wrote: > At least two standard error handlers are documented as working for > encoding only: > > xmlcharrefreplace > backslashreplace > > See http://docs.python.org/library/codecs.html#codec-base-classes > > and http://docs.python.org/py3k/library/codecs.html > > Why is this? I presume the purpose of both is to facilitate transmission of unicode text via byte transmission by extending incomplete byte encodings by replacing unicode chars that do not fit in the given encoding by a ascii byte sequence that will fit. > I don't see why they shouldn't work for decoding as well. > Consider this example using Python 3.2: > >>>> b"aaa--\xe9z--\xe9!--bbb".decode("cp932") > Traceback (most recent call last): > File "", line 1, in > UnicodeDecodeError: 'cp932' codec can't decode bytes in position 9-10: > illegal multibyte sequence > > The two bytes b'\xe9!' is an illegal multibyte sequence for CP-932 (also > known as MS-KANJI or SHIFT-JIS). Is there some reason why this shouldn't > or can't be supported? > > # This doesn't actually work. > b"aaa--\xe9z--\xe9!--bbb".decode("cp932", "backslashreplace") > => r'aaa--?--\xe9\x21--bbb' This output does not round-trip and would be a bit of a fib since it somewhat misrepresents what the encoded bytes were: >>> r'aaa--?--\xe9\x21--bbb'.encode("cp932") b'aaa--\xe9z--\\xe9\\x21--bbb' >>> b'aaa--\xe9z--\\xe9\\x21--bbb'.decode("cp932") 'aaa--?--\\xe9\\x21--bbb' Python 3 added surrogateescape error handling to solve this problem. > and similarly for xmlcharrefreplace. Since xml character references are representations of unicode chars, and not bytes, I do not see how that would work. By analogy, perhaps you mean to have '&#e9;' in your output instead of '\xe9\x21', but those would not properly be xml numeric character references. -- Terry Jan Reedy From sorsorday at gmail.com Sun Mar 11 14:53:45 2012 From: sorsorday at gmail.com (Herman) Date: Sun, 11 Mar 2012 11:53:45 -0700 Subject: How to break long method name into more than one line? Message-ID: I am trying to stick to the rule described in the TDD book that, each test method name consists of the method name to be tested, inputs and the expected outputs. It takes up a lot of space and my company has a rule of limiting 79 characters (or 80) per line. I found that def abcdeef\ dddaaa(self): pass does not work, but def \ abcsajfoijfiawifoiwejfoi(self): pass works. Is this the only way to do it? From bob at mellowood.ca Sun Mar 11 15:04:55 2012 From: bob at mellowood.ca (bvdp) Date: Sun, 11 Mar 2012 12:04:55 -0700 (PDT) Subject: Raise X or Raise X()? Message-ID: <387014.2537.1331492695725.JavaMail.geo-discussion-forums@pbjv6> Which is preferred in a raise: X or X()? I've seen both. In my specific case I'm dumping out of a deep loop: try: for ... for ... for ... if match: raise StopInteration() else ... except StopInteration: print "found it" From roy at panix.com Sun Mar 11 15:11:29 2012 From: roy at panix.com (Roy Smith) Date: Sun, 11 Mar 2012 15:11:29 -0400 Subject: How to break long method name into more than one line? References: Message-ID: In article , Herman wrote: > I am trying to stick to the rule described in the TDD book that, each > test method name consists of the method name to be tested, inputs and > the expected outputs. It takes up a lot of space and my company has a > rule of limiting 79 characters (or 80) per line. I found that > def abcdeef\ > dddaaa(self): > pass > > does not work, but > def \ > abcsajfoijfiawifoiwejfoi(self): > pass > > works. Is this the only way to do it? Arrrrrrrrhhhggggg. If you can't fit a test method name into 79 characters, you're doing somthing wrong. Just for fun, I found all the test methods in the project I'm working on and sorted them by length. Here's the top of the list: $ find . -name 'test*py' | xargs grep -h 'def *test' | sort | uniq | awk '{print length($0), $0}' | sort -nr 55 def test_update_name_changes_dasherized_name(self): 51 def test_get_followers_with_no_followers(self): 50 def test_update_station_song_adds_false(self): 50 def test_anonymous_get_user_collections(self): 49 def test_wrong_user_update_should_fail(self): 49 def test_login_with_email_and_password(self): 47 def test_unknown_station_returns_404(self): 47 def test_login_failure_with_facebook(self): 47 def test_get_follows_with_no_follows(self): 46 def test_station_by_dasherized_name(self): 46 def test_nonexistent_recent_station(self): 46 def test_new_user_with_display_name(self): 46 def test_auto_connect_with_facebook(self): 46 def test_anonymous_created_stations(self): 45 def test_no_php_fatal_error_in_log(self): 45 def test_get_only_songza_followers(self): 45 def test_anonymous_vote_transition(self): 44 def test_non_ascii_global_station(self): 44 def test_global_station_not_found(self): 44 def test_gallery_create_duplicate(self): 44 def test_anonymous_listen_history(self): and so on down to the wonderfully terse: 21 def test_x(self): which I'm assuming actually makes sense in the context of the TestCase class it belongs to. At least I hope it does :-) The examples above are a reasonable upper limit on the verbosity you should be shooting for, IMHO. From nagle at animats.com Sun Mar 11 16:30:58 2012 From: nagle at animats.com (John Nagle) Date: Sun, 11 Mar 2012 13:30:58 -0700 Subject: html5lib not thread safe. Is the Python SAX library thread-safe? Message-ID: <4f5d0b82$0$11967$742ec2ed@news.sonic.net> "html5lib" is apparently not thread safe. (see "http://code.google.com/p/html5lib/issues/detail?id=189") Looking at the code, I've only found about three problems. They're all the usual "cached in a global without locking" bug. A few locks would fix that. But html5lib calls the XML SAX parser. Is that thread-safe? Or is there more trouble down at the bottom? (I run a multi-threaded web crawler, and currently use BeautifulSoup, which is thread safe, although dated. I'm looking at converting to html5lib.) John Nagle From irmen.NOSPAM at xs4all.nl Sun Mar 11 16:37:26 2012 From: irmen.NOSPAM at xs4all.nl (Irmen de Jong) Date: Sun, 11 Mar 2012 21:37:26 +0100 Subject: Raise X or Raise X()? In-Reply-To: <387014.2537.1331492695725.JavaMail.geo-discussion-forums@pbjv6> References: <387014.2537.1331492695725.JavaMail.geo-discussion-forums@pbjv6> Message-ID: <4f5d0d06$0$6856$e4fe514c@news2.news.xs4all.nl> On 11-3-2012 20:04, bvdp wrote: > Which is preferred in a raise: X or X()? I've seen both. In my specific case I'm dumping out of a deep loop: > > try: > for ... > for ... > for ... > if match: > raise StopInteration() > else ... > > except StopInteration: > print "found it" "raise X" is a special case of the 3-args raise. Effectively it just raises an instance of X which is constructed with an empty argument list. Therefore, "raise X()" is equivalent, as far as I know. See http://docs.python.org/reference/simple_stmts.html#the-raise-statement Irmen From atavory at gmail.com Sun Mar 11 17:01:01 2012 From: atavory at gmail.com (Ami Tavory) Date: Sun, 11 Mar 2012 23:01:01 +0200 Subject: Launching A Truly Disjoint Process Message-ID: Hello, I'm encountering a problem using the multiprocessing module to create a process that is truly disjoint from the parent process: i.e., one that contains no "memory" of the parent process, nor any record in the parent process that it is its child. This originated in a pygtk problem, but I'll try to put down as little pygtk as possible - just enough to explain the problem (also, sorry, but I couldn't get an answer at the gtk forum). The code is a small python debugger front-end for GEdit. The plugin code, run from GEdit's process, uses multiprocessing.Process(target = run_dbg) to launch the debugger in a function in separate process. The debugger uses the bdb module like this: bdb.run('execfile("%s")' % script). This seems to work fine, except if the script being debugged is itself a pygtk script. Specifically, if it contains the code Gtk.main() then GEdit crashes with [xcb] Unknown sequence number while processing queue [xcb] Most likely this is a multi-threaded client and XInitThreads has not been called [xcb] Aborting, sorry about that. gedit: ../../src/xcb_io.c:273: poll_for_event: Assertion `!xcb_xlib_threads_sequence_lost' failed. Googling this error yielded many results, but they all consisted of advice to change either the code launching the process (possibly compiling it differently), or change the launched process running gtk. It seems like gtk requires that a single thread run this. Unfortunately, in this case, the launching process is GEdit (whose code I cannot modify from a plugin), and the launched process essentially runs a hypothetical script that is being debugged (and whose code, therefore, is a given). OTOH, clearly it is possible to run more than a single gtk app concurrently from completely separate processes. Is there a way, therefore, to launch the second process, or have the launched process do something when it starts, so that the two processes should essentially be disjoint? Thanks, Ami -------------- next part -------------- An HTML attachment was scrubbed... URL: From d at davea.name Sun Mar 11 17:34:41 2012 From: d at davea.name (Dave Angel) Date: Sun, 11 Mar 2012 17:34:41 -0400 Subject: Launching A Truly Disjoint Process In-Reply-To: References: Message-ID: <4F5D1A71.1010908@davea.name> On 03/11/2012 05:01 PM, Ami Tavory wrote: > Hello, > > I'm encountering a problem using the multiprocessing module to create a > process that is truly disjoint from the parent process: i.e., one that > contains no "memory" of the parent process, nor any record in the parent > process that it is its child. This originated in a pygtk problem, but I'll > try to put down as little pygtk as possible - just enough to explain the > problem (also, sorry, but I couldn't get an answer at the gtk forum). > > The code is a small python debugger front-end for GEdit. The plugin code, > run from GEdit's process, uses > multiprocessing.Process(target = run_dbg) > to launch the debugger in a function in separate process. The debugger uses > the bdb module like this: > bdb.run('execfile("%s")' % script). > This seems to work fine, except if the script being debugged is itself a > pygtk script. Specifically, if it contains the code > Gtk.main() > then GEdit crashes with > > [xcb] Unknown sequence number while processing queue > [xcb] Most likely this is a multi-threaded client and XInitThreads has not > been called > [xcb] Aborting, sorry about that. > gedit: ../../src/xcb_io.c:273: poll_for_event: Assertion > `!xcb_xlib_threads_sequence_lost' failed. > > Googling this error yielded many results, but they all consisted of > advice to change either the code launching the process (possibly compiling > it differently), or change the launched process running gtk. It seems like > gtk requires that a single thread run this. Unfortunately, in this case, > the launching process is GEdit (whose code I cannot modify from a plugin), > and the launched process essentially runs a hypothetical script that is > being debugged (and whose code, therefore, is a given). > OTOH, clearly it is possible to run more than a single gtk app > concurrently from completely separate processes. Is there a way, therefore, > to launch the second process, or have the launched process do something > when it starts, so that the two processes should essentially be disjoint? > > Thanks, > > Ami > Why not try using bash as an intermediate executable? Have your first python process invoke bash, giving it the arguments to in turn launch the second python process. If that won't work, then at least tell us some more of your environment. What version of Python, what version of OS? -- DaveA From cs at zip.com.au Sun Mar 11 17:45:01 2012 From: cs at zip.com.au (Cameron Simpson) Date: Mon, 12 Mar 2012 08:45:01 +1100 Subject: html5lib not thread safe. Is the Python SAX library thread-safe? In-Reply-To: <4f5d0b82$0$11967$742ec2ed@news.sonic.net> References: <4f5d0b82$0$11967$742ec2ed@news.sonic.net> Message-ID: <20120311214501.GA12816@cskk.homeip.net> On 11Mar2012 13:30, John Nagle wrote: | "html5lib" is apparently not thread safe. | (see "http://code.google.com/p/html5lib/issues/detail?id=189") | Looking at the code, I've only found about three problems. | They're all the usual "cached in a global without locking" bug. | A few locks would fix that. | | But html5lib calls the XML SAX parser. Is that thread-safe? | Or is there more trouble down at the bottom? | | (I run a multi-threaded web crawler, and currently use BeautifulSoup, | which is thread safe, although dated. I'm looking at converting to | html5lib.) IIRC, BeautifulSoup4 may do that for you: http://www.crummy.com/software/BeautifulSoup/bs4/doc/ http://www.crummy.com/software/BeautifulSoup/bs4/doc/#you-need-a-parser "Beautiful Soup 4 uses html.parser by default, but you can plug in lxml or html5lib and use that instead." Just for interest, re locking, I wrote a little decorator the other day, thus: @locked_property def foo(self): compute foo here ... return foo value and am rolling its use out amongst my classes. Code: def locked_property(func, lock_name='_lock', prop_name=None, unset_object=None): ''' A property whose access is controlled by a lock if unset. ''' if prop_name is None: prop_name = '_' + func.func_name def getprop(self): ''' Attempt lockless fetch of property first. Use lock if property is unset. ''' p = getattr(self, prop_name) if p is unset_object: with getattr(self, lock_name): p = getattr(self, prop_name) if p is unset_object: p = func(self) setattr(self, prop_name, p) return p return property(getprop) It tries to be lockless in the common case. I suspect it is only safe in CPython where there is a GIL. If raw python assignments and fetches can overlap (eg Jypthon I think?) I probably need shared "read" lock around the first "p = getattr(self, prop_name). Any remarks? Cheers, -- Cameron Simpson DoD#743 http://www.cskk.ezoshosting.com/cs/ Ed Campbell's pointers for long trips: 1. lay out the bare minimum of stuff that you need to take with you, then put at least half of it back. From clp2 at rebertia.com Sun Mar 11 17:49:25 2012 From: clp2 at rebertia.com (Chris Rebert) Date: Sun, 11 Mar 2012 14:49:25 -0700 Subject: Raise X or Raise X()? In-Reply-To: <4f5d0d06$0$6856$e4fe514c@news2.news.xs4all.nl> References: <387014.2537.1331492695725.JavaMail.geo-discussion-forums@pbjv6> <4f5d0d06$0$6856$e4fe514c@news2.news.xs4all.nl> Message-ID: On Sun, Mar 11, 2012 at 1:37 PM, Irmen de Jong wrote: > On 11-3-2012 20:04, bvdp wrote: >> Which is preferred in a raise: X or X()? I've seen both. In my specific case I'm dumping out of a deep loop: >> >> try: >> ? for ... >> ? ? for ... >> ? ? ? for ... >> ? ? ? ? if match: >> ? ? ? ? ? ?raise StopInteration() >> ? ? ? ? ?else ... >> >> except StopInteration: >> ? ?print "found it" > > "raise X" is a special case of the 3-args raise. Effectively it just raises an instance > of X which is constructed with an empty argument list. Therefore, "raise X()" is > equivalent, as far as I know. > > See http://docs.python.org/reference/simple_stmts.html#the-raise-statement Note that the 3-argument form of `raise` has been eliminated in Python 3. However, both: raise an_exception_instance and: raise AnExceptionClass # will have a blank error message are still permitted. Interesting stylistic question though. I'd support the X() form for uniformity with the majority of cases where an error message is specified for the exception. Cheers, Chris From ben+python at benfinney.id.au Sun Mar 11 18:27:08 2012 From: ben+python at benfinney.id.au (Ben Finney) Date: Mon, 12 Mar 2012 09:27:08 +1100 Subject: [RFC] PEP 3143: supplementary group list concerns References: Message-ID: <874ntukc3n.fsf@benfinney.id.au> Jan Pokorn? writes: > in the light of a recent spot in Python Paste [1], I've come across > the python-daemon [2] implementation and found it also lacks support > for supplementary groups. Thank you for your interest in ?python-daemon?. To know specifically what you're referring to in most of this message, I think your reference ?[1]? is necessary; but you didn't provide it. -- \ ?Pray, v. To ask that the laws of the universe be annulled in | `\ behalf of a single petitioner confessedly unworthy.? ?Ambrose | _o__) Bierce, _The Devil's Dictionary_, 1906 | Ben Finney From johnjsal at gmail.com Sun Mar 11 18:53:47 2012 From: johnjsal at gmail.com (John Salerno) Date: Sun, 11 Mar 2012 15:53:47 -0700 (PDT) Subject: What's the best way to parse this HTML tag? Message-ID: <239c4ad7-ac93-45c5-98d6-71a434e1c5aa@r21g2000yqa.googlegroups.com> I'm using Beautiful Soup to extract some song information from a radio station's website that lists the songs it plays as it plays them. Getting the time that the song is played is easy, because the time is wrapped in a
    tag all by itself with a class attribute that has a specific value I can search for. But the actual song title and artist information is harder, because the HTML isn't quite as precise. Here's a sample: This is about as far as I can drill down without getting TOO specific. I simply find the
    tags with the "cmPlaylistContent" class. This tag contains both the song title and the artist name, and sometimes miscellaneous other information as well, like a way to vote for the song or links to purchase it from iTunes or Amazon. So my question is, given the above HTML, how can I best extract the song title and artist name? It SEEMS like they are always the first two pieces of information in the tag, such that: for item in div.stripped_strings: print(item) Love Without End, Amen George Strait Download Song: iTunes | Amazon MP3 Comments??(1) Votes??(1) and I could simply get the first two items returned by that generator. It's not quite as clean as I'd like, because I have no idea if anything could ever be inserted before either of these items, thus messing it all up. I also don't want to rely on the tag, which makes me shudder, or the tag, because I don't know if they will always have an href. Ideall, the tag would have also had an attribute that labeled the title as the title, and the artist as the artist, but alas..... Therefore, I appeal to your greater wisdom in these matters. Given this HTML, is there a "best practice" for how to refer to the song title and artist? Thanks! From cs at zip.com.au Sun Mar 11 19:04:14 2012 From: cs at zip.com.au (Cameron Simpson) Date: Mon, 12 Mar 2012 10:04:14 +1100 Subject: Launching A Truly Disjoint Process In-Reply-To: <4F5D1A71.1010908@davea.name> References: <4F5D1A71.1010908@davea.name> Message-ID: <20120311230414.GA20637@cskk.homeip.net> On 11Mar2012 17:34, Dave Angel wrote: | On 03/11/2012 05:01 PM, Ami Tavory wrote: | > I'm encountering a problem using the multiprocessing module to create a | > process that is truly disjoint from the parent process: i.e., one that | > contains no "memory" of the parent process, nor any record in the parent | > process that it is its child. This originated in a pygtk problem, but I'll | > try to put down as little pygtk as possible - just enough to explain the | > problem (also, sorry, but I couldn't get an answer at the gtk forum). | > | > The code is a small python debugger front-end for GEdit. The plugin code, | > run from GEdit's process, uses | > multiprocessing.Process(target = run_dbg) | > to launch the debugger in a function in separate process. The debugger uses | > the bdb module like this: | > bdb.run('execfile("%s")' % script). | > This seems to work fine, except if the script being debugged is itself a | > pygtk script. Specifically, if it contains the code | > Gtk.main() | > then GEdit crashes with [...snip...] | | Why not try using bash as an intermediate executable? Have your first | python process invoke bash, giving it the arguments to in turn launch | the second python process. Why use bash at all? That requires painful and inefficient argument quoting, etc. Just invoke Python itself directly i.e. get subprocess to fork/exec (aka spawn) a new invocation of Python instead of using execfile. Totally untested prototype based purely on a cursory glance at the docs: subprocess.Popen( ( 'env', 'bdb_execfile='+script, 'python', '-c', 'import bdb; import os; bdb.run("execfile(os.environ[\"bdb_execfile\"])")', ) ) That "import..." string is all one line. Of course various arguments to Popen as required, etc. Cheers, -- Cameron Simpson DoD#743 http://www.cskk.ezoshosting.com/cs/ Here's a great .sig I wrote, so good it doesn't rhyme. Jon Benger From jpokorny at redhat.com Sun Mar 11 19:41:52 2012 From: jpokorny at redhat.com (Jan =?iso-8859-1?Q?Pokorn=FD?=) Date: Mon, 12 Mar 2012 00:41:52 +0100 Subject: [RFC] PEP 3143: supplementary group list concerns In-Reply-To: <874ntukc3n.fsf@benfinney.id.au> References: <874ntukc3n.fsf@benfinney.id.au> Message-ID: <20120311234152.GA6118@redhat.com> On 12/03/12 09:27 +1100, Ben Finney wrote: > Jan Pokorn? writes: > >> in the light of a recent spot in Python Paste [1], I've come across >> the python-daemon [2] implementation and found it also lacks support >> for supplementary groups. > > Thank you for your interest in ?python-daemon?. > > To know specifically what you're referring to in most of this message, > I think your reference ?[1]? is necessary; but you didn't provide it. My bad, I've sent it with unfinished renumbering. Please swap [1]+[2] in the quoted part and the missing reference is http://pypi.python.org/pypi/python-daemon/ (for some reason, this points to 1.5.5, even though 1.6 is also there: http://pypi.python.org/pypi/python-daemon/1.6 ). From gelonida at gmail.com Sun Mar 11 19:56:26 2012 From: gelonida at gmail.com (Gelonida N) Date: Mon, 12 Mar 2012 00:56:26 +0100 Subject: How to know that two pyc files contain the same code In-Reply-To: <4f5c4f0d$0$29891$c3e8da3$5496439d@news.astraweb.com> References: <4f5bdb14$0$29891$c3e8da3$5496439d@news.astraweb.com> <4f5c4f0d$0$29891$c3e8da3$5496439d@news.astraweb.com> Message-ID: On 03/11/2012 08:06 AM, Steven D'Aprano wrote: > What if one merely changed the order of definition? Instead of: > > def foo(): pass > def bar(): pass > > one had this? > > def bar(): pass > def foo(): pass > > It depends on why the OP cares if they are "identical". I can imagine use- > cases where the right solution is to forget ideas about identical code, > and just checksum the files (ignoring any timestamps). I guess this is what I will do for my use case Perform a checksum ignoring the time stamp. What I did not know though is where the time stamp was located. it seems it's in bytes 4-7 for all C-python versions so far. What is regrettable though is, that the absolute path name is part of the .pyc file, as I do not care Following snippet calculates the hash of a .pyc file by just ignoring the time stamp: import hashlib def md5_for_pyc(fname): hasher = hashlib.md5() with open(fname, 'rb') as fin: version = fin.read(4) hasher.update(version) _tstamp = fin.read(4) bytecode = fin.read() hasher.update(bytecode) return hasher.hexdigest() From steve+comp.lang.python at pearwood.info Sun Mar 11 19:59:09 2012 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 11 Mar 2012 23:59:09 GMT Subject: Raise X or Raise X()? References: <387014.2537.1331492695725.JavaMail.geo-discussion-forums@pbjv6> Message-ID: <4f5d3c4c$0$29891$c3e8da3$5496439d@news.astraweb.com> On Sun, 11 Mar 2012 12:04:55 -0700, bvdp wrote: > Which is preferred in a raise: X or X()? Both. Always use raise "X(*args)" when you need to provide arguments (which you should always do for exceptions meant for the caller to see). The form "raise X, args" should be considered discouraged, and in fact is gone in Python 3.x. Purely internal exceptions (which you raise and catch yourself) don't need arguments, so there is no difference between the two forms: "raise X" is exactly equivalent to "raise X()" with no arguments. Use whichever takes your fancy. Personally, I used "raise X" to mean "this doesn't need arguments and should never have any" and "raise X()" to mean "this needs arguments but I'm too lazy to provide them right now". Think of it as a FIXME. -- Steven From roy at panix.com Sun Mar 11 20:28:33 2012 From: roy at panix.com (Roy Smith) Date: Sun, 11 Mar 2012 20:28:33 -0400 Subject: What's the best way to parse this HTML tag? References: <239c4ad7-ac93-45c5-98d6-71a434e1c5aa@r21g2000yqa.googlegroups.com> Message-ID: In article <239c4ad7-ac93-45c5-98d6-71a434e1c5aa at r21g2000yqa.googlegroups.com>, John Salerno wrote: > Getting the time that the song is played is easy, because the time is > wrapped in a
    tag all by itself with a class attribute that has a > specific value I can search for. But the actual song title and artist > information is harder, because the HTML isn't quite as precise. Here's > a sample: > >
    > > > Love Without End, Amen > > >
    > > George Strait > > [...] > Therefore, I appeal to your greater wisdom in these matters. Given > this HTML, is there a "best practice" for how to refer to the song > title and artist? Obviously, any attempt at screen scraping is fraught with peril. Beautiful Soup is a great tool but it doesn't negate the fact that you've made a pact with the devil. That being said, if I had to guess, here's your puppy: > > Love Without End, Amen > the thing to look for is an "a" element with an href that starts with "/lsp/t", where "t" is for "track". Likewise: > > George Strait > an href starting with "/lsp/a" is probably an artist link. You owe the Oracle three helpings of tag soup. From steve+comp.lang.python at pearwood.info Sun Mar 11 20:30:08 2012 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 12 Mar 2012 00:30:08 GMT Subject: How to break long method name into more than one line? References: Message-ID: <4f5d4390$0$29891$c3e8da3$5496439d@news.astraweb.com> On Sun, 11 Mar 2012 11:53:45 -0700, Herman wrote: > I am trying to stick to the rule described in the TDD book that, each > test method name consists of the method name to be tested, inputs and > the expected outputs. *The* TDD book? There's only one? Surely not. That rule sounds utterly impractical. I can't think of anything to recommend it. Like any other function, method or class, tests should have meaningful names, but reading the name alone should not necessarily tell you *everything* about the function. We have "len", not "len_sequence_or_mapping_int", and similarly it is perfectly reasonable to have "test_len_empty" rather than "test_len_emptylist_emptystr_emptyunicode_emptydict_emptyset_emptytuple_zero". I expect that naming rule was invented by either people who have heard of test driven development, but never actually done it, or by people so anally-retentive that if they make seven short car trips over an hour, they check the tyre pressure, oil and water seven times because "the manual says to check before *every* trip". No offence. My advice is to moderate the naming convention of your tests with a good dose of common sense and aim for names which are readable rather than names that contain everything including the kitchen sink. Imagine you are in a technical meeting with some of your fellow programmers, and need to ask for help with a failing test. Imagine saying the name of the test aloud in a sentence. Does it add clarity to the discussion, or obfuscate it? People's short term memory can only hold so much (allegedly "seven plus or minus two"), and if the name itself hits that limit, you leave nothing left for the rest of the sentence. http://en.wikipedia.org/wiki/The_Magical_Number_Seven,_Plus_or_Minus_Two Names should be practically, rather than conforming to some naming rule that hurts readability and obfuscates the tests. > It takes up a lot of space and my company has a > rule of limiting 79 characters (or 80) per line. I found that def > abcdeef\ > dddaaa(self): > pass > > does not work, but > def \ > abcsajfoijfiawifoiwejfoi(self): > pass > > works. Is this the only way to do it? Yes. You can't split tokens over multiple lines, or put any whitespace between them. -- Steven From roy at panix.com Sun Mar 11 20:43:13 2012 From: roy at panix.com (Roy Smith) Date: Sun, 11 Mar 2012 20:43:13 -0400 Subject: How to break long method name into more than one line? References: <4f5d4390$0$29891$c3e8da3$5496439d@news.astraweb.com> Message-ID: In article <4f5d4390$0$29891$c3e8da3$5496439d at news.astraweb.com>, Steven D'Aprano wrote: > You can't split tokens over multiple lines, or put any whitespace > between them. Well, if you truly wanted to be perverse, you could write some kind of decorator: @make_long_named_test_method('some', 'very', 'long', 'list', 'of', 'token', 'fragments') def x(self): blah, blah, blah which creates a "test_some_very_long_list_of_token_fragments" method. But it would be a lot easier to just use sane method names. From bob at mellowood.ca Sun Mar 11 21:53:06 2012 From: bob at mellowood.ca (bvdp) Date: Sun, 11 Mar 2012 18:53:06 -0700 (PDT) Subject: Raise X or Raise X()? In-Reply-To: <4f5d3c4c$0$29891$c3e8da3$5496439d@news.astraweb.com> References: <387014.2537.1331492695725.JavaMail.geo-discussion-forums@pbjv6> <4f5d3c4c$0$29891$c3e8da3$5496439d@news.astraweb.com> Message-ID: <12235670.2782.1331517186309.JavaMail.geo-discussion-forums@pbjv6> Thanks all for the comments. > Personally, I used "raise X" to mean "this doesn't need arguments and > should never have any" and "raise X()" to mean "this needs arguments but > I'm too lazy to provide them right now". Think of it as a FIXME. Yes, that makes as much sense as anything else :) From python at mrabarnett.plus.com Sun Mar 11 22:26:03 2012 From: python at mrabarnett.plus.com (MRAB) Date: Mon, 12 Mar 2012 02:26:03 +0000 Subject: Raise X or Raise X()? In-Reply-To: <4f5d3c4c$0$29891$c3e8da3$5496439d@news.astraweb.com> References: <387014.2537.1331492695725.JavaMail.geo-discussion-forums@pbjv6> <4f5d3c4c$0$29891$c3e8da3$5496439d@news.astraweb.com> Message-ID: <4F5D5EBB.8090001@mrabarnett.plus.com> On 11/03/2012 23:59, Steven D'Aprano wrote: > On Sun, 11 Mar 2012 12:04:55 -0700, bvdp wrote: > >> Which is preferred in a raise: X or X()? > > Both. > > Always use raise "X(*args)" when you need to provide arguments (which you > should always do for exceptions meant for the caller to see). The form > "raise X, args" should be considered discouraged, and in fact is gone in > Python 3.x. > > Purely internal exceptions (which you raise and catch yourself) don't > need arguments, so there is no difference between the two forms: > "raise X" is exactly equivalent to "raise X()" with no arguments. Use > whichever takes your fancy. > > Personally, I used "raise X" to mean "this doesn't need arguments and > should never have any" and "raise X()" to mean "this needs arguments but > I'm too lazy to provide them right now". Think of it as a FIXME. > As some do need arguments, I'd do the opposite; no parentheses would mean "I haven't finished yet". :-) From johnjsal at gmail.com Sun Mar 11 22:35:50 2012 From: johnjsal at gmail.com (John Salerno) Date: Sun, 11 Mar 2012 19:35:50 -0700 (PDT) Subject: What's the best way to parse this HTML tag? References: <239c4ad7-ac93-45c5-98d6-71a434e1c5aa@r21g2000yqa.googlegroups.com> Message-ID: On Mar 11, 7:28?pm, Roy Smith wrote: > In article > <239c4ad7-ac93-45c5-98d6-71a434e1c... at r21g2000yqa.googlegroups.com>, > ?John Salerno wrote: > > > > > > > > > > > Getting the time that the song is played is easy, because the time is > > wrapped in a
    tag all by itself with a class attribute that has a > > specific value I can search for. But the actual song title and artist > > information is harder, because the HTML isn't quite as precise. Here's > > a sample: > > >
    > > ? > > ? > > ? ?Love Without End, Amen > > ? > > ? > > ?
    > > ? > > ? George Strait > > ? > > [...] > > Therefore, I appeal to your greater wisdom in these matters. Given > > this HTML, is there a "best practice" for how to refer to the song > > title and artist? > > Obviously, any attempt at screen scraping is fraught with peril. > Beautiful Soup is a great tool but it doesn't negate the fact that > you've made a pact with the devil. ?That being said, if I had to guess, > here's your puppy: > > > ? > > ? ?Love Without End, Amen > > ? > > the thing to look for is an "a" element with an href that starts with > "/lsp/t", where "t" is for "track". ?Likewise: > > > ? > > ? George Strait > > ? > > an href starting with "/lsp/a" is probably an artist link. > > You owe the Oracle three helpings of tag soup. Well, I had considered exactly that method, but I don't know for sure if the titles and names will always have links like that, so I didn't want to tie my programming to something so specific. But perhaps it's still better than just taking the first two strings. From nagle at animats.com Mon Mar 12 00:48:19 2012 From: nagle at animats.com (John Nagle) Date: Sun, 11 Mar 2012 21:48:19 -0700 Subject: html5lib not thread safe. Is the Python SAX library thread-safe? In-Reply-To: References: <4f5d0b82$0$11967$742ec2ed@news.sonic.net> Message-ID: <4f5d8012$0$12021$742ec2ed@news.sonic.net> On 3/11/2012 2:45 PM, Cameron Simpson wrote: > On 11Mar2012 13:30, John Nagle wrote: > | "html5lib" is apparently not thread safe. > | (see "http://code.google.com/p/html5lib/issues/detail?id=189") > | Looking at the code, I've only found about three problems. > | They're all the usual "cached in a global without locking" bug. > | A few locks would fix that. > | > | But html5lib calls the XML SAX parser. Is that thread-safe? > | Or is there more trouble down at the bottom? > | > | (I run a multi-threaded web crawler, and currently use BeautifulSoup, > | which is thread safe, although dated. I'm looking at converting to > | html5lib.) > > IIRC, BeautifulSoup4 may do that for you: > > http://www.crummy.com/software/BeautifulSoup/bs4/doc/ > > http://www.crummy.com/software/BeautifulSoup/bs4/doc/#you-need-a-parser > "Beautiful Soup 4 uses html.parser by default, but you can plug in > lxml or html5lib and use that instead." I want to use HTML5 standard parsing of bad HTML. (HTML5 formally defines how to parse bad comments, for example.) I currently have a modified version of BeautifulSoup that's more robust than the standard one, but it doesn't handle errors the same way browsers do. John Nagle From hotice.vegtiger at gmail.com Mon Mar 12 01:39:54 2012 From: hotice.vegtiger at gmail.com (Ashish Aggarwal) Date: Sun, 11 Mar 2012 22:39:54 -0700 (PDT) Subject: How Python empowers Java? Message-ID: <90d7a28f-8d7b-4623-88ea-07e0e101b4e3@ni10g2000pbc.googlegroups.com> I am a Java developer but new to Python. I am trying to assess, as what are new capabilities that Python will provide me if I use it with Java. Guys can you please help me? From bv4bv4bv4 at gmail.com Mon Mar 12 02:15:46 2012 From: bv4bv4bv4 at gmail.com (BV BV) Date: Sun, 11 Mar 2012 23:15:46 -0700 (PDT) Subject: GENOCIDE IN THE TWENTY-FIRST CENTURY IN SYRIA !!!!!!!!!!!!!! Message-ID: GENOCIDE IN THE TWENTY-FIRST CENTURY IN SYRIA SCHOKING ASSAD REGIME SYRIA http://www.youtube.com/watch?v=5H1NL8aOlsg http://www.youtube.com/watch?v=jZP51eRKy34 http://www.youtube.com/watch?v=e7AY8hSUjVc http://www.youtube.com/watch?v=g3ZPbUcKI-k&feature=related BABY TORTURED TO DEATH http://www.youtube.com/watch?v=938X3JkpnV4&feature=related http://www.youtube.com/watch?v=ybMeT4UUe6o&feature=related TORTURE CHILDREN IN FRONT OF HIS MOTHER'S SHOOTING ON HIS FEET http://www.youtube.com/watch?v=s-hfEArhs60&feature=related THE FIRST SCENS FOR AL-SABEEL AREA MASSACRE IN HOMS 5 2 2012 http://www.youtube.com/watch?v=bfJKCxiplXg BABA AMR MASSACRE 26 DEC 2011 http://www.youtube.com/watch?v=IK0hutwbopk&feature=related&skipcontrinter=1 From atavory at gmail.com Mon Mar 12 04:41:09 2012 From: atavory at gmail.com (Ami Tavory) Date: Mon, 12 Mar 2012 10:41:09 +0200 Subject: Fwd: Launching A Truly Disjoint Process In-Reply-To: <20120311230414.GA20637@cskk.homeip.net> References: <4F5D1A71.1010908@davea.name> <20120311230414.GA20637@cskk.homeip.net> Message-ID: ---------- Forwarded message ---------- From: Cameron Simpson Date: Mon, Mar 12, 2012 at 1:04 AM Subject: Re: Launching A Truly Disjoint Process To: Dave Angel Cc: Ami Tavory , python-list at python.org On 11Mar2012 17:34, Dave Angel wrote: | On 03/11/2012 05:01 PM, Ami Tavory wrote: | > I'm encountering a problem using the multiprocessing module to create a | > process that is truly disjoint from the parent process:... | Why not try using bash as an intermediate executable? Have your first | python process invoke bash, giving it the arguments to in turn launch | the second python process. Why use bash at all? That requires painful and inefficient argument quoting, etc. Just invoke Python itself directly i.e. get subprocess to fork/exec (aka spawn) a new invocation of Python instead of using execfile. Dave, Cameron, Many thanks. I ran some initial tests regarding your suggestions, and things look good. -------------- next part -------------- An HTML attachment was scrubbed... URL: From hyperboogie at gmail.com Mon Mar 12 05:09:36 2012 From: hyperboogie at gmail.com (hyperboogie) Date: Mon, 12 Mar 2012 02:09:36 -0700 (PDT) Subject: newb __init__ inheritance In-Reply-To: <1c6db866-6fa3-4de5-96de-51d6720a1300@x17g2000yqj.googlegroups.com> References: <1c6db866-6fa3-4de5-96de-51d6720a1300@x17g2000yqj.googlegroups.com> Message-ID: <18399211.724.1331543376411.JavaMail.geo-discussion-forums@vbbfy7> On Thursday, March 8, 2012 5:25:06 PM UTC+2, hyperboogie wrote: > Hello everyone. > > This is my first post in this group. > I started learning python a week ago from the "dive into python" e- > book and thus far all was clear. > However today while reading chapter 5 about objects and object > orientation I ran into something that confused me. > it says here: > http://www.diveintopython.net/object_oriented_framework/defining_classes.html#fileinfo.class.example > > "__init__ methods are optional, but when you define one, you must > remember to explicitly call the ancestor's __init__ method (if it > defines one). This is more generally true: whenever a descendant wants > to extend the behavior of the ancestor, the descendant method must > explicitly call the ancestor method at the proper time, with the > proper arguments. " > > However later on in the chapter: > http://www.diveintopython.net/object_oriented_framework/userdict.html > > it says: > "Methods are defined solely by their name, and there can be only one > method per class with a given name. So if a descendant class has an > __init__ method, it always overrides the ancestor __init__ method, > even if the descendant defines it with a different argument list. And > the same rule applies to any other method. " > > My question is if __init__ in the descendant class overrides __init__ > in the parent class how can I call the parent's __init__ from the > descendant class - I just overrode it didn't I? > > Am I missing something more fundamental here? > Thanks Thank you so much everyone for you help. No doubt I still have a long way to go before I feel comfortable with python. Appreciate all your help... From no.email at nospam.invalid Mon Mar 12 05:39:39 2012 From: no.email at nospam.invalid (Paul Rubin) Date: Mon, 12 Mar 2012 02:39:39 -0700 Subject: html5lib not thread safe. Is the Python SAX library thread-safe? References: <4f5d0b82$0$11967$742ec2ed@news.sonic.net> Message-ID: <7x399e40pw.fsf@ruckus.brouhaha.com> John Nagle writes: > But html5lib calls the XML SAX parser. Is that thread-safe? > Or is there more trouble down at the bottom? According to http://xmlbench.sourceforge.net/results/features200303/index.html libxml and expat both purport to be thread-safe. I've used the python expat library (not from multiple threads) and it works fine, though the python calls slow it down by worse than an order of magnitude. From stefan_ml at behnel.de Mon Mar 12 06:05:34 2012 From: stefan_ml at behnel.de (Stefan Behnel) Date: Mon, 12 Mar 2012 11:05:34 +0100 Subject: html5lib not thread safe. Is the Python SAX library thread-safe? In-Reply-To: <4f5d0b82$0$11967$742ec2ed@news.sonic.net> References: <4f5d0b82$0$11967$742ec2ed@news.sonic.net> Message-ID: John Nagle, 11.03.2012 21:30: > "html5lib" is apparently not thread safe. > (see "http://code.google.com/p/html5lib/issues/detail?id=189") > Looking at the code, I've only found about three problems. > They're all the usual "cached in a global without locking" bug. > A few locks would fix that. > > But html5lib calls the XML SAX parser. Is that thread-safe? > Or is there more trouble down at the bottom? > > (I run a multi-threaded web crawler, and currently use BeautifulSoup, > which is thread safe, although dated. I'm looking at converting to > html5lib.) You may also consider moving to lxml. BeautifulSoup supports it as a parser backend these days, so you wouldn't even have to rewrite your code to use it. And performance-wise, well ... http://blog.ianbicking.org/2008/03/30/python-html-parser-performance/ Stefan From jeanmichel at sequans.com Mon Mar 12 06:37:48 2012 From: jeanmichel at sequans.com (Jean-Michel Pichavant) Date: Mon, 12 Mar 2012 11:37:48 +0100 Subject: Raise X or Raise X()? In-Reply-To: <387014.2537.1331492695725.JavaMail.geo-discussion-forums@pbjv6> References: <387014.2537.1331492695725.JavaMail.geo-discussion-forums@pbjv6> Message-ID: <4F5DD1FC.7080603@sequans.com> bvdp wrote: > Which is preferred in a raise: X or X()? I've seen both. In my specific case I'm dumping out of a deep loop: > > try: > for ... > for ... > for ... > if match: > raise StopInteration() > else ... > > except StopInteration: > print "found it" > I prefer the raise X() version, it fulfils the zen of python : "Special cases aren't special enough to break the rules. There should be one-- and preferably only one --obvious way to do it." I still wonder why they've added the class raise form, on which purpose. JM From albert at spenarnc.xs4all.nl Mon Mar 12 07:27:25 2012 From: albert at spenarnc.xs4all.nl (Albert van der Horst) Date: 12 Mar 2012 11:27:25 GMT Subject: New Science Discovery: Perl Idiots Remain Idiots After A Decade!New Science Discovery: Perl Idiots Remain Idiots After A Decade! References: <0078bbfb-5dfc-48fc-af1a-69de3cf15c3e@b1g2000yqb.googlegroups.com> Message-ID: In article <0078bbfb-5dfc-48fc-af1a-69de3cf15c3e at b1g2000yqb.googlegroups.com>, Xah Lee wrote: >New Science Discovery: Perl Idiots Remain Idiots After A Decade! > >A excerpt from the new book =E3=80=88Modern Perl=E3=80=89, just published, = >chapter 4 >on =E2=80=9COperators=E2=80=9D. Quote: > >=C2=ABThe associativity of an operator governs whether it evaluates from >left to right or right to left. Addition is left associative, such >that 2 + 3 + 4 evaluates 2 + 3 first, then adds 4 to the result. >Exponentiation is right associative, such that 2 ** 3 ** 4 evaluates 3 >** 4 first, then raises 2 to the 81st power. =C2=BB > >LOL. Looks like the perl folks haven't changed. Fundamentals of >serious math got botched so badly. You're confused. Associativity of operators is defined in mathematics. (The same concept may be used in programming). "left-associativity" and "right-associativity" are computer languages concept and their definitions are not from mathematics. Interestingly in mathematics associative means that it doesn't matter whether you use (a.b).c or a.(b.c). Using xxx-associativity to indicate that it *does* matter is a bit perverse, but the Perl people are not to blame if they use a term in their usual sense. Groetjes Albert -- -- Albert van der Horst, UTRECHT,THE NETHERLANDS Economic growth -- being exponential -- ultimately falters. albert at spe&ar&c.xs4all.nl &=n http://home.hccnet.nl/a.w.m.van.der.horst From spamtrap at library.lspace.org.invalid Mon Mar 12 08:40:56 2012 From: spamtrap at library.lspace.org.invalid (Shmuel Metz (Seymour J.)) Date: Mon, 12 Mar 2012 08:40:56 -0400 Subject: New Science Discovery: Perl Detractors Remain Idiots After A Decade References: <0078bbfb-5dfc-48fc-af1a-69de3cf15c3e@b1g2000yqb.googlegroups.com> Message-ID: <4f5deed8$6$fuzhry+tra$mr2ice@news.patriot.net> In , on 03/12/2012 at 11:27 AM, Albert van der Horst said: >You're confused. No, s/h/it is just an acephalic troll with delusions of adequacy. >"left-associativity" and "right-associativity" are computer >languages concept and their definitions are not from mathematics. Don't confuse the google pest with facts. -- Shmuel (Seymour J.) Metz, SysProg and JOAT Unsolicited bulk E-mail subject to legal action. I reserve the right to publicly post or ridicule any abusive E-mail. Reply to domain Patriot dot net user shmuel+news to contact me. Do not reply to spamtrap at library.lspace.org From robert.kern at gmail.com Mon Mar 12 08:47:27 2012 From: robert.kern at gmail.com (Robert Kern) Date: Mon, 12 Mar 2012 12:47:27 +0000 Subject: Raise X or Raise X()? In-Reply-To: <4F5DD1FC.7080603@sequans.com> References: <387014.2537.1331492695725.JavaMail.geo-discussion-forums@pbjv6> <4F5DD1FC.7080603@sequans.com> Message-ID: On 3/12/12 10:37 AM, Jean-Michel Pichavant wrote: > bvdp wrote: >> Which is preferred in a raise: X or X()? I've seen both. In my specific case >> I'm dumping out of a deep loop: >> >> try: >> for ... >> for ... >> for ... >> if match: >> raise StopInteration() >> else ... >> >> except StopInteration: >> print "found it" > > I prefer the raise X() version, it fulfils the zen of python : > > "Special cases aren't special enough to break the rules. > There should be one-- and preferably only one --obvious way to do it." > > I still wonder why they've added the class raise form, on which purpose. The class raise form used to be the only way to raise exceptions. To pass an argument, there was special syntax: raise Exception, "some message" This syntax has been done away with in Python 3 in favor of regular calling conventions. Python 3 still allows bare classes, though. I also prefer to always raise instances of exceptions rather than bare exception classes. It simplifies the mental model. -- Robert Kern "I have come to believe that the whole world is an enigma, a harmless enigma that is made terrible by our own mad attempt to interpret it as though it had an underlying truth." -- Umberto Eco From kiuhnm03.4t.yahoo.it Mon Mar 12 09:05:54 2012 From: kiuhnm03.4t.yahoo.it (Kiuhnm) Date: Mon, 12 Mar 2012 14:05:54 +0100 Subject: New Science Discovery: Perl Idiots Remain Idiots After A Decade!New Science Discovery: Perl Idiots Remain Idiots After A Decade! In-Reply-To: References: <0078bbfb-5dfc-48fc-af1a-69de3cf15c3e@b1g2000yqb.googlegroups.com> Message-ID: <4f5df4b3$0$1375$4fafbaef@reader1.news.tin.it> On 3/12/2012 12:27, Albert van der Horst wrote: > Interestingly in mathematics associative means that it doesn't matter > whether you use (a.b).c or a.(b.c). > Using xxx-associativity to indicate that it *does* matter is > a bit perverse, but the Perl people are not to blame if they use > a term in their usual sense. You may see it this way: Def1. An operator +:SxS->S is left-associative iff a+b+c = (a+b)+c for all a,b,c in S. Def2. An operator +:SxS->S is right-associative iff a+b+c = a+(b+c) for all a,b,c in S. Def3. An operator +:SxS->S is associative iff it is both left and right-associative. Kiuhnm From fil.oracle at gmail.com Mon Mar 12 09:06:32 2012 From: fil.oracle at gmail.com (James Elford) Date: Mon, 12 Mar 2012 13:06:32 +0000 Subject: Raise X or Raise X()? In-Reply-To: <387014.2537.1331492695725.JavaMail.geo-discussion-forums@pbjv6> References: <387014.2537.1331492695725.JavaMail.geo-discussion-forums@pbjv6> Message-ID: <4F5DF4D8.20901@gmail.com> On 11/03/12 19:04, bvdp wrote: > Which is preferred in a raise: X or X()? I've seen both. In my specific case I'm dumping out of a deep loop: > > try: > for ... > for ... > for ... > if match: > raise StopInteration() > else ... > > except StopInteration: > print "found it" I wonder whether you need to use an exception here rather than a yield statement? Exceptions should reflect Exceptional circumstances (and come with associated stack trace, and so on...). The following should do something like what you want, without raising exceptions. >>> # Deeply loop into a collection of collections >>> def find(collection): ... for sub_col in collection: ... for item in sub_col: ... for foo in item.list_field: ... if foo.is_match: ... yield foo >>> # Some junk classes to iterate over >>> class Item(object): ... def __init__(self, some_range): ... self.list_field = [ListedItem(i) for i in some_range] >>> class ListedItem(object): ... def __init__(self, number): ... self.tag = number ... self.is_match = False >>> def __str__(self): ... return str(self.tag) >>> # Construct a list of items >>> l = [[Item(range(i)) for i in range(10)], ... [Item(range(i, 2*i)) for i in range(10,20)]] >>> l[0][9].list_field[3].is_match = True >>> for i in find(l): ... print(i) 3 James From rosuav at gmail.com Mon Mar 12 09:13:57 2012 From: rosuav at gmail.com (Chris Angelico) Date: Tue, 13 Mar 2012 00:13:57 +1100 Subject: Raise X or Raise X()? In-Reply-To: <4F5DF4D8.20901@gmail.com> References: <387014.2537.1331492695725.JavaMail.geo-discussion-forums@pbjv6> <4F5DF4D8.20901@gmail.com> Message-ID: On Tue, Mar 13, 2012 at 12:06 AM, James Elford wrote: > I wonder whether you need to use an exception here rather than a yield > statement? Or a return statement, if you're not needing multiple responses. ChrisA From roy at panix.com Mon Mar 12 09:27:02 2012 From: roy at panix.com (Roy Smith) Date: Mon, 12 Mar 2012 09:27:02 -0400 Subject: What's the best way to parse this HTML tag? References: <239c4ad7-ac93-45c5-98d6-71a434e1c5aa@r21g2000yqa.googlegroups.com> Message-ID: In article , John Salerno wrote: > Well, I had considered exactly that method, but I don't know for sure > if the titles and names will always have links like that, so I didn't > want to tie my programming to something so specific. But perhaps it's > still better than just taking the first two strings. Such is the nature of screen scraping. For the most part, web pages are not meant to be parsed. If you decide to go down the road of trying to extract data from them, all bets are off. You look at the markup, take your best guess, and go for it. There's no magic here. Nobody can look at this HTML and come up with some hard and fast rule for how you're supposed to parse it. And, even if they could, it's all likely to change tomorrow when the site rolls out their next UI makeover. From stefan_ml at behnel.de Mon Mar 12 09:52:49 2012 From: stefan_ml at behnel.de (Stefan Behnel) Date: Mon, 12 Mar 2012 14:52:49 +0100 Subject: Raise X or Raise X()? In-Reply-To: <4f5d0d06$0$6856$e4fe514c@news2.news.xs4all.nl> References: <387014.2537.1331492695725.JavaMail.geo-discussion-forums@pbjv6> <4f5d0d06$0$6856$e4fe514c@news2.news.xs4all.nl> Message-ID: Irmen de Jong, 11.03.2012 21:37: > On 11-3-2012 20:04, bvdp wrote: >> Which is preferred in a raise: X or X()? I've seen both. In my specific case I'm dumping out of a deep loop: >> >> try: >> for ... >> for ... >> for ... >> if match: >> raise StopInteration() >> else ... >> >> except StopInteration: >> print "found it" > > "raise X" is a special case of the 3-args raise. Effectively it just raises an instance > of X which is constructed with an empty argument list. Therefore, "raise X()" is > equivalent, as far as I know. Not completely, although that may be considered an implementation detail. When you raise an exception instance, it gets instantiated before being raised (by your own code). So you control exactly how the exception instance comes to life. When you raise the class instead of the instance, it may or may not get instantiated, depending on how it is being caught or discarded (and by whom, e.g. internally in the interpreter). In most cases, it will be instantiated, but only when someone catches it, i.e. at a later time, after raising it. If the instantiation of the exception has side effects, or if it fails for some reason (e.g. bad or missing arguments), the time of instantiation may make a difference. It's obviously bad design to use side effects here, but it's equally bad design to silently rely on it being side effect free. Note that if the exception happens to never get instantiated, you will safe a tiny bit of time for the overall propagation. But since it's hard to tell if that will happen or not, it would be a rather misguided micro optimisation for most Python code to base your decision on this, at least without prior benchmarking (with a real work-load etc.). In general, I tend to raise exception types only for very safe and common built-in exceptions, such as StopIteration, but whenever they take an argument, I raise the instance instead. For user provided exceptions, there is no real excuse for raising the type. BTW, StopIteration takes an optional argument in Python 3.3, but that's not a feature that is generally going to be used by Python code, I assume. So I'll just keep raising the type. :) Stefan From steve+comp.lang.python at pearwood.info Mon Mar 12 11:08:49 2012 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 12 Mar 2012 15:08:49 GMT Subject: Raise X or Raise X()? References: <387014.2537.1331492695725.JavaMail.geo-discussion-forums@pbjv6> <4f5d0d06$0$6856$e4fe514c@news2.news.xs4all.nl> Message-ID: <4f5e1180$0$29891$c3e8da3$5496439d@news.astraweb.com> On Mon, 12 Mar 2012 14:52:49 +0100, Stefan Behnel wrote: >> "raise X" is a special case of the 3-args raise. Effectively it just >> raises an instance of X which is constructed with an empty argument >> list. Therefore, "raise X()" is equivalent, as far as I know. > > Not completely, although that may be considered an implementation > detail. > > When you raise an exception instance, it gets instantiated before being > raised (by your own code). So you control exactly how the exception > instance comes to life. Normally the exception is instantiated just before you raise it. Of course, that's not compulsory. You can pre-load it if you want: instance = ValueError("spam") time.sleep(60) raise instance but generally we say raise ValueError("spam") and be done with it. > When you raise the class instead of the instance, it may or may not get > instantiated, depending on how it is being caught or discarded (and by > whom, e.g. internally in the interpreter). In most cases, it will be > instantiated, but only when someone catches it, i.e. at a later time, > after raising it. I don't think that is correct. Either the exception gets raised, or it doesn't. If it doesn't get raised, then no instance is instantiated (unless you did it yourself, as in the example above). But if it does get raised, then regardless of which form you use (the class or the instance), the exception instance *will* be instantiated. If you don't do it yourself, the raise statement will do it. Using Python 3.2: >>> class TestException(Exception): ... def __init__(self, *args): ... print("initialising exception") ... super().__init__(*args) ... >>> try: ... raise TestException ... except: ... pass ... initialising exception Whether you catch the exception or not, it still gets instantiated. Try it and see, and if you can find some way to actually raise the exception without instantiating the instance, I would love to see it. Implementation-wise, at least for Python 3.2, what seems to happen as best as I can tell from reading ceval.c, is that the opcode for raise checks the argument. If it is already an instance, it uses that; if it is not, it instantiates it immediately. (see function do_raise in ceval.c) So, technically, there may be a minuscule timing difference depending on whether you instantiate the exception in Python code or in C code, but I don't believe that this meaningful. > If the instantiation of the exception has side > effects, or if it fails for some reason (e.g. bad or missing arguments), > the time of instantiation may make a difference. I expect this is only relevant if you pre-instantiate the exception ahead of time. I suppose it is conceivable that, in a particularly odd corner case or two (perhaps using exceptions with side effects and/or threads or something) the nanosecond difference between raise X() and raise X might make a difference. But I'm having difficulty seeing that this is plausible. I think you will have to show me an example to prove it. Certainly, without threads, I don't think there is any difference. > It's obviously bad > design to use side effects here, but it's equally bad design to silently > rely on it being side effect free. I don't understand what you are trying to say here. We rely on code being side-effect free *all the time*. Or at least known side-effects, such as import or list.append. > Note that if the exception happens to never get instantiated, you will > safe a tiny bit of time for the overall propagation. I don't believe that is true. Looking at the C code, the exception appears to always be instantiated once you call raise. > But since it's hard > to tell if that will happen or not, it would be a rather misguided micro > optimisation for most Python code to base your decision on this, at > least without prior benchmarking (with a real work-load etc.). > > In general, I tend to raise exception types only for very safe and > common built-in exceptions, such as StopIteration, but whenever they > take an argument, I raise the instance instead. For user provided > exceptions, there is no real excuse for raising the type. My excuses are: * sometimes I don't need an error message, so why give one? * and it makes no difference whether I instantiate the exception or let raise do it for me > BTW, StopIteration takes an optional argument in Python 3.3, The time machine strikes again. StopIteration takes an optional argument going back to at least 2.6. steve at runes:~$ python2.6 Python 2.6.6 (r266:84292, Dec 27 2010, 00:02:40) [GCC 4.4.5] on linux2 Type "help", "copyright", "credits" or "license" for more information. >>> raise StopIteration("out of fuel") Traceback (most recent call last): File "", line 1, in StopIteration: out of fuel -- Steven From nagle at animats.com Mon Mar 12 12:07:56 2012 From: nagle at animats.com (John Nagle) Date: Mon, 12 Mar 2012 09:07:56 -0700 Subject: html5lib not thread safe. Is the Python SAX library thread-safe? In-Reply-To: References: <4f5d0b82$0$11967$742ec2ed@news.sonic.net> Message-ID: <4f5e1f5b$0$12023$742ec2ed@news.sonic.net> On 3/12/2012 3:05 AM, Stefan Behnel wrote: > John Nagle, 11.03.2012 21:30: >> "html5lib" is apparently not thread safe. >> (see "http://code.google.com/p/html5lib/issues/detail?id=189") >> Looking at the code, I've only found about three problems. >> They're all the usual "cached in a global without locking" bug. >> A few locks would fix that. >> >> But html5lib calls the XML SAX parser. Is that thread-safe? >> Or is there more trouble down at the bottom? >> >> (I run a multi-threaded web crawler, and currently use BeautifulSoup, >> which is thread safe, although dated. I'm looking at converting to >> html5lib.) > > You may also consider moving to lxml. BeautifulSoup supports it as a parser > backend these days, so you wouldn't even have to rewrite your code to use > it. And performance-wise, well ... > > http://blog.ianbicking.org/2008/03/30/python-html-parser-performance/ > > Stefan I want to move to html5lib because it handles HTML errors as specified by the HTML5 spec, which is what all newer browsers do. The HTML5 spec actually specifies, in great detail, how to parse common errors in HTML. It's amusing seeing that formalized. Malformed comments ( <- instead of <-- ) are now handled in a standard way, for example. So I'm trying to get html5parser fixed for thread safety. John Nagle From stefan_ml at behnel.de Mon Mar 12 12:08:09 2012 From: stefan_ml at behnel.de (Stefan Behnel) Date: Mon, 12 Mar 2012 17:08:09 +0100 Subject: Raise X or Raise X()? In-Reply-To: <4f5e1180$0$29891$c3e8da3$5496439d@news.astraweb.com> References: <387014.2537.1331492695725.JavaMail.geo-discussion-forums@pbjv6> <4f5d0d06$0$6856$e4fe514c@news2.news.xs4all.nl> <4f5e1180$0$29891$c3e8da3$5496439d@news.astraweb.com> Message-ID: Steven D'Aprano, 12.03.2012 16:08: > On Mon, 12 Mar 2012 14:52:49 +0100, Stefan Behnel wrote: >>> "raise X" is a special case of the 3-args raise. Effectively it just >>> raises an instance of X which is constructed with an empty argument >>> list. Therefore, "raise X()" is equivalent, as far as I know. >> >> Not completely, although that may be considered an implementation >> detail. >> >> When you raise an exception instance, it gets instantiated before being >> raised (by your own code). So you control exactly how the exception >> instance comes to life. > >> When you raise the class instead of the instance, it may or may not get >> instantiated, depending on how it is being caught or discarded (and by >> whom, e.g. internally in the interpreter). In most cases, it will be >> instantiated, but only when someone catches it, i.e. at a later time, >> after raising it. > > I don't think that is correct. Either the exception gets raised, or it > doesn't. If it doesn't get raised, then no instance is instantiated > (unless you did it yourself, as in the example above). But if it does get > raised, then regardless of which form you use (the class or the > instance), the exception instance *will* be instantiated. If you don't do > it yourself, the raise statement will do it. > > Using Python 3.2: Note that the exception handling was seriously reworked in Python 3, so there are substantial differences to Python 2. Although maybe not so many at the Python code level. > >>> class TestException(Exception): > .... def __init__(self, *args): > .... print("initialising exception") > .... super().__init__(*args) > .... > >>> try: > .... raise TestException > .... except: > .... pass > .... > initialising exception > > Whether you catch the exception or not, it still gets instantiated. Try > it and see, and if you can find some way to actually raise the exception > without instantiating the instance, I would love to see it. > > Implementation-wise, at least for Python 3.2, what seems to happen as > best as I can tell from reading ceval.c, is that the opcode for raise > checks the argument. If it is already an instance, it uses that; if it is > not, it instantiates it immediately. > > (see function do_raise in ceval.c) Right, it normalises the exception immediately, also in older Python versions. That's different at the C layer, but it looks like the interpreter does the right (i.e. only safe) thing for Python code. Good to know - and thanks for clearing this up. > So, technically, there may be a minuscule timing difference depending on > whether you instantiate the exception in Python code or in C code, but I > don't believe that this meaningful. The difference can be substantial in C code, especially for something like StopIteration if the instantiation can be avoided (in some cases even raising the exception is avoided completely!). However, given that Python code apparently can't raise types without instantiating them, I agree that it's not worth looking for a difference at that level. > I suppose it is conceivable that, in a particularly odd corner case or > two (perhaps using exceptions with side effects and/or threads or > something) the nanosecond difference between raise X() and raise X might > make a difference. But I'm having difficulty seeing that this is > plausible. I think you will have to show me an example to prove it. > > Certainly, without threads, I don't think there is any difference. Even with threads it will be hard to get at this difference due to the GIL. I can't see anything in do_raise() that would allow foreign code to run between the evaluation of the "raise" opcode and starting to instantiate the exception. >> It's obviously bad >> design to use side effects here, but it's equally bad design to silently >> rely on it being side effect free. > > I don't understand what you are trying to say here. We rely on code being > side-effect free *all the time*. That's fine for builtin stuff, functions etc. But for user provided exceptions, why should you make your code dependent on a side effect free instantiation just to be able to raise them without parentheses? Sounds like too little a gain to me. Besides, this is getting way hypothetical. >> Note that if the exception happens to never get instantiated, you will >> safe a tiny bit of time for the overall propagation. > > I don't believe that is true. Looking at the C code, the exception > appears to always be instantiated once you call raise. My fault, I was thinking at the C level again. >> BTW, StopIteration takes an optional argument in Python 3.3, > > The time machine strikes again. StopIteration takes an optional argument > going back to at least 2.6. > > steve at runes:~$ python2.6 > Python 2.6.6 (r266:84292, Dec 27 2010, 00:02:40) > [GCC 4.4.5] on linux2 > Type "help", "copyright", "credits" or "license" for more information. > >>> raise StopIteration("out of fuel") > Traceback (most recent call last): > File "", line 1, in > StopIteration: out of fuel Right, I think it's even at least 2.4 and likely much older than that. What I meant to say was that StopIteration has a "value" (an actual property) in Python 3.3, which represents its first argument. So that argument actually has specific semantics (see PEP 380), instead of just "being there". Stefan From tjreedy at udel.edu Mon Mar 12 12:11:32 2012 From: tjreedy at udel.edu (Terry Reedy) Date: Mon, 12 Mar 2012 12:11:32 -0400 Subject: How Python empowers Java? In-Reply-To: <90d7a28f-8d7b-4623-88ea-07e0e101b4e3@ni10g2000pbc.googlegroups.com> References: <90d7a28f-8d7b-4623-88ea-07e0e101b4e3@ni10g2000pbc.googlegroups.com> Message-ID: On 3/12/2012 1:39 AM, Ashish Aggarwal wrote: > I am a Java developer but new to Python. > I am trying to assess, as what are new capabilities that Python will > provide me if I use it with Java. > > Guys can you please help me? 1. Jython is a Python interpreter (older version) implemented in Java. It accesses Java classes located on the same machine. I believe it has an interactive mode just like CPython. So you can experiment interactively with the behavior of Java code. You can also write test suites for Java code in Jython. This is one actual use of Jython. 2. Learning a different object model may help you understand Java better. -- Terry Jan Reedy From raw at unknown-00-23-6c-8d-9e-26.lan Mon Mar 12 14:20:26 2012 From: raw at unknown-00-23-6c-8d-9e-26.lan (Raymond Wiker) Date: Mon, 12 Mar 2012 19:20:26 +0100 Subject: New Science Discovery: Perl Detractors Remain Idiots After A Decade References: <0078bbfb-5dfc-48fc-af1a-69de3cf15c3e@b1g2000yqb.googlegroups.com> <4f5deed8$6$fuzhry+tra$mr2ice@news.patriot.net> Message-ID: Shmuel (Seymour J.) Metz writes: > In , on 03/12/2012 > at 11:27 AM, Albert van der Horst said: > >>You're confused. > > No, s/h/it is just an acephalic troll with delusions of adequacy. Another way to put it is to say that Xah is a legend in his own mind. From albert at spenarnc.xs4all.nl Mon Mar 12 15:00:30 2012 From: albert at spenarnc.xs4all.nl (Albert van der Horst) Date: 12 Mar 2012 19:00:30 GMT Subject: New Science Discovery: Perl Idiots Remain Idiots After A Decade!New Science Discovery: Perl Idiots Remain Idiots After A Decade! References: <0078bbfb-5dfc-48fc-af1a-69de3cf15c3e@b1g2000yqb.googlegroups.com> <4f5df4b3$0$1375$4fafbaef@reader1.news.tin.it> Message-ID: In article <4f5df4b3$0$1375$4fafbaef at reader1.news.tin.it>, Kiuhnm wrote: >On 3/12/2012 12:27, Albert van der Horst wrote: >> Interestingly in mathematics associative means that it doesn't matter >> whether you use (a.b).c or a.(b.c). >> Using xxx-associativity to indicate that it *does* matter is >> a bit perverse, but the Perl people are not to blame if they use >> a term in their usual sense. > >You may see it this way: >Def1. An operator +:SxS->S is left-associative iff > a+b+c = (a+b)+c for all a,b,c in S. >Def2. An operator +:SxS->S is right-associative iff > a+b+c = a+(b+c) for all a,b,c in S. >Def3. An operator +:SxS->S is associative iff it is both left and >right-associative. I know, but what the mathematicians do make so much more sense: (a+b)+c = a+(b+c) definition of associative. Henceforth we may leave out the brackets. Don't leave out the brackets if the operators if the operators is not associative. P.S. There is no need for the operators to be SxS->S. For example a b c may be m by n, n by l, l by k matrices respectively. > >Kiuhnm Groetjes Albert -- -- Albert van der Horst, UTRECHT,THE NETHERLANDS Economic growth -- being exponential -- ultimately falters. albert at spe&ar&c.xs4all.nl &=n http://home.hccnet.nl/a.w.m.van.der.horst From vs at it.uu.se Mon Mar 12 15:39:34 2012 From: vs at it.uu.se (Virgil Stokes) Date: Mon, 12 Mar 2012 20:39:34 +0100 Subject: Fast file data retrieval? Message-ID: <4F5E50F6.9070309@it.uu.se> I have a rather large ASCII file that is structured as follows header line 9 nonblank lines with alphanumeric data header line 9 nonblank lines with alphanumeric data ... ... ... header line 9 nonblank lines with alphanumeric data EOF where, a data set contains 10 lines (header + 9 nonblank) and there can be several thousand data sets in a single file. In addition,*each header has a* *unique ID code*. Is there a fast method for the retrieval of a data set from this large file given its ID code? -------------- next part -------------- An HTML attachment was scrubbed... URL: From spamtrap at library.lspace.org.invalid Mon Mar 12 16:20:22 2012 From: spamtrap at library.lspace.org.invalid (Shmuel Metz (Seymour J.)) Date: Mon, 12 Mar 2012 16:20:22 -0400 Subject: New Science Discovery: Perl Idiots Remain Idiots After A Decade!New Science Discovery: Perl Idiots Remain Idiots Af References: <0078bbfb-5dfc-48fc-af1a-69de3cf15c3e@b1g2000yqb.googlegroups.com> <4f5df4b3$0$1375$4fafbaef@reader1.news.tin.it> Message-ID: <4f5e5a86$10$fuzhry+tra$mr2ice@news.patriot.net> In , on 03/12/2012 at 07:00 PM, Albert van der Horst said: >I know, but what the mathematicians do make so much more sense: Not really; Mathematical notation is a matter of convention, and the conventions owe as much to History as they do to logical necessity. The conventions aren't even the same from author to author, e.g., whether "field" implies Abelian. -- Shmuel (Seymour J.) Metz, SysProg and JOAT Unsolicited bulk E-mail subject to legal action. I reserve the right to publicly post or ridicule any abusive E-mail. Reply to domain Patriot dot net user shmuel+news to contact me. Do not reply to spamtrap at library.lspace.org From kiuhnm03.4t.yahoo.it Mon Mar 12 16:27:25 2012 From: kiuhnm03.4t.yahoo.it (Kiuhnm) Date: Mon, 12 Mar 2012 21:27:25 +0100 Subject: New Science Discovery: Perl Idiots Remain Idiots After A Decade!New Science Discovery: Perl Idiots Remain Idiots After A Decade! In-Reply-To: References: <0078bbfb-5dfc-48fc-af1a-69de3cf15c3e@b1g2000yqb.googlegroups.com> <4f5df4b3$0$1375$4fafbaef@reader1.news.tin.it> Message-ID: <4f5e5c2f$0$1379$4fafbaef@reader2.news.tin.it> On 3/12/2012 20:00, Albert van der Horst wrote: > In article<4f5df4b3$0$1375$4fafbaef at reader1.news.tin.it>, > Kiuhnm wrote: >> On 3/12/2012 12:27, Albert van der Horst wrote: >>> Interestingly in mathematics associative means that it doesn't matter >>> whether you use (a.b).c or a.(b.c). >>> Using xxx-associativity to indicate that it *does* matter is >>> a bit perverse, but the Perl people are not to blame if they use >>> a term in their usual sense. >> >> You may see it this way: >> Def1. An operator +:SxS->S is left-associative iff >> a+b+c = (a+b)+c for all a,b,c in S. >> Def2. An operator +:SxS->S is right-associative iff >> a+b+c = a+(b+c) for all a,b,c in S. >> Def3. An operator +:SxS->S is associative iff it is both left and >> right-associative. > > I know, but what the mathematicians do make so much more sense: > (a+b)+c = a+(b+c) definition of associative. > Henceforth we may leave out the brackets. That's Def3. I don't see your point. > Don't leave out the brackets if the operators if the operators is > not associative. (1 - 1) - 1 != 1 - (1 - 1) and yet we can leave out the parentheses. > P.S. There is no need for the operators to be SxS->S. > For example a b c may be m by n, n by l, l by k matrices respectively. Ops, you're right. Kiuhnm From arnodel at gmail.com Mon Mar 12 16:31:26 2012 From: arnodel at gmail.com (Arnaud Delobelle) Date: Mon, 12 Mar 2012 20:31:26 +0000 Subject: Fast file data retrieval? In-Reply-To: <4F5E50F6.9070309@it.uu.se> References: <4F5E50F6.9070309@it.uu.se> Message-ID: On 12 March 2012 19:39, Virgil Stokes wrote: > I have a rather large ASCII file that is structured as follows > > header line > 9 nonblank lines with alphanumeric data > header line > 9 nonblank lines with alphanumeric data > ... > ... > ... > header line > 9 nonblank lines with alphanumeric data > EOF > > where, a data set contains 10 lines (header + 9 nonblank) and there can be > several thousand > data sets in a single file. In addition, each header has a unique ID code. > > Is there a fast method for the retrieval of a data set from this large file > given its ID code? It depends. I guess if it's a long running application, you could load up all the data into a dictionary at startup time (several thousand data sets doesn't sound like that much). Another option would be to put all this into a dbm database file (http://docs.python.org/library/dbm.html) - it would be very easy to do. Or you could have your own custom solution where you scan the file and build a dictionary mapping keys to file offsets, then when requesting a dataset you can seek directly to the correct position. -- Arnaud From python at mrabarnett.plus.com Mon Mar 12 16:31:35 2012 From: python at mrabarnett.plus.com (MRAB) Date: Mon, 12 Mar 2012 20:31:35 +0000 Subject: Fast file data retrieval? In-Reply-To: <4F5E50F6.9070309@it.uu.se> References: <4F5E50F6.9070309@it.uu.se> Message-ID: <4F5E5D27.4010403@mrabarnett.plus.com> On 12/03/2012 19:39, Virgil Stokes wrote: > I have a rather large ASCII file that is structured as follows > > header line > 9 nonblank lines with alphanumeric data > header line > 9 nonblank lines with alphanumeric data > ... > ... > ... > header line > 9 nonblank lines with alphanumeric data > EOF > > where, a data set contains 10 lines (header + 9 nonblank) and there can > be several thousand > data sets in a single file. In addition,*each header has a* *unique ID > code*. > > Is there a fast method for the retrieval of a data set from this large > file given its ID code? > Probably the best solution is to put it into a database. Have a look at the sqlite3 module. Alternatively, you could scan the file, recording the ID and the file offset in a dict so that, given an ID, you can seek directly to that file position. From drsalists at gmail.com Mon Mar 12 16:33:26 2012 From: drsalists at gmail.com (Dan Stromberg) Date: Mon, 12 Mar 2012 13:33:26 -0700 Subject: Fast file data retrieval? In-Reply-To: <4F5E50F6.9070309@it.uu.se> References: <4F5E50F6.9070309@it.uu.se> Message-ID: If the ID's are sorted, you could probably rig a binary search using seek. This'll be easier if the records have a constant length, but it's still possible for variable-length, just messier. Otherwise you could stash them all in a dictionary (in memory) or anydbm (on disk) to get indexed access. On Mon, Mar 12, 2012 at 12:39 PM, Virgil Stokes wrote: > I have a rather large ASCII file that is structured as follows > > header line > 9 nonblank lines with alphanumeric data > header line > 9 nonblank lines with alphanumeric data > ... > ... > ... > header line > 9 nonblank lines with alphanumeric data > EOF > > where, a data set contains 10 lines (header + 9 nonblank) and there can be > several thousand > data sets in a single file. In addition,* each header has a* *unique ID > code*. > > Is there a fast method for the retrieval of a data set from this large > file given its ID code? > > > -- > http://mail.python.org/mailman/listinfo/python-list > > -------------- next part -------------- An HTML attachment was scrubbed... URL: From alec.taylor6 at gmail.com Mon Mar 12 16:38:29 2012 From: alec.taylor6 at gmail.com (Alec Taylor) Date: Tue, 13 Mar 2012 07:38:29 +1100 Subject: PyCrypto builds neither with MSVC nor MinGW In-Reply-To: References: <35da69c3-edcc-4466-8a0d-70237c88af3b@qv4g2000pbc.googlegroups.com> Message-ID: On a brand new Windows install now, with a brand new VS8 installed with new YASM and MPIR in c:\usr\src\include and c:\usr\src\lib. But it still isn't working: C:\workingdir\pycrypto>python setup.py build_ext -Ic:\usr\src\include -Lc:\usr\src\lib install running build_ext warning: GMP or MPIR library not found; Not building Crypto.PublicKey._fastmath. building 'Crypto.Random.OSRNG.winrandom' extension Traceback (most recent call last): File "setup.py", line 452, in core.setup(**kw) File "C:\Python27\lib\distutils\core.py", line 152, in setup dist.run_commands() File "C:\Python27\lib\distutils\dist.py", line 953, in run_commands self.run_command(cmd) File "C:\Python27\lib\distutils\dist.py", line 972, in run_command cmd_obj.run() File "setup.py", line 249, in run build_ext.run(self) File "C:\Python27\lib\distutils\command\build_ext.py", line 339, in run self.build_extensions() File "setup.py", line 146, in build_extensions build_ext.build_extensions(self) File "C:\Python27\lib\distutils\command\build_ext.py", line 448, in build_extensions self.build_extension(ext) File "C:\Python27\lib\distutils\command\build_ext.py", line 498, in build_extension depends=ext.depends) File "C:\Python27\lib\distutils\msvc9compiler.py", line 473, in compile self.initialize() File "C:\Python27\lib\distutils\msvc9compiler.py", line 383, in initialize vc_env = query_vcvarsall(VERSION, plat_spec) File "C:\Python27\lib\distutils\msvc9compiler.py", line 299, in query_vcvarsall raise ValueError(str(list(result.keys()))) ValueError: [u'path'] On Wed, Feb 8, 2012 at 11:31 PM, Case Van Horsen wrote: > On Wed, Feb 8, 2012 at 4:24 AM, Alec Taylor wrote: >> Thanks, but to get it to work with pip, wouldn't I need to add it to >> PATH? - Or can I just add those library args to pip? > I don't think so. pyCrypto probably builds a single DLL so the MPIR library is > statically linked into that DLL. Only the innvocation of setup.py should need > to refer to the MPIR library locations. ?I don't use pip so I'm not sure how to > get pip to install the resulting DLL, etc. >> >> On Wed, Feb 8, 2012 at 9:48 PM, Case Van Horsen wrote: >>> On Tue, Feb 7, 2012 at 9:37 PM, Alec Taylor wrote: >>>> Thanks all for your replies. >>>> >>>> I have now installed MSVC8 and YASM. >>> I assume you installed Visual Studio. I've omitted the commands to use >>> the SDK compiler below. >>>> >>>> I was able to successfully run configure.bat and make.bat (including >>>> make.bat check). >>>> >>>> However, I'm unsure what to do about install, since there is no >>>> install arg. Do I copy it across to my VC\bin folder, or does it need >>>> it's own place in PATH + system variables? >>> >>> The following is just a guess. >>> >>> I copy the files to a convenient location and then specify that >>> location to setup.py. Below is an excerpt from my build process. >>> >>> mkdir c:\src\lib >>> mkdir c:\src\include >>> xcopy /Y mpir.h c:\src\include\*.* >>> xcopy /Y win\mpir.lib c:\src\lib\*.* >>> >>> python setup.py build_ext -Ic:\src\include -Lc:\src\lib install >>> >>>> >>>> I am asking because I don't know where it is looking for the MPIR library. >>>> >>>> Thanks for all suggestions, >>>> >>>> Alec Taylor From ramit.prasad at jpmorgan.com Mon Mar 12 17:09:05 2012 From: ramit.prasad at jpmorgan.com (Prasad, Ramit) Date: Mon, 12 Mar 2012 21:09:05 +0000 Subject: Fast file data retrieval? In-Reply-To: <4F5E5D27.4010403@mrabarnett.plus.com> References: <4F5E50F6.9070309@it.uu.se> <4F5E5D27.4010403@mrabarnett.plus.com> Message-ID: <5B80DD153D7D744689F57F4FB69AF4741C2692@SCACMX008.exchad.jpmchase.net> > > header line > > 9 nonblank lines with alphanumeric data > > header line > > 9 nonblank lines with alphanumeric data > > ... > > ... > > ... > > header line > > 9 nonblank lines with alphanumeric data > > EOF > > > > where, a data set contains 10 lines (header + 9 nonblank) and there can > > be several thousand > > data sets in a single file. In addition,*each header has a* *unique ID > > code*. > Alternatively, you could scan the file, recording the ID and the file > offset in a dict so that, given an ID, you can seek directly to that > file position. If you can grep for the header lines you can retrieve the headers and the line number for seeking. grep is (probably) faster than python so I would have it be 2 steps. 1. grep > temp.txt 2. python; check if ID is in temp.txt and then processes Ramit Ramit Prasad | JPMorgan Chase Investment Bank | Currencies Technology 712 Main Street | Houston, TX 77002 work phone: 713 - 216 - 5423 -- This email is confidential and subject to important disclaimers and conditions including on offers for the purchase or sale of securities, accuracy and completeness of information, viruses, confidentiality, legal privilege, and legal entity disclaimers, available at http://www.jpmorgan.com/pages/disclosures/email. From alec.taylor6 at gmail.com Mon Mar 12 17:21:51 2012 From: alec.taylor6 at gmail.com (Alec Taylor) Date: Tue, 13 Mar 2012 08:21:51 +1100 Subject: PyCrypto builds neither with MSVC nor MinGW In-Reply-To: References: <35da69c3-edcc-4466-8a0d-70237c88af3b@qv4g2000pbc.googlegroups.com> Message-ID: FYI: When running "vcvarsall" manually, I get a variety of linker errors, even though I have the SDK and everything else installed: running build_ext building 'Crypto.Random.OSRNG.winrandom' extension C:\Program Files (x86)\Microsoft Visual Studio 9.0\VC\BIN\cl.exe /c /nologo /Ox /MD /W3 /GS- /DNDEBUG -Isrc/ -Isrc/inc-msvc/ -Ic:\usr\src\include -IC:\Python27\include -IC:\Python27\PC /Tcsrc/winrand.c /Fobuild\temp.win-amd64-2.7\Release\src/winrand.obj winrand.c C:\Program Files (x86)\Microsoft Visual Studio 9.0\VC\BIN\link.exe /DLL /nologo /INCREMENTAL:NO /LIBPATH:c:\usr\src\lib /LIBPATH:C:\Python27\libs /LIBPATH:C:\Python27\PCbuild\amd64 ws2_32.lib advapi32.lib /EXPORT:initwinrandom build\temp.win-amd64-2.7\Release\src/winrand.obj /OUT:build\lib.win-amd64-2.7\Crypto\Random\OSRNG\winrandom.pyd /IMPLIB:build\temp.win-amd64-2.7\Release\src\winrandom.lib /MANIFESTFILE:build\temp.win-amd64-2.7\Release\src\winrandom.pyd.manifest Creating library build\temp.win-amd64-2.7\Release\src\winrandom.lib and object build\temp.win-amd64-2.7\Release\src\winrandom.exp winrand.obj : error LNK2019: unresolved external symbol __imp__PyObject_Free referenced in function _WRdealloc winrand.obj : error LNK2019: unresolved external symbol __imp__PyExc_SystemError referenced in function _WRdealloc winrand.obj : error LNK2019: unresolved external symbol __imp__PyErr_Format referenced in function _WRdealloc winrand.obj : error LNK2019: unresolved external symbol __imp__PyExc_TypeError referenced in function _WRdealloc winrand.obj : error LNK2019: unresolved external symbol __imp___PyObject_New referenced in function _winrandom_new winrand.obj : error LNK2019: unresolved external symbol __imp__PyArg_ParseTupleAndKeywords referenced in function _winrandom_new winrand.obj : error LNK2019: unresolved external symbol __imp__PyString_FromStringAndSize referenced in function _WR_get_bytes winrand.obj : error LNK2019: unresolved external symbol __imp__PyMem_Free referenced in function _WR_get_bytes winrand.obj : error LNK2019: unresolved external symbol __imp__PyErr_NoMemory referenced in function _WR_get_bytes winrand.obj : error LNK2019: unresolved external symbol __imp__PyMem_Malloc referenced in function _WR_get_bytes winrand.obj : error LNK2019: unresolved external symbol __imp__PyErr_SetString referenced in function _WR_get_bytes winrand.obj : error LNK2019: unresolved external symbol __imp__PyExc_ValueError referenced in function _WR_get_bytes winrand.obj : error LNK2019: unresolved external symbol __imp__PyArg_ParseTuple referenced in function _WR_get_bytes winrand.obj : error LNK2019: unresolved external symbol __imp__Py_FindMethod referenced in function _WRgetattr winrand.obj : error LNK2019: unresolved external symbol __imp__PyInt_FromLong referenced in function _WRgetattr winrand.obj : error LNK2019: unresolved external symbol __imp__Py_FatalError referenced in function _initwinrandom winrand.obj : error LNK2019: unresolved external symbol __imp__PyErr_Occurred referenced in function _initwinrandom winrand.obj : error LNK2019: unresolved external symbol __imp__PyModule_AddStringConstant referenced in function _initwinrandom winrand.obj : error LNK2019: unresolved external symbol __imp__PyModule_AddIntConstant referenced in function _initwinrandom winrand.obj : error LNK2019: unresolved external symbol __imp__Py_InitModule4 referenced in function _initwinrandom winrand.obj : error LNK2019: unresolved external symbol __imp__PyType_Type referenced in function _initwinrandom build\lib.win-amd64-2.7\Crypto\Random\OSRNG\winrandom.pyd : fatal error LNK1120: 21 unresolved externals From rosuav at gmail.com Mon Mar 12 17:59:14 2012 From: rosuav at gmail.com (Chris Angelico) Date: Tue, 13 Mar 2012 08:59:14 +1100 Subject: How to break long method name into more than one line? In-Reply-To: References: <4f5d4390$0$29891$c3e8da3$5496439d@news.astraweb.com> Message-ID: On Tue, Mar 13, 2012 at 3:24 AM, Dennis Lee Bieber wrote: > On 12 Mar 2012 00:30:08 GMT, Steven D'Aprano > declaimed the following in > gmane.comp.python.general: >> I expect that naming rule was invented by either people who have heard of >> test driven development, but never actually done it, or by people so >> anally-retentive that if they make seven short car trips over an hour, >> they check the tyre pressure, oil and water seven times because "the >> manual says to check before *every* trip". >> > ? ? ? ?By which time they find they have to add air, oil, and water as: the > pressure gauge usage lets out some air each time; they've wiped a few > drops of oil onto a rag each time; and the radiator was still > hot&pressurized such that they got an "overfull" result. In defense of such rules: There's a period in every new programmer's life when it helps to learn a whole lot of principles; and if he's working on some collaborative project, rules are the easiest way to demand such behavior. Later on, you learn how and when it's safe to break the rules (and/or how to deal with rule conflicts), but the rules still have value. Just never treat them as laws of physics (in Soviet Physics, rules break you!). ChrisA From mmanns at gmx.net Mon Mar 12 19:22:56 2012 From: mmanns at gmx.net (Martin Manns) Date: Tue, 13 Mar 2012 00:22:56 +0100 Subject: [ANN] pyspread 0.2.1 Message-ID: ============== pyspread 0.2.1 ============== Pyspread 0.2.1 is released. The new version improves GPG integration. About pyspread ============== Pyspread is a non-traditional spreadsheet application that is based on and written in the programming language Python. The goal of pyspread is to be the most pythonic spreadsheet application. Pyspread is designed for Linux and other GTK platforms. Pyspread is free software. It is released under the GPL v3. Project website: http://manns.github.com/pyspread/ What is new in 0.2.1 ==================== * Format menu added * Printing bug (first line not printed) fixed * GPG key choice dialog added * Secret key generation dialog added * Password saving in .pyspreadrc is now optional * Preferences dialog entries are now validated * Toolbar positions are now saved on exit * Absolute addressing with mouse changed to + * Relative addressing with mouse changed to + Enjoy Martin From joncle at googlemail.com Mon Mar 12 23:38:25 2012 From: joncle at googlemail.com (Jon Clements) Date: Mon, 12 Mar 2012 20:38:25 -0700 (PDT) Subject: Fast file data retrieval? In-Reply-To: References: <4F5E50F6.9070309@it.uu.se> Message-ID: <8469277.2076.1331609905709.JavaMail.geo-discussion-forums@vbai14> On Monday, 12 March 2012 20:31:35 UTC, MRAB wrote: > On 12/03/2012 19:39, Virgil Stokes wrote: > > I have a rather large ASCII file that is structured as follows > > > > header line > > 9 nonblank lines with alphanumeric data > > header line > > 9 nonblank lines with alphanumeric data > > ... > > ... > > ... > > header line > > 9 nonblank lines with alphanumeric data > > EOF > > > > where, a data set contains 10 lines (header + 9 nonblank) and there can > > be several thousand > > data sets in a single file. In addition,*each header has a* *unique ID > > code*. > > > > Is there a fast method for the retrieval of a data set from this large > > file given its ID code? > > > Probably the best solution is to put it into a database. Have a look at > the sqlite3 module. > > Alternatively, you could scan the file, recording the ID and the file > offset in a dict so that, given an ID, you can seek directly to that > file position. I would have a look at either bsddb, Tokyo (or Kyoto) Cabinet or hamsterdb. If it's really going to get large and needs a full blown server, maybe MongoDB/redis/hadoop... From joncle at googlemail.com Mon Mar 12 23:38:25 2012 From: joncle at googlemail.com (Jon Clements) Date: Mon, 12 Mar 2012 20:38:25 -0700 (PDT) Subject: Fast file data retrieval? In-Reply-To: References: <4F5E50F6.9070309@it.uu.se> Message-ID: <8469277.2076.1331609905709.JavaMail.geo-discussion-forums@vbai14> On Monday, 12 March 2012 20:31:35 UTC, MRAB wrote: > On 12/03/2012 19:39, Virgil Stokes wrote: > > I have a rather large ASCII file that is structured as follows > > > > header line > > 9 nonblank lines with alphanumeric data > > header line > > 9 nonblank lines with alphanumeric data > > ... > > ... > > ... > > header line > > 9 nonblank lines with alphanumeric data > > EOF > > > > where, a data set contains 10 lines (header + 9 nonblank) and there can > > be several thousand > > data sets in a single file. In addition,*each header has a* *unique ID > > code*. > > > > Is there a fast method for the retrieval of a data set from this large > > file given its ID code? > > > Probably the best solution is to put it into a database. Have a look at > the sqlite3 module. > > Alternatively, you could scan the file, recording the ID and the file > offset in a dict so that, given an ID, you can seek directly to that > file position. I would have a look at either bsddb, Tokyo (or Kyoto) Cabinet or hamsterdb. If it's really going to get large and needs a full blown server, maybe MongoDB/redis/hadoop... From casevh at gmail.com Mon Mar 12 23:59:38 2012 From: casevh at gmail.com (casevh at gmail.com) Date: Mon, 12 Mar 2012 20:59:38 -0700 (PDT) Subject: PyCrypto builds neither with MSVC nor MinGW In-Reply-To: References: <35da69c3-edcc-4466-8a0d-70237c88af3b@qv4g2000pbc.googlegroups.com> Message-ID: <13993807.3661.1331611178050.JavaMail.geo-discussion-forums@pbcgf10> On Monday, March 12, 2012 1:38:29 PM UTC-7, Alec Taylor wrote: > On a brand new Windows install now, with a brand new VS8 installed > with new YASM and MPIR in c:\usr\src\include and c:\usr\src\lib. > > But it still isn't working: > This was a little challenging. I looked through the setup.py to figure out what assumptions their build process made. First, the file pycrypto-2.5\src\inc-msvc\config.h must be modified. Below is the file I used: config.h =================================================================== /* Define to 1 if you have the declaration of `mpz_powm', and to 0 if you don't. */ #define HAVE_DECL_MPZ_POWM 1 /* Define to 1 if you have the declaration of `mpz_powm_sec', and to 0 if you don't. */ #define HAVE_DECL_MPZ_POWM_SEC 0 /* Define to 1 if you have the `gmp' library (-lgmp). */ #undef HAVE_LIBGMP /* Define to 1 if you have the `mpir' library (-lmpir). */ #define HAVE_LIBMPIR 1 /* Define to 1 if you have the header file. */ #define HAVE_STDINT_H 1 =================================================================== Although I was able to specify an include directory for mpir.h with -Ic:\usr\include, I was not able specify a lib directory with -Lc:\usr\lib. It looks like setup.py does not honor the -L option. So I finally gave up and just copied the mpir.h file into my Python27\include directory and the mpir.lib file into my Python27\libs directory. After copying the files "python setup.py install" was successful. I created a binary installer with "python setup.py bdist-wininst". There may be a cleaner way to build PyCrypto, but these steps worked for me. casevh From casevh at gmail.com Mon Mar 12 23:59:38 2012 From: casevh at gmail.com (casevh at gmail.com) Date: Mon, 12 Mar 2012 20:59:38 -0700 (PDT) Subject: PyCrypto builds neither with MSVC nor MinGW In-Reply-To: References: <35da69c3-edcc-4466-8a0d-70237c88af3b@qv4g2000pbc.googlegroups.com> Message-ID: <13993807.3661.1331611178050.JavaMail.geo-discussion-forums@pbcgf10> On Monday, March 12, 2012 1:38:29 PM UTC-7, Alec Taylor wrote: > On a brand new Windows install now, with a brand new VS8 installed > with new YASM and MPIR in c:\usr\src\include and c:\usr\src\lib. > > But it still isn't working: > This was a little challenging. I looked through the setup.py to figure out what assumptions their build process made. First, the file pycrypto-2.5\src\inc-msvc\config.h must be modified. Below is the file I used: config.h =================================================================== /* Define to 1 if you have the declaration of `mpz_powm', and to 0 if you don't. */ #define HAVE_DECL_MPZ_POWM 1 /* Define to 1 if you have the declaration of `mpz_powm_sec', and to 0 if you don't. */ #define HAVE_DECL_MPZ_POWM_SEC 0 /* Define to 1 if you have the `gmp' library (-lgmp). */ #undef HAVE_LIBGMP /* Define to 1 if you have the `mpir' library (-lmpir). */ #define HAVE_LIBMPIR 1 /* Define to 1 if you have the header file. */ #define HAVE_STDINT_H 1 =================================================================== Although I was able to specify an include directory for mpir.h with -Ic:\usr\include, I was not able specify a lib directory with -Lc:\usr\lib. It looks like setup.py does not honor the -L option. So I finally gave up and just copied the mpir.h file into my Python27\include directory and the mpir.lib file into my Python27\libs directory. After copying the files "python setup.py install" was successful. I created a binary installer with "python setup.py bdist-wininst". There may be a cleaner way to build PyCrypto, but these steps worked for me. casevh From jg07024 at gmail.com Tue Mar 13 00:06:39 2012 From: jg07024 at gmail.com (John Graves) Date: Tue, 13 Mar 2012 17:06:39 +1300 Subject: A Plausible Promise of Abundant Educational Resources In-Reply-To: References: Message-ID: The warning from Google should be fixed by now. A server outside my control had been infected with malware, so I shifted servers, but the warning message remained attached to the domain name. The address http://slidespeech.org leads to http://code.google.com/p/slidespeech/ the source code repository. On Sat, Mar 10, 2012 at 3:11 AM, John Graves wrote: > Dear Python-List: > > If you find Wikipedia useful and can see the value of collaborating on a > project which could make learning material as freely and spectacularly > available as Wikipedia does reference material[1], please read on. > > Background: > > In November 2009, I began learning Python with the objective of trying to > understand the following research question in my PhD research study of open > source software development: "We have built Wikipedia and other big, > successful open source projects. How can we do it again (and again)?" The > critical issue for me was how to start a project which would grow to > self-sustainability. So for over two years now, my research method has been > to try to actually start such a project. I failed. Over and over. The data > collection period for my study ended. > > Before I could start writing up my PhD, however, I saw an answer provided > in February 2012 by the founder of Craigslist, on Quora. When asked, "How > did Craigslist gain its initial traction?"[2], Craig Newmark, Customer > Service Rep & Founder wrote: > > - from beginning, did something simple and useful > - from beginning, began cycle: > -- asked for community feedback > -- did something about it > -- repeat, forever > -- got lucky with simple site design > > So I have now tried to take what started as a horribly over ambitious > desktop application[3], combined with an equally inept Android mobile > application (done in Java)[4] and boiled down the core text-to-speech > functionality into something "simple and useful" which runs on the web. The > project is now called SlideSpeech[5] and it does a couple of pretty > interesting things. Interesting enough to attract venture capital. > > The Future: > > As of 23 February 2012, SlideSpeech Limited is a company. But it is still > an open source software development research project with a Pythonic heart. > I can now pay for development of some professional quality software by > people who know much more Java and Python than I do. Perhaps this will help > the project reach self-sustainability, although, as Derek Sivers points out > in a memorable TED talk[6], just initiating or leading a project like this > is not what makes it a success: there must be joiners and followers for a > project with a plausible promise to grow to realise its potential. The > followers are the real heroes. > > Now Peter Diamandis just gave a TED talk entitled, "Abundance is our > future"[7] which everyone should watch. He talks of 3 billion people coming > on-line this decade. I want SlideSpeech to be useful and helpful to those > people. Not to make money from them but to help foster a global > conversation and global distribution of knowledge. We should all share in > Educational Abundance. Diamandis says, "we're going to hit 70 percent > penetration of cellphones in the developing world by the end of 2013." > SlideSpeech can plausibly promise to deliver free, interactive learning > material to smart phones anywhere on the planet this year. The current > working prototype does this today. > > In its simplest form, the system works like this: > 1) you start in your presentation software, adding a voice over script in > the speaker notes of each slide > 2) you upload your presentation to SlideSpeech > 3) on the SlideSpeech server (which can be your own PC, running Python, > made viewable to the world using PageKite[8]), the presentation is > "decomposed" into slide images and text scripts. The scripts are fed into a > text-to-speech engine. The resulting audio files are wrapped in HTML with > their corresponding slide image files. Finally, a link to access the HTML > is e-mailed back to you > 4) you open the link on your mobile phone's web browser and the > presentation you were writing just moments before "delivers itself" on your > phone ... or on any smart phone, tablet or web browser, anywhere. No need > to organise a venue, send invitations or get people to actually physically > show up to see and hear your talk. You can just forward the e-mail. > > Cooler still, > 5) if you have a native application play the script using the phone's > text-to-speech engine, you don't have to download audio (or video), so you > save 75% of the bandwidth. Multiplied by billions of people, multiplied by > the number of downloads[9], that is a huge savings. > > The compression of content into the simple combination of images and > text-to-speech scripts allows SlideSpeech to realise part of the One Laptop > Per Child vision using "talking" smart phones and tablets. Students can > learn on their own. Current prices on the cheapest Android 2.2 gear which > can deliver SlideSpeech content here in Auckland, New Zealand are under > NZ$150. > > A Revolution in Learning: > > Think of SlideSpeech as a platform like Khan Academy[10] with the > exercises integrated into the presentation. The scripts can be created and > improved collaboratively, like Wikipedia articles, or cloned and customised > for particular audiences. Unlike Khan Academy videos, the text of > SlideSpeech presentations is search-able and machine-translatable. > > With presentation feedback built into the system[11], a newly created > presentation can be distributed and then dynamically critiqued and revised, > so later viewers see the corrected and improved version. It is remarkable > how quickly changes can be made, especially in contrast to the feedback > cycle a typical instructor goes through to improve their teaching. > > These ideas and technologies are not new. Text-to-speech, in particular, > has been around for a long time. Lately, however, the voices have become > "Avatar-quality"[12]. > > These ideas are disruptive. The current working prototypes of SlideSpeech > may appear to work poorly, underperforming relative to established > products, but as Clayton Christensen explains[13], having the ability to > meet an underlying need in a radically different way transforms industries. > I like to make an analogy with trains and cars. Current educational systems > are like trains: everyone has to go between the same fixed destinations at > the same fixed times, like it or not. SlideSpeech-based learning is like > having a car: you get to go learn whatever you want, whenever you want, > wherever you are, at your own pace (which is sometimes very, very fast!). > > Content is King: > > Having lots of content available will accelerate the adoption of > SlideSpeech above all else. Over the coming weeks, as the system matures, > you can start preparing by authoring presentations with speaker notes. Once > the system is fully available on-line, or downloadable to your PC, you can > drop your presentations in and get out "self-delivering" talks in HTML or > even video format, voiced by a wide selection of computer voices in English > and in many other languages. > > Please feel free to jump in with suggestions, contributions or forks of > the code repositories listed below. > > Let's make Educational Abundance happen with Python this year. > > Exponentially yours, > > John Graves > PhD Student > AUT University > Auckland, New Zealand > > Founder and CEO > SlideSpeech > > [1] The English language version of Wikipedia has 50 times as many words > as *Encyclop?dia Britannica > * http://en.wikipedia.org/wiki/Wikipedia:Size_comparisons > > [2] http://www.quora.com/How-did-Craigslist-gain-its-initial-traction > > [3] http://code.google.com/p/open-allure-ds/ > > [4] http://code.google.com/p/wiki-to-speech/ > > [5] http://code.google.com/p/slidespeech/ > > [6] http://www.ted.com/talks/derek_sivers_how_to_start_a_movement.html > > [7] http://www.ted.com/talks/peter_diamandis_abundance_is_our_future.html > > [8] http://pagekite.net > > [9] average for Wikipedia is about one article per person per day (18.1 > billion pages / 482 million unique visitors in January 2012) > http://stats.wikimedia.org/reportcard/ > > [10] http://khanacademy.org > > [11] http://code.google.com/p/slidespeech/wiki/WorkflowDiagrams > > [12] I particularly like Loquendo's Veena, Indian English voice > http://www.loquendo.com/en/demo-center/tts-demo/english/ > > [13] http://en.wikipedia.org/wiki/Disruptive_technology > -------------- next part -------------- An HTML attachment was scrubbed... URL: From jg07024 at gmail.com Tue Mar 13 00:08:50 2012 From: jg07024 at gmail.com (John Graves) Date: Tue, 13 Mar 2012 17:08:50 +1300 Subject: A Plausible Promise of Abundant Educational Resources In-Reply-To: References: Message-ID: OK. Do you have an presentation prepared? I've put the one with the photographsonto Dropbox. On Tue, Mar 13, 2012 at 5:06 PM, John Graves wrote: > The warning from Google should be fixed by now. A server outside my > control had been infected with malware, so I shifted servers, but the > warning message remained attached to the domain name. The address > http://slidespeech.org leads to http://code.google.com/p/slidespeech/ the > source code repository. > > > On Sat, Mar 10, 2012 at 3:11 AM, John Graves wrote: > >> Dear Python-List: >> >> If you find Wikipedia useful and can see the value of collaborating on a >> project which could make learning material as freely and spectacularly >> available as Wikipedia does reference material[1], please read on. >> >> Background: >> >> In November 2009, I began learning Python with the objective of trying to >> understand the following research question in my PhD research study of open >> source software development: "We have built Wikipedia and other big, >> successful open source projects. How can we do it again (and again)?" The >> critical issue for me was how to start a project which would grow to >> self-sustainability. So for over two years now, my research method has been >> to try to actually start such a project. I failed. Over and over. The data >> collection period for my study ended. >> >> Before I could start writing up my PhD, however, I saw an answer provided >> in February 2012 by the founder of Craigslist, on Quora. When asked, "How >> did Craigslist gain its initial traction?"[2], Craig Newmark, Customer >> Service Rep & Founder wrote: >> >> - from beginning, did something simple and useful >> - from beginning, began cycle: >> -- asked for community feedback >> -- did something about it >> -- repeat, forever >> -- got lucky with simple site design >> >> So I have now tried to take what started as a horribly over ambitious >> desktop application[3], combined with an equally inept Android mobile >> application (done in Java)[4] and boiled down the core text-to-speech >> functionality into something "simple and useful" which runs on the web. The >> project is now called SlideSpeech[5] and it does a couple of pretty >> interesting things. Interesting enough to attract venture capital. >> >> The Future: >> >> As of 23 February 2012, SlideSpeech Limited is a company. But it is still >> an open source software development research project with a Pythonic heart. >> I can now pay for development of some professional quality software by >> people who know much more Java and Python than I do. Perhaps this will help >> the project reach self-sustainability, although, as Derek Sivers points out >> in a memorable TED talk[6], just initiating or leading a project like this >> is not what makes it a success: there must be joiners and followers for a >> project with a plausible promise to grow to realise its potential. The >> followers are the real heroes. >> >> Now Peter Diamandis just gave a TED talk entitled, "Abundance is our >> future"[7] which everyone should watch. He talks of 3 billion people coming >> on-line this decade. I want SlideSpeech to be useful and helpful to those >> people. Not to make money from them but to help foster a global >> conversation and global distribution of knowledge. We should all share in >> Educational Abundance. Diamandis says, "we're going to hit 70 percent >> penetration of cellphones in the developing world by the end of 2013." >> SlideSpeech can plausibly promise to deliver free, interactive learning >> material to smart phones anywhere on the planet this year. The current >> working prototype does this today. >> >> In its simplest form, the system works like this: >> 1) you start in your presentation software, adding a voice over script in >> the speaker notes of each slide >> 2) you upload your presentation to SlideSpeech >> 3) on the SlideSpeech server (which can be your own PC, running Python, >> made viewable to the world using PageKite[8]), the presentation is >> "decomposed" into slide images and text scripts. The scripts are fed into a >> text-to-speech engine. The resulting audio files are wrapped in HTML with >> their corresponding slide image files. Finally, a link to access the HTML >> is e-mailed back to you >> 4) you open the link on your mobile phone's web browser and the >> presentation you were writing just moments before "delivers itself" on your >> phone ... or on any smart phone, tablet or web browser, anywhere. No need >> to organise a venue, send invitations or get people to actually physically >> show up to see and hear your talk. You can just forward the e-mail. >> >> Cooler still, >> 5) if you have a native application play the script using the phone's >> text-to-speech engine, you don't have to download audio (or video), so you >> save 75% of the bandwidth. Multiplied by billions of people, multiplied by >> the number of downloads[9], that is a huge savings. >> >> The compression of content into the simple combination of images and >> text-to-speech scripts allows SlideSpeech to realise part of the One Laptop >> Per Child vision using "talking" smart phones and tablets. Students can >> learn on their own. Current prices on the cheapest Android 2.2 gear which >> can deliver SlideSpeech content here in Auckland, New Zealand are under >> NZ$150. >> >> A Revolution in Learning: >> >> Think of SlideSpeech as a platform like Khan Academy[10] with the >> exercises integrated into the presentation. The scripts can be created and >> improved collaboratively, like Wikipedia articles, or cloned and customised >> for particular audiences. Unlike Khan Academy videos, the text of >> SlideSpeech presentations is search-able and machine-translatable. >> >> With presentation feedback built into the system[11], a newly created >> presentation can be distributed and then dynamically critiqued and revised, >> so later viewers see the corrected and improved version. It is remarkable >> how quickly changes can be made, especially in contrast to the feedback >> cycle a typical instructor goes through to improve their teaching. >> >> These ideas and technologies are not new. Text-to-speech, in particular, >> has been around for a long time. Lately, however, the voices have become >> "Avatar-quality"[12]. >> >> These ideas are disruptive. The current working prototypes of SlideSpeech >> may appear to work poorly, underperforming relative to established >> products, but as Clayton Christensen explains[13], having the ability to >> meet an underlying need in a radically different way transforms industries. >> I like to make an analogy with trains and cars. Current educational systems >> are like trains: everyone has to go between the same fixed destinations at >> the same fixed times, like it or not. SlideSpeech-based learning is like >> having a car: you get to go learn whatever you want, whenever you want, >> wherever you are, at your own pace (which is sometimes very, very fast!). >> >> Content is King: >> >> Having lots of content available will accelerate the adoption of >> SlideSpeech above all else. Over the coming weeks, as the system matures, >> you can start preparing by authoring presentations with speaker notes. Once >> the system is fully available on-line, or downloadable to your PC, you can >> drop your presentations in and get out "self-delivering" talks in HTML or >> even video format, voiced by a wide selection of computer voices in English >> and in many other languages. >> >> Please feel free to jump in with suggestions, contributions or forks of >> the code repositories listed below. >> >> Let's make Educational Abundance happen with Python this year. >> >> Exponentially yours, >> >> John Graves >> PhD Student >> AUT University >> Auckland, New Zealand >> >> Founder and CEO >> SlideSpeech >> >> [1] The English language version of Wikipedia has 50 times as many words >> as *Encyclop?dia Britannica >> * http://en.wikipedia.org/wiki/Wikipedia:Size_comparisons >> >> [2] http://www.quora.com/How-did-Craigslist-gain-its-initial-traction >> >> [3] http://code.google.com/p/open-allure-ds/ >> >> [4] http://code.google.com/p/wiki-to-speech/ >> >> [5] http://code.google.com/p/slidespeech/ >> >> [6] http://www.ted.com/talks/derek_sivers_how_to_start_a_movement.html >> >> [7] http://www.ted.com/talks/peter_diamandis_abundance_is_our_future.html >> >> [8] http://pagekite.net >> >> [9] average for Wikipedia is about one article per person per day (18.1 >> billion pages / 482 million unique visitors in January 2012) >> http://stats.wikimedia.org/reportcard/ >> >> [10] http://khanacademy.org >> >> [11] http://code.google.com/p/slidespeech/wiki/WorkflowDiagrams >> >> [12] I particularly like Loquendo's Veena, Indian English voice >> http://www.loquendo.com/en/demo-center/tts-demo/english/ >> >> [13] http://en.wikipedia.org/wiki/Disruptive_technology >> > > -------------- next part -------------- An HTML attachment was scrubbed... URL: From alec.taylor6 at gmail.com Tue Mar 13 00:57:51 2012 From: alec.taylor6 at gmail.com (Alec Taylor) Date: Tue, 13 Mar 2012 15:57:51 +1100 Subject: PyCrypto builds neither with MSVC nor MinGW In-Reply-To: <13993807.3661.1331611178050.JavaMail.geo-discussion-forums@pbcgf10> References: <35da69c3-edcc-4466-8a0d-70237c88af3b@qv4g2000pbc.googlegroups.com> <13993807.3661.1331611178050.JavaMail.geo-discussion-forums@pbcgf10> Message-ID: Hmm, I just tried that method, but the output I got was still: C:\workingdir\pycrypto>python setup.py install running install running build running build_py running build_ext building 'Crypto.Random.OSRNG.winrandom' extension Traceback (most recent call last): File "setup.py", line 452, in core.setup(**kw) File "C:\Python27\lib\distutils\core.py", line 152, in setup dist.run_commands() File "C:\Python27\lib\distutils\dist.py", line 953, in run_commands self.run_command(cmd) File "C:\Python27\lib\distutils\dist.py", line 972, in run_command cmd_obj.run() File "C:\Python27\lib\distutils\command\install.py", line 563, in run self.run_command('build') File "C:\Python27\lib\distutils\cmd.py", line 326, in run_command self.distribution.run_command(command) File "C:\Python27\lib\distutils\dist.py", line 972, in run_command cmd_obj.run() File "C:\Python27\lib\distutils\command\build.py", line 127, in run self.run_command(cmd_name) File "C:\Python27\lib\distutils\cmd.py", line 326, in run_command self.distribution.run_command(command) File "C:\Python27\lib\distutils\dist.py", line 972, in run_command cmd_obj.run() File "setup.py", line 249, in run build_ext.run(self) File "C:\Python27\lib\distutils\command\build_ext.py", line 339, in run self.build_extensions() File "setup.py", line 146, in build_extensions build_ext.build_extensions(self) File "C:\Python27\lib\distutils\command\build_ext.py", line 448, in build_extensions self.build_extension(ext) File "C:\Python27\lib\distutils\command\build_ext.py", line 498, in build_extension depends=ext.depends) File "C:\Python27\lib\distutils\msvc9compiler.py", line 473, in compile self.initialize() File "C:\Python27\lib\distutils\msvc9compiler.py", line 383, in initialize vc_env = query_vcvarsall(VERSION, plat_spec) File "C:\Python27\lib\distutils\msvc9compiler.py", line 299, in query_vcvarsall raise ValueError(str(list(result.keys()))) ValueError: [u'path'] -------------- and when I manually run vcvarsall (which is in PATH), I get the aforementioned linker errors: -------------- C:\workingdir\pycrypto>python setup.py install running install running build running build_py running build_ext building 'Crypto.Random.OSRNG.winrandom' extension C:\Program Files (x86)\Microsoft Visual Studio 9.0\VC\BIN\cl.exe /c /nologo /Ox /MD /W3 /GS- /DNDEBUG -Isrc/ -Isrc/inc-msvc/ -IC:\Python27\include -IC:\Python27 \PC /Tcsrc/winrand.c /Fobuild\temp.win-amd64-2.7\Release\src/winrand.obj winrand.c C:\Program Files (x86)\Microsoft Visual Studio 9.0\VC\BIN\link.exe /DLL /nologo /INCREMENTAL:NO /LIBPATH:C:\Python27\libs /LIBPATH:C:\Python27\PCbuild\amd64 ws2 _32.lib advapi32.lib /EXPORT:initwinrandom build\temp.win-amd64-2.7\Release\src/ winrand.obj /OUT:build\lib.win-amd64-2.7\Crypto\Random\OSRNG\winrandom.pyd /IMPL IB:build\temp.win-amd64-2.7\Release\src\winrandom.lib /MANIFESTFILE:build\temp.win-amd64-2.7\Release\src\winrandom.pyd.manifest Creating library build\temp.win-amd64-2.7\Release\src\winrandom.lib and object build\temp.win-amd64-2.7\Release\src\winrandom.exp winrand.obj : error LNK2019: unresolved external symbol __imp__PyObject_Free referenced in function _WRdealloc winrand.obj : error LNK2019: unresolved external symbol __imp__PyExc_SystemError referenced in function _WRdealloc winrand.obj : error LNK2019: unresolved external symbol __imp__PyErr_Format referenced in function _WRdealloc winrand.obj : error LNK2019: unresolved external symbol __imp__PyExc_TypeError referenced in function _WRdealloc winrand.obj : error LNK2019: unresolved external symbol __imp___PyObject_New referenced in function _winrandom_new winrand.obj : error LNK2019: unresolved external symbol __imp__PyArg_ParseTupleAndKeywords referenced in function _winrandom_new winrand.obj : error LNK2019: unresolved external symbol __imp__PyString_FromStringAndSize referenced in function _WR_get_bytes winrand.obj : error LNK2019: unresolved external symbol __imp__PyMem_Free referenced in function _WR_get_bytes winrand.obj : error LNK2019: unresolved external symbol __imp__PyErr_NoMemory referenced in function _WR_get_bytes winrand.obj : error LNK2019: unresolved external symbol __imp__PyMem_Malloc referenced in function _WR_get_bytes winrand.obj : error LNK2019: unresolved external symbol __imp__PyErr_SetString referenced in function _WR_get_bytes winrand.obj : error LNK2019: unresolved external symbol __imp__PyExc_ValueError referenced in function _WR_get_bytes winrand.obj : error LNK2019: unresolved external symbol __imp__PyArg_ParseTuple referenced in function _WR_get_bytes winrand.obj : error LNK2019: unresolved external symbol __imp__Py_FindMethod referenced in function _WRgetattr winrand.obj : error LNK2019: unresolved external symbol __imp__PyInt_FromLong referenced in function _WRgetattr winrand.obj : error LNK2019: unresolved external symbol __imp__Py_FatalError referenced in function _initwinrandom winrand.obj : error LNK2019: unresolved external symbol __imp__PyErr_Occurred referenced in function _initwinrandom winrand.obj : error LNK2019: unresolved external symbol __imp__PyModule_AddStringConstant referenced in function _initwinrandom winrand.obj : error LNK2019: unresolved external symbol __imp__PyModule_AddIntConstant referenced in function _initwinrandom winrand.obj : error LNK2019: unresolved external symbol __imp__Py_InitModule4 referenced in function _initwinrandom winrand.obj : error LNK2019: unresolved external symbol __imp__PyType_Type referenced in function _initwinrandom build\lib.win-amd64-2.7\Crypto\Random\OSRNG\winrandom.pyd : fatal error LNK1120: 21 unresolved externals error: command '"C:\Program Files (x86)\Microsoft Visual Studio 9.0\VC\BIN\link.exe"' failed with exit status 1120 On Tue, Mar 13, 2012 at 2:59 PM, wrote: > On Monday, March 12, 2012 1:38:29 PM UTC-7, Alec Taylor wrote: >> On a brand new Windows install now, with a brand new VS8 installed >> with new YASM and MPIR in c:\usr\src\include and c:\usr\src\lib. >> >> But it still isn't working: >> > This was a little challenging. I looked through the setup.py to figure out what assumptions their build process made. First, the file pycrypto-2.5\src\inc-msvc\config.h must be modified. Below is the file I used: > > config.h > =================================================================== > /* Define to 1 if you have the declaration of `mpz_powm', and to 0 if you > ? don't. */ > #define HAVE_DECL_MPZ_POWM 1 > > /* Define to 1 if you have the declaration of `mpz_powm_sec', and to 0 if you > ? don't. */ > #define HAVE_DECL_MPZ_POWM_SEC 0 > > /* Define to 1 if you have the `gmp' library (-lgmp). */ > #undef HAVE_LIBGMP > > /* Define to 1 if you have the `mpir' library (-lmpir). */ > #define HAVE_LIBMPIR 1 > > /* Define to 1 if you have the header file. */ > #define HAVE_STDINT_H 1 > =================================================================== > > Although I was able to specify an include directory for mpir.h with -Ic:\usr\include, I was not able specify a lib directory with -Lc:\usr\lib. It looks like setup.py does not honor the -L option. So I finally gave up and just copied the mpir.h file into my Python27\include directory and the mpir.lib file into my Python27\libs directory. > > After copying the files "python setup.py install" was successful. I created a binary installer with "python setup.py bdist-wininst". > > There may be a cleaner way to build PyCrypto, but these steps worked for me. > > casevh > -- > http://mail.python.org/mailman/listinfo/python-list From alec.taylor6 at gmail.com Tue Mar 13 02:09:38 2012 From: alec.taylor6 at gmail.com (Alec Taylor) Date: Tue, 13 Mar 2012 17:09:38 +1100 Subject: PyCrypto builds neither with MSVC nor MinGW In-Reply-To: References: <35da69c3-edcc-4466-8a0d-70237c88af3b@qv4g2000pbc.googlegroups.com> <13993807.3661.1331611178050.JavaMail.geo-discussion-forums@pbcgf10> Message-ID: Nope, I have C:\Python27 (and C:\Python27\Scripts) in my PATH. C:\workingdir\pycrypto>where python C:\Python27\python.exe On Tue, Mar 13, 2012 at 4:44 PM, Case Van Horsen wrote: > On Mon, Mar 12, 2012 at 9:57 PM, Alec Taylor wrote: >> Hmm, I just tried that method, but the output I got was still: >> >> C:\workingdir\pycrypto>python setup.py install >> running install >> running build >> running build_py >> running build_ext >> building 'Crypto.Random.OSRNG.winrandom' extension >> Traceback (most recent call last): >> ?File "setup.py", line 452, in >> ? ?core.setup(**kw) >> ?File "C:\Python27\lib\distutils\core.py", line 152, in setup >> ? ?dist.run_commands() >> ?File "C:\Python27\lib\distutils\dist.py", line 953, in run_commands >> ? ?self.run_command(cmd) >> ?File "C:\Python27\lib\distutils\dist.py", line 972, in run_command >> ? ?cmd_obj.run() >> ?File "C:\Python27\lib\distutils\command\install.py", line 563, in run >> ? ?self.run_command('build') >> ?File "C:\Python27\lib\distutils\cmd.py", line 326, in run_command >> ? ?self.distribution.run_command(command) >> ?File "C:\Python27\lib\distutils\dist.py", line 972, in run_command >> ? ?cmd_obj.run() >> ?File "C:\Python27\lib\distutils\command\build.py", line 127, in run >> ? ?self.run_command(cmd_name) >> ?File "C:\Python27\lib\distutils\cmd.py", line 326, in run_command >> ? ?self.distribution.run_command(command) >> ?File "C:\Python27\lib\distutils\dist.py", line 972, in run_command >> ? ?cmd_obj.run() >> ?File "setup.py", line 249, in run >> ? ?build_ext.run(self) >> ?File "C:\Python27\lib\distutils\command\build_ext.py", line 339, in run >> ? ?self.build_extensions() >> ?File "setup.py", line 146, in build_extensions >> ? ?build_ext.build_extensions(self) >> ?File "C:\Python27\lib\distutils\command\build_ext.py", line 448, in >> build_extensions >> ? ?self.build_extension(ext) >> ?File "C:\Python27\lib\distutils\command\build_ext.py", line 498, in >> build_extension >> ? ?depends=ext.depends) >> ?File "C:\Python27\lib\distutils\msvc9compiler.py", line 473, in compile >> ? ?self.initialize() >> ?File "C:\Python27\lib\distutils\msvc9compiler.py", line 383, in initialize >> ? ?vc_env = query_vcvarsall(VERSION, plat_spec) >> ?File "C:\Python27\lib\distutils\msvc9compiler.py", line 299, in >> query_vcvarsall >> ? ?raise ValueError(str(list(result.keys()))) >> ValueError: [u'path'] >> >> -------------- >> and when I manually run vcvarsall (which is in PATH), I get the >> aforementioned linker errors: >> -------------- >> >> C:\workingdir\pycrypto>python setup.py install >> running install >> running build >> running build_py >> running build_ext >> building 'Crypto.Random.OSRNG.winrandom' extension >> C:\Program Files (x86)\Microsoft Visual Studio 9.0\VC\BIN\cl.exe /c >> /nologo /Ox /MD /W3 /GS- /DNDEBUG -Isrc/ -Isrc/inc-msvc/ >> -IC:\Python27\include -IC:\Python27 \PC /Tcsrc/winrand.c >> /Fobuild\temp.win-amd64-2.7\Release\src/winrand.obj winrand.c >> C:\Program Files (x86)\Microsoft Visual Studio 9.0\VC\BIN\link.exe >> /DLL /nologo /INCREMENTAL:NO /LIBPATH:C:\Python27\libs >> /LIBPATH:C:\Python27\PCbuild\amd64 ws2 _32.lib advapi32.lib >> /EXPORT:initwinrandom build\temp.win-amd64-2.7\Release\src/ >> winrand.obj /OUT:build\lib.win-amd64-2.7\Crypto\Random\OSRNG\winrandom.pyd /IMPL >> IB:build\temp.win-amd64-2.7\Release\src\winrandom.lib >> /MANIFESTFILE:build\temp.win-amd64-2.7\Release\src\winrandom.pyd.manifest >> ? Creating library build\temp.win-amd64-2.7\Release\src\winrandom.lib >> and object build\temp.win-amd64-2.7\Release\src\winrandom.exp >> winrand.obj : error LNK2019: unresolved external symbol >> __imp__PyObject_Free referenced in function _WRdealloc >> winrand.obj : error LNK2019: unresolved external symbol >> __imp__PyExc_SystemError referenced in function _WRdealloc >> winrand.obj : error LNK2019: unresolved external symbol >> __imp__PyErr_Format referenced in function _WRdealloc >> winrand.obj : error LNK2019: unresolved external symbol >> __imp__PyExc_TypeError referenced in function _WRdealloc >> winrand.obj : error LNK2019: unresolved external symbol >> __imp___PyObject_New referenced in function _winrandom_new >> winrand.obj : error LNK2019: unresolved external symbol >> __imp__PyArg_ParseTupleAndKeywords referenced in function >> _winrandom_new >> winrand.obj : error LNK2019: unresolved external symbol >> __imp__PyString_FromStringAndSize referenced in function _WR_get_bytes >> winrand.obj : error LNK2019: unresolved external symbol >> __imp__PyMem_Free referenced in function _WR_get_bytes >> winrand.obj : error LNK2019: unresolved external symbol >> __imp__PyErr_NoMemory referenced in function _WR_get_bytes >> winrand.obj : error LNK2019: unresolved external symbol >> __imp__PyMem_Malloc referenced in function _WR_get_bytes >> winrand.obj : error LNK2019: unresolved external symbol >> __imp__PyErr_SetString referenced in function _WR_get_bytes >> winrand.obj : error LNK2019: unresolved external symbol >> __imp__PyExc_ValueError referenced in function _WR_get_bytes >> winrand.obj : error LNK2019: unresolved external symbol >> __imp__PyArg_ParseTuple referenced in function _WR_get_bytes >> winrand.obj : error LNK2019: unresolved external symbol >> __imp__Py_FindMethod referenced in function _WRgetattr >> winrand.obj : error LNK2019: unresolved external symbol >> __imp__PyInt_FromLong referenced in function _WRgetattr >> winrand.obj : error LNK2019: unresolved external symbol >> __imp__Py_FatalError referenced in function _initwinrandom >> winrand.obj : error LNK2019: unresolved external symbol >> __imp__PyErr_Occurred referenced in function _initwinrandom >> winrand.obj : error LNK2019: unresolved external symbol >> __imp__PyModule_AddStringConstant referenced in function >> _initwinrandom >> winrand.obj : error LNK2019: unresolved external symbol >> __imp__PyModule_AddIntConstant referenced in function _initwinrandom >> winrand.obj : error LNK2019: unresolved external symbol >> __imp__Py_InitModule4 referenced in function _initwinrandom >> winrand.obj : error LNK2019: unresolved external symbol >> __imp__PyType_Type referenced in function _initwinrandom >> build\lib.win-amd64-2.7\Crypto\Random\OSRNG\winrandom.pyd : fatal error LNK1120: >> ?21 unresolved externals >> error: command '"C:\Program Files (x86)\Microsoft Visual Studio >> 9.0\VC\BIN\link.exe"' failed with exit status 1120 >> > > It almost seems that python can't find all its files. Are you using a > macro or batch file to invoke python. I actually used > > "c:\x64\Python27\python.exe setup.py install" > > IIRC, I've had issues with a DOSKEY macro before so now I explicitly > use the full path to python.exe. > > Otherwise I'm stumped. >> On Tue, Mar 13, 2012 at 2:59 PM, ? wrote: >>> On Monday, March 12, 2012 1:38:29 PM UTC-7, Alec Taylor wrote: >>>> On a brand new Windows install now, with a brand new VS8 installed >>>> with new YASM and MPIR in c:\usr\src\include and c:\usr\src\lib. >>>> >>>> But it still isn't working: >>>> >>> This was a little challenging. I looked through the setup.py to figure out what assumptions their build process made. First, the file pycrypto-2.5\src\inc-msvc\config.h must be modified. Below is the file I used: >>> >>> config.h >>> =================================================================== >>> /* Define to 1 if you have the declaration of `mpz_powm', and to 0 if you >>> ? don't. */ >>> #define HAVE_DECL_MPZ_POWM 1 >>> >>> /* Define to 1 if you have the declaration of `mpz_powm_sec', and to 0 if you >>> ? don't. */ >>> #define HAVE_DECL_MPZ_POWM_SEC 0 >>> >>> /* Define to 1 if you have the `gmp' library (-lgmp). */ >>> #undef HAVE_LIBGMP >>> >>> /* Define to 1 if you have the `mpir' library (-lmpir). */ >>> #define HAVE_LIBMPIR 1 >>> >>> /* Define to 1 if you have the header file. */ >>> #define HAVE_STDINT_H 1 >>> =================================================================== >>> >>> Although I was able to specify an include directory for mpir.h with -Ic:\usr\include, I was not able specify a lib directory with -Lc:\usr\lib. It looks like setup.py does not honor the -L option. So I finally gave up and just copied the mpir.h file into my Python27\include directory and the mpir.lib file into my Python27\libs directory. >>> >>> After copying the files "python setup.py install" was successful. I created a binary installer with "python setup.py bdist-wininst". >>> >>> There may be a cleaner way to build PyCrypto, but these steps worked for me. >>> >>> casevh >>> -- >>> http://mail.python.org/mailman/listinfo/python-list From patrick.szabo at lexisnexis.at Tue Mar 13 05:41:41 2012 From: patrick.szabo at lexisnexis.at (Szabo, Patrick (LNG-VIE)) Date: Tue, 13 Mar 2012 10:41:41 +0100 Subject: Windows Contextmenu Message-ID: Hi, I wrote the following Script which I want to run from the open with contextmenu in Windows. For that purpose I used py2exe to make an exe out of it. import sys, time, webbrowser def main(): for para in sys.argv[1:]: print sys.argv print "###############################" print para url = "http://production.lexisnexis.at:8080/cocoon/glp/html/%s" % str(para).replace("R:\\", "").replace(".xml", ".html") webbrowser.open_new(url) time.sleep(10) if __name__ == "__main__": main() Now the script runs fine but I don't get all arguments from sys.argv. No mather how many files I mark in the explorer I only get one as an argument. Can anyone tell me how to overcome this issue ? Best regards . . . . . . . . . . . . . . . . . . . . . . . . . . Ing. Patrick Szabo XSLT Developer LexisNexis A-1030 Wien, Marxergasse 25 mailto:patrick.szabo at lexisnexis.at Tel.: +43 1 53452 1573 Fax: +43 1 534 52 146 -------------- next part -------------- An HTML attachment was scrubbed... URL: From jeanmichel at sequans.com Tue Mar 13 06:30:56 2012 From: jeanmichel at sequans.com (Jean-Michel Pichavant) Date: Tue, 13 Mar 2012 11:30:56 +0100 Subject: How to break long method name into more than one line? In-Reply-To: References: <4f5d4390$0$29891$c3e8da3$5496439d@news.astraweb.com> Message-ID: <4F5F21E0.4010308@sequans.com> Chris Angelico wrote: > Just never treat them as laws of physics (in > Soviet Physics, rules break you!). > > ChrisA > hum ... I wonder how this political message is relevant to the OP problem. JM From rosuav at gmail.com Tue Mar 13 06:35:44 2012 From: rosuav at gmail.com (Chris Angelico) Date: Tue, 13 Mar 2012 21:35:44 +1100 Subject: How to break long method name into more than one line? In-Reply-To: <4F5F21E0.4010308@sequans.com> References: <4f5d4390$0$29891$c3e8da3$5496439d@news.astraweb.com> <4F5F21E0.4010308@sequans.com> Message-ID: On Tue, Mar 13, 2012 at 9:30 PM, Jean-Michel Pichavant wrote: > Chris Angelico wrote: >> >> Just never treat them as laws of physics (in >> Soviet Physics, rules break you!). > > hum ... > I wonder how this political message is relevant to the OP problem. Ehh, it's a reference to the "in Soviet Russia" theme of one-liners. You don't break the laws of physics, they break you. My point is that rules about function names etc are *not* inviolate, and should be treated accordingly. ChrisA From albert at spenarnc.xs4all.nl Tue Mar 13 06:40:29 2012 From: albert at spenarnc.xs4all.nl (Albert van der Horst) Date: 13 Mar 2012 10:40:29 GMT Subject: are int, float, long, double, side-effects of computer engineering? References: <5aaded58-af09-41dc-9afd-56d7b7ced239@d7g2000pbl.googlegroups.com> Message-ID: In article <5aaded58-af09-41dc-9afd-56d7b7ced239 at d7g2000pbl.googlegroups.com>, Xah Lee wrote: > >what i meant to point out is that Mathematica deals with numbers at a >high-level human way. That is, one doesn't think in terms of float, >long, int, double. These words are never mentioned. Instead, you have >concepts of machine precision, accuracy. The lang automatically handle >the translation to hardware, and invoking exact value or infinite >precision as required or requested. With e.g. a vanderMonde matrix you can easily make Mathematica fail. If you don't understand what a condition number is, you can't use Mathematica. And yes condition numbers are fully in the realm of concepts of machine precisions and accuracy. Infinite precision takes infinite time. Approaching infinite precious may take exponentional time. > > Xah Groetjes Albert -- -- Albert van der Horst, UTRECHT,THE NETHERLANDS Economic growth -- being exponential -- ultimately falters. albert at spe&ar&c.xs4all.nl &=n http://home.hccnet.nl/a.w.m.van.der.horst From mail at timgolden.me.uk Tue Mar 13 06:40:49 2012 From: mail at timgolden.me.uk (Tim Golden) Date: Tue, 13 Mar 2012 10:40:49 +0000 Subject: Windows Contextmenu In-Reply-To: References: Message-ID: <4F5F2431.2080109@timgolden.me.uk> On 13/03/2012 09:41, Szabo, Patrick (LNG-VIE) wrote: > I wrote the following Script which I want to run from the open with > contextmenu in Windows. > > For that purpose I used py2exe to make an exe out of it. [... snip ...] > > Now the script runs fine but I don?t get all arguments from sys.argv. > > No mather how many files I mark in the explorer I only get one as an > argument. You're missing out vital information: * How have you attached this code to the context menu? What was the exact registry entry (or other method) you used? * Does it work as native Python (ie without the py2exe layer)? * Presumably the same issue occurs if you simply have: print sys.argv on its own (ie it's nothing to do with your loop and later code) TJG From kiuhnm03.4t.yahoo.it Tue Mar 13 07:00:55 2012 From: kiuhnm03.4t.yahoo.it (Kiuhnm) Date: Tue, 13 Mar 2012 12:00:55 +0100 Subject: New Science Discovery: Perl Idiots Remain Idiots After A Decade!New Science Discovery: Perl Idiots Remain Idiots After A Decade! In-Reply-To: References: <0078bbfb-5dfc-48fc-af1a-69de3cf15c3e@b1g2000yqb.googlegroups.com> <4f5df4b3$0$1375$4fafbaef@reader1.news.tin.it> Message-ID: <4f5f28e8$0$1385$4fafbaef@reader2.news.tin.it> On 3/12/2012 20:00, Albert van der Horst wrote: > In article<4f5df4b3$0$1375$4fafbaef at reader1.news.tin.it>, > Kiuhnm wrote: >> On 3/12/2012 12:27, Albert van der Horst wrote: >>> Interestingly in mathematics associative means that it doesn't matter >>> whether you use (a.b).c or a.(b.c). >>> Using xxx-associativity to indicate that it *does* matter is >>> a bit perverse, but the Perl people are not to blame if they use >>> a term in their usual sense. >> >> You may see it this way: >> Def1. An operator +:SxS->S is left-associative iff >> a+b+c = (a+b)+c for all a,b,c in S. >> Def2. An operator +:SxS->S is right-associative iff >> a+b+c = a+(b+c) for all a,b,c in S. >> Def3. An operator +:SxS->S is associative iff it is both left and >> right-associative. > > I know, but what the mathematicians do make so much more sense: > (a+b)+c = a+(b+c) definition of associative. > Henceforth we may leave out the brackets. That's Def3. I don't see your point. > Don't leave out the brackets if the operators if the operators is > not associative. (1 - 1) - 1 != 1 - (1 - 1) and yet we can leave out the parentheses. > P.S. There is no need for the operators to be SxS->S. > For example a b c may be m by n, n by l, l by k matrices respectively. Ops, you're right. Kiuhnm From kiuhnm03.4t.yahoo.it Tue Mar 13 07:03:45 2012 From: kiuhnm03.4t.yahoo.it (Kiuhnm) Date: Tue, 13 Mar 2012 12:03:45 +0100 Subject: New Science Discovery: Perl Idiots Remain Idiots After A Decade!New Science Discovery: Perl Idiots Remain Idiots After A Decade! In-Reply-To: References: <0078bbfb-5dfc-48fc-af1a-69de3cf15c3e@b1g2000yqb.googlegroups.com> <4f5df4b3$0$1375$4fafbaef@reader1.news.tin.it> Message-ID: <4f5f2993$0$1385$4fafbaef@reader2.news.tin.it> On 3/12/2012 20:00, Albert van der Horst wrote: > In article<4f5df4b3$0$1375$4fafbaef at reader1.news.tin.it>, > Kiuhnm wrote: >> On 3/12/2012 12:27, Albert van der Horst wrote: >>> Interestingly in mathematics associative means that it doesn't matter >>> whether you use (a.b).c or a.(b.c). >>> Using xxx-associativity to indicate that it *does* matter is >>> a bit perverse, but the Perl people are not to blame if they use >>> a term in their usual sense. >> >> You may see it this way: >> Def1. An operator +:SxS->S is left-associative iff >> a+b+c = (a+b)+c for all a,b,c in S. >> Def2. An operator +:SxS->S is right-associative iff >> a+b+c = a+(b+c) for all a,b,c in S. >> Def3. An operator +:SxS->S is associative iff it is both left and >> right-associative. > > I know, but what the mathematicians do make so much more sense: > (a+b)+c = a+(b+c) definition of associative. > Henceforth we may leave out the brackets. That's Def3. I don't see your point. > Don't leave out the brackets if the operators if the operators is > not associative. (1 - 1) - 1 != 1 - (1 - 1) and yet we can leave out the parentheses. > P.S. There is no need for the operators to be SxS->S. > For example a b c may be m by n, n by l, l by k matrices respectively. Ops, you're right. Kiuhnm From ferreirafm at lim12.fm.usp.br Tue Mar 13 10:35:32 2012 From: ferreirafm at lim12.fm.usp.br (ferreirafm) Date: Tue, 13 Mar 2012 07:35:32 -0700 (PDT) Subject: concatenate function Message-ID: <1331649332216-4574176.post@n6.nabble.com> Hi List, I've coded three functions that I would like to concatenate. I mean, run them one after another. The third function depends on the results of the second function, which depends on the results of the first one. When I call one function after another, python runs them at the same time causing obvious errors messages. I've tried to call one of them from inside another but no way. Any clues are appreciated. Complete code goes here: http://ompldr.org/vZDB4OQ -- View this message in context: http://python.6.n6.nabble.com/concatenate-function-tp4574176p4574176.html Sent from the Python - python-list mailing list archive at Nabble.com. From ian.g.kelly at gmail.com Tue Mar 13 10:54:10 2012 From: ian.g.kelly at gmail.com (Ian Kelly) Date: Tue, 13 Mar 2012 08:54:10 -0600 Subject: concatenate function In-Reply-To: <1331649332216-4574176.post@n6.nabble.com> References: <1331649332216-4574176.post@n6.nabble.com> Message-ID: On Tue, Mar 13, 2012 at 8:35 AM, ferreirafm wrote: > Hi List, > I've coded three functions that I would like to concatenate. I mean, run > them one after another. The third function depends on the results of the > second function, which depends on the results of the first one. When I call > one function after another, python runs them at the same time causing > obvious errors messages. I've tried to call one of them from inside another > but no way. Any clues are appreciated. > Complete code goes here: > http://ompldr.org/vZDB4OQ They don't look to me like they would run at the same time -- subprocess.call is supposed to wait for the subprocess to finish. What error messages are you getting? From robert.kern at gmail.com Tue Mar 13 11:02:12 2012 From: robert.kern at gmail.com (Robert Kern) Date: Tue, 13 Mar 2012 15:02:12 +0000 Subject: concatenate function In-Reply-To: <1331649332216-4574176.post@n6.nabble.com> References: <1331649332216-4574176.post@n6.nabble.com> Message-ID: On 3/13/12 2:35 PM, ferreirafm wrote: > Hi List, > I've coded three functions that I would like to concatenate. I mean, run > them one after another. The third function depends on the results of the > second function, which depends on the results of the first one. When I call > one function after another, python runs them at the same time causing > obvious errors messages. I've tried to call one of them from inside another > but no way. Any clues are appreciated. > Complete code goes here: > http://ompldr.org/vZDB4OQ Just to clarify, the Python functions are indeed running consecutively, not concurrently. Your Python functions write scripts and then use subprocess.call() to make qsub (an external program) to submit those scripts to a job queue. What you are calling a "function" in your post are these scripts. Please don't call them "functions". It's confusing. Python is not running these scripts concurrently. Your job queue is. subprocess.call() will wait until qsub returns. However, qsub just submits the script to the job queue; it does not wait until the job is completed. Most qsub-using job queues can be set up to make jobs depend on the completion of other jobs. You will need to read the documentation of your job queue to figure out how to do this. Once you figure out the right arguments to give to qsub, your Python code is already more or less correct. -- Robert Kern "I have come to believe that the whole world is an enigma, a harmless enigma that is made terrible by our own mad attempt to interpret it as though it had an underlying truth." -- Umberto Eco From ferreirafm at lim12.fm.usp.br Tue Mar 13 11:17:18 2012 From: ferreirafm at lim12.fm.usp.br (ferreirafm) Date: Tue, 13 Mar 2012 08:17:18 -0700 (PDT) Subject: concatenate function In-Reply-To: References: <1331649332216-4574176.post@n6.nabble.com> Message-ID: <1331651838058-4574337.post@n6.nabble.com> Hi Ian, That what I have: > burst.py Your job 46665 ("top_n_pdb.qsub") has been submitted Your job 46666 ("extr_pdb.qsub") has been submitted Your job 46667 ("combine_top.qsub") has been submitted The first job runs quite well. The second is still runing and the third issue the following: > more combine_top.qsub.e46667 ERROR: Cannot open PDB file "S_3MSEB_26_0032.pdb" ERROR:: Exit from: src/core/import_pose/import_pose.cc line: 199 -- View this message in context: http://python.6.n6.nabble.com/concatenate-function-tp4574176p4574337.html Sent from the Python - python-list mailing list archive at Nabble.com. From paul.nospam at rudin.co.uk Tue Mar 13 11:44:00 2012 From: paul.nospam at rudin.co.uk (Paul Rudin) Date: Tue, 13 Mar 2012 15:44:00 +0000 Subject: Software Engineer - References: <74c28456-5467-48e8-88a9-e5649358373a@to5g2000pbc.googlegroups.com> Message-ID: <87vcm8h5fj.fsf@no-fixed-abode.cable.virginmedia.net> Chris Withers writes: > On 11/03/2012 09:00, Blue Line Talent wrote: >> Blue Line Talent is looking for a mid-level software engineer with >> experience in a combination of > > Please don't spam this list with jobs, use the Python job board instead: > > http://www.python.org/community/jobs/ Just out of interest why do people object to job adverts here? Seems harmless enough... From fil.oracle at gmail.com Tue Mar 13 11:54:20 2012 From: fil.oracle at gmail.com (James Elford) Date: Tue, 13 Mar 2012 15:54:20 +0000 Subject: concatenate function In-Reply-To: <1331649332216-4574176.post@n6.nabble.com> References: <1331649332216-4574176.post@n6.nabble.com> Message-ID: <4F5F6DAC.8000900@gmail.com> On 13/03/12 14:35, ferreirafm wrote: > Hi List, > I've coded three functions that I would like to concatenate. I mean, run > them one after another. The third function depends on the results of the > second function, which depends on the results of the first one. When I call > one function after another, python runs them at the same time causing > obvious errors messages. I've tried to call one of them from inside another > but no way. Any clues are appreciated. > Complete code goes here: > http://ompldr.org/vZDB4OQ Do you think you could provide a much shorter example to illustrate what you need? In general, when you want to run one function on the result of another, you can do something like: <<< def increment_all(l); ... return [i+1 for i in l] <<< increment_all(increment_all(range(3)) [2, 3, 4] Here we apply the function increment_all to the result of the function increment_all. If you are talking about the "results" of each function in terms of it mutating an object, and then the next function mutating the same object in a (possibly) different way, then calling the functions in order will do what you want. l = [0, 3, 5, 2] l.append(10) # [0, 3, 5, 2, 10] l.sort() # [0, 2, 3, 5, 10] l.append(3) # [0, 2, 3, 5, 10, 3] James > > > > -- > View this message in context: http://python.6.n6.nabble.com/concatenate-function-tp4574176p4574176.html > Sent from the Python - python-list mailing list archive at Nabble.com. From ferreirafm at lim12.fm.usp.br Tue Mar 13 11:59:26 2012 From: ferreirafm at lim12.fm.usp.br (ferreirafm) Date: Tue, 13 Mar 2012 08:59:26 -0700 (PDT) Subject: concatenate function In-Reply-To: References: <1331649332216-4574176.post@n6.nabble.com> Message-ID: <1331654366771-4574496.post@n6.nabble.com> Hi Robert, Thanks for you kind replay and I'm sorry for my semantic mistakes. Indeed, that's what I'm doing: qsub-ing different cshell scripts. Certainly, that's not the best approach and the only problem. I've unsuccessfully tried to set an os.environ and call qsub from it. However, subprocess.Popen seems not accept to run "qsub" over a second program. Do you have a over come to this issue? Code goes here: http://ompldr.org/vZDB5YQ -- View this message in context: http://python.6.n6.nabble.com/concatenate-function-tp4574176p4574496.html Sent from the Python - python-list mailing list archive at Nabble.com. From ferreirafm at lim12.fm.usp.br Tue Mar 13 12:02:39 2012 From: ferreirafm at lim12.fm.usp.br (ferreirafm) Date: Tue, 13 Mar 2012 09:02:39 -0700 (PDT) Subject: concatenate function In-Reply-To: <4F5F6DAC.8000900@gmail.com> References: <1331649332216-4574176.post@n6.nabble.com> <4F5F6DAC.8000900@gmail.com> Message-ID: <1331654559793-4574511.post@n6.nabble.com> Hi James, thank you for your replay. Indeed, the problem is qsub. And as warned by Robert, I don't have functions properly, but just scripts. -- View this message in context: http://python.6.n6.nabble.com/concatenate-function-tp4574176p4574511.html Sent from the Python - python-list mailing list archive at Nabble.com. From robert.kern at gmail.com Tue Mar 13 12:09:49 2012 From: robert.kern at gmail.com (Robert Kern) Date: Tue, 13 Mar 2012 16:09:49 +0000 Subject: concatenate function In-Reply-To: <1331654366771-4574496.post@n6.nabble.com> References: <1331649332216-4574176.post@n6.nabble.com> <1331654366771-4574496.post@n6.nabble.com> Message-ID: On 3/13/12 3:59 PM, ferreirafm wrote: > Hi Robert, > Thanks for you kind replay and I'm sorry for my semantic mistakes. > Indeed, that's what I'm doing: qsub-ing different cshell scripts. Certainly, > that's not the best approach and the only problem. It's not a problem to write out a script and have qsub run it. That's a perfectly fine thing to do. You need to read the documentation for your job queue to find out the right arguments to give to qsub to make it wait until the first job finishes before executing the second job. This is not a Python problem. You just need to find the right flags to give to qsub. Alternately, you could just make a single .qsub script running all three of your programs in a single job instead of making three separate .qsub scripts. > I've unsuccessfully tried > to set an os.environ and call qsub from it. However, subprocess.Popen seems > not accept to run "qsub" over a second program. Do you have a over come to > this issue? > Code goes here: > http://ompldr.org/vZDB5YQ When you report a problem, you should copy-and-paste the output that you got and also state the output that you expected. I have no idea what you mean when you say "subprocess.Popen seems not accept to run "qsub" over a second program." -- Robert Kern "I have come to believe that the whole world is an enigma, a harmless enigma that is made terrible by our own mad attempt to interpret it as though it had an underlying truth." -- Umberto Eco From fil.oracle at gmail.com Tue Mar 13 12:12:56 2012 From: fil.oracle at gmail.com (James Elford) Date: Tue, 13 Mar 2012 16:12:56 +0000 Subject: concatenate function In-Reply-To: <1331654559793-4574511.post@n6.nabble.com> References: <1331649332216-4574176.post@n6.nabble.com> <4F5F6DAC.8000900@gmail.com> <1331654559793-4574511.post@n6.nabble.com> Message-ID: <4F5F7208.5060905@gmail.com> On 13/03/12 16:02, ferreirafm wrote: > Hi James, thank you for your replay. Indeed, the problem is qsub. And as > warned by Robert, I don't have functions properly, but just scripts. > > > -- > View this message in context: http://python.6.n6.nabble.com/concatenate-function-tp4574176p4574511.html > Sent from the Python - python-list mailing list archive at Nabble.com. It looks like you're not calling wait() on your subprocesses: you're effectively launching a bunch of processes, then not waiting for them to finish before you ask the next process to operate on the same file. If you haven't given it a good look-over already, the subprocess documentation [1] is worth taking a little time over. [1]: http://docs.python.org/library/subprocess.html#popen-objects James From kiuhnm03.4t.yahoo.it Tue Mar 13 12:41:51 2012 From: kiuhnm03.4t.yahoo.it (Kiuhnm) Date: Tue, 13 Mar 2012 17:41:51 +0100 Subject: New Science Discovery: Perl Idiots Remain Idiots After A Decade!New Science Discovery: Perl Idiots Remain Idiots After A Decade! In-Reply-To: References: <0078bbfb-5dfc-48fc-af1a-69de3cf15c3e@b1g2000yqb.googlegroups.com> <4f5df4b3$0$1375$4fafbaef@reader1.news.tin.it> Message-ID: <4f5f78d1$0$1375$4fafbaef@reader2.news.tin.it> On 3/12/2012 20:00, Albert van der Horst wrote: [...] Sorry for triple posting. I hadn't noticed the follow up and I was blaming my newsserver. BTW, Python is the next language (right after Perl) I'm going to learn. Then I'll probably have a look at Ruby... Kiuhnm From dilvanezanardine at gmail.com Tue Mar 13 12:42:10 2012 From: dilvanezanardine at gmail.com (dilvanezanardine at gmail.com) Date: Tue, 13 Mar 2012 09:42:10 -0700 (PDT) Subject: Installing Python Apps on Mac Lion In-Reply-To: <2ffee45b-8987-4fb4-8c8b-c1eed728e890@glegroupsg2000goo.googlegroups.com> References: <2ffee45b-8987-4fb4-8c8b-c1eed728e890@glegroupsg2000goo.googlegroups.com> Message-ID: <15535377.495.1331656930882.JavaMail.geo-discussion-forums@ynje4> S?bado, 25 de Junho de 2011 02h20min49s UTC+1, JKPeck escreveu: > The Lion version of the OS on the Mac comes with Python 2.7 installed, but it is in /System/Library/Frameworks/..., and this area is not writable by third party apps. > > So is there a consensus on what apps that typically install under the Python site-packages directory should do in this situation? Installing Python from python.org puts it in the writable area /Library/Frameworks/Python.framework. > > So, what should a Python app installer do? > > Thanks Hello, currently I have: /Library/Python/2.7/ /Library/Frameworks/Python.framework/Versions/2.7/ /Users/user/Library/Python/2.7/ With 3 folders "site-packages" and do not know why. What's the difference? Thanks. From phgsouto at gmail.com Tue Mar 13 13:17:22 2012 From: phgsouto at gmail.com (Pedro H. G. Souto) Date: Tue, 13 Mar 2012 14:17:22 -0300 Subject: Software Engineer - In-Reply-To: <87vcm8h5fj.fsf@no-fixed-abode.cable.virginmedia.net> References: <74c28456-5467-48e8-88a9-e5649358373a@to5g2000pbc.googlegroups.com> <87vcm8h5fj.fsf@no-fixed-abode.cable.virginmedia.net> Message-ID: <4F5F8122.8080206@gmail.com> On 2012-03-13 12:44 PM, Paul Rudin wrote: > Just out of interest why do people object to job adverts here? Seems > harmless enough... Wannabe list admins... Or list admins with a need to proof themselves... Or none of the above. From neilc at norwich.edu Tue Mar 13 13:22:31 2012 From: neilc at norwich.edu (Neil Cerutti) Date: 13 Mar 2012 17:22:31 GMT Subject: Software Engineer - References: <74c28456-5467-48e8-88a9-e5649358373a@to5g2000pbc.googlegroups.com> <87vcm8h5fj.fsf@no-fixed-abode.cable.virginmedia.net> Message-ID: <9s9e2nF2rtU1@mid.individual.net> On 2012-03-13, Pedro H. G. Souto wrote: > On 2012-03-13 12:44 PM, Paul Rudin wrote: >> Just out of interest why do people object to job adverts here? >> Seems harmless enough... > > Wannabe list admins... Or list admins with a need to proof > themselves... Or none of the above. A job listing here or there would fine. If the discussion were clogged with them, it would be really annoying. In addition, it's more efficient to post job listing in a place where people looking for jobs can easily find them, and it's annoying and useless to post them in a place where reader not looking for jobs have to delete them. -- Neil Cerutti From ramit.prasad at jpmorgan.com Tue Mar 13 13:28:10 2012 From: ramit.prasad at jpmorgan.com (Prasad, Ramit) Date: Tue, 13 Mar 2012 17:28:10 +0000 Subject: Windows Contextmenu In-Reply-To: <4F5F2431.2080109@timgolden.me.uk> References: <4F5F2431.2080109@timgolden.me.uk> Message-ID: <5B80DD153D7D744689F57F4FB69AF4741C86E6@SCACMX008.exchad.jpmchase.net> > > Now the script runs fine but I don't get all arguments from sys.argv. > > > > No mather how many files I mark in the explorer I only get one as an > > argument. > > You're missing out vital information: > > * How have you attached this code to the context menu? What was > the exact registry entry (or other method) you used? From a quick Google search, it seems that most of the context menu entries open a single file. If multiple files are selected then the command is called once for each file. The workaround seems to check if the processes is already running and if it is then to directly send it a "open" command. That being said, since you are opening a web browser (or so it seems to me based on the webbrowser.open), you should not have an issue because modern web browsers will open each link in a tab. To answer your question, you will not get more than one as an argument. That is expected behavior. Ramit Ramit Prasad | JPMorgan Chase Investment Bank | Currencies Technology 712 Main Street | Houston, TX 77002 work phone: 713 - 216 - 5423 -- This email is confidential and subject to important disclaimers and conditions including on offers for the purchase or sale of securities, accuracy and completeness of information, viruses, confidentiality, legal privilege, and legal entity disclaimers, available at http://www.jpmorgan.com/pages/disclosures/email. From ferreirafm at lim12.fm.usp.br Tue Mar 13 14:01:44 2012 From: ferreirafm at lim12.fm.usp.br (ferreirafm) Date: Tue, 13 Mar 2012 11:01:44 -0700 (PDT) Subject: concatenate function In-Reply-To: References: <1331649332216-4574176.post@n6.nabble.com> <1331654366771-4574496.post@n6.nabble.com> Message-ID: <1331661704724-4574967.post@n6.nabble.com> Robert Kern-2 wrote > > When you report a problem, you should copy-and-paste the output that you > got and > also state the output that you expected. I have no idea what you mean when > you > say "subprocess.Popen seems not accept to run "qsub" over a second > program." > Code goes here: http://ompldr.org/vZDB5YQ stdout: $ no_name.py --toplist top_percent.list Traceback (most recent call last): File "/home6/psloliveira/ferreirafm/bin/no_name.py", line 73, in main() File "/home6/psloliveira/ferreirafm/bin/no_name.py", line 68, in main comb_slt(toplist) File "/home6/psloliveira/ferreirafm/bin/no_name.py", line 55, in comb_slt subprocess.Popen([cmd, options], env=qsub_env) File "/share/apps/python/lib/python2.7/subprocess.py", line 679, in __init__ errread, errwrite) File "/share/apps/python/lib/python2.7/subprocess.py", line 1228, in _execute_child raise child_exception OSError: [Errno 13] Permission denied -- View this message in context: http://python.6.n6.nabble.com/concatenate-function-tp4574176p4574967.html Sent from the Python - python-list mailing list archive at Nabble.com. From benjamin.kaplan at case.edu Tue Mar 13 15:28:37 2012 From: benjamin.kaplan at case.edu (Benjamin Kaplan) Date: Tue, 13 Mar 2012 15:28:37 -0400 Subject: Installing Python Apps on Mac Lion In-Reply-To: <15535377.495.1331656930882.JavaMail.geo-discussion-forums@ynje4> References: <2ffee45b-8987-4fb4-8c8b-c1eed728e890@glegroupsg2000goo.googlegroups.com> <15535377.495.1331656930882.JavaMail.geo-discussion-forums@ynje4> Message-ID: On Tue, Mar 13, 2012 at 12:42 PM, wrote: > > S?bado, 25 de Junho de 2011 02h20min49s UTC+1, JKPeck escreveu: > > The Lion version of the OS on the Mac comes with Python 2.7 installed, > > but it is in /System/Library/Frameworks/..., and this area is not writable > > by third party apps. > > > > So is there a consensus on what apps that typically install under the > > Python site-packages directory should do in this situation? ?Installing > > Python from python.org puts it in the writable area > > /Library/Frameworks/Python.framework. > > > > So, what should a Python app installer do? > > > > Thanks > > Hello, > > currently I have: > > /Library/Python/2.7/ > /Library/Frameworks/Python.framework/Versions/2.7/ > /Users/user/Library/Python/2.7/ > > With 3 folders "site-packages" and do not know why. > What's the difference? > > Thanks. > If I had to take a guess, having not played too much with Lion: /Library/Python/2.7 is for user-installed packages for the system python that are installed for all users. /Library/Frameworks/... is for the user-installed Python (that's where it's always gone) /Users/user/Library... is for user-installed packages for the system Python that are only installed for the specific user. From tjreedy at udel.edu Tue Mar 13 16:07:29 2012 From: tjreedy at udel.edu (Terry Reedy) Date: Tue, 13 Mar 2012 16:07:29 -0400 Subject: Windows Contextmenu In-Reply-To: References: Message-ID: On 3/13/2012 5:41 AM, Szabo, Patrick (LNG-VIE) wrote: > Hi, > > I wrote the following Script which I want to run from the open with > contextmenu in Windows. > Now the script runs fine but I don?t get all arguments from sys.argv. > > No mather how many files I mark in the explorer I only get one as an > argument. The right-click contextmenu is not a command line. It is more like a list of no-arg* methods to call on the selected file. * or rather, one input arg, with others having default values set when the menu entry is created. Sometimes a second input arg is handled, at least in effect, with a second submenu, but I am not familiar with how those are done in Windows. -- Terry Jan Reedy From robert.kern at gmail.com Tue Mar 13 16:35:04 2012 From: robert.kern at gmail.com (Robert Kern) Date: Tue, 13 Mar 2012 20:35:04 +0000 Subject: concatenate function In-Reply-To: <1331661704724-4574967.post@n6.nabble.com> References: <1331649332216-4574176.post@n6.nabble.com> <1331654366771-4574496.post@n6.nabble.com> <1331661704724-4574967.post@n6.nabble.com> Message-ID: On 3/13/12 6:01 PM, ferreirafm wrote: > > Robert Kern-2 wrote >> >> When you report a problem, you should copy-and-paste the output that you >> got and >> also state the output that you expected. I have no idea what you mean when >> you >> say "subprocess.Popen seems not accept to run "qsub" over a second >> program." >> > > Code goes here: > http://ompldr.org/vZDB5YQ > > stdout: > $ no_name.py --toplist top_percent.list > Traceback (most recent call last): > File "/home6/psloliveira/ferreirafm/bin/no_name.py", line 73, in > main() > File "/home6/psloliveira/ferreirafm/bin/no_name.py", line 68, in main > comb_slt(toplist) > File "/home6/psloliveira/ferreirafm/bin/no_name.py", line 55, in comb_slt > subprocess.Popen([cmd, options], env=qsub_env) > File "/share/apps/python/lib/python2.7/subprocess.py", line 679, in > __init__ > errread, errwrite) > File "/share/apps/python/lib/python2.7/subprocess.py", line 1228, in > _execute_child > raise child_exception > OSError: [Errno 13] Permission denied You need to use a command list like this: ['qsub', 'combine_silent.linuxgccrelease', '-database', '/home6/psloliveira/rosetta_database/', ...] The program to run ("qsub", not "qsub combine_silent.linuxgccrelease") and each individual argument must be a separate string in the list. You cannot combine them together with spaces. The reason you get a "Permission denied" error is that it tried to find an executable file named "qsub combine_silent.linuxgccrelease" and, obviously, could not. -- Robert Kern "I have come to believe that the whole world is an enigma, a harmless enigma that is made terrible by our own mad attempt to interpret it as though it had an underlying truth." -- Umberto Eco From clp2 at rebertia.com Tue Mar 13 16:40:40 2012 From: clp2 at rebertia.com (Chris Rebert) Date: Tue, 13 Mar 2012 13:40:40 -0700 Subject: concatenate function In-Reply-To: References: <1331649332216-4574176.post@n6.nabble.com> <1331654366771-4574496.post@n6.nabble.com> <1331661704724-4574967.post@n6.nabble.com> Message-ID: On Tue, Mar 13, 2012 at 1:35 PM, Robert Kern wrote: > On 3/13/12 6:01 PM, ferreirafm wrote: >> Robert Kern-2 wrote >>> When you report a problem, you should copy-and-paste the output that you >>> got and >>> also state the output that you expected. I have no idea what you mean >>> when >>> you >>> say "subprocess.Popen seems not accept to run "qsub" over a second >>> program." >>> >> >> Code goes here: >> http://ompldr.org/vZDB5YQ >> >> stdout: >> $ no_name.py --toplist top_percent.list >> Traceback (most recent call last): >> ? File "/home6/psloliveira/ferreirafm/bin/no_name.py", line 73, in >> ? ? main() >> ? File "/home6/psloliveira/ferreirafm/bin/no_name.py", line 68, in main >> ? ? comb_slt(toplist) >> ? File "/home6/psloliveira/ferreirafm/bin/no_name.py", line 55, in >> comb_slt >> ? ? subprocess.Popen([cmd, options], env=qsub_env) >> ? File "/share/apps/python/lib/python2.7/subprocess.py", line 679, in >> __init__ >> ? ? errread, errwrite) >> ? File "/share/apps/python/lib/python2.7/subprocess.py", line 1228, in >> _execute_child >> ? ? raise child_exception >> OSError: [Errno 13] Permission denied > > > You need to use a command list like this: > > ['qsub', 'combine_silent.linuxgccrelease', '-database', > '/home6/psloliveira/rosetta_database/', ...] > > The program to run ("qsub", not "qsub combine_silent.linuxgccrelease") and > each individual argument must be a separate string in the list. You cannot > combine them together with spaces. The reason you get a "Permission denied" > error is that it tried to find an executable file named "qsub > combine_silent.linuxgccrelease" and, obviously, could not. See also the first "Note" box (and the description of "args" generally) under http://docs.python.org/library/subprocess.html#popen-constructor Cheers, Chris From grahn+nntp at snipabacken.se Tue Mar 13 16:44:37 2012 From: grahn+nntp at snipabacken.se (Jorgen Grahn) Date: 13 Mar 2012 20:44:37 GMT Subject: Fast file data retrieval? References: <4F5E50F6.9070309@it.uu.se> Message-ID: On Mon, 2012-03-12, MRAB wrote: > On 12/03/2012 19:39, Virgil Stokes wrote: >> I have a rather large ASCII file that is structured as follows >> >> header line >> 9 nonblank lines with alphanumeric data >> header line >> 9 nonblank lines with alphanumeric data >> ... >> ... >> ... >> header line >> 9 nonblank lines with alphanumeric data >> EOF >> >> where, a data set contains 10 lines (header + 9 nonblank) and there can >> be several thousand >> data sets in a single file. In addition,*each header has a* *unique ID >> code*. >> >> Is there a fast method for the retrieval of a data set from this large >> file given its ID code? [Responding here since the original is not available on my server.] It depends on what you want to do. Access a few of the entries (what you call data sets) from your program? Process all of them? How fast do you need it to be? > Probably the best solution is to put it into a database. Have a look at > the sqlite3 module. Some people like to use databases for everything, others never use them. I'm in the latter crowd, so to me this sounds as overkill, and possibly impractical. What if he has to keep the text file around? A database on disk would mean duplicating the data. A database in memory would not offer any benefits over a hash. > Alternatively, you could scan the file, recording the ID and the file > offset in a dict so that, given an ID, you can seek directly to that > file position. Mmapping the file (the mmap module) is another option. But I wonder if this really would improve things. "Several thousand" entries is not much these days. If a line is 80 characters, 5000 entries would take ~3MB of memory. The time to move this from disk to a Python list of 9-tuples of strings would be almost only disk I/O. I think he should try to do it the dumb way first: read everything into memory once. /Jorgen -- // Jorgen Grahn O o . From roy at panix.com Tue Mar 13 17:08:08 2012 From: roy at panix.com (Roy Smith) Date: 13 Mar 2012 17:08:08 -0400 Subject: Enchancement suggestion for argparse: intuit type from default Message-ID: Using argparse, if I write: parser.add_argument('--foo', default=100) it seems like it should be able to intuit that the type of foo should be int (i.e. type(default)) without my having to write: parser.add_argument('--foo', type=int, default=100) Does this seem like a reasonable enhancement to argparse? From ben+python at benfinney.id.au Tue Mar 13 17:35:12 2012 From: ben+python at benfinney.id.au (Ben Finney) Date: Wed, 14 Mar 2012 08:35:12 +1100 Subject: Enchancement suggestion for argparse: intuit type from default References: Message-ID: <87zkbkgp67.fsf@benfinney.id.au> roy at panix.com (Roy Smith) writes: > Using argparse, if I write: > > parser.add_argument('--foo', default=100) > > it seems like it should be able to intuit that the type of foo should > be int (i.e. type(default)) [?] -0.5. That feels too magical to me. I don't see a need to special-case that usage. There's not much burden in being explicit for the argument type. -- \ ?Value your freedom or you will lose it, teaches history. | `\ ?Don't bother us with politics,? respond those who don't want | _o__) to learn.? ?Richard M. Stallman, 2002 | Ben Finney From ben+python at benfinney.id.au Tue Mar 13 18:37:39 2012 From: ben+python at benfinney.id.au (Ben Finney) Date: Wed, 14 Mar 2012 09:37:39 +1100 Subject: Adopting =?utf-8?B?4oCYbG9ja2ZpbGXigJk=?= References: <874nu5nywc.fsf@benfinney.id.au> Message-ID: <87ty1sgma4.fsf@benfinney.id.au> Chris Withers writes: > On 03/03/2012 21:43, Ben Finney wrote: > > I don't see a need to horse around with Git either :-) It's currently in > > Subversion, right? Can you not export the VCS history from Google Code's > > Subversion repository [?] > What's wrong with a "git svn clone svn-url-here" ? Thanks for the suggestion. I've imported it from Subversion into Bazaar (my preferred DVCS), and it went smoothly. I will proceed with a handover from Skip for maintenance of ?lockfile?. This will definitely need more people than me to maintain, though! I am interested and motivated to work on the Linux platform, but other platforms will suffer unless I get co-maintainers with experience in the different file locking semantics there. -- \ ?I find the whole business of religion profoundly interesting. | `\ But it does mystify me that otherwise intelligent people take | _o__) it seriously.? ?Douglas Adams | Ben Finney From davidgshi at yahoo.co.uk Tue Mar 13 19:05:39 2012 From: davidgshi at yahoo.co.uk (David Shi) Date: Tue, 13 Mar 2012 23:05:39 +0000 (GMT) Subject: Python-list Digest, Vol 102, Issue 64 In-Reply-To: References: Message-ID: <1331679939.28910.YahooMailNeo@web171605.mail.ir2.yahoo.com> I am looking very simple and straightforward open source Python REST and SOAP demo modules. I really need things which are very simple and convincing.?? I want to demonstrate these to other people. I want to promote you guys' interest.?? I find asp and others frustrating and occupy too much in the market and popularity. Can we do a new tidal wave to win a reasonable portion of the development market? Send me materials to davidgshi at yahoo.co.uk I will give it a go on behalf of the Python community. Regards. David ________________________________ From: "python-list-request at python.org" To: python-list at python.org Sent: Tuesday, 13 March 2012, 20:35 Subject: Python-list Digest, Vol 102, Issue 64 ----- Forwarded Message ----- Send Python-list mailing list submissions to ??? python-list at python.org To subscribe or unsubscribe via the World Wide Web, visit ??? http://mail.python.org/mailman/listinfo/python-list or, via email, send a message with subject or body 'help' to ??? python-list-request at python.org You can reach the person managing the list at ??? python-list-owner at python.org When replying, please edit your Subject line so it is more specific than "Re: Contents of Python-list digest..." Today's Topics: ? 1. Re: concatenate function (James Elford) ? 2. Re: New Science Discovery: Perl Idiots Remain Idiots After A ? ? ? Decade!New??? Science Discovery: Perl Idiots Remain Idiots After A ? ? ? Decade! (Kiuhnm) ? 3. Re: Installing Python Apps on? Mac Lion ? ? ? (dilvanezanardine at gmail.com) ? 4. Re: Software Engineer - (Pedro H. G. Souto) ? 5. Re: Software Engineer - (Neil Cerutti) ? 6. RE: Windows Contextmenu (Prasad, Ramit) ? 7. Re: concatenate function (ferreirafm) ? 8. Re: Installing Python Apps on Mac Lion (Benjamin Kaplan) ? 9. Re: Windows Contextmenu (Terry Reedy) ? 10. Re: concatenate function (Robert Kern) On 13/03/12 16:02, ferreirafm wrote: > Hi James, thank you for your replay. Indeed, the problem is qsub. And as > warned by Robert, I don't have functions properly, but just scripts. >? > > -- > View this message in context: http://python.6.n6.nabble.com/concatenate-function-tp4574176p4574511.html > Sent from the Python - python-list mailing list archive at Nabble.com. It looks like you're not calling wait() on your subprocesses: you're effectively launching a bunch of processes, then not waiting for them to finish before you ask the next process to operate on the same file. If you haven't given it a good look-over already, the subprocess documentation [1] is worth taking a little time over. ??? [1]: http://docs.python.org/library/subprocess.html#popen-objects James On 3/12/2012 20:00, Albert van der Horst wrote: [...] Sorry for triple posting. I hadn't noticed the follow up and I was blaming my newsserver. BTW, Python is the next language (right after Perl) I'm going to learn. Then I'll probably have a look at Ruby... Kiuhnm S?bado, 25 de Junho de 2011 02h20min49s UTC+1, JKPeck escreveu: > The Lion version of the OS on the Mac comes with Python 2.7 installed, but it is in /System/Library/Frameworks/..., and this area is not writable by third party apps. > > So is there a consensus on what apps that typically install under the Python site-packages directory should do in this situation?? Installing Python from python.org puts it in the writable area /Library/Frameworks/Python.framework. > > So, what should a Python app installer do? > > Thanks Hello, currently I have: /Library/Python/2.7/ /Library/Frameworks/Python.framework/Versions/2.7/ /Users/user/Library/Python/2.7/ With 3 folders "site-packages" and do not know why. What's the difference? Thanks. On 2012-03-13 12:44 PM, Paul Rudin wrote: > Just out of interest why do people object to job adverts here? Seems > harmless enough... Wannabe list admins... Or list admins with a need to proof themselves... Or none of the above. On 2012-03-13, Pedro H. G. Souto wrote: > On 2012-03-13 12:44 PM, Paul Rudin wrote: >> Just out of interest why do people object to job adverts here? >> Seems harmless enough... > > Wannabe list admins... Or list admins with a need to proof > themselves... Or none of the above. A job listing here or there would fine. If the discussion were clogged with them, it would be really annoying. In addition, it's more efficient to post job listing in a place where people looking for jobs can easily find them, and it's annoying and useless to post them in a place where reader not looking for jobs have to delete them. -- Neil Cerutti > > Now the script runs fine but I don't get all arguments from sys.argv. > > > > No mather how many files I mark in the explorer I only get one as an > > argument. > > You're missing out vital information: > > * How have you attached this code to the context menu? What was > the exact registry entry (or other method) you used? From a quick Google search, it seems that most of the context menu entries open a single file. If multiple files are selected then the command is called once for each file. The workaround seems to check if the processes is already running and if it is then to directly send it a "open" command. That being said, since you are opening a web browser (or so it seems to me based on the webbrowser.open), you should not have an issue because modern web browsers will open each link in a tab. To answer your question, you will not get more than one as an argument. That is expected behavior. Ramit Ramit Prasad | JPMorgan Chase Investment Bank | Currencies Technology 712 Main Street | Houston, TX 77002 work phone: 713 - 216 - 5423 -- This email is confidential and subject to important disclaimers and conditions including on offers for the purchase or sale of securities, accuracy and completeness of information, viruses, confidentiality, legal privilege, and legal entity disclaimers, available at http://www.jpmorgan.com/pages/disclosures/email. Robert Kern-2 wrote > > When you report a problem, you should copy-and-paste the output that you > got and > also state the output that you expected. I have no idea what you mean when > you > say "subprocess.Popen seems not accept to run "qsub" over a second > program." > Code goes here: http://ompldr.org/vZDB5YQ stdout: $ no_name.py --toplist top_percent.list Traceback (most recent call last): ? File "/home6/psloliveira/ferreirafm/bin/no_name.py", line 73, in ? ? main() ? File "/home6/psloliveira/ferreirafm/bin/no_name.py", line 68, in main ? ? comb_slt(toplist) ? File "/home6/psloliveira/ferreirafm/bin/no_name.py", line 55, in comb_slt ? ? subprocess.Popen([cmd, options], env=qsub_env) ? File "/share/apps/python/lib/python2.7/subprocess.py", line 679, in __init__ ? ? errread, errwrite) ? File "/share/apps/python/lib/python2.7/subprocess.py", line 1228, in _execute_child ? ? raise child_exception OSError: [Errno 13] Permission denied -- View this message in context: http://python.6.n6.nabble.com/concatenate-function-tp4574176p4574967.html Sent from the Python - python-list mailing list archive at Nabble.com. On Tue, Mar 13, 2012 at 12:42 PM, wrote: > > S?bado, 25 de Junho de 2011 02h20min49s UTC+1, JKPeck escreveu: > > The Lion version of the OS on the Mac comes with Python 2.7 installed, > > but it is in /System/Library/Frameworks/..., and this area is not writable > > by third party apps. > > > > So is there a consensus on what apps that typically install under the > > Python site-packages directory should do in this situation? ?Installing > > Python from python.org puts it in the writable area > > /Library/Frameworks/Python.framework. > > > > So, what should a Python app installer do? > > > > Thanks > > Hello, > > currently I have: > > /Library/Python/2.7/ > /Library/Frameworks/Python.framework/Versions/2.7/ > /Users/user/Library/Python/2.7/ > > With 3 folders "site-packages" and do not know why. > What's the difference? > > Thanks. > If I had to take a guess, having not played too much with Lion: /Library/Python/2.7 is for user-installed packages for the system python that are installed for all users. /Library/Frameworks/... is for the user-installed Python (that's where it's always gone) /Users/user/Library... is for user-installed packages for the system Python that are only installed for the specific user. On 3/13/2012 5:41 AM, Szabo, Patrick (LNG-VIE) wrote: > Hi, > > I wrote the following Script which I want to run from the open with > contextmenu in Windows. > Now the script runs fine but I don?t get all arguments from sys.argv. > > No mather how many files I mark in the explorer I only get one as an > argument. The right-click contextmenu is not a command line. It is more like a list of no-arg* methods to call on the selected file. * or rather, one input arg, with others having default values set when the menu entry is created. Sometimes a second input arg is handled, at least in effect, with a second submenu, but I am not familiar with how those are done in Windows. -- Terry Jan Reedy On 3/13/12 6:01 PM, ferreirafm wrote: > > Robert Kern-2 wrote >> >> When you report a problem, you should copy-and-paste the output that you >> got and >> also state the output that you expected. I have no idea what you mean when >> you >> say "subprocess.Popen seems not accept to run "qsub" over a second >> program." >> > > Code goes here: > http://ompldr.org/vZDB5YQ > > stdout: > $ no_name.py --toplist top_percent.list > Traceback (most recent call last): >? ? File "/home6/psloliveira/ferreirafm/bin/no_name.py", line 73, in >? ? ? main() >? ? File "/home6/psloliveira/ferreirafm/bin/no_name.py", line 68, in main >? ? ? comb_slt(toplist) >? ? File "/home6/psloliveira/ferreirafm/bin/no_name.py", line 55, in comb_slt >? ? ? subprocess.Popen([cmd, options], env=qsub_env) >? ? File "/share/apps/python/lib/python2.7/subprocess.py", line 679, in > __init__ >? ? ? errread, errwrite) >? ? File "/share/apps/python/lib/python2.7/subprocess.py", line 1228, in > _execute_child >? ? ? raise child_exception > OSError: [Errno 13] Permission denied You need to use a command list like this: ['qsub', 'combine_silent.linuxgccrelease', '-database', '/home6/psloliveira/rosetta_database/', ...] The program to run ("qsub", not "qsub combine_silent.linuxgccrelease") and each individual argument must be a separate string in the list. You cannot combine them together with spaces. The reason you get a "Permission denied" error is that it tried to find an executable file named "qsub combine_silent.linuxgccrelease" and, obviously, could not. -- Robert Kern "I have come to believe that the whole world is an enigma, a harmless enigma that is made terrible by our own mad attempt to interpret it as though it had an underlying truth." ? -- Umberto Eco -- http://mail.python.org/mailman/listinfo/python-list -------------- next part -------------- An HTML attachment was scrubbed... URL: From veeru.bangalore2012 at gmail.com Wed Mar 14 00:25:26 2012 From: veeru.bangalore2012 at gmail.com (Veeru .) Date: Tue, 13 Mar 2012 21:25:26 -0700 (PDT) Subject: India Software Developer Conference: Learn from the Experts at Top Tech Companies (March 24 & 25, 2012 Bangalore) Message-ID: <5e45aa44-b0c4-44f9-8e51-c5aeeac4f332@qb4g2000pbb.googlegroups.com> Hi, I got to know of an exciting event happening in Bangalore on March 24th & 25th India Software Developer Conference 2012 which is an enterprise software developer conference designed for developers, team leads, architects and project management is back! There is no other event in India with similar opportunities for learning, networking, and tracking innovation occurring in the Java, .NET, Html5, Mobile, Agile and Architecture communities I believe it is worth attending as there are interesting topics. The Conference starts at 8.30 AM. The Venue NIMHANS Convention Centre, Hosur Road, Near Diary Circle, Bangalore, The Conference organizers will call you back to confirm. Please find below is the url to go through the website http://tinyurl.com/ISDC-Blr Regards, Veeru From nagle at animats.com Wed Mar 14 01:32:14 2012 From: nagle at animats.com (John Nagle) Date: Tue, 13 Mar 2012 22:32:14 -0700 Subject: are int, float, long, double, side-effects of computer engineering? In-Reply-To: <7a32aa69-e1c7-4129-be11-70ae461b34b8@od7g2000pbb.googlegroups.com> References: <5aaded58-af09-41dc-9afd-56d7b7ced239@d7g2000pbl.googlegroups.com> <8a3cd8d4-26d2-4cdf-b66d-43895a0bcd1e@qb4g2000pbb.googlegroups.com> <7a32aa69-e1c7-4129-be11-70ae461b34b8@od7g2000pbb.googlegroups.com> Message-ID: <4f602d5b$0$12043$742ec2ed@news.sonic.net> On 3/7/2012 2:02 PM, Russ P. wrote: > On Mar 6, 7:25 pm, rusi wrote: >> On Mar 6, 6:11 am, Xah Lee wrote: > I might add that Mathematica is designed mainly for symbolic > computation, whereas IEEE floating point numbers are intended for > numerical computation. Those are two very different endeavors. I > played with Mathematica a bit several years ago, and I know it can do > numerical computation too. I wonder if it resorts to IEEE floating > point numbers when it does. Mathematica has, for some computations, algorithms to determine the precision of results. This is different than trying to do infinite precision arithmetic, which doesn't help as soon as you get to trig functions. It's about bounding the error. It's possible to do bounded arithmetic, where you carry along an upper and lower bound on each number. The problem is what to do about comparisons. Comparisons between bounded numbers are ambiguous when the ranges overlap. Algorithms have to be designed to deal with that. Mathematica has such algorithms for some operations, especially numerical integration. It's a very real issue. I had to deal with this when I was writing the first "ragdoll physics" system that worked right, back in the 1990s. Everybody else's system blew up on the hard cases; mine just slowed down. Correct integration over a force function that's changing over 18 orders of magnitude is difficult, but quite possible. (Here it is, from 1997: "http://www.youtube.com/watch?v=5lHqEwk7YHs") (A test with a heavy object: "http://www.youtube.com/watch?v=-DaWIHc1VLY". Most physics engines don't do heavy objects well. Everything looks too light. We call this the "boink problem.") John Nagle From alec.taylor6 at gmail.com Wed Mar 14 05:47:52 2012 From: alec.taylor6 at gmail.com (Alec Taylor) Date: Wed, 14 Mar 2012 20:47:52 +1100 Subject: PyCrypto builds neither with MSVC nor MinGW In-Reply-To: References: <35da69c3-edcc-4466-8a0d-70237c88af3b@qv4g2000pbc.googlegroups.com> <13993807.3661.1331611178050.JavaMail.geo-discussion-forums@pbcgf10> Message-ID: Oh wait, just realised it was loading the (x86) tools. Doing a quick search I noticed that I didn't have the x64 components installed, so loading up the MSVC08 setup again and installing it, then: copying vcvarsamd64.bat to vcvarsall.bat and adding its directory (C:\Program Files (x86)\Microsoft Visual Studio 9.0\VC\bin\amd64\) to PATH.... AND IT WORKS! =D From gelonida at gmail.com Wed Mar 14 06:07:33 2012 From: gelonida at gmail.com (Gelonida N) Date: Wed, 14 Mar 2012 11:07:33 +0100 Subject: Is there a ConfigParser which keeps comments Message-ID: Hi, At the moment I use ConfigParser http://docs.python.org/library/configparser.html for one of my applications. Now I'm looking for a library, which behaves like config parser, but with one minor difference. The write() mehtod should keep existing comments. Does anybody know or implement something like this or is there as switrch, that I overlooked in hte documentaiton. From rustompmody at gmail.com Wed Mar 14 06:22:02 2012 From: rustompmody at gmail.com (rusi) Date: Wed, 14 Mar 2012 03:22:02 -0700 (PDT) Subject: Enchancement suggestion for argparse: intuit type from default References: Message-ID: <431e658c-9dd2-4f49-b9be-d228367dc48e@ms3g2000pbb.googlegroups.com> On Mar 14, 2:08?am, r... at panix.com (Roy Smith) wrote: > Using argparse, if I write: > > ? ? parser.add_argument('--foo', default=100) > > it seems like it should be able to intuit that the type of foo should > be int (i.e. type(default)) without my having to write: > > ? ? parser.add_argument('--foo', type=int, default=100) > > Does this seem like a reasonable enhancement to argparse? Sounds reasonable to me From laloothadhani at gmail.com Wed Mar 14 07:41:23 2012 From: laloothadhani at gmail.com (laloo) Date: Wed, 14 Mar 2012 04:41:23 -0700 (PDT) Subject: Info on RIDE Message-ID: <6b8aa4a4-7515-4dd7-b05b-d68abd39d3db@pz2g2000pbc.googlegroups.com> Hi Sir I have installed the robot framework but have a problem understanding the RIDE and how to execute Data driven Test Case If you can take me through this on Skype it will be really great. Thanks Laloo Thadhani From ulrich.eckhardt at dominolaser.com Wed Mar 14 08:26:14 2012 From: ulrich.eckhardt at dominolaser.com (Ulrich Eckhardt) Date: Wed, 14 Mar 2012 13:26:14 +0100 Subject: Enchancement suggestion for argparse: intuit type from default In-Reply-To: References: Message-ID: <6cf639-pm6.ln1@satorlaser.homedns.org> Am 13.03.2012 22:08, schrieb Roy Smith: > Using argparse, if I write: > > parser.add_argument('--foo', default=100) > > it seems like it should be able to intuit that the type of foo should > be int (i.e. type(default)) without my having to write: > > parser.add_argument('--foo', type=int, default=100) > > Does this seem like a reasonable enhancement to argparse? The following would turn into an error: # in foo.py: p.add_argument('--offset', 0) # calling foo.py: foo.py --offset 1.5 OTOH, this would be obvious even from halfway serious testing, so I'm +1 for making this change. Have you looked at existing use of this and where it would break anything? When the argument doesn't match the type, is the error message sufficiently understandable? Uli From steve+comp.lang.python at pearwood.info Wed Mar 14 08:53:25 2012 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 14 Mar 2012 12:53:25 GMT Subject: Enchancement suggestion for argparse: intuit type from default References: <87zkbkgp67.fsf@benfinney.id.au> Message-ID: <4f6094c5$0$29972$c3e8da3$5496439d@news.astraweb.com> On Wed, 14 Mar 2012 08:35:12 +1100, Ben Finney wrote: > roy at panix.com (Roy Smith) writes: > >> Using argparse, if I write: >> >> parser.add_argument('--foo', default=100) >> >> it seems like it should be able to intuit that the type of foo should >> be int (i.e. type(default)) > [?] > > -0.5. > > That feels too magical to me. I don't see a need to special-case that > usage. There's not much burden in being explicit for the argument type. And yet you are programming in Python instead of Java, Pascal or Ada :) It's not magic at all, it's science! Or to be precise, it's a very simple form of type inference, similar to (but much more basic than) that used by languages such as Go, Haskell, Ocaml, and ML. http://en.wikipedia.org/wiki/Type_inference Given the premise that arguments in argparser are typed, if the argument can take the value 100 (the default), it is logical that it can't be a string (because 100 is not a string) or a boolean (because 100 is not a boolean) or a list (because... well, you get the point). What if you want an argument --foo that will accept arbitrary types? Then you would need some way to tell argparse not to infer the type from the default. Python *names* are not typed, but objects are. Python infers the type of the object from its syntax. We write: n = 100 and not: n = int 100 Assuming that argparse arguments are typed, and that there is a way to over-rule the type-inference, there is no need to declare types in the common case. Explicit declarations should be used only for the uncommon cases where type inference cannot cope. -- Steven From ben+python at benfinney.id.au Wed Mar 14 09:19:15 2012 From: ben+python at benfinney.id.au (Ben Finney) Date: Thu, 15 Mar 2012 00:19:15 +1100 Subject: Enchancement suggestion for argparse: intuit type from default References: <87zkbkgp67.fsf@benfinney.id.au> <4f6094c5$0$29972$c3e8da3$5496439d@news.astraweb.com> Message-ID: <87399bgw18.fsf@benfinney.id.au> Steven D'Aprano writes: > On Wed, 14 Mar 2012 08:35:12 +1100, Ben Finney wrote: > > That feels too magical to me. I don't see a need to special-case > > that usage. There's not much burden in being explicit for the > > argument type. > > And yet you are programming in Python instead of Java, Pascal or Ada > :) That's a good point :-) > It's not magic at all, it's science! Or to be precise, it's a very simple > form of type inference Right. I dislike proposals for run-time type inference in Python, since they are too magical. Especially since we're talking about user input (arguments from the command line to the program); that requires more explicit declarations and checking, not less. > What if you want an argument --foo that will accept arbitrary types? Then > you would need some way to tell argparse not to infer the type from the > default. So we would then need to special-case the special-case? Even more reason to dislike this proposal. > Explicit declarations should be used only for the uncommon cases where > type inference cannot cope. That's our point of disagreement, then: I think explicit declarations should be required regarding user input. -- \ ?Ridicule is the only weapon which can be used against | `\ unintelligible propositions.? ?Thomas Jefferson, 1816-07-30 | _o__) | Ben Finney From cosmius at gmail.com Wed Mar 14 09:28:58 2012 From: cosmius at gmail.com (Cosmia Luna) Date: Wed, 14 Mar 2012 06:28:58 -0700 (PDT) Subject: How to decide if a object is instancemethod? Message-ID: <8815977.3878.1331731738209.JavaMail.geo-discussion-forums@vbux23> class Foo(object): def bar(self): return 'Something' func = Foo().bar if type(func) == : # This should be always true pass # do something here What should type at ? Thanks Cosmia From roy at panix.com Wed Mar 14 09:30:45 2012 From: roy at panix.com (Roy Smith) Date: Wed, 14 Mar 2012 09:30:45 -0400 Subject: Enchancement suggestion for argparse: intuit type from default References: <87zkbkgp67.fsf@benfinney.id.au> <4f6094c5$0$29972$c3e8da3$5496439d@news.astraweb.com> <87399bgw18.fsf@benfinney.id.au> Message-ID: In article <87399bgw18.fsf at benfinney.id.au>, Ben Finney wrote: > Right. I dislike proposals for run-time type inference in Python, since > they are too magical. > > Especially since we're talking about user input (arguments from the > command line to the program); that requires more explicit declarations > and checking, not less. > > > What if you want an argument --foo that will accept arbitrary types? Then > > you would need some way to tell argparse not to infer the type from the > > default. > > So we would then need to special-case the special-case? Even more reason > to dislike this proposal. > > > Explicit declarations should be used only for the uncommon cases where > > type inference cannot cope. > > That's our point of disagreement, then: I think explicit declarations > should be required regarding user input. I wasn't suggesting that the type be inferred from what the user entered. I was suggesting it be inferred from what the programmer had done (i.e. what value they had given the 'default' parameter). It's already inferred that the type is a string if you don't give it any value. What possible meaning could: parser.add_argument('--foo', default=100) have? If I run the program with: $ prog then foo defaults to the integer 100, but if I run it with: $ prog --foo=100 then I get the string "100"? Surely there's not much of a use case for that. From didierblanchard at gmail.com Wed Mar 14 09:46:01 2012 From: didierblanchard at gmail.com (Dids) Date: Wed, 14 Mar 2012 06:46:01 -0700 (PDT) Subject: Instantiate a python class object in C Message-ID: <500e1575-78e7-45aa-8fc3-78427bbe917c@l7g2000vbw.googlegroups.com> Hi, Apologies if this was asked before, I couldn't find anything. I have a class defined in a python file: for example: class demo: [ class definition goes here] I'm writing a C extension. In the first function, I take an instance of the "demo" class and do my magic. It's working, all is good. What I can't figure out is how to create a second C function that returns a new instance to the "demo" class to python. There must a be tutorial somewhere, but I can't find anything. I do not want to define a new python class in C. Another example: This is working: demo_obj1 = demo() my_C_extension.function_1( demo_obj1 ) //working, all good. This I can't figure out how to do: new_demo_obj = my_C_extension.function_2() Thanks for reading, Dids, From joncle at googlemail.com Wed Mar 14 09:57:35 2012 From: joncle at googlemail.com (Jon Clements) Date: Wed, 14 Mar 2012 06:57:35 -0700 (PDT) Subject: How to decide if a object is instancemethod? In-Reply-To: <8815977.3878.1331731738209.JavaMail.geo-discussion-forums@vbux23> References: <8815977.3878.1331731738209.JavaMail.geo-discussion-forums@vbux23> Message-ID: <389400.5582.1331733455084.JavaMail.geo-discussion-forums@vbiz13> On Wednesday, 14 March 2012 13:28:58 UTC, Cosmia Luna wrote: > class Foo(object): > def bar(self): > return 'Something' > > func = Foo().bar > > if type(func) == : # This should be always true > pass # do something here > > What should type at ? > > Thanks > Cosmia import inspect if inspect.ismethod(foo): # ... Will return True if foo is a bound method. hth Jon From stefan_ml at behnel.de Wed Mar 14 10:13:05 2012 From: stefan_ml at behnel.de (Stefan Behnel) Date: Wed, 14 Mar 2012 15:13:05 +0100 Subject: Instantiate a python class object in C In-Reply-To: <500e1575-78e7-45aa-8fc3-78427bbe917c@l7g2000vbw.googlegroups.com> References: <500e1575-78e7-45aa-8fc3-78427bbe917c@l7g2000vbw.googlegroups.com> Message-ID: Dids, 14.03.2012 14:46: > Apologies if this was asked before, I couldn't find anything. > > I have a class defined in a python file: > for example: > > class demo: > [ class definition goes here] > > I'm writing a C extension. > In the first function, I take an instance of the "demo" class and do > my magic. It's working, all is good. > > What I can't figure out is how to create a second C function that > returns a new instance to the "demo" class to python. > There must a be tutorial somewhere, but I can't find anything. I do > not want to define a new python class in C. > > Another example: > This is working: > demo_obj1 = demo() > my_C_extension.function_1( demo_obj1 ) //working, all good. > > This I can't figure out how to do: > new_demo_obj = my_C_extension.function_2() You should consider giving Cython a try. It will allow you to write normal Python code for your C extension that it translates to efficient C code. This is much easier than writing all of this by hand, especially when it comes to classes. It will also optimise the code for you, so that you'll often end up with faster code than what you'd manually write. Stefan From josephmeiring at gmail.com Wed Mar 14 10:16:35 2012 From: josephmeiring at gmail.com (JoeM) Date: Wed, 14 Mar 2012 07:16:35 -0700 (PDT) Subject: Jinja2 + jQuery tabs widget Message-ID: <1715f106-4e6f-45db-b224-fb9f219c2027@x17g2000yqj.googlegroups.com> Hi All, I'm having issues including a {block} of content from Jinja2 template into a jQueryUI tab. Does anyone know if such a thing is possible? An example is below, which gives me a 500 error when loading the page. Thanks, Joe
    {% block map_content %} {% endblock %}
    From didierblanchard at gmail.com Wed Mar 14 10:28:35 2012 From: didierblanchard at gmail.com (Dids) Date: Wed, 14 Mar 2012 07:28:35 -0700 (PDT) Subject: Instantiate a python class object in C References: <500e1575-78e7-45aa-8fc3-78427bbe917c@l7g2000vbw.googlegroups.com> Message-ID: <44ca54da-a2ca-48ff-83e7-9de18b064f0e@y10g2000vbn.googlegroups.com> Ok, I have it :) PyImport_Import , PyModule_GetDict, PyDict_GetItemString and PyObject_CallObject Need to take a second look at cython when I have a spare cycle or 2. Thanks for the the tip :) A+ Dids, From ferreirafm at lim12.fm.usp.br Wed Mar 14 10:37:52 2012 From: ferreirafm at lim12.fm.usp.br (ferreirafm) Date: Wed, 14 Mar 2012 07:37:52 -0700 (PDT) Subject: concatenate function In-Reply-To: References: <1331649332216-4574176.post@n6.nabble.com> <1331654366771-4574496.post@n6.nabble.com> <1331661704724-4574967.post@n6.nabble.com> Message-ID: <1331735872293-4578408.post@n6.nabble.com> Hi there, The problem has been solved. I 've decided to run the python script as argument of qsub instead of run qsub from inside of the script itself. I also use .wait() as suggest by colleagues above. Final code goes here: http://ompldr.org/vZDFiag Thank you very much for helping. -- View this message in context: http://python.6.n6.nabble.com/concatenate-function-tp4574176p4578408.html Sent from the Python - python-list mailing list archive at Nabble.com. From joncle at googlemail.com Wed Mar 14 10:39:00 2012 From: joncle at googlemail.com (Jon Clements) Date: Wed, 14 Mar 2012 07:39:00 -0700 (PDT) Subject: Jinja2 + jQuery tabs widget In-Reply-To: <1715f106-4e6f-45db-b224-fb9f219c2027@x17g2000yqj.googlegroups.com> References: <1715f106-4e6f-45db-b224-fb9f219c2027@x17g2000yqj.googlegroups.com> Message-ID: <1279295.3910.1331735941023.JavaMail.geo-discussion-forums@vbue17> On Wednesday, 14 March 2012 14:16:35 UTC, JoeM wrote: > Hi All, > > I'm having issues including a {block} of content from Jinja2 > template into a jQueryUI tab. Does anyone know if such a thing is > possible? An example is below, which gives me a 500 error when loading > the page. > > Thanks, > Joe > > > > > > > > > > > {% block map_content %} {% endblock %} >
    >
    Firstly, this isn't really a Python language question - although jinja2 is a commonly used module for web frameworks. Secondly, the code looks fine, except we don't know what's in the map_content block. Thirdly, 500 is an internal server error - so it's possible it's nothing to do with any of this anyway -- could you provide a more comprehensive error message? Jon. From tymoteusz.jankowski at gmail.com Wed Mar 14 10:43:07 2012 From: tymoteusz.jankowski at gmail.com (xliiv) Date: Wed, 14 Mar 2012 07:43:07 -0700 (PDT) Subject: Is it technically possible to give Python option of naming process of running script? Message-ID: <19118128.4791.1331736187952.JavaMail.geo-discussion-forums@vbai14> Like the topic.. . I use Python a lot, both Windows and Linux, and it's little weird to have many python process without fast distinction which is what. From josephmeiring at gmail.com Wed Mar 14 10:50:10 2012 From: josephmeiring at gmail.com (JoeM) Date: Wed, 14 Mar 2012 07:50:10 -0700 (PDT) Subject: Jinja2 + jQuery tabs widget In-Reply-To: <1715f106-4e6f-45db-b224-fb9f219c2027@x17g2000yqj.googlegroups.com> References: <1715f106-4e6f-45db-b224-fb9f219c2027@x17g2000yqj.googlegroups.com> Message-ID: <32873446.2390.1331736610160.JavaMail.geo-discussion-forums@vbfl9> Disregard, apparently you can't include a {block} more than once in a Jinja2 template, which was causing the error. Cheers, Joed From rosuav at gmail.com Wed Mar 14 11:13:46 2012 From: rosuav at gmail.com (Chris Angelico) Date: Thu, 15 Mar 2012 02:13:46 +1100 Subject: Is it technically possible to give Python option of naming process of running script? In-Reply-To: <19118128.4791.1331736187952.JavaMail.geo-discussion-forums@vbai14> References: <19118128.4791.1331736187952.JavaMail.geo-discussion-forums@vbai14> Message-ID: On Thu, Mar 15, 2012 at 1:43 AM, xliiv wrote: > Like the topic.. . > I use Python a lot, both Windows and Linux, and it's little weird to have many python process without fast distinction which is what. I've no idea if it's even possible on Windows. On Linux, what you want is the prctl function, which (AFAIK) isn't directly available. Google is your friend, though. Question's already been asked on Stack Overflow and such, and has a few answers. Nothing that looks cut-and-dried ready, but several that might work. Look for 'prctl' and 'PR_SET_NAME', which are the C-level function and constant that do the job; a cursory examination of PyPI shows a module with prctl in the name, so that may be of value. ChrisA From invalid at invalid.invalid Wed Mar 14 12:02:02 2012 From: invalid at invalid.invalid (Grant Edwards) Date: Wed, 14 Mar 2012 16:02:02 +0000 (UTC) Subject: Is it technically possible to give Python option of naming process of running script? References: <19118128.4791.1331736187952.JavaMail.geo-discussion-forums@vbai14> Message-ID: On 2012-03-14, Chris Angelico wrote: > On Thu, Mar 15, 2012 at 1:43 AM, xliiv wrote: >> Like the topic.. . >> I use Python a lot, both Windows and Linux, and it's little weird to have many python process without fast distinction which is what. > > I've no idea if it's even possible on Windows. On Linux, what you want > is the prctl function, which (AFAIK) isn't directly available. > > Google is your friend, though. Question's already been asked on Stack > Overflow and such, and has a few answers. Nothing that looks > cut-and-dried ready, but several that might work. The question of how to set the application name comes up somewhat regularly. It would be awfully nice if there was a way for python applications to set their application name. It's especially useful for daemons, and makes it much easier when you can kill them by name instead of having to look up the PID. It seems like an excellent thing to add to the "os" module. > Look for 'prctl' and 'PR_SET_NAME', which are the C-level function > and constant that do the job; a cursory examination of PyPI shows a > module with prctl in the name, so that may be of value. -- Grant Edwards grant.b.edwards Yow! TONY RANDALL! Is YOUR at life a PATIO of FUN?? gmail.com From tjreedy at udel.edu Wed Mar 14 13:06:30 2012 From: tjreedy at udel.edu (Terry Reedy) Date: Wed, 14 Mar 2012 13:06:30 -0400 Subject: Is there a ConfigParser which keeps comments In-Reply-To: References: Message-ID: On 3/14/2012 6:07 AM, Gelonida N wrote: > Hi, > > > At the moment I use ConfigParser > http://docs.python.org/library/configparser.html > for one of my applications. > > > Now I'm looking for a library, which behaves like config parser, but > with one minor difference. > > The write() mehtod should keep existing comments. > Does anybody know or implement something like this or is there as > switrch, that I overlooked in hte documentaiton. Assuming that you have not overlooked anything, I would just subclass ConfigParser with an altered write method. -- Terry Jan Reedy From tjreedy at udel.edu Wed Mar 14 13:13:49 2012 From: tjreedy at udel.edu (Terry Reedy) Date: Wed, 14 Mar 2012 13:13:49 -0400 Subject: Is it technically possible to give Python option of naming process of running script? In-Reply-To: References: <19118128.4791.1331736187952.JavaMail.geo-discussion-forums@vbai14> Message-ID: On 3/14/2012 12:02 PM, Grant Edwards wrote: > It seems like an excellent thing to add to the "os" module. If 'prctl' is a standard POSIX system call, then it should be a candidate for inclusion in the os module if someone opens a tracker enhancement issue and presents an argument in favor. -- Terry Jan Reedy From ramit.prasad at jpmorgan.com Wed Mar 14 13:20:50 2012 From: ramit.prasad at jpmorgan.com (Prasad, Ramit) Date: Wed, 14 Mar 2012 17:20:50 +0000 Subject: Is it technically possible to give Python option of naming process of running script? In-Reply-To: References: <19118128.4791.1331736187952.JavaMail.geo-discussion-forums@vbai14> Message-ID: <5B80DD153D7D744689F57F4FB69AF474026A27FC@SBECMX008.exchad.jpmchase.net> > > It seems like an excellent thing to add to the "os" module. > > If 'prctl' is a standard POSIX system call, then it should be a > candidate for inclusion in the os module if someone opens a tracker > enhancement issue and presents an argument in favor. I think this request was already denied: http://bugs.python.org/issue5672 Ramit Ramit Prasad | JPMorgan Chase Investment Bank | Currencies Technology 712 Main Street | Houston, TX 77002 work phone: 713 - 216 - 5423 -- This email is confidential and subject to important disclaimers and conditions including on offers for the purchase or sale of securities, accuracy and completeness of information, viruses, confidentiality, legal privilege, and legal entity disclaimers, available at http://www.jpmorgan.com/pages/disclosures/email. From python at mrabarnett.plus.com Wed Mar 14 13:26:19 2012 From: python at mrabarnett.plus.com (MRAB) Date: Wed, 14 Mar 2012 17:26:19 +0000 Subject: Enchancement suggestion for argparse: intuit type from default In-Reply-To: References: <87zkbkgp67.fsf@benfinney.id.au> <4f6094c5$0$29972$c3e8da3$5496439d@news.astraweb.com> <87399bgw18.fsf@benfinney.id.au> Message-ID: <4F60D4BB.9000803@mrabarnett.plus.com> On 14/03/2012 13:30, Roy Smith wrote: > In article<87399bgw18.fsf at benfinney.id.au>, > Ben Finney wrote: > >> Right. I dislike proposals for run-time type inference in Python, since >> they are too magical. >> >> Especially since we're talking about user input (arguments from the >> command line to the program); that requires more explicit declarations >> and checking, not less. >> >> > What if you want an argument --foo that will accept arbitrary types? Then >> > you would need some way to tell argparse not to infer the type from the >> > default. >> >> So we would then need to special-case the special-case? Even more reason >> to dislike this proposal. >> >> > Explicit declarations should be used only for the uncommon cases where >> > type inference cannot cope. >> >> That's our point of disagreement, then: I think explicit declarations >> should be required regarding user input. > > I wasn't suggesting that the type be inferred from what the user > entered. I was suggesting it be inferred from what the programmer had > done (i.e. what value they had given the 'default' parameter). > In other words, if there's a default but no explicit type, then the type is the type of the default. > It's already inferred that the type is a string if you don't give it any > value. What possible meaning could: > > parser.add_argument('--foo', default=100) > > have? If I run the program with: > > $ prog > > then foo defaults to the integer 100, but if I run it with: > > $ prog --foo=100 > > then I get the string "100"? Surely there's not much of a use case for > that. From ramit.prasad at jpmorgan.com Wed Mar 14 13:27:10 2012 From: ramit.prasad at jpmorgan.com (Prasad, Ramit) Date: Wed, 14 Mar 2012 17:27:10 +0000 Subject: Is it technically possible to give Python option of naming process of running script? In-Reply-To: <5B80DD153D7D744689F57F4FB69AF474026A27FC@SBECMX008.exchad.jpmchase.net> References: <19118128.4791.1331736187952.JavaMail.geo-discussion-forums@vbai14> <5B80DD153D7D744689F57F4FB69AF474026A27FC@SBECMX008.exchad.jpmchase.net> Message-ID: <5B80DD153D7D744689F57F4FB69AF474026A280E@SBECMX008.exchad.jpmchase.net> > > > It seems like an excellent thing to add to the "os" module. > > > > If 'prctl' is a standard POSIX system call, then it should be a > > candidate for inclusion in the os module if someone opens a tracker > > enhancement issue and presents an argument in favor. > > > I think this request was already denied: http://bugs.python.org/issue5672 Also take a look at: https://github.com/dvarrazzo/py-setproctitle Though since they just create a Named Object in Windows, I am not sure it would work for something like killall. Ramit Ramit Prasad | JPMorgan Chase Investment Bank | Currencies Technology 712 Main Street | Houston, TX 77002 work phone: 713 - 216 - 5423 -- This email is confidential and subject to important disclaimers and conditions including on offers for the purchase or sale of securities, accuracy and completeness of information, viruses, confidentiality, legal privilege, and legal entity disclaimers, available at http://www.jpmorgan.com/pages/disclosures/email. From alain at dpt-info.u-strasbg.fr Wed Mar 14 13:34:34 2012 From: alain at dpt-info.u-strasbg.fr (Alain Ketterlin) Date: Wed, 14 Mar 2012 18:34:34 +0100 Subject: Is it technically possible to give Python option of naming process of running script? References: <19118128.4791.1331736187952.JavaMail.geo-discussion-forums@vbai14> Message-ID: <87zkbjgk7p.fsf@dpt-info.u-strasbg.fr> Terry Reedy writes: > On 3/14/2012 12:02 PM, Grant Edwards wrote: > >> It seems like an excellent thing to add to the "os" module. > > If 'prctl' is a standard POSIX system call, then it should be a > candidate for inclusion in the os module if someone opens a tracker > enhancement issue and presents an argument in favor. It's not. The man page says "This call is Linux-specific." -- Alain. From mabhanisi.blues at gmail.com Wed Mar 14 14:03:28 2012 From: mabhanisi.blues at gmail.com (mabhanisi blues) Date: Wed, 14 Mar 2012 11:03:28 -0700 (PDT) Subject: blues Message-ID: <6fd5c5e4-5a5e-404a-ac61-255a2ca9e970@i18g2000vbx.googlegroups.com> Can i come in am i welcome From python.list at tim.thechases.com Wed Mar 14 14:13:12 2012 From: python.list at tim.thechases.com (Tim Chase) Date: Wed, 14 Mar 2012 13:13:12 -0500 Subject: Is there a ConfigParser which keeps comments In-Reply-To: References: Message-ID: <4F60DFB8.8080703@tim.thechases.com> On 03/14/12 12:06, Terry Reedy wrote: > On 3/14/2012 6:07 AM, Gelonida N wrote: >> Now I'm looking for a library, which behaves like config parser, but >> with one minor difference. >> >> The write() mehtod should keep existing comments. > > Assuming that you have not overlooked anything, I would just subclass > ConfigParser with an altered write method. It would require a lot more than that. It would entail changing the reading as well so that it preserved the comments as well as the order of sections & keys, and a way of storing those associated comments in sequence. I looked into it a fair while back and it was a LOT more work than I cared to do for minimal gain. I wimped out and just documented it with "If you use the ability to (re)write a configuration file, it will not keep any comments or ordering from any original sources." -tkc From darrel343 at gmail.com Wed Mar 14 14:41:27 2012 From: darrel343 at gmail.com (Darrel Grant) Date: Wed, 14 Mar 2012 11:41:27 -0700 Subject: Global join function? Message-ID: In the virtualenv example bootstrap code, a global join function is used. http://pypi.python.org/pypi/virtualenv subprocess.call([join(home_dir, 'bin', 'easy_install'), 'BlogApplication']) In interpeter, I tried this: >>> [join([], 'bin', 'easy_install')] Traceback (most recent call last): File "", line 1, in NameError: name 'join' is not defined I think I've seen this used elsewhere, but googling only seems to show results about the string method join, not whatever this is. To be clear, I understand how to use "".join(list), but have not found any information about this other, seemingly global, join function which takes multiple arguments. It's been bugging me. From joncle at googlemail.com Wed Mar 14 14:52:50 2012 From: joncle at googlemail.com (Jon Clements) Date: Wed, 14 Mar 2012 11:52:50 -0700 (PDT) Subject: Global join function? In-Reply-To: References: Message-ID: <9936996.807.1331751170123.JavaMail.geo-discussion-forums@vbyl20> On Wednesday, 14 March 2012 18:41:27 UTC, Darrel Grant wrote: > In the virtualenv example bootstrap code, a global join function is used. > > http://pypi.python.org/pypi/virtualenv > > subprocess.call([join(home_dir, 'bin', 'easy_install'), > 'BlogApplication']) > > > In interpeter, I tried this: > > >>> [join([], 'bin', 'easy_install')] > Traceback (most recent call last): > File "", line 1, in > NameError: name 'join' is not defined > > I think I've seen this used elsewhere, but googling only seems to show > results about the string method join, not whatever this is. > > To be clear, I understand how to use "".join(list), but have not found > any information about this other, seemingly global, join function > which takes multiple arguments. It's been bugging me. os.path.join Jon From joncle at googlemail.com Wed Mar 14 14:52:50 2012 From: joncle at googlemail.com (Jon Clements) Date: Wed, 14 Mar 2012 11:52:50 -0700 (PDT) Subject: Global join function? In-Reply-To: References: Message-ID: <9936996.807.1331751170123.JavaMail.geo-discussion-forums@vbyl20> On Wednesday, 14 March 2012 18:41:27 UTC, Darrel Grant wrote: > In the virtualenv example bootstrap code, a global join function is used. > > http://pypi.python.org/pypi/virtualenv > > subprocess.call([join(home_dir, 'bin', 'easy_install'), > 'BlogApplication']) > > > In interpeter, I tried this: > > >>> [join([], 'bin', 'easy_install')] > Traceback (most recent call last): > File "", line 1, in > NameError: name 'join' is not defined > > I think I've seen this used elsewhere, but googling only seems to show > results about the string method join, not whatever this is. > > To be clear, I understand how to use "".join(list), but have not found > any information about this other, seemingly global, join function > which takes multiple arguments. It's been bugging me. os.path.join Jon From clp2 at rebertia.com Wed Mar 14 14:54:32 2012 From: clp2 at rebertia.com (Chris Rebert) Date: Wed, 14 Mar 2012 11:54:32 -0700 Subject: Global join function? In-Reply-To: References: Message-ID: On Wed, Mar 14, 2012 at 11:41 AM, Darrel Grant wrote: > In the virtualenv example bootstrap code, a global join function is used. > > http://pypi.python.org/pypi/virtualenv > > ? ?subprocess.call([join(home_dir, 'bin', 'easy_install'), > ? ? ? ? ? ? ? ? ? ? 'BlogApplication']) > > > In interpeter, I tried this: > >>>> [join([], 'bin', 'easy_install')] > Traceback (most recent call last): > ?File "", line 1, in > NameError: name 'join' is not defined > > I think I've seen this used elsewhere, but googling only seems to show > results about the string method join, not whatever this is. Those example snippets are broken. They're presumably missing the line: from os.path import join Docs for the function in question: http://docs.python.org/library/os.path.html#os.path.join Cheers, Chris From __peter__ at web.de Wed Mar 14 14:59:03 2012 From: __peter__ at web.de (Peter Otten) Date: Wed, 14 Mar 2012 19:59:03 +0100 Subject: Global join function? References: Message-ID: Darrel Grant wrote: > In the virtualenv example bootstrap code, a global join function is used. > > http://pypi.python.org/pypi/virtualenv At this point there is probably an import that you have overlooked: from os.path import join > subprocess.call([join(home_dir, 'bin', 'easy_install'), > 'BlogApplication']) > > > In interpeter, I tried this: > >>>> [join([], 'bin', 'easy_install')] > Traceback (most recent call last): > File "", line 1, in > NameError: name 'join' is not defined > > I think I've seen this used elsewhere, but googling only seems to show > results about the string method join, not whatever this is. > > To be clear, I understand how to use "".join(list), but have not found > any information about this other, seemingly global, join function > which takes multiple arguments. It's been bugging me. From ian.g.kelly at gmail.com Wed Mar 14 15:03:28 2012 From: ian.g.kelly at gmail.com (Ian Kelly) Date: Wed, 14 Mar 2012 13:03:28 -0600 Subject: Enchancement suggestion for argparse: intuit type from default In-Reply-To: References: <87zkbkgp67.fsf@benfinney.id.au> <4f6094c5$0$29972$c3e8da3$5496439d@news.astraweb.com> <87399bgw18.fsf@benfinney.id.au> Message-ID: On Wed, Mar 14, 2012 at 7:30 AM, Roy Smith wrote: > It's already inferred that the type is a string if you don't give it any > value. ?What possible meaning could: > > parser.add_argument('--foo', default=100) > > have? ?If I run the program with: > > $ prog > > then foo defaults to the integer 100, but if I run it with: > > $ prog --foo=100 > > then I get the string "100"? ?Surely there's not much of a use case for > that. What about: parser.add_argument('--foo', default=None) Probably it should not infer NoneType as the argument type in this case. So would it just ignore the default in this case and let the type remain str? Also, how would the inference interact with different actions? For example: parser.add_argument('--foo', action='append', default=['one']) I'm not exactly sure what a use case for this might be, but anyway, the type here should clearly be str, not list. And then what about this variation: parser.add_argument('--foo', action='append', default=[1]) Should it try to infer that because the list contains an int, the type should be int? And even if you manage to get the inference working flawlessly and expectedly for append, what about custom actions? It seems to me that there are a large number of edge cases here that will end up hurting predictability for the end user. Cheers, Ian From michael at stroeder.com Wed Mar 14 15:57:48 2012 From: michael at stroeder.com (=?ISO-8859-1?Q?Michael_Str=F6der?=) Date: Wed, 14 Mar 2012 20:57:48 +0100 Subject: ANN: python-ldap 2.4.9 Message-ID: Find a new release of python-ldap: http://pypi.python.org/pypi/python-ldap/2.4.8 python-ldap provides an object-oriented API to access LDAP directory servers from Python programs. It mainly wraps the OpenLDAP 2.x libs for that purpose. Additionally it contains modules for other LDAP-related stuff (e.g. processing LDIF, LDAPURLs and LDAPv3 schema). Project's web site: http://www.python-ldap.org/ Ciao, Michael. ---------------------------------------------------------------- Released 2.4.9 2012-03-14 Changes since 2.4.8: Lib/ * ldapobject.ReconnectLDAPObject.reconnect() now does kind of an internal locking to pause other threads while reconnecting is pending. * Changes to bind- and startTLS-related operation methods of class ReconnectLDAPObject for more robustness * New constant ldap.OPT_NAMES_DICT contains mapping from integer to variable name for all option-related constants. From croepha at gmail.com Wed Mar 14 16:37:12 2012 From: croepha at gmail.com (Croepha) Date: Wed, 14 Mar 2012 14:37:12 -0600 Subject: Style question (Poll) Message-ID: Which is preferred: for value in list: if not value is another_value: value.do_something() break --or-- if list and not list[0] is another_value: list[0].do_something() Comments are welcome, Thanks -------------- next part -------------- An HTML attachment was scrubbed... URL: From arnodel at gmail.com Wed Mar 14 16:49:02 2012 From: arnodel at gmail.com (Arnaud Delobelle) Date: Wed, 14 Mar 2012 20:49:02 +0000 Subject: Style question (Poll) In-Reply-To: References: Message-ID: On 14 March 2012 20:37, Croepha wrote: > Which is?preferred: > > for value in list: > ?if not value is another_value: > ? ?value.do_something() > ? ?break > > --or-- > > if list and not list[0] is another_value: > ?list[0].do_something() Hard to say, since they don't do the same thing :) I suspect you meant: for value in list: ? if not value is another_value: ? ? value.do_something() ?break I always feel uncomfortable with this because it's misleading: a loop that never loops. -- Arnaud From sorsorday at gmail.com Wed Mar 14 16:53:27 2012 From: sorsorday at gmail.com (Herman) Date: Wed, 14 Mar 2012 13:53:27 -0700 Subject: How to break long method name into more than one line? Message-ID: I followed the rule because it was a very good advice. For example, def test_plus_1Plus1_2(self): If this test fails, you immediately know that it's testing the "plus" method, with 1 and 1 as the arguments, and expect to return 2. Sticking this rule also means your test cases are small enough, so you clearly know what you are testing on. Most of the time, the method name is what you first see when your test fails. Another alternative is to put meaningful string in each of the assert, which is probably not practical. You are right, only people who really follow the TDD method know the good things about it. This naming rule served me very well. Tests method should have meaningful name, and the advice by the book is a meaningful one. I said it's the TDD book because I forgot the exact title. It's actually called Test Driven: TDD and Acceptance TDD for Java Developers. I thought it should be popular enough that most people learned TDD may have heard it also used this naming advice, but look like i was wrong. > *The* TDD book? There's only one? Surely not. > > That rule sounds utterly impractical. I can't think of anything to > recommend it. Like any other function, method or class, tests should have > meaningful names, but reading the name alone should not necessarily tell > you *everything* about the function. > > We have "len", not "len_sequence_or_mapping_int", and similarly it is > perfectly reasonable to have "test_len_empty" rather than > "test_len_emptylist_emptystr_emptyunicode_emptydict_emptyset_emptytuple_zero". > > I expect that naming rule was invented by either people who have heard of > test driven development, but never actually done it, or by people so > anally-retentive that if they make seven short car trips over an hour, > they check the tyre pressure, oil and water seven times because "the > manual says to check before *every* trip". > > No offence. > > My advice is to moderate the naming convention of your tests with a good > dose of common sense and aim for names which are readable rather than > names that contain everything including the kitchen sink. Imagine you are > in a technical meeting with some of your fellow programmers, and need to > ask for help with a failing test. Imagine saying the name of the test > aloud in a sentence. Does it add clarity to the discussion, or obfuscate > it? > > People's short term memory can only hold so much (allegedly "seven plus > or minus two"), and if the name itself hits that limit, you leave nothing > left for the rest of the sentence. > > http://en.wikipedia.org/wiki/The_Magical_Number_Seven,_Plus_or_Minus_Two > > Names should be practically, rather than conforming to some naming rule > that hurts readability and obfuscates the tests. > > From tjreedy at udel.edu Wed Mar 14 17:16:05 2012 From: tjreedy at udel.edu (Terry Reedy) Date: Wed, 14 Mar 2012 17:16:05 -0400 Subject: Style question (Poll) In-Reply-To: References: Message-ID: On 3/14/2012 4:49 PM, Arnaud Delobelle wrote: > On 14 March 2012 20:37, Croepha wrote: >> Which is preferred: >> >> for value in list: >> if not value is another_value: >> value.do_something() >> break Do you really mean 'is' or '=='? If you mean x is not y, write it that way. 'not x is y' can be misread and misunderstood, depending on whether the 'is' is true or not. >>> not 1 is 1 False >>> not (1 is 1) False >>> (not 1) is 1 False Does not matter how read. >>> not (1 is 0) True >>> (not 1) is 0 False >>> not 1 is 0 True Does matter how read. >> if list and not list[0] is another_value: >> list[0].do_something() Or try: value = mylist[0] if value is not another_value: value.dosomething except IndexError: pass I would not do this in this case of index 0, but if the index were a complicated expression or expensive function call, making 'if list' an inadequate test, I might. > Hard to say, since they don't do the same thing :) > > I suspect you meant: > > for value in list: > if not value is another_value: > value.do_something() > break > > I always feel uncomfortable with this because it's misleading: a loop > that never loops. I agree. Please do not do this in public ;-). -- Terry Jan Reedy From ben+python at benfinney.id.au Wed Mar 14 17:26:22 2012 From: ben+python at benfinney.id.au (Ben Finney) Date: Thu, 15 Mar 2012 08:26:22 +1100 Subject: How to decide if a object is instancemethod? References: <8815977.3878.1331731738209.JavaMail.geo-discussion-forums@vbux23> <389400.5582.1331733455084.JavaMail.geo-discussion-forums@vbiz13> Message-ID: <87ty1qg9hd.fsf@benfinney.id.au> Jon Clements writes: > import inspect > if inspect.ismethod(foo): > # ... > > Will return True if foo is a bound method. But under what other conditions will it return True? The name suggests that *any* method ? static method, class method, bound method, unbound method ? will also result in True. The documentation says only ?instance method?, though. Confusing :-( -- \ ?Airports are ugly. Some are very ugly. Some attain a degree of | `\ ugliness that can only be the result of a special effort.? | _o__) ?Douglas Adams, _The Long Dark Tea-Time Of The Soul_ | Ben Finney From tjreedy at udel.edu Wed Mar 14 17:40:54 2012 From: tjreedy at udel.edu (Terry Reedy) Date: Wed, 14 Mar 2012 17:40:54 -0400 Subject: How to break long method name into more than one line? In-Reply-To: References: Message-ID: On 3/14/2012 4:53 PM, Herman wrote: > I followed the rule because it was a very good advice. For example, > def test_plus_1Plus1_2(self): Suppose you want to test that a function call returns a particular 300-char multiline string? > If this test fails, you immediately know that it's testing the "plus" > method, with 1 and 1 as the arguments, and expect to return 2. If you use unittest and the right assert method, the message will say more than pass/fail. I believe .AssertEqual(a,b, 'optional message') will say that a is not equal to b, and print the optional message. "In addition, if first and second are the exact same type and one of list, tuple, dict, set, frozenset or str or any type that a subclass registers with addTypeEqualityFunc() the type-specific equality function will be called in order to generate a more useful default error message (see also the list of type-specific methods)." For instance "assertMultiLineEqual(first, second, msg=None) Test that the multiline string first is equal to the string second. When not equal a diff of the two strings highlighting the differences will be included in the error message. This method is used by default when comparing strings with assertEqual()." > Sticking this rule also means your test cases are small enough, To me, it makes them too small. I think a test of addition should have multiple input-output pairs. Besides that, a single test output object may need to pass multiple conditions to pass. Putting them all in a single large conjuction would obscure which is not passing. However, anything is better than no tests. -- Terry Jan Reedy From ramit.prasad at jpmorgan.com Wed Mar 14 18:15:38 2012 From: ramit.prasad at jpmorgan.com (Prasad, Ramit) Date: Wed, 14 Mar 2012 22:15:38 +0000 Subject: Style question (Poll) In-Reply-To: References: Message-ID: <5B80DD153D7D744689F57F4FB69AF474026A5ECE@SBECMX008.exchad.jpmchase.net> > >> Which is preferred: > >> > >> for value in list: > >> if not value is another_value: > >> value.do_something() > >> break > > Do you really mean 'is' or '=='? Let me expound on how 'is' and '==' are very different. It may work for some comparisons but often not for others. Certain examples work because of the Python implementation. >>> c = 1 >>> d = 1 >>> c is d # This only works because CPython caches small values. True >>> c == d True >>> a = 10000000000000 >>> b = 10000000000000 >>> a is b False >>> a == b True >>> 10000000000000 is 10000000000000 True '10000000000000 is 10000000000000' works because the interpreter caches the number because it is on the same line. Only use 'is' if you are looking for objects like True, False, None or something that MUST be exactly the same object. In general, use '=='. Ramit Ramit Prasad | JPMorgan Chase Investment Bank | Currencies Technology 712 Main Street | Houston, TX 77002 work phone: 713 - 216 - 5423 -- This email is confidential and subject to important disclaimers and conditions including on offers for the purchase or sale of securities, accuracy and completeness of information, viruses, confidentiality, legal privilege, and legal entity disclaimers, available at http://www.jpmorgan.com/pages/disclosures/email. From arnodel at gmail.com Wed Mar 14 18:30:01 2012 From: arnodel at gmail.com (Arnaud Delobelle) Date: Wed, 14 Mar 2012 22:30:01 +0000 Subject: Style question (Poll) In-Reply-To: <5B80DD153D7D744689F57F4FB69AF474026A5ECE@SBECMX008.exchad.jpmchase.net> References: <5B80DD153D7D744689F57F4FB69AF474026A5ECE@SBECMX008.exchad.jpmchase.net> Message-ID: On 14 March 2012 22:15, Prasad, Ramit wrote: > Only use 'is' if you are looking for objects like True, > False, None or something that MUST be exactly the same object. I've rarely seen valid uses of 'is True' or 'is False'. -- Arnaud From ramit.prasad at jpmorgan.com Wed Mar 14 19:08:17 2012 From: ramit.prasad at jpmorgan.com (Prasad, Ramit) Date: Wed, 14 Mar 2012 23:08:17 +0000 Subject: Style question (Poll) In-Reply-To: References: <5B80DD153D7D744689F57F4FB69AF474026A5ECE@SBECMX008.exchad.jpmchase.net> Message-ID: <5B80DD153D7D744689F57F4FB69AF474026A5FC8@SBECMX008.exchad.jpmchase.net> > > Only use 'is' if you are looking for objects like True, > > False, None or something that MUST be exactly the same object. > > I've rarely seen valid uses of 'is True' or 'is False'. It can be useful when you think something might be None or False. Although, I suppose you could always just use 'is None' instead. >>> 1 == True True >>> 1 is True False >>> 0 == False True >>> 0 is False False Granted, the above example is a pretty facetious case; not sure I can come up with a reasonably real world use case. Ramit Ramit Prasad | JPMorgan Chase Investment Bank | Currencies Technology 712 Main Street | Houston, TX 77002 work phone: 713 - 216 - 5423 -- This email is confidential and subject to important disclaimers and conditions including on offers for the purchase or sale of securities, accuracy and completeness of information, viruses, confidentiality, legal privilege, and legal entity disclaimers, available at http://www.jpmorgan.com/pages/disclosures/email. From steve+comp.lang.python at pearwood.info Wed Mar 14 19:30:27 2012 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 14 Mar 2012 23:30:27 GMT Subject: How to decide if a object is instancemethod? References: <8815977.3878.1331731738209.JavaMail.geo-discussion-forums@vbux23> <389400.5582.1331733455084.JavaMail.geo-discussion-forums@vbiz13> <87ty1qg9hd.fsf@benfinney.id.au> Message-ID: <4f612a12$0$29981$c3e8da3$5496439d@news.astraweb.com> On Thu, 15 Mar 2012 08:26:22 +1100, Ben Finney wrote: > Jon Clements writes: > >> import inspect >> if inspect.ismethod(foo): >> # ... >> >> Will return True if foo is a bound method. > > But under what other conditions will it return True? The name suggests > that *any* method ? static method, class method, bound method, unbound > method ? will also result in True. > > The documentation says only ?instance method?, though. Confusing :-( Bound and unbound methods are instance methods. To be precise, the "method" in "(un)bound method" stands for instance method, and the difference between the two in Python 2.x is a flag on the method object. (Unbound methods are gone in Python 3.) Class and static methods are not instance methods. I suppose it is conceivable that you could have an unbound class method in theory, but I can't see any way to actually get one in practice. In Python, and probably most languages, a bare, unadorned "method" is implied to be an instance method; "instance method" is (possibly) a retronym to distinguish them from other, newer(?), types of method. http://en.wikipedia.org/wiki/Retronym -- Steven From nagle at animats.com Wed Mar 14 19:32:41 2012 From: nagle at animats.com (John Nagle) Date: Wed, 14 Mar 2012 16:32:41 -0700 Subject: Enchancement suggestion for argparse: intuit type from default In-Reply-To: References: Message-ID: <4f612a9d$0$12033$742ec2ed@news.sonic.net> On 3/13/2012 2:08 PM, Roy Smith wrote: > Using argparse, if I write: > > parser.add_argument('--foo', default=100) > > it seems like it should be able to intuit that the type of foo should > be int (i.e. type(default)) without my having to write: > > parser.add_argument('--foo', type=int, default=100) > > Does this seem like a reasonable enhancement to argparse? default=None presents some problems. John Nagle From kiuhnm03.4t.yahoo.it Wed Mar 14 19:34:47 2012 From: kiuhnm03.4t.yahoo.it (Kiuhnm) Date: Thu, 15 Mar 2012 00:34:47 +0100 Subject: Python is readable Message-ID: <4f612b19$0$1379$4fafbaef@reader2.news.tin.it> I've just started to read The Quick Python Book (2nd ed.) The author claims that Python code is more readable than Perl code and provides this example: --- Perl --- sub pairwise_sum { my($arg1, $arg2) = @_; my(@result) = (); @list1 = @$arg1; @list2 = @$arg2; for($i=0; $i < length(@list1); $i++) { push(@result, $list1[$i] + $list2[$i]); } return(\@result); } --- Python --- def pairwise_sum(list1, list2): result = [] for i in range(len(list1)): result.append(list1[i] + list2[i]) return result --- --- It's quite clear that he knows little about Perl. Here's what I would've written: sub pairwise_sum { my ($list1, $list2) = @_; my @result; push @result, $list1->[$_] + $list2->[$_] for (0..@$list1-1); \@result; } Having said that, the Python code is still more readable, so there's no need to misrepresent Perl that way. Now I'm wondering whether the author will show me "good" or "bad" Python code throughout the book. Should I keep reading? Kiuhnm From arnodel at gmail.com Wed Mar 14 19:54:31 2012 From: arnodel at gmail.com (Arnaud Delobelle) Date: Wed, 14 Mar 2012 23:54:31 +0000 Subject: Python is readable In-Reply-To: <4f612b19$0$1379$4fafbaef@reader2.news.tin.it> References: <4f612b19$0$1379$4fafbaef@reader2.news.tin.it> Message-ID: On 14 March 2012 23:34, Kiuhnm wrote: > I've just started to read > ?The Quick Python Book (2nd ed.) > The author claims that Python code is more readable than Perl code and > provides this example: > > --- Perl --- > sub pairwise_sum { > ? ?my($arg1, $arg2) = @_; > ? ?my(@result) = (); > ? ?@list1 = @$arg1; > ? ?@list2 = @$arg2; > ? ?for($i=0; $i < length(@list1); $i++) { > ? ? ? ?push(@result, $list1[$i] + $list2[$i]); > ? ?} > ? ?return(\@result); > } > > --- Python --- > def pairwise_sum(list1, list2): > ? ?result = [] > ? ?for i in range(len(list1)): > ? ? ? ?result.append(list1[i] + list2[i]) > ? ?return result > --- --- > > It's quite clear that he knows little about Perl. > Here's what I would've written: > > sub pairwise_sum { > ? ?my ($list1, $list2) = @_; > ? ?my @result; > ? ?push @result, $list1->[$_] + $list2->[$_] for (0..@$list1-1); > ? ?\@result; > } > > Having said that, the Python code is still more readable, so there's no need > to misrepresent Perl that way. > Now I'm wondering whether the author will show me "good" or "bad" Python > code throughout the book. Should I keep reading? I don't know this book and there may be a pedagogical reason for the implementation you quote, but pairwise_sum is probably better implemented in Python 3.X as: def pairwise_sum(list1, list2): return [x1 + x2 for x1, x2 in zip(list1, list2)] Or in Python 2.X: from itertools import izip def pairwise_sum(list1, list2): return [x1 + x2 for x1, x2 in izip(list1, list2)] Or even: from operator import add def pairwise_sum(list1, list2): return map(add, list1, list2) -- Arnaud From steve+comp.lang.python at pearwood.info Wed Mar 14 20:07:52 2012 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 15 Mar 2012 00:07:52 GMT Subject: How to break long method name into more than one line? References: Message-ID: <4f6132d8$0$29981$c3e8da3$5496439d@news.astraweb.com> On Wed, 14 Mar 2012 13:53:27 -0700, Herman wrote: > I followed the rule because it was a very good advice. For example, def > test_plus_1Plus1_2(self): > If this test fails, you immediately know that it's testing the "plus" > method, with 1 and 1 as the arguments, and expect to return 2. That is hardly a representative example, or you would not be asking for advice on splitting long method names over multiple lines. A more relevant example might be def test_alongmethodname_someargument_YouRepeatTheMethodNameForSomeReason_anotherargument_someresult (self): For utterly trivial examples such as testing that 1+1 == 2 nearly any naming scheme would be suitable. But for realistic test cases, the rule fails utterly. Here is a real test case from one of my own projects: I have a project that defines dozens of related statistical functions, with hundreds of tests. Here is one test class for one function, the population variance (pvariance): class PVarianceTest(NumericTestCase, UnivariateMixin): # Test population variance. # This will be subclassed by variance and [p]stdev. tol = 1e-11 def __init__(self, *args, **kwargs): super().__init__(*args, **kwargs) self.func = calcstats.pvariance # Test data for test_main, test_shift: self.data = [4.0, 7.0, 13.0, 16.0] self.expected = 22.5 # Exact population variance of self.data. # If you duplicate each data point, the variance will scale by # this value: self.dup_scale_factor = 1.0 def setUp(self): random.shuffle(self.data) def get_allowed_kinds(self): kinds = super().get_allowed_kinds() return [kind for kind in kinds if hasattr(kind, '__len__')] def test_main(self): # Test that pvariance calculates the correct result. self.assertEqual(self.func(self.data), self.expected) def test_shift(self): # Shifting the data by a constant amount should not affect # the variance. for shift in (1e2, 1e6, 1e9): data = [x + shift for x in self.data] self.assertEqual(self.func(data), self.expected) def test_equal_data(self): # If the data is constant, the variance should be zero. self.assertEqual(self.func([42]*10), 0) def testDuplicate(self): # Test that the variance behaves as expected when you duplicate # each data point [a,b,c,...] -> [a,a,b,b,c,c,...] data = [random.uniform(-100, 500) for _ in range(20)] expected = self.func(data)*self.dup_scale_factor actual = self.func(data*2) self.assertApproxEqual(actual, expected) def testDomainError(self): # Domain error exception reported by Geremy Condra. data = [0.123456789012345]*10000 # All the items are identical, so variance should be exactly zero. # We allow some small round-off error. self.assertApproxEqual(self.func(data), 0.0, tol=5e-17) def testSingleton(self): # Population variance of a single value is always zero. for x in self.data: self.assertEqual(self.func([x]), 0) def testMeanArgument(self): # Variance calculated with the given mean should be the same # as that calculated without the mean. data = [random.random() for _ in range(15)] m = calcstats.mean(data) expected = self.func(data, m=None) self.assertEqual(self.func(data, m=m), expected) (I'm a little inconsistent when choosing between camelCase and under_score names in my tests. My bad.) Even with the limited examples shown there, the naming convention you give is utterly impractical. Most of the inputs are random (e.g. testDuplicate uses 20 randomly selected integers) or implementation details (e.g. test_equal_data takes a list of ten 42s, and returns 0, but that could have been thirty-five 7s, or six 1.29345e-9s, or nearly any other value). Some of the tests don't even test a *specific* input and output, but compare that the variance of one set of data matches the variance of a different set of data. > Sticking > this rule also means your test cases are small enough, so you clearly > know what you are testing on. Sticking to this rule means that you are probably missing tests that don't fit into the simple "arguments -> result" framework, and compromising the quality test suite. If you only test the simple cases, you aren't testing the cases that are most likely to fail. -- Steven From rosuav at gmail.com Wed Mar 14 20:17:49 2012 From: rosuav at gmail.com (Chris Angelico) Date: Thu, 15 Mar 2012 11:17:49 +1100 Subject: Style question (Poll) In-Reply-To: References: Message-ID: On Thu, Mar 15, 2012 at 7:37 AM, Croepha wrote: > Which is?preferred: > > for value in list: > ?if not value is another_value: > ? ?value.do_something() > ? ?break > > --or-- > > if list and not list[0] is another_value: > ?list[0].do_something() > > Comments are welcome, Thanks General principle: Make the code look like what it's doing. I don't mean text art and making code in the shape of pi that prints the digits of pi (although that can be awesome too), but more that a loop should not be used when you don't intend for it to loop. Consider the For-Case Paradigm[1] and the amazing confusion value that it can offer. A loop needn't execute more than once (it needn't even execute the first time), but it should at least have the _potential_ to execute the same code multiple times, otherwise it's hardly a loop. I had a particularly nasty example of a loop-that-wasn't-a-loop at work a while ago; it was PHP, not Python, so I won't share it here, but it had a do-while loop and an insidious bug in it. Very tricky. ChrisA [1] http://thedailywtf.com/Articles/The_FOR-CASE_paradigm.aspx From rosuav at gmail.com Wed Mar 14 20:27:54 2012 From: rosuav at gmail.com (Chris Angelico) Date: Thu, 15 Mar 2012 11:27:54 +1100 Subject: Python is readable In-Reply-To: References: <4f612b19$0$1379$4fafbaef@reader2.news.tin.it> Message-ID: On Thu, Mar 15, 2012 at 10:54 AM, Arnaud Delobelle wrote: > I don't know this book and there may be a pedagogical reason for the > implementation you quote, but pairwise_sum is probably better > implemented in Python 3.X as: > > def pairwise_sum(list1, list2): > ? ?return [x1 + x2 for x1, x2 in zip(list1, list2)] Okay, here's something for debate. Should the readability of a language be gauged on the basis of its standard library, or should you be comparing actual code? For instance, a quine in C can be fairly complex and messy, and it can be unobvious what it's doing - but in HQ9+ it's easy. Is it fair to compare on that basis, or should you actually implement the same / equivalent code in each before judging? Of course, that's all without getting into the question of what does "readable" even mean. This has nothing to do with the eternal question of whether it's more readable to use verbose English keywords or cryptic symbols. ChrisA From roy at panix.com Wed Mar 14 20:52:23 2012 From: roy at panix.com (Roy Smith) Date: Wed, 14 Mar 2012 20:52:23 -0400 Subject: Enchancement suggestion for argparse: intuit type from default References: <4f612a9d$0$12033$742ec2ed@news.sonic.net> Message-ID: In article <4f612a9d$0$12033$742ec2ed at news.sonic.net>, John Nagle wrote: > On 3/13/2012 2:08 PM, Roy Smith wrote: > > Using argparse, if I write: > > > > parser.add_argument('--foo', default=100) > > > > it seems like it should be able to intuit that the type of foo should > > be int (i.e. type(default)) without my having to write: > > > > parser.add_argument('--foo', type=int, default=100) > > > > Does this seem like a reasonable enhancement to argparse? > > default=None > > presents some problems. I'll admit I hadn't considered that, but I don't see it as a major problem. The type intuition could be designed to only work for types other than NoneType. From ben+python at benfinney.id.au Wed Mar 14 21:22:13 2012 From: ben+python at benfinney.id.au (Ben Finney) Date: Thu, 15 Mar 2012 12:22:13 +1100 Subject: Enchancement suggestion for argparse: intuit type from default References: <4f612a9d$0$12033$742ec2ed@news.sonic.net> Message-ID: <87pqcefyka.fsf@benfinney.id.au> Roy Smith writes: > I'll admit I hadn't considered that, but I don't see it as a major > problem. The type intuition could be designed to only work for types > other than NoneType. ?1, then. It's growing too many special cases, and is no longer simple to describe, so that indicates it's probably a bad idea. -- \ ?[W]e are still the first generation of users, and for all that | `\ we may have invented the net, we still don't really get it.? | _o__) ?Douglas Adams | Ben Finney From python at mrabarnett.plus.com Wed Mar 14 22:10:11 2012 From: python at mrabarnett.plus.com (MRAB) Date: Thu, 15 Mar 2012 02:10:11 +0000 Subject: Enchancement suggestion for argparse: intuit type from default In-Reply-To: References: <4f612a9d$0$12033$742ec2ed@news.sonic.net> Message-ID: <4F614F83.7020300@mrabarnett.plus.com> On 15/03/2012 00:52, Roy Smith wrote: > In article<4f612a9d$0$12033$742ec2ed at news.sonic.net>, > John Nagle wrote: > >> On 3/13/2012 2:08 PM, Roy Smith wrote: >> > Using argparse, if I write: >> > >> > parser.add_argument('--foo', default=100) >> > >> > it seems like it should be able to intuit that the type of foo should >> > be int (i.e. type(default)) without my having to write: >> > >> > parser.add_argument('--foo', type=int, default=100) >> > >> > Does this seem like a reasonable enhancement to argparse? >> >> default=None >> >> presents some problems. > > I'll admit I hadn't considered that, but I don't see it as a major > problem. The type intuition could be designed to only work for types > other than NoneType. True, you could consider that a special case. If you really do want NoneType, or if the type doesn't otherwise match the default (or there's no default), then you can still be explicit. From d at davea.name Wed Mar 14 22:15:28 2012 From: d at davea.name (Dave Angel) Date: Wed, 14 Mar 2012 22:15:28 -0400 Subject: Is it technically possible to give Python option of naming process of running script? In-Reply-To: <5B80DD153D7D744689F57F4FB69AF474026A280E@SBECMX008.exchad.jpmchase.net> References: <19118128.4791.1331736187952.JavaMail.geo-discussion-forums@vbai14> <5B80DD153D7D744689F57F4FB69AF474026A27FC@SBECMX008.exchad.jpmchase.net> <5B80DD153D7D744689F57F4FB69AF474026A280E@SBECMX008.exchad.jpmchase.net> Message-ID: <4F6150C0.3000302@davea.name> On 03/14/2012 01:27 PM, Prasad, Ramit wrote: >>>> It seems like an excellent thing to add to the "os" module. >>> If 'prctl' is a standard POSIX system call, then it should be a >>> candidate for inclusion in the os module if someone opens a tracker >>> enhancement issue and presents an argument in favor. >> >> I think this request was already denied: http://bugs.python.org/issue5672 > Also take a look at: https://github.com/dvarrazzo/py-setproctitle > Though since they just create a Named Object in Windows, I am not sure > it would work for something like killall. > > There is/was a project called exemaker for Windows. (see Pypi for link). I don't use Windows any more, but it was a nice trick, when it worked. Not all python scripts could be wrapped in it, but basically it let you wrap a python script in a tiny Windows program which launched the usual python dll's. You could call it anything you liked, and that's what the task manager saw as the process name. -- DaveA From steveo at syslang.net Wed Mar 14 22:48:32 2012 From: steveo at syslang.net (Steven W. Orr) Date: Wed, 14 Mar 2012 22:48:32 -0400 Subject: Is there a ConfigParser which keeps comments In-Reply-To: References: Message-ID: <4F615880.6080005@syslang.net> On 3/14/2012 6:07 AM, Gelonida N wrote: > Hi, > > > At the moment I use ConfigParser > http://docs.python.org/library/configparser.html > for one of my applications. > > > Now I'm looking for a library, which behaves like config parser, but > with one minor difference. > > The write() mehtod should keep existing comments. > > Does anybody know or implement something like this or is there as > switrch, that I overlooked in hte documentaiton. > > I use ConfigObj. -- Time flies like the wind. Fruit flies like a banana. Stranger things have .0. happened but none stranger than this. Does your driver's license say Organ ..0 Donor?Black holes are where God divided by zero. Listen to me! We are all- 000 individuals! What if this weren't a hypothetical question? steveo at syslang.net From rantingrickjohnson at gmail.com Wed Mar 14 23:02:58 2012 From: rantingrickjohnson at gmail.com (Rick Johnson) Date: Wed, 14 Mar 2012 20:02:58 -0700 (PDT) Subject: Python is readable References: <4f612b19$0$1379$4fafbaef@reader2.news.tin.it> Message-ID: <8e72d74f-c844-4de3-8a37-f6b1fdc2291f@y27g2000yqy.googlegroups.com> On Mar 14, 7:27?pm, Chris Angelico wrote: > Okay, here's something for debate. > > Should the readability of a language be gauged on the basis of its > standard library, or should you be comparing actual code? I think the library matters greatly. Yes, one could argue that the same functionality "could" be wrapped-up in the competing language, but then, why has it not already been wrapped? When comparing say, "language A" (WITHOUT a built-in print function) and "Language B" (WITH a built-in print function), would you cry unfairness when B wielded the built-in? > [...] > Of course, that's all without getting into the question of what does > "readable" even mean. One could get caught in an infinite loop of the "Chicken and the Egg" paradox here. However, when we are talking about the Python programming language "readable" simply means: "neophyte readable". That is, "readable to someone with little or no experience with the language". I think that has always been Python's philosophy from the beginning (even all the way back to CP4E!). > This has nothing to do with the eternal question > of whether it's more readable to use verbose English keywords or > cryptic symbols. Again, for the case of Python, cryptic symbols are frowned upon. Of course for the "hacker", cryptic symbols can save keystrokes and white space -- but at the expense of "neophyte readability"! > ChrisA Thanks for reminding me of your name. I had almost forgotten who i replied to ;-) From cs at zip.com.au Thu Mar 15 01:59:08 2012 From: cs at zip.com.au (Cameron Simpson) Date: Thu, 15 Mar 2012 16:59:08 +1100 Subject: Enchancement suggestion for argparse: intuit type from default In-Reply-To: <87pqcefyka.fsf@benfinney.id.au> References: <87pqcefyka.fsf@benfinney.id.au> Message-ID: <20120315055908.GA8886@cskk.homeip.net> On 15Mar2012 12:22, Ben Finney wrote: | Roy Smith writes: | > I'll admit I hadn't considered that, but I don't see it as a major | > problem. The type intuition could be designed to only work for types | > other than NoneType. | | ?1, then. It's growing too many special cases, and is no longer simple | to describe, so that indicates it's probably a bad idea. If `type` is not supplied and `default` is present and not None, `type` shall be the type of `default`. That seems straightforward to me. It's a single sentence, easy to read and understand, and potentially saves a lot of code verbiage (gratuitous type= prarameters). I say "gratuitous" because unless `default` is a sentinel for "no option supplied", the `type` should always match type(default). Or am I wrong about that? Cheers, -- Cameron Simpson DoD#743 http://www.cskk.ezoshosting.com/cs/ You only live once in life, but if you do it right, once is enough! - Rob Castro From wuwei23 at gmail.com Thu Mar 15 02:23:30 2012 From: wuwei23 at gmail.com (alex23) Date: Wed, 14 Mar 2012 23:23:30 -0700 (PDT) Subject: Python is readable References: <4f612b19$0$1379$4fafbaef@reader2.news.tin.it> <8e72d74f-c844-4de3-8a37-f6b1fdc2291f@y27g2000yqy.googlegroups.com> Message-ID: <50e9ceec-40f1-4ead-b2b6-87328b30d084@ow8g2000pbc.googlegroups.com> Rick Johnson wrote: > However, when we are talking about the Python > programming language "readable" simply means: "neophyte readable". > That is, "readable to someone with little or no experience with the > language". Nonsense. List comprehensions are not immediately obvious to new Python users. The functionality of 'with' requires an understanding of context managers. Python's readability has more to do with simplifying code maintenance. The idea that Python code has to be obvious to non-programmers is an incorrect and dangerous one. From tymoteusz.jankowski at gmail.com Thu Mar 15 03:24:58 2012 From: tymoteusz.jankowski at gmail.com (xliiv) Date: Thu, 15 Mar 2012 00:24:58 -0700 (PDT) Subject: Is it technically possible to give Python option of naming process of running script? In-Reply-To: References: <19118128.4791.1331736187952.JavaMail.geo-discussion-forums@vbai14> Message-ID: <19923939.18.1331796298704.JavaMail.geo-discussion-forums@vbhz5> > >> Like the topic.. . > >> I use Python a lot, both Windows and Linux, and it's little weird to have many python process without fast distinction which is what. > > > > I've no idea if it's even possible on Windows. On Linux, what you want > > is the prctl function, which (AFAIK) isn't directly available. > > > > Google is your friend, though. Question's already been asked on Stack > > Overflow and such, and has a few answers. Nothing that looks > > cut-and-dried ready, but several that might work. > > The question of how to set the application name comes up somewhat > regularly. It would be awfully nice if there was a way for python > applications to set their application name. It's especially useful > for daemons, and makes it much easier when you can kill them by name > instead of having to look up the PID. > > It seems like an excellent thing to add to the "os" module. > > > Look for 'prctl' and 'PR_SET_NAME', which are the C-level function > > and constant that do the job; a cursory examination of PyPI shows a > > module with prctl in the name, so that may be of value. I did google, I've played with Exemaker (it works perfect, but not py3) and i've seen questions on Stackoverflow. The thing I mean is a build feature of python to give such a name. Not 3rd part or etc. like Grant Edwards said. Is it possible? From tymoteusz.jankowski at gmail.com Thu Mar 15 03:26:51 2012 From: tymoteusz.jankowski at gmail.com (xliiv) Date: Thu, 15 Mar 2012 00:26:51 -0700 (PDT) Subject: Is it technically possible to give Python option of naming process of running script? In-Reply-To: References: <19118128.4791.1331736187952.JavaMail.geo-discussion-forums@vbai14> Message-ID: <22071354.8904.1331796412001.JavaMail.geo-discussion-forums@vbkc1> > >> Like the topic.. . > >> I use Python a lot, both Windows and Linux, and it's little weird to have many python process without fast distinction which is what. > > > > I've no idea if it's even possible on Windows. On Linux, what you want > > is the prctl function, which (AFAIK) isn't directly available. > > > > Google is your friend, though. Question's already been asked on Stack > > Overflow and such, and has a few answers. Nothing that looks > > cut-and-dried ready, but several that might work. > > The question of how to set the application name comes up somewhat > regularly. It would be awfully nice if there was a way for python > applications to set their application name. It's especially useful > for daemons, and makes it much easier when you can kill them by name > instead of having to look up the PID. > > It seems like an excellent thing to add to the "os" module. > > > Look for 'prctl' and 'PR_SET_NAME', which are the C-level function > > and constant that do the job; a cursory examination of PyPI shows a > > module with prctl in the name, so that may be of value. I did google, I've played with Exemaker (it works perfect, but not py3) and i've seen questions on Stackoverflow. The thing I mean is a build feature of python to give such a name. Not 3rd part or etc. like Grant Edwards said. Is it possible? From arunpdasuit at gmail.com Thu Mar 15 04:19:26 2012 From: arunpdasuit at gmail.com (Arun p das) Date: Thu, 15 Mar 2012 13:49:26 +0530 Subject: pyserial for GPS data Message-ID: I have a USB GPS dongle using this for getting position information. I installed gpsd daemon so that any clients can read data from that. It is working fine used xgps, cgps as clients. *gpsd -n -N -D2 /dev/ttyUSB0 * import gps, os, time g = gps.gps(mode=gps.WATCH_NEWSTYLE) while 1: os.system('clear') g.poll() #if gps.PACKET_SET: g.stream() print 'latitude ' , g.fix.latitude print 'longitude ' , g.fix.longitude print 'time utc ' , g.utc,' + ', g.fix.time Used the following program to read gps data but it is not giving accurate readings as cgps,xgps clients. I tried to read directly from the serial port using the following program but its giving non printable characters as output as it should return something like $GPRMC,199304.973,3248.7780,N,11355.7832,W,1,06,02.2,25722.5,M,,,*00" *import serial* *ser = serial.Serial( port='/dev/ttyUSB0', baudrate=4800,timeout=1) * *while True:* * line=ser.read()* * print line,* *f.close()* -------------- next part -------------- An HTML attachment was scrubbed... URL: From robert.kern at gmail.com Thu Mar 15 06:06:48 2012 From: robert.kern at gmail.com (Robert Kern) Date: Thu, 15 Mar 2012 10:06:48 +0000 Subject: Enchancement suggestion for argparse: intuit type from default In-Reply-To: <20120315055908.GA8886@cskk.homeip.net> References: <87pqcefyka.fsf@benfinney.id.au> <20120315055908.GA8886@cskk.homeip.net> Message-ID: On 3/15/12 5:59 AM, Cameron Simpson wrote: > On 15Mar2012 12:22, Ben Finney wrote: > | Roy Smith writes: > |> I'll admit I hadn't considered that, but I don't see it as a major > |> problem. The type intuition could be designed to only work for types > |> other than NoneType. > | > | ?1, then. It's growing too many special cases, and is no longer simple > | to describe, so that indicates it's probably a bad idea. > > If `type` is not supplied and `default` is present and not None, `type` > shall be the type of `default`. > > That seems straightforward to me. It's a single sentence, easy to read > and understand, and potentially saves a lot of code verbiage (gratuitous > type= prarameters). I say "gratuitous" because unless `default` is a > sentinel for "no option supplied", the `type` should always match > type(default). Or am I wrong about that? Yes. Not all type(default) types can be called with a string to produce a valid value. Note that "type=" is really a misnomer. argparse doesn't really want a type object there; it wants a converter function that takes a string to an object. -- Robert Kern "I have come to believe that the whole world is an enigma, a harmless enigma that is made terrible by our own mad attempt to interpret it as though it had an underlying truth." -- Umberto Eco From cs at zip.com.au Thu Mar 15 06:35:03 2012 From: cs at zip.com.au (Cameron Simpson) Date: Thu, 15 Mar 2012 21:35:03 +1100 Subject: Enchancement suggestion for argparse: intuit type from default In-Reply-To: References: Message-ID: <20120315103503.GA1725@cskk.homeip.net> On 15Mar2012 10:06, Robert Kern wrote: | On 3/15/12 5:59 AM, Cameron Simpson wrote: | > On 15Mar2012 12:22, Ben Finney wrote: | > | Roy Smith writes: | > |> I'll admit I hadn't considered that, but I don't see it as a major | > |> problem. The type intuition could be designed to only work for types | > |> other than NoneType. | > | | > | ?1, then. It's growing too many special cases, and is no longer simple | > | to describe, so that indicates it's probably a bad idea. | > | > If `type` is not supplied and `default` is present and not None, `type` | > shall be the type of `default`. | > | > That seems straightforward to me. [... sentinels aside...] the `type` | > should always match type(default). Or am I wrong about that? | | Yes. Not all type(default) types can be called with a string to produce a valid | value. Note that "type=" is really a misnomer. argparse doesn't really want a | type object there; it wants a converter function that takes a string to an object. Aha. Still, you could change the docs to say you only need type= if type(default) _isn't_ useful as the string->value converter. -- Cameron Simpson DoD#743 http://www.cskk.ezoshosting.com/cs/ As your attorney, it is my duty to inform you that it is not important that you understand what I'm doing or why you're paying me so much money. What's important is that you continue to do so. - Hunter S. Thompson's Samoan Attorney From dmitrey15 at gmail.com Thu Mar 15 06:44:43 2012 From: dmitrey15 at gmail.com (dmitrey) Date: Thu, 15 Mar 2012 03:44:43 -0700 (PDT) Subject: new release 0.38 of OpenOpt, FuncDesigner, SpaceFuncs, DerApproximator Message-ID: Hi all, I'm glad to inform you about new release 0.38 (2012-March-15): OpenOpt: interalg can handle discrete variables interalg can handle multiobjective problems (MOP) interalg can handle problems with parameters fixedVars/freeVars Many interalg improvements and some bugfixes Add another EIG solver: numpy.linalg.eig New LLSP solver pymls with box bounds handling FuncDesigner: Some improvements for sum() Add funcs tanh, arctanh, arcsinh, arccosh Can solve EIG built from derivatives of several functions, obtained by automatic differentiation by FuncDesigner SpaceFuncs: Add method point.symmetry(Point|Line|Plane) Add method LineSegment.middle Add method Point.rotate(Center, angle) DerApproximator: Minor changes See http://openopt.org for more details Regards, D. From kiuhnm03.4t.yahoo.it Thu Mar 15 06:44:55 2012 From: kiuhnm03.4t.yahoo.it (Kiuhnm) Date: Thu, 15 Mar 2012 11:44:55 +0100 Subject: Python is readable In-Reply-To: <50e9ceec-40f1-4ead-b2b6-87328b30d084@ow8g2000pbc.googlegroups.com> References: <4f612b19$0$1379$4fafbaef@reader2.news.tin.it> <8e72d74f-c844-4de3-8a37-f6b1fdc2291f@y27g2000yqy.googlegroups.com> <50e9ceec-40f1-4ead-b2b6-87328b30d084@ow8g2000pbc.googlegroups.com> Message-ID: <4f61c828$0$1390$4fafbaef@reader2.news.tin.it> On 3/15/2012 7:23, alex23 wrote: > Rick Johnson wrote: >> However, when we are talking about the Python >> programming language "readable" simply means: "neophyte readable". >> That is, "readable to someone with little or no experience with the >> language". > > Nonsense. List comprehensions are not immediately obvious to new > Python users. The functionality of 'with' requires an understanding of > context managers. Python's readability has more to do with simplifying > code maintenance. Let's try that. Show me an example of "list comprehensions" and "with" (whatever they are). Kiuhnm From rosuav at gmail.com Thu Mar 15 06:50:59 2012 From: rosuav at gmail.com (Chris Angelico) Date: Thu, 15 Mar 2012 21:50:59 +1100 Subject: Python is readable In-Reply-To: <4f61c828$0$1390$4fafbaef@reader2.news.tin.it> References: <4f612b19$0$1379$4fafbaef@reader2.news.tin.it> <8e72d74f-c844-4de3-8a37-f6b1fdc2291f@y27g2000yqy.googlegroups.com> <50e9ceec-40f1-4ead-b2b6-87328b30d084@ow8g2000pbc.googlegroups.com> <4f61c828$0$1390$4fafbaef@reader2.news.tin.it> Message-ID: On Thu, Mar 15, 2012 at 9:44 PM, Kiuhnm wrote: > Let's try that. > Show me an example of "list comprehensions" and "with" (whatever they are). I'll do a list comp, because they lend themselves well to one-liners. what_am_i = '\n'.join(["%X\t%c"%(i,i) for i in range(128)]) Okay, that one also uses printf formatting, which may be a smidge obscure. Here's a simpler example: what_am_i = [x*x for x in range(11)] ChrisA From nutznetz-0c1b6768-bfa9-48d5-a470-7603bd3aa915 at spamschutz.glglgl.de Thu Mar 15 07:14:28 2012 From: nutznetz-0c1b6768-bfa9-48d5-a470-7603bd3aa915 at spamschutz.glglgl.de (Thomas Rachel) Date: Thu, 15 Mar 2012 12:14:28 +0100 Subject: Python is readable In-Reply-To: <4f61c828$0$1390$4fafbaef@reader2.news.tin.it> References: <4f612b19$0$1379$4fafbaef@reader2.news.tin.it> <8e72d74f-c844-4de3-8a37-f6b1fdc2291f@y27g2000yqy.googlegroups.com> <50e9ceec-40f1-4ead-b2b6-87328b30d084@ow8g2000pbc.googlegroups.com> <4f61c828$0$1390$4fafbaef@reader2.news.tin.it> Message-ID: Am 15.03.2012 11:44 schrieb Kiuhnm: > Let's try that. > Show me an example of "list comprehensions" and "with" (whatever they are). with open("filename", "w") as f: f.write(stuff) with lock: do_something_exclusively() Thomas From kiuhnm03.4t.yahoo.it Thu Mar 15 07:27:28 2012 From: kiuhnm03.4t.yahoo.it (Kiuhnm) Date: Thu, 15 Mar 2012 12:27:28 +0100 Subject: Python is readable In-Reply-To: References: <4f612b19$0$1379$4fafbaef@reader2.news.tin.it> <8e72d74f-c844-4de3-8a37-f6b1fdc2291f@y27g2000yqy.googlegroups.com> <50e9ceec-40f1-4ead-b2b6-87328b30d084@ow8g2000pbc.googlegroups.com> <4f61c828$0$1390$4fafbaef@reader2.news.tin.it> Message-ID: <4f61d221$0$1375$4fafbaef@reader2.news.tin.it> On 3/15/2012 11:50, Chris Angelico wrote: > On Thu, Mar 15, 2012 at 9:44 PM, Kiuhnm > wrote: >> Let's try that. >> Show me an example of "list comprehensions" and "with" (whatever they are). > > I'll do a list comp, because they lend themselves well to one-liners. > what_am_i = '\n'.join(["%X\t%c"%(i,i) for i in range(128)]) A few conjectures: 1) '\n' is an object and join one of its methods; 2) [...] is a list comprehension; 3) that 'for' suggests that range isn't (or doesn't return) a list but an iterator; 4) points 2 and 3 suggest that [...] builds a list (or array?) by querying an iterator. 5) "%X\t%"(i,i) is probably equivalent to the C-like Perl's sprintf("%X\t%c", i, i) So what_am_i is a simple ASCII table. > Okay, that one also uses printf formatting, which may be a smidge > obscure. Here's a simpler example: > > what_am_i = [x*x for x in range(11)] what_am_i = 0, 1, 4, 9, ..., 100 Your first example suggests that range(n) is a sequence iterator which returns, if queried n times, 0,...,n-1 (which is a bit counterintuitive, IMHO). Kiuhnm From rosuav at gmail.com Thu Mar 15 07:47:49 2012 From: rosuav at gmail.com (Chris Angelico) Date: Thu, 15 Mar 2012 22:47:49 +1100 Subject: Python is readable In-Reply-To: <4f61d221$0$1375$4fafbaef@reader2.news.tin.it> References: <4f612b19$0$1379$4fafbaef@reader2.news.tin.it> <8e72d74f-c844-4de3-8a37-f6b1fdc2291f@y27g2000yqy.googlegroups.com> <50e9ceec-40f1-4ead-b2b6-87328b30d084@ow8g2000pbc.googlegroups.com> <4f61c828$0$1390$4fafbaef@reader2.news.tin.it> <4f61d221$0$1375$4fafbaef@reader2.news.tin.it> Message-ID: On Thu, Mar 15, 2012 at 10:27 PM, Kiuhnm wrote: > On 3/15/2012 11:50, Chris Angelico wrote: >> I'll do a list comp, because they lend themselves well to one-liners. >> what_am_i = '\n'.join(["%X\t%c"%(i,i) for i in range(128)]) > > > A few conjectures: > 1) '\n' is an object and join one of its methods; > 2) [...] is a list comprehension; > 3) that 'for' suggests that range isn't (or doesn't return) a list but an > iterator; > 4) points 2 and 3 suggest that [...] builds a list (or array?) by querying > an iterator. > 5) "%X\t%"(i,i) is probably equivalent to the C-like Perl's > ?sprintf("%X\t%c", i, i) > > So what_am_i is a simple ASCII table. Correct. Actually, there's a few differences between Python 2 and 3; in Py2, range() returns a list, but in Py3 an iterable object. But 'for' will happily iterate over a list. >> Okay, that one also uses printf formatting, which may be a smidge >> obscure. Here's a simpler example: >> >> what_am_i = [x*x for x in range(11)] > > what_am_i = 0, 1, 4, 9, ..., 100 Correct again. > Your first example suggests that range(n) is a sequence iterator which > returns, if queried n times, > ?0,...,n-1 > (which is a bit counterintuitive, IMHO). It's a little odd, perhaps, if seen in a vacuum. But everything counts from zero - list indices, etc - so it makes sense for range(len(lst)) to return indices valid for lst. List comps are pretty readable if you know how programming languages work. Python need not be readable by everyone and his grandmother, and it does a fairly good job of being grokkable to someone who has a few ranks in Coding. (Yeah, I'm a D&D nerd. ) ChrisA From kiuhnm03.4t.yahoo.it Thu Mar 15 07:48:55 2012 From: kiuhnm03.4t.yahoo.it (Kiuhnm) Date: Thu, 15 Mar 2012 12:48:55 +0100 Subject: Python is readable In-Reply-To: References: <4f612b19$0$1379$4fafbaef@reader2.news.tin.it> <8e72d74f-c844-4de3-8a37-f6b1fdc2291f@y27g2000yqy.googlegroups.com> <50e9ceec-40f1-4ead-b2b6-87328b30d084@ow8g2000pbc.googlegroups.com> <4f61c828$0$1390$4fafbaef@reader2.news.tin.it> Message-ID: <4f61d728$0$1375$4fafbaef@reader2.news.tin.it> On 3/15/2012 12:14, Thomas Rachel wrote: > Am 15.03.2012 11:44 schrieb Kiuhnm: > >> Let's try that. >> Show me an example of "list comprehensions" and "with" (whatever they >> are). > > with open("filename", "w") as f: > f.write(stuff) Here f is created before executing the block and destroyed right after leaving the block. f's destructor will probably close the file handle. > with lock: > do_something_exclusively() It's clear what it does, but I don't know if that's special syntax. Maybe objects can have two special methods that are called respect. on entering and leaving the with-block. Or, more likely, lock creates an object which keeps the lock "acquired". The lock is released when we leave the block. So we could inspect the lock with with lock as l: inspect l... do_some..... BTW, aren't those ':' redundant? Kiuhnm From kiuhnm03.4t.yahoo.it Thu Mar 15 07:59:29 2012 From: kiuhnm03.4t.yahoo.it (Kiuhnm) Date: Thu, 15 Mar 2012 12:59:29 +0100 Subject: Python is readable In-Reply-To: References: <4f612b19$0$1379$4fafbaef@reader2.news.tin.it> <8e72d74f-c844-4de3-8a37-f6b1fdc2291f@y27g2000yqy.googlegroups.com> <50e9ceec-40f1-4ead-b2b6-87328b30d084@ow8g2000pbc.googlegroups.com> <4f61c828$0$1390$4fafbaef@reader2.news.tin.it> <4f61d221$0$1375$4fafbaef@reader2.news.tin.it> Message-ID: <4f61d9a2$0$1377$4fafbaef@reader2.news.tin.it> On 3/15/2012 12:47, Chris Angelico wrote: > On Thu, Mar 15, 2012 at 10:27 PM, Kiuhnm >> Your first example suggests that range(n) is a sequence iterator which >> returns, if queried n times, >> 0,...,n-1 >> (which is a bit counterintuitive, IMHO). > > It's a little odd, perhaps, if seen in a vacuum. But everything counts > from zero - list indices, etc - so it makes sense for range(len(lst)) > to return indices valid for lst. Maybe range uses [...) intervals? So range(a,b) is a,a+1,a+2,...,b-1 and range(b) is just short-hand for range(0,b)? > List comps are pretty readable if you know how programming languages > work. Python need not be readable by everyone and his grandmother, and > it does a fairly good job of being grokkable to someone who has a few > ranks in Coding. (Yeah, I'm a D&D nerd. ) I like what I've seen so far. Kiuhnm From karthip444 at gmail.com Thu Mar 15 08:21:03 2012 From: karthip444 at gmail.com (karthi karthi) Date: Thu, 15 Mar 2012 05:21:03 -0700 (PDT) Subject: hi see this Message-ID: <1f4aefb4-9043-4931-bc57-650e374f4411@to5g2000pbc.googlegroups.com> http://123maza.com/46/share115/ From rosuav at gmail.com Thu Mar 15 08:21:29 2012 From: rosuav at gmail.com (Chris Angelico) Date: Thu, 15 Mar 2012 23:21:29 +1100 Subject: Python is readable In-Reply-To: <4f61d9a2$0$1377$4fafbaef@reader2.news.tin.it> References: <4f612b19$0$1379$4fafbaef@reader2.news.tin.it> <8e72d74f-c844-4de3-8a37-f6b1fdc2291f@y27g2000yqy.googlegroups.com> <50e9ceec-40f1-4ead-b2b6-87328b30d084@ow8g2000pbc.googlegroups.com> <4f61c828$0$1390$4fafbaef@reader2.news.tin.it> <4f61d221$0$1375$4fafbaef@reader2.news.tin.it> <4f61d9a2$0$1377$4fafbaef@reader2.news.tin.it> Message-ID: On Thu, Mar 15, 2012 at 10:59 PM, Kiuhnm wrote: > On 3/15/2012 12:47, Chris Angelico wrote: >> It's a little odd, perhaps, if seen in a vacuum. But everything counts >> from zero - list indices, etc - so it makes sense for range(len(lst)) >> to return indices valid for lst. > > Maybe range uses [...) intervals? So range(a,b) is a,a+1,a+2,...,b-1 and > range(b) is just short-hand for range(0,b)? Yup. It's amazing how accurate your conjectures are - it's almost like you've been reading the docs! :D But yeah, that's pretty logical IMHO; and having gotten used to [) intervals in many areas of computing, I've come to find [] intervals disconcerting. Bible passages are described as, for instance, John 14:5-7, which is a three-verse passage (5, 6, 7), even though 7-5=2. However, inclusive-inclusive intervals have the benefit that they don't require the element "beyond the last" to be indexable. This is important if you're working with something that takes up all of addressable memory - going back to the IBM PCs on which I learned to code, you could use one 64KB segment for an array, but then there's no way for a 16-bit integer to indicate "past the end". >> List comps are pretty readable if you know how programming languages >> work. Python need not be readable by everyone and his grandmother, and >> it does a fairly good job of being grokkable to someone who has a few >> ranks in Coding. (Yeah, I'm a D&D nerd. ) > > I like what I've seen so far. Python has its problems, but it's a good language. I personally prefer to delimit blocks of code with braces than with indentation, and I also prefer explicit declaration of variables (yes, it's extra work, but you can have infinitely nested scopes and easily-caught syntax errors when you misspell one), but they're relatively minor. One of my favorite aspects of Python is that *everything* is an object. There's no magic syntax that gives you a piece of an object, or something special about variables that contain this, that, or the other. A literal list [like, this, one] can be used in exactly the same ways as the name of a variable containing a list or a function call returning a list - there is no difference. Oh how I yearn for that when working in C++ or PHP! ChrisA From ben+python at benfinney.id.au Thu Mar 15 08:31:01 2012 From: ben+python at benfinney.id.au (Ben Finney) Date: Thu, 15 Mar 2012 23:31:01 +1100 Subject: Python is readable References: <4f612b19$0$1379$4fafbaef@reader2.news.tin.it> <8e72d74f-c844-4de3-8a37-f6b1fdc2291f@y27g2000yqy.googlegroups.com> <50e9ceec-40f1-4ead-b2b6-87328b30d084@ow8g2000pbc.googlegroups.com> <4f61c828$0$1390$4fafbaef@reader2.news.tin.it> <4f61d221$0$1375$4fafbaef@reader2.news.tin.it> <4f61d9a2$0$1377$4fafbaef@reader2.news.tin.it> Message-ID: <87k42moxkq.fsf@benfinney.id.au> Chris Angelico writes: > Yup. It's amazing how accurate your conjectures are - it's almost like > you've been reading the docs! :D But yeah, that's pretty logical IMHO; > and having gotten used to [) intervals in many areas of computing, > I've come to find [] intervals disconcerting. Bible passages are > described as, for instance, John 14:5-7, which is a three-verse > passage (5, 6, 7), even though 7-5=2. Another good reason to advocate for proper typography. ?John 14:5?7? indicates a range (because it uses U+2013 EN DASH), whereas ?7?5? indicates subtraction (because it uses U+2212 MINUS SIGN). A hyphen (?-? U+002D) is inappropriate in either case. -- \ ?He that would make his own liberty secure must guard even his | `\ enemy from oppression.? ?Thomas Paine | _o__) | Ben Finney From rosuav at gmail.com Thu Mar 15 08:38:27 2012 From: rosuav at gmail.com (Chris Angelico) Date: Thu, 15 Mar 2012 23:38:27 +1100 Subject: Python is readable In-Reply-To: <87k42moxkq.fsf@benfinney.id.au> References: <4f612b19$0$1379$4fafbaef@reader2.news.tin.it> <8e72d74f-c844-4de3-8a37-f6b1fdc2291f@y27g2000yqy.googlegroups.com> <50e9ceec-40f1-4ead-b2b6-87328b30d084@ow8g2000pbc.googlegroups.com> <4f61c828$0$1390$4fafbaef@reader2.news.tin.it> <4f61d221$0$1375$4fafbaef@reader2.news.tin.it> <4f61d9a2$0$1377$4fafbaef@reader2.news.tin.it> <87k42moxkq.fsf@benfinney.id.au> Message-ID: On Thu, Mar 15, 2012 at 11:31 PM, Ben Finney wrote: > Another good reason to advocate for proper typography. "John 14:5-7" > indicates a range (because it uses U+2013 EN DASH), whereas "7-5" > indicates subtraction (because it uses U+2212 MINUS SIGN). A hyphen ('-' > U+002D) is inappropriate in either case. Heh. Yes, but when you're seeking the size of a range, you use subtraction. The fact that the en dash and minus sign are both often represented in ASCII with a hyphen is pure coincidence. ChrisA From ben+python at benfinney.id.au Thu Mar 15 09:16:28 2012 From: ben+python at benfinney.id.au (Ben Finney) Date: Fri, 16 Mar 2012 00:16:28 +1100 Subject: Python is readable References: <4f612b19$0$1379$4fafbaef@reader2.news.tin.it> <8e72d74f-c844-4de3-8a37-f6b1fdc2291f@y27g2000yqy.googlegroups.com> <50e9ceec-40f1-4ead-b2b6-87328b30d084@ow8g2000pbc.googlegroups.com> <4f61c828$0$1390$4fafbaef@reader2.news.tin.it> <4f61d221$0$1375$4fafbaef@reader2.news.tin.it> <4f61d9a2$0$1377$4fafbaef@reader2.news.tin.it> <87k42moxkq.fsf@benfinney.id.au> Message-ID: <87fwdaovgz.fsf@benfinney.id.au> Chris Angelico writes: > On Thu, Mar 15, 2012 at 11:31 PM, Ben Finney wrote: > > Another good reason to advocate for proper typography. "John 14:5-7" > > indicates a range (because it uses U+2013 EN DASH), whereas "7-5" > > indicates subtraction (because it uses U+2212 MINUS SIGN). A hyphen > > ('-' U+002D) is inappropriate in either case. > > Heh. Yes, but when you're seeking the size of a range, you use > subtraction. Not the size of an *inclusive* range, such as a range indicated by use of an en dash :-) > The fact that the en dash and minus sign are both often represented in > ASCII with a hyphen is pure coincidence. Hopefully, the fact that your quoting of my text munged the characters down to ASCII is also pure coincidence, and is soon to be corrected at your end? Or has your client program not joined the rest of us in the third millennium with Unicode? -- \ ?Geeks like to think that they can ignore politics. You can | `\ leave politics alone, but politics won't leave you alone.? | _o__) ?Richard M. Stallman, 2002-07-26 | Ben Finney From roy at panix.com Thu Mar 15 09:28:02 2012 From: roy at panix.com (Roy Smith) Date: Thu, 15 Mar 2012 09:28:02 -0400 Subject: Enchancement suggestion for argparse: intuit type from default References: <87pqcefyka.fsf@benfinney.id.au> <20120315055908.GA8886@cskk.homeip.net> Message-ID: In article , Robert Kern wrote: > Yes. Not all type(default) types can be called with a string to produce a > valid > value. Note that "type=" is really a misnomer. argparse doesn't really want a > type object there; it wants a converter function that takes a string to an > object. Orthogonal to my original suggestion, I agree that this is misnamed. I'm +1 on the idea of renaming it to conversion= or something like that (we'd need to keep type= around as a deprecated synonym for backwards compatability). It's really hard to get your head around "type=open". From rosuav at gmail.com Thu Mar 15 09:33:09 2012 From: rosuav at gmail.com (Chris Angelico) Date: Fri, 16 Mar 2012 00:33:09 +1100 Subject: Python is readable In-Reply-To: <87fwdaovgz.fsf@benfinney.id.au> References: <4f612b19$0$1379$4fafbaef@reader2.news.tin.it> <8e72d74f-c844-4de3-8a37-f6b1fdc2291f@y27g2000yqy.googlegroups.com> <50e9ceec-40f1-4ead-b2b6-87328b30d084@ow8g2000pbc.googlegroups.com> <4f61c828$0$1390$4fafbaef@reader2.news.tin.it> <4f61d221$0$1375$4fafbaef@reader2.news.tin.it> <4f61d9a2$0$1377$4fafbaef@reader2.news.tin.it> <87k42moxkq.fsf@benfinney.id.au> <87fwdaovgz.fsf@benfinney.id.au> Message-ID: On Fri, Mar 16, 2012 at 12:16 AM, Ben Finney wrote: > Chris Angelico writes: > >> On Thu, Mar 15, 2012 at 11:31 PM, Ben Finney wrote: >> > Another good reason to advocate for proper typography. "John 14:5-7" >> > indicates a range (because it uses U+2013 EN DASH), whereas "7-5" >> > indicates subtraction (because it uses U+2212 MINUS SIGN). A hyphen >> > ('-' U+002D) is inappropriate in either case. >> >> Heh. Yes, but when you're seeking the size of a range, you use >> subtraction. > > Not the size of an *inclusive* range, such as a range indicated by use > of an en dash :-) Yes you do, you just have to add one to it. You still use subtraction. :) >> The fact that the en dash and minus sign are both often represented in >> ASCII with a hyphen is pure coincidence. > > Hopefully, the fact that your quoting of my text munged the characters > down to ASCII is also pure coincidence, and is soon to be corrected at > your end? Or has your client program not joined the rest of us in the > third millennium with Unicode? It's gmail, and I don't know why it folded everything down. I've told it to cast everything to text (to avoid the stupid look you sometimes get with nested replies to HTML-formatted emails), and I guess it decided to go ASCII. Your mail displayed just fine, it was something in the reply mechanism. ChrisA From ben+python at benfinney.id.au Thu Mar 15 09:50:01 2012 From: ben+python at benfinney.id.au (Ben Finney) Date: Fri, 16 Mar 2012 00:50:01 +1100 Subject: Python is readable References: <4f612b19$0$1379$4fafbaef@reader2.news.tin.it> <8e72d74f-c844-4de3-8a37-f6b1fdc2291f@y27g2000yqy.googlegroups.com> <50e9ceec-40f1-4ead-b2b6-87328b30d084@ow8g2000pbc.googlegroups.com> <4f61c828$0$1390$4fafbaef@reader2.news.tin.it> <4f61d221$0$1375$4fafbaef@reader2.news.tin.it> <4f61d9a2$0$1377$4fafbaef@reader2.news.tin.it> <87k42moxkq.fsf@benfinney.id.au> <87fwdaovgz.fsf@benfinney.id.au> Message-ID: <87bonyotx2.fsf@benfinney.id.au> Chris Angelico writes: > On Fri, Mar 16, 2012 at 12:16 AM, Ben Finney wrote: > > Hopefully, the fact that your quoting of my text munged the > > characters down to ASCII is also pure coincidence, and is soon to be > > corrected at your end? Or has your client program not joined the > > rest of us in the third millennium with Unicode? > > It's gmail, and I don't know why it folded everything down. Ah. The answer is ?No?, then. Gmail (from what I can tell of receiving messages from it) is terrible at Unicode, and for that reason among many others is a poor choice for interacting with modern forums. I recommend you add your voice to those complaining at Gmail's support team about poor Unicode support, and meanwhile use a better-maintained free-software client. -- \ ?Quidquid latine dictum sit, altum viditur.? (?Whatever is | `\ said in Latin, sounds profound.?) ?anonymous | _o__) | Ben Finney From breamoreboy at yahoo.co.uk Thu Mar 15 10:06:01 2012 From: breamoreboy at yahoo.co.uk (Mark Lawrence) Date: Thu, 15 Mar 2012 14:06:01 +0000 Subject: Python is readable In-Reply-To: <4f61d728$0$1375$4fafbaef@reader2.news.tin.it> References: <4f612b19$0$1379$4fafbaef@reader2.news.tin.it> <8e72d74f-c844-4de3-8a37-f6b1fdc2291f@y27g2000yqy.googlegroups.com> <50e9ceec-40f1-4ead-b2b6-87328b30d084@ow8g2000pbc.googlegroups.com> <4f61c828$0$1390$4fafbaef@reader2.news.tin.it> <4f61d728$0$1375$4fafbaef@reader2.news.tin.it> Message-ID: On 15/03/2012 11:48, Kiuhnm wrote: > On 3/15/2012 12:14, Thomas Rachel wrote: >> Am 15.03.2012 11:44 schrieb Kiuhnm: >> >>> Let's try that. >>> Show me an example of "list comprehensions" and "with" (whatever they >>> are). >> >> with open("filename", "w") as f: >> f.write(stuff) > > Here f is created before executing the block and destroyed right after > leaving the block. f's destructor will probably close the file handle. > >> with lock: >> do_something_exclusively() > > It's clear what it does, but I don't know if that's special syntax. > Maybe objects can have two special methods that are called respect. on > entering and leaving the with-block. > Or, more likely, lock creates an object which keeps the lock "acquired". > The lock is released when we leave the block. > So we could inspect the lock with > with lock as l: > inspect l... > do_some..... > > BTW, aren't those ':' redundant? > > Kiuhnm Nope. Python 2.7.2 (default, Jun 12 2011, 15:08:59) [MSC v.1500 32 bit (Intel)] on win32 Type "help", "copyright", "credits" or "license" for more information. >>> with open("filename", "w") as f File "", line 1 with open("filename", "w") as f ^ SyntaxError: invalid syntax -- Cheers. Mark Lawrence. From kiuhnm03.4t.yahoo.it Thu Mar 15 10:16:31 2012 From: kiuhnm03.4t.yahoo.it (Kiuhnm) Date: Thu, 15 Mar 2012 15:16:31 +0100 Subject: Python is readable In-Reply-To: References: <4f612b19$0$1379$4fafbaef@reader2.news.tin.it> <8e72d74f-c844-4de3-8a37-f6b1fdc2291f@y27g2000yqy.googlegroups.com> <50e9ceec-40f1-4ead-b2b6-87328b30d084@ow8g2000pbc.googlegroups.com> <4f61c828$0$1390$4fafbaef@reader2.news.tin.it> <4f61d221$0$1375$4fafbaef@reader2.news.tin.it> <4f61d9a2$0$1377$4fafbaef@reader2.news.tin.it> Message-ID: <4f61f9bf$0$1381$4fafbaef@reader2.news.tin.it> On 3/15/2012 13:21, Chris Angelico wrote: > On Thu, Mar 15, 2012 at 10:59 PM, Kiuhnm > wrote: >> On 3/15/2012 12:47, Chris Angelico wrote: >>> It's a little odd, perhaps, if seen in a vacuum. But everything counts >>> from zero - list indices, etc - so it makes sense for range(len(lst)) >>> to return indices valid for lst. >> >> Maybe range uses [...) intervals? So range(a,b) is a,a+1,a+2,...,b-1 and >> range(b) is just short-hand for range(0,b)? > > Yup. It's amazing how accurate your conjectures are - it's almost like > you've been reading the docs! :D Come on... that was easy! :) > But yeah, that's pretty logical IMHO; > and having gotten used to [) intervals in many areas of computing, > I've come to find [] intervals disconcerting. Bible passages are > described as, for instance, John 14:5-7, which is a three-verse > passage (5, 6, 7), even though 7-5=2. Common people use mainly inclusive intervals as far as I can tell. For instance, "from" and "to" are inclusive. They could tell you they don't like your intervals because 8-5+1 = 4 instead of 3. > However, inclusive-inclusive intervals have the benefit that they > don't require the element "beyond the last" to be indexable. This is > important if you're working with something that takes up all of > addressable memory - going back to the IBM PCs on which I learned to > code, you could use one 64KB segment for an array, but then there's no > way for a 16-bit integer to indicate "past the end". But you lose the empty interval (a,a). You're forced to use (a,a-1) or something similar. There's always a drawback. >>> List comps are pretty readable if you know how programming languages >>> work. Python need not be readable by everyone and his grandmother, and >>> it does a fairly good job of being grokkable to someone who has a few >>> ranks in Coding. (Yeah, I'm a D&D nerd. ) >> >> I like what I've seen so far. > > Python has its problems, but it's a good language. I personally prefer > to delimit blocks of code with braces than with indentation, I, on the other hand, prefer indentation. I find braces redundant (in fact, I never use them in pseudo-code). > and I > also prefer explicit declaration of variables (yes, it's extra work, > but you can have infinitely nested scopes and easily-caught syntax > errors when you misspell one), but they're relatively minor. I usually declare my variables but close to where I need them. > One of my > favorite aspects of Python is that *everything* is an object. There's > no magic syntax that gives you a piece of an object, or something > special about variables that contain this, that, or the other. A > literal list [like, this, one] can be used in exactly the same ways as > the name of a variable containing a list or a function call returning > a list - there is no difference. Oh how I yearn for that when working > in C++ or PHP! Don't worry. Soon you'll be using C++0x :))) Kiuhnm From alec.taylor6 at gmail.com Thu Mar 15 10:17:49 2012 From: alec.taylor6 at gmail.com (Alec Taylor) Date: Fri, 16 Mar 2012 01:17:49 +1100 Subject: Python is readable In-Reply-To: References: <4f612b19$0$1379$4fafbaef@reader2.news.tin.it> <8e72d74f-c844-4de3-8a37-f6b1fdc2291f@y27g2000yqy.googlegroups.com> <50e9ceec-40f1-4ead-b2b6-87328b30d084@ow8g2000pbc.googlegroups.com> <4f61c828$0$1390$4fafbaef@reader2.news.tin.it> <4f61d728$0$1375$4fafbaef@reader2.news.tin.it> Message-ID: On Fri, Mar 16, 2012 at 1:06 AM, Mark Lawrence wrote: > Python 2.7.2 (default, Jun 12 2011, 15:08:59) [MSC v.1500 32 bit (Intel)] on > win32 > Type "help", "copyright", "credits" or "license" for more information. > >>>> with open("filename", "w") as f > ?File "", line 1 > > ? ?with open("filename", "w") as f > ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ?^ > SyntaxError: invalid syntax > > -- > Cheers. > > Mark Lawrence. > Erred for me also; but under f: Python 2.7.3rc1 (default, Feb 24 2012, 21:28:59) [MSC v.1500 64 bit (AMD64)] on win32 Type "help", "copyright", "credits" or "license" for more information. >>> with open("filename", "w") as f File "", line 1 with open("filename", "w") as f ^ SyntaxError: invalid syntax From kiuhnm03.4t.yahoo.it Thu Mar 15 10:19:53 2012 From: kiuhnm03.4t.yahoo.it (Kiuhnm) Date: Thu, 15 Mar 2012 15:19:53 +0100 Subject: Python is readable In-Reply-To: References: <4f612b19$0$1379$4fafbaef@reader2.news.tin.it> <8e72d74f-c844-4de3-8a37-f6b1fdc2291f@y27g2000yqy.googlegroups.com> <50e9ceec-40f1-4ead-b2b6-87328b30d084@ow8g2000pbc.googlegroups.com> <4f61c828$0$1390$4fafbaef@reader2.news.tin.it> <4f61d728$0$1375$4fafbaef@reader2.news.tin.it> Message-ID: <4f61fa8a$0$1381$4fafbaef@reader2.news.tin.it> On 3/15/2012 15:06, Mark Lawrence wrote: > On 15/03/2012 11:48, Kiuhnm wrote: >> On 3/15/2012 12:14, Thomas Rachel wrote: >>> Am 15.03.2012 11:44 schrieb Kiuhnm: >>> >>>> Let's try that. >>>> Show me an example of "list comprehensions" and "with" (whatever they >>>> are). >>> >>> with open("filename", "w") as f: >>> f.write(stuff) >> >> Here f is created before executing the block and destroyed right after >> leaving the block. f's destructor will probably close the file handle. >> >>> with lock: >>> do_something_exclusively() >> >> It's clear what it does, but I don't know if that's special syntax. >> Maybe objects can have two special methods that are called respect. on >> entering and leaving the with-block. >> Or, more likely, lock creates an object which keeps the lock "acquired". >> The lock is released when we leave the block. >> So we could inspect the lock with >> with lock as l: >> inspect l... >> do_some..... >> >> BTW, aren't those ':' redundant? >> >> Kiuhnm > > Nope. > > Python 2.7.2 (default, Jun 12 2011, 15:08:59) [MSC v.1500 32 bit > (Intel)] on win32 > Type "help", "copyright", "credits" or "license" for more information. > >>> with open("filename", "w") as f > File "", line 1 > with open("filename", "w") as f > ^ > SyntaxError: invalid syntax Ok, so they're mandatory, but I was mainly talking of design. Why are they needed? Kiuhnm From duncan.booth at invalid.invalid Thu Mar 15 10:23:38 2012 From: duncan.booth at invalid.invalid (Duncan Booth) Date: 15 Mar 2012 14:23:38 GMT Subject: Python is readable References: <4f612b19$0$1379$4fafbaef@reader2.news.tin.it> <8e72d74f-c844-4de3-8a37-f6b1fdc2291f@y27g2000yqy.googlegroups.com> <50e9ceec-40f1-4ead-b2b6-87328b30d084@ow8g2000pbc.googlegroups.com> <4f61c828$0$1390$4fafbaef@reader2.news.tin.it> <4f61d728$0$1375$4fafbaef@reader2.news.tin.it> Message-ID: Kiuhnm wrote: > BTW, aren't those ':' redundant? > They are required by the grammar, but in a sense you are correct. You could modify Python's grammar to make the colons optional and still keep it unambiguous but that would make it harder for other tools (such as text editors or indeed humans) to understand. A little bit of redundancy in the grammar is seen as a good way to minimise errors. -- Duncan Booth http://kupuguy.blogspot.com From mail at timgolden.me.uk Thu Mar 15 10:28:38 2012 From: mail at timgolden.me.uk (Tim Golden) Date: Thu, 15 Mar 2012 14:28:38 +0000 Subject: Python is readable In-Reply-To: <4f61fa8a$0$1381$4fafbaef@reader2.news.tin.it> References: <4f612b19$0$1379$4fafbaef@reader2.news.tin.it> <8e72d74f-c844-4de3-8a37-f6b1fdc2291f@y27g2000yqy.googlegroups.com> <50e9ceec-40f1-4ead-b2b6-87328b30d084@ow8g2000pbc.googlegroups.com> <4f61c828$0$1390$4fafbaef@reader2.news.tin.it> <4f61d728$0$1375$4fafbaef@reader2.news.tin.it> <4f61fa8a$0$1381$4fafbaef@reader2.news.tin.it> Message-ID: <4F61FC96.8010807@timgolden.me.uk> On 15/03/2012 14:19, Kiuhnm wrote: > On 3/15/2012 15:06, Mark Lawrence wrote: >> On 15/03/2012 11:48, Kiuhnm wrote: >>> BTW, aren't those ':' redundant? >>> >>> Kiuhnm >> >> Nope. >> >> Python 2.7.2 (default, Jun 12 2011, 15:08:59) [MSC v.1500 32 bit >> (Intel)] on win32 >> Type "help", "copyright", "credits" or "license" for more information. >> >>> with open("filename", "w") as f >> File "", line 1 >> with open("filename", "w") as f >> ^ >> SyntaxError: invalid syntax > > Ok, so they're mandatory, but I was mainly talking of design. Why are > they needed? > > Kiuhnm http://docs.python.org/faq/design.html#why-are-colons-required-for-the-if-while-def-class-statements TJG From rosuav at gmail.com Thu Mar 15 10:29:12 2012 From: rosuav at gmail.com (Chris Angelico) Date: Fri, 16 Mar 2012 01:29:12 +1100 Subject: Python is readable In-Reply-To: <4f61f9bf$0$1381$4fafbaef@reader2.news.tin.it> References: <4f612b19$0$1379$4fafbaef@reader2.news.tin.it> <8e72d74f-c844-4de3-8a37-f6b1fdc2291f@y27g2000yqy.googlegroups.com> <50e9ceec-40f1-4ead-b2b6-87328b30d084@ow8g2000pbc.googlegroups.com> <4f61c828$0$1390$4fafbaef@reader2.news.tin.it> <4f61d221$0$1375$4fafbaef@reader2.news.tin.it> <4f61d9a2$0$1377$4fafbaef@reader2.news.tin.it> <4f61f9bf$0$1381$4fafbaef@reader2.news.tin.it> Message-ID: On Fri, Mar 16, 2012 at 1:16 AM, Kiuhnm wrote: > Don't worry. Soon you'll be using C++0x :))) I use gcc/g++ with most of the new features enabled. There's some pretty handy features in it. Frankly, though, if I'd known about Cython when I started the current project, I would have argued to write it all in Python and Cify (is that a word?) the most performance-critical sections afterwards, instead of writing it in C++. It'd be a lot of hassle to change it now, but if anyone else is looking at writing a large project in C "for performance", I would strongly recommend writing in Python or Pike first. (Some day, I'm going to have to actually try Cython. But I know enough of embedding/extending Python to know that the technique would definitely be viable, and Cython can only make it easier.) ChrisA From kiuhnm03.4t.yahoo.it Thu Mar 15 10:30:33 2012 From: kiuhnm03.4t.yahoo.it (Kiuhnm) Date: Thu, 15 Mar 2012 15:30:33 +0100 Subject: Python is readable In-Reply-To: References: <4f612b19$0$1379$4fafbaef@reader2.news.tin.it> <8e72d74f-c844-4de3-8a37-f6b1fdc2291f@y27g2000yqy.googlegroups.com> <50e9ceec-40f1-4ead-b2b6-87328b30d084@ow8g2000pbc.googlegroups.com> <4f61c828$0$1390$4fafbaef@reader2.news.tin.it> <4f61d728$0$1375$4fafbaef@reader2.news.tin.it> Message-ID: <4f61fd0a$0$1389$4fafbaef@reader2.news.tin.it> On 3/15/2012 15:23, Duncan Booth wrote: > Kiuhnm wrote: > >> BTW, aren't those ':' redundant? >> > > They are required by the grammar, but in a sense you are correct. You could > modify Python's grammar to make the colons optional and still keep it > unambiguous but that would make it harder for other tools (such as text > editors or indeed humans) to understand. Sorry, but I can't see how it would make it harder for humans to understand. Are there particular situations you're referring to? Kiuhnm From robin at reportlab.com Thu Mar 15 10:31:03 2012 From: robin at reportlab.com (Robin Becker) Date: Thu, 15 Mar 2012 14:31:03 +0000 Subject: client ssl verification Message-ID: <4F61FD27.8080204@chamonix.reportlab.co.uk> I'm trying to do client ssl verification with code that looks like the sample below. I am able to reach and read urls that are secure and have no client certificate requirement OK. If I set explicit_check to True then verbose output indicates that the server certs are being checked fine ie I see the correct cert details and am able to check them. However, when I try to reach an apache location like sslverifyclient require sslverifydepth 10 I am getting an error from urllib2 that goes like this urllib2.py", line 1148, in do_open raise URLError(err) URLError: import socket, ssl, fnmatch, datetime, urllib2, httplib > verbose=False > > # wraps https connections with ssl certificate verification > class SecuredHTTPSHandler(urllib2.HTTPSHandler): > def __init__(self,key_file=None,cert_file=None,ca_certs=None,explicit_check=False): > class SecuredHTTPSConnection(httplib.HTTPSConnection): > def connect(self): > # overrides the version in httplib so that we do > # certificate verification > sock = socket.create_connection((self.host, self.port), self.timeout) > if self._tunnel_host: > self.sock = sock > self._tunnel() > # wrap the socket using verification with the root > # certs in ca_certs > if verbose: > print ca_certs, key_file, cert_file > self.sock = ssl.wrap_socket(sock, > cert_reqs=ssl.CERT_REQUIRED, > ca_certs=ca_certs, > keyfile=key_file, > certfile=cert_file, > ) > if explicit_check: > cert = self.sock.getpeercert() > if verbose: > import pprint > pprint.pprint(cert) > for key,field in cert.iteritems(): > if key=='subject': > sd = dict([x[0] for x in field]) > certhost = sd.get('commonName') > if not fnmatch.fnmatch(self.host,certhost): > raise ssl.SSLError("Host name '%s' doesn't match certificate host '%s'" > % (self.host, certhost)) > if verbose: > print 'matched "%s" to "%s"' % (self.host,certhost) > elif key=='notAfter': > now = datetime.datetime.now() > crttime = datetime.datetime.strptime(field,'%b %d %H:%M:%S %Y %Z') > if verbose: > print 'crttime=%s now=%s' % (crttime,now) > if now>=crttime: > raise ssl.SSLError("Host '%s' certificate expired on %s" > % (self.host, field)) > self.specialized_conn_class = SecuredHTTPSConnection > urllib2.HTTPSHandler.__init__(self) > > def https_open(self, req): > return self.do_open(self.specialized_conn_class, req) > > def secureDataGet(uri,ca_certs='cacert.pem',key_file=None,cert_file=None, explicit_check=False): > https_handler = SecuredHTTPSHandler(key_file=key_file,cert_file=cert_file, > ca_certs=ca_certs,explicit_check=explicit_check) > url_opener = urllib2.build_opener(https_handler) > handle = url_opener.open(uri) > response = handle.readlines() > handle.close() > return response -- Robin Becker From kiuhnm03.4t.yahoo.it Thu Mar 15 10:37:23 2012 From: kiuhnm03.4t.yahoo.it (Kiuhnm) Date: Thu, 15 Mar 2012 15:37:23 +0100 Subject: Python is readable In-Reply-To: References: <4f612b19$0$1379$4fafbaef@reader2.news.tin.it> <8e72d74f-c844-4de3-8a37-f6b1fdc2291f@y27g2000yqy.googlegroups.com> <50e9ceec-40f1-4ead-b2b6-87328b30d084@ow8g2000pbc.googlegroups.com> <4f61c828$0$1390$4fafbaef@reader2.news.tin.it> <4f61d221$0$1375$4fafbaef@reader2.news.tin.it> <4f61d9a2$0$1377$4fafbaef@reader2.news.tin.it> <4f61f9bf$0$1381$4fafbaef@reader2.news.tin.it> Message-ID: <4f61fea4$0$1378$4fafbaef@reader2.news.tin.it> On 3/15/2012 15:29, Chris Angelico wrote: > On Fri, Mar 16, 2012 at 1:16 AM, Kiuhnm > wrote: >> Don't worry. Soon you'll be using C++0x :))) > > I use gcc/g++ with most of the new features enabled. There's some > pretty handy features in it. Frankly, though, if I'd known about > Cython when I started the current project, I would have argued to > write it all in Python and Cify (is that a word?) the most > performance-critical sections afterwards, instead of writing it in > C++. Wise words. Indeed, I was joking :) I don't like what C++ is becoming. C++ should be rewritten from scratch but then who would use it? Kiuhnm From robert.kern at gmail.com Thu Mar 15 10:43:44 2012 From: robert.kern at gmail.com (Robert Kern) Date: Thu, 15 Mar 2012 14:43:44 +0000 Subject: Python is readable In-Reply-To: <4f61fd0a$0$1389$4fafbaef@reader2.news.tin.it> References: <4f612b19$0$1379$4fafbaef@reader2.news.tin.it> <8e72d74f-c844-4de3-8a37-f6b1fdc2291f@y27g2000yqy.googlegroups.com> <50e9ceec-40f1-4ead-b2b6-87328b30d084@ow8g2000pbc.googlegroups.com> <4f61c828$0$1390$4fafbaef@reader2.news.tin.it> <4f61d728$0$1375$4fafbaef@reader2.news.tin.it> <4f61fd0a$0$1389$4fafbaef@reader2.news.tin.it> Message-ID: On 3/15/12 2:30 PM, Kiuhnm wrote: > On 3/15/2012 15:23, Duncan Booth wrote: >> Kiuhnm wrote: >> >>> BTW, aren't those ':' redundant? >>> >> >> They are required by the grammar, but in a sense you are correct. You could >> modify Python's grammar to make the colons optional and still keep it >> unambiguous but that would make it harder for other tools (such as text >> editors or indeed humans) to understand. > > Sorry, but I can't see how it would make it harder for humans to understand. Are > there particular situations you're referring to? There were usability studies done on one of Python's indentation-based ancestors, ABC. Those studies found, empirically, that having the colons helped people read and understand the code faster. -- Robert Kern "I have come to believe that the whole world is an enigma, a harmless enigma that is made terrible by our own mad attempt to interpret it as though it had an underlying truth." -- Umberto Eco From rosuav at gmail.com Thu Mar 15 10:48:09 2012 From: rosuav at gmail.com (Chris Angelico) Date: Fri, 16 Mar 2012 01:48:09 +1100 Subject: Python is readable In-Reply-To: <4f61fd0a$0$1389$4fafbaef@reader2.news.tin.it> References: <4f612b19$0$1379$4fafbaef@reader2.news.tin.it> <8e72d74f-c844-4de3-8a37-f6b1fdc2291f@y27g2000yqy.googlegroups.com> <50e9ceec-40f1-4ead-b2b6-87328b30d084@ow8g2000pbc.googlegroups.com> <4f61c828$0$1390$4fafbaef@reader2.news.tin.it> <4f61d728$0$1375$4fafbaef@reader2.news.tin.it> <4f61fd0a$0$1389$4fafbaef@reader2.news.tin.it> Message-ID: On Fri, Mar 16, 2012 at 1:30 AM, Kiuhnm wrote: > Sorry, but I can't see how it would make it harder for humans to understand. > Are there particular situations you're referring to? In a trivial example, it's mostly just noise: if a == b # who needs the colon? print(c) But when your condition is more complicated, it's cleaner to explicitly mark the end of the condition. Also, Python allows you to put a simple body on the same line as the if, which is very handy: if a == b: print(c) Without the colon, this would be awkward to parse. And the bash style of using actual statement separators feels really weird, although it does mean that the newline is truly optional. ChrisA From kiuhnm03.4t.yahoo.it Thu Mar 15 10:55:05 2012 From: kiuhnm03.4t.yahoo.it (Kiuhnm) Date: Thu, 15 Mar 2012 15:55:05 +0100 Subject: Python is readable In-Reply-To: References: <4f612b19$0$1379$4fafbaef@reader2.news.tin.it> <8e72d74f-c844-4de3-8a37-f6b1fdc2291f@y27g2000yqy.googlegroups.com> <50e9ceec-40f1-4ead-b2b6-87328b30d084@ow8g2000pbc.googlegroups.com> <4f61c828$0$1390$4fafbaef@reader2.news.tin.it> <4f61d728$0$1375$4fafbaef@reader2.news.tin.it> <4f61fa8a$0$1381$4fafbaef@reader2.news.tin.it> Message-ID: <4f6202cb$0$1377$4fafbaef@reader2.news.tin.it> On 3/15/2012 15:28, Tim Golden wrote: > On 15/03/2012 14:19, Kiuhnm wrote: >> On 3/15/2012 15:06, Mark Lawrence wrote: >>> On 15/03/2012 11:48, Kiuhnm wrote: >>>> BTW, aren't those ':' redundant? >>>> >>>> Kiuhnm >>> >>> Nope. >>> >>> Python 2.7.2 (default, Jun 12 2011, 15:08:59) [MSC v.1500 32 bit >>> (Intel)] on win32 >>> Type "help", "copyright", "credits" or "license" for more information. >>> >>> with open("filename", "w") as f >>> File "", line 1 >>> with open("filename", "w") as f >>> ^ >>> SyntaxError: invalid syntax >> >> Ok, so they're mandatory, but I was mainly talking of design. Why are >> they needed? >> >> Kiuhnm > > http://docs.python.org/faq/design.html#why-are-colons-required-for-the-if-while-def-class-statements The second one is slightly easier to read because it's syntax-highlighted. Was that on purpose? By the way, the more elaborate parsing consists of looking for an END_OF_LINE followed by one or more spaces. It doesn't sound that complicated. And what about an editor which indent when you press the spacebar or tab? Kiuhnm From kiuhnm03.4t.yahoo.it Thu Mar 15 11:05:58 2012 From: kiuhnm03.4t.yahoo.it (Kiuhnm) Date: Thu, 15 Mar 2012 16:05:58 +0100 Subject: Python is readable In-Reply-To: References: <4f612b19$0$1379$4fafbaef@reader2.news.tin.it> <8e72d74f-c844-4de3-8a37-f6b1fdc2291f@y27g2000yqy.googlegroups.com> <50e9ceec-40f1-4ead-b2b6-87328b30d084@ow8g2000pbc.googlegroups.com> <4f61c828$0$1390$4fafbaef@reader2.news.tin.it> <4f61d728$0$1375$4fafbaef@reader2.news.tin.it> <4f61fd0a$0$1389$4fafbaef@reader2.news.tin.it> Message-ID: <4f620557$0$1388$4fafbaef@reader2.news.tin.it> On 3/15/2012 15:48, Chris Angelico wrote: > On Fri, Mar 16, 2012 at 1:30 AM, Kiuhnm > wrote: >> Sorry, but I can't see how it would make it harder for humans to understand. >> Are there particular situations you're referring to? > > In a trivial example, it's mostly just noise: > > if a == b # who needs the colon? > print(c) > > But when your condition is more complicated, it's cleaner to > explicitly mark the end of the condition. Also, Python allows you to > put a simple body on the same line as the if, which is very handy: > > if a == b: print(c) > > Without the colon, this would be awkward to parse. And the bash style > of using actual statement separators feels really weird, although it > does mean that the newline is truly optional. I had thought about the single-line case. What I hadn't thought about is that Python strives to be as regular as possible, so having different cases just for saving one keystroke isn't worth it. Kiuhnm From rosuav at gmail.com Thu Mar 15 11:08:37 2012 From: rosuav at gmail.com (Chris Angelico) Date: Fri, 16 Mar 2012 02:08:37 +1100 Subject: Python is readable In-Reply-To: <4f6202cb$0$1377$4fafbaef@reader2.news.tin.it> References: <4f612b19$0$1379$4fafbaef@reader2.news.tin.it> <8e72d74f-c844-4de3-8a37-f6b1fdc2291f@y27g2000yqy.googlegroups.com> <50e9ceec-40f1-4ead-b2b6-87328b30d084@ow8g2000pbc.googlegroups.com> <4f61c828$0$1390$4fafbaef@reader2.news.tin.it> <4f61d728$0$1375$4fafbaef@reader2.news.tin.it> <4f61fa8a$0$1381$4fafbaef@reader2.news.tin.it> <4f6202cb$0$1377$4fafbaef@reader2.news.tin.it> Message-ID: On Fri, Mar 16, 2012 at 1:55 AM, Kiuhnm wrote: > By the way, the more elaborate parsing consists of looking for an > END_OF_LINE followed by one or more spaces. It doesn't sound that > complicated. Only in the trivial case. What if you want to break your condition over multiple lines? (Although you have to parenthesize or backslash, so that's still unambig.) It's helpful to be explicit. > And what about an editor which indent when you press the spacebar or tab? Sure, but a good editor helps out by noticing that you did something that begs for indentation. If I put an open brace, SciTE will indent - very simple rule. With Python, if there were no colon markers, it would be quite complicated to figure out whether or not to indent; with the colons, it's simply "if/while/etc" followed by text followed by colon, and then no further non-comment text. (This sounds involved. It's not. It's right enough. -- Lady Blanche) ChrisA From robert.kern at gmail.com Thu Mar 15 11:13:46 2012 From: robert.kern at gmail.com (Robert Kern) Date: Thu, 15 Mar 2012 15:13:46 +0000 Subject: Python is readable In-Reply-To: <4f6202cb$0$1377$4fafbaef@reader2.news.tin.it> References: <4f612b19$0$1379$4fafbaef@reader2.news.tin.it> <8e72d74f-c844-4de3-8a37-f6b1fdc2291f@y27g2000yqy.googlegroups.com> <50e9ceec-40f1-4ead-b2b6-87328b30d084@ow8g2000pbc.googlegroups.com> <4f61c828$0$1390$4fafbaef@reader2.news.tin.it> <4f61d728$0$1375$4fafbaef@reader2.news.tin.it> <4f61fa8a$0$1381$4fafbaef@reader2.news.tin.it> <4f6202cb$0$1377$4fafbaef@reader2.news.tin.it> Message-ID: On 3/15/12 2:55 PM, Kiuhnm wrote: > On 3/15/2012 15:28, Tim Golden wrote: >> http://docs.python.org/faq/design.html#why-are-colons-required-for-the-if-while-def-class-statements > > The second one is slightly easier to read because it's syntax-highlighted. Was > that on purpose? No, it's an unintended side effect. The (automated) syntax highlighting was added to the FAQ much, much later than that entry was written. The syntax highlighting tool does not recognize the first example as Python, so it does not apply Python syntax highlighting to it. -- Robert Kern "I have come to believe that the whole world is an enigma, a harmless enigma that is made terrible by our own mad attempt to interpret it as though it had an underlying truth." -- Umberto Eco From roy at panix.com Thu Mar 15 11:14:02 2012 From: roy at panix.com (Roy Smith) Date: Thu, 15 Mar 2012 11:14:02 -0400 Subject: Python is readable References: <4f612b19$0$1379$4fafbaef@reader2.news.tin.it> <8e72d74f-c844-4de3-8a37-f6b1fdc2291f@y27g2000yqy.googlegroups.com> <50e9ceec-40f1-4ead-b2b6-87328b30d084@ow8g2000pbc.googlegroups.com> <4f61c828$0$1390$4fafbaef@reader2.news.tin.it> <4f61d221$0$1375$4fafbaef@reader2.news.tin.it> <4f61d9a2$0$1377$4fafbaef@reader2.news.tin.it> <4f61f9bf$0$1381$4fafbaef@reader2.news.tin.it> Message-ID: In article , Chris Angelico wrote: > I use gcc/g++ with most of the new features enabled. There's some > pretty handy features in it. Frankly, though, if I'd known about > Cython when I started the current project, I would have argued to > write it all in Python and Cify (is that a word?) the most > performance-critical sections afterwards, instead of writing it in > C++. +1. With the exception of the client-side javascript, virtually 100% of the application code behind songza.com is python. We use django, tornado, and gunicorn (all pure python). The ORM layer (mongoengine) is pure python. Of course, there's plenty of C/C++ code in the database (MongoDB), HTTP proxies (nginx and haproxy), and search engine (Xapian), but the core application code is all python. About 80,000 lines worth. Every time we look at performance, we discover the same thing. The time spent running python code is insignificant. It's all about network I/O and database queries. The only time we ever see any significant time running python code is when we do something stupid and write some O(n^2) code that can be replaced by a more appropriate algorithm. While it's nice to know that we've got the ability to write extensions in C, not once have we ever felt the need. I suppose if you're running a CPU-bound application, that might not be the case, but surprisingly few applications really are compute bound these days. I had an interesting experience the other day. We had a job applicant implement one of our coding tests in Java. It's a data mining exercise where you need to generate some summary statistics from a 700,000 line log file we give you. My Python version takes under a second. His Java version came up with the right numbers but took 2 minutes. I looked at his code and didn't any any obvious problem. It turned out he used a regex that started with '.*', and apparently the Java regex library implements that badly. Eliminating the leading '.*' got his Java running in the same time as my Python. From rosuav at gmail.com Thu Mar 15 11:14:54 2012 From: rosuav at gmail.com (Chris Angelico) Date: Fri, 16 Mar 2012 02:14:54 +1100 Subject: Python is readable In-Reply-To: <4f620557$0$1388$4fafbaef@reader2.news.tin.it> References: <4f612b19$0$1379$4fafbaef@reader2.news.tin.it> <8e72d74f-c844-4de3-8a37-f6b1fdc2291f@y27g2000yqy.googlegroups.com> <50e9ceec-40f1-4ead-b2b6-87328b30d084@ow8g2000pbc.googlegroups.com> <4f61c828$0$1390$4fafbaef@reader2.news.tin.it> <4f61d728$0$1375$4fafbaef@reader2.news.tin.it> <4f61fd0a$0$1389$4fafbaef@reader2.news.tin.it> <4f620557$0$1388$4fafbaef@reader2.news.tin.it> Message-ID: On Fri, Mar 16, 2012 at 2:05 AM, Kiuhnm wrote: > I had thought about the single-line case. What I hadn't thought about is > that Python strives to be as regular as possible, so having different cases > just for saving one keystroke isn't worth it. Yep. Have you read the Zen of Python? >>> import this (trimmed for brevity) Explicit is better than implicit. Readability counts. Special cases aren't special enough to break the rules. Although practicality beats purity. In the face of ambiguity, refuse the temptation to guess. Omitting the colon is definitely a not-special-enough case. ChrisA From kiuhnm03.4t.yahoo.it Thu Mar 15 11:18:14 2012 From: kiuhnm03.4t.yahoo.it (Kiuhnm) Date: Thu, 15 Mar 2012 16:18:14 +0100 Subject: Python is readable In-Reply-To: References: <4f612b19$0$1379$4fafbaef@reader2.news.tin.it> <8e72d74f-c844-4de3-8a37-f6b1fdc2291f@y27g2000yqy.googlegroups.com> <50e9ceec-40f1-4ead-b2b6-87328b30d084@ow8g2000pbc.googlegroups.com> <4f61c828$0$1390$4fafbaef@reader2.news.tin.it> <4f61d728$0$1375$4fafbaef@reader2.news.tin.it> <4f61fd0a$0$1389$4fafbaef@reader2.news.tin.it> Message-ID: <4f620837$0$1382$4fafbaef@reader2.news.tin.it> On 3/15/2012 15:43, Robert Kern wrote: > On 3/15/12 2:30 PM, Kiuhnm wrote: >> On 3/15/2012 15:23, Duncan Booth wrote: >>> Kiuhnm wrote: >>> >>>> BTW, aren't those ':' redundant? >>>> >>> >>> They are required by the grammar, but in a sense you are correct. You >>> could >>> modify Python's grammar to make the colons optional and still keep it >>> unambiguous but that would make it harder for other tools (such as text >>> editors or indeed humans) to understand. >> >> Sorry, but I can't see how it would make it harder for humans to >> understand. Are >> there particular situations you're referring to? > > There were usability studies done on one of Python's indentation-based > ancestors, ABC. Those studies found, empirically, that having the colons > helped people read and understand the code faster. Here's what Guido van Rossum writes about it: "Python?s use of indentation comes directly from ABC, but this idea didn?t originate with ABC--it had already been promoted by Donald Knuth and was a well-known concept of programming style. (The occam programming language also used it.) However, ABC?s authors did invent the use of the colon that separates the lead-in clause from the indented block. ----> After early user testing without the colon, it was discovered that the meaning of the indentation was unclear to beginners being taught the first steps of programming. <---- The addition of the colon clarified it significantly: the colon somehow draws attention to what follows and ties the phrases before and after it together in just the right way." If that passage is correct, those studies don't say that adding the colon increases the readability, but that it makes more sense to beginners who don't even know what indentation is. Kiuhnm From rosuav at gmail.com Thu Mar 15 11:27:31 2012 From: rosuav at gmail.com (Chris Angelico) Date: Fri, 16 Mar 2012 02:27:31 +1100 Subject: Python is readable In-Reply-To: References: <4f612b19$0$1379$4fafbaef@reader2.news.tin.it> <8e72d74f-c844-4de3-8a37-f6b1fdc2291f@y27g2000yqy.googlegroups.com> <50e9ceec-40f1-4ead-b2b6-87328b30d084@ow8g2000pbc.googlegroups.com> <4f61c828$0$1390$4fafbaef@reader2.news.tin.it> <4f61d221$0$1375$4fafbaef@reader2.news.tin.it> <4f61d9a2$0$1377$4fafbaef@reader2.news.tin.it> <4f61f9bf$0$1381$4fafbaef@reader2.news.tin.it> Message-ID: On Fri, Mar 16, 2012 at 2:14 AM, Roy Smith wrote: > While it's nice to know that we've got the ability to write extensions > in C, not once have we ever felt the need. ?I suppose if you're running > a CPU-bound application, that might not be the case, but surprisingly > few applications really are compute bound these days. My boss and I have these discussions now and then. A topic of performance comes up, and we debate whether or not, for instance, it's worth doing a separate check of an input file to see if it's properly-formed UTF-8 before parsing it (this is in PHP, or it'd be easy - just do a UTF-8 decode and work with Unicode). The debate ended, as they inevitably do, with "We're talking about a file that someone's uploaded to us, so it won't matter". Whatever processing we do is massively dwarfed by network time, and both scale linearly with the size of the file. ChrisA From nutznetz-0c1b6768-bfa9-48d5-a470-7603bd3aa915 at spamschutz.glglgl.de Thu Mar 15 11:41:36 2012 From: nutznetz-0c1b6768-bfa9-48d5-a470-7603bd3aa915 at spamschutz.glglgl.de (Thomas Rachel) Date: Thu, 15 Mar 2012 16:41:36 +0100 Subject: Python is readable In-Reply-To: <4f61d728$0$1375$4fafbaef@reader2.news.tin.it> References: <4f612b19$0$1379$4fafbaef@reader2.news.tin.it> <8e72d74f-c844-4de3-8a37-f6b1fdc2291f@y27g2000yqy.googlegroups.com> <50e9ceec-40f1-4ead-b2b6-87328b30d084@ow8g2000pbc.googlegroups.com> <4f61c828$0$1390$4fafbaef@reader2.news.tin.it> <4f61d728$0$1375$4fafbaef@reader2.news.tin.it> Message-ID: Am 15.03.2012 12:48 schrieb Kiuhnm: > On 3/15/2012 12:14, Thomas Rachel wrote: >> Am 15.03.2012 11:44 schrieb Kiuhnm: >> >>> Let's try that. >>> Show me an example of "list comprehensions" and "with" (whatever they >>> are). >> >> with open("filename", "w") as f: >> f.write(stuff) > > Here f is created before executing the block and destroyed right after > leaving the block. f's destructor will probably close the file handle. No, that is the point here: with calls __enter__ on entry and __exit__ on, well, exit. In the case of files, __enter__ doesn't probably do anything special, but returns the object again in order to be assigned to f. In __exit__, the file is closed. with open("/tmp/filename", "w") as f: print f print f So after the with clause, f is actually closed, but still present as object. >> with lock: >> do_something_exclusively() > It's clear what it does, but I don't know if that's special syntax. If you call "with" special syntax, it is. > Maybe objects can have two special methods that are called respect. on > entering and leaving the with-block. Exactly, see above. Here, on entry __enter__ is called which acquires the lock. __exit__ releases it again. > Or, more likely, lock creates an object which keeps the lock "acquired". > The lock is released when we leave the block. > So we could inspect the lock with > with lock as l: > inspect l... > do_some..... Or just inspect l - I don't know if a lock's __enter__ methos returns it again for assignment with "as"... Thomas From roy at panix.com Thu Mar 15 11:44:07 2012 From: roy at panix.com (Roy Smith) Date: Thu, 15 Mar 2012 11:44:07 -0400 Subject: Python is readable References: <4f612b19$0$1379$4fafbaef@reader2.news.tin.it> <8e72d74f-c844-4de3-8a37-f6b1fdc2291f@y27g2000yqy.googlegroups.com> <50e9ceec-40f1-4ead-b2b6-87328b30d084@ow8g2000pbc.googlegroups.com> <4f61c828$0$1390$4fafbaef@reader2.news.tin.it> <4f61d221$0$1375$4fafbaef@reader2.news.tin.it> <4f61d9a2$0$1377$4fafbaef@reader2.news.tin.it> <4f61f9bf$0$1381$4fafbaef@reader2.news.tin.it> Message-ID: In article , Chris Angelico wrote: > "We're talking about a file that someone's uploaded to us, so it > won't matter". Whatever processing we do is massively dwarfed by > network time, and both scale linearly with the size of the file. That last part (both scaling linearly) may not be true. There's an overhead of one RTT (Round Trip Time) to open a TCP connection. Add at least (handwave) one more RTT if you're negotiating encryption (i.e. https). If you're sending lots of small files, this can easily swamp the data transfer time. The single biggest optimization we've made recently was using a persistent https connection to an external data provider. Fortunately, the truly awesome requests library (http://docs.python-requests.org/) made that trivial to implement. From alec.taylor6 at gmail.com Thu Mar 15 12:01:42 2012 From: alec.taylor6 at gmail.com (Alec Taylor) Date: Fri, 16 Mar 2012 03:01:42 +1100 Subject: Python is readable In-Reply-To: <4f61f9bf$0$1381$4fafbaef@reader2.news.tin.it> References: <4f612b19$0$1379$4fafbaef@reader2.news.tin.it> <8e72d74f-c844-4de3-8a37-f6b1fdc2291f@y27g2000yqy.googlegroups.com> <50e9ceec-40f1-4ead-b2b6-87328b30d084@ow8g2000pbc.googlegroups.com> <4f61c828$0$1390$4fafbaef@reader2.news.tin.it> <4f61d221$0$1375$4fafbaef@reader2.news.tin.it> <4f61d9a2$0$1377$4fafbaef@reader2.news.tin.it> <4f61f9bf$0$1381$4fafbaef@reader2.news.tin.it> Message-ID: On Fri, Mar 16, 2012 at 1:16 AM, Kiuhnm wrote: > On 3/15/2012 13:21, Chris Angelico wrote: >> >> On Thu, Mar 15, 2012 at 10:59 PM, Kiuhnm >> ?wrote: >>> >>> On 3/15/2012 12:47, Chris Angelico wrote: >>>> >>>> It's a little odd, perhaps, if seen in a vacuum. But everything counts >>>> from zero - list indices, etc - so it makes sense for range(len(lst)) >>>> to return indices valid for lst. >>> >>> >>> Maybe range uses [...) intervals? So range(a,b) is a,a+1,a+2,...,b-1 and >>> range(b) is just short-hand for range(0,b)? >> >> >> Yup. It's amazing how accurate your conjectures are - it's almost like >> you've been reading the docs! :D > > > Come on... that was easy! :) > > >> But yeah, that's pretty logical IMHO; >> and having gotten used to [) intervals in many areas of computing, >> I've come to find [] intervals disconcerting. Bible passages are >> described as, for instance, John 14:5-7, which is a three-verse >> passage (5, 6, 7), even though 7-5=2. > > > Common people use mainly inclusive intervals as far as I can tell. > For instance, "from" and "to" are inclusive. > They could tell you they don't like your intervals because 8-5+1 = 4 instead > of 3. > > >> However, inclusive-inclusive intervals have the benefit that they >> don't require the element "beyond the last" to be indexable. This is >> important if you're working with something that takes up all of >> addressable memory - going back to the IBM PCs on which I learned to >> code, you could use one 64KB segment for an array, but then there's no >> way for a 16-bit integer to indicate "past the end". > > > But you lose the empty interval (a,a). You're forced to use (a,a-1) or > something similar. There's always a drawback. > >>>> List comps are pretty readable if you know how programming languages >>>> work. Python need not be readable by everyone and his grandmother, and >>>> it does a fairly good job of being grokkable to someone who has a few >>>> ranks in Coding. (Yeah, I'm a D&D nerd. ) >>> >>> >>> I like what I've seen so far. >> >> >> Python has its problems, but it's a good language. I personally prefer >> to delimit blocks of code with braces than with indentation, > > > I, on the other hand, prefer indentation. I find braces redundant (in fact, > I never use them in pseudo-code). > > >> and I >> also prefer explicit declaration of variables (yes, it's extra work, >> but you can have infinitely nested scopes and easily-caught syntax >> errors when you misspell one), but they're relatively minor. > > > I usually declare my variables but close to where I need them. > > >> One of my >> favorite aspects of Python is that *everything* is an object. There's >> no magic syntax that gives you a piece of an object, or something >> special about variables that contain this, that, or the other. A >> literal list [like, this, one] can be used in exactly the same ways as >> the name of a variable containing a list or a function call returning >> a list - there is no difference. Oh how I yearn for that when working >> in C++ or PHP! > > > Don't worry. Soon you'll be using C++0x :))) > > Kiuhnm > -- > http://mail.python.org/mailman/listinfo/python-list C++0x? You mean C++11? :P On that note, is Python upgrading to use C11? :V From d at davea.name Thu Mar 15 12:04:06 2012 From: d at davea.name (Dave Angel) Date: Thu, 15 Mar 2012 12:04:06 -0400 Subject: Is it technically possible to give Python option of naming process of running script? In-Reply-To: <22071354.8904.1331796412001.JavaMail.geo-discussion-forums@vbkc1> References: <19118128.4791.1331736187952.JavaMail.geo-discussion-forums@vbai14> <22071354.8904.1331796412001.JavaMail.geo-discussion-forums@vbkc1> Message-ID: <4F6212F6.5080202@davea.name> On 03/15/2012 03:26 AM, xliiv wrote: >>>> Like the topic.. . >>>> I use Python a lot, both Windows and Linux, and it's little weird to have many python process without fast distinction which is what. >> > > I did google, I've played with Exemaker (it works perfect, but not py3) and i've seen questions on Stackoverflow. > The thing I mean is a build feature of python to give such a name. Not 3rd part or etc. like Grant Edwards said. Is it possible? How about simply using cp to copy the python executable, run chmod +x on it, and run that one? Then ps would list it as the new name, not as python. i tried it on /usr/bin/python2.7 but I see no reason the same approach won't work on 3.x Note, I copied it to a new name in the same directory, which may be important. or not. -- DaveA From llanitedave at veawb.coop Thu Mar 15 12:59:54 2012 From: llanitedave at veawb.coop (llanitedave) Date: Thu, 15 Mar 2012 09:59:54 -0700 (PDT) Subject: Pragmas, foreign keys in sqlite3? Message-ID: <41621d5f-072f-41e5-a880-57d78a298250@j5g2000yqm.googlegroups.com> Several questions here, but they're related. I'm trying to incorporate an sqlite3 database that was created using Sqliteman1.2.2. I don't know what version of sqlite3 that one uses, but it seems to have ignored any attempts to create foreign keys for its tables. I'm using Python 2.7.2, and I know that the sqlite3 version that it contains is 3.7.7. Therefore, it should be able to handle foreign keys. Where I'm clueless is about how to get that information out of it, and how to implement or add foreign keys to existing tables. Is there some way to use the sqlite PRAGMA command from within python? I tried connecting to the database and got >>> cr.execute('''PRAGMA foreign_keys;''') using "inspect.getmembers()" I got a huge list of everything; it lets me see that there's no foreign key created, but I can't get that particular tuple separated out, and I have no idea how to add them. Do I need to recreate the entire database structure from scratch? From joncle at googlemail.com Thu Mar 15 13:13:41 2012 From: joncle at googlemail.com (Jon Clements) Date: Thu, 15 Mar 2012 10:13:41 -0700 (PDT) Subject: Style question (Poll) In-Reply-To: References: Message-ID: <24625945.5378.1331831621256.JavaMail.geo-discussion-forums@vblb5> On Wednesday, 14 March 2012 21:16:05 UTC, Terry Reedy wrote: > On 3/14/2012 4:49 PM, Arnaud Delobelle wrote: > > On 14 March 2012 20:37, Croepha wrote: > >> Which is preferred: > >> > >> for value in list: > >> if not value is another_value: > >> value.do_something() > >> break > > Do you really mean 'is' or '=='? > > If you mean x is not y, write it that way. > 'not x is y' can be misread and misunderstood, depending on whether > the 'is' is true or not. > > >>> not 1 is 1 > False > >>> not (1 is 1) > False > >>> (not 1) is 1 > False > > Does not matter how read. > > >>> not (1 is 0) > True > >>> (not 1) is 0 > False > >>> not 1 is 0 > True > > Does matter how read. > > >> if list and not list[0] is another_value: > >> list[0].do_something() > > Or > try: > value = mylist[0] > if value is not another_value: value.dosomething > except IndexError: > pass > > I would not do this in this case of index 0, but if the index were a > complicated expression or expensive function call, making 'if list' an > inadequate test, I might. > > > Hard to say, since they don't do the same thing :) > > > > I suspect you meant: > > > > for value in list: > > if not value is another_value: > > value.do_something() > > break > > > > I always feel uncomfortable with this because it's misleading: a loop > > that never loops. > > I agree. Please do not do this in public ;-). > > -- > Terry Jan Reedy I'm not sure it's efficient or even if I like it, but it avoids try/except and the use of a for loop. if next( iter(mylist), object() ) is not another_value: # ... Just my 2p, Jon. From joncle at googlemail.com Thu Mar 15 13:13:41 2012 From: joncle at googlemail.com (Jon Clements) Date: Thu, 15 Mar 2012 10:13:41 -0700 (PDT) Subject: Style question (Poll) In-Reply-To: References: Message-ID: <24625945.5378.1331831621256.JavaMail.geo-discussion-forums@vblb5> On Wednesday, 14 March 2012 21:16:05 UTC, Terry Reedy wrote: > On 3/14/2012 4:49 PM, Arnaud Delobelle wrote: > > On 14 March 2012 20:37, Croepha wrote: > >> Which is preferred: > >> > >> for value in list: > >> if not value is another_value: > >> value.do_something() > >> break > > Do you really mean 'is' or '=='? > > If you mean x is not y, write it that way. > 'not x is y' can be misread and misunderstood, depending on whether > the 'is' is true or not. > > >>> not 1 is 1 > False > >>> not (1 is 1) > False > >>> (not 1) is 1 > False > > Does not matter how read. > > >>> not (1 is 0) > True > >>> (not 1) is 0 > False > >>> not 1 is 0 > True > > Does matter how read. > > >> if list and not list[0] is another_value: > >> list[0].do_something() > > Or > try: > value = mylist[0] > if value is not another_value: value.dosomething > except IndexError: > pass > > I would not do this in this case of index 0, but if the index were a > complicated expression or expensive function call, making 'if list' an > inadequate test, I might. > > > Hard to say, since they don't do the same thing :) > > > > I suspect you meant: > > > > for value in list: > > if not value is another_value: > > value.do_something() > > break > > > > I always feel uncomfortable with this because it's misleading: a loop > > that never loops. > > I agree. Please do not do this in public ;-). > > -- > Terry Jan Reedy I'm not sure it's efficient or even if I like it, but it avoids try/except and the use of a for loop. if next( iter(mylist), object() ) is not another_value: # ... Just my 2p, Jon. From steveo at syslang.net Thu Mar 15 13:32:14 2012 From: steveo at syslang.net (Steven W. Orr) Date: Thu, 15 Mar 2012 13:32:14 -0400 Subject: Questions about the use of descriptors. Message-ID: <4F62279E.9050102@syslang.net> Question 1: I have a class A with one attribute and I define __get__ and __set__ for that class. Then I create another class B that uses it. Why does B require that the instance of A be a class variable in B and not created as an instance variable in __init__? E.g., # This works fine. class Truth(object): def __init__(self): self.is_slave = False def __get__(self, obj, objtype): return self.is_slave def __set__(self, obj, val): if not self.is_slave and val: self.is_slave = val class TruthHolder(object): IsSlave = Truth() def set_truth(self): self.IsSlave = True tt = TruthHolder() print tt.IsSlave tt.IsSlave = True print tt.IsSlave tt.IsSlave = False print tt.IsSlave But if I change TruthHolder to not start as a class variable class TruthHolder(object): def __init__(self): self.IsSlave = Truth() def set_truth(self): self.IsSlave = True it doesn't seem to use descriptor methods of Truth. It's just using the default setter and getter of TruthHolder. Question2: Is it the case that people only use descriptors for classes with single attributes? Or is it more frequent that descriptors are used with classes that have multiple attributes? I feel like this is powerful juju, but I'm not getting when I should be using property and when I should be using descriptors. General note: I see really simple examples in my searches, but I'd like to see a good practical example that has just a bit more meat on it. -- Time flies like the wind. Fruit flies like a banana. Stranger things have .0. happened but none stranger than this. Does your driver's license say Organ ..0 Donor?Black holes are where God divided by zero. Listen to me! We are all- 000 individuals! What if this weren't a hypothetical question? steveo at syslang.net From ramit.prasad at jpmorgan.com Thu Mar 15 13:34:44 2012 From: ramit.prasad at jpmorgan.com (Prasad, Ramit) Date: Thu, 15 Mar 2012 17:34:44 +0000 Subject: Context Manager getting str instead of AttributeError instance Message-ID: <5B80DD153D7D744689F57F4FB69AF474026B9264@SCACMX008.exchad.jpmchase.net> So I have a context manager used to catch errors def __exit__( self, exceptionClass, exception, tracebackObject ): if isinstance( exception, self.exceptionClasses ): #do something here Normally exception would be the exception instance, but for AttributeError it seems to be a string instead. 1) Why is AttributeError different than the other built-ins in this respect? 2) Are there other standard errors like this (I know that SystemExit is different as well)? 3) Taking into account that I want to include subclasses of classes listed in self.exceptionClasses, Is there a better check I can use? Ramit Ramit Prasad | JPMorgan Chase Investment Bank | Currencies Technology 712 Main Street | Houston, TX 77002 work phone: 713 - 216 - 5423 -- This email is confidential and subject to important disclaimers and conditions including on offers for the purchase or sale of securities, accuracy and completeness of information, viruses, confidentiality, legal privilege, and legal entity disclaimers, available at http://www.jpmorgan.com/pages/disclosures/email. From breamoreboy at yahoo.co.uk Thu Mar 15 13:41:12 2012 From: breamoreboy at yahoo.co.uk (Mark Lawrence) Date: Thu, 15 Mar 2012 17:41:12 +0000 Subject: Python is readable In-Reply-To: References: <4f612b19$0$1379$4fafbaef@reader2.news.tin.it> <8e72d74f-c844-4de3-8a37-f6b1fdc2291f@y27g2000yqy.googlegroups.com> <50e9ceec-40f1-4ead-b2b6-87328b30d084@ow8g2000pbc.googlegroups.com> <4f61c828$0$1390$4fafbaef@reader2.news.tin.it> <4f61d221$0$1375$4fafbaef@reader2.news.tin.it> <4f61d9a2$0$1377$4fafbaef@reader2.news.tin.it> <4f61f9bf$0$1381$4fafbaef@reader2.news.tin.it> Message-ID: On 15/03/2012 16:01, Alec Taylor wrote: > > C++0x? You mean C++11? :P > > On that note, is Python upgrading to use C11? :V Not for Windows given http://mail.python.org/pipermail/python-dev/2012-February/116258.html. I've no idea regarding *nix, os x or whatever. -- Cheers. Mark Lawrence. From ramit.prasad at jpmorgan.com Thu Mar 15 13:43:29 2012 From: ramit.prasad at jpmorgan.com (Prasad, Ramit) Date: Thu, 15 Mar 2012 17:43:29 +0000 Subject: Python is readable In-Reply-To: <87bonyotx2.fsf@benfinney.id.au> References: <4f612b19$0$1379$4fafbaef@reader2.news.tin.it> <8e72d74f-c844-4de3-8a37-f6b1fdc2291f@y27g2000yqy.googlegroups.com> <50e9ceec-40f1-4ead-b2b6-87328b30d084@ow8g2000pbc.googlegroups.com> <4f61c828$0$1390$4fafbaef@reader2.news.tin.it> <4f61d221$0$1375$4fafbaef@reader2.news.tin.it> <4f61d9a2$0$1377$4fafbaef@reader2.news.tin.it> <87k42moxkq.fsf@benfinney.id.au> <87fwdaovgz.fsf@benfinney.id.au> <87bonyotx2.fsf@benfinney.id.au> Message-ID: <5B80DD153D7D744689F57F4FB69AF474026B92B4@SCACMX008.exchad.jpmchase.net> > > > Hopefully, the fact that your quoting of my text munged the > > > characters down to ASCII is also pure coincidence, and is soon to be > > > corrected at your end? Or has your client program not joined the > > > rest of us in the third millennium with Unicode? Outlook showed the EN DASH but your MINUS SIGN and hyphen were the same for me. (UTF-8) Ramit Ramit Prasad | JPMorgan Chase Investment Bank | Currencies Technology 712 Main Street | Houston, TX 77002 work phone: 713 - 216 - 5423 -- This email is confidential and subject to important disclaimers and conditions including on offers for the purchase or sale of securities, accuracy and completeness of information, viruses, confidentiality, legal privilege, and legal entity disclaimers, available at http://www.jpmorgan.com/pages/disclosures/email. From jeanpierreda at gmail.com Thu Mar 15 13:51:05 2012 From: jeanpierreda at gmail.com (Devin Jeanpierre) Date: Thu, 15 Mar 2012 13:51:05 -0400 Subject: Python is readable In-Reply-To: References: <4f612b19$0$1379$4fafbaef@reader2.news.tin.it> Message-ID: On Wed, Mar 14, 2012 at 8:27 PM, Chris Angelico wrote: > On Thu, Mar 15, 2012 at 10:54 AM, Arnaud Delobelle wrote: >> I don't know this book and there may be a pedagogical reason for the >> implementation you quote, but pairwise_sum is probably better >> implemented in Python 3.X as: >> >> def pairwise_sum(list1, list2): >> ? ?return [x1 + x2 for x1, x2 in zip(list1, list2)] > > Okay, here's something for debate. > > Should the readability of a language be gauged on the basis of its > standard library, or should you be comparing actual code? "Actual code" often uses the standard library. > For instance, a quine in C can be fairly complex and messy, and it can > be unobvious what it's doing - but in HQ9+ it's easy. Is it fair to > compare on that basis, or should you actually implement the same / > equivalent code in each before judging? It's fair. But it's also fair to note that the comparison is silly, because the easiness of writing quines doesn't correspond with the easiness of doing productive things. -- Devin From k.sahithi2862 at gmail.com Thu Mar 15 13:55:43 2012 From: k.sahithi2862 at gmail.com (SAHITHI) Date: Thu, 15 Mar 2012 10:55:43 -0700 (PDT) Subject: HOT ACTRESS PHOTOS & VIDEOS Message-ID: TOP DATING TIPS TO ENCOURAGE WOMEN FOR DATING http://datingsitesdatingtips.blogspot.in/ FOR ONLY HOT GUYS SEE THIS SIDDI MAMRE HOT ROMANTIC STILLS http://hotactress-kalyani.blogspot.in/2012/02/siddhi-mamre-hot.html SHEENA SHAHABADI LATEST HOT PHOTOS http://hotactress-kalyani.blogspot.com/2012/02/sheena-shahabadi-hot.html LATEST HOT KATRINA KAIF PHOTOS http://hotactress-kalyani.blogspot.in/2011/08/katrina-kaif-hot.html ANUSHKA LATEST HOT PHOTOS http://hotactress-kalyani.blogspot.in/2011/08/anushka-hot.html KAJAL AGARWAL HOT SAREE STILLS http://hotactress-kalyani.blogspot.in/2011/11/kajal-agarwal-hot-in-saree.html PRIYAMANI HOT PHOTOS http://hotactress-kalyani.blogspot.in/2011/09/priyamani-hot.html KAJAL AGARWAL LATEST HOT WITHOUT TOP http://hotactress-kalyani.blogspot.in/2011/08/kajal-agarwal-hot-photos.html NEERU BAJWA LATEST SPICY STILLS http://hotactress-kalyani.blogspot.in/2011/12/neeru-bajwa-hot.html PRIYANKA TIWARI HOT PHOTOS http://hotactress-kalyani.blogspot.in/2011/12/priyanka-tiwari-hot.html SAMANTHA LATEST HOT STILLS http://hotactress-kalyani.blogspot.in/2011/09/samantha-hot.html DEEKSHASETH LATEST ROMANTIC STILLS http://hotactress-kalyani.blogspot.in/2011/09/deeksha-seth-hot.html PAYAL GHOSH HOT PHOTOS http://hotactress-kalyani.blogspot.in/2011/11/payal-ghosh-hot.html RAGINI DWIVEDI HOT PHOTOS http://hotactress-kalyani.blogspot.in/2011/12/ragini-dwivedi.html PARVATHI MELTON LATEST HOT PHOTOS http://hotactress-kalyani.blogspot.in/2011/11/parvathi-melton-hot.html SARAH JANE DIAS HOT PHOTOS http://hotactress-kalyani.blogspot.in/2011/11/sarah-jane-dias-hot.html TAMANNA LATEST HOT PHOTOS http://hotactress-kalyani.blogspot.in/2011/08/tamanna-hot.html PARUL HOT PHOTO STILLS http://hotactress-kalyani.blogspot.in/2011/12/parul-hot.html ADITI AGARWAL NEW ROMANTIC STILLS http://hotactress-kalyani.blogspot.in/2011/12/aditi-agarwal-hot.html POONAM KAUR HOT ROMANTIC STILLS http://hotactress-kalyani.blogspot.in/2011/11/poonam-kaur-hot.html AMISHA PATEL LATEST HOT BIKINI STILLS http://hotactress-kalyani.blogspot.in/2011/08/amisha-patel-hot.html { ALL LATEST MOVIE STILLS} KAJAL BUSINESSMAN MOVIE STILLS http://actressgallery-kalyani.blogspot.in/2012/01/kajal-agarwal-in-business-man.html SONAM KAPOOR LATEST HOT STILLS http://actressgallery-kalyani.blogspot.in/2012/01/sonam-kapoor-maxim-photoshoot-stills.html RITU KAUR LATEST PHOTO STILLS http://actressgallery-kalyani.blogspot.in/2012/01/ritu-kaur-stills.html SWAPNA SUNDARI MOVIE STILLS http://actressgallery-kalyani.blogspot.in/2012/01/swapna-sundari-movie-stills.html SEVAKUDU MOVIE STILLS http://actressgallery-kalyani.blogspot.in/2012/01/sevakudu-movie-stills.html. SRIKANTH DEVARA MOVIE GALLERY http://actressgallery-kalyani.blogspot.in/2011/12/devaraya-movie-stills.html KULLUMANALI MOVIE STILLS http://actressgallery-kalyani.blogspot.in/2011/12/kullu-manali-movie-stills.html BUSINESSMAN MOVIE STILLS http://actressgallery-kalyani.blogspot.in/2011/12/businessman-movie-stills.html HOT ACTRESS BIKINI STILLS IN 2012 CALENDAR http://actressgallery-kalyani.blogspot.in/2011/12/2012-actress-calendar-wallpapers.html KSHETHRAM MOVIE STILLS http://actressgallery-kalyani.blogspot.in/2011/12/kshethram-movie-stills.html SAMANTHA SOUTHSCOPE HOT PHOTOS http://actressgallery-kalyani.blogspot.in/2011/12/samantha-at-south-scope-magazine.html BODYGAURD LATEST MOVIE STILLS http://actressgallery-kalyani.blogspot.in/2011/12/bodyguard-telugu-movie-stills_14.html DEEPIKA PADUKONE SPICY WALLPAPERS http://actressgallery-kalyani.blogspot.in/2011/12/deepika-padukone.html KATRINA KAIF LATEST HOT WALLPAPERS http://actressgallery-kalyani.blogspot.in/2011/12/katrina-kaif-wallpapers.html NIPPU MOVIE STILLS http://actressgallery-kalyani.blogspot.in/2011/11/nippu-movie-stills.html LOVE FAILURE MOVIE STILLS http://actressgallery-kalyani.blogspot.in/2011/12/love-failure-movie-stills.html VIKRAM VEEDINTHE MOVIE STILLS http://actressgallery-kalyani.blogspot.in/2011/12/veedinthe-movie-stills.html 4FRIENDS MOVIE STILLS http://actressgallery-kalyani.blogspot.in/2011/12/4-friends-movie-stills.html NANDEESWARUDU MOVIE STILLS http://actressgallery-kalyani.blogspot.in/2011/12/nandeeswarudu-movie-stills.html HARI PRIYA HOT PHOTO STILLS http://actressgallery-kalyani.blogspot.in/2011/12/haripariya-actress.html SHRUTI HASSAN HOT IN 3 MOVIE http://actressgallery-kalyani.blogspot.in/2011/11/shruti-hassan-in-3-movie.html PANJA MOVIE LATEST STILLS http://actressgallery-kalyani.blogspot.in/2011/11/panja-movie-stills.html URIMI LATEST MOVIE STILLS http://actressgallery-kalyani.blogspot.in/2011/11/urimi-movie-stills.html ROUDRAM MOVIE STILLS http://actressgallery-kalyani.blogspot.in/2011/11/roudram-movie-stills.html SIMHAPUTHRUDU MOVIE STILLS http://actressgallery-kalyani.blogspot.in/2011/11/simhaputhrudu-movie-stills.html SOLO MOVIE STILLS http://actressgallery-kalyani.blogspot.in/2011/11/solo-movie-stills.html BEZAWADA MOVIE STILLS http://actressgallery-kalyani.blogspot.in/2011/11/bezawada-movie-stills.html RAJANNA MOVIE STILLS http://actressgallery-kalyani.blogspot.in/2011/11/rajanna-movie-stills.html\ POOLARANGADU MOVIE STILLS http://actressgallery-kalyani.blogspot.in/2011/11/poolarangadu-movie-stills.html PRIYUDU HOT ROMANTIC STILLS http://actressgallery-kalyani.blogspot.in/2011/11/priyudu-movie-stills.html ADHINAYAKUDU LATEST MOVIE STILLS http://actressgallery-kalyani.blogspot.in/2011/11/adhinayakudu-movie-stills.html HOT KATRINA KAIF PHOTOS http://actressgallery-kalyani.blogspot.in/2011/09/katrina-kaif.html AISHWARYA RAI HOT HQ PHOTO STILLS http://actressgallery-kalyani.blogspot.in/2011/09/aishwarya-rai.html ASIN HOT PHOTO GALLERY http://actressgallery-kalyani.blogspot.in/2011/09/asin.html HANSIKA MATOWNI LATEST HOT STILLS http://actressgallery-kalyani.blogspot.in/2011/09/hansika-motwani.html KAJAL AGARWAL HOT PHOTOS http://actressgallery-kalyani.blogspot.in/2011/09/kajal-agarwal.html SNEHA HOT GOA MOVIE STILLS http://actressgallery-kalyani.blogspot.in/2011/09/goa-movie-stills.html FOR FAST UPDATES IN FILM INDUSTRY KATRINA KAIF RARE PHOTOS http://allyouwants.blogspot.in/2011/12/katrina-kaif.html From ian.g.kelly at gmail.com Thu Mar 15 14:22:38 2012 From: ian.g.kelly at gmail.com (Ian Kelly) Date: Thu, 15 Mar 2012 12:22:38 -0600 Subject: Questions about the use of descriptors. In-Reply-To: <4F62279E.9050102@syslang.net> References: <4F62279E.9050102@syslang.net> Message-ID: On Thu, Mar 15, 2012 at 11:32 AM, Steven W. Orr wrote: > Question 1: > > I have a class A with one attribute and I define __get__ and __set__ for > that class. Then I create another class B that uses it. > > Why does B require that the instance of A be a class variable in B and not > created as an instance variable in __init__? Because that's the way descriptors work -- you put them on a class, and they modify the behavior of instances of that class w.r.t. the attribute they're stored in. If you store an object that implements the descriptor protocol in an instance attribute, then it is treated as ordinary data, not as a descriptor (which would often be undesirable). For example, this behavior is the reason that you can store functions in instance attributes without having them automagically turn into methods of the instance: def make_color(name): if name == 'red': return (255, 0, 0) elif name == 'green': return (0, 255, 0) elif name == 'blue': return (0, 0, 255) else: raise ValueError('Unsupported color %r' % name) class FactoryUser(object): def __init__(self, factory): self.factory = factory def show_blue(self): color = self.factory('blue') print(color) FactoryUser(make_color).show_blue() Here, if "self.factory" were treated as a descriptor, then it would become a method of the FactoryUser instance instead of just an arbitrary function, and the call "self.factory('blue')" would fail, because it would try to pass "self" in as the first argument to "make_color", which it is not expecting since it is not a member of FactoryUser. > Question2: > > Is it the case that people only use descriptors for classes with single > attributes? Or is it more frequent that descriptors are used with classes > that have multiple attributes? property is a convenient shorthand for a one-off descriptor. I use descriptor classes instead when I have a generic behavior that I want to use across multiple attributes, either on a single class or in multiple classes. As a simple, real example, I have a wxPython app with some classes for dialog windows, each of which contain one or more text controls, and I want to be able to access the contents of those text controls as attributes. I could create a whole bunch of properties, each of which does basically the same thing, or I could just use this descriptor class: class TextDescriptor(object): def __init__(self, control_name): self._control_name = control_name def __get__(self, instance, owner): if instance is not None: return getattr(instance, self._control_name).GetValue() def __set__(self, instance, value): getattr(instance, self._control_name).ChangeValue(value) Then to create the individual properties, all I have to do is this: class MyDialog(wx.Dialog): name = TextDescriptor('_name') description = TextDescriptor('_description') address = TextDescriptor('_address') def __init__(self, ...): # Build the dialog along with the _name, _description, and _address controls... Cheers, Ian From invalid at invalid.invalid Thu Mar 15 14:39:11 2012 From: invalid at invalid.invalid (Grant Edwards) Date: Thu, 15 Mar 2012 18:39:11 +0000 (UTC) Subject: Is it technically possible to give Python option of naming process of running script? References: <19118128.4791.1331736187952.JavaMail.geo-discussion-forums@vbai14> <22071354.8904.1331796412001.JavaMail.geo-discussion-forums@vbkc1> Message-ID: On 2012-03-15, Dave Angel wrote: > On 03/15/2012 03:26 AM, xliiv wrote: >>>>> Like the topic.. . >>>>> I use Python a lot, both Windows and Linux, and it's little weird to have many python process without fast distinction which is what. >>> >> >> I did google, I've played with Exemaker (it works perfect, but not py3) and i've seen questions on Stackoverflow. >> The thing I mean is a build feature of python to give such a name. Not 3rd part or etc. like Grant Edwards said. Is it possible? > > How about simply using cp to copy the python executable, run chmod +x on > it, and run that one? Then ps would list it as the new name, not as python. That's rather a waste of memory. Better to use a link. That way the executable can still be shared by multiple programs and won't be duplicated in memory. > i tried it on /usr/bin/python2.7 but I see no reason the same > approach won't work on 3.x Note, I copied it to a new name in the same > directory, which may be important. or not. Seems like an awfully obtuse way of doing things -- I don't really want to have 15 different copies of Python (or even links), and it requires root privleges every time you want to run a Python program with the "correct" name. -- Grant Edwards grant.b.edwards Yow! Can I have an IMPULSE at ITEM instead? gmail.com From __peter__ at web.de Thu Mar 15 15:01:38 2012 From: __peter__ at web.de (Peter Otten) Date: Thu, 15 Mar 2012 20:01:38 +0100 Subject: Context Manager getting str instead of AttributeError instance References: <5B80DD153D7D744689F57F4FB69AF474026B9264@SCACMX008.exchad.jpmchase.net> Message-ID: Prasad, Ramit wrote: > So I have a context manager used to catch errors > > def __exit__( self, exceptionClass, exception, tracebackObject ): > if isinstance( exception, self.exceptionClasses ): > #do something here > > Normally exception would be the exception instance, but for > AttributeError it seems to be a string instead. I don't think so: >>> class A(object): ... def __enter__(self): return self ... def __exit__(self, *args): print args ... >>> with A() as a: ... a.x ... (, AttributeError("'A' object has no attribute 'x'",), ) Traceback (most recent call last): File "", line 2, in AttributeError: 'A' object has no attribute 'x' > 1) Why is AttributeError different than the other built-ins > in this respect? > 2) Are there other standard errors like this (I know > that SystemExit is different as well)? > 3) Taking into account that I want to include subclasses of > classes listed in self.exceptionClasses, Is there a better check I can > use? From ramit.prasad at jpmorgan.com Thu Mar 15 15:10:59 2012 From: ramit.prasad at jpmorgan.com (Prasad, Ramit) Date: Thu, 15 Mar 2012 19:10:59 +0000 Subject: Context Manager getting str instead of AttributeError instance In-Reply-To: References: <5B80DD153D7D744689F57F4FB69AF474026B9264@SCACMX008.exchad.jpmchase.net> Message-ID: <5B80DD153D7D744689F57F4FB69AF474026B9625@SCACMX008.exchad.jpmchase.net> > Prasad, Ramit wrote: > > > So I have a context manager used to catch errors > > > > def __exit__( self, exceptionClass, exception, tracebackObject ): > > if isinstance( exception, self.exceptionClasses ): > > #do something here > > > > Normally exception would be the exception instance, but for > > AttributeError it seems to be a string instead. > > I don't think so: > > >>> class A(object): > ... def __enter__(self): return self > ... def __exit__(self, *args): print args > ... > >>> with A() as a: > ... a.x > ... > (, AttributeError("'A' object has no > attribute 'x'",), ) > Traceback (most recent call last): > File "", line 2, in > AttributeError: 'A' object has no attribute 'x' > > > 1) Why is AttributeError different than the other built-ins > > in this respect? > > 2) Are there other standard errors like this (I know > > that SystemExit is different as well)? > > 3) Taking into account that I want to include subclasses of > > classes listed in self.exceptionClasses, Is there a better check I can > > use? Not sure why mine behaves differently: Python 2.6.6 (r266:84292, Dec 17 2010, 12:36:53) [MSC v.1500 32 bit (Intel)] on win32 >>> >>> class A(object): ... def __enter__(self): return self ... def __exit__(self, *args): print args ... >>> with A() as a: ... a.x ... (, "'A' object has no attribute 'x'", ) AttributeError: 'A' object has no attribute 'x' As you can see, I am getting a string while you are not. Ramit Ramit Prasad | JPMorgan Chase Investment Bank | Currencies Technology 712 Main Street | Houston, TX 77002 work phone: 713 - 216 - 5423 -- This email is confidential and subject to important disclaimers and conditions including on offers for the purchase or sale of securities, accuracy and completeness of information, viruses, confidentiality, legal privilege, and legal entity disclaimers, available at http://www.jpmorgan.com/pages/disclosures/email. From kiuhnm03.4t.yahoo.it Thu Mar 15 15:40:52 2012 From: kiuhnm03.4t.yahoo.it (Kiuhnm) Date: Thu, 15 Mar 2012 20:40:52 +0100 Subject: Python is readable In-Reply-To: References: <4f612b19$0$1379$4fafbaef@reader2.news.tin.it> <8e72d74f-c844-4de3-8a37-f6b1fdc2291f@y27g2000yqy.googlegroups.com> <50e9ceec-40f1-4ead-b2b6-87328b30d084@ow8g2000pbc.googlegroups.com> <4f61c828$0$1390$4fafbaef@reader2.news.tin.it> <4f61d728$0$1375$4fafbaef@reader2.news.tin.it> <4f61fa8a$0$1381$4fafbaef@reader2.news.tin.it> <4f6202cb$0$1377$4fafbaef@reader2.news.tin.it> Message-ID: <4f6245c5$0$1384$4fafbaef@reader2.news.tin.it> On 3/15/2012 16:08, Chris Angelico wrote: > On Fri, Mar 16, 2012 at 1:55 AM, Kiuhnm > wrote: >> By the way, the more elaborate parsing consists of looking for an >> END_OF_LINE followed by one or more spaces. It doesn't sound that >> complicated. > > Only in the trivial case. What if you want to break your condition > over multiple lines? (Although you have to parenthesize or backslash, > so that's still unambig.) It's helpful to be explicit. You said it yourself. Just look out for parentheses or backslashes. C and C++ editors do that all the time with single-statement control-flow constructs. >> And what about an editor which indent when you press the spacebar or tab? > > Sure, but a good editor helps out by noticing that you did something > that begs for indentation. If I put an open brace, SciTE will indent - > very simple rule. What about braces in strings? There's always some parsing going on and since you probably want syntax highlighting and maybe code autocompletion, what's the problem with missing colons? Moreover, I think that if (............ ............ ............): ............ ............ ............ is not very readable anyway. Kiuhnm From storchaka at gmail.com Thu Mar 15 15:43:46 2012 From: storchaka at gmail.com (Serhiy Storchaka) Date: Thu, 15 Mar 2012 21:43:46 +0200 Subject: Python is readable In-Reply-To: <4f61fa8a$0$1381$4fafbaef@reader2.news.tin.it> References: <4f612b19$0$1379$4fafbaef@reader2.news.tin.it> <8e72d74f-c844-4de3-8a37-f6b1fdc2291f@y27g2000yqy.googlegroups.com> <50e9ceec-40f1-4ead-b2b6-87328b30d084@ow8g2000pbc.googlegroups.com> <4f61c828$0$1390$4fafbaef@reader2.news.tin.it> <4f61d728$0$1375$4fafbaef@reader2.news.tin.it> <4f61fa8a$0$1381$4fafbaef@reader2.news.tin.it> Message-ID: 15.03.12 16:19, Kiuhnm ???????(??): > Ok, so they're mandatory, but I was mainly talking of design. Why are they needed? http://python-history.blogspot.com/2011/07/karin-dewar-indentation-and-colon.html From ian.g.kelly at gmail.com Thu Mar 15 15:49:02 2012 From: ian.g.kelly at gmail.com (Ian Kelly) Date: Thu, 15 Mar 2012 13:49:02 -0600 Subject: Context Manager getting str instead of AttributeError instance In-Reply-To: <5B80DD153D7D744689F57F4FB69AF474026B9625@SCACMX008.exchad.jpmchase.net> References: <5B80DD153D7D744689F57F4FB69AF474026B9264@SCACMX008.exchad.jpmchase.net> <5B80DD153D7D744689F57F4FB69AF474026B9625@SCACMX008.exchad.jpmchase.net> Message-ID: On Thu, Mar 15, 2012 at 1:10 PM, Prasad, Ramit wrote: >> Prasad, Ramit wrote: >> >> > So I have a context manager used to catch errors >> > >> > def __exit__( self, exceptionClass, exception, tracebackObject ): >> > ? ? if isinstance( exception, self.exceptionClasses ): >> > ? ? ? ? ?#do something here >> > >> > Normally exception would be the exception instance, but for >> > AttributeError it seems to be a string instead. >> >> I don't think so: >> >> >>> class A(object): >> ... ? ? def __enter__(self): return self >> ... ? ? def __exit__(self, *args): print args >> ... >> >>> with A() as a: >> ... ? ? a.x >> ... >> (, AttributeError("'A' object has no >> attribute 'x'",), ) >> Traceback (most recent call last): >> ? File "", line 2, in >> AttributeError: 'A' object has no attribute 'x' >> >> > 1) Why is AttributeError different than the other built-ins >> > in this respect? >> > 2) Are there other standard errors like this (I know >> > that SystemExit is different as well)? >> > 3) Taking into account that I want to include subclasses of >> > classes listed in self.exceptionClasses, Is there a better check I can >> > use? > > Not sure why mine behaves differently: > Python 2.6.6 (r266:84292, Dec 17 2010, 12:36:53) [MSC v.1500 32 bit (Intel)] on win32 >>>> >>>> class A(object): > ... ? ? def __enter__(self): return self > ... ? ? def __exit__(self, *args): print args > ... >>>> with A() as a: > ... ? ? a.x > ... > (, "'A' object has no attribute 'x'", ) > AttributeError: 'A' object has no attribute 'x' > > As you can see, I am getting a string while you are not. Looks like a version difference. I don't have Python 2.6 handy to test on, but I get a str in Python 2.5 and an AttributeError instance in Python 2.7. From ramit.prasad at jpmorgan.com Thu Mar 15 16:25:46 2012 From: ramit.prasad at jpmorgan.com (Prasad, Ramit) Date: Thu, 15 Mar 2012 20:25:46 +0000 Subject: Context Manager getting str instead of AttributeError instance In-Reply-To: References: <5B80DD153D7D744689F57F4FB69AF474026B9264@SCACMX008.exchad.jpmchase.net> <5B80DD153D7D744689F57F4FB69AF474026B9625@SCACMX008.exchad.jpmchase.net> Message-ID: <5B80DD153D7D744689F57F4FB69AF474026B9706@SCACMX008.exchad.jpmchase.net> > > ... > > (, "'A' object has no attribute 'x'", > ) > > AttributeError: 'A' object has no attribute 'x' > > > > As you can see, I am getting a string while you are not. > >Ian Kelly said: > Looks like a version difference. I don't have Python 2.6 handy to > test on, but I get a str in Python 2.5 and an AttributeError instance > in Python 2.7. Thanks Ian, that was the key! I guess I will just have to work around it. Any suggestions? I am thinking about just creating a blank instance of the error class since that the class gets passed successfully. Ramit Ramit Prasad | JPMorgan Chase Investment Bank | Currencies Technology 712 Main Street | Houston, TX 77002 work phone: 713 - 216 - 5423 -- This email is confidential and subject to important disclaimers and conditions including on offers for the purchase or sale of securities, accuracy and completeness of information, viruses, confidentiality, legal privilege, and legal entity disclaimers, available at http://www.jpmorgan.com/pages/disclosures/email. From ian.g.kelly at gmail.com Thu Mar 15 16:33:46 2012 From: ian.g.kelly at gmail.com (Ian Kelly) Date: Thu, 15 Mar 2012 14:33:46 -0600 Subject: Context Manager getting str instead of AttributeError instance In-Reply-To: <5B80DD153D7D744689F57F4FB69AF474026B9706@SCACMX008.exchad.jpmchase.net> References: <5B80DD153D7D744689F57F4FB69AF474026B9264@SCACMX008.exchad.jpmchase.net> <5B80DD153D7D744689F57F4FB69AF474026B9625@SCACMX008.exchad.jpmchase.net> <5B80DD153D7D744689F57F4FB69AF474026B9706@SCACMX008.exchad.jpmchase.net> Message-ID: On Thu, Mar 15, 2012 at 2:25 PM, Prasad, Ramit wrote: >> > ... >> > (, "'A' object has no attribute 'x'", >> ) >> > AttributeError: 'A' object has no attribute 'x' >> > >> > As you can see, I am getting a string while you are not. >> >>Ian Kelly said: >> Looks like a version difference. ?I don't have Python 2.6 handy to >> test on, but I get a str in Python 2.5 and an AttributeError instance >> in Python 2.7. > > Thanks Ian, that was the key! I guess I will just have to work around it. > Any suggestions? I am thinking about just creating a blank instance of > the error class since that the class gets passed successfully. Well, for what you want to do, I don't think you need an instance at all -- just use issubclass instead of isinstance: def __exit__( self, exceptionClass, exception, tracebackObject ): if issubclass( exceptionClass, self.exceptionClasses ): #do something here Cheers, Ian From __peter__ at web.de Thu Mar 15 16:38:22 2012 From: __peter__ at web.de (Peter Otten) Date: Thu, 15 Mar 2012 21:38:22 +0100 Subject: Context Manager getting str instead of AttributeError instance References: <5B80DD153D7D744689F57F4FB69AF474026B9264@SCACMX008.exchad.jpmchase.net> <5B80DD153D7D744689F57F4FB69AF474026B9625@SCACMX008.exchad.jpmchase.net> Message-ID: Prasad, Ramit wrote: >> Prasad, Ramit wrote: >> >> > So I have a context manager used to catch errors >> > >> > def __exit__( self, exceptionClass, exception, tracebackObject ): >> > if isinstance( exception, self.exceptionClasses ): >> > #do something here >> > >> > Normally exception would be the exception instance, but for >> > AttributeError it seems to be a string instead. >> >> I don't think so: >> >> >>> class A(object): >> ... def __enter__(self): return self >> ... def __exit__(self, *args): print args >> ... >> >>> with A() as a: >> ... a.x >> ... >> (, AttributeError("'A' object has no >> attribute 'x'",), ) >> Traceback (most recent call last): >> File "", line 2, in >> AttributeError: 'A' object has no attribute 'x' >> >> > 1) Why is AttributeError different than the other built-ins >> > in this respect? >> > 2) Are there other standard errors like this (I know >> > that SystemExit is different as well)? >> > 3) Taking into account that I want to include subclasses of >> > classes listed in self.exceptionClasses, Is there a better check I can >> > use? > > Not sure why mine behaves differently: > Python 2.6.6 (r266:84292, Dec 17 2010, 12:36:53) [MSC v.1500 32 bit > (Intel)] on win32 >>>> >>>> class A(object): > ... def __enter__(self): return self > ... def __exit__(self, *args): print args > ... >>>> with A() as a: > ... a.x > ... > (, "'A' object has no attribute 'x'", > ) AttributeError: 'A' object has no > attribute 'x' > > As you can see, I am getting a string while you are not. Ah, it's a bug: http://bugs.python.org/issue7853 Unfortunately it is to severe to fix in a bugfix release. You could work around it with an issubclass() test on the first argument. From arnodel at gmail.com Thu Mar 15 16:54:30 2012 From: arnodel at gmail.com (Arnaud Delobelle) Date: Thu, 15 Mar 2012 20:54:30 +0000 Subject: Python is readable In-Reply-To: References: <4f612b19$0$1379$4fafbaef@reader2.news.tin.it> Message-ID: On 15 March 2012 00:27, Chris Angelico wrote: > On Thu, Mar 15, 2012 at 10:54 AM, Arnaud Delobelle wrote: >> I don't know this book and there may be a pedagogical reason for the >> implementation you quote, but pairwise_sum is probably better >> implemented in Python 3.X as: >> >> def pairwise_sum(list1, list2): >> ? ?return [x1 + x2 for x1, x2 in zip(list1, list2)] > > Okay, here's something for debate. > > Should the readability of a language be gauged on the basis of its > standard library, or should you be comparing actual code? But here's the code posted by the OP: --- Python --- def pairwise_sum(list1, list2): result = [] for i in range(len(list1)): result.append(list1[i] + list2[i]) return result --- --- The code I posted uses one builtin function (zip), the code posted by the OP uses two (range and len). Neither uses the standard library. -- Arnaud From cs at zip.com.au Thu Mar 15 17:18:57 2012 From: cs at zip.com.au (Cameron Simpson) Date: Fri, 16 Mar 2012 08:18:57 +1100 Subject: Enchancement suggestion for argparse: intuit type from default In-Reply-To: References: Message-ID: <20120315211857.GA31617@cskk.homeip.net> On 15Mar2012 09:28, Roy Smith wrote: | In article , | Robert Kern wrote: | > Yes. Not all type(default) types can be called with a string to produce a | > valid | > value. Note that "type=" is really a misnomer. argparse doesn't really want a | > type object there; it wants a converter function that takes a string to an | > object. | | Orthogonal to my original suggestion, I agree that this is misnamed. | I'm +1 on the idea of renaming it to conversion= or something like that | (we'd need to keep type= around as a deprecated synonym for backwards | compatability). It's really hard to get your head around "type=open". "factory"? Anyway, far too late to change this now! -- Cameron Simpson DoD#743 http://www.cskk.ezoshosting.com/cs/ all coders are created equal; that they are endowed with certain unalienable rights, of these are beer, net connectivity, and the pursuit of bugfixes... - Gregory R Block From cs at zip.com.au Thu Mar 15 17:42:24 2012 From: cs at zip.com.au (Cameron Simpson) Date: Fri, 16 Mar 2012 08:42:24 +1100 Subject: Is there a ConfigParser which keeps comments In-Reply-To: <4F60DFB8.8080703@tim.thechases.com> References: <4F60DFB8.8080703@tim.thechases.com> Message-ID: <20120315214224.GA3390@cskk.homeip.net> On 14Mar2012 13:13, Tim Chase wrote: | On 03/14/12 12:06, Terry Reedy wrote: | > On 3/14/2012 6:07 AM, Gelonida N wrote: | >> Now I'm looking for a library, which behaves like config parser, but | >> with one minor difference. | >> | >> The write() mehtod should keep existing comments. | > | > Assuming that you have not overlooked anything, I would just subclass | > ConfigParser with an altered write method. | | It would require a lot more than that. It would entail changing | the reading as well so that it preserved the comments as well as | the order of sections & keys, and a way of storing those | associated comments in sequence. I looked into it a fair while | back and it was a LOT more work than I cared to do for minimal | gain. I wimped out and just documented it with "If you use the | ability to (re)write a configuration file, it will not keep any | comments or ordering from any original sources." A low cost approach might be to patch the file instead of transcribing the in-memory state. Not the same semantics, but it would not be too hard to add a patch_config(filename, section, setting, value) that read the old file and wrote a new one with an adjusted section, ignoring the in-memory state (indeed, on that basis the siganture isn't a method but a standalone function). The logic is easy enough that I even wrote a shell script in 2004 to do essentially this: https://bitbucket.org/cameron_simpson/css/src/ef42896872b5/bin/winclauseappend One could imagine an efficient python implementation and a ConfigParser subclass that patched the file if a setting got changed, or had a .patch method to apply particular setting changes as desired. Cheers, -- Cameron Simpson DoD#743 http://www.cskk.ezoshosting.com/cs/ From sci.physics: tron at mailzone.com: The only problem is, how do you send a message from Earth to Mars instantly? Does anyone have any ideas about where we can start? John Baez References: <4F615880.6080005@syslang.net> Message-ID: <4F626405.7040609@gmail.com> Le 15/03/2012 03:48, Steven W. Orr a ?crit : > On 3/14/2012 6:07 AM, Gelonida N wrote: >> Hi, >> >> >> At the moment I use ConfigParser >> http://docs.python.org/library/configparser.html >> for one of my applications. >> >> >> Now I'm looking for a library, which behaves like config parser, but >> with one minor difference. >> >> The write() mehtod should keep existing comments. >> >> Does anybody know or implement something like this or is there as >> switrch, that I overlooked in hte documentaiton. >> >> > > I use ConfigObj. > Sure configObj is a must...I use it too. http://www.voidspace.org.uk/python/configobj.html Cheers Karim From torriem at gmail.com Thu Mar 15 18:12:28 2012 From: torriem at gmail.com (Michael Torrie) Date: Thu, 15 Mar 2012 16:12:28 -0600 Subject: Python is readable In-Reply-To: <4f6245c5$0$1384$4fafbaef@reader2.news.tin.it> References: <4f612b19$0$1379$4fafbaef@reader2.news.tin.it> <8e72d74f-c844-4de3-8a37-f6b1fdc2291f@y27g2000yqy.googlegroups.com> <50e9ceec-40f1-4ead-b2b6-87328b30d084@ow8g2000pbc.googlegroups.com> <4f61c828$0$1390$4fafbaef@reader2.news.tin.it> <4f61d728$0$1375$4fafbaef@reader2.news.tin.it> <4f61fa8a$0$1381$4fafbaef@reader2.news.tin.it> <4f6202cb$0$1377$4fafbaef@reader2.news.tin.it> <4f6245c5$0$1384$4fafbaef@reader2.news.tin.it> Message-ID: <4F62694C.30007@gmail.com> On 03/15/2012 01:40 PM, Kiuhnm wrote: > Moreover, I think that > if (............ > ............ > ............): > ............ > ............ > ............ > is not very readable anyway. Sure but neither is if (............ \ ............ \ ............) ............ ............ ............ In other words, with or without the : if you format your if statements in an unreadable way, it will be unreadable. Nothing to do with python's syntax at all. Now, if ............ ............ ............: ............ ............ ............ isn't too bad for readability. In other words the C-ism of putting the IF predicate in parenthesis normally doesn't belong in python, though there are cases when you need to enforce a certain operator precedence, granted. From torriem at gmail.com Thu Mar 15 18:17:36 2012 From: torriem at gmail.com (Michael Torrie) Date: Thu, 15 Mar 2012 16:17:36 -0600 Subject: Python is readable In-Reply-To: <4f620837$0$1382$4fafbaef@reader2.news.tin.it> References: <4f612b19$0$1379$4fafbaef@reader2.news.tin.it> <8e72d74f-c844-4de3-8a37-f6b1fdc2291f@y27g2000yqy.googlegroups.com> <50e9ceec-40f1-4ead-b2b6-87328b30d084@ow8g2000pbc.googlegroups.com> <4f61c828$0$1390$4fafbaef@reader2.news.tin.it> <4f61d728$0$1375$4fafbaef@reader2.news.tin.it> <4f61fd0a$0$1389$4fafbaef@reader2.news.tin.it> <4f620837$0$1382$4fafbaef@reader2.news.tin.it> Message-ID: <4F626A80.7080607@gmail.com> On 03/15/2012 09:18 AM, Kiuhnm wrote: > ----> After early user testing without the colon, it was discovered that > the meaning of the indentation was unclear to beginners being taught the > first steps of programming. <---- > > The addition of the colon clarified it significantly: the colon somehow > draws attention to what follows and ties the phrases before and after it > together in just the right way." > > If that passage is correct, those studies don't say that adding the > colon increases the readability, but that it makes more sense to > beginners who don't even know what indentation is. Seems to me that helping code to make more sense to a beginner is, by definition, increasing readability. From ben+python at benfinney.id.au Thu Mar 15 18:35:53 2012 From: ben+python at benfinney.id.au (Ben Finney) Date: Fri, 16 Mar 2012 09:35:53 +1100 Subject: Python is readable References: <4f612b19$0$1379$4fafbaef@reader2.news.tin.it> <8e72d74f-c844-4de3-8a37-f6b1fdc2291f@y27g2000yqy.googlegroups.com> <50e9ceec-40f1-4ead-b2b6-87328b30d084@ow8g2000pbc.googlegroups.com> <4f61c828$0$1390$4fafbaef@reader2.news.tin.it> <4f61d728$0$1375$4fafbaef@reader2.news.tin.it> <4f61fa8a$0$1381$4fafbaef@reader2.news.tin.it> <4f6202cb$0$1377$4fafbaef@reader2.news.tin.it> <4f6245c5$0$1384$4fafbaef@reader2.news.tin.it> Message-ID: <873999pk52.fsf@benfinney.id.au> Kiuhnm writes: > Moreover, I think that > if (............ > ............ > ............): > ............ > ............ > ............ > is not very readable anyway. I agree, and am glad PEP 8 has been updated to recommend an extra level of indentation for continuation, to distinguish from the new block that follows . -- \ ?From the moment I picked your book up until I laid it down I | `\ was convulsed with laughter. Someday I intend reading it.? | _o__) ?Groucho Marx | Ben Finney From arnodel at gmail.com Thu Mar 15 19:00:23 2012 From: arnodel at gmail.com (Arnaud Delobelle) Date: Thu, 15 Mar 2012 23:00:23 +0000 Subject: Python is readable In-Reply-To: <873999pk52.fsf@benfinney.id.au> References: <4f612b19$0$1379$4fafbaef@reader2.news.tin.it> <8e72d74f-c844-4de3-8a37-f6b1fdc2291f@y27g2000yqy.googlegroups.com> <50e9ceec-40f1-4ead-b2b6-87328b30d084@ow8g2000pbc.googlegroups.com> <4f61c828$0$1390$4fafbaef@reader2.news.tin.it> <4f61d728$0$1375$4fafbaef@reader2.news.tin.it> <4f61fa8a$0$1381$4fafbaef@reader2.news.tin.it> <4f6202cb$0$1377$4fafbaef@reader2.news.tin.it> <4f6245c5$0$1384$4fafbaef@reader2.news.tin.it> <873999pk52.fsf@benfinney.id.au> Message-ID: On 15 March 2012 22:35, Ben Finney wrote: > Kiuhnm writes: > >> Moreover, I think that >> ? if (............ >> ? ? ? ............ >> ? ? ? ............): >> ? ? ? ............ >> ? ? ? ............ >> ? ? ? ............ >> is not very readable anyway. > > I agree, and am glad PEP 8 has been updated to recommend an extra level > of indentation for continuation, to distinguish from the new block that > follows . Personally I solve this by never writing if conditions that span more than one line. If the worst comes to the worst, I would write: aptly_named_condition = ( very long condition that goes over plenty of lines ) if aptly_named_condition: do stuff -- Arnaud From kiuhnm03.4t.yahoo.it Thu Mar 15 19:32:52 2012 From: kiuhnm03.4t.yahoo.it (Kiuhnm) Date: Fri, 16 Mar 2012 00:32:52 +0100 Subject: Python is readable In-Reply-To: References: <4f612b19$0$1379$4fafbaef@reader2.news.tin.it> <8e72d74f-c844-4de3-8a37-f6b1fdc2291f@y27g2000yqy.googlegroups.com> <50e9ceec-40f1-4ead-b2b6-87328b30d084@ow8g2000pbc.googlegroups.com> <4f61c828$0$1390$4fafbaef@reader2.news.tin.it> <4f61d728$0$1375$4fafbaef@reader2.news.tin.it> <4f61fd0a$0$1389$4fafbaef@reader2.news.tin.it> <4f620837$0$1382$4fafbaef@reader2.news.tin.it> Message-ID: <4f627c25$0$1381$4fafbaef@reader2.news.tin.it> On 3/15/2012 23:17, Michael Torrie wrote: > On 03/15/2012 09:18 AM, Kiuhnm wrote: >> ----> After early user testing without the colon, it was discovered that >> the meaning of the indentation was unclear to beginners being taught the >> first steps of programming.<---- >> >> The addition of the colon clarified it significantly: the colon somehow >> draws attention to what follows and ties the phrases before and after it >> together in just the right way." >> >> If that passage is correct, those studies don't say that adding the >> colon increases the readability, but that it makes more sense to >> beginners who don't even know what indentation is. > > Seems to me that helping code to make more sense to a beginner is, by > definition, increasing readability. Pick up two math books about the same topic but on two different levels (e.g. under-graduated and graduated). If you compare the proofs you'll see that those in the higher-level book are almost always sketched. Why is that? Because they're more readable for a mature reader. But they're almost incomprehensible to a beginner. As another example, why do people use jargon? Because that makes communication more efficient. And yet that frustrate beginners. So, no, I can't agree with you. There are too many situations where a steep learning curve pays off in the long run. Making that curve too shallow may help beginners but damage experienced users. Is functional programming code more readable than imperative code? Ask a beginner and you'll receive a resounding "no". Ask an experienced coder and he will probably say "it depends". If he says "yes, always" he is a just a lisp fanatic :) Kiuhnm From kiuhnm03.4t.yahoo.it Thu Mar 15 19:46:35 2012 From: kiuhnm03.4t.yahoo.it (Kiuhnm) Date: Fri, 16 Mar 2012 00:46:35 +0100 Subject: Python is readable In-Reply-To: References: <4f612b19$0$1379$4fafbaef@reader2.news.tin.it> <8e72d74f-c844-4de3-8a37-f6b1fdc2291f@y27g2000yqy.googlegroups.com> <50e9ceec-40f1-4ead-b2b6-87328b30d084@ow8g2000pbc.googlegroups.com> <4f61c828$0$1390$4fafbaef@reader2.news.tin.it> <4f61d728$0$1375$4fafbaef@reader2.news.tin.it> <4f61fa8a$0$1381$4fafbaef@reader2.news.tin.it> <4f6202cb$0$1377$4fafbaef@reader2.news.tin.it> <4f6245c5$0$1384$4fafbaef@reader2.news.tin.it> <873999pk52.fsf@benfinney.id.au> Message-ID: <4f627f5c$0$1389$4fafbaef@reader2.news.tin.it> On 3/16/2012 0:00, Arnaud Delobelle wrote: > On 15 March 2012 22:35, Ben Finney wrote: >> Kiuhnm writes: >> >>> Moreover, I think that >>> if (............ >>> ............ >>> ............): >>> ............ >>> ............ >>> ............ >>> is not very readable anyway. >> >> I agree, and am glad PEP 8 has been updated to recommend an extra level >> of indentation for continuation, to distinguish from the new block that >> follows. > > Personally I solve this by never writing if conditions that span more > than one line. If the worst comes to the worst, I would write: > > aptly_named_condition = ( > very long condition > that goes over > plenty of lines > ) > if aptly_named_condition: > do stuff Will I be able to use extra indentation in Python code? For instance, res = and(or(cond1, cond2), cond3, or(and(cond4, cond5, cond6), and(cond7, cond8))) I like it because it reads like a tree. Kiuhnm From steve+comp.lang.python at pearwood.info Thu Mar 15 19:52:01 2012 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 15 Mar 2012 23:52:01 GMT Subject: Python is readable References: <4f612b19$0$1379$4fafbaef@reader2.news.tin.it> <8e72d74f-c844-4de3-8a37-f6b1fdc2291f@y27g2000yqy.googlegroups.com> <50e9ceec-40f1-4ead-b2b6-87328b30d084@ow8g2000pbc.googlegroups.com> <4f61c828$0$1390$4fafbaef@reader2.news.tin.it> <4f61d728$0$1375$4fafbaef@reader2.news.tin.it> <4f61fd0a$0$1389$4fafbaef@reader2.news.tin.it> Message-ID: <4f6280a0$0$29981$c3e8da3$5496439d@news.astraweb.com> On Fri, 16 Mar 2012 01:48:09 +1100, Chris Angelico wrote: > On Fri, Mar 16, 2012 at 1:30 AM, Kiuhnm > wrote: >> Sorry, but I can't see how it would make it harder for humans to >> understand. Are there particular situations you're referring to? > > In a trivial example, it's mostly just noise: > > if a == b # who needs the colon? > print(c) The reader, for the same reason that above you wrote: "In a trivial example, it's mostly just noise COLON" and indeed I too used a colon for the same reason. It ties the lead sentence to the following block without ending the sentence, but still introducing a new grouping or clause. It is *remarkable* how people take the colon for granted. It is so simple and so obvious that they use it in their own writing often without thinking about it, but because it is not strictly necessary to avoid ambiguity in the grammar, they fool themselves into thinking that it is "just noise" or "pointless". It is not noise, it is a hint to the reader. Again, applying to both computer languages and natural languages, leaving out punctuation (either in the grammar, or just out of laziness) is doing a great disservice to the reader. The time the writer saves by not inserting punctuation is lost a million times for the reader (we read text and code thousands of times more than we write it, and there are thousands more readers than writers). Leaving out punctuation is a real pessimation: an example of being "penny wise and pound foolish". -- Steven From ben+python at benfinney.id.au Thu Mar 15 19:57:33 2012 From: ben+python at benfinney.id.au (Ben Finney) Date: Fri, 16 Mar 2012 10:57:33 +1100 Subject: Python is readable References: <4f612b19$0$1379$4fafbaef@reader2.news.tin.it> <8e72d74f-c844-4de3-8a37-f6b1fdc2291f@y27g2000yqy.googlegroups.com> <50e9ceec-40f1-4ead-b2b6-87328b30d084@ow8g2000pbc.googlegroups.com> <4f61c828$0$1390$4fafbaef@reader2.news.tin.it> <4f61d728$0$1375$4fafbaef@reader2.news.tin.it> <4f61fa8a$0$1381$4fafbaef@reader2.news.tin.it> <4f6202cb$0$1377$4fafbaef@reader2.news.tin.it> <4f6245c5$0$1384$4fafbaef@reader2.news.tin.it> <873999pk52.fsf@benfinney.id.au> Message-ID: <87mx7ho1si.fsf@benfinney.id.au> Arnaud Delobelle writes: > On 15 March 2012 22:35, Ben Finney wrote: > > I agree, and am glad PEP 8 has been updated to recommend an extra > > level of indentation for continuation, to distinguish from the new > > block that follows > > . > > Personally I solve this by never writing if conditions that span more > than one line. The admonition applies not only to ?if? conditions, but also to ?while?, ?with?, ?for?, etc.; and also to bracketing constructs like function calls, literal lists/dicts/sets, etc. In a single statement, the indentation for continuation lines should be indented two levels, so that they don't look so much like a new block of statements. -- \ ?If you do not trust the source do not use this program.? | `\ ?Microsoft Vista security dialogue | _o__) | Ben Finney From breamoreboy at yahoo.co.uk Thu Mar 15 19:58:08 2012 From: breamoreboy at yahoo.co.uk (Mark Lawrence) Date: Thu, 15 Mar 2012 23:58:08 +0000 Subject: Python is readable In-Reply-To: <4f627f5c$0$1389$4fafbaef@reader2.news.tin.it> References: <4f612b19$0$1379$4fafbaef@reader2.news.tin.it> <8e72d74f-c844-4de3-8a37-f6b1fdc2291f@y27g2000yqy.googlegroups.com> <50e9ceec-40f1-4ead-b2b6-87328b30d084@ow8g2000pbc.googlegroups.com> <4f61c828$0$1390$4fafbaef@reader2.news.tin.it> <4f61d728$0$1375$4fafbaef@reader2.news.tin.it> <4f61fa8a$0$1381$4fafbaef@reader2.news.tin.it> <4f6202cb$0$1377$4fafbaef@reader2.news.tin.it> <4f6245c5$0$1384$4fafbaef@reader2.news.tin.it> <873999pk52.fsf@benfinney.id.au> <4f627f5c$0$1389$4fafbaef@reader2.news.tin.it> Message-ID: On 15/03/2012 23:46, Kiuhnm wrote: > On 3/16/2012 0:00, Arnaud Delobelle wrote: >> On 15 March 2012 22:35, Ben Finney wrote: >>> Kiuhnm writes: >>> >>>> Moreover, I think that >>>> if (............ >>>> ............ >>>> ............): >>>> ............ >>>> ............ >>>> ............ >>>> is not very readable anyway. >>> >>> I agree, and am glad PEP 8 has been updated to recommend an extra level >>> of indentation for continuation, to distinguish from the new block that >>> follows. >> >> Personally I solve this by never writing if conditions that span more >> than one line. If the worst comes to the worst, I would write: >> >> aptly_named_condition = ( >> very long condition >> that goes over >> plenty of lines >> ) >> if aptly_named_condition: >> do stuff > > Will I be able to use extra indentation in Python code? > For instance, > > res = and(or(cond1, > cond2), > cond3, > or(and(cond4, > cond5, > cond6), > and(cond7, > cond8))) > > I like it because it reads like a tree. > > Kiuhnm Why not find out for yourself by slapping the code into an interactive Python interpreter and seeing what the result is? -- Cheers. Mark Lawrence. From steve+comp.lang.python at pearwood.info Thu Mar 15 20:15:14 2012 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 16 Mar 2012 00:15:14 GMT Subject: Python is readable References: <4f612b19$0$1379$4fafbaef@reader2.news.tin.it> <8e72d74f-c844-4de3-8a37-f6b1fdc2291f@y27g2000yqy.googlegroups.com> <50e9ceec-40f1-4ead-b2b6-87328b30d084@ow8g2000pbc.googlegroups.com> <4f61c828$0$1390$4fafbaef@reader2.news.tin.it> <4f61d728$0$1375$4fafbaef@reader2.news.tin.it> <4f61fa8a$0$1381$4fafbaef@reader2.news.tin.it> <4f6202cb$0$1377$4fafbaef@reader2.news.tin.it> <4f6245c5$0$1384$4fafbaef@reader2.news.tin.it> <873999pk52.fsf@benfinney.id.au> <4f627f5c$0$1389$4fafbaef@reader2.news.tin.it> Message-ID: <4f628611$0$29981$c3e8da3$5496439d@news.astraweb.com> On Fri, 16 Mar 2012 00:46:35 +0100, Kiuhnm wrote: > On 3/16/2012 0:00, Arnaud Delobelle wrote: >> On 15 March 2012 22:35, Ben Finney wrote: >>> Kiuhnm writes: >>> >>>> Moreover, I think that >>>> if (............ >>>> ............ >>>> ............): >>>> ............ >>>> ............ >>>> ............ >>>> is not very readable anyway. >>> >>> I agree, and am glad PEP 8 has been updated to recommend an extra >>> level of indentation for continuation, to distinguish from the new >>> block that >>> follows. >> >> Personally I solve this by never writing if conditions that span more >> than one line. If the worst comes to the worst, I would write: >> >> aptly_named_condition = ( >> very long condition >> that goes over >> plenty of lines >> ) >> if aptly_named_condition: >> do stuff > > Will I be able to use extra indentation in Python code? For instance, > > res = and(or(cond1, > cond2), > cond3, > or(and(cond4, > cond5, > cond6), > and(cond7, > cond8))) Not that exact example, because `and` and `or` are operators, not functions and you will get a syntax error. Python uses infix notation, not prefix or postfix: x and y # yes and(x, y) # no x y and # no But in general, yes, you can use whatever indentation you like inside a line-continuation bracket: py> x = [ ... 1, 2, 3, ... 4, 5, 6, ... 7, 8, 9, ... 10, 11, 12, ... 13, 14, 15 ... ] py> x [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15] Indentation is only syntactically significant in blocks and statements. > I like it because it reads like a tree. Funny. I dislike it because it is a tree on its side. -- Steven From gelonida at gmail.com Thu Mar 15 20:34:44 2012 From: gelonida at gmail.com (Gelonida N) Date: Fri, 16 Mar 2012 01:34:44 +0100 Subject: Is there a ConfigParser which keeps comments In-Reply-To: <20120315214224.GA3390@cskk.homeip.net> References: <4F60DFB8.8080703@tim.thechases.com> <20120315214224.GA3390@cskk.homeip.net> Message-ID: On 03/15/2012 10:42 PM, Cameron Simpson wrote: > On 14Mar2012 13:13, Tim Chase wrote: > | On 03/14/12 12:06, Terry Reedy wrote: > | > On 3/14/2012 6:07 AM, Gelonida N wrote: > | >> Now I'm looking for a library, which behaves like config parser, but > | >> with one minor difference. > | >> > | >> The write() mehtod should keep existing comments. > | > > | > Assuming that you have not overlooked anything, I would just subclass > | > ConfigParser with an altered write method. > | > | It would require a lot more than that. It would entail changing > | the reading as well so that it preserved the comments as well as > | the order of sections & keys, and a way of storing those > | associated comments in sequence. I looked into it a fair while > | back and it was a LOT more work than I cared to do for minimal > | gain. I wimped out and just documented it with "If you use the > | ability to (re)write a configuration file, it will not keep any > | comments or ordering from any original sources." > > A low cost approach might be to patch the file instead of transcribing > the in-memory state. Not the same semantics, but it would not be too > hard to add a patch_config(filename, section, setting, value) that read > the old file and wrote a new one with an adjusted section, ignoring the > in-memory state (indeed, on that basis the siganture isn't a method but > a standalone function). > > The logic is easy enough that I even wrote a shell script in 2004 to do > essentially this: > > https://bitbucket.org/cameron_simpson/css/src/ef42896872b5/bin/winclauseappend > > One could imagine an efficient python implementation and a ConfigParser > subclass that patched the file if a setting got changed, or had a .patch > method to apply particular setting changes as desired. > Agreed, patching is simpler than parsing the file and keeping all the comment info in the config object. I will also look at ConfigObj as suggested by Steven and Karim If this does what I want, then it's probably less effort to use this library than patching Configparser. From steve+comp.lang.python at pearwood.info Thu Mar 15 21:53:44 2012 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 16 Mar 2012 01:53:44 GMT Subject: Python is readable References: <4f612b19$0$1379$4fafbaef@reader2.news.tin.it> Message-ID: <4f629d27$0$29981$c3e8da3$5496439d@news.astraweb.com> On Thu, 15 Mar 2012 00:34:47 +0100, Kiuhnm wrote: > I've just started to read > The Quick Python Book (2nd ed.) Is this the one? http://manning.com/ceder/ > The author claims that Python code is more readable than Perl code and > provides this example: > > --- Perl --- > sub pairwise_sum { > my($arg1, $arg2) = @_; > my(@result) = (); > @list1 = @$arg1; > @list2 = @$arg2; I don't understand the reason for $arg1 and $arg2. Is there some reason why the code couldn't do this instead? my(@list1, @list2) = @_; > for($i=0; $i < length(@list1); $i++) { > push(@result, $list1[$i] + $list2[$i]); > } > return(\@result); > } > > --- Python --- > def pairwise_sum(list1, list2): > result = [] > for i in range(len(list1)): > result.append(list1[i] + list2[i]) > return result > --- --- > > It's quite clear that he knows little about Perl. On the contrary -- it is quite clear that you are missing the point of the comparison, which is not to compare the most idiomatic Perl with the most idiomatic Python, but to make a direct comparison of syntax for the purpose of teaching beginners. The problem with idiomatic comparisons is that they often don't give you a feel for the overall language syntax. Instead they end up comparing built-ins. For example, here is how I would write the above pairwise addition using idiomatic RPL, the Forth-like programming language used on some Hewlett-Packard scientific calculators: ADD That's it. One word. Would you conclude from this that RPL is easier to read and write than Python? I can tell you that it is not, and I *like* stack-based languages that use reverse Polish Notation. > Here's what I would've written: > > sub pairwise_sum { > my ($list1, $list2) = @_; > my @result; > push @result, $list1->[$_] + $list2->[$_] for (0..@$list1-1); > \@result; > } > > Having said that, the Python code is still more readable, so there's no > need to misrepresent Perl that way. Speaking as somebody who doesn't know Perl, I think that your version would do a great disservice to Perl. Your version is shorter, but conciseness is often in opposition to readability. Without the author's version above, and the function name, I would have literally NO IDEA what your version does. It is virtually pure line-noise. I know enough Perl to guess that @result might be an array, and so guess that push pushes a value onto the array, but the rest might as well be written in Martian. Or APL. The author's version above, which you denigrate, is *much* more understandable than your more idiomatic Perl, especially since I can compare it feature to feature with the Python code. Far from misrepresenting Perl, he has gone out of his way to show Perl in the best possible light. Idiomatic Perl code, written by experts, is even more incomprehensible and unreadable to non-Perl hackers than his example. > Now I'm wondering whether the author will show me "good" or "bad" Python > code throughout the book. Should I keep reading? >From what you have show, and the sample chapters on the link above, I am impressed. The author is aiming to teach basic concepts and impart *understanding* rather than just force-feed the reader idioms which would be incomprehensible to them. Vern Cedar (the author) is an actual professional teacher, and from the samples I have seen, he knows what he is doing. -- Steven From d at davea.name Thu Mar 15 22:00:43 2012 From: d at davea.name (Dave Angel) Date: Thu, 15 Mar 2012 22:00:43 -0400 Subject: Is it technically possible to give Python option of naming process of running script? In-Reply-To: References: <19118128.4791.1331736187952.JavaMail.geo-discussion-forums@vbai14> <22071354.8904.1331796412001.JavaMail.geo-discussion-forums@vbkc1> Message-ID: <4F629ECB.3090104@davea.name> On 03/15/2012 02:39 PM, Grant Edwards wrote: > On 2012-03-15, Dave Angel wrote: >> On 03/15/2012 03:26 AM, xliiv wrote: >>>>>> Like the topic.. . >>>>>> I use Python a lot, both Windows and Linux, and it's little weird to have many python process without fast distinction which is what. >>> I did google, I've played with Exemaker (it works perfect, but not py3) and i've seen questions on Stackoverflow. >>> The thing I mean is a build feature of python to give such a name. Not 3rd part or etc. like Grant Edwards said. Is it possible? >> How about simply using cp to copy the python executable, run chmod +x on >> it, and run that one? Then ps would list it as the new name, not as python. > That's rather a waste of memory. Better to use a link. That way the > executable can still be shared by multiple programs and won't be > duplicated in memory. > >> i tried it on /usr/bin/python2.7 but I see no reason the same >> approach won't work on 3.x Note, I copied it to a new name in the same >> directory, which may be important. or not. > Seems like an awfully obtuse way of doing things -- I don't really > want to have 15 different copies of Python (or even links), and it > requires root privleges every time you want to run a Python program > with the "correct" name. > Good point about using a link. I was trying to make something that would probably also work in Windows. As for the needing of root privileges, that's only for those programs you need to be able to identify with ps, and only one time for each. Anyway, it's a response to a specific need, which I don't share, and it was my second suggestion, not first. -- DaveA From steve+comp.lang.python at pearwood.info Thu Mar 15 22:03:59 2012 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 16 Mar 2012 02:03:59 GMT Subject: Python is readable References: <4f612b19$0$1379$4fafbaef@reader2.news.tin.it> Message-ID: <4f629f8e$0$29981$c3e8da3$5496439d@news.astraweb.com> On Thu, 15 Mar 2012 20:54:30 +0000, Arnaud Delobelle wrote: > On 15 March 2012 00:27, Chris Angelico wrote: >> On Thu, Mar 15, 2012 at 10:54 AM, Arnaud Delobelle >> wrote: >>> I don't know this book and there may be a pedagogical reason for the >>> implementation you quote, but pairwise_sum is probably better >>> implemented in Python 3.X as: >>> >>> def pairwise_sum(list1, list2): >>> ? ?return [x1 + x2 for x1, x2 in zip(list1, list2)] >> >> Okay, here's something for debate. >> >> Should the readability of a language be gauged on the basis of its >> standard library, or should you be comparing actual code? > > But here's the code posted by the OP: > > --- Python --- > def pairwise_sum(list1, list2): > result = [] > for i in range(len(list1)): > result.append(list1[i] + list2[i]) > return result > --- --- > > The code I posted uses one builtin function (zip), the code posted by > the OP uses two (range and len). Neither uses the standard library. For beginners, code using range and len is MUCH easier to understand than code using zip. len is obviously short for length, and range (at least in the one-argument version) is simple to explain. But zip? To understand zip, you need to have a good concept of iteration in your head. When writing for beginners, you can't assume that. For beginners, the most idiomatic code is not necessarily the simplest code. I would never start beginners with a list comprehension: result = [a+b for a,b in zip(list1, list2)] which is likely to be just incomprehensible jargon. You need to understand the syntax, which may not be obvious even to people with a mathematics background. (List comps are copied from Haskell, where they derive their syntax from mathematicians' set notation.) You need to understand zip, which requires having a good mental model of element-wise iteration. Although it is longer and less idiomatic, the Python1.5-ish result = [] for i in range(len(list1)): result.append(list1[i] + list2[i]) is likely to be simpler to understand. The downside is that experienced programmers may roll their eyes at how you are dumbing down the code, or worse, accusing you of deliberately misrepresenting the language. -- Steven From breamoreboy at yahoo.co.uk Thu Mar 15 22:16:34 2012 From: breamoreboy at yahoo.co.uk (Mark Lawrence) Date: Fri, 16 Mar 2012 02:16:34 +0000 Subject: Python is readable In-Reply-To: <4f629d27$0$29981$c3e8da3$5496439d@news.astraweb.com> References: <4f612b19$0$1379$4fafbaef@reader2.news.tin.it> <4f629d27$0$29981$c3e8da3$5496439d@news.astraweb.com> Message-ID: On 16/03/2012 01:53, Steven D'Aprano wrote: > On Thu, 15 Mar 2012 00:34:47 +0100, Kiuhnm wrote: > >> I've just started to read >> The Quick Python Book (2nd ed.) > > Is this the one? > > http://manning.com/ceder/ > > >> The author claims that Python code is more readable than Perl code and >> provides this example: >> >> --- Perl --- >> sub pairwise_sum { >> my($arg1, $arg2) = @_; >> my(@result) = (); >> @list1 = @$arg1; >> @list2 = @$arg2; > > I don't understand the reason for $arg1 and $arg2. Is there some reason > why the code couldn't do this instead? > > my(@list1, @list2) = @_; > > >> for($i=0; $i< length(@list1); $i++) { >> push(@result, $list1[$i] + $list2[$i]); >> } >> return(\@result); >> } >> >> --- Python --- >> def pairwise_sum(list1, list2): >> result = [] >> for i in range(len(list1)): >> result.append(list1[i] + list2[i]) >> return result >> --- --- >> >> It's quite clear that he knows little about Perl. > > On the contrary -- it is quite clear that you are missing the point of > the comparison, which is not to compare the most idiomatic Perl with the > most idiomatic Python, but to make a direct comparison of syntax for the > purpose of teaching beginners. > > The problem with idiomatic comparisons is that they often don't give you > a feel for the overall language syntax. Instead they end up comparing > built-ins. For example, here is how I would write the above pairwise > addition using idiomatic RPL, the Forth-like programming language used on > some Hewlett-Packard scientific calculators: > > ADD > > That's it. One word. Would you conclude from this that RPL is easier to > read and write than Python? I can tell you that it is not, and I *like* > stack-based languages that use reverse Polish Notation. > > >> Here's what I would've written: >> >> sub pairwise_sum { >> my ($list1, $list2) = @_; >> my @result; >> push @result, $list1->[$_] + $list2->[$_] for (0..@$list1-1); >> \@result; >> } >> >> Having said that, the Python code is still more readable, so there's no >> need to misrepresent Perl that way. > > Speaking as somebody who doesn't know Perl, I think that your version > would do a great disservice to Perl. Your version is shorter, but > conciseness is often in opposition to readability. Without the author's > version above, and the function name, I would have literally NO IDEA what > your version does. It is virtually pure line-noise. I know enough Perl to > guess that @result might be an array, and so guess that push pushes a > value onto the array, but the rest might as well be written in Martian. > Or APL. > > The author's version above, which you denigrate, is *much* more > understandable than your more idiomatic Perl, especially since I can > compare it feature to feature with the Python code. > > Far from misrepresenting Perl, he has gone out of his way to show Perl in > the best possible light. Idiomatic Perl code, written by experts, is even > more incomprehensible and unreadable to non-Perl hackers than his example. > > >> Now I'm wondering whether the author will show me "good" or "bad" Python >> code throughout the book. Should I keep reading? > >> From what you have show, and the sample chapters on the link above, I am > impressed. The author is aiming to teach basic concepts and impart > *understanding* rather than just force-feed the reader idioms which would > be incomprehensible to them. Vern Cedar (the author) is an actual > professional teacher, and from the samples I have seen, he knows what he > is doing. > > Well put Sir. And (seriously) when making your comments you show the killer instincts of a great bowler in an Ashes Test Match, now could there be anything more important in life or showing greater esteem than that? -- Cheers. Mark Lawrence. From rex.0510 at gmail.com Thu Mar 15 22:23:41 2012 From: rex.0510 at gmail.com (choi2k) Date: Thu, 15 Mar 2012 19:23:41 -0700 (PDT) Subject: Python simulate browser activity Message-ID: <214c4c0c-f8ec-4030-946b-8becc8e1aa9c@ur9g2000pbc.googlegroups.com> Hi, everyone I am trying to write a small application using python but I am not sure whether it is possible to do so.. The application aims to simulate user activity including visit a website and perform some interactive actions (click on the menu, submit a form, redirect to another pages...etc) I have found some libraries / plugins which aims to simulate browser activity but ... none of them support AJAX request and/or running javascript. Here is one of the simple tasks which I would like to do using the application: 1. simulate the user activity, visit the website ("https:// www.abc.com") 2. find out the target element by id ("submitBtn") and simulate mouse click on the item. 3. perform some javascript functions which invoked by click event from step 2. ( the function is bind to the item by jquery) 4. post ajax request using javascript and if the page has been redirected, load the new page content Is it possible to do so? Thank you in advance. From clp2 at rebertia.com Thu Mar 15 22:54:03 2012 From: clp2 at rebertia.com (Chris Rebert) Date: Thu, 15 Mar 2012 19:54:03 -0700 Subject: Python simulate browser activity In-Reply-To: <214c4c0c-f8ec-4030-946b-8becc8e1aa9c@ur9g2000pbc.googlegroups.com> References: <214c4c0c-f8ec-4030-946b-8becc8e1aa9c@ur9g2000pbc.googlegroups.com> Message-ID: On Thu, Mar 15, 2012 at 7:23 PM, choi2k wrote: > Hi, everyone > > I am trying to write a small application using python but I am not > sure whether it is possible to do so.. > The application aims to simulate user activity including visit a > website and perform some interactive actions (click on the menu, > submit a form, redirect to another pages...etc) > I have found some libraries / plugins which aims to simulate browser > activity but ... none of them support AJAX request and/or running > javascript. Did you look at Selenium? http://seleniumhq.org/ Cheers, Chris From rosuav at gmail.com Thu Mar 15 23:12:44 2012 From: rosuav at gmail.com (Chris Angelico) Date: Fri, 16 Mar 2012 14:12:44 +1100 Subject: Python is readable In-Reply-To: <4f6280a0$0$29981$c3e8da3$5496439d@news.astraweb.com> References: <4f612b19$0$1379$4fafbaef@reader2.news.tin.it> <8e72d74f-c844-4de3-8a37-f6b1fdc2291f@y27g2000yqy.googlegroups.com> <50e9ceec-40f1-4ead-b2b6-87328b30d084@ow8g2000pbc.googlegroups.com> <4f61c828$0$1390$4fafbaef@reader2.news.tin.it> <4f61d728$0$1375$4fafbaef@reader2.news.tin.it> <4f61fd0a$0$1389$4fafbaef@reader2.news.tin.it> <4f6280a0$0$29981$c3e8da3$5496439d@news.astraweb.com> Message-ID: On Fri, Mar 16, 2012 at 10:52 AM, Steven D'Aprano wrote: > On Fri, 16 Mar 2012 01:48:09 +1100, Chris Angelico wrote: > >> In a trivial example, it's mostly just noise: >> >> if a == b ? ?# who needs the colon? >> ? ? print(c) > > The reader, for the same reason that above you wrote: > > "In a trivial example, it's mostly just noise COLON" > > and indeed I too used a colon for the same reason. It ties the lead > sentence to the following block without ending the sentence, but still > introducing a new grouping or clause. Yep. As everyone who communicates on the internet knows, punctuation can often be omitted without introducing ambiguity. That doesn't mean it *should* be omitted. NOT TELEGRAMS TODAY STOP ChrisA From rosuav at gmail.com Thu Mar 15 23:14:03 2012 From: rosuav at gmail.com (Chris Angelico) Date: Fri, 16 Mar 2012 14:14:03 +1100 Subject: Is it technically possible to give Python option of naming process of running script? In-Reply-To: References: <19118128.4791.1331736187952.JavaMail.geo-discussion-forums@vbai14> <22071354.8904.1331796412001.JavaMail.geo-discussion-forums@vbkc1> Message-ID: On Fri, Mar 16, 2012 at 5:39 AM, Grant Edwards wrote: > Seems like an awfully obtuse way of doing things -- I don't really > want to have 15 different copies of Python (or even links), and it > requires root privleges every time you want to run a Python program > with the "correct" name. Why do you need root? Can't you copy / link into your own home directory? I may have misunderstood something here. ChrisA From malaclypse2 at gmail.com Thu Mar 15 23:44:29 2012 From: malaclypse2 at gmail.com (Jerry Hill) Date: Thu, 15 Mar 2012 23:44:29 -0400 Subject: Python simulate browser activity In-Reply-To: References: <214c4c0c-f8ec-4030-946b-8becc8e1aa9c@ur9g2000pbc.googlegroups.com> Message-ID: On Thu, Mar 15, 2012 at 10:54 PM, Chris Rebert wrote: > On Thu, Mar 15, 2012 at 7:23 PM, choi2k wrote: >> The application aims to simulate user activity including visit a >> website and perform some interactive actions (click on the menu, >> submit a form, redirect to another pages...etc) > > Did you look at Selenium? > http://seleniumhq.org/ You might also be interested in Sikuli (http://sikuli.org/), which uses Jython to write scripts to automate other programs using screenshots. It's pretty neat if you need to automate a GUI that is otherwise difficult to deal with. -- Jerry From steve+comp.lang.python at pearwood.info Thu Mar 15 23:55:43 2012 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 16 Mar 2012 03:55:43 GMT Subject: Python is readable References: <4f612b19$0$1379$4fafbaef@reader2.news.tin.it> <8e72d74f-c844-4de3-8a37-f6b1fdc2291f@y27g2000yqy.googlegroups.com> <50e9ceec-40f1-4ead-b2b6-87328b30d084@ow8g2000pbc.googlegroups.com> <4f61c828$0$1390$4fafbaef@reader2.news.tin.it> <4f61d728$0$1375$4fafbaef@reader2.news.tin.it> <4f61fd0a$0$1389$4fafbaef@reader2.news.tin.it> <4f620837$0$1382$4fafbaef@reader2.news.tin.it> <4f627c25$0$1381$4fafbaef@reader2.news.tin.it> Message-ID: <4f62b9be$0$29981$c3e8da3$5496439d@news.astraweb.com> On Fri, 16 Mar 2012 00:32:52 +0100, Kiuhnm wrote: > Pick up two math books about the same topic but on two different levels > (e.g. under-graduated and graduated). If you compare the proofs you'll > see that those in the higher-level book are almost always sketched. Why > is that? Because they're more readable for a mature reader. No. They're not more readable. They simply have less to read (per proof), or another way of putting it, you can fit more of the good stuff that the experienced reader wants ("yes yes, I know about the associative law, get to the part where you prove the Goldbach conjecture...") in the same amount of space. The text is compressed by leaving out the parts that an experienced reader can infer from her knowledge of the domain. Since an expert can infer meaning more quickly than they can read the actual words, this is a big win for efficiency. But the text is not more readable, there's just less to read for a given result. The same amount, or even more, brain processing occurs. It just happens in a different part of the brain. In Python terms, it's analogous to moving something out of a pure-Python O(log n) binary tree into a fast O(n) linear array written in C. Until the concepts get complex enough, it is faster for the expert to infer meaning than to read explicitly, even though technically more work is probably being done. Experts often find pedagogical texts harder to read because it seems dumbed down. It's as if they are reading text like this: The cat, which is a small animal with fur known for being aloof and yet attractive to many people, sat on the mat, which is like a rug or blanket except thicker, while Jack, a small male child, and Jill, a young female child, ran, that is to say travelled quickly by lifting their feet and moving forward in such a fashion that sometimes both feet are in the air simultaneously, up the hill, a moderately- sized elevation of land smaller than a mountain. It gets painful after a while because, as an expert, you can interpret the subtext quicker than you can read the actual words. But when teaching non-experts, you can't expect the reader to interpret the subtext quickly or at all. Which is more readable, that is to say, more comprehensible? The wix sat on the zaj, while Megf and Parz vev up the leff. Lacking any domain knowledge, the above carries virtually no information at all. We know that wixes can sit on things, and that's about it. Contrast this: The wix, which is a small animal with fur known for being aloof and yet attractive to many people, sat on the zaj, which is like a rug or blanket except thicker, while Megf, a small male child, and Parz, a young female child, vev, that is to say travelled quickly by lifting their feet and moving forward in such a fashion that sometimes both feet are in the air simultaneously, up the leff, a moderately- sized elevation of land smaller than a mountain. Despite having about 8 times as much content, and being one long run-on sentence, this version is far more comprehensible. (In practice, I wouldn't define terms in the sentence I was using them in this fashion. Or at least not more than one per sentence. Very long sentences have their own readability costs.) When people talk about readability, they normally mean to ask how much mental effort is needed to interpret the meaning of the text, not how much time does it take to pass your eyes over the characters. In other words they are actually talking about comprehensibility. Well obviously that depends on who is doing the reading. To somebody in the know, meaning can be incredibly compressed. You can crack up Monty Python fans with just two words: "Norwegian Blue". To those not in the know, that's incomprehensible. When speaking about programming languages, the reader who is judging readability is assumed to be: - somebody with a good grasp of natural language, normally English, and capable of understanding sentences containing loops and conditionals such as "soak and rinse the beans three times" "scrub the potatoes until the dirt is gone" "if the tap is dripping, replace the washer" - possessing an intuitive understanding of such concepts as "is-a" and "has-a" (Fido is a dog, Fido has a tail); - possessing a simple knowledge of basic arithmetic and logic; - able to intuit the meaning of programming concepts if they match simple natural language concepts (e.g. print, delete, but not necessarily import, delegate, and certainly not currying, closures, monads); - but not familiar with the programming language, its data model, or the details of its functions and commands; - and of average intelligence, neither a dummy nor a genius. (Despite the proliferation of books with titles like "Programming For Utter Morans", they aren't actually written for dummies.) To judge the readability of a language, we have to put ourselves into the position of such a beginner: ignorant but not stupid. To judge the expressibility and power of a language, we have to put ourselves into the position of an expert who knows all the idioms. The trick is to increase power without hurting readability. For example, in the late 80s or early 90s, Apple introduced the forerunner to Applescript, Hypertalk. Hypertalk is *extremely* readable: put the result into x add 15 to x go to the second card of background "Data" put x after word 7 of field "Age" get field "Name" put it into field "Alias" Aside: there's a non-GUI version of Hypertalk-on-steroids available from here: http://code.google.com/p/openxion/ Very readable indeed. You can possibly even infer part of the data model from the code (everything is text; text is stored in fields, which exist on cards collected into groupings called backgrounds). But, frankly, it's not too expressible. It's too verbose for experts. The data model is too simple. (Modern versions like OpenXion have a richer data model not as strongly tied to the original Hypercard GUI.) I think Python is pretty close to the top of the readability versus expressiveness curve. That's not to say that Python is the optimal combination, or can't be improved, or even that every language should compromise expressiveness for comprehensibility (or vice versa). -- Steven From aasayanisen at gmail.com Fri Mar 16 00:45:06 2012 From: aasayanisen at gmail.com (Sayani Sen) Date: Thu, 15 Mar 2012 21:45:06 -0700 (PDT) Subject: easy earn at home 50000 per month Message-ID: <30257078.288.1331873106000.JavaMail.geo-discussion-forums@pbcwe9> http://unlimitedmoney.yolasite.com From slo at hep.caltech.edu Fri Mar 16 02:47:36 2012 From: slo at hep.caltech.edu (Steven Lo) Date: Thu, 15 Mar 2012 23:47:36 -0700 Subject: cannot open shared object file Message-ID: <4F62E208.70005@hep.caltech.edu> Hi, We are getting the following error during a 'make' process on a CentOS release 5.4 system: Running mkfontdir... Creating SELinux policy... /usr/bin/python: error while loading shared libraries: libpython2.4.so.1.0: cannot open shared object file: No such file or directory However, we are able to execute 'python' without any problem # which python /usr/bin/python # python Python 2.4.3 (#1, Sep 3 2009, 15:37:37) [GCC 4.1.2 20080704 (Red Hat 4.1.2-46)] on linux2 Type "help", "copyright", "credits" or "license" for more information. >>> # ldd /usr/bin/python libpython2.4.so.1.0 => /usr/lib64/libpython2.4.so.1.0 (0x0000003fb7600000) libpthread.so.0 => /lib64/libpthread.so.0 (0x0000003b59600000) libdl.so.2 => /lib64/libdl.so.2 (0x0000003b59200000) libutil.so.1 => /lib64/libutil.so.1 (0x0000003b64000000) libm.so.6 => /lib64/libm.so.6 (0x0000003b58e00000) libc.so.6 => /lib64/libc.so.6 (0x0000003b58a00000) /lib64/ld-linux-x86-64.so.2 (0x0000003b58600000) # ls -lad /usr/lib64/*python* lrwxrwxrwx 1 root root 19 Feb 27 21:15 /usr/lib64/libpython2.4.so -> libpython2.4.so.1.0 -r-xr-xr-x 1 root root 1236344 Sep 3 2009 /usr/lib64/libpython2.4.so.1.0 drwxr-xr-x 18 root root 20480 Feb 27 21:15 /usr/lib64/python2.4 In this 'make' process, we are suppose to execute the applicate-specific python (/opt/rocks/bin/python) which has static link (not dynamic link) # ldd /opt/rocks/bin/python libpthread.so.0 => /lib64/libpthread.so.0 (0x0000003b59600000) libdl.so.2 => /lib64/libdl.so.2 (0x0000003b59200000) libutil.so.1 => /lib64/libutil.so.1 (0x0000003b64000000) libstdc++.so.6 => /usr/lib64/libstdc++.so.6 (0x0000003b6b400000) libm.so.6 => /lib64/libm.so.6 (0x0000003b58e00000) libgcc_s.so.1 => /lib64/libgcc_s.so.1 (0x0000003b67c00000) libc.so.6 => /lib64/libc.so.6 (0x0000003b58a00000) /lib64/ld-linux-x86-64.so.2 (0x0000003b58600000) Basically, we try to understand: * why /opt/rocks/bin/python not being used ? * why /usr/bin/python can not find the dynamic library Please let us know if you have any suggestion on how to troubleshoot this problem. If this is not the list to ask this type of question, please point us to the appropriate list. Thanks. S. -------------- next part -------------- An HTML attachment was scrubbed... URL: From tymoteusz.jankowski at gmail.com Fri Mar 16 04:19:38 2012 From: tymoteusz.jankowski at gmail.com (xliiv) Date: Fri, 16 Mar 2012 01:19:38 -0700 (PDT) Subject: Is it technically possible to give Python option of naming process of running script? In-Reply-To: References: <19118128.4791.1331736187952.JavaMail.geo-discussion-forums@vbai14> <22071354.8904.1331796412001.JavaMail.geo-discussion-forums@vbkc1> Message-ID: <19653171.562.1331885978787.JavaMail.geo-discussion-forums@vbbfw10> > > Seems like an awfully obtuse way of doing things -- I don't really > > want to have 15 different copies of Python (or even links), and it > > requires root privleges every time you want to run a Python program > > with the "correct" name. > > Why do you need root? Can't you copy / link into your own home directory? > > I may have misunderstood something here. > > ChrisA It's nice walkaround for now and for linux. But how about my question and future? :) From tymoteusz.jankowski at gmail.com Fri Mar 16 04:19:38 2012 From: tymoteusz.jankowski at gmail.com (xliiv) Date: Fri, 16 Mar 2012 01:19:38 -0700 (PDT) Subject: Is it technically possible to give Python option of naming process of running script? In-Reply-To: References: <19118128.4791.1331736187952.JavaMail.geo-discussion-forums@vbai14> <22071354.8904.1331796412001.JavaMail.geo-discussion-forums@vbkc1> Message-ID: <19653171.562.1331885978787.JavaMail.geo-discussion-forums@vbbfw10> > > Seems like an awfully obtuse way of doing things -- I don't really > > want to have 15 different copies of Python (or even links), and it > > requires root privleges every time you want to run a Python program > > with the "correct" name. > > Why do you need root? Can't you copy / link into your own home directory? > > I may have misunderstood something here. > > ChrisA It's nice walkaround for now and for linux. But how about my question and future? :) From Peter.Condon at airwavesolutions.co.uk Fri Mar 16 05:20:50 2012 From: Peter.Condon at airwavesolutions.co.uk (Peter Condon) Date: Fri, 16 Mar 2012 09:20:50 +0000 Subject: Android Message-ID: <8AF12430BDA2C6479273908A1873E24516BE65C6@AMRGBEX01.airmis.airwave.pri> Dear Sirs, I am a new student learning this and am getting an Android tablet for my birthday will python be able to run on android? Kindest regards Peter This email and any attachments to it may contain information which is confidential, legally privileged, subject to the Official Secrets Act, or otherwise not disclosable by law, and is protected by copyright. It is intended only for the addressee named above. If you are not the intended recipient you must delete this email immediately and not use, distribute, copy, disclose or take any action in reliance on this email or its contents. If you have received this email in error please notify us by return email immediately. Airwave Solutions Limited is a company registered in England and Wales having company number 03985643. Registered Office: Airwave Solutions Ltd, Charter Court, 50 Windsor Road, Slough, Berkshire, SL1 2EJ. -------------- next part -------------- An HTML attachment was scrubbed... URL: From duncan.booth at invalid.invalid Fri Mar 16 05:30:17 2012 From: duncan.booth at invalid.invalid (Duncan Booth) Date: 16 Mar 2012 09:30:17 GMT Subject: Python is readable References: <4f612b19$0$1379$4fafbaef@reader2.news.tin.it> <8e72d74f-c844-4de3-8a37-f6b1fdc2291f@y27g2000yqy.googlegroups.com> <50e9ceec-40f1-4ead-b2b6-87328b30d084@ow8g2000pbc.googlegroups.com> <4f61c828$0$1390$4fafbaef@reader2.news.tin.it> <4f61d728$0$1375$4fafbaef@reader2.news.tin.it> Message-ID: Thomas Rachel wrote: >> Or, more likely, lock creates an object which keeps the lock "acquired". >> The lock is released when we leave the block. >> So we could inspect the lock with >> with lock as l: >> inspect l... >> do_some..... > > Or just inspect l - I don't know if a lock's __enter__ methos returns it > again for assignment with "as"... > No, if you do `with lock as l:` then l will get the boolean True. The lock's __enter__ method is the same as lock.acquire(). That method takes an optional argument which can be used to conditionally acquire the lock and return a boolean indicating success or failure. When used inside a `with` statement you can't pass in the optional argument so it acquires it unconditionally but still returns the success status which is either True or it never returns. -- Duncan Booth http://kupuguy.blogspot.com From patrick.szabo at lexisnexis.at Fri Mar 16 07:38:55 2012 From: patrick.szabo at lexisnexis.at (Szabo, Patrick (LNG-VIE)) Date: Fri, 16 Mar 2012 12:38:55 +0100 Subject: AW: Android In-Reply-To: <8AF12430BDA2C6479273908A1873E24516BE65C6@AMRGBEX01.airmis.airwave.pri> References: <8AF12430BDA2C6479273908A1873E24516BE65C6@AMRGBEX01.airmis.airwave.pri> Message-ID: You might be interested in this: http://www.linuxjournal.com/article/10940 I had this installed on my Desire and it ran pretty nicely. regards Von: python-list-bounces+patrick.szabo=lexisnexis.at at python.org [mailto:python-list-bounces+patrick.szabo=lexisnexis.at at python.org] Im Auftrag von Peter Condon Gesendet: Freitag, 16. M?rz 2012 10:21 An: python-list at python.org Betreff: Android Dear Sirs, I am a new student learning this and am getting an Android tablet for my birthday will python be able to run on android? Kindest regards Peter This email and any attachments to it may contain information which is confidential, legally privileged, subject to the Official Secrets Act, or otherwise not disclosable by law, and is protected by copyright. It is intended only for the addressee named above. If you are not the intended recipient you must delete this email immediately and not use, distribute, copy, disclose or take any action in reliance on this email or its contents. If you have received this email in error please notify us by return email immediately. Airwave Solutions Limited a company registered in England and Wales having company number 03985643. Registered Office: Airwave Solutions Ltd, Charter Court, 50 Windsor Road, Slough, Berkshire, SL1 2EJ. . . . . . . . . . . . . . . . . . . . . . . . . . . Ing. Patrick Szabo XSLT Developer LexisNexis A-1030 Wien, Marxergasse 25 mailto:patrick.szabo at lexisnexis.at Tel.: +43 1 53452 1573 Fax: +43 1 534 52 146 -------------- next part -------------- An HTML attachment was scrubbed... URL: From kiuhnm03.4t.yahoo.it Fri Mar 16 07:41:49 2012 From: kiuhnm03.4t.yahoo.it (Kiuhnm) Date: Fri, 16 Mar 2012 12:41:49 +0100 Subject: Python is readable In-Reply-To: References: <4f612b19$0$1379$4fafbaef@reader2.news.tin.it> <8e72d74f-c844-4de3-8a37-f6b1fdc2291f@y27g2000yqy.googlegroups.com> <50e9ceec-40f1-4ead-b2b6-87328b30d084@ow8g2000pbc.googlegroups.com> <4f61c828$0$1390$4fafbaef@reader2.news.tin.it> <4f61d728$0$1375$4fafbaef@reader2.news.tin.it> <4f61fa8a$0$1381$4fafbaef@reader2.news.tin.it> <4f6202cb$0$1377$4fafbaef@reader2.news.tin.it> <4f6245c5$0$1384$4fafbaef@reader2.news.tin.it> <873999pk52.fsf@benfinney.id.au> <4f627f5c$0$1389$4fafbaef@reader2.news.tin.it> Message-ID: <4f6326fe$0$1381$4fafbaef@reader1.news.tin.it> On 3/16/2012 0:58, Mark Lawrence wrote: > On 15/03/2012 23:46, Kiuhnm wrote: >> On 3/16/2012 0:00, Arnaud Delobelle wrote: >>> On 15 March 2012 22:35, Ben Finney wrote: >>>> Kiuhnm writes: >>>> >>>>> Moreover, I think that >>>>> if (............ >>>>> ............ >>>>> ............): >>>>> ............ >>>>> ............ >>>>> ............ >>>>> is not very readable anyway. >>>> >>>> I agree, and am glad PEP 8 has been updated to recommend an extra level >>>> of indentation for continuation, to distinguish from the new block that >>>> follows. >>> >>> Personally I solve this by never writing if conditions that span more >>> than one line. If the worst comes to the worst, I would write: >>> >>> aptly_named_condition = ( >>> very long condition >>> that goes over >>> plenty of lines >>> ) >>> if aptly_named_condition: >>> do stuff >> >> Will I be able to use extra indentation in Python code? >> For instance, >> >> res = and(or(cond1, >> cond2), >> cond3, >> or(and(cond4, >> cond5, >> cond6), >> and(cond7, >> cond8))) >> >> I like it because it reads like a tree. >> >> Kiuhnm > > Why not find out for yourself by slapping the code into an interactive > Python interpreter and seeing what the result is? Ok, it works. I had to use different names though. Kiuhnm From kiuhnm03.4t.yahoo.it Fri Mar 16 08:10:12 2012 From: kiuhnm03.4t.yahoo.it (Kiuhnm) Date: Fri, 16 Mar 2012 13:10:12 +0100 Subject: Python is readable In-Reply-To: <4f62b9be$0$29981$c3e8da3$5496439d@news.astraweb.com> References: <4f612b19$0$1379$4fafbaef@reader2.news.tin.it> <8e72d74f-c844-4de3-8a37-f6b1fdc2291f@y27g2000yqy.googlegroups.com> <50e9ceec-40f1-4ead-b2b6-87328b30d084@ow8g2000pbc.googlegroups.com> <4f61c828$0$1390$4fafbaef@reader2.news.tin.it> <4f61d728$0$1375$4fafbaef@reader2.news.tin.it> <4f61fd0a$0$1389$4fafbaef@reader2.news.tin.it> <4f620837$0$1382$4fafbaef@reader2.news.tin.it> <4f627c25$0$1381$4fafbaef@reader2.news.tin.it> <4f62b9be$0$29981$c3e8da3$5496439d@news.astraweb.com> Message-ID: <4f632da5$0$1375$4fafbaef@reader1.news.tin.it> On 3/16/2012 4:55, Steven D'Aprano wrote: > On Fri, 16 Mar 2012 00:32:52 +0100, Kiuhnm wrote: > >> Pick up two math books about the same topic but on two different levels >> (e.g. under-graduated and graduated). If you compare the proofs you'll >> see that those in the higher-level book are almost always sketched. Why >> is that? Because they're more readable for a mature reader. > > No. They're not more readable. They simply have less to read (per proof), > or another way of putting it, you can fit more of the good stuff that the > experienced reader wants ("yes yes, I know about the associative law, get > to the part where you prove the Goldbach conjecture...") in the same > amount of space. The text is compressed by leaving out the parts that an > experienced reader can infer from her knowledge of the domain. > > Since an expert can infer meaning more quickly than they can read the > actual words, this is a big win for efficiency. But the text is not more > readable, there's just less to read for a given result. The same amount, > or even more, brain processing occurs. It just happens in a different > part of the brain. Maybe we should define *exactly* what readability is (in less then 500 lines, if possible). According to your view, ASM code is more readable than Python code. It's just that there's more to read in ASM. Kiuhnm From kiuhnm03.4t.yahoo.it Fri Mar 16 08:36:25 2012 From: kiuhnm03.4t.yahoo.it (Kiuhnm) Date: Fri, 16 Mar 2012 13:36:25 +0100 Subject: Python is readable In-Reply-To: <4f6280a0$0$29981$c3e8da3$5496439d@news.astraweb.com> References: <4f612b19$0$1379$4fafbaef@reader2.news.tin.it> <8e72d74f-c844-4de3-8a37-f6b1fdc2291f@y27g2000yqy.googlegroups.com> <50e9ceec-40f1-4ead-b2b6-87328b30d084@ow8g2000pbc.googlegroups.com> <4f61c828$0$1390$4fafbaef@reader2.news.tin.it> <4f61d728$0$1375$4fafbaef@reader2.news.tin.it> <4f61fd0a$0$1389$4fafbaef@reader2.news.tin.it> <4f6280a0$0$29981$c3e8da3$5496439d@news.astraweb.com> Message-ID: <4f6333ca$0$1392$4fafbaef@reader1.news.tin.it> On 3/16/2012 0:52, Steven D'Aprano wrote: >> On Fri, Mar 16, 2012 at 1:30 AM, Kiuhnm >> wrote: >>> Sorry, but I can't see how it would make it harder for humans to >>> understand. Are there particular situations you're referring to? >> >> In a trivial example, it's mostly just noise: >> >> if a == b # who needs the colon? >> print(c) > > The reader, for the same reason that above you wrote: > > "In a trivial example, it's mostly just noise COLON" > > and indeed I too used a colon for the same reason. It ties the lead > sentence to the following block without ending the sentence, but still > introducing a new grouping or clause. > > It is *remarkable* how people take the colon for granted. It is so simple > and so obvious that they use it in their own writing often without > thinking about it, but because it is not strictly necessary to avoid > ambiguity in the grammar, they fool themselves into thinking that it is > "just noise" or "pointless". It is not noise, it is a hint to the reader. IMHO, Python misuses colons. No grammarian would ever write "If you can: take the bus." Natural languages are irregular while Python strives to be as regular as possible. BTW, I prefer The matrix [....] can be ..... and it gives [....] which ..... to The matrix: [....] can be ..... and it gives: [....] which .... Colons should introduce more specific information, not all the information. For instance, "I like many things in life: " is way better than "I like: ". As you can see, I'm not an English native speaker, but I think I know a few things about punctuation. We second language learners remember all the wrong things :( Kiuhnm From emacsray at gmail.com Fri Mar 16 08:45:15 2012 From: emacsray at gmail.com (Ray Song) Date: Fri, 16 Mar 2012 20:45:15 +0800 Subject: Why not use juxtaposition to indicate function application Message-ID: <20120316124515.GA2529@lap.tuna.tsinghua.edu.cn> I confess i've indulged in Haskell and found f a more readable than f(a) And why aren't functions curried (partially applied function is another function which takes the rest arguments) by default? Thanks in advance for any suggestions. -- Ray From neilc at norwich.edu Fri Mar 16 08:50:33 2012 From: neilc at norwich.edu (Neil Cerutti) Date: 16 Mar 2012 12:50:33 GMT Subject: Python is readable References: <4f612b19$0$1379$4fafbaef@reader2.news.tin.it> <8e72d74f-c844-4de3-8a37-f6b1fdc2291f@y27g2000yqy.googlegroups.com> <50e9ceec-40f1-4ead-b2b6-87328b30d084@ow8g2000pbc.googlegroups.com> <4f61c828$0$1390$4fafbaef@reader2.news.tin.it> <4f61d728$0$1375$4fafbaef@reader2.news.tin.it> <4f61fd0a$0$1389$4fafbaef@reader2.news.tin.it> <4f6280a0$0$29981$c3e8da3$5496439d@news.astraweb.com> <4f6333ca$0$1392$4fafbaef@reader1.news.tin.it> Message-ID: <9sgr8oF2opU9@mid.individual.net> On 2012-03-16, Kiuhnm wrote: > As you can see, I'm not an English native speaker, but I think > I know a few things about punctuation. We second language > learners remember all the wrong things :( English's punctuation rules have to be a lot easier to remember than the seemingly random way in which we apply articles to our nouns. -- Neil Cerutti From kiuhnm03.4t.yahoo.it Fri Mar 16 08:55:06 2012 From: kiuhnm03.4t.yahoo.it (Kiuhnm) Date: Fri, 16 Mar 2012 13:55:06 +0100 Subject: Python is readable In-Reply-To: <4f629d27$0$29981$c3e8da3$5496439d@news.astraweb.com> References: <4f612b19$0$1379$4fafbaef@reader2.news.tin.it> <4f629d27$0$29981$c3e8da3$5496439d@news.astraweb.com> Message-ID: <4f63382b$0$1375$4fafbaef@reader1.news.tin.it> On 3/16/2012 2:53, Steven D'Aprano wrote: > On Thu, 15 Mar 2012 00:34:47 +0100, Kiuhnm wrote: > >> I've just started to read >> The Quick Python Book (2nd ed.) > > Is this the one? > > http://manning.com/ceder/ > > >> The author claims that Python code is more readable than Perl code and >> provides this example: >> >> --- Perl --- >> sub pairwise_sum { >> my($arg1, $arg2) = @_; >> my(@result) = (); >> @list1 = @$arg1; >> @list2 = @$arg2; > > I don't understand the reason for $arg1 and $arg2. Is there some reason > why the code couldn't do this instead? > > my(@list1, @list2) = @_; @_ contains references to arrays. You can't pass two arrays to a function. Kiuhnm From roy at panix.com Fri Mar 16 08:57:30 2012 From: roy at panix.com (Roy Smith) Date: Fri, 16 Mar 2012 08:57:30 -0400 Subject: Python simulate browser activity References: <214c4c0c-f8ec-4030-946b-8becc8e1aa9c@ur9g2000pbc.googlegroups.com> Message-ID: In article <214c4c0c-f8ec-4030-946b-8becc8e1aa9c at ur9g2000pbc.googlegroups.com>, choi2k wrote: > Hi, everyone > > I am trying to write a small application using python but I am not > sure whether it is possible to do so.. > The application aims to simulate user activity including visit a > website and perform some interactive actions (click on the menu, > submit a form, redirect to another pages...etc) > I have found some libraries / plugins which aims to simulate browser > activity but ... none of them support AJAX request and/or running > javascript. > > Here is one of the simple tasks which I would like to do using the > application: > 1. simulate the user activity, visit the website ("https:// > www.abc.com") > 2. find out the target element by id ("submitBtn") and simulate mouse > click on the item. > 3. perform some javascript functions which invoked by click event from > step 2. ( the function is bind to the item by jquery) > 4. post ajax request using javascript and if the page has been > redirected, load the new page content > > Is it possible to do so? > > Thank you in advance. Depending on exactly what you're trying to test, this may or may not be possible. #1 is easy. Just get the URL with urllib (or, even better, Kenneth Reitz's very cool requests library (http://docs.python-requests.org/). #2 gets a little more interesting, but still not that big a deal. Parse the HTML you get back with something like lxml (http://lxml.de/). Navigate the DOM with a CSSSelector to find the element you're looking for. Use urllib/requests again to get the href. #3 is where things get fun. What, exactly, are you trying to test? Are you trying to test that the js works, or are you really trying to test your server and you're just using the embedded js as a means to generate the next HTTP request? If the former, then you really want to be exploring something like selenium (http://seleniumhq.org/). If the latter, then skip all the js crap and just go a GET or POST (back to urllib/requests) on the appropriate url. #4 falls into the same bucket as #3. Once you have figured all this out, you will get a greater appreciation for the need to cleanly separate your presentation (HTML, CSS, Javascript) from your business logic and data layers. If there is a clean interface between them, it becomes easy to test one in isolation from the other. If not, then you end up playing games with screen scraping via lxml and selenium just to test your database queries. Which will quickly lead to you running screaming into the night. From steve+comp.lang.python at pearwood.info Fri Mar 16 09:03:22 2012 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 16 Mar 2012 13:03:22 GMT Subject: Python is readable References: <4f612b19$0$1379$4fafbaef@reader2.news.tin.it> <8e72d74f-c844-4de3-8a37-f6b1fdc2291f@y27g2000yqy.googlegroups.com> <50e9ceec-40f1-4ead-b2b6-87328b30d084@ow8g2000pbc.googlegroups.com> <4f61c828$0$1390$4fafbaef@reader2.news.tin.it> <4f61d728$0$1375$4fafbaef@reader2.news.tin.it> <4f61fd0a$0$1389$4fafbaef@reader2.news.tin.it> <4f6280a0$0$29981$c3e8da3$5496439d@news.astraweb.com> <4f6333ca$0$1392$4fafbaef@reader1.news.tin.it> Message-ID: <4f633a1a$0$29981$c3e8da3$5496439d@news.astraweb.com> On Fri, 16 Mar 2012 13:36:25 +0100, Kiuhnm wrote: > On 3/16/2012 0:52, Steven D'Aprano wrote: >> It is *remarkable* how people take the colon for granted. It is so >> simple and so obvious that they use it in their own writing often >> without thinking about it, but because it is not strictly necessary to >> avoid ambiguity in the grammar, they fool themselves into thinking that >> it is "just noise" or "pointless". It is not noise, it is a hint to the >> reader. > > IMHO, Python misuses colons. According to the rules of which language? Latin? Cantonese? Russian? Or perhaps Perl? Javascript? Forth? > No grammarian would ever write > "If you can: take the bus." A grammarian might very well write: Your assignment, if you choose to accept it, is to: 1. Take the bus to Swansea. 2. Go across the road to the little shop on the corner. 3. Ask for Dave. 4. Tell him George sent you. 5. He will give you a package. Take it to the park down the street. 6. You will see a man making balloon animals. Give him the package. 7. He will give you a balloon giraffe. Take it to the pub. 8. Put the giraffe on the piano in the public bar, and leave. In English, one typical use for colons is to introduce a list or sequence of items, including instructions. A sequence of instructions is an algorithm, program or routine. You may have heard of them :) A one line routine is still a routine. There is nothing ungrammatical about "If you can: take the bus.", although it is non-idiomatic English. > Natural languages are irregular while Python strives to be as regular as > possible. So what? -- Steven From neilc at norwich.edu Fri Mar 16 09:08:49 2012 From: neilc at norwich.edu (Neil Cerutti) Date: 16 Mar 2012 13:08:49 GMT Subject: Python is readable References: <4f612b19$0$1379$4fafbaef@reader2.news.tin.it> <8e72d74f-c844-4de3-8a37-f6b1fdc2291f@y27g2000yqy.googlegroups.com> <50e9ceec-40f1-4ead-b2b6-87328b30d084@ow8g2000pbc.googlegroups.com> <4f61c828$0$1390$4fafbaef@reader2.news.tin.it> <4f61d728$0$1375$4fafbaef@reader2.news.tin.it> <4f61fd0a$0$1389$4fafbaef@reader2.news.tin.it> <4f6280a0$0$29981$c3e8da3$5496439d@news.astraweb.com> <4f6333ca$0$1392$4fafbaef@reader1.news.tin.it> <4f633a1a$0$29981$c3e8da3$5496439d@news.astraweb.com> Message-ID: <9sgsb1FsbpU1@mid.individual.net> On 2012-03-16, Steven D'Aprano wrote: > A grammarian might very well write: > > Your assignment, if you choose to accept it, is to: > > 1. Take the bus to Swansea. > ... > > In English, one typical use for colons is to introduce a list > or sequence of items, including instructions. A sequence of > instructions is an algorithm, program or routine. You may have > heard of them :) A grammarian always uses complete sentence before a colon, even when introducing a list. -- Neil Cerutti From bruno.desthuilliers at gmail.com Fri Mar 16 09:14:59 2012 From: bruno.desthuilliers at gmail.com (bruno.desthuilliers at gmail.com) Date: Fri, 16 Mar 2012 06:14:59 -0700 (PDT) Subject: Why not use juxtaposition to indicate function application References: Message-ID: <42cac695-761e-4cdb-aa3b-7c82789b76f9@h20g2000yqd.googlegroups.com> On Mar 16, 1:45?pm, Ray Song wrote: > I confess i've indulged in Haskell and found > ? ? f a > more readable than > ? ? f(a) Hmmm... What about: f a b versus f(a(b)) or was it supposed to be read as f(a)(b) or as f(a, b) ?-) > And why aren't functions curried (partially applied function is another function which takes the rest arguments) by default? If you're asking "why isn't Python like Haskell", the obvious answer is, well, "because Python is not Haskell" ;) Remember that Pythons is first and foremost an object-oriented language, where most of the support for functional idioms comes from the underlying object model. functions are central to fp, objects are central to OOP, so better to use objects than functions (hint: there's a builtin "partial" type). From invalid at invalid.invalid Fri Mar 16 09:27:34 2012 From: invalid at invalid.invalid (Grant Edwards) Date: Fri, 16 Mar 2012 13:27:34 +0000 (UTC) Subject: Is it technically possible to give Python option of naming process of running script? References: <19118128.4791.1331736187952.JavaMail.geo-discussion-forums@vbai14> <22071354.8904.1331796412001.JavaMail.geo-discussion-forums@vbkc1> Message-ID: On 2012-03-16, Chris Angelico wrote: > On Fri, Mar 16, 2012 at 5:39 AM, Grant Edwards wrote: >> Seems like an awfully obtuse way of doing things -- I don't really >> want to have 15 different copies of Python (or even links), and it >> requires root privleges every time you want to run a Python program >> with the "correct" name. > > Why do you need root? Can't you copy / link into your own home directory? I was thinging about daemons and system-type stuff. One possible problem with linking from one's home directory is that home directories are often on different filesystems than /usr/bin (or wherever python is). Using a symlink doesn't work, the process name still ends up as python2.6 (or whatever the real binary is called). -- Grant Edwards grant.b.edwards Yow! Where do your SOCKS at go when you lose them in gmail.com th' WASHER? From cjw at ncf.ca Fri Mar 16 11:06:12 2012 From: cjw at ncf.ca (Colin J. Williams) Date: Fri, 16 Mar 2012 11:06:12 -0400 Subject: Why not use juxtaposition to indicate function application In-Reply-To: References: Message-ID: On 16/03/2012 8:45 AM, Ray Song wrote: > I confess i've indulged in Haskell and found > f a > more readable than > f(a) > > And why aren't functions curried (partially applied function is another function which takes the rest arguments) by default? > > > Thanks in advance for any suggestions. > > -- > Ray +1 Colin W. From kiuhnm03.4t.yahoo.it Fri Mar 16 12:00:16 2012 From: kiuhnm03.4t.yahoo.it (Kiuhnm) Date: Fri, 16 Mar 2012 17:00:16 +0100 Subject: Why not use juxtaposition to indicate function application In-Reply-To: <42cac695-761e-4cdb-aa3b-7c82789b76f9@h20g2000yqd.googlegroups.com> References: <42cac695-761e-4cdb-aa3b-7c82789b76f9@h20g2000yqd.googlegroups.com> Message-ID: <4f636391$0$1382$4fafbaef@reader1.news.tin.it> On 3/16/2012 14:14, bruno.desthuilliers at gmail.com wrote: > On Mar 16, 1:45 pm, Ray Song wrote: >> I confess i've indulged in Haskell and found >> f a >> more readable than >> f(a) > > Hmmm... What about: > > f a b > > versus > > f(a(b)) > > or was it supposed to be read as > > f(a)(b) > > > or as > > f(a, b) > > ?-) That would be f (a b) # Haskell f(a(b)) # Python Kiuhnm From ramit.prasad at jpmorgan.com Fri Mar 16 12:13:38 2012 From: ramit.prasad at jpmorgan.com (Prasad, Ramit) Date: Fri, 16 Mar 2012 16:13:38 +0000 Subject: Why not use juxtaposition to indicate function application In-Reply-To: <4f636391$0$1382$4fafbaef@reader1.news.tin.it> References: <42cac695-761e-4cdb-aa3b-7c82789b76f9@h20g2000yqd.googlegroups.com> <4f636391$0$1382$4fafbaef@reader1.news.tin.it> Message-ID: <5B80DD153D7D744689F57F4FB69AF474026BB729@SCACMX008.exchad.jpmchase.net> > >> I confess i've indulged in Haskell and found > >> f a > >> more readable than > >> f(a) > > > > Hmmm... What about: > > > > f a b > > > > versus > > > > f(a(b)) > > > > or was it supposed to be read as > > > > f(a)(b) > > > > > > or as > > > > f(a, b) > > > > ?-) > > That would be > f (a b) # Haskell > f(a(b)) # Python I have not used Haskell so far, but in this case I think I prefer the 'Explicit is better than implicit.' I would probably always forget if it should be f a b or f ( a b ) Not to mention the first line look like text rather than a function call because my mind tends to filter out whitespaces like that when reading. I blame variable width fonts (and the mind being a strange thing). Ramit Ramit Prasad | JPMorgan Chase Investment Bank | Currencies Technology 712 Main Street | Houston, TX 77002 work phone: 713 - 216 - 5423 -- This email is confidential and subject to important disclaimers and conditions including on offers for the purchase or sale of securities, accuracy and completeness of information, viruses, confidentiality, legal privilege, and legal entity disclaimers, available at http://www.jpmorgan.com/pages/disclosures/email. From robert.kern at gmail.com Fri Mar 16 12:18:57 2012 From: robert.kern at gmail.com (Robert Kern) Date: Fri, 16 Mar 2012 16:18:57 +0000 Subject: Why not use juxtaposition to indicate function application In-Reply-To: <20120316124515.GA2529@lap.tuna.tsinghua.edu.cn> References: <20120316124515.GA2529@lap.tuna.tsinghua.edu.cn> Message-ID: On 3/16/12 12:45 PM, Ray Song wrote: > I confess i've indulged in Haskell and found > f a > more readable than > f(a) > > And why aren't functions curried (partially applied function is another function which takes the rest arguments) by default? Python isn't a strongly functional language. We just don't do partial function application all that frequently to make it a language feature. Leaving out an argument is a common enough mistake, though, and using curry-by-default would postpone the error and make for even more inscrutable error messages. -- Robert Kern "I have come to believe that the whole world is an enigma, a harmless enigma that is made terrible by our own mad attempt to interpret it as though it had an underlying truth." -- Umberto Eco From steve+comp.lang.python at pearwood.info Fri Mar 16 12:25:32 2012 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 16 Mar 2012 16:25:32 GMT Subject: Python is readable References: <4f612b19$0$1379$4fafbaef@reader2.news.tin.it> <4f629d27$0$29981$c3e8da3$5496439d@news.astraweb.com> <4f63382b$0$1375$4fafbaef@reader1.news.tin.it> Message-ID: <4f63697c$0$29981$c3e8da3$5496439d@news.astraweb.com> On Fri, 16 Mar 2012 13:55:06 +0100, Kiuhnm wrote: >> I don't understand the reason for $arg1 and $arg2. Is there some reason >> why the code couldn't do this instead? >> >> my(@list1, @list2) = @_; > > @_ contains references to arrays. You can't pass two arrays to a > function. Why ever not? That seems like basic functionality to me. I can't imagine any modern language that lacks such a simple feature. Even Pascal allows you to pass arrays as arguments to functions. Is there some design principle that I'm missing that explains why Perl lacks this feature? -- Steven From steve+comp.lang.python at pearwood.info Fri Mar 16 12:28:41 2012 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 16 Mar 2012 16:28:41 GMT Subject: Python is readable References: <4f612b19$0$1379$4fafbaef@reader2.news.tin.it> <8e72d74f-c844-4de3-8a37-f6b1fdc2291f@y27g2000yqy.googlegroups.com> <50e9ceec-40f1-4ead-b2b6-87328b30d084@ow8g2000pbc.googlegroups.com> <4f61c828$0$1390$4fafbaef@reader2.news.tin.it> <4f61d728$0$1375$4fafbaef@reader2.news.tin.it> <4f61fd0a$0$1389$4fafbaef@reader2.news.tin.it> <4f6280a0$0$29981$c3e8da3$5496439d@news.astraweb.com> <4f6333ca$0$1392$4fafbaef@reader1.news.tin.it> <4f633a1a$0$29981$c3e8da3$5496439d@news.astraweb.com> <9sgsb1FsbpU1@mid.individual.net> Message-ID: <4f636a38$0$29981$c3e8da3$5496439d@news.astraweb.com> On Fri, 16 Mar 2012 13:08:49 +0000, Neil Cerutti wrote: > On 2012-03-16, Steven D'Aprano > wrote: >> A grammarian might very well write: >> >> Your assignment, if you choose to accept it, is to: >> >> 1. Take the bus to Swansea. >> ... >> >> In English, one typical use for colons is to introduce a list or >> sequence of items, including instructions. A sequence of instructions >> is an algorithm, program or routine. You may have heard of them :) > > A grammarian always uses complete sentence before a colon, even when > introducing a list. Ah, perhaps you're talking about *prescriptivist* grammarians, who insist on applying grammatical rules that exist only in their own fevered imagination. Sorry, I was talking about the other sort, the ones who apply the grammatical rules used by people in real life. You know the ones: linguists. My mistake. Colons don't end sentences, therefore there is no need to use a complete sentence before a colon. -- Steven From kiuhnm03.4t.yahoo.it Fri Mar 16 12:31:06 2012 From: kiuhnm03.4t.yahoo.it (Kiuhnm) Date: Fri, 16 Mar 2012 17:31:06 +0100 Subject: Why not use juxtaposition to indicate function application In-Reply-To: References: <42cac695-761e-4cdb-aa3b-7c82789b76f9@h20g2000yqd.googlegroups.com> <4f636391$0$1382$4fafbaef@reader1.news.tin.it> Message-ID: <4f636acb$0$1381$4fafbaef@reader1.news.tin.it> On 3/16/2012 17:13, Prasad, Ramit wrote: >>>> I confess i've indulged in Haskell and found >>>> f a >>>> more readable than >>>> f(a) >>> >>> Hmmm... What about: >>> >>> f a b >>> >>> versus >>> >>> f(a(b)) >>> >>> or was it supposed to be read as >>> >>> f(a)(b) >>> >>> >>> or as >>> >>> f(a, b) >>> >>> ?-) >> >> That would be >> f (a b) # Haskell >> f(a(b)) # Python > > I have not used Haskell so far, but in this case I think I prefer the > 'Explicit is better than implicit.' Are you sure that "call the function f with the params a and b" is better than f a b or f(a,b) ? > I would probably always forget if it should be > > f a b > > or > > f ( a b ) You wouldn't, because Haskel's way is more regular and makes a lot of sense: parentheses are for grouping and that's it. Kiuhnm From steve+comp.lang.python at pearwood.info Fri Mar 16 12:45:55 2012 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 16 Mar 2012 16:45:55 GMT Subject: Why not use juxtaposition to indicate function application References: <42cac695-761e-4cdb-aa3b-7c82789b76f9@h20g2000yqd.googlegroups.com> <4f636391$0$1382$4fafbaef@reader1.news.tin.it> <4f636acb$0$1381$4fafbaef@reader1.news.tin.it> Message-ID: <4f636e43$0$29981$c3e8da3$5496439d@news.astraweb.com> On Fri, 16 Mar 2012 17:31:06 +0100, Kiuhnm wrote: > You wouldn't, because Haskel's way is more regular and makes a lot of > sense: parentheses are for grouping and that's it. If f is a function which normally takes (for the sake of the argument) one argument, then f would call the function with no arguments (which may return a curried function, or may apply default arguments, or perhaps raise an exception). So how would you refer to the function itself without calling it? -- Steven From steve+comp.lang.python at pearwood.info Fri Mar 16 12:48:21 2012 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 16 Mar 2012 16:48:21 GMT Subject: Python is readable References: <4f612b19$0$1379$4fafbaef@reader2.news.tin.it> <8e72d74f-c844-4de3-8a37-f6b1fdc2291f@y27g2000yqy.googlegroups.com> <50e9ceec-40f1-4ead-b2b6-87328b30d084@ow8g2000pbc.googlegroups.com> <4f61c828$0$1390$4fafbaef@reader2.news.tin.it> <4f61d728$0$1375$4fafbaef@reader2.news.tin.it> <4f61fd0a$0$1389$4fafbaef@reader2.news.tin.it> <4f620837$0$1382$4fafbaef@reader2.news.tin.it> <4f627c25$0$1381$4fafbaef@reader2.news.tin.it> <4f62b9be$0$29981$c3e8da3$5496439d@news.astraweb.com> <4f632da5$0$1375$4fafbaef@reader1.news.tin.it> Message-ID: <4f636ed5$0$29981$c3e8da3$5496439d@news.astraweb.com> On Fri, 16 Mar 2012 13:10:12 +0100, Kiuhnm wrote: > Maybe we should define *exactly* what readability is (in less then 500 > lines, if possible). If you can't be bothered to read my post before replying, save yourself some more time and don't bother to reply at all. I quote from the part of the my post you deleted: When people talk about readability, they normally mean to ask how much mental effort is needed to interpret the meaning of the text, not how much time does it take to pass your eyes over the characters. In other words they are actually talking about comprehensibility. Unless I've made a mistake counting, that's less than 500 lines. > According to your view, ASM code is more readable than Python code. It's > just that there's more to read in ASM. What a ridiculous misrepresentation of my position. Readability is not proportional to length. -- Steven From andrea.crotti.0 at gmail.com Fri Mar 16 12:49:17 2012 From: andrea.crotti.0 at gmail.com (Andrea Crotti) Date: Fri, 16 Mar 2012 16:49:17 +0000 Subject: avoid import short-circuiting Message-ID: <4F636F0D.3060006@gmail.com> I started the following small project: https://github.com/AndreaCrotti/import-tree because I would like to find out what exactly depends on what at run-time, using an import hook. It works quite well for small examples but the main problem is that once a module is imported it's added to sys.modules and then it doesn't go through the import hook anymore. I tried to mess around with sys.modules but it might not be a good idea, and it leads to easy infinite loops. Is there a good way to achieve this? I guess I could do the loop detection myself, but that should not be too hard.. Thanks, Andrea From kiuhnm03.4t.yahoo.it Fri Mar 16 12:58:36 2012 From: kiuhnm03.4t.yahoo.it (Kiuhnm) Date: Fri, 16 Mar 2012 17:58:36 +0100 Subject: Python is readable In-Reply-To: <4f63697c$0$29981$c3e8da3$5496439d@news.astraweb.com> References: <4f612b19$0$1379$4fafbaef@reader2.news.tin.it> <4f629d27$0$29981$c3e8da3$5496439d@news.astraweb.com> <4f63382b$0$1375$4fafbaef@reader1.news.tin.it> <4f63697c$0$29981$c3e8da3$5496439d@news.astraweb.com> Message-ID: <4f63713d$0$1374$4fafbaef@reader1.news.tin.it> On 3/16/2012 17:25, Steven D'Aprano wrote: > On Fri, 16 Mar 2012 13:55:06 +0100, Kiuhnm wrote: > > >>> I don't understand the reason for $arg1 and $arg2. Is there some reason >>> why the code couldn't do this instead? >>> >>> my(@list1, @list2) = @_; >> >> @_ contains references to arrays. You can't pass two arrays to a >> function. > > > Why ever not? That seems like basic functionality to me. I can't imagine > any modern language that lacks such a simple feature. Even Pascal allows > you to pass arrays as arguments to functions. > > Is there some design principle that I'm missing that explains why Perl > lacks this feature? Perl uses references only when explicitly told so. For instance, my @a = (1,2,3); my @b = @a; creates two distinct arrays and you can modify @b without touching @a at all. Another odd thing is that Perl "flattens" lists or arrays. If you write my @a = (1,2,3); my @b = (0, at a,4); you'll end up with @b = (0,1,2,3,4). If you want nested data structures, you'll need to use explicit references: my @b = (0,\@a,4); # '\' = take the ref of Now you can write $b[1][0] but that's short-hand for $b[1]->[0] # deref. $b[1] and get the first elem which is short-hand for ${$b[1]}[0] Square brackets build an array and return a reference to it: my $ref = [0,1,2]; (Notice that, in Perl, '$' means one ($ref is one reference), while '@' means many.) Now you can write my @a = (1,[2,3,4],5) because you're putting a reference into $a[1]! So, let's go back to this code: sub pairwise_sum { my($arg1, $arg2) = @_; my(@result) = (); @list1 = @$arg1; @list2 = @$arg2; for($i=0; $i < length(@list1); $i++) { push(@result, $list1[$i] + $list2[$i]); } return(\@result); } Here @list1 and @list2 are copies. No careful Perl programmer would do such extra copies. And no Perl programmer would use a C-style for loop. Kiuhnm From ramit.prasad at jpmorgan.com Fri Mar 16 13:01:28 2012 From: ramit.prasad at jpmorgan.com (Prasad, Ramit) Date: Fri, 16 Mar 2012 17:01:28 +0000 Subject: Python is readable In-Reply-To: <4f63697c$0$29981$c3e8da3$5496439d@news.astraweb.com> References: <4f612b19$0$1379$4fafbaef@reader2.news.tin.it> <4f629d27$0$29981$c3e8da3$5496439d@news.astraweb.com> <4f63382b$0$1375$4fafbaef@reader1.news.tin.it> <4f63697c$0$29981$c3e8da3$5496439d@news.astraweb.com> Message-ID: <5B80DD153D7D744689F57F4FB69AF474026BB7D3@SCACMX008.exchad.jpmchase.net> > >> I don't understand the reason for $arg1 and $arg2. Is there some reason > >> why the code couldn't do this instead? > >> > >> my(@list1, @list2) = @_; > > > > @_ contains references to arrays. You can't pass two arrays to a > > function. > > > Why ever not? That seems like basic functionality to me. I can't imagine > any modern language that lacks such a simple feature. Even Pascal allows > you to pass arrays as arguments to functions. > > Is there some design principle that I'm missing that explains why Perl > lacks this feature? My understanding is that it assigns each scalar argument until it finds a list to assign and then it assigns everything remaining to the list. my @arr = ( 'test', 'blah', '1234', 'boop', 'foo', 'bar' ); my @arr2 = ( 'adsf', 'qwerty' ); print "@arr\n"; my @arr3 = (@arr, @arr2); print "arr3:@arr3\n"; my ($arg1, $arg2, @arg3) = @arr3; print "arg3:@arg3\n"; bash-3.2$ perl temp.pl testblah1234boopfoobar arr3:test blah 1234 boop foo bar adsf qwerty arg3:1234 boop foo bar adsf qwerty I assume this is because it combines both elements of the list into one giant list and then if you try and assign two lists it does not know where to split it. Now if you pass a reference to the two arrays instead of the values it should work as expected, but now you are dealing with pointers / references. bash-3.2$ cat temp.pl my @arr = ( 'test', 'blah', '1234', 'boop', 'foo', 'bar' ); my @arr2 = ( 'adsf', 'qwerty' ); print "@arr\n"; my @arr3 = (\@arr, \@arr2); print "arr3:@arr3\n"; my ($arg1, $arg2, @arg3) = @arr3; print "arg1:@$arg1\narg2:@$arg2\narg3:@arg3\n"; bash-3.2$ perl temp.pl test blah 1234 boop foo bar arr3:ARRAY(0xb2f0f90) ARRAY(0xb2f1020) arg1:test blah 1234 boop foo bar arg2:adsf qwerty arg3: Ramit Ramit Prasad | JPMorgan Chase Investment Bank | Currencies Technology 712 Main Street | Houston, TX 77002 work phone: 713 - 216 - 5423 -- This email is confidential and subject to important disclaimers and conditions including on offers for the purchase or sale of securities, accuracy and completeness of information, viruses, confidentiality, legal privilege, and legal entity disclaimers, available at http://www.jpmorgan.com/pages/disclosures/email. From ethan at stoneleaf.us Fri Mar 16 13:06:31 2012 From: ethan at stoneleaf.us (Ethan Furman) Date: Fri, 16 Mar 2012 10:06:31 -0700 Subject: avoid import short-circuiting In-Reply-To: <4F636F0D.3060006@gmail.com> References: <4F636F0D.3060006@gmail.com> Message-ID: <4F637317.6010403@stoneleaf.us> Andrea Crotti wrote: > I started the following small project: > > https://github.com/AndreaCrotti/import-tree > > because I would like to find out what exactly depends on what at > run-time, using an import hook. > > It works quite well for small examples but the main problem is that once > a module is imported > it's added to sys.modules and then it doesn't go through the import hook > anymore. > > I tried to mess around with sys.modules but it might not be a good idea, > and it leads to easy > infinite loops. > Is there a good way to achieve this? > I guess I could do the loop detection myself, but that should not be too > hard.. I believe sys.modules is a dictionary; you might try replacing it with your own custom dictionary that does whatever when the keys are accessed. ~Ethan~ From kiuhnm03.4t.yahoo.it Fri Mar 16 13:18:21 2012 From: kiuhnm03.4t.yahoo.it (Kiuhnm) Date: Fri, 16 Mar 2012 18:18:21 +0100 Subject: Why not use juxtaposition to indicate function application In-Reply-To: <4f636e43$0$29981$c3e8da3$5496439d@news.astraweb.com> References: <42cac695-761e-4cdb-aa3b-7c82789b76f9@h20g2000yqd.googlegroups.com> <4f636391$0$1382$4fafbaef@reader1.news.tin.it> <4f636acb$0$1381$4fafbaef@reader1.news.tin.it> <4f636e43$0$29981$c3e8da3$5496439d@news.astraweb.com> Message-ID: <4f6375de$0$1382$4fafbaef@reader1.news.tin.it> On 3/16/2012 17:45, Steven D'Aprano wrote: > On Fri, 16 Mar 2012 17:31:06 +0100, Kiuhnm wrote: > >> You wouldn't, because Haskel's way is more regular and makes a lot of >> sense: parentheses are for grouping and that's it. > > If f is a function which normally takes (for the sake of the argument) > one argument, then f would call the function with no arguments (which may > return a curried function, or may apply default arguments, or perhaps > raise an exception). So how would you refer to the function itself > without calling it? Thanks to Referential Transparency, a function with no params is a constant. But that's a good observation. It would cause some problems in Python. ML languages use the empty tuple: f(). Kiuhnm From robert.kern at gmail.com Fri Mar 16 13:19:47 2012 From: robert.kern at gmail.com (Robert Kern) Date: Fri, 16 Mar 2012 17:19:47 +0000 Subject: avoid import short-circuiting In-Reply-To: <4F636F0D.3060006@gmail.com> References: <4F636F0D.3060006@gmail.com> Message-ID: On 3/16/12 4:49 PM, Andrea Crotti wrote: > I started the following small project: > > https://github.com/AndreaCrotti/import-tree > > because I would like to find out what exactly depends on what at run-time, using > an import hook. > > It works quite well for small examples but the main problem is that once a > module is imported > it's added to sys.modules and then it doesn't go through the import hook anymore. > > I tried to mess around with sys.modules but it might not be a good idea, and it > leads to easy > infinite loops. > Is there a good way to achieve this? > I guess I could do the loop detection myself, but that should not be too hard.. You want to monkeypatch __builtin__.__import__() instead. It always gets called. -- Robert Kern "I have come to believe that the whole world is an enigma, a harmless enigma that is made terrible by our own mad attempt to interpret it as though it had an underlying truth." -- Umberto Eco From neilc at norwich.edu Fri Mar 16 13:53:24 2012 From: neilc at norwich.edu (Neil Cerutti) Date: 16 Mar 2012 17:53:24 GMT Subject: Python is readable References: <4f612b19$0$1379$4fafbaef@reader2.news.tin.it> <8e72d74f-c844-4de3-8a37-f6b1fdc2291f@y27g2000yqy.googlegroups.com> <50e9ceec-40f1-4ead-b2b6-87328b30d084@ow8g2000pbc.googlegroups.com> <4f61c828$0$1390$4fafbaef@reader2.news.tin.it> <4f61d728$0$1375$4fafbaef@reader2.news.tin.it> <4f61fd0a$0$1389$4fafbaef@reader2.news.tin.it> <4f6280a0$0$29981$c3e8da3$5496439d@news.astraweb.com> <4f6333ca$0$1392$4fafbaef@reader1.news.tin.it> <4f633a1a$0$29981$c3e8da3$5496439d@news.astraweb.com> <9sgsb1FsbpU1@mid.individual.net> <4f636a38$0$29981$c3e8da3$5496439d@news.astraweb.com> Message-ID: <9shd0kFvgbU1@mid.individual.net> On 2012-03-16, Steven D'Aprano wrote: > Ah, perhaps you're talking about *prescriptivist* grammarians, > who insist on applying grammatical rules that exist only in > their own fevered imagination. Sorry, I was talking about the > other sort, the ones who apply the grammatical rules used by > people in real life. You know the ones: linguists. My mistake. I am not pedantic. You are wrong. -- Neil Cerutti From ian.g.kelly at gmail.com Fri Mar 16 13:59:51 2012 From: ian.g.kelly at gmail.com (Ian Kelly) Date: Fri, 16 Mar 2012 11:59:51 -0600 Subject: Why not use juxtaposition to indicate function application In-Reply-To: <4f636e43$0$29981$c3e8da3$5496439d@news.astraweb.com> References: <42cac695-761e-4cdb-aa3b-7c82789b76f9@h20g2000yqd.googlegroups.com> <4f636391$0$1382$4fafbaef@reader1.news.tin.it> <4f636acb$0$1381$4fafbaef@reader1.news.tin.it> <4f636e43$0$29981$c3e8da3$5496439d@news.astraweb.com> Message-ID: On Fri, Mar 16, 2012 at 10:45 AM, Steven D'Aprano wrote: > On Fri, 16 Mar 2012 17:31:06 +0100, Kiuhnm wrote: > >> You wouldn't, because Haskel's way is more regular and makes a lot of >> sense: parentheses are for grouping and that's it. > > If f is a function which normally takes (for the sake of the argument) > one argument, then f would call the function with no arguments (which may > return a curried function, or may apply default arguments, or perhaps > raise an exception). So how would you refer to the function itself > without calling it? A partial application of f with no arguments is still just f. From steve+comp.lang.python at pearwood.info Fri Mar 16 14:50:31 2012 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 16 Mar 2012 18:50:31 GMT Subject: Python is readable References: <4f612b19$0$1379$4fafbaef@reader2.news.tin.it> <8e72d74f-c844-4de3-8a37-f6b1fdc2291f@y27g2000yqy.googlegroups.com> <50e9ceec-40f1-4ead-b2b6-87328b30d084@ow8g2000pbc.googlegroups.com> <4f61c828$0$1390$4fafbaef@reader2.news.tin.it> <4f61d728$0$1375$4fafbaef@reader2.news.tin.it> <4f61fd0a$0$1389$4fafbaef@reader2.news.tin.it> <4f6280a0$0$29981$c3e8da3$5496439d@news.astraweb.com> <4f6333ca$0$1392$4fafbaef@reader1.news.tin.it> <4f633a1a$0$29981$c3e8da3$5496439d@news.astraweb.com> <9sgsb1FsbpU1@mid.individual.net> <4f636a38$0$29981$c3e8da3$5496439d@news.astraweb.com> <9shd0kFvgbU1@mid.individual.net> Message-ID: <4f638b76$0$29981$c3e8da3$5496439d@news.astraweb.com> On Fri, 16 Mar 2012 17:53:24 +0000, Neil Cerutti wrote: > On 2012-03-16, Steven D'Aprano > wrote: >> Ah, perhaps you're talking about *prescriptivist* grammarians, who >> insist on applying grammatical rules that exist only in their own >> fevered imagination. Sorry, I was talking about the other sort, the >> ones who apply the grammatical rules used by people in real life. You >> know the ones: linguists. My mistake. > > I am not pedantic. You are wrong. Whether you like it or not, it simply is a fact that in English (I won't speak for other languages) people use colons without the first clause *necessarily* being a complete sentence. They write things like this: Star Wars Episode IV: A New Hope Also like these: Example: this is an example of a colon following a sentence fragment. Last update: Oct 4, 2007. Shopping list: - eggs - milk - cheese They even use the reverse construction: Lists, quotations, explanations, examples: some of the things which follow after a colon. Check the use of colons here: http://articles.baltimoresun.com/2012-03-15/features/bal-the-raven-reviews-20120313_1_edgar-allan-poe-john-cusack-mystery-writer I count at least ten colons on the page (including the title) and *not one of them* uses a complete sentence before the colon. While it is common for the clause preceding the colon to be an independent clause (i.e. it would stand alone as a complete sentence) it is not required that it be so. I think I'll end this with a quote from Gore Vidal: "The four most beautiful words in our common language: I told you so." http://grammar.about.com/od/c/g/colon.htm -- Steven From rosuav at gmail.com Fri Mar 16 15:20:17 2012 From: rosuav at gmail.com (Chris Angelico) Date: Sat, 17 Mar 2012 06:20:17 +1100 Subject: Python simulate browser activity In-Reply-To: <214c4c0c-f8ec-4030-946b-8becc8e1aa9c@ur9g2000pbc.googlegroups.com> References: <214c4c0c-f8ec-4030-946b-8becc8e1aa9c@ur9g2000pbc.googlegroups.com> Message-ID: On Fri, Mar 16, 2012 at 1:23 PM, choi2k wrote: > The application aims to simulate user activity including visit a > website and perform some interactive actions (click on the menu, > submit a form, redirect to another pages...etc) > I have found some libraries / plugins which aims to simulate browser > activity but ... none of them support AJAX request and/or running > javascript. > > Here is one of the simple tasks which I would like to do using the > application: > 4. post ajax request using javascript and if the page has been > redirected, load the new page content To the web server, everything is a request. Don't think in terms of Javascript; there is no Javascript, there is no AJAX, there is not even a web browser. There's just a TCP socket connection and an HTTP request. That's all you have. On that basis, your Python script most definitely can simulate the request. It needs simply to make the same HTTP query that the Javascript would have made. The only tricky part is figuring out what that request would be. If you can use a non-SSL connection, that'll make your job easier - just get a proxy or packet sniffer to monitor an actual web browser, then save the request headers and body. You can then replay that using Python; it's not difficult to handle cookies and such, too. Hope that helps! ChrisA From neilc at norwich.edu Fri Mar 16 15:35:34 2012 From: neilc at norwich.edu (Neil Cerutti) Date: 16 Mar 2012 19:35:34 GMT Subject: Python is readable References: <4f612b19$0$1379$4fafbaef@reader2.news.tin.it> <8e72d74f-c844-4de3-8a37-f6b1fdc2291f@y27g2000yqy.googlegroups.com> <50e9ceec-40f1-4ead-b2b6-87328b30d084@ow8g2000pbc.googlegroups.com> <4f61c828$0$1390$4fafbaef@reader2.news.tin.it> <4f61d728$0$1375$4fafbaef@reader2.news.tin.it> <4f61fd0a$0$1389$4fafbaef@reader2.news.tin.it> <4f6280a0$0$29981$c3e8da3$5496439d@news.astraweb.com> <4f6333ca$0$1392$4fafbaef@reader1.news.tin.it> <4f633a1a$0$29981$c3e8da3$5496439d@news.astraweb.com> <9sgsb1FsbpU1@mid.individual.net> <4f636a38$0$29981$c3e8da3$5496439d@news.astraweb.com> <9shd0kFvgbU1@mid.individual.net> <4f638b76$0$29981$c3e8da3$5496439d@news.astraweb.com> Message-ID: <9shj05FabeU1@mid.individual.net> On 2012-03-16, Steven D'Aprano wrote: > On Fri, 16 Mar 2012 17:53:24 +0000, Neil Cerutti wrote: > >> On 2012-03-16, Steven D'Aprano >> wrote: >>> Ah, perhaps you're talking about *prescriptivist* grammarians, who >>> insist on applying grammatical rules that exist only in their own >>> fevered imagination. Sorry, I was talking about the other sort, the >>> ones who apply the grammatical rules used by people in real life. You >>> know the ones: linguists. My mistake. >> >> I am not pedantic. You are wrong. > > Whether you like it or not, it simply is a fact that in English > (I won't speak for other languages) people use colons without > the first clause *necessarily* being a complete sentence. They > write things like this: People spell your name Stephen, sometimes too. Thinking of changing it? Gore Vidal's quote has panache, a valid compensation for breaking the usual rule. How many other uses on that page are similar? -- Neil Cerutti From mwilson at the-wire.com Fri Mar 16 16:01:13 2012 From: mwilson at the-wire.com (Mel Wilson) Date: Fri, 16 Mar 2012 16:01:13 -0400 Subject: Python is readable References: <4f612b19$0$1379$4fafbaef@reader2.news.tin.it> <8e72d74f-c844-4de3-8a37-f6b1fdc2291f@y27g2000yqy.googlegroups.com> <50e9ceec-40f1-4ead-b2b6-87328b30d084@ow8g2000pbc.googlegroups.com> <4f61c828$0$1390$4fafbaef@reader2.news.tin.it> <4f61d728$0$1375$4fafbaef@reader2.news.tin.it> <4f61fd0a$0$1389$4fafbaef@reader2.news.tin.it> <4f6280a0$0$29981$c3e8da3$5496439d@news.astraweb.com> <4f6333ca$0$1392$4fafbaef@reader1.news.tin.it> <4f633a1a$0$29981$c3e8da3$5496439d@news.astraweb.com> <9sgsb1FsbpU1@mid.individual.net> <4f636a38$0$29981$c3e8da3$5496439d@news.astraweb.com> <9shd0kFvgbU1@mid.individual.net> <4f638b76$0$29981$c3e8da3$5496439d@news.astraweb.com> Message-ID: Steven D'Aprano wrote: > On Fri, 16 Mar 2012 17:53:24 +0000, Neil Cerutti wrote: > >> On 2012-03-16, Steven D'Aprano >> wrote: >>> Ah, perhaps you're talking about *prescriptivist* grammarians, who >>> insist on applying grammatical rules that exist only in their own >>> fevered imagination. Sorry, I was talking about the other sort, the >>> ones who apply the grammatical rules used by people in real life. You >>> know the ones: linguists. My mistake. >> >> I am not pedantic. You are wrong. > > > Whether you like it or not, it simply is a fact that in English (I won't > speak for other languages) people use colons without the first clause > *necessarily* being a complete sentence. They write things like this: > > Star Wars Episode IV: A New Hope Come to think of it, just about every "serious" book title works this way. Mel. From ramit.prasad at jpmorgan.com Fri Mar 16 16:04:57 2012 From: ramit.prasad at jpmorgan.com (Prasad, Ramit) Date: Fri, 16 Mar 2012 20:04:57 +0000 Subject: Python is readable In-Reply-To: <9shj05FabeU1@mid.individual.net> References: <4f612b19$0$1379$4fafbaef@reader2.news.tin.it> <8e72d74f-c844-4de3-8a37-f6b1fdc2291f@y27g2000yqy.googlegroups.com> <50e9ceec-40f1-4ead-b2b6-87328b30d084@ow8g2000pbc.googlegroups.com> <4f61c828$0$1390$4fafbaef@reader2.news.tin.it> <4f61d728$0$1375$4fafbaef@reader2.news.tin.it> <4f61fd0a$0$1389$4fafbaef@reader2.news.tin.it> <4f6280a0$0$29981$c3e8da3$5496439d@news.astraweb.com> <4f6333ca$0$1392$4fafbaef@reader1.news.tin.it> <4f633a1a$0$29981$c3e8da3$5496439d@news.astraweb.com> <9sgsb1FsbpU1@mid.individual.net> <4f636a38$0$29981$c3e8da3$5496439d@news.astraweb.com> <9shd0kFvgbU1@mid.individual.net> <4f638b76$0$29981$c3e8da3$5496439d@news.astraweb.com> <9shj05FabeU1@mid.individual.net> Message-ID: <5B80DD153D7D744689F57F4FB69AF474026BBCD8@SCACMX008.exchad.jpmchase.net> > People spell your name Stephen, sometimes too. Thinking of changing it? > Gore Vidal's quote has panache, a valid compensation for breaking the usual rule. How many other uses on that page are similar? He provided common examples and reference links. Seems like a pretty reasonable way of trying to prove a point. If you don't like reference links, what would convince you that the point was correct? I have not seen any counter examples or counter references on your behalf... Ramit Ramit Prasad | JPMorgan Chase Investment Bank | Currencies Technology 712 Main Street | Houston, TX 77002 work phone: 713 - 216 - 5423 -- This email is confidential and subject to important disclaimers and conditions including on offers for the purchase or sale of securities, accuracy and completeness of information, viruses, confidentiality, legal privilege, and legal entity disclaimers, available at http://www.jpmorgan.com/pages/disclosures/email. From ramit.prasad at jpmorgan.com Fri Mar 16 16:14:16 2012 From: ramit.prasad at jpmorgan.com (Prasad, Ramit) Date: Fri, 16 Mar 2012 20:14:16 +0000 Subject: Is it technically possible to give Python option of naming process of running script? In-Reply-To: References: <19118128.4791.1331736187952.JavaMail.geo-discussion-forums@vbai14> <22071354.8904.1331796412001.JavaMail.geo-discussion-forums@vbkc1> Message-ID: <5B80DD153D7D744689F57F4FB69AF474026BBD75@SCACMX008.exchad.jpmchase.net> > I was thinging about daemons and system-type stuff. > > One possible problem with linking from one's home directory is that > home directories are often on different filesystems than /usr/bin (or > wherever python is). Using a symlink doesn't work, the process name > still ends up as python2.6 (or whatever the real binary is called). Try a hardlink instead of symlink? It seems to work for me. Ramit Ramit Prasad | JPMorgan Chase Investment Bank | Currencies Technology 712 Main Street | Houston, TX 77002 work phone: 713 - 216 - 5423 -- This email is confidential and subject to important disclaimers and conditions including on offers for the purchase or sale of securities, accuracy and completeness of information, viruses, confidentiality, legal privilege, and legal entity disclaimers, available at http://www.jpmorgan.com/pages/disclosures/email. From ethan at stoneleaf.us Fri Mar 16 16:30:15 2012 From: ethan at stoneleaf.us (Ethan Furman) Date: Fri, 16 Mar 2012 13:30:15 -0700 Subject: Python is readable In-Reply-To: <9shd0kFvgbU1@mid.individual.net> References: <4f612b19$0$1379$4fafbaef@reader2.news.tin.it> <8e72d74f-c844-4de3-8a37-f6b1fdc2291f@y27g2000yqy.googlegroups.com> <50e9ceec-40f1-4ead-b2b6-87328b30d084@ow8g2000pbc.googlegroups.com> <4f61c828$0$1390$4fafbaef@reader2.news.tin.it> <4f61d728$0$1375$4fafbaef@reader2.news.tin.it> <4f61fd0a$0$1389$4fafbaef@reader2.news.tin.it> <4f6280a0$0$29981$c3e8da3$5496439d@news.astraweb.com> <4f6333ca$0$1392$4fafbaef@reader1.news.tin.it> <4f633a1a$0$29981$c3e8da3$5496439d@news.astraweb.com> <9sgsb1FsbpU1@mid.individual.net> <4f636a38$0$29981$c3e8da3$5496439d@news.astraweb.com> <9shd0kFvgbU1@mid.individual.net> Message-ID: <4F63A2D7.7040309@stoneleaf.us> Neil Cerutti wrote: > On 2012-03-16, Steven D'Aprano wrote: >> Ah, perhaps you're talking about *prescriptivist* grammarians, >> who insist on applying grammatical rules that exist only in >> their own fevered imagination. Sorry, I was talking about the >> other sort, the ones who apply the grammatical rules used by >> people in real life. You know the ones: linguists. My mistake. > > I am not pedantic. You are wrong. > When saying somebody is wrong, you really should back it up with references (wiki, dictionary, etc.). At this point, if I had to decide between Steven and you, I'd go with Steven. Of course, it doesn't hurt that everything he has said matches with my experience on the topic. ~Ethan~ From drsalists at gmail.com Fri Mar 16 16:31:13 2012 From: drsalists at gmail.com (Dan Stromberg) Date: Fri, 16 Mar 2012 13:31:13 -0700 Subject: cannot open shared object file In-Reply-To: <4F62E208.70005@hep.caltech.edu> References: <4F62E208.70005@hep.caltech.edu> Message-ID: A suggestion: 1) strace it. http://stromberg.dnsalias.org/~strombrg/debugging-with-syscall-tracers.html 2) Show the output to a C programmer, or take some educated guesses yourself. On Thu, Mar 15, 2012 at 11:47 PM, Steven Lo wrote: > ** > > Hi, > > We are getting the following error during a 'make' process on a CentOS > release 5.4 system: > > Running mkfontdir... > Creating SELinux policy... > /usr/bin/python: error while loading shared libraries: > libpython2.4.so.1.0: cannot open shared object file: No such file or > directory > > > However, we are able to execute 'python' without any problem > > # which python > /usr/bin/python > > # python > Python 2.4.3 (#1, Sep 3 2009, 15:37:37) > [GCC 4.1.2 20080704 (Red Hat 4.1.2-46)] on linux2 > Type "help", "copyright", "credits" or "license" for more information. > >>> > > > # ldd /usr/bin/python > libpython2.4.so.1.0 => /usr/lib64/libpython2.4.so.1.0 > (0x0000003fb7600000) > libpthread.so.0 => /lib64/libpthread.so.0 (0x0000003b59600000) > libdl.so.2 => /lib64/libdl.so.2 (0x0000003b59200000) > libutil.so.1 => /lib64/libutil.so.1 (0x0000003b64000000) > libm.so.6 => /lib64/libm.so.6 (0x0000003b58e00000) > libc.so.6 => /lib64/libc.so.6 (0x0000003b58a00000) > /lib64/ld-linux-x86-64.so.2 (0x0000003b58600000) > > > # ls -lad /usr/lib64/*python* > lrwxrwxrwx 1 root root 19 Feb 27 21:15 /usr/lib64/libpython2.4.so-> libpython2.4.so.1.0 > -r-xr-xr-x 1 root root 1236344 Sep 3 2009 /usr/lib64/libpython2.4.so.1.0 > drwxr-xr-x 18 root root 20480 Feb 27 21:15 /usr/lib64/python2.4 > > > > In this 'make' process, we are suppose to execute the applicate-specific > python > (/opt/rocks/bin/python) which has static link (not dynamic link) > > # ldd /opt/rocks/bin/python > libpthread.so.0 => /lib64/libpthread.so.0 (0x0000003b59600000) > libdl.so.2 => /lib64/libdl.so.2 (0x0000003b59200000) > libutil.so.1 => /lib64/libutil.so.1 (0x0000003b64000000) > libstdc++.so.6 => /usr/lib64/libstdc++.so.6 (0x0000003b6b400000) > libm.so.6 => /lib64/libm.so.6 (0x0000003b58e00000) > libgcc_s.so.1 => /lib64/libgcc_s.so.1 (0x0000003b67c00000) > libc.so.6 => /lib64/libc.so.6 (0x0000003b58a00000) > /lib64/ld-linux-x86-64.so.2 (0x0000003b58600000) > > > > Basically, we try to understand: > * why /opt/rocks/bin/python not being used ? > * why /usr/bin/python can not find the dynamic library > > > Please let us know if you have any suggestion on how to troubleshoot this > problem. > > If this is not the list to ask this type of question, please point us to > the appropriate > list. > > > Thanks. > > S. > > > -- > http://mail.python.org/mailman/listinfo/python-list > > -------------- next part -------------- An HTML attachment was scrubbed... URL: From invalid at invalid.invalid Fri Mar 16 16:54:16 2012 From: invalid at invalid.invalid (Grant Edwards) Date: Fri, 16 Mar 2012 20:54:16 +0000 (UTC) Subject: Is it technically possible to give Python option of naming process of running script? References: <19118128.4791.1331736187952.JavaMail.geo-discussion-forums@vbai14> <22071354.8904.1331796412001.JavaMail.geo-discussion-forums@vbkc1> Message-ID: On 2012-03-16, Prasad, Ramit wrote: > >> One possible problem with linking from one's home directory is that >> home directories are often on different filesystems than /usr/bin (or >> wherever python is). Using a symlink doesn't work, the process name >> still ends up as python2.6 (or whatever the real binary is called). > > Try a hardlink instead of symlink? It seems to work for me. Not across different filesystems -- which was what I was talking about. -- Grant Edwards grant.b.edwards Yow! As President I have at to go vacuum my coin gmail.com collection! From storchaka at gmail.com Fri Mar 16 16:57:04 2012 From: storchaka at gmail.com (Serhiy Storchaka) Date: Fri, 16 Mar 2012 22:57:04 +0200 Subject: Why not use juxtaposition to indicate function application In-Reply-To: <4f636e43$0$29981$c3e8da3$5496439d@news.astraweb.com> References: <42cac695-761e-4cdb-aa3b-7c82789b76f9@h20g2000yqd.googlegroups.com> <4f636391$0$1382$4fafbaef@reader1.news.tin.it> <4f636acb$0$1381$4fafbaef@reader1.news.tin.it> <4f636e43$0$29981$c3e8da3$5496439d@news.astraweb.com> Message-ID: 16.03.12 18:45, Steven D'Aprano ???????(??): > If f is a function which normally takes (for the sake of the argument) > one argument, then f would call the function with no arguments (which may > return a curried function, or may apply default arguments, or perhaps > raise an exception). So how would you refer to the function itself > without calling it? lambda:f From rosuav at gmail.com Fri Mar 16 16:59:18 2012 From: rosuav at gmail.com (Chris Angelico) Date: Sat, 17 Mar 2012 07:59:18 +1100 Subject: Python is readable In-Reply-To: <4F63A2D7.7040309@stoneleaf.us> References: <4f612b19$0$1379$4fafbaef@reader2.news.tin.it> <8e72d74f-c844-4de3-8a37-f6b1fdc2291f@y27g2000yqy.googlegroups.com> <50e9ceec-40f1-4ead-b2b6-87328b30d084@ow8g2000pbc.googlegroups.com> <4f61c828$0$1390$4fafbaef@reader2.news.tin.it> <4f61d728$0$1375$4fafbaef@reader2.news.tin.it> <4f61fd0a$0$1389$4fafbaef@reader2.news.tin.it> <4f6280a0$0$29981$c3e8da3$5496439d@news.astraweb.com> <4f6333ca$0$1392$4fafbaef@reader1.news.tin.it> <4f633a1a$0$29981$c3e8da3$5496439d@news.astraweb.com> <9sgsb1FsbpU1@mid.individual.net> <4f636a38$0$29981$c3e8da3$5496439d@news.astraweb.com> <9shd0kFvgbU1@mid.individual.net> <4F63A2D7.7040309@stoneleaf.us> Message-ID: On Sat, Mar 17, 2012 at 7:30 AM, Ethan Furman wrote: > Neil Cerutti wrote: >> >> I am not pedantic. You are wrong. >> > > When saying somebody is wrong, you really should back it up with references > (wiki, dictionary, etc.). I interpret this simply as a witty statement, one that can be thrown into any argument that has descended into pure pedantry. As such, it needs no backing, and is completely on topic for this thread (if not for python-list itself). Personally, I find it amusing. ChrisA From clp2 at rebertia.com Fri Mar 16 17:02:51 2012 From: clp2 at rebertia.com (Chris Rebert) Date: Fri, 16 Mar 2012 14:02:51 -0700 Subject: Why not use juxtaposition to indicate function application In-Reply-To: References: <42cac695-761e-4cdb-aa3b-7c82789b76f9@h20g2000yqd.googlegroups.com> <4f636391$0$1382$4fafbaef@reader1.news.tin.it> <4f636acb$0$1381$4fafbaef@reader1.news.tin.it> <4f636e43$0$29981$c3e8da3$5496439d@news.astraweb.com> Message-ID: On Fri, Mar 16, 2012 at 1:57 PM, Serhiy Storchaka wrote: > 16.03.12 18:45, Steven D'Aprano ???????(??): >> If f is a function which normally takes (for the sake of the argument) >> one argument, then f would call the function with no arguments (which may >> return a curried function, or may apply default arguments, or perhaps >> raise an exception). So how would you refer to the function itself >> without calling it? > > lambda:f Doesn't help; wouldn't the lambda be implicitly called? Cheers, Chris From andrea.crotti.0 at gmail.com Fri Mar 16 18:04:04 2012 From: andrea.crotti.0 at gmail.com (Andrea Crotti) Date: Fri, 16 Mar 2012 22:04:04 +0000 Subject: avoid import short-circuiting In-Reply-To: References: <4F636F0D.3060006@gmail.com> Message-ID: <4F63B8D4.8010103@gmail.com> On 03/16/2012 05:19 PM, Robert Kern wrote: > On 3/16/12 4:49 PM, Andrea Crotti wrote: >> I started the following small project: >> >> https://github.com/AndreaCrotti/import-tree >> >> because I would like to find out what exactly depends on what at >> run-time, using >> an import hook. >> >> It works quite well for small examples but the main problem is that >> once a >> module is imported >> it's added to sys.modules and then it doesn't go through the import >> hook anymore. >> >> I tried to mess around with sys.modules but it might not be a good >> idea, and it >> leads to easy >> infinite loops. >> Is there a good way to achieve this? >> I guess I could do the loop detection myself, but that should not be >> too hard.. > > You want to monkeypatch __builtin__.__import__() instead. It always > gets called. > Seems like a good idea :) My first attempt failes though def full(module): from __builtin__ import __import__ ls = [] orig = __import__ def my_import(name): ls.append(name) orig(name) __import__ = my_import __import__(module) __import__ = orig return ls it imports only the first element and doesn't import the dependencies.. Any hints? From storchaka at gmail.com Fri Mar 16 18:14:19 2012 From: storchaka at gmail.com (Serhiy Storchaka) Date: Sat, 17 Mar 2012 00:14:19 +0200 Subject: Why not use juxtaposition to indicate function application In-Reply-To: References: <42cac695-761e-4cdb-aa3b-7c82789b76f9@h20g2000yqd.googlegroups.com> <4f636391$0$1382$4fafbaef@reader1.news.tin.it> <4f636acb$0$1381$4fafbaef@reader1.news.tin.it> <4f636e43$0$29981$c3e8da3$5496439d@news.astraweb.com> Message-ID: 16.03.12 23:02, Chris Rebert ???????(??): > On Fri, Mar 16, 2012 at 1:57 PM, Serhiy Storchaka wrote: >> lambda:f > > Doesn't help; wouldn't the lambda be implicitly called? No, the lambda is only for declaration. I prefer to use braces for lambda syntax, it will be fine with 'if' and 'while' functions. But all this for some other, fictitious, language, not for Python. From ian.g.kelly at gmail.com Fri Mar 16 18:18:07 2012 From: ian.g.kelly at gmail.com (Ian Kelly) Date: Fri, 16 Mar 2012 16:18:07 -0600 Subject: avoid import short-circuiting In-Reply-To: <4F63B8D4.8010103@gmail.com> References: <4F636F0D.3060006@gmail.com> <4F63B8D4.8010103@gmail.com> Message-ID: On Fri, Mar 16, 2012 at 4:04 PM, Andrea Crotti wrote: >> You want to monkeypatch __builtin__.__import__() instead. It always gets >> called. >> > > Seems like a good idea :) > > My first attempt failes though > > > def full(module): > ? ?from __builtin__ import __import__ > ? ?ls = [] > ? ?orig = __import__ > > ? ?def my_import(name): > ? ? ? ?ls.append(name) > ? ? ? ?orig(name) > > ? ?__import__ = my_import > ? ?__import__(module) > ? ?__import__ = orig > ? ?return ls > > > it imports only the first element and doesn't import the dependencies.. > Any hints? You didn't actually monkey-patch it. You just created a local called __import__ that stores a wrapped version of the function. You need to actually replace it in the __builtin__ module: import __builtin__ __builtin__.__import__ = my_import Cheers, Ian From robert.kern at gmail.com Fri Mar 16 18:20:15 2012 From: robert.kern at gmail.com (Robert Kern) Date: Fri, 16 Mar 2012 22:20:15 +0000 Subject: avoid import short-circuiting In-Reply-To: <4F63B8D4.8010103@gmail.com> References: <4F636F0D.3060006@gmail.com> <4F63B8D4.8010103@gmail.com> Message-ID: On 3/16/12 10:04 PM, Andrea Crotti wrote: > On 03/16/2012 05:19 PM, Robert Kern wrote: >> On 3/16/12 4:49 PM, Andrea Crotti wrote: >>> I started the following small project: >>> >>> https://github.com/AndreaCrotti/import-tree >>> >>> because I would like to find out what exactly depends on what at run-time, using >>> an import hook. >>> >>> It works quite well for small examples but the main problem is that once a >>> module is imported >>> it's added to sys.modules and then it doesn't go through the import hook >>> anymore. >>> >>> I tried to mess around with sys.modules but it might not be a good idea, and it >>> leads to easy >>> infinite loops. >>> Is there a good way to achieve this? >>> I guess I could do the loop detection myself, but that should not be too hard.. >> >> You want to monkeypatch __builtin__.__import__() instead. It always gets called. >> > > Seems like a good idea :) > > My first attempt failes though > > > def full(module): > from __builtin__ import __import__ > ls = [] > orig = __import__ > > def my_import(name): > ls.append(name) > orig(name) > > __import__ = my_import > __import__(module) > __import__ = orig > return ls > > > it imports only the first element and doesn't import the dependencies.. > Any hints? You need to replace it in __builtin__. Don't forget to handle all of the arguments. import __builtin__ orig_import = __builtin__.__import__ all_imports = [] def my_import(*args, **kwds): module = orig_import(*args, **kwds) # Get the fully-qualified module name from the module object itself # instead of trying to compute it yourself. all_imports.append(module.__name__) return module __builtin__.__import__ = my_import For extra points, make a context manager that hooks and then unhooks your custom importer. You may also want to take a look at an import profiler that I once made: http://www.enthought.com/~rkern/cgi-bin/hgwebdir.cgi/import_profiler/file/tip/import_profiler.py#l23 -- Robert Kern "I have come to believe that the whole world is an enigma, a harmless enigma that is made terrible by our own mad attempt to interpret it as though it had an underlying truth." -- Umberto Eco From andrea.crotti.0 at gmail.com Fri Mar 16 19:14:16 2012 From: andrea.crotti.0 at gmail.com (Andrea Crotti) Date: Fri, 16 Mar 2012 23:14:16 +0000 Subject: avoid import short-circuiting In-Reply-To: References: <4F636F0D.3060006@gmail.com> <4F63B8D4.8010103@gmail.com> Message-ID: <4F63C948.8020700@gmail.com> On 03/16/2012 10:20 PM, Robert Kern wrote: > On 3/16/12 10:04 PM, Andrea Crotti wrote: >> On 03/16/2012 05:19 PM, Robert Kern wrote: >>> On 3/16/12 4:49 PM, Andrea Crotti wrote: >>>> I started the following small project: >>>> >>>> https://github.com/AndreaCrotti/import-tree >>>> >>>> because I would like to find out what exactly depends on what at >>>> run-time, using >>>> an import hook. >>>> >>>> It works quite well for small examples but the main problem is that >>>> once a >>>> module is imported >>>> it's added to sys.modules and then it doesn't go through the import >>>> hook >>>> anymore. >>>> >>>> I tried to mess around with sys.modules but it might not be a good >>>> idea, and it >>>> leads to easy >>>> infinite loops. >>>> Is there a good way to achieve this? >>>> I guess I could do the loop detection myself, but that should not >>>> be too hard.. >>> >>> You want to monkeypatch __builtin__.__import__() instead. It always >>> gets called. >>> >> >> Seems like a good idea :) >> >> My first attempt failes though >> >> >> def full(module): >> from __builtin__ import __import__ >> ls = [] >> orig = __import__ >> >> def my_import(name): >> ls.append(name) >> orig(name) >> >> __import__ = my_import >> __import__(module) >> __import__ = orig >> return ls >> >> >> it imports only the first element and doesn't import the dependencies.. >> Any hints? > > You need to replace it in __builtin__. Don't forget to handle all of > the arguments. > > > import __builtin__ > > orig_import = __builtin__.__import__ > > all_imports = [] > > def my_import(*args, **kwds): > module = orig_import(*args, **kwds) > # Get the fully-qualified module name from the module object itself > # instead of trying to compute it yourself. > all_imports.append(module.__name__) > return module > > __builtin__.__import__ = my_import > > > For extra points, make a context manager that hooks and then unhooks your > custom importer. > > You may also want to take a look at an import profiler that I once made: > > http://www.enthought.com/~rkern/cgi-bin/hgwebdir.cgi/import_profiler/file/tip/import_profiler.py#l23 > > Very nice thanks, here it is class ImportMock: def _my_import(self, *args, **kwargs): self.ls.append(args[0]) self.orig(*args, **kwargs) def __enter__(self): self.orig = __builtin__.__import__ self.ls = [] __builtin__.__import__ = self._my_import return self def __exit__(self, type, value, traceback): __builtin__.__import__ = self.orig now I only need to make it create also the graph and then I should be done :) From torriem at gmail.com Fri Mar 16 19:39:21 2012 From: torriem at gmail.com (Michael Torrie) Date: Fri, 16 Mar 2012 17:39:21 -0600 Subject: Python is readable In-Reply-To: <4f636ed5$0$29981$c3e8da3$5496439d@news.astraweb.com> References: <4f612b19$0$1379$4fafbaef@reader2.news.tin.it> <8e72d74f-c844-4de3-8a37-f6b1fdc2291f@y27g2000yqy.googlegroups.com> <50e9ceec-40f1-4ead-b2b6-87328b30d084@ow8g2000pbc.googlegroups.com> <4f61c828$0$1390$4fafbaef@reader2.news.tin.it> <4f61d728$0$1375$4fafbaef@reader2.news.tin.it> <4f61fd0a$0$1389$4fafbaef@reader2.news.tin.it> <4f620837$0$1382$4fafbaef@reader2.news.tin.it> <4f627c25$0$1381$4fafbaef@reader2.news.tin.it> <4f62b9be$0$29981$c3e8da3$5496439d@news.astraweb.com> <4f632da5$0$1375$4fafbaef@reader1.news.tin.it> <4f636ed5$0$29981$c3e8da3$5496439d@news.astraweb.com> Message-ID: <4F63CF29.7010906@gmail.com> On 03/16/2012 10:48 AM, Steven D'Aprano wrote: > On Fri, 16 Mar 2012 13:10:12 +0100, Kiuhnm wrote: > >> Maybe we should define *exactly* what readability is (in less then 500 >> lines, if possible). > > If you can't be bothered to read my post before replying, save yourself > some more time and don't bother to reply at all. > > I quote from the part of the my post you deleted: > > When people talk about readability, they normally mean to > ask how much mental effort is needed to interpret the > meaning of the text, not how much time does it take to > pass your eyes over the characters. In other words they > are actually talking about comprehensibility. > > > Unless I've made a mistake counting, that's less than 500 lines. > > >> According to your view, ASM code is more readable than Python code. It's >> just that there's more to read in ASM. > > What a ridiculous misrepresentation of my position. Readability is not > proportional to length. For someone who claims he's merely examining the language and seeking to learn about it, Kiuhnm is jumping awfully quickly into the realm of trolling. From kiuhnm03.4t.yahoo.it Fri Mar 16 21:21:32 2012 From: kiuhnm03.4t.yahoo.it (Kiuhnm) Date: Sat, 17 Mar 2012 02:21:32 +0100 Subject: Currying in Python Message-ID: <4f63e724$0$1386$4fafbaef@reader1.news.tin.it> Here we go. ---> def genCur(f, unique = True, minArgs = -1): """ Generates a 'curried' version of a function. """ def geng(curArgs, curKwargs): def g(*args, **kwargs): nonlocal f, curArgs, curKwargs, minArgs; # our STATIC data if len(args) or len(kwargs): # Allocates data for the next 'g'. We don't want to modify our # static data. newArgs = curArgs[:]; newKwargs = dict.copy(curKwargs); # Adds positional arguments. newArgs += args; # Adds/updates keyword arguments. if unique: # We don't want repeated keyword arguments. for k in kwargs.keys(): if k in newKwargs: raise(Exception("Repeated kw arg while unique = True")); newKwargs.update(kwargs); # Checks whether it's time to evaluate f. if minArgs >= 0 and minArgs <= len(newArgs) + len(newKwargs): return f(*newArgs, **newKwargs); # f has enough args else: return geng(newArgs, newKwargs); # f needs some more args else: return f(*curArgs, **curKwargs); # the caller forced the evaluation return g; return geng([], {}); def cur(f, minArgs = -1): return genCur(f, True, minArgs); def curr(f, minArgs = -1): return genCur(f, False, minArgs); # Simple Function. def f(a, b, c, d, e, f, g = 100): print(a, b, c, d, e, f, g); # NOTE: '<====' means "this line prints to the screen". # Example 1. c1 = cur(f)(1); c2 = c1(2, d = 4); # Note that c is still unbound c3 = c2(3)(f = 6)(e = 5); # now c = 3 c3(); # () forces the evaluation <==== c4 = c2(30)(f = 60)(e = 50); # now c = 30 c4(); # () forces the evaluation <==== print("\n------\n"); # Example 2. c1 = curr(f)(1, 2)(3, 4); # curr = cur with possibly repeated # keyword args c2 = c1(e = 5)(f = 6)(e = 10)(); # ops... we repeated 'e' because we <==== # changed our mind about it! # again, () forces the evaluation print("\n------\n"); # Example 3. c1 = cur(f, 6); # forces the evaluation after 6 arguments c2 = c1(1, 2, 3); # num args = 3 c3 = c2(4, f = 6); # num args = 5 c4 = c3(5); # num args = 6 ==> evalution <==== c5 = c3(5, g = -1); # num args = 7 ==> evaluation <==== # we can specify more than 6 arguments, but # 6 are enough to force the evaluation print("\n------\n"); # Example 4. def printTree(func, level = -1): if level == -1: printTree(cur(func), level + 1); elif level == 6: func(g = '')(); # or just func('')() else: printTree(func(0), level + 1); printTree(func(1), level + 1); printTree(f); print("\n------\n"); def f2(*args): print(", ".join(["%3d"%(x) for x in args])); def stress(f, n): if n: stress(f(n), n - 1) else: f(); # enough is enough stress(cur(f2), 100); <--- Kiuhnm From robert.kern at gmail.com Fri Mar 16 21:22:05 2012 From: robert.kern at gmail.com (Robert Kern) Date: Sat, 17 Mar 2012 01:22:05 +0000 Subject: avoid import short-circuiting In-Reply-To: <4F63C948.8020700@gmail.com> References: <4F636F0D.3060006@gmail.com> <4F63B8D4.8010103@gmail.com> <4F63C948.8020700@gmail.com> Message-ID: On 3/16/12 11:14 PM, Andrea Crotti wrote: > Very nice thanks, here it is > class ImportMock: > > def _my_import(self, *args, **kwargs): > self.ls.append(args[0]) > self.orig(*args, **kwargs) There's a bug here. You need to return the module object you got from calling self.orig(). By the way, you really should follow my example of getting the .__name__ from the module object instead of the argument in order to properly account for relative imports inside packages. __import__() will be passed the relative name, not the fully-qualified name. -- Robert Kern "I have come to believe that the whole world is an enigma, a harmless enigma that is made terrible by our own mad attempt to interpret it as though it had an underlying truth." -- Umberto Eco From nagle at animats.com Fri Mar 16 21:44:41 2012 From: nagle at animats.com (John Nagle) Date: Fri, 16 Mar 2012 18:44:41 -0700 Subject: Does anyone actually use PyPy in production? Message-ID: <4f63ec8b$0$11975$742ec2ed@news.sonic.net> Does anyone run PyPy in production? John Nagle From steve+comp.lang.python at pearwood.info Fri Mar 16 21:46:59 2012 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 17 Mar 2012 01:46:59 GMT Subject: Currying in Python References: <4f63e724$0$1386$4fafbaef@reader1.news.tin.it> Message-ID: <4f63ed13$0$29981$c3e8da3$5496439d@news.astraweb.com> On Sat, 17 Mar 2012 02:21:32 +0100, Kiuhnm wrote: > Here we go. [snip code] Have you looked at functools.partial? import functools new_func = functools.partial(func, ham, spam=23) (I am aware that, technically, currying and partial function application are not quite the same thing, but it seems to me on a superficial reading that your function performs partial function application rather than actually currying. But I haven't read it in enough detail to be sure.) -- Steven From NA Fri Mar 16 21:51:49 2012 From: NA (NA) Date: Fri, 16 Mar 2012 21:51:49 -0400 Subject: Python simulate browser activity References: <214c4c0c-f8ec-4030-946b-8becc8e1aa9c@ur9g2000pbc.googlegroups.com> Message-ID: <2012031621514936408-NA@news.giganews.com> selenium is the best bet. http://github.com/antlong/selenium From dcday137 at gmail.com Fri Mar 16 21:56:41 2012 From: dcday137 at gmail.com (Collin Day) Date: Fri, 16 Mar 2012 19:56:41 -0600 Subject: PIL for py3k not picking up external libraries Message-ID: <4F63EF59.6010605@gmail.com> Hi all, I am using python 3.2 on an amd64 Gentoo system. I was trying to compile an unofficial version of PIL to work in 3.2 that I found here: http://www.lfd.uci.edu/~gohlke/pythonlibs Anyway, when I run the setup.py to compile the source, it doesn't pick up tkinter, zlib, or freetype. When I use pdb to step through the code where it is looking for libraries (for example zlib here), I make it all the way into unixcompiler.py: > /usr/lib64/python3.2/distutils/unixccompiler.py(318)find_library_file() -> shared_f = self.library_filename(lib, lib_type='shared') which returns 'libz.cpython-32.so' or 'libtcl8.5.cpython-32.py', depending on what it is looking for. If I step in further to ccompiler.py "") 881 fmt = getattr(self, lib_type + "_lib_format") 882 ext = getattr(self, lib_type + "_lib_extension") 883 884 -> dir, base = os.path.split(libname) 885 filename = fmt % (base, ext) The extension returns .cpython-32.so I have a lot of these extensions for site packages, but how do I generate libraries compatible with this for say tkinter, zlib, etc. For example, I see libtcl8.5.so, but no libtcl8.5.cpython-32.so. Can someone tell me what I am missing? Thanks! From java at leeclemens.net Fri Mar 16 22:12:14 2012 From: java at leeclemens.net (Lee Clemens) Date: Fri, 16 Mar 2012 22:12:14 -0400 Subject: Daemonization / Popen / pipe issue Message-ID: <4F63F2FE.1030409@leeclemens.net> Hello, I am new to the list, have many years of Java experience but an fairly new to Python. I am hoping this is an issue caused by my misuse of Python in a multi-threaded way, but so far no one has identified such to me. I have a multi-threaded application, each thread has an instance of a class which calls Popen. The command(s) being executed (shell=True) include pipes. The errors I have seen involve "broken pipe" and unexepected output (as demonstrated in the test case). This issues only seem to occur when the application is "daemonized", using a double-fork and os.dup2, as shown here: http://www.jejik.com/articles/2007/02/a_simple_unix_linux_daemon_in_python/ I have provided a test-case here: https://gist.github.com/2054194 Please test how flipping DAEMONIZE between True and False yield different results. I have used this on Red Hat/CentOS/Fedora using Python 2.6.x (latest) and 2.7.1 and on Solaris with 2.6.4. I know it's a bit long, but I have added comments to explain where the oddities appear and how it is called (fairly straight-forward multi-threaded). Please keep in mind this is a test-case based on a much larger application - I understand a lot of pieces included here are not necessary in this case. Any assistance/advice would be greatly appreciated. Thanks, Lee From steve+comp.lang.python at pearwood.info Fri Mar 16 22:14:54 2012 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 17 Mar 2012 02:14:54 GMT Subject: Currying in Python References: <4f63e724$0$1386$4fafbaef@reader1.news.tin.it> <4f63ed13$0$29981$c3e8da3$5496439d@news.astraweb.com> Message-ID: <4f63f39e$0$29981$c3e8da3$5496439d@news.astraweb.com> On Sat, 17 Mar 2012 01:46:59 +0000, Steven D'Aprano wrote: > On Sat, 17 Mar 2012 02:21:32 +0100, Kiuhnm wrote: > >> Here we go. > [snip code] > > > Have you looked at functools.partial? > > > import functools > new_func = functools.partial(func, ham, spam=23) > > > (I am aware that, technically, currying and partial function application > are not quite the same thing, but it seems to me on a superficial > reading that your function performs partial function application rather > than actually currying. But I haven't read it in enough detail to be > sure.) Okay, that was an incredibly superficial reading, because on a second reading, I can see it's nothing like partial function application. Sorry for the noise. -- Steven From research at johnohagan.com Fri Mar 16 23:37:26 2012 From: research at johnohagan.com (John O'Hagan) Date: Sat, 17 Mar 2012 14:37:26 +1100 Subject: Daemonization / Popen / pipe issue In-Reply-To: <4F63F2FE.1030409@leeclemens.net> References: <4F63F2FE.1030409@leeclemens.net> Message-ID: <20120317143726.7134d2b04d56d1759d8eeeb6@johnohagan.com> On Fri, 16 Mar 2012 22:12:14 -0400 Lee Clemens wrote: > > I have a multi-threaded application, each thread has an instance of a class > which calls Popen. The command(s) being executed (shell=True) include pipes. > The errors I have seen involve "broken pipe" and unexepected output (as > demonstrated in the test case). > > This issues only seem to occur when the application is "daemonized", using a > double-fork and os.dup2, as shown here: > http://www.jejik.com/articles/2007/02/a_simple_unix_linux_daemon_in_python/ > > I have provided a test-case here: https://gist.github.com/2054194 > > Please test how flipping DAEMONIZE between True and False yield different > results. I haven't looked at your test case yet, but a possible cause is the fact that the main application (or main thread) exits if it has finished executing and only daemon threads remain. This can abruptly terminate threads which may be busy, for example, communicating via a pipe. The best solution IMO is not to use daemon threads, but to give all threads a way to terminate cleanly before the main thread does, even if this means using a flag or the like. HTH, John From tjreedy at udel.edu Sat Mar 17 00:38:27 2012 From: tjreedy at udel.edu (Terry Reedy) Date: Sat, 17 Mar 2012 00:38:27 -0400 Subject: Why not use juxtaposition to indicate function application In-Reply-To: <42cac695-761e-4cdb-aa3b-7c82789b76f9@h20g2000yqd.googlegroups.com> References: <42cac695-761e-4cdb-aa3b-7c82789b76f9@h20g2000yqd.googlegroups.com> Message-ID: On 3/16/2012 9:14 AM, bruno.desthuilliers at gmail.com wrote: > On Mar 16, 1:45 pm, Ray Song wrote: >> I confess i've indulged in Haskell and found >> f a >> more readable than >> f(a) > > Hmmm... What about: > > f a b > > versus > > f(a(b)) > > or was it supposed to be read as > > f(a)(b) > > > or as > > f(a, b) > > ?-) One also has to consider Python calls with *args, **kwds, and arg=obj. These are all compile-time SyntaxErrors unless inside parens that follow a expression. Also, function calls, especially in a functional language without side-effects, do not usually occur in isolation. 'f(a) + 3' would have to be written as '(f a) + 3', so saving of parens anyway. Also, is 'f a - 2' f(a -2) or f(a, -2)? A new precedence rule is needed to disambiguage. -- Terry Jan Reedy From tjreedy at udel.edu Sat Mar 17 01:09:04 2012 From: tjreedy at udel.edu (Terry Reedy) Date: Sat, 17 Mar 2012 01:09:04 -0400 Subject: Python is readable In-Reply-To: <9sgsb1FsbpU1@mid.individual.net> References: <4f612b19$0$1379$4fafbaef@reader2.news.tin.it> <8e72d74f-c844-4de3-8a37-f6b1fdc2291f@y27g2000yqy.googlegroups.com> <50e9ceec-40f1-4ead-b2b6-87328b30d084@ow8g2000pbc.googlegroups.com> <4f61c828$0$1390$4fafbaef@reader2.news.tin.it> <4f61d728$0$1375$4fafbaef@reader2.news.tin.it> <4f61fd0a$0$1389$4fafbaef@reader2.news.tin.it> <4f6280a0$0$29981$c3e8da3$5496439d@news.astraweb.com> <4f6333ca$0$1392$4fafbaef@reader1.news.tin.it> <4f633a1a$0$29981$c3e8da3$5496439d@news.astraweb.com> <9sgsb1FsbpU1@mid.individual.net> Message-ID: On 3/16/2012 9:08 AM, Neil Cerutti wrote: > A grammarian always uses complete sentence before a colon, even > when introducing a list. The Chicago Manual of Style*, 13th edition, says "The colon is used to mark a discontinuity of grammatical construction greater than that indicated by the semicolon and less than that indicated by the period." While most of the examples in that section have what would be a complete sentence before the colon, not all do. Not in that section is this, from the Table of Contents: "Documentation: References, Notes, and Bibliographies". Here are a couple more from their Library of Congress Cataloging in Publication data: "Rev. ed. of: A manual of style." and "Bibliography: p.". And in letters: "To:", "From:", and "Date:" *A major style guide for general American writing and publication: used by some as the 'Bible'. -- Terry Jan Reedy From tjreedy at udel.edu Sat Mar 17 01:20:15 2012 From: tjreedy at udel.edu (Terry Reedy) Date: Sat, 17 Mar 2012 01:20:15 -0400 Subject: Does anyone actually use PyPy in production? In-Reply-To: <4f63ec8b$0$11975$742ec2ed@news.sonic.net> References: <4f63ec8b$0$11975$742ec2ed@news.sonic.net> Message-ID: On 3/16/2012 9:44 PM, John Nagle wrote: > Does anyone run PyPy in production? The pypy list, accessible via gmane, might be a better place to ask. But my impression is yes, and that they are getting commercial $$$ support. -- Terry Jan Reedy From rustompmody at gmail.com Sat Mar 17 01:26:28 2012 From: rustompmody at gmail.com (rusi) Date: Fri, 16 Mar 2012 22:26:28 -0700 (PDT) Subject: Haskellizing python (was Why not use juxtaposition to indicate function application) References: Message-ID: On Mar 16, 5:45?pm, Ray Song wrote: > I confess i've indulged in Haskell and found > ? ? f a > more readable than > ? ? f(a) > > And why aren't functions curried (partially applied function is another function which takes the rest arguments) by default? > > Thanks in advance for any suggestions. > > -- > Ray In Haskell a b c d is short for (((a b) c) d) This works nicely when the latter is commonly required, as for example happens in a language where what one may call 'the currying convention' is the default. It fails when one wants the opposite convention -- a (b (c (d))) -- which may be called the 'function-composition convention.' The fact that the default convention in haskell is not always a good idea is seen in the existence of a special application operator $ with low precedence which allows a (b (c (d))) to be written as a $ b $ c $ d It is another matter: as someone pointed out that () is overloaded in python to denote: - function application - tupling - grouping Comes from the hegemony of ASCII. A from-first-principles unicode language would use more of these: http://xahlee.org/comp/unicode_matching_brackets.html From cosmius at gmail.com Sat Mar 17 01:30:34 2012 From: cosmius at gmail.com (Cosmia Luna) Date: Fri, 16 Mar 2012 22:30:34 -0700 (PDT) Subject: How to get a reference of the 'owner' class to which a method belongs in Python 3.X? Message-ID: <20411334.2044.1331962234309.JavaMail.geo-discussion-forums@yncd8> I'm porting my existing work to Python 3.X, but... class Foo: def bar(self): pass mthd = Foo.bar assert mthd.im_class is Foo # this does not work in py3k So, how can I get a reference to Foo? This is important when writing decorators, the only way I can think out is: class Foo: def bar(self): 'Foo' # manually declare the owner class pass mthd = Foo.bar assert mthd.__globals__[mthd.__doc__] is Foo # this works class Child(Foo): def bar(self): 'Child' # I have to override all method defined by bar but do nothing pass child_mthd = Child.bar assert child_mthd.__globals__[child_mthd.__doc__] is Child # this works But the code above is quite ugly and abuses the __doc__. Is there any equivalent in py3k of im_class? Thanks, Cosmia From clp2 at rebertia.com Sat Mar 17 01:51:05 2012 From: clp2 at rebertia.com (Chris Rebert) Date: Fri, 16 Mar 2012 22:51:05 -0700 Subject: How to get a reference of the 'owner' class to which a method belongs in Python 3.X? In-Reply-To: <20411334.2044.1331962234309.JavaMail.geo-discussion-forums@yncd8> References: <20411334.2044.1331962234309.JavaMail.geo-discussion-forums@yncd8> Message-ID: On Fri, Mar 16, 2012 at 10:30 PM, Cosmia Luna wrote: > I'm porting my existing work to Python 3.X, but... > > class Foo: > ? ?def bar(self): > ? ? ? ?pass > > mthd = Foo.bar > > assert mthd.im_class is Foo # this does not work in py3k > > So, how can I get a reference to Foo? This is important when writing > decorators, Could you give an example of such a decorator? Cheers, Chris From dcday137 at gmail.com Sat Mar 17 02:05:29 2012 From: dcday137 at gmail.com (Collin Day) Date: Sat, 17 Mar 2012 00:05:29 -0600 Subject: Question about python 3.2 distutils Message-ID: <4F6429A9.1010008@gmail.com> Hi all, I have a question about python 3.2 distutils on a Gentoo amd64 system. When I open an ipython session and import distutils.unixcompiler and then check the shared library extension with UnixCCompiler.shared)lib_extension, it returns '.so', as I would expect. When I run a setup.py in an unofficial PIL source that should work with python 3.2 and step into it, I hit the line: find_library_file(self, "tcl" + version): feature.tcl = "tcl"+TCL_VERSION self is: <__main__.pil_build_ext object at 0xf44510> find_library_file is: def find_library_file(self, library): return self.compiler.find_library_file(self.compiler.library_dirs, library) self.compiler is library is: 'tcl8.5' when I check the shared_lib_extension it returns '.cpython-32.so' - not '.so' This is causing a problem because, for example, I have libtcl8.5.so, but it is looking for libtcl8.5.cpython-32.so. Where is this shared lib extension being determined? After all, in an interactive session, it is just looking for .so, but in the script, it is looking for .cpython-32.so. I tried grep -R cpython-32 * in the top level directory of ther PIL source I am using, thinking it may be ovridden or set somewhere, but it turns up empty. Can anyone tell me what the difference is? I posted earlier, but I just noticed this difference between interactive session and script. Thanks! From orgnut at yahoo.com Sat Mar 17 02:39:28 2012 From: orgnut at yahoo.com (Larry Hudson) Date: Fri, 16 Mar 2012 23:39:28 -0700 Subject: Why not use juxtaposition to indicate function application In-Reply-To: References: Message-ID: On 03/16/2012 05:45 AM, Ray Song wrote: > I confess i've indulged in Haskell and found > f a > more readable than > f(a) > > And why aren't functions curried (partially applied function is another function which takes the rest arguments) by default? > > > Thanks in advance for any suggestions. > > -- > Ray My suggestion is that your question is irrelevant -- Python and Haskell are two different languages each with different syntax rules and coming from different backgrounds. I would say that trying to make any language look like some other is, at best, misguided. Simply learn, and get used to, the language you're using AS IT IS DEFINED, not as you think it should be. If you want to combine the features of two different languages, write a new one -- don't expect that existing languages are going to change due to someone's whim. To expect otherwise is simply a waste of time. As to readability, I would suggest that that's more a function of what you're used to than any inherent language syntax rules. If my comments seem harsh -- sorry 'bout that. I'm old, and sometimes tend to be a curmugeon. And as a completely irrelevant aside concerning readability: Is anyone familiar with the IOCCC (International Obfuscated C Coding Contest)? The object is to write the most obscure, but functional, C code possible. I haven't looked at any of this for many years myself, but I just Googled it to see that this contest is still going on. Anyone familiar with C might find it amusing to take a look... -=- Larry -=- From chardster at gmail.com Sat Mar 17 03:34:57 2012 From: chardster at gmail.com (Richard Thomas) Date: Sat, 17 Mar 2012 00:34:57 -0700 (PDT) Subject: How to get a reference of the 'owner' class to which a method belongs in Python 3.X? In-Reply-To: <20411334.2044.1331962234309.JavaMail.geo-discussion-forums@yncd8> References: <20411334.2044.1331962234309.JavaMail.geo-discussion-forums@yncd8> Message-ID: <32504391.2142.1331969697343.JavaMail.geo-discussion-forums@ynil17> On Saturday, 17 March 2012 05:30:34 UTC, Cosmia Luna wrote: > I'm porting my existing work to Python 3.X, but... > > class Foo: > def bar(self): > pass > > mthd = Foo.bar > > assert mthd.im_class is Foo # this does not work in py3k mthd.im_class is the class of mthd.im_self not the class that defined the method. > > So, how can I get a reference to Foo? This is important when writing > decorators, the only way I can think out is: Not sure what sort of decorators you're writing. Examples? You can achieve this with metaclasses but if you're using classes from someone else's code this doesn't necessarily work. Something in inspect module can probably do the trick, check the docs. Frankly though it sounds messy no matter what. It might be better to find an alternative to knowing the class. > class Foo: > def bar(self): > 'Foo' # manually declare the owner class > pass > > mthd = Foo.bar > > assert mthd.__globals__[mthd.__doc__] is Foo # this works > > class Child(Foo): > def bar(self): > 'Child' # I have to override all method defined by bar but do nothing > pass > > child_mthd = Child.bar > > assert child_mthd.__globals__[child_mthd.__doc__] is Child # this works > > But the code above is quite ugly and abuses the __doc__. Is there any > equivalent in py3k of im_class? > > Thanks, > Cosmia From cosmius at gmail.com Sat Mar 17 04:11:17 2012 From: cosmius at gmail.com (Cosmia Luna) Date: Sat, 17 Mar 2012 01:11:17 -0700 (PDT) Subject: How to get a reference of the 'owner' class to which a method belongs in Python 3.X? In-Reply-To: <32504391.2142.1331969697343.JavaMail.geo-discussion-forums@ynil17> References: <20411334.2044.1331962234309.JavaMail.geo-discussion-forums@yncd8> <32504391.2142.1331969697343.JavaMail.geo-discussion-forums@ynil17> Message-ID: <2929404.2007.1331971877783.JavaMail.geo-discussion-forums@ynbo9> On Saturday, March 17, 2012 3:34:57 PM UTC+8, Richard Thomas wrote: > On Saturday, 17 March 2012 05:30:34 UTC, Cosmia Luna wrote: > > I'm porting my existing work to Python 3.X, but... > > > > class Foo: > > def bar(self): > > pass > > > > mthd = Foo.bar > > > > assert mthd.im_class is Foo # this does not work in py3k > > mthd.im_class is the class of mthd.im_self not the class that defined the method. > > > > > So, how can I get a reference to Foo? This is important when writing > > decorators, the only way I can think out is: > > Not sure what sort of decorators you're writing. Examples? A decorator is not necessary but a similar function accept a method. I don't like any of existing web frameworks and try to write one via werkzeug from pocoo. from myapp.controllers import RootController from werkzeug.routing import Map, Rule from werkzeug.exceptions import HTTPException from werkzeug.wrappers import Request url_map = Map([ Rule('/', endpoint=RootController.index), Rule('/about', endpoint=RootController.about), Rule('/contact', endpoint=RootController.contact), Rule('//', endpoint=RootController.otheraction) ]) def application(environ, start_response): #this is a WSGI 1.0 app bound_url_map = url_map.bind_to_environ(environ) try: endpoint, args = bound_url_map.match() except HTTPException, e: return e(environ, start_response) Controller = endpoint.im_class controller = Controller(Request(environ)) if hasattr(controller, '__before__'): controller.__before__() endpoint(controller) if hasattr(controller, '__after__'): controller.__after__() response = controller.__get_response__(): return response(environ, start_response) This is a Pylons-style application, but I don't like others in Pylons. > > You can achieve this with metaclasses but if you're using classes from someone else's code this doesn't necessarily work. Something in inspect module can probably do the trick, check the docs. Frankly though it sounds messy no matter what. It might be better to find an alternative to knowing the class. > > > class Foo: > > def bar(self): > > 'Foo' # manually declare the owner class > > pass > > > > mthd = Foo.bar > > > > assert mthd.__globals__[mthd.__doc__] is Foo # this works > > > > class Child(Foo): > > def bar(self): > > 'Child' # I have to override all method defined by bar but do nothing > > pass > > > > child_mthd = Child.bar > > > > assert child_mthd.__globals__[child_mthd.__doc__] is Child # this works > > > > But the code above is quite ugly and abuses the __doc__. Is there any > > equivalent in py3k of im_class? > > > > Thanks, > > Cosmia From __peter__ at web.de Sat Mar 17 05:25:06 2012 From: __peter__ at web.de (Peter Otten) Date: Sat, 17 Mar 2012 10:25:06 +0100 Subject: How to get a reference of the 'owner' class to which a method belongs in Python 3.X? References: <20411334.2044.1331962234309.JavaMail.geo-discussion-forums@yncd8> Message-ID: Cosmia Luna wrote: > I'm porting my existing work to Python 3.X, but... > > class Foo: > def bar(self): > pass > > mthd = Foo.bar > > assert mthd.im_class is Foo # this does not work in py3k > > So, how can I get a reference to Foo? This is important when writing > decorators, the only way I can think out is: > > class Foo: > def bar(self): > 'Foo' # manually declare the owner class > pass > > mthd = Foo.bar > > assert mthd.__globals__[mthd.__doc__] is Foo # this works > > class Child(Foo): > def bar(self): > 'Child' # I have to override all method defined by bar but do > nothing pass > > child_mthd = Child.bar > > assert child_mthd.__globals__[child_mthd.__doc__] is Child # this works > > But the code above is quite ugly and abuses the __doc__. Is there any > equivalent in py3k of im_class? class set_class: def __init__(self, method): self.method = method def __get__(self, instance, class_): if instance is None: method = self.method def f(*args, **kw): return method(*args, **kw) f.im_class = class_ f.__name__ = method.__name__ return f return self.method.__get__(instance, class_) class Foo: def __init__(self, name): self.name = name @set_class def bar(self): print("%s says hello from bar()" % self) def __str__(self): return self.name class Bar(Foo): pass assert Foo.bar.im_class is Foo assert Bar.bar.im_class is Bar Foo("Fred").bar() Foo.bar(Foo("Fred")) Bar("Fred").bar() Bar.bar(Bar("Fred")) The cleaner approach is probably: Rule('//', endpoint=(RootController, RootController.otheraction)) ... Controller, method = endpoint controller = Controller(Request(environ)) ... method(controller) From steve+comp.lang.python at pearwood.info Sat Mar 17 06:01:37 2012 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 17 Mar 2012 10:01:37 GMT Subject: How to get a reference of the 'owner' class to which a method belongs in Python 3.X? References: <20411334.2044.1331962234309.JavaMail.geo-discussion-forums@yncd8> Message-ID: <4f646101$0$29981$c3e8da3$5496439d@news.astraweb.com> On Fri, 16 Mar 2012 22:30:34 -0700, Cosmia Luna wrote: > I'm porting my existing work to Python 3.X, but... > > class Foo: > def bar(self): > pass > > mthd = Foo.bar > > assert mthd.im_class is Foo # this does not work in py3k > > So, how can I get a reference to Foo? This is important when writing > decorators, the only way I can think out is: I don't believe you can get a reference to Foo just by inspecting the function object Foo.bar. (In Python 2.x, Foo.bar would be an unbound method, but they no longer exist in Python 3.x.) > class Foo: > def bar(self): > 'Foo' # manually declare the owner class > pass A better approach might be to inject a reference to the class after the event, using a class decorator: function = type(lambda: None) def inject_class(cls): for name, obj in vars(cls).items(): if type(obj) is function: obj.owner_class = cls return cls And in use: py> @inject_class ... class Test: ... a = 1 ... b = 2 ... def method(self, x): ... return (x, self) ... py> Test.a 1 py> Test.method py> Test.method.owner_class is Test True Does this help? -- Steven From cosmius at gmail.com Sat Mar 17 06:04:58 2012 From: cosmius at gmail.com (Cosmia Luna) Date: Sat, 17 Mar 2012 03:04:58 -0700 (PDT) Subject: How to get a reference of the 'owner' class to which a method belongs in Python 3.X? In-Reply-To: References: <20411334.2044.1331962234309.JavaMail.geo-discussion-forums@yncd8> Message-ID: <31776112.2291.1331978698664.JavaMail.geo-discussion-forums@ynne2> On Saturday, March 17, 2012 5:25:06 PM UTC+8, Peter Otten wrote: > Cosmia Luna wrote: > > > I'm porting my existing work to Python 3.X, but... > > > > class Foo: > > def bar(self): > > pass > > > > mthd = Foo.bar > > > > assert mthd.im_class is Foo # this does not work in py3k > > > > So, how can I get a reference to Foo? This is important when writing > > decorators, the only way I can think out is: > > > > class Foo: > > def bar(self): > > 'Foo' # manually declare the owner class > > pass > > > > mthd = Foo.bar > > > > assert mthd.__globals__[mthd.__doc__] is Foo # this works > > > > class Child(Foo): > > def bar(self): > > 'Child' # I have to override all method defined by bar but do > > nothing pass > > > > child_mthd = Child.bar > > > > assert child_mthd.__globals__[child_mthd.__doc__] is Child # this works > > > > But the code above is quite ugly and abuses the __doc__. Is there any > > equivalent in py3k of im_class? > > class set_class: > def __init__(self, method): > self.method = method > def __get__(self, instance, class_): > if instance is None: > method = self.method > def f(*args, **kw): > return method(*args, **kw) > f.im_class = class_ > f.__name__ = method.__name__ > return f > return self.method.__get__(instance, class_) > > class Foo: > def __init__(self, name): > self.name = name > @set_class > def bar(self): > print("%s says hello from bar()" % self) > def __str__(self): > return self.name > > class Bar(Foo): > pass > > assert Foo.bar.im_class is Foo > assert Bar.bar.im_class is Bar > > Foo("Fred").bar() > Foo.bar(Foo("Fred")) > > Bar("Fred").bar() > Bar.bar(Bar("Fred")) > > The cleaner approach is probably: > > Rule('//', endpoint=(RootController, RootController.otheraction)) > ... > Controller, method = endpoint > controller = Controller(Request(environ)) > ... > method(controller) That's exactly what I want, and I think you're right, the approach below is cleaner. Rule('//', endpoint=(RootController, RootController.otheraction)). Thanks a lot. Cosmia From cosmius at gmail.com Sat Mar 17 06:04:58 2012 From: cosmius at gmail.com (Cosmia Luna) Date: Sat, 17 Mar 2012 03:04:58 -0700 (PDT) Subject: How to get a reference of the 'owner' class to which a method belongs in Python 3.X? In-Reply-To: References: <20411334.2044.1331962234309.JavaMail.geo-discussion-forums@yncd8> Message-ID: <31776112.2291.1331978698664.JavaMail.geo-discussion-forums@ynne2> On Saturday, March 17, 2012 5:25:06 PM UTC+8, Peter Otten wrote: > Cosmia Luna wrote: > > > I'm porting my existing work to Python 3.X, but... > > > > class Foo: > > def bar(self): > > pass > > > > mthd = Foo.bar > > > > assert mthd.im_class is Foo # this does not work in py3k > > > > So, how can I get a reference to Foo? This is important when writing > > decorators, the only way I can think out is: > > > > class Foo: > > def bar(self): > > 'Foo' # manually declare the owner class > > pass > > > > mthd = Foo.bar > > > > assert mthd.__globals__[mthd.__doc__] is Foo # this works > > > > class Child(Foo): > > def bar(self): > > 'Child' # I have to override all method defined by bar but do > > nothing pass > > > > child_mthd = Child.bar > > > > assert child_mthd.__globals__[child_mthd.__doc__] is Child # this works > > > > But the code above is quite ugly and abuses the __doc__. Is there any > > equivalent in py3k of im_class? > > class set_class: > def __init__(self, method): > self.method = method > def __get__(self, instance, class_): > if instance is None: > method = self.method > def f(*args, **kw): > return method(*args, **kw) > f.im_class = class_ > f.__name__ = method.__name__ > return f > return self.method.__get__(instance, class_) > > class Foo: > def __init__(self, name): > self.name = name > @set_class > def bar(self): > print("%s says hello from bar()" % self) > def __str__(self): > return self.name > > class Bar(Foo): > pass > > assert Foo.bar.im_class is Foo > assert Bar.bar.im_class is Bar > > Foo("Fred").bar() > Foo.bar(Foo("Fred")) > > Bar("Fred").bar() > Bar.bar(Bar("Fred")) > > The cleaner approach is probably: > > Rule('//', endpoint=(RootController, RootController.otheraction)) > ... > Controller, method = endpoint > controller = Controller(Request(environ)) > ... > method(controller) That's exactly what I want, and I think you're right, the approach below is cleaner. Rule('//', endpoint=(RootController, RootController.otheraction)). Thanks a lot. Cosmia From steve+comp.lang.python at pearwood.info Sat Mar 17 07:18:47 2012 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 17 Mar 2012 11:18:47 GMT Subject: Using non-dict namespaces in functions Message-ID: <4f647317$0$29981$c3e8da3$5496439d@news.astraweb.com> Inspired by the new collections.ChainMap in Python 3.3 http://docs.python.org/dev/library/collections.html#collections.ChainMap I would like to experiment with similar non-dictionary namespaces in Python 3.2. My starting point is these two recipes, adapted for Python 3.2: http://code.activestate.com/recipes/305268/ http://code.activestate.com/recipes/577434/ Or for simplicity, here's a mock version: from collections import Mapping class MockChainMap(Mapping): def __getitem__(self, key): if key == 'a': return 1 elif key == 'b': return 2 raise KeyError(key) def __len__(self): return 2 def __iter__(self): yield 'a' yield 'b' Note that it is important for my purposes that MockChainMap does not inherit from dict. Now I try to create a function that uses a MockChainMap instead of a dict for its globals: function = type(lambda: None) f = lambda x: (a+b+x) g = function(f.__code__, MockChainMap(), 'g') And that's where I get into trouble: Traceback (most recent call last): File "", line 1, in TypeError: function() argument 2 must be dict, not MockChainMap How do I build a function with globals set to a non-dict mapping? If this can't be done, any suggestions for how I might proceed? -- Steven From cosmius at gmail.com Sat Mar 17 08:21:02 2012 From: cosmius at gmail.com (Cosmia Luna) Date: Sat, 17 Mar 2012 05:21:02 -0700 (PDT) Subject: How to get a reference of the 'owner' class to which a method belongs in Python 3.X? In-Reply-To: References: <20411334.2044.1331962234309.JavaMail.geo-discussion-forums@yncd8> Message-ID: <23527589.2560.1331986862750.JavaMail.geo-discussion-forums@ynmb12> On Saturday, March 17, 2012 6:04:58 PM UTC+8, Cosmia Luna wrote: > On Saturday, March 17, 2012 5:25:06 PM UTC+8, Peter Otten wrote: > > Cosmia Luna wrote: > > > > > I'm porting my existing work to Python 3.X, but... > > > > > > class Foo: > > > def bar(self): > > > pass > > > > > > mthd = Foo.bar > > > > > > assert mthd.im_class is Foo # this does not work in py3k > > > > > > So, how can I get a reference to Foo? This is important when writing > > > decorators, the only way I can think out is: > > > > > > class Foo: > > > def bar(self): > > > 'Foo' # manually declare the owner class > > > pass > > > > > > mthd = Foo.bar > > > > > > assert mthd.__globals__[mthd.__doc__] is Foo # this works > > > > > > class Child(Foo): > > > def bar(self): > > > 'Child' # I have to override all method defined by bar but do > > > nothing pass > > > > > > child_mthd = Child.bar > > > > > > assert child_mthd.__globals__[child_mthd.__doc__] is Child # this works > > > > > > But the code above is quite ugly and abuses the __doc__. Is there any > > > equivalent in py3k of im_class? > > > > class set_class: > > def __init__(self, method): > > self.method = method > > def __get__(self, instance, class_): > > if instance is None: > > method = self.method > > def f(*args, **kw): > > return method(*args, **kw) > > f.im_class = class_ > > f.__name__ = method.__name__ > > return f > > return self.method.__get__(instance, class_) > > > > class Foo: > > def __init__(self, name): > > self.name = name > > @set_class > > def bar(self): > > print("%s says hello from bar()" % self) > > def __str__(self): > > return self.name > > > > class Bar(Foo): > > pass > > > > assert Foo.bar.im_class is Foo > > assert Bar.bar.im_class is Bar > > > > Foo("Fred").bar() > > Foo.bar(Foo("Fred")) > > > > Bar("Fred").bar() > > Bar.bar(Bar("Fred")) > > > > The cleaner approach is probably: > > > > Rule('//', endpoint=(RootController, RootController.otheraction)) > > ... > > Controller, method = endpoint > > controller = Controller(Request(environ)) > > ... > > method(controller) > > > That's exactly what I want, and I think you're right, the approach below is cleaner. > Rule('//', endpoint=(RootController, RootController.otheraction)). > > Thanks a lot. > Cosmia Oh I'm wrong. If I use a decorator, the decorator will NEVER get the owner class even in Python 2.X. The function is just plain function instead of unbound method before the code of a class is fully evaluated. So the decorator ALWAYS receives a plain function. I'll look into the module inspect and try to get the frame of calling... Cosmia From cosmius at gmail.com Sat Mar 17 08:21:02 2012 From: cosmius at gmail.com (Cosmia Luna) Date: Sat, 17 Mar 2012 05:21:02 -0700 (PDT) Subject: How to get a reference of the 'owner' class to which a method belongs in Python 3.X? In-Reply-To: References: <20411334.2044.1331962234309.JavaMail.geo-discussion-forums@yncd8> Message-ID: <23527589.2560.1331986862750.JavaMail.geo-discussion-forums@ynmb12> On Saturday, March 17, 2012 6:04:58 PM UTC+8, Cosmia Luna wrote: > On Saturday, March 17, 2012 5:25:06 PM UTC+8, Peter Otten wrote: > > Cosmia Luna wrote: > > > > > I'm porting my existing work to Python 3.X, but... > > > > > > class Foo: > > > def bar(self): > > > pass > > > > > > mthd = Foo.bar > > > > > > assert mthd.im_class is Foo # this does not work in py3k > > > > > > So, how can I get a reference to Foo? This is important when writing > > > decorators, the only way I can think out is: > > > > > > class Foo: > > > def bar(self): > > > 'Foo' # manually declare the owner class > > > pass > > > > > > mthd = Foo.bar > > > > > > assert mthd.__globals__[mthd.__doc__] is Foo # this works > > > > > > class Child(Foo): > > > def bar(self): > > > 'Child' # I have to override all method defined by bar but do > > > nothing pass > > > > > > child_mthd = Child.bar > > > > > > assert child_mthd.__globals__[child_mthd.__doc__] is Child # this works > > > > > > But the code above is quite ugly and abuses the __doc__. Is there any > > > equivalent in py3k of im_class? > > > > class set_class: > > def __init__(self, method): > > self.method = method > > def __get__(self, instance, class_): > > if instance is None: > > method = self.method > > def f(*args, **kw): > > return method(*args, **kw) > > f.im_class = class_ > > f.__name__ = method.__name__ > > return f > > return self.method.__get__(instance, class_) > > > > class Foo: > > def __init__(self, name): > > self.name = name > > @set_class > > def bar(self): > > print("%s says hello from bar()" % self) > > def __str__(self): > > return self.name > > > > class Bar(Foo): > > pass > > > > assert Foo.bar.im_class is Foo > > assert Bar.bar.im_class is Bar > > > > Foo("Fred").bar() > > Foo.bar(Foo("Fred")) > > > > Bar("Fred").bar() > > Bar.bar(Bar("Fred")) > > > > The cleaner approach is probably: > > > > Rule('//', endpoint=(RootController, RootController.otheraction)) > > ... > > Controller, method = endpoint > > controller = Controller(Request(environ)) > > ... > > method(controller) > > > That's exactly what I want, and I think you're right, the approach below is cleaner. > Rule('//', endpoint=(RootController, RootController.otheraction)). > > Thanks a lot. > Cosmia Oh I'm wrong. If I use a decorator, the decorator will NEVER get the owner class even in Python 2.X. The function is just plain function instead of unbound method before the code of a class is fully evaluated. So the decorator ALWAYS receives a plain function. I'll look into the module inspect and try to get the frame of calling... Cosmia From antti.ylikoski at tkk.fi Sat Mar 17 10:03:52 2012 From: antti.ylikoski at tkk.fi (Antti J Ylikoski) Date: Sat, 17 Mar 2012 16:03:52 +0200 Subject: Programming D. E. Knuth in Python with the Deterministic Finite Automaton construct Message-ID: In his legendary book series The Art of Computer Programming, Professor Donald E. Knuth presents many of his algorithms in the form that they have been divided in several individual phases, with instructions to GOTO to another phase interspersed in the text of the individual phases. I. e. they look like the following, purely invented, example: (Knuth is being clearer than me below.....) A1. (Do the work of Phase A1.) If then go to Phase A5, otherwise continue. A2. (Do some work.) If go to Phase A4. A3. (Some more work.) A4. (Do something.) If go to Phase A1. A5. (Something more). If then go to Phase A2, otherwise end. I came across the problem, which would be the clearest way to program such algorithms with a programming language such as Python, which has no GOTO statement. It struck me that the above construction actually is a modified Deterministic Finite Automaton with states A1 -- A5 + [END], transferring to different states, not on read input, but according to conditions in the running program. So one very clear way to program Knuth with Python is the following kind of a construct. continueLoop = 1 nextState = "A1" while continueLoop: if nextState == "A1": # (Do the work of Phase A1.) if : nextState = "A5" elif nextState == "A2": # (Do some work.) if zorp: nextState = "A4" else: nextState = "A3" elif nextState == "A3": # (Some more work.) nextState = "A4" elif nextState == "A4": # (Do something.) if ZZZ: nextState = "A1" else: nextState = "A5" elif nextState == "A5": # (Something more). if foobar: nextState = "A2" else: continueLoop = 0 else: error("Impossible -- I quit!\n") Following is a working Python function which iteratively calculates the lexicographically ordered permutations of integers [1, 2, 3, 4, ..., n], where n is an arbitary integer. The function was written after D. E. Knuth with the abovementioned DFA construct. def iterAllPerm(n): # iteratively generate all permutations of n integers 1-n # After Donald Knuth, The Art of Computer Programming, Vol4, # Fascicle 2, # ISBN 0-201-85393-0. See pp. 39--40. listofPerm = [] # list of lists to collect permutations continueLoop = 1 # indicates whether to continue the iteration nextStat = "L1" # next phase in Knuth's text a = list(range(0, n+1)) # [0, 1, 2, 3, 4, ..., n] -- see Knuth while continueLoop: if nextStat == "L1": app = listofPerm.append(a[1:n+1]) nextStat = "L2" continueLoop = 1 elif nextStat == "L2": j = n - 1 while a[j] >= a[j+1]: j -= 1 if j == 0: continueLoop = 0 nextStat = "Finis Algorithm" else: continueLoop = 1 nextStat = "L3" elif nextStat == "L3": l = n while a[j] >= a[l]: l -= 1 temp = a[j] a[j] = a[l] a[l] = temp nextStat = "L4" continueLoop = 1 elif nextStat == "L4": k = j + 1 l = n while k < l: temp = a[k] a[k] = a[l] a[l] = temp k += 1 l -= 1 nextStat = "L1" continueLoop = 1 else: continueLoop = 0 error("Impossible -- I quit!\n") return(listofPerm) kind regards, Antti J Ylikoski Helsinki, Finland, the EU From gandalf at shopzeus.com Sat Mar 17 10:13:16 2012 From: gandalf at shopzeus.com (Laszlo Nagy) Date: Sat, 17 Mar 2012 15:13:16 +0100 Subject: urllib.urlretrieve never returns??? Message-ID: <4F649BFC.1080601@shopzeus.com> See attached example code. I have a program that calls exactly the same code, and here is the strange thing about it: * Program is started as "start.py", e.g. with an open console. In this case, the program works! * Program is started as "start.pyw", e.g. with no open console under Windows 7 64bit - the program does not work! In the later case, "log.txt" only contains "#1" and nothing else. If I look at pythonw.exe from task manager, then its shows +1 thread every time I click the button, and "#1" is appended to the file. Seems like urllib.urlretrieve() does not return at all! Using wx.PySimpleApp(redirect=True) does not help either - nothing is printed on the redirected console. Unfortunately, I cannot send the whole program, because it is too big and also because it is confidental. Question is: how is it possible that urllib.urlretrieve() does not return? It is part of a system library. What I could have possibly done to screw it up? And moreover, how is it possible that it does not return ONLY when the program is started with pythonw.exe? Thanks, Laszlo -------------- next part -------------- An HTML attachment was scrubbed... URL: -------------- next part -------------- An embedded and charset-unspecified text was scrubbed... Name: test.py URL: From mwilson at the-wire.com Sat Mar 17 10:39:38 2012 From: mwilson at the-wire.com (Mel Wilson) Date: Sat, 17 Mar 2012 10:39:38 -0400 Subject: Programming D. E. Knuth in Python with the Deterministic Finite Automaton construct References: Message-ID: Antti J Ylikoski wrote: > > In his legendary book series The Art of Computer Programming, > Professor Donald E. Knuth presents many of his algorithms in the form > that they have been divided in several individual phases, with > instructions to GOTO to another phase interspersed in the text of the > individual phases. > > > > I. e. they look like the following, purely invented, example: (Knuth is > being clearer than me below.....) > > > > A1. (Do the work of Phase A1.) If then go to Phase A5, > otherwise continue. > > A2. (Do some work.) If go to Phase A4. > > A3. (Some more work.) > > A4. (Do something.) If go to Phase A1. > > A5. (Something more). If then go to Phase A2, otherwise > end. > > > > I came across the problem, which would be the clearest way to program > such algorithms with a programming language such as Python, which has > no GOTO statement. It struck me that the above construction actually > is a modified Deterministic Finite Automaton with states A1 -- A5 + > [END], transferring to different states, not on read input, but > according to conditions in the running program. > > So one very clear way to program Knuth with Python is the following > kind of a construct. Yeah. This is an idea that came up during the '70s after Dijkstra published his "GOTO Considered Harmful". Model the execution pointer as a state, and then explicit changes to the execution pointer (prohibited in GOTO-less languages) get replaced by assignments to the state. It preserves the objectionable part of GOTO: that there's no easy way to predict the conditions that any statement might execute under. You can't understand any of the program until you understand all of the program. I think Knuth kept the assembly-language model for his algorithms because it promotes his real goal, which is mathematical analysis of the performance of the algorithms. It helps that his algorithms are very short. As "the quickest way to get a Knuth algorithm running in Python", this is a pretty good idea. My own preference is to get the algo "really" coded in Python, but that usually takes a fair bit of time and effort. Mel. From kiuhnm03.4t.yahoo.it Sat Mar 17 10:45:45 2012 From: kiuhnm03.4t.yahoo.it (Kiuhnm) Date: Sat, 17 Mar 2012 15:45:45 +0100 Subject: Programming D. E. Knuth in Python with the Deterministic Finite Automaton construct In-Reply-To: References: Message-ID: <4f64a3a0$0$1386$4fafbaef@reader2.news.tin.it> On 3/17/2012 15:03, Antti J Ylikoski wrote: > In his legendary book series The Art of Computer Programming, > Professor Donald E. Knuth presents many of his algorithms in the form > that they have been divided in several individual phases, with > instructions to GOTO to another phase interspersed in the text of the > individual phases. > > > > I. e. they look like the following, purely invented, example: (Knuth is > being clearer than me below.....) > > > > A1. (Do the work of Phase A1.) If then go to Phase A5, > otherwise continue. > > A2. (Do some work.) If go to Phase A4. > > A3. (Some more work.) > > A4. (Do something.) If go to Phase A1. > > A5. (Something more). If then go to Phase A2, otherwise > end. > > > > I came across the problem, which would be the clearest way to program > such algorithms with a programming language such as Python, which has > no GOTO statement. It struck me that the above construction actually > is a modified Deterministic Finite Automaton with states A1 -- A5 + > [END], transferring to different states, not on read input, but > according to conditions in the running program. A1 and A5 are NOT states: they're labels. There is no garanteed bijection from labels to states. > So one very clear way to program Knuth with Python is the following > kind of a construct. [...] Your way is easy, but the result is poor. Your should try to rewrite it. Decompilers do exactly that. Kiuhnm From torriem at gmail.com Sat Mar 17 11:01:59 2012 From: torriem at gmail.com (Michael Torrie) Date: Sat, 17 Mar 2012 09:01:59 -0600 Subject: Programming D. E. Knuth in Python with the Deterministic Finite Automaton construct In-Reply-To: <4f64a3a0$0$1386$4fafbaef@reader2.news.tin.it> References: <4f64a3a0$0$1386$4fafbaef@reader2.news.tin.it> Message-ID: <4F64A767.4060505@gmail.com> On 03/17/2012 08:45 AM, Kiuhnm wrote: > Your way is easy, but the result is poor. In what way? What is your recommended way? > Your should try to rewrite it. > Decompilers do exactly that. Decompilers rewrite code for people? That's really neat. From kiuhnm03.4t.yahoo.it Sat Mar 17 11:12:29 2012 From: kiuhnm03.4t.yahoo.it (Kiuhnm) Date: Sat, 17 Mar 2012 16:12:29 +0100 Subject: Programming D. E. Knuth in Python with the Deterministic Finite Automaton construct In-Reply-To: References: <4f64a3a0$0$1386$4fafbaef@reader2.news.tin.it> Message-ID: <4f64a9e5$0$1385$4fafbaef@reader2.news.tin.it> On 3/17/2012 16:01, Michael Torrie wrote: > On 03/17/2012 08:45 AM, Kiuhnm wrote: >> Your way is easy, but the result is poor. > > In what way? The resulting code is inefficient, difficult to comprehend and to mantain. > What is your recommended way? One should rewrite the code. There is a reason why Python doesn't have gotos. >> Your should try to rewrite it. >> Decompilers do exactly that. > > Decompilers rewrite code for people? That's really neat. No, they try to rewrite code that contains jmps in order to remove them. If one jmp is too difficult to remove, one should use a flag or something similar. Kiuhnm From roy at panix.com Sat Mar 17 11:47:55 2012 From: roy at panix.com (Roy Smith) Date: Sat, 17 Mar 2012 11:47:55 -0400 Subject: Programming D. E. Knuth in Python with the Deterministic Finite Automaton construct References: Message-ID: In article , Antti J Ylikoski wrote: > I came across the problem, which would be the clearest way to program > such algorithms with a programming language such as Python, which has > no GOTO statement. It struck me that the above construction actually > is a modified Deterministic Finite Automaton with states A1 -- A5 + > [END], transferring to different states, not on read input, but > according to conditions in the running program. > > So one very clear way to program Knuth with Python is the following > kind of a construct. > > > > continueLoop = 1 > nextState = "A1" > > while continueLoop: > if nextState == "A1": > # (Do the work of Phase A1.) > if : > nextState = "A5" > elif nextState == "A2": > # (Do some work.) > if zorp: > nextState = "A4" > else: > nextState = "A3" > elif nextState == "A3": > # (Some more work.) > nextState = "A4" > elif nextState == "A4": > # (Do something.) > if ZZZ: > nextState = "A1" > else: > nextState = "A5" > elif nextState == "A5": > # (Something more). > if foobar: > nextState = "A2" > else: > continueLoop = 0 > else: > error("Impossible -- I quit!\n") Oh, my, I can't even begin to get my head around all the nested conditionals. And that for a nearly trivial machine with only 5 states. Down this path lies madness. Keep in mind that Knuth wrote The Art of Computer Programming in the 1960s. The algorithms may still be valid, but we've learned a lot about how to write readable programs since then. Most people today are walking around with phones that have far more compute power than the biggest supercomputers of Knuth's day. We're no longer worried about bumming every cycle by writing in assembler. When I've done FSMs in Python, I've found the cleanest way is to make each state a function. Do something like: def a1(input): # (Do the work of Phase A1.) if : return a5 # goto state a5 else: return a1 # stay in the same state # and so on for the other states. next_state = a1 for input in whatever(): next_state = next_state(input) if next_state is None: break You can adjust that for your needs. Sometimes I have the states return a (next_state, output) tuple. You could use a distinguished done() state, or just use None for that. I wrote the example above as global functions, but more commonly these would be methods of some StateMachine class. From torriem at gmail.com Sat Mar 17 11:53:23 2012 From: torriem at gmail.com (Michael Torrie) Date: Sat, 17 Mar 2012 09:53:23 -0600 Subject: Programming D. E. Knuth in Python with the Deterministic Finite Automaton construct In-Reply-To: <4f64a9e5$0$1385$4fafbaef@reader2.news.tin.it> References: <4f64a3a0$0$1386$4fafbaef@reader2.news.tin.it> <4f64a9e5$0$1385$4fafbaef@reader2.news.tin.it> Message-ID: <4F64B373.204@gmail.com> On 03/17/2012 09:12 AM, Kiuhnm wrote: > On 3/17/2012 16:01, Michael Torrie wrote: >> On 03/17/2012 08:45 AM, Kiuhnm wrote: >>> Your way is easy, but the result is poor. >> >> In what way? > > The resulting code is inefficient, difficult to comprehend and to mantain. > >> What is your recommended way? > > One should rewrite the code. There is a reason why Python doesn't have > gotos. We appear to have a language barrier here. How should one rewrite the code? Everyone knows python doesn't have gotos and state machines have to be created using other mechanisms like loops, state variables, and such. Your suggestion to "rewrite the code" is unhelpful to the OP if you're not willing to suggest the best method for doing so. Saying, "be like a decompiler" doesn't say anything. From antti.ylikoski at tkk.fi Sat Mar 17 12:31:02 2012 From: antti.ylikoski at tkk.fi (Antti J Ylikoski) Date: Sat, 17 Mar 2012 18:31:02 +0200 Subject: Programming D. E. Knuth in Python with the Deterministic Finite Automaton construct In-Reply-To: References: Message-ID: On 17.3.2012 17:47, Roy Smith wrote: > In article, > Antti J Ylikoski wrote: > >> I came across the problem, which would be the clearest way to program >> such algorithms with a programming language such as Python, which has >> no GOTO statement. It struck me that the above construction actually >> is a modified Deterministic Finite Automaton with states A1 -- A5 + >> [END], transferring to different states, not on read input, but >> according to conditions in the running program. >> >> So one very clear way to program Knuth with Python is the following >> kind of a construct. >> >> >> >> continueLoop = 1 >> nextState = "A1" >> >> while continueLoop: >> if nextState == "A1": >> # (Do the work of Phase A1.) >> if: >> nextState = "A5" >> elif nextState == "A2": >> # (Do some work.) >> if zorp: >> nextState = "A4" >> else: >> nextState = "A3" >> elif nextState == "A3": >> # (Some more work.) >> nextState = "A4" >> elif nextState == "A4": >> # (Do something.) >> if ZZZ: >> nextState = "A1" >> else: >> nextState = "A5" >> elif nextState == "A5": >> # (Something more). >> if foobar: >> nextState = "A2" >> else: >> continueLoop = 0 >> else: >> error("Impossible -- I quit!\n") > > Oh, my, I can't even begin to get my head around all the nested > conditionals. And that for a nearly trivial machine with only 5 states. > Down this path lies madness. Keep in mind that Knuth wrote The Art of > Computer Programming in the 1960s. The algorithms may still be valid, > but we've learned a lot about how to write readable programs since then. > Most people today are walking around with phones that have far more > compute power than the biggest supercomputers of Knuth's day. We're no > longer worried about bumming every cycle by writing in assembler. > > When I've done FSMs in Python, I've found the cleanest way is to make > each state a function. Do something like: > > def a1(input): > # (Do the work of Phase A1.) > if: > return a5 # goto state a5 > else: > return a1 # stay in the same state > > # and so on for the other states. > > next_state = a1 > for input in whatever(): > next_state = next_state(input) > if next_state is None: > break > > You can adjust that for your needs. Sometimes I have the states return > a (next_state, output) tuple. You could use a distinguished done() > state, or just use None for that. I wrote the example above as global > functions, but more commonly these would be methods of some StateMachine > class. Thank you, that is a very good idea to my opinion. Antti "Andy" From rosuav at gmail.com Sat Mar 17 12:34:05 2012 From: rosuav at gmail.com (Chris Angelico) Date: Sun, 18 Mar 2012 03:34:05 +1100 Subject: urllib.urlretrieve never returns??? In-Reply-To: <4F649BFC.1080601@shopzeus.com> References: <4F649BFC.1080601@shopzeus.com> Message-ID: 2012/3/18 Laszlo Nagy : > In the later case, "log.txt" only contains "#1" and nothing else. If I look > at pythonw.exe from task manager, then its shows +1 thread every time I > click the button, and "#1" is appended to the file. try: fpath = urllib.urlretrieve(imgurl)[0] except: self.Log(traceback.format_exc()) return Just a stab in the dark, but I'm wondering if something's throwing an exception when it's running without a GUI? Your except clause references 'traceback' which I don't see anywhere else - or is that part of the code you can't share? Anyway, my guess is that something perhaps tries to write to the console and can't, and it gets stuck inside format_exc(). Is that testable? For instance, replace the "fpath=" line with "fpath = 1/0" to raise WhatKindOfIdiotAreYouError (it's spelled differently, but that's what the computer thinks of people who ask it to divide by zero) - see what that does. Or maybe add self.log("#1.5") at the beginning of the except: clause. Without all your code, I can't actually run it to test, so it's entirely possible that I'm completely wrong here. ChrisA From miki.tebeka at gmail.com Sat Mar 17 13:12:59 2012 From: miki.tebeka at gmail.com (Miki Tebeka) Date: Sat, 17 Mar 2012 10:12:59 -0700 (PDT) Subject: elasticsearch client Message-ID: <16392875.280.1332004379343.JavaMail.geo-discussion-forums@ynjx8> Greetings, I see several elasticsearch clients on PyPI, any recommendations? Thanks, -- Miki From gandalf at shopzeus.com Sat Mar 17 13:31:33 2012 From: gandalf at shopzeus.com (Laszlo Nagy) Date: Sat, 17 Mar 2012 18:31:33 +0100 Subject: urllib.urlretrieve never returns??? In-Reply-To: References: <4F649BFC.1080601@shopzeus.com> Message-ID: <4F64CA75.1060108@shopzeus.com> 2012.03.17. 17:34 keltez?ssel, Chris Angelico wrote > 2012/3/18 Laszlo Nagy: >> In the later case, "log.txt" only contains "#1" and nothing else. If I look >> at pythonw.exe from task manager, then its shows +1 thread every time I >> click the button, and "#1" is appended to the file. > try: > fpath = urllib.urlretrieve(imgurl)[0] > except: > self.Log(traceback.format_exc()) > return > > > Just a stab in the dark, but I'm wondering if something's throwing an > exception when it's running without a GUI? Your except clause > references 'traceback' which I don't see anywhere else - or is that > part of the code you can't share? Anyway, my guess is that something > perhaps tries to write to the console and can't, and it gets stuck > inside format_exc(). Is that testable? You are right, I should have added "import traceback". However, I tried this: try: fpath = urllib.urlretrieve(imgurl)[0] except: self.Log("Exception") return and still nothing was logged. Another proof is that the number of threads is increased every time I press the button. So I'm 100% sure that urlretrieve does not return from the call. From rosuav at gmail.com Sat Mar 17 13:53:24 2012 From: rosuav at gmail.com (Chris Angelico) Date: Sun, 18 Mar 2012 04:53:24 +1100 Subject: urllib.urlretrieve never returns??? In-Reply-To: <4F64CA75.1060108@shopzeus.com> References: <4F649BFC.1080601@shopzeus.com> <4F64CA75.1060108@shopzeus.com> Message-ID: On Sun, Mar 18, 2012 at 4:31 AM, Laszlo Nagy wrote: > You are right, I should have added "import traceback". However, I tried > this: > > ? ? ? ?except: > ? ? ? ? ? ?self.Log("Exception") > > and still nothing was logged. Another proof is that the number of threads is > increased every time I press the button. So I'm 100% sure that urlretrieve > does not return from the call. Okay, was worth a shot! Hopefully someone else can help more. ChrisA From kiuhnm03.4t.yahoo.it Sat Mar 17 13:55:14 2012 From: kiuhnm03.4t.yahoo.it (Kiuhnm) Date: Sat, 17 Mar 2012 18:55:14 +0100 Subject: Programming D. E. Knuth in Python with the Deterministic Finite Automaton construct In-Reply-To: References: <4f64a3a0$0$1386$4fafbaef@reader2.news.tin.it> <4f64a9e5$0$1385$4fafbaef@reader2.news.tin.it> Message-ID: <4f64d00a$0$1390$4fafbaef@reader1.news.tin.it> On 3/17/2012 16:53, Michael Torrie wrote: > On 03/17/2012 09:12 AM, Kiuhnm wrote: >> On 3/17/2012 16:01, Michael Torrie wrote: >>> On 03/17/2012 08:45 AM, Kiuhnm wrote: >>>> Your way is easy, but the result is poor. >>> >>> In what way? >> >> The resulting code is inefficient, difficult to comprehend and to mantain. >> >>> What is your recommended way? >> >> One should rewrite the code. There is a reason why Python doesn't have >> gotos. > > We appear to have a language barrier here. How should one rewrite the > code? Everyone knows python doesn't have gotos and state machines have > to be created using other mechanisms like loops, state variables, and > such. Your suggestion to "rewrite the code" is unhelpful to the OP if > you're not willing to suggest the best method for doing so. Why should I write a treatise on decompilation techniques on this ng? > Saying, "be > like a decompiler" doesn't say anything. That looks like a glaring contradiction to me... I'm sure the interested reader will think of some ways of getting additional information on the subject. Here's an example of rewriting: A1. (Do the work of Phase A1.) If then go to Phase A5, otherwise continue. A2. (Do some work.) If go to Phase A4. A3. (Some more work.) A4. (Do something.) If go to Phase A1. A5. (Something more). If then go to Phase A2, otherwise end. ==> A1. (Do the work of Phase A1.) If not : A2. (Do some work.) If go to Phase A4. A3. (Some more work.) A4. (Do something.) If go to Phase A1. A5. (Something more). If then go to Phase A2, otherwise end. ==> A1. (Do the work of Phase A1.) If not : A2. (Do some work.) If not : A3. (Some more work.) A4. (Do something.) If go to Phase A1. A5. (Something more). If then go to Phase A2, otherwise end. ==> while (True): A1. (Do the work of Phase A1.) If not : A2. (Do some work.) If not : A3. (Some more work.) A4. (Do something.) If not : break A5. (Something more). If then go to Phase A2 ==> while (True): A1. (Do the work of Phase A1.) If not : A2. (Do some work.) If not : A3. (Some more work.) A4. (Do something.) If not : A5. (Something more). If then go to Phase A2 break ==> again = TRUE while (again): A1. (Do the work of Phase A1.) If not : while (True): A2. (Do some work.) If not : A3. (Some more work.) A4. (Do something.) If not : A5. (Something more). If : continue again = FALSE; break ==> def f: while (True): A1. (Do the work of Phase A1.) If not : while (True): A2. (Do some work.) If not : A3. (Some more work.) A4. (Do something.) If not : A5. (Something more). If : continue return ==> def f: while (True): A1. (Do the work of Phase A1.) If : continue while (True): A2. (Do some work.) If not : A3. (Some more work.) A4. (Do something.) If not : A5. (Something more). If : continue return ==> def f: while (True): A1. (Do the work of Phase A1.) If : continue while (True): A2. (Do some work.) If not : A3. (Some more work.) A4. (Do something.) If : continue A5. (Something more). If : continue return ==> def f: while (True): A1. (Do the work of Phase A1.) If : continue while (True): A2. (Do some work.) If not : A3. (Some more work.) A4. (Do something.) If : continue A5. (Something more). If not : return Etc... until you're satisfied with the result. If the code is more complex, divide et impera. Kiuhnm From lists at cheimes.de Sat Mar 17 14:18:25 2012 From: lists at cheimes.de (Christian Heimes) Date: Sat, 17 Mar 2012 19:18:25 +0100 Subject: urllib.urlretrieve never returns??? In-Reply-To: <4F649BFC.1080601@shopzeus.com> References: <4F649BFC.1080601@shopzeus.com> Message-ID: Am 17.03.2012 15:13, schrieb Laszlo Nagy: > See attached example code. I have a program that calls exactly the same > code, and here is the strange thing about it: > > * Program is started as "start.py", e.g. with an open console. In this > case, the program works! > * Program is started as "start.pyw", e.g. with no open console under > Windows 7 64bit - the program does not work! The pythonw.exe may not have the rights to access network resources. Have you set a default timeout for sockets? import socket socket.setdefaulttimeout(10) # 10 seconds A pyw Python doesn't have stdout, stderr or stdin. Any attempt to write to them (e.g. print statement, default exception logger) can cause an exception. Christian From ericsnowcurrently at gmail.com Sat Mar 17 14:42:49 2012 From: ericsnowcurrently at gmail.com (Eric Snow) Date: Sat, 17 Mar 2012 11:42:49 -0700 Subject: Using non-dict namespaces in functions In-Reply-To: <4f647317$0$29981$c3e8da3$5496439d@news.astraweb.com> References: <4f647317$0$29981$c3e8da3$5496439d@news.astraweb.com> Message-ID: On Sat, Mar 17, 2012 at 4:18 AM, Steven D'Aprano wrote: > Note that it is important for my purposes that MockChainMap does not > inherit from dict. Care to elaborate? > Now I try to create a function that uses a MockChainMap instead of a dict > for its globals: > > function = type(lambda: None) > f = lambda x: (a+b+x) > g = function(f.__code__, MockChainMap(), 'g') > > And that's where I get into trouble: > > Traceback (most recent call last): > ?File "", line 1, in > TypeError: function() argument 2 must be dict, not MockChainMap > > > How do I build a function with globals set to a non-dict mapping? > > If this can't be done, any suggestions for how I might proceed? This looks like one of those cases where there is strict type checking (of a Python object) at the C level. You may consider bringing this up in a tracker ticket. Unless there are performance implications, it's likely a case of no one having bothered to change this spot to be more duck-type friendly. There are quite a few of those in CPython and I've seen at least a couple updated when someone brought it up. Regardless, you could also implement __call__() on a function look-alike class to get what you're after. It may not be as performant though. -eric From nagle at animats.com Sat Mar 17 14:44:32 2012 From: nagle at animats.com (John Nagle) Date: Sat, 17 Mar 2012 11:44:32 -0700 Subject: Programming D. E. Knuth in Python with the Deterministic Finite Automaton construct In-Reply-To: References: Message-ID: <4f64db92$0$12041$742ec2ed@news.sonic.net> On 3/17/2012 9:31 AM, Antti J Ylikoski wrote: > On 17.3.2012 17:47, Roy Smith wrote: >> In article, >> Antti J Ylikoski wrote: >> >>> I came across the problem, which would be the clearest way to program >>> such algorithms with a programming language such as Python, which has >>> no GOTO statement. >> Oh, my, I can't even begin to get my head around all the nested >> conditionals. And that for a nearly trivial machine with only 5 states. >> Down this path lies madness. Right. Few programs should be written as state machines. As a means of rewriting Knuth's algorithms, it's inappropriate. Some should. LALR(1) parsers, such as what YACC and Bison generate, are state machines. They're huge collections of nested switch statements. Python doesn't have a "switch" or "case" statement. Which is surprising, for a language that loves dictionary lookups. You can create a dict full of function names and lambdas, but it's clunky looking. John Nagle From kiuhnm03.4t.yahoo.it Sat Mar 17 15:59:34 2012 From: kiuhnm03.4t.yahoo.it (Kiuhnm) Date: Sat, 17 Mar 2012 20:59:34 +0100 Subject: Python is readable In-Reply-To: <4f636ed5$0$29981$c3e8da3$5496439d@news.astraweb.com> References: <4f612b19$0$1379$4fafbaef@reader2.news.tin.it> <8e72d74f-c844-4de3-8a37-f6b1fdc2291f@y27g2000yqy.googlegroups.com> <50e9ceec-40f1-4ead-b2b6-87328b30d084@ow8g2000pbc.googlegroups.com> <4f61c828$0$1390$4fafbaef@reader2.news.tin.it> <4f61d728$0$1375$4fafbaef@reader2.news.tin.it> <4f61fd0a$0$1389$4fafbaef@reader2.news.tin.it> <4f620837$0$1382$4fafbaef@reader2.news.tin.it> <4f627c25$0$1381$4fafbaef@reader2.news.tin.it> <4f62b9be$0$29981$c3e8da3$5496439d@news.astraweb.com> <4f632da5$0$1375$4fafbaef@reader1.news.tin.it> <4f636ed5$0$29981$c3e8da3$5496439d@news.astraweb.com> Message-ID: <4f64ed2e$0$1389$4fafbaef@reader1.news.tin.it> On 3/16/2012 17:48, Steven D'Aprano wrote: > On Fri, 16 Mar 2012 13:10:12 +0100, Kiuhnm wrote: > >> Maybe we should define *exactly* what readability is (in less then 500 >> lines, if possible). > > If you can't be bothered to read my post before replying, save yourself > some more time and don't bother to reply at all. > > I quote from the part of the my post you deleted: > > When people talk about readability, they normally mean to > ask how much mental effort is needed to interpret the > meaning of the text, not how much time does it take to > pass your eyes over the characters. In other words they > are actually talking about comprehensibility. > > > Unless I've made a mistake counting, that's less than 500 lines. > > >> According to your view, ASM code is more readable than Python code. It's >> just that there's more to read in ASM. > > What a ridiculous misrepresentation of my position. Readability is not > proportional to length. Ok, so length and readability are orthogonal properties. Could you please explain to me in which way mov eax, 3 should be less readable than for i in x: print(i) ? From kiuhnm03.4t.yahoo.it Sat Mar 17 16:23:45 2012 From: kiuhnm03.4t.yahoo.it (Kiuhnm) Date: Sat, 17 Mar 2012 21:23:45 +0100 Subject: Python is readable In-Reply-To: <4f633a1a$0$29981$c3e8da3$5496439d@news.astraweb.com> References: <4f612b19$0$1379$4fafbaef@reader2.news.tin.it> <8e72d74f-c844-4de3-8a37-f6b1fdc2291f@y27g2000yqy.googlegroups.com> <50e9ceec-40f1-4ead-b2b6-87328b30d084@ow8g2000pbc.googlegroups.com> <4f61c828$0$1390$4fafbaef@reader2.news.tin.it> <4f61d728$0$1375$4fafbaef@reader2.news.tin.it> <4f61fd0a$0$1389$4fafbaef@reader2.news.tin.it> <4f6280a0$0$29981$c3e8da3$5496439d@news.astraweb.com> <4f6333ca$0$1392$4fafbaef@reader1.news.tin.it> <4f633a1a$0$29981$c3e8da3$5496439d@news.astraweb.com> Message-ID: <4f64f2d8$0$1393$4fafbaef@reader1.news.tin.it> On 3/16/2012 14:03, Steven D'Aprano wrote: > A one line routine is still a routine. There is nothing ungrammatical > about "If you can: take the bus.", although it is non-idiomatic English. In another post you wrote "Sorry, I was talking about the other sort, the ones who apply the grammatical rules used by people in real life. You know the ones: linguists." Then how do you know that there's nothing ungrammatical about "If you can: take the bus" if people don't use it? Kiuhnm From kiuhnm03.4t.yahoo.it Sat Mar 17 16:54:40 2012 From: kiuhnm03.4t.yahoo.it (Kiuhnm) Date: Sat, 17 Mar 2012 21:54:40 +0100 Subject: Python is readable In-Reply-To: References: <4f612b19$0$1379$4fafbaef@reader2.news.tin.it> <8e72d74f-c844-4de3-8a37-f6b1fdc2291f@y27g2000yqy.googlegroups.com> <50e9ceec-40f1-4ead-b2b6-87328b30d084@ow8g2000pbc.googlegroups.com> <4f61c828$0$1390$4fafbaef@reader2.news.tin.it> <4f61d728$0$1375$4fafbaef@reader2.news.tin.it> <4f61fd0a$0$1389$4fafbaef@reader2.news.tin.it> <4f6280a0$0$29981$c3e8da3$5496439d@news.astraweb.com> <4f6333ca$0$1392$4fafbaef@reader1.news.tin.it> <4f633a1a$0$29981$c3e8da3$5496439d@news.astraweb.com> <9sgsb1FsbpU1@mid.individual.net> <4f636a38$0$29981$c3e8da3$5496439d@news.astraweb.com> <9shd0kFvgbU1@mid.individual.net> <4f638b76$0$29981$c3e8da3$5496439d@news.astraweb.com> <9shj05FabeU1@mid.individual.net> Message-ID: <4f64fa18$0$1392$4fafbaef@reader1.news.tin.it> On 3/16/2012 21:04, Prasad, Ramit wrote: >> People spell your name Stephen, sometimes too. Thinking of changing it? >> Gore Vidal's quote has panache, a valid compensation for breaking > the usual rule. How many other uses on that page are similar? > > > He provided common examples and reference links. Seems like a pretty > reasonable way of trying to prove a point. If you don't like reference > links, what would convince you that the point was correct? I have > not seen any counter examples or counter references on your behalf... He's referring to this "rule": "A colon should not precede a list unless it follows a complete sentence; however, the colon is a style choice that some publications allow." http://www.grammarbook.com/punctuation/colons.asp Kiuhnm From rosuav at gmail.com Sat Mar 17 17:20:14 2012 From: rosuav at gmail.com (Chris Angelico) Date: Sun, 18 Mar 2012 08:20:14 +1100 Subject: Python is readable In-Reply-To: <4f64ed2e$0$1389$4fafbaef@reader1.news.tin.it> References: <4f612b19$0$1379$4fafbaef@reader2.news.tin.it> <8e72d74f-c844-4de3-8a37-f6b1fdc2291f@y27g2000yqy.googlegroups.com> <50e9ceec-40f1-4ead-b2b6-87328b30d084@ow8g2000pbc.googlegroups.com> <4f61c828$0$1390$4fafbaef@reader2.news.tin.it> <4f61d728$0$1375$4fafbaef@reader2.news.tin.it> <4f61fd0a$0$1389$4fafbaef@reader2.news.tin.it> <4f620837$0$1382$4fafbaef@reader2.news.tin.it> <4f627c25$0$1381$4fafbaef@reader2.news.tin.it> <4f62b9be$0$29981$c3e8da3$5496439d@news.astraweb.com> <4f632da5$0$1375$4fafbaef@reader1.news.tin.it> <4f636ed5$0$29981$c3e8da3$5496439d@news.astraweb.com> <4f64ed2e$0$1389$4fafbaef@reader1.news.tin.it> Message-ID: On Sun, Mar 18, 2012 at 6:59 AM, Kiuhnm wrote: > Could you please explain to me in which way > ? ?mov eax, 3 > should be less readable than > ? ?for i in x: print(i) > ? They are equally readable. The first one sets EAX to 3; the second displays all elements of x on the console. Assembly is readable on a very low level, but it's by nature verbose at a high level, and thus less readable (you can't eyeball a function and know exactly what it does, especially if that function spans more than a screenful of code). ChrisA From kiuhnm03.4t.yahoo.it Sat Mar 17 17:22:12 2012 From: kiuhnm03.4t.yahoo.it (Kiuhnm) Date: Sat, 17 Mar 2012 22:22:12 +0100 Subject: Python is readable In-Reply-To: References: <4f612b19$0$1379$4fafbaef@reader2.news.tin.it> <8e72d74f-c844-4de3-8a37-f6b1fdc2291f@y27g2000yqy.googlegroups.com> <50e9ceec-40f1-4ead-b2b6-87328b30d084@ow8g2000pbc.googlegroups.com> <4f61c828$0$1390$4fafbaef@reader2.news.tin.it> <4f61d728$0$1375$4fafbaef@reader2.news.tin.it> <4f61fd0a$0$1389$4fafbaef@reader2.news.tin.it> <4f620837$0$1382$4fafbaef@reader2.news.tin.it> <4f627c25$0$1381$4fafbaef@reader2.news.tin.it> <4f62b9be$0$29981$c3e8da3$5496439d@news.astraweb.com> <4f632da5$0$1375$4fafbaef@reader1.news.tin.it> <4f636ed5$0$29981$c3e8da3$5496439d@news.astraweb.com> Message-ID: <4f65008c$0$1375$4fafbaef@reader1.news.tin.it> On 3/17/2012 0:39, Michael Torrie wrote: > For someone who claims he's merely examining the language and seeking to > learn about it, Kiuhnm is jumping awfully quickly into the realm of > trolling. I'm speechless... thanks, man! Kiuhnm From kiuhnm03.4t.yahoo.it Sat Mar 17 17:28:44 2012 From: kiuhnm03.4t.yahoo.it (Kiuhnm) Date: Sat, 17 Mar 2012 22:28:44 +0100 Subject: Python is readable In-Reply-To: References: <4f612b19$0$1379$4fafbaef@reader2.news.tin.it> <8e72d74f-c844-4de3-8a37-f6b1fdc2291f@y27g2000yqy.googlegroups.com> <50e9ceec-40f1-4ead-b2b6-87328b30d084@ow8g2000pbc.googlegroups.com> <4f61c828$0$1390$4fafbaef@reader2.news.tin.it> <4f61d728$0$1375$4fafbaef@reader2.news.tin.it> <4f61fd0a$0$1389$4fafbaef@reader2.news.tin.it> <4f620837$0$1382$4fafbaef@reader2.news.tin.it> <4f627c25$0$1381$4fafbaef@reader2.news.tin.it> <4f62b9be$0$29981$c3e8da3$5496439d@news.astraweb.com> <4f632da5$0$1375$4fafbaef@reader1.news.tin.it> <4f636ed5$0$29981$c3e8da3$5496439d@news.astraweb.com> <4f64ed2e$0$1389$4fafbaef@reader1.news.tin.it> Message-ID: <4f650213$0$1375$4fafbaef@reader1.news.tin.it> On 3/17/2012 22:20, Chris Angelico wrote: > On Sun, Mar 18, 2012 at 6:59 AM, Kiuhnm > wrote: >> Could you please explain to me in which way >> mov eax, 3 >> should be less readable than >> for i in x: print(i) >> ? > > They are equally readable. The first one sets EAX to 3; the second > displays all elements of x on the console. Assembly is readable on a > very low level, but it's by nature verbose at a high level, and thus > less readable (you can't eyeball a function and know exactly what it > does, especially if that function spans more than a screenful of > code). Welcome in the realm of trolling. Kiuhnm From java at leeclemens.net Sat Mar 17 18:17:10 2012 From: java at leeclemens.net (Lee Clemens) Date: Sat, 17 Mar 2012 18:17:10 -0400 Subject: Daemonization / Popen / pipe issue In-Reply-To: <20120317143726.7134d2b04d56d1759d8eeeb6@johnohagan.com> References: <4F63F2FE.1030409@leeclemens.net> <20120317143726.7134d2b04d56d1759d8eeeb6@johnohagan.com> Message-ID: <4F650D66.4040209@leeclemens.net> On 03/16/2012 11:37 PM, John O'Hagan wrote: > On Fri, 16 Mar 2012 22:12:14 -0400 > Lee Clemens wrote: > >> I have a multi-threaded application >> >> I have provided a test-case here: https://gist.github.com/2054194 > I haven't looked at your test case yet, but a possible cause is the fact that > the main application (or main thread) exits if it has finished executing and > only daemon threads remain. This can abruptly terminate threads which may be > busy, for example, communicating via a pipe. The best solution IMO is not to > use daemon threads, but to give all threads a way to terminate cleanly before > the main thread does, even if this means using a flag or the like. > > HTH, > > John > I call .join() on each spawned thread, whether it is daemonized or not. The code is available here: https://gist.github.com/2054194 Is it generally not recommended to daemonize Python applications using this method? Do you have any references or data to support your opinion? Do you have any references which specifically state - "Daemonizing Python applications cause Python to work in unexpected ways."? As that is what seems to be happening - data corrupting pipe redirection at an underlying level.... From torriem at gmail.com Sat Mar 17 19:04:14 2012 From: torriem at gmail.com (Michael Torrie) Date: Sat, 17 Mar 2012 17:04:14 -0600 Subject: Python is readable In-Reply-To: <4f650213$0$1375$4fafbaef@reader1.news.tin.it> References: <4f612b19$0$1379$4fafbaef@reader2.news.tin.it> <8e72d74f-c844-4de3-8a37-f6b1fdc2291f@y27g2000yqy.googlegroups.com> <50e9ceec-40f1-4ead-b2b6-87328b30d084@ow8g2000pbc.googlegroups.com> <4f61c828$0$1390$4fafbaef@reader2.news.tin.it> <4f61d728$0$1375$4fafbaef@reader2.news.tin.it> <4f61fd0a$0$1389$4fafbaef@reader2.news.tin.it> <4f620837$0$1382$4fafbaef@reader2.news.tin.it> <4f627c25$0$1381$4fafbaef@reader2.news.tin.it> <4f62b9be$0$29981$c3e8da3$5496439d@news.astraweb.com> <4f632da5$0$1375$4fafbaef@reader1.news.tin.it> <4f636ed5$0$29981$c3e8da3$5496439d@news.astraweb.com> <4f64ed2e$0$1389$4fafbaef@reader1.news.tin.it> <4f650213$0$1375$4fafbaef@reader1.news.tin.it> Message-ID: <4F65186E.8010901@gmail.com> On 03/17/2012 03:28 PM, Kiuhnm wrote: >> They are equally readable. The first one sets EAX to 3; the second >> displays all elements of x on the console. Assembly is readable on a >> very low level, but it's by nature verbose at a high level, and thus >> less readable (you can't eyeball a function and know exactly what it >> does, especially if that function spans more than a screenful of >> code). > > Welcome in the realm of trolling. Seems like you're the one trolling. From torriem at gmail.com Sat Mar 17 19:28:38 2012 From: torriem at gmail.com (Michael Torrie) Date: Sat, 17 Mar 2012 17:28:38 -0600 Subject: Programming D. E. Knuth in Python with the Deterministic Finite Automaton construct In-Reply-To: <4f64d00a$0$1390$4fafbaef@reader1.news.tin.it> References: <4f64a3a0$0$1386$4fafbaef@reader2.news.tin.it> <4f64a9e5$0$1385$4fafbaef@reader2.news.tin.it> <4f64d00a$0$1390$4fafbaef@reader1.news.tin.it> Message-ID: <4F651E26.7010705@gmail.com> On 03/17/2012 11:55 AM, Kiuhnm wrote: > Why should I write a treatise on decompilation techniques on this ng? You were the one that said simply, you're doing it wrong followed by a terse statement, do it like a decompiler. I am familiar with how one might implement a decompiler, as well as a compiler (having written a simple one in the past), but even now I don't see a connection between a decompiler and the process of converting a knuth algorithm into a python python implementation. I was hoping you would shed some light on that. But alas, I'm not really as much of an "interested reader" as you would like me to be. >> Saying, "be like a decompiler" doesn't say anything. > That looks like a glaring contradiction to me... True, if you wish to be pedantic. I should have said, "meaningless," or at least, "not a useful response." > Here's an example of rewriting: > Thank you. Your example makes more clear your assertion about "labels" and how really A1 and A5 were the only real labels in the example. Though I still do not really see why "states" is not a good equivalence for labels in this case. As well, Roy's idea for doing the state machines, which works equally well as the nested if statements, is more pythonic, which is generally preferred in Python. From ben+python at benfinney.id.au Sat Mar 17 20:42:49 2012 From: ben+python at benfinney.id.au (Ben Finney) Date: Sun, 18 Mar 2012 11:42:49 +1100 Subject: Python is readable References: <4f612b19$0$1379$4fafbaef@reader2.news.tin.it> <8e72d74f-c844-4de3-8a37-f6b1fdc2291f@y27g2000yqy.googlegroups.com> <50e9ceec-40f1-4ead-b2b6-87328b30d084@ow8g2000pbc.googlegroups.com> <4f61c828$0$1390$4fafbaef@reader2.news.tin.it> <4f61d728$0$1375$4fafbaef@reader2.news.tin.it> <4f61fd0a$0$1389$4fafbaef@reader2.news.tin.it> <4f620837$0$1382$4fafbaef@reader2.news.tin.it> <4f627c25$0$1381$4fafbaef@reader2.news.tin.it> <4f62b9be$0$29981$c3e8da3$5496439d@news.astraweb.com> <4f632da5$0$1375$4fafbaef@reader1.news.tin.it> <4f636ed5$0$29981$c3e8da3$5496439d@news.astraweb.com> <4f64ed2e$0$1389$4fafbaef@reader1.news.tin.it> <4f650213$0$1375$4fafbaef@reader1.news.tin.it> Message-ID: <877gyioi2e.fsf@benfinney.id.au> Kiuhnm writes: > Welcome in the realm of trolling. Thank you for stating clearly what you're doing. Welcome to yet another kill-file. *plonk* -- \ ?I am too firm in my consciousness of the marvelous to be ever | `\ fascinated by the mere supernatural ?? ?Joseph Conrad, _The | _o__) Shadow-Line_ | Ben Finney From drsalists at gmail.com Sat Mar 17 20:44:07 2012 From: drsalists at gmail.com (Dan Stromberg) Date: Sat, 17 Mar 2012 17:44:07 -0700 Subject: Does anyone actually use PyPy in production? In-Reply-To: <4f63ec8b$0$11975$742ec2ed@news.sonic.net> References: <4f63ec8b$0$11975$742ec2ed@news.sonic.net> Message-ID: I personally feel that python-list should be restricted to discussing Python the language, not just CPython the implementation. Anyway, there are many kinds of production, no? But I use Pypy for my backups frequently, which is a form of production use. Pypy+backshift pass my automated tests as well as CPython+backshift and Jython+backshift, so why not? On Fri, Mar 16, 2012 at 6:44 PM, John Nagle wrote: > Does anyone run PyPy in production? > > John Nagle > -- > http://mail.python.org/**mailman/listinfo/python-list > -------------- next part -------------- An HTML attachment was scrubbed... URL: From steve+comp.lang.python at pearwood.info Sat Mar 17 20:57:11 2012 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 18 Mar 2012 00:57:11 GMT Subject: Python is readable References: <4f612b19$0$1379$4fafbaef@reader2.news.tin.it> <8e72d74f-c844-4de3-8a37-f6b1fdc2291f@y27g2000yqy.googlegroups.com> <50e9ceec-40f1-4ead-b2b6-87328b30d084@ow8g2000pbc.googlegroups.com> <4f61c828$0$1390$4fafbaef@reader2.news.tin.it> <4f61d728$0$1375$4fafbaef@reader2.news.tin.it> <4f61fd0a$0$1389$4fafbaef@reader2.news.tin.it> <4f6280a0$0$29981$c3e8da3$5496439d@news.astraweb.com> <4f6333ca$0$1392$4fafbaef@reader1.news.tin.it> <4f633a1a$0$29981$c3e8da3$5496439d@news.astraweb.com> <9sgsb1FsbpU1@mid.individual.net> <4f636a38$0$29981$c3e8da3$5496439d@news.astraweb.com> <9shd0kFvgbU1@mid.individual.net> <4f638b76$0$29981$c3e8da3$5496439d@news.astraweb.com> <9shj05FabeU1@mid.individual.net> <4f64fa18$0$1392$4fafbaef@reader1.news.tin.it> Message-ID: <4f6532e7$0$29981$c3e8da3$5496439d@news.astraweb.com> On Sat, 17 Mar 2012 21:54:40 +0100, Kiuhnm wrote: > On 3/16/2012 21:04, Prasad, Ramit wrote: >>> People spell your name Stephen, sometimes too. Thinking of changing >>> it? Gore Vidal's quote has panache, a valid compensation for breaking >> the usual rule. How many other uses on that page are similar? >> >> >> He provided common examples and reference links. Seems like a pretty >> reasonable way of trying to prove a point. If you don't like reference >> links, what would convince you that the point was correct? I have not >> seen any counter examples or counter references on your behalf... > > He's referring to this "rule": > "A colon should not precede a list unless it follows a complete > sentence; however, the colon is a style choice that some publications > allow." > http://www.grammarbook.com/punctuation/colons.asp That is an invented prescriptivist rule and not based on English grammar as it actually is used by native English speakers. It is *bullshit*. Even the author of that page breaks it. Immediately following the above prohibition, she follows it with the sentence fragment: "Examples:" and then a list -- exactly what she says you may not do. People *do* precede lists by a colon following a sentence fragment. This is unremarkable English grammar, with only a tiny number of arse-plugged prescriptivists finding anything to complain about it, and even they break their own bullshit made-up so-called rule. The vast majority of English speakers write things like: TO DO: - mow the lawn - wash the car - take kids to the zoo - write book on grammar and there is nothing wrong with doing so. -- Steven From rosuav at gmail.com Sat Mar 17 21:07:36 2012 From: rosuav at gmail.com (Chris Angelico) Date: Sun, 18 Mar 2012 12:07:36 +1100 Subject: Python is readable In-Reply-To: <4f6532e7$0$29981$c3e8da3$5496439d@news.astraweb.com> References: <4f612b19$0$1379$4fafbaef@reader2.news.tin.it> <8e72d74f-c844-4de3-8a37-f6b1fdc2291f@y27g2000yqy.googlegroups.com> <50e9ceec-40f1-4ead-b2b6-87328b30d084@ow8g2000pbc.googlegroups.com> <4f61c828$0$1390$4fafbaef@reader2.news.tin.it> <4f61d728$0$1375$4fafbaef@reader2.news.tin.it> <4f61fd0a$0$1389$4fafbaef@reader2.news.tin.it> <4f6280a0$0$29981$c3e8da3$5496439d@news.astraweb.com> <4f6333ca$0$1392$4fafbaef@reader1.news.tin.it> <4f633a1a$0$29981$c3e8da3$5496439d@news.astraweb.com> <9sgsb1FsbpU1@mid.individual.net> <4f636a38$0$29981$c3e8da3$5496439d@news.astraweb.com> <9shd0kFvgbU1@mid.individual.net> <4f638b76$0$29981$c3e8da3$5496439d@news.astraweb.com> <9shj05FabeU1@mid.individual.net> <4f64fa18$0$1392$4fafbaef@reader1.news.tin.it> <4f6532e7$0$29981$c3e8da3$5496439d@news.astraweb.com> Message-ID: On Sun, Mar 18, 2012 at 11:57 AM, Steven D'Aprano wrote: > The vast majority of English speakers write things like: > > ? ?TO DO: And the vast majority of programmers leave out the space, even in non-code. ChrisA From research at johnohagan.com Sat Mar 17 21:35:16 2012 From: research at johnohagan.com (John O'Hagan) Date: Sun, 18 Mar 2012 12:35:16 +1100 Subject: Daemonization / Popen / pipe issue In-Reply-To: <4F650D66.4040209@leeclemens.net> References: <4F63F2FE.1030409@leeclemens.net> <20120317143726.7134d2b04d56d1759d8eeeb6@johnohagan.com> <4F650D66.4040209@leeclemens.net> Message-ID: <20120318123516.0c13a6345c333a040568b95a@johnohagan.com> On Sat, 17 Mar 2012 18:17:10 -0400 Lee Clemens wrote: > On 03/16/2012 11:37 PM, John O'Hagan wrote: > > On Fri, 16 Mar 2012 22:12:14 -0400 > > Lee Clemens wrote: > > > >> I have a multi-threaded application > >> > >> I have provided a test-case here: https://gist.github.com/2054194 > > I haven't looked at your test case yet, but a possible cause is the fact > > that the main application (or main thread) exits if it has finished > > executing and only daemon threads remain. This can abruptly terminate > > threads which may be busy, for example, communicating via a pipe. The best > > solution IMO is not to use daemon threads, but to give all threads a way to > > terminate cleanly before the main thread does, even if this means using a > > flag or the like. > > > > HTH, > > > > John > > > I call .join() on each spawned thread, whether it is daemonized or not. > The code is available here: > > https://gist.github.com/2054194 I've tried running your code (which at a glance looks very well-written) but I get the broken pipe errors whether the DAEMONIZE flag is True or False (Python 2.7, Debian testing). I don't have time to dig much deeper. > Is it generally not recommended to daemonize Python applications using > this method? I'm no guru, but not that I know of. I haven't seen the os.fork method you use before; out of interest, why not use Thread.setDaemon? > Do you have any references or data to support your opinion? > Do you have any references which specifically state - "Daemonizing > Python applications cause Python to work in unexpected ways."? Not particularly, although there are a few oldish references to "Python daemon threads considered harmful" out there. You probably know that daemonising can cover a multitude of sins, and it's always a good idea to ensure clean termination and not just assume that what happens in a daemon thread on program exit is moot. I'm not saying you haven't done that, in fact your errors seem to occur during execution, not termination. I replied to your post because I've had broken pipe errors before with daemon threads communicating on sockets which sounded similar to your issue. I solved them by rewriting so that the main thread told the threads to terminate, and waited till they had. This made daemonising unnecessary in that case. [...] Regards, John From steve+comp.lang.python at pearwood.info Sat Mar 17 21:36:30 2012 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 18 Mar 2012 01:36:30 GMT Subject: Python is readable References: <4f612b19$0$1379$4fafbaef@reader2.news.tin.it> <8e72d74f-c844-4de3-8a37-f6b1fdc2291f@y27g2000yqy.googlegroups.com> <50e9ceec-40f1-4ead-b2b6-87328b30d084@ow8g2000pbc.googlegroups.com> <4f61c828$0$1390$4fafbaef@reader2.news.tin.it> <4f61d728$0$1375$4fafbaef@reader2.news.tin.it> <4f61fd0a$0$1389$4fafbaef@reader2.news.tin.it> <4f620837$0$1382$4fafbaef@reader2.news.tin.it> <4f627c25$0$1381$4fafbaef@reader2.news.tin.it> <4f62b9be$0$29981$c3e8da3$5496439d@news.astraweb.com> <4f632da5$0$1375$4fafbaef@reader1.news.tin.it> <4f636ed5$0$29981$c3e8da3$5496439d@news.astraweb.com> <4f64ed2e$0$1389$4fafbaef@reader1.news.tin.it> Message-ID: <4f653c1e$0$29981$c3e8da3$5496439d@news.astraweb.com> On Sat, 17 Mar 2012 20:59:34 +0100, Kiuhnm wrote: > Ok, so length and readability are orthogonal properties. Could you > please explain to me in which way > mov eax, 3 > should be less readable than > for i in x: print(i) > ? "mov eax, 3" requires more domain-specific knowledge. It operates at a very low level, that of memory locations and bytes, rather than at a level which most people can reason about efficiently. English speakers would probably guess that "mov" was an abbreviation of "move", but what is being moved, and from where to where, for what purpose? They're also likely to flounder on the analogy of "moving" bytes. When you move a book from here to there, you leave a space in the row of books where there is no longer a book. (You might choose to move a second book into that gap, but first there is a gap.) But when you move bytes, you don't leave a gap. There are always bytes at every valid address. The average non-programmer is likely to have the wrong data model to understand what "mov eax, 3" does. In the second example, most English speakers would intuit that "print(i)" prints i, whatever i is. "for i in x" is more cryptic, but if it were written with less jargon-like names, such as "for item in list" or "for person in family" or similar, they would likely guess that it means to repeat the following instructions for each item in the set: "For each person at the table, place a plate, knife and fork." And even if the reader can't guess the meaning of the for-loop, it is a concept easy enough for most people to grasp given some explanations and examples. It's neither too low level (assembly language), nor too high level (monads, functors) but is at just the right level of abstraction versus concreteness for the average person to follow. -- Steven From steve+comp.lang.python at pearwood.info Sat Mar 17 21:46:04 2012 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 18 Mar 2012 01:46:04 GMT Subject: Python is readable References: <4f612b19$0$1379$4fafbaef@reader2.news.tin.it> <8e72d74f-c844-4de3-8a37-f6b1fdc2291f@y27g2000yqy.googlegroups.com> <50e9ceec-40f1-4ead-b2b6-87328b30d084@ow8g2000pbc.googlegroups.com> <4f61c828$0$1390$4fafbaef@reader2.news.tin.it> <4f61d728$0$1375$4fafbaef@reader2.news.tin.it> <4f61fd0a$0$1389$4fafbaef@reader2.news.tin.it> <4f6280a0$0$29981$c3e8da3$5496439d@news.astraweb.com> <4f6333ca$0$1392$4fafbaef@reader1.news.tin.it> <4f633a1a$0$29981$c3e8da3$5496439d@news.astraweb.com> <4f64f2d8$0$1393$4fafbaef@reader1.news.tin.it> Message-ID: <4f653e5c$0$29981$c3e8da3$5496439d@news.astraweb.com> On Sat, 17 Mar 2012 21:23:45 +0100, Kiuhnm wrote: > On 3/16/2012 14:03, Steven D'Aprano wrote: >> A one line routine is still a routine. There is nothing ungrammatical >> about "If you can: take the bus.", although it is non-idiomatic >> English. > > In another post you wrote > "Sorry, I was talking about the other sort, the ones who apply the > grammatical rules used by people in real life. You know the ones: > linguists." > > Then how do you know that there's nothing ungrammatical about "If you > can: take the bus" if people don't use it? Who says it is ungrammatical? If the list (a list of one item, but still a list) was labelled as a list like this: If you can: (1) take the bus. or if the items were offset like this: If you can: - take the bus. (or similar) I wouldn't hesitate to say it was following the same form as this: Your mission, should you choose to accept it, is to: - take the bus ... - do this - do that - etc. even though in English we don't usually treat a list of one item as a list. That would make it unidiomatic but grammatically valid. But written in line, as you do, I'm not entirely sure. It is more of a grey area. It is not explicitly written as a list of items, so a colon seems a bit too "heavy" and I would prefer to write: If you can, take the bus. That flows better and is more idiomatic. On balance, I think it *is* grammatical but only on a technicality (a little like the (in)famous "Buffalo buffalo buffalo buffalo" sentence), but poorly written and not idiomatic. Natural languages frequently have many sentences which obey the grammatical rules and yet nobody uses that *specific* sentence, either because they feel clumsy, or because they are semantically meaningless, e.g. "hairless fears deconstruct lustily". But the problem with "If you can: take the bus" is not the colon or the initial sentence fragment. It is the fact that it introduces a list of a single item in a form that doesn't look like a list of items. This, for example, reads much more naturally: "If you can: take the bus to work every day; work hard for an unappreciative boss; give up 40% of your pay in taxes for a war you disagree with; use the rest to support a family that despises you; remind yourself that you're still happier than 90% of the people who have every lived." -- Steven From steve+comp.lang.python at pearwood.info Sat Mar 17 21:52:25 2012 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 18 Mar 2012 01:52:25 GMT Subject: Using non-dict namespaces in functions References: <4f647317$0$29981$c3e8da3$5496439d@news.astraweb.com> Message-ID: <4f653fd9$0$29981$c3e8da3$5496439d@news.astraweb.com> On Sat, 17 Mar 2012 11:42:49 -0700, Eric Snow wrote: > On Sat, Mar 17, 2012 at 4:18 AM, Steven D'Aprano > wrote: >> Note that it is important for my purposes that MockChainMap does not >> inherit from dict. > > Care to elaborate? I want to use collections.ChainMap, or something very like it, and I don't want to be forced into an unnatural is-a relationship with dict if I don't have to. [...] > Regardless, you could also implement __call__() on a function look-alike > class to get what you're after. It may not be as performant though. I don't think that can work, because __call__ itself is a function, and I would need to change *its* globals. Which brings me back exactly where I started, trying to change globals in a function to a non-dict. -- Steven From steve+comp.lang.python at pearwood.info Sat Mar 17 21:54:10 2012 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 18 Mar 2012 01:54:10 GMT Subject: Programming D. E. Knuth in Python with the Deterministic Finite Automaton construct References: <4f64a3a0$0$1386$4fafbaef@reader2.news.tin.it> <4f64a9e5$0$1385$4fafbaef@reader2.news.tin.it> <4f64d00a$0$1390$4fafbaef@reader1.news.tin.it> Message-ID: <4f654042$0$29981$c3e8da3$5496439d@news.astraweb.com> On Sat, 17 Mar 2012 17:28:38 -0600, Michael Torrie wrote: > Thank you. Your example makes more clear your assertion about "labels" > and how really A1 and A5 were the only real labels in the example. > Though I still do not really see why "states" is not a good equivalence > for labels in this case. Program labels are states. You can treat every line of code as being invisibly labelled with the line number. (Or visibly, if you are using BASIC back in 1975.) Clearly "the interpreter is executing at line 42" is a state distinct from "the interpreter is executing line 23", but that state *alone* is not sufficient to know the overall state of the program. Adding an explicit GOTO label does not change this. But this refers to the state of the interpreter, not the state of the program being executed, and either way, is not a state in the sense of a finite state machine. -- Steven From steve+usenet at pearwood.info Sat Mar 17 22:05:38 2012 From: steve+usenet at pearwood.info (Steven D'Aprano) Date: 18 Mar 2012 02:05:38 GMT Subject: Python is readable References: <4f612b19$0$1379$4fafbaef@reader2.news.tin.it> <50e9ceec-40f1-4ead-b2b6-87328b30d084@ow8g2000pbc.googlegroups.com> <4f61c828$0$1390$4fafbaef@reader2.news.tin.it> <4f61d728$0$1375$4fafbaef@reader2.news.tin.it> <4f61fd0a$0$1389$4fafbaef@reader2.news.tin.it> <4f6280a0$0$29981$c3e8da3$5496439d@news.astraweb.com> <4f6333ca$0$1392$4fafbaef@reader1.news.tin.it> <4f633a1a$0$29981$c3e8da3$5496439d@news.astraweb.com> <9sgsb1FsbpU1@mid.individual.net> <4f636a38$0$29981$c3e8da3$5496439d@news.astraweb.com> <9shd0kFvgbU1@mid.individual.net> <4f638b76$0$29981$c3e8da3$5496439d@news.astraweb.com> <9shj05FabeU1@mid.individual.net> <4f64fa18$0$1392$4fafbaef@reader1.news.tin.it> <4f6532e7$0$29981$c3e8da3$5496439d@news.astraweb.com> Message-ID: <4f6542f1$0$29981$c3e8da3$5496439d@news.astraweb.com> On Sun, 18 Mar 2012 12:07:36 +1100, Chris Angelico wrote: > On Sun, Mar 18, 2012 at 11:57 AM, Steven D'Aprano > wrote: >> The vast majority of English speakers write things like: >> >> ? ?TO DO: > > And the vast majority of programmers leave out the space, even in > non-code. I'm not sure if you're making a point there, or just a witty observation, but for the record I would accept dictionaries adding "todo" as a jargon entry. I don't think it is widespread enough to count as a regular word, but if we can have "another", "anywhere", "nowhere" and "pocketbook", I don't see why we might not someday have "todo". -- Steven From rosuav at gmail.com Sat Mar 17 22:15:08 2012 From: rosuav at gmail.com (Chris Angelico) Date: Sun, 18 Mar 2012 13:15:08 +1100 Subject: Python is readable In-Reply-To: <4f6542f1$0$29981$c3e8da3$5496439d@news.astraweb.com> References: <4f612b19$0$1379$4fafbaef@reader2.news.tin.it> <50e9ceec-40f1-4ead-b2b6-87328b30d084@ow8g2000pbc.googlegroups.com> <4f61c828$0$1390$4fafbaef@reader2.news.tin.it> <4f61d728$0$1375$4fafbaef@reader2.news.tin.it> <4f61fd0a$0$1389$4fafbaef@reader2.news.tin.it> <4f6280a0$0$29981$c3e8da3$5496439d@news.astraweb.com> <4f6333ca$0$1392$4fafbaef@reader1.news.tin.it> <4f633a1a$0$29981$c3e8da3$5496439d@news.astraweb.com> <9sgsb1FsbpU1@mid.individual.net> <4f636a38$0$29981$c3e8da3$5496439d@news.astraweb.com> <9shd0kFvgbU1@mid.individual.net> <4f638b76$0$29981$c3e8da3$5496439d@news.astraweb.com> <9shj05FabeU1@mid.individual.net> <4f64fa18$0$1392$4fafbaef@reader1.news.tin.it> <4f6532e7$0$29981$c3e8da3$5496439d@news.astraweb.com> <4f6542f1$0$29981$c3e8da3$5496439d@news.astraweb.com> Message-ID: On Sun, Mar 18, 2012 at 1:05 PM, Steven D'Aprano wrote: > I'm not sure if you're making a point there, or just a witty observation, > but for the record I would accept dictionaries adding "todo" as a jargon > entry. I don't think it is widespread enough to count as a regular word, > but if we can have "another", "anywhere", "nowhere" and "pocketbook", I > don't see why we might not someday have "todo". A bit of both. My point is: The jargon that is developed in specific domains (such as TODO, and the P-convention among Lispers, and so on) often ends up used outside it. Once people not associated with the original domain are using that jargon, it can be safely declared to be part of the language. TODO mightn't be there quite yet, but I agree, it's highly likely to be dictionarified (is THAT a word?) before long. ChrisA From driscoll at cs.wisc.edu Sat Mar 17 22:59:31 2012 From: driscoll at cs.wisc.edu (Evan Driscoll) Date: Sat, 17 Mar 2012 21:59:31 -0500 Subject: Programming D. E. Knuth in Python with the Deterministic Finite Automaton construct In-Reply-To: References: Message-ID: <4F654F93.4080309@cs.wisc.edu> On 3/17/2012 9:03, Antti J Ylikoski wrote: > > In his legendary book series The Art of Computer Programming, > Professor Donald E. Knuth presents many of his algorithms in the form > that they have been divided in several individual phases, with > instructions to GOTO to another phase interspersed in the text of the > individual phases. > > > A1. (Do the work of Phase A1.) If then go to Phase A5, > otherwise continue. > > A2. (Do some work.) If go to Phase A4. > > A3. (Some more work.) > > A4. (Do something.) If go to Phase A1. > > A5. (Something more). If then go to Phase A2, otherwise > end. Clearly you just need the goto module (http://entrian.com/goto/): from goto import goto, label label .A1 # do work of phase A1 if : goto .A5 label .A2 # do some work if : goto .A4 # do some more work label .A4 # do something if : goto .A1 label .A5 # something more if : goto .A2 Clearly the best solution of all. (Note: do not actually do this.) Evan -------------- next part -------------- A non-text attachment was scrubbed... Name: signature.asc Type: application/pgp-signature Size: 552 bytes Desc: OpenPGP digital signature URL: From cs at zip.com.au Sun Mar 18 00:15:48 2012 From: cs at zip.com.au (Cameron Simpson) Date: Sun, 18 Mar 2012 15:15:48 +1100 Subject: Daemonization / Popen / pipe issue In-Reply-To: <20120318123516.0c13a6345c333a040568b95a@johnohagan.com> References: <20120318123516.0c13a6345c333a040568b95a@johnohagan.com> Message-ID: <20120318041548.GA15675@cskk.homeip.net> On 18Mar2012 12:35, John O'Hagan wrote: | On Sat, 17 Mar 2012 18:17:10 -0400 | Lee Clemens wrote: | > Is it generally not recommended to daemonize Python applications using | > this method? | | I'm no guru, but not that I know of. I haven't seen the os.fork method you use | before; out of interest, why not use Thread.setDaemon? They are two entirely different practices. Thread.setDaemon is a flag for a particular thread telling the python system to not bother waiting for it at exit time. The daemonize stuff Lee is using is "daemon" in the UNIX sense: forking the main process (the whole python instance) into an unassociated process not subject to job control etc. I glanced at Lee's code and have seen found anything obviously wrong yet. Maybe if I get a bit more time later. It seems that in daemon mode the code forks first, exactly once, before firing off any subprocesses or threads. Is this correct? If the daemonising happened per thread that would be very bad. BTW, Lee, there is an external module for daemonising things in the UNIX sense: http://pypi.python.org/pypi/python-daemon I recommend you use it. Cheers, -- Cameron Simpson DoD#743 http://www.cskk.ezoshosting.com/cs/ The First Law of Internet Communications: Be liberal in what you accept, and conservative in what you send. - Jon Postel From van.lindberg at gmail.com Sun Mar 18 00:51:49 2012 From: van.lindberg at gmail.com (VanL) Date: Sat, 17 Mar 2012 23:51:49 -0500 Subject: Comments wanted: Proposed change to install layout Message-ID: There is a proposal on Python-dev right now (championed by me) to harmonize the install layout for Python between platforms. This change would be most noticeable on Windows. Specifically, using Python 3.3 or above: 1) the 'Scripts' directory would change to 'bin'; 2) python.exe would move to the 'bin' directory; and 3) the installer for Windows would get the optional ability to add this directory to the PATH. Please reply if this would help you or harm you, and how. Thanks, Van -------------- next part -------------- An HTML attachment was scrubbed... URL: From __peter__ at web.de Sun Mar 18 03:50:46 2012 From: __peter__ at web.de (Peter Otten) Date: Sun, 18 Mar 2012 08:50:46 +0100 Subject: Using non-dict namespaces in functions References: <4f647317$0$29981$c3e8da3$5496439d@news.astraweb.com> <4f653fd9$0$29981$c3e8da3$5496439d@news.astraweb.com> Message-ID: Steven D'Aprano wrote: > On Sat, 17 Mar 2012 11:42:49 -0700, Eric Snow wrote: > >> On Sat, Mar 17, 2012 at 4:18 AM, Steven D'Aprano >> wrote: >>> Note that it is important for my purposes that MockChainMap does not >>> inherit from dict. >> >> Care to elaborate? > > I want to use collections.ChainMap, or something very like it, and I > don't want to be forced into an unnatural is-a relationship with dict if > I don't have to. > > > [...] >> Regardless, you could also implement __call__() on a function look-alike >> class to get what you're after. It may not be as performant though. > > I don't think that can work, because __call__ itself is a function, and I > would need to change *its* globals. Which brings me back exactly where I > started, trying to change globals in a function to a non-dict. The key lookup code in ceval.c is inlined, so even subclassing dict and overriding __getitem__() won't help. Instead of def f(a): return a + b # b taken from some custom namespace you have to resort to the conventional approach def f(a, ns=magic()): return a + ns["b"] or def f(self, a): return a + self.b From cosmius at gmail.com Sun Mar 18 05:42:20 2012 From: cosmius at gmail.com (Cosmia Luna) Date: Sun, 18 Mar 2012 02:42:20 -0700 (PDT) Subject: How to get a reference of the 'owner' class to which a method belongs in Python 3.X? In-Reply-To: References: <20411334.2044.1331962234309.JavaMail.geo-discussion-forums@yncd8> Message-ID: <14929632.47.1332063740635.JavaMail.geo-discussion-forums@ynbq18> I think I got the way to handle it but with small problem and probably at unnecessary performance cost. If you're going to use it, be sure rewrite the code and remove the lines which you don't need. Annnnd, test them, the code below is only tested on py3.2, and may contains a lot of bugs even in py3.2. You don't need it in py2.X, really. ----------------------------------BEGIN PYTHON---------------------------------- from functools import wraps from types import FunctionType CLASS_REF = 'im_class' class Py2Type(type): def __init__(cls, name, bases, dict_): for k, v in dict_.items(): #ref3 if isinstance(v, FunctionType): setattr(v, CLASS_REF, cls) for base in bases: for k, v in base.__dict__.items(): if isinstance(v, FunctionType) and k not in dict_: @wraps(v) def wrapper(*args, **kwargs): return v(*args, **kwargs) setattr(wrapper, CLASS_REF, cls) dict_[k] = wrapper setattr(cls, k, wrapper) #ref1 type.__init__(cls, name, bases, dict_) #ref2 Py2TypeBase = Py2Type('Py2TypeBase', (object, ), {}) -----------------------------------END PYTHON----------------------------------- And any class inherit(directly or indirectly) from Py2TypeBase can have them unbound method has a 'im_class' attribute reference to the owner class. Usage: Just subclass Py2TypeBase and write anything you want. ----------------------------------BEGIN PYTHON---------------------------------- class Foo(Py2TypeBase): def get(self): pass def set(self): pass class Bar(Foo): def get(self): pass assert Foo.get.im_class is Foo assert Foo.set.im_class is Foo assert Bar.get.im_class is Bar assert Bar.set.im_class is Bar # the code above works, but only the explicitly defined will has the # im_class attribute, so assert Foo.__init__.im_class is Foo # this doesn't work. -----------------------------------END PYTHON----------------------------------- But it seems that the last line(#ref2) in the Py2Type.__init__ does not work at all. It seems really weird, 'type' is an instance of 'type' itself, I'm not sure if I'm calling the unbound method __init__ or bound method __init__. And the original code does not have the line(#ref1), but because line(#ref2) does not work, I added them. It seems type.__new__ calls type.__init__ before it calls Py2Type.__init__, because dict_ is already copied to cls.__dict__ at line(#ref3). But 'type' is written in C or some other, it's beyond my ability to read the code. Can anyone tell me what python does when a class block is fully evaluated kindly? Regards, Cosmia From cosmius at gmail.com Sun Mar 18 05:42:20 2012 From: cosmius at gmail.com (Cosmia Luna) Date: Sun, 18 Mar 2012 02:42:20 -0700 (PDT) Subject: How to get a reference of the 'owner' class to which a method belongs in Python 3.X? In-Reply-To: References: <20411334.2044.1331962234309.JavaMail.geo-discussion-forums@yncd8> Message-ID: <14929632.47.1332063740635.JavaMail.geo-discussion-forums@ynbq18> I think I got the way to handle it but with small problem and probably at unnecessary performance cost. If you're going to use it, be sure rewrite the code and remove the lines which you don't need. Annnnd, test them, the code below is only tested on py3.2, and may contains a lot of bugs even in py3.2. You don't need it in py2.X, really. ----------------------------------BEGIN PYTHON---------------------------------- from functools import wraps from types import FunctionType CLASS_REF = 'im_class' class Py2Type(type): def __init__(cls, name, bases, dict_): for k, v in dict_.items(): #ref3 if isinstance(v, FunctionType): setattr(v, CLASS_REF, cls) for base in bases: for k, v in base.__dict__.items(): if isinstance(v, FunctionType) and k not in dict_: @wraps(v) def wrapper(*args, **kwargs): return v(*args, **kwargs) setattr(wrapper, CLASS_REF, cls) dict_[k] = wrapper setattr(cls, k, wrapper) #ref1 type.__init__(cls, name, bases, dict_) #ref2 Py2TypeBase = Py2Type('Py2TypeBase', (object, ), {}) -----------------------------------END PYTHON----------------------------------- And any class inherit(directly or indirectly) from Py2TypeBase can have them unbound method has a 'im_class' attribute reference to the owner class. Usage: Just subclass Py2TypeBase and write anything you want. ----------------------------------BEGIN PYTHON---------------------------------- class Foo(Py2TypeBase): def get(self): pass def set(self): pass class Bar(Foo): def get(self): pass assert Foo.get.im_class is Foo assert Foo.set.im_class is Foo assert Bar.get.im_class is Bar assert Bar.set.im_class is Bar # the code above works, but only the explicitly defined will has the # im_class attribute, so assert Foo.__init__.im_class is Foo # this doesn't work. -----------------------------------END PYTHON----------------------------------- But it seems that the last line(#ref2) in the Py2Type.__init__ does not work at all. It seems really weird, 'type' is an instance of 'type' itself, I'm not sure if I'm calling the unbound method __init__ or bound method __init__. And the original code does not have the line(#ref1), but because line(#ref2) does not work, I added them. It seems type.__new__ calls type.__init__ before it calls Py2Type.__init__, because dict_ is already copied to cls.__dict__ at line(#ref3). But 'type' is written in C or some other, it's beyond my ability to read the code. Can anyone tell me what python does when a class block is fully evaluated kindly? Regards, Cosmia From albert at spenarnc.xs4all.nl Sun Mar 18 07:03:43 2012 From: albert at spenarnc.xs4all.nl (Albert van der Horst) Date: 18 Mar 2012 11:03:43 GMT Subject: Programming D. E. Knuth in Python with the Deterministic Finite Automaton construct References: <4f64d00a$0$1390$4fafbaef@reader1.news.tin.it> <4f654042$0$29981$c3e8da3$5496439d@news.astraweb.com> Message-ID: In article <4f654042$0$29981$c3e8da3$5496439d at news.astraweb.com>, Steven D'Aprano wrote: >On Sat, 17 Mar 2012 17:28:38 -0600, Michael Torrie wrote: > >> Thank you. Your example makes more clear your assertion about "labels" >> and how really A1 and A5 were the only real labels in the example. >> Though I still do not really see why "states" is not a good equivalence >> for labels in this case. > >Program labels are states. > >You can treat every line of code as being invisibly labelled with the >line number. (Or visibly, if you are using BASIC back in 1975.) Clearly >"the interpreter is executing at line 42" is a state distinct from "the >interpreter is executing line 23", but that state *alone* is not >sufficient to know the overall state of the program. This is the idea of the original (not universal, hard coded) Turing machine with cards. Of course you then still need the infinite tape to store calculation input and output. > >Adding an explicit GOTO label does not change this. > >But this refers to the state of the interpreter, not the state of the >program being executed, and either way, is not a state in the sense of a >finite state machine. I hope the reference to the Turing machine makes this clearer. Turing Machines and Finite State Machines are different constructions in automaton theory. Remember those definitions are like A Turing machine is a set S the set of symbols T a mapping of S onto IZ (natural numbers) ... F is a mapping from SxT into G .. Some such. (A FSM is just different with different mappings ) The memory of the Turing machine is T , the tape, time dependant. The program of the Turing is e.g. F, to be thought of as hard wiring. A Turing machine is *not* a stored program computer! The universal Turing machine is, it contains a hardwired program to execute a stored program on the tape. > >-- >Steven Groetjes Albert -- -- Albert van der Horst, UTRECHT,THE NETHERLANDS Economic growth -- being exponential -- ultimately falters. albert at spe&ar&c.xs4all.nl &=n http://home.hccnet.nl/a.w.m.van.der.horst From albert at spenarnc.xs4all.nl Sun Mar 18 07:08:59 2012 From: albert at spenarnc.xs4all.nl (Albert van der Horst) Date: 18 Mar 2012 11:08:59 GMT Subject: Programming D. E. Knuth in Python with the Deterministic Finite Automaton construct References: Message-ID: In article , Antti J Ylikoski wrote: > >In his legendary book series The Art of Computer Programming, >Professor Donald E. Knuth presents many of his algorithms in the form >that they have been divided in several individual phases, with >instructions to GOTO to another phase interspersed in the text of the >individual phases. > > > >I. e. they look like the following, purely invented, example: (Knuth is >being clearer than me below.....) > > > >A1. (Do the work of Phase A1.) If then go to Phase A5, >otherwise continue. > >A2. (Do some work.) If go to Phase A4. > >A3. (Some more work.) > >A4. (Do something.) If go to Phase A1. > >A5. (Something more). If then go to Phase A2, otherwise >end. I can rewrite this into Python in my sleep, without resorting to formal techniques. Instead try one of the harder algorithms like T (Toom Cook) that must be translated to recursive functions that pass data down. That took me quite a wile. The correct answer is, it is just labour. Deal with it. Note that if you want to translate it to assembler, it is relatively easy. > >kind regards, Antti J Ylikoski >Helsinki, Finland, the EU Groetjes Albert -- -- Albert van der Horst, UTRECHT,THE NETHERLANDS Economic growth -- being exponential -- ultimately falters. albert at spe&ar&c.xs4all.nl &=n http://home.hccnet.nl/a.w.m.van.der.horst From adminlewis at gmail.com Sun Mar 18 08:03:47 2012 From: adminlewis at gmail.com (admin lewis) Date: Sun, 18 Mar 2012 13:03:47 +0100 Subject: dpkg status Message-ID: Hi, anyone know what library i have to use to manage /var/lib/dpkg/status file to get url of packages ? thanks lewis -- Linux Server, Microsoft Windows 2003/2008 Server, Exchange 2007 http://predellino.blogspot.com/ From andrea.crotti.0 at gmail.com Sun Mar 18 09:31:50 2012 From: andrea.crotti.0 at gmail.com (Andrea Crotti) Date: Sun, 18 Mar 2012 13:31:50 +0000 Subject: Unittest2 on python 2.6 Message-ID: <4F65E3C6.2020405@gmail.com> Suppose we want to use the unittest from Python 2.7, but also want to support Python 2.6, what is the best way to do it? The solution used now is to have in setup.py if sys.version < '2.7': tests_require.append('unittest2') and then in every test file try: import unittest2 as unittest except ImportError: import unittest and it should work just fine, but it's a bit verbose to have this try/except dance everywhere.. Any ideas? From vincent.vandevyvre at swing.be Sun Mar 18 10:00:06 2012 From: vincent.vandevyvre at swing.be (Vincent Vande Vyvre) Date: Sun, 18 Mar 2012 15:00:06 +0100 Subject: dpkg status In-Reply-To: References: Message-ID: <4F65EA66.8000509@swing.be> An HTML attachment was scrubbed... URL: From adminlewis at gmail.com Sun Mar 18 10:54:41 2012 From: adminlewis at gmail.com (admin lewis) Date: Sun, 18 Mar 2012 15:54:41 +0100 Subject: dpkg status In-Reply-To: <4F65EA66.8000509@swing.be> References: <4F65EA66.8000509@swing.be> Message-ID: 2012/3/18 Vincent Vande Vyvre : > Le 18/03/12 13:03, admin lewis a ?crit?: > > Hi, > > What url ?, Sources, maintainer? > No, I need of to open /var/lib/dpkg/status and extract the packages and its url to download it... I know that there is python-apt http://apt.alioth.debian.org/python-apt-doc/library/index.html but I dont understand how it works.. -- Linux Server, Microsoft Windows 2003/2008 Server, Exchange 2007 http://predellino.blogspot.com/ From vincent.vandevyvre at swing.be Sun Mar 18 11:17:57 2012 From: vincent.vandevyvre at swing.be (Vincent Vande Vyvre) Date: Sun, 18 Mar 2012 16:17:57 +0100 Subject: dpkg status In-Reply-To: References: <4F65EA66.8000509@swing.be> Message-ID: <4F65FCA5.8090504@swing.be> An HTML attachment was scrubbed... URL: From tjreedy at udel.edu Sun Mar 18 11:46:39 2012 From: tjreedy at udel.edu (Terry Reedy) Date: Sun, 18 Mar 2012 11:46:39 -0400 Subject: Unittest2 on python 2.6 In-Reply-To: <4F65E3C6.2020405@gmail.com> References: <4F65E3C6.2020405@gmail.com> Message-ID: On 3/18/2012 9:31 AM, Andrea Crotti wrote: > Suppose we want to use the unittest from Python 2.7, but also want to > support Python 2.6, > what is the best way to do it? > > The solution used now is to have in setup.py > > if sys.version < '2.7': > tests_require.append('unittest2') > > and then in every test file > > try: > import unittest2 as unittest > except ImportError: > import unittest > > and it should work just fine, but it's a bit verbose to have this > try/except dance everywhere.. > Any ideas? 1. If the difference between unittest and unittest2 is strictly a matter of deletions and addition, replace unittest with the union of the two. 2. Put the try/except dance in a compat file. Then everywhere else 'from compat import unittest'. This idea is one of those used to write code that will run on both 2.x and 3.x -- Terry Jan Reedy From ian.g.kelly at gmail.com Sun Mar 18 12:14:12 2012 From: ian.g.kelly at gmail.com (Ian Kelly) Date: Sun, 18 Mar 2012 10:14:12 -0600 Subject: How to get a reference of the 'owner' class to which a method belongs in Python 3.X? In-Reply-To: <14929632.47.1332063740635.JavaMail.geo-discussion-forums@ynbq18> References: <20411334.2044.1331962234309.JavaMail.geo-discussion-forums@yncd8> <14929632.47.1332063740635.JavaMail.geo-discussion-forums@ynbq18> Message-ID: On Sun, Mar 18, 2012 at 3:42 AM, Cosmia Luna wrote: > But it seems that the last line(#ref2) in the Py2Type.__init__ does not work at > all. I'm not sure what you're expecting it to do, but type.__init__ does not actually do anything > It seems really weird, 'type' is an instance of 'type' itself, I'm not sure > if I'm calling the unbound method __init__ or bound method __init__. type.__init__ is never bound. > It seems type.__new__ calls type.__init__ before it calls Py2Type.__init__, > because dict_ is already copied to cls.__dict__ at line(#ref3). No, type.__new__ does not call type.__init__ at all. Rather, it is type.__new__ that is responsible for copying the dict, not type.__init__. For this reason you should override type.__new__ in your metaclass, not type.__init__. Cheers, Ian From adminlewis at gmail.com Sun Mar 18 12:43:51 2012 From: adminlewis at gmail.com (admin lewis) Date: Sun, 18 Mar 2012 17:43:51 +0100 Subject: dpkg status In-Reply-To: <4F65FCA5.8090504@swing.be> References: <4F65EA66.8000509@swing.be> <4F65FCA5.8090504@swing.be> Message-ID: 2012/3/18 Vincent Vande Vyvre : > > > OK, you know apt, I see (your blog). > > But packages have no url, just repositery. > > I see your link python-apt, this doc is very minimalistic, maybe you can > find repositeries infos of packages with aptsources.distinfo, but methods > are not documented. > > http://apt.alioth.debian.org/python-apt-doc/library/aptsources.distinfo.html#module-aptsources.distinfo > Well no, I need something like the following: import apt_pkg tagf = apt_pkg.TagFile(open('/home/lightbox/status')) for section in tagf: indirizzo="http://it.archive.ubuntu.com/ubuntu/pool/main/"+section['Package'][0]+'/'+section['Package']+'/'+section['Package']+'_'+section['Version']+'_'+section['Architecture']+'.deb'+'\n' print indirizzo with the following output: http://it.archive.ubuntu.com/ubuntu/pool/main/t/texlive-lang-all/texlive-lang-all_2009-3_all.deb http://it.archive.ubuntu.com/ubuntu/pool/main/x/xserver-xorg-input-vmmouse/xserver-xorg-input-vmmouse_1:12.7.0-2_i386.deb http://it.archive.ubuntu.com/ubuntu/pool/main/l/libmono-system-data4.0-cil/libmono-system-data4.0-cil_2.10.5-1_all.deb but the best sould be that the script make the download of deb automatically.. infact if u see the output u will see that is not correct.. because the section texlive-lang-all doesn't exist and the correct one is texlive-lang I dont know if i have to connect to the cache of apt or simply i need of source.list.. thanks for any help luigi P.S. the /home/lightbox/status is a partial file of /var/lib/dpkg/status -- Linux Server, Microsoft Windows 2003/2008 Server, Exchange 2007 http://predellino.blogspot.com/ From alister.ware at ntlworld.com Sun Mar 18 14:19:23 2012 From: alister.ware at ntlworld.com (alister) Date: Sun, 18 Mar 2012 18:19:23 GMT Subject: Python is readable References: <4f612b19$0$1379$4fafbaef@reader2.news.tin.it> Message-ID: On Thu, 15 Mar 2012 00:34:47 +0100, Kiuhnm wrote: > I've just started to read > The Quick Python Book (2nd ed.) > The author claims that Python code is more readable than Perl code and > provides this example: > > --- Perl --- > sub pairwise_sum { > my($arg1, $arg2) = @_; > my(@result) = (); > @list1 = @$arg1; > @list2 = @$arg2; > for($i=0; $i < length(@list1); $i++) { > push(@result, $list1[$i] + $list2[$i]); > } > return(\@result); > } > > --- Python --- > def pairwise_sum(list1, list2): > result = [] > for i in range(len(list1)): > result.append(list1[i] + list2[i]) > return result > --- --- > > It's quite clear that he knows little about Perl. > Here's what I would've written: > > sub pairwise_sum { > my ($list1, $list2) = @_; > my @result; > push @result, $list1->[$_] + $list2->[$_] for (0..@$list1-1); > \@result; > } > > Having said that, the Python code is still more readable, so there's no > need to misrepresent Perl that way. > Now I'm wondering whether the author will show me "good" or "bad" Python > code throughout the book. Should I keep reading? > > Kiuhnm I have a simple experience which to me demonstrates python must be fairly readable. I gave a copy of a small utility to a friend of mine, whilst running it he found an obscure case that would cause a crash, he has only limited programming experience of any sort but from the python trace-back he was able to read my code & made a suggestion of what he thought would fix the issue, this suggestion was spot on. -- Necessity is a mother. From alex at moreati.org.uk Sun Mar 18 16:13:32 2012 From: alex at moreati.org.uk (Alex Willmer) Date: Sun, 18 Mar 2012 13:13:32 -0700 (PDT) Subject: Benchmarking stripping of Unicode characters which are invalid XML Message-ID: <11575952.4030.1332101612105.JavaMail.geo-discussion-forums@vbai14> Last week I was surprised to discover that there are Unicode characters that aren't valid in an XML document. That is regardless of escaping (e.g. �) and unicode encoding (e.g. UTF-8) - not every Unicode string can be stored in XML. The valid characters are (as of XML 1.0) #x9 | #xA | #xD | [#x20-#xD7FF] | [#xE000-#xFFFD] | [#x10000-#x10FFFF]. Others such as #x13 must be stripped, replaced or placed inside a wrapper such as base64. I didn't find an existing function to strip these so I wrote some and benchmarked them. I'd be interested for thoughts, suggestions and improvements. regsub_p2 was the fastest on a string containing mostly printable-ascii. regsub_p1 0.422097921371 True regsub_p2 0.353546857834 True regsub_p3 0.697242021561 True regsub_p4 0.677567005157 True genexp_p1 6.43633103371 True genexp_p2 6.43329787254 True genexp_p3 6.80837488174 True genexp_p4 6.81470417976 True filter_p1 7.21444416046 True filter_p2 7.46805095673 True filter_p3 7.37018704414 True filter_p4 7.03261303902 True genexp_f1 12.8470640182 True genexp_f2 5.43630099297 True genexp_f3 4.9708840847 True genexp_f4 12.2384109497 True genexp_f5 6.95861411095 True genexp_f6 4.7168610096 True genexp_f7 20.2065701485 True genexp_f8 21.1112251282 True Regards, Alex #!/usr/bin/python # Valid XML 1.0 characters are # #x9 | #xA | #xD | [#x20-#xD7FF] | [#xE000-#xFFFD] | [#x10000-#x10FFFF] # http://www.w3.org/TR/2008/PER-xml-20080205/#charsets # # Before passing an arbitrary unicode string to an XML encoder invalid characters # must be stripped or replaced. Escaping them doesn't help - they're simply not # allowed in a well formed XML 1.0 document. # The following script banchmarks several functions that strip them import re import string import timeit p1 = re.compile(u'[^\x09\x0A\x0D\u0020-\uD7FF' u'\uE000-\uFFFD\U00010000-\U0010FFFF]', re.U) p2 = re.compile(u'[^\u0020-\uD7FF\x09\x0A\x0D' u'\uE000-\uFFFD\U00010000-\U0010FFFF]', re.U) p3 = re.compile(p1.pattern + u'+', re.U) p4 = re.compile(p2.pattern + u'+', re.U) def regsub_p1(s): return p1.sub(u'', s) def regsub_p2(s): return p2.sub(u'', s) def regsub_p3(s): return p3.sub(u'', s) def regsub_p4(s): return p4.sub(u'', s) def genexp_p1(s): return u''.join(c for c in s if not p1.match(c)) def genexp_p2(s): return u''.join(c for c in s if not p2.match(c)) def genexp_p3(s): return u''.join(c for c in s if not p3.match(c)) def genexp_p4(s): return u''.join(c for c in s if not p4.match(c)) def filter_p1(s): return u''.join(filter(lambda c: not p1.match(c), s)) def filter_p2(s): return u''.join(filter(lambda c: not p2.match(c), s)) def filter_p3(s): return u''.join(filter(lambda c: not p3.match(c), s)) def filter_p4(s): return u''.join(filter(lambda c: not p4.match(c), s)) def f1(c): i = ord(c) return (i in set([0x09, 0x0A, 0x0D]) or 0x0020 <= i <= 0xD7FF or 0xE000 <= i <= 0xFFFD or 0x00010000 <= i <= 0x0010FFFF) def f2(c): i = ord(c) return (0x0020 <= i <= 0xD7FF or i in set([0x09, 0x0A, 0x0D]) or 0xE000 <= i <= 0xFFFD or 0x00010000 <= i <= 0x0010FFFF) def f3(c): return (u'\u0020' <= c <= u'\uD7FF' or c in set([u'\x09', u'\x0A', u'\x0D']) or u'\uE000' <= c <= u'\uFFFD' or u'\U00010000' <= c <= u'\U0010FFFF') def f4(c): return (c in set([u'\x09', u'\x0A', u'\x0D']) or u'\u0020' <= c <= u'\uD7FF' or u'\uE000' <= c <= u'\uFFFD' or u'\U00010000' <= c <= u'\U0010FFFF') def f5(c): return (c == u'\x09' or c == u'\x0A' or c == u'\x0D' or u'\u0020' <= c <= u'\uD7FF' or u'\uE000' <= c <= u'\uFFFD' or u'\U00010000' <= c <= u'\U0010FFFF') def f6(c): return (u'\u0020' <= c <= u'\uD7FF' or c == u'\x09' or c == u'\x0A' or c == u'\x0D' or u'\uE000' <= c <= u'\uFFFD' or u'\U00010000' <= c <= u'\U0010FFFF') every_8bit = u''.join(unichr(i) for i in range(256)) valid_8bit = u''.join(c for c in every_8bit if f1(c)) invalid_8bit = u''.join(c for c in every_8bit if not f1(c)) invalid_8bit_iso88591 = invalid_8bit.encode('iso-8859-1') translator = string.maketrans(invalid_8bit_iso88591, '\x00' * len(invalid_8bit_iso88591)) def f7(c): return ((c <= u'\xff' and ord(string.translate(c.encode('iso-8859-1'), translator))) or u'\uE000' <= c <= u'\uFFFD' or u'\U00010000' <= c <= u'\U0010FFFF') def f8(c): return ((c <= u'\xff' and string.translate(c.encode('iso-8859-1'), None, invalid_8bit_iso88591)) or u'\uE000' <= c <= u'\uFFFD' or u'\U00010000' <= c <= u'\U0010FFFF') def genexp_f1(s): return u''.join(c for c in s if f1(c)) def genexp_f2(s): return u''.join(c for c in s if f2(c)) def genexp_f3(s): return u''.join(c for c in s if f3(c)) def genexp_f4(s): return u''.join(c for c in s if f4(c)) def genexp_f5(s): return u''.join(c for c in s if f5(c)) def genexp_f6(s): return u''.join(c for c in s if f6(c)) def genexp_f7(s): return u''.join(c for c in s if f7(c)) def genexp_f8(s): return u''.join(c for c in s if f8(c)) if __name__ == '__main__': sample_in = u'''Lorem ipsum dolor sit amet\x00, consectetur adipisicing elit, \tsed \rdo eiusmod tempor incididunt \x13ut labore et dolore magna \xf7aliqua.\ufffe''' expected_out = u'''Lorem ipsum dolor sit amet, consectetur adipisicing elit, \tsed \rdo eiusmod tempor incididunt ut labore et dolore magna \xf7aliqua.''' for func, inner_fun in [(regsub_p1, p1), (regsub_p2, p2), (regsub_p3, p3), (regsub_p4, p4), (genexp_p1, p1), (genexp_p2, p2), (genexp_p3, p3), (genexp_p4, p4), (filter_p1, p1), (filter_p2, p2), (filter_p3, p3), (filter_p4, p4), (genexp_f1, f1), (genexp_f2, f2), (genexp_f3, f3), (genexp_f4, f4), (genexp_f5, f5), (genexp_f6, f6), (genexp_f7, f7), (genexp_f8, f8), ]: t = timeit.Timer(r'%s(%s)' % (func.__name__, repr(sample_in)), 'from __main__ import %s' % (func.__name__,)) print func.__name__, print min(t.repeat(3, 100000)), print func(sample_in) == expected_out, print From andrea.crotti.0 at gmail.com Sun Mar 18 16:55:04 2012 From: andrea.crotti.0 at gmail.com (Andrea Crotti) Date: Sun, 18 Mar 2012 20:55:04 +0000 Subject: Unittest2 on python 2.6 In-Reply-To: References: <4F65E3C6.2020405@gmail.com> Message-ID: <4F664BA8.8090800@gmail.com> On 03/18/2012 03:46 PM, Terry Reedy wrote: > 1. If the difference between unittest and unittest2 is strictly a > matter of deletions and addition, replace unittest with the union of > the two. > > 2. Put the try/except dance in a compat file. Then everywhere else > 'from compat import unittest'. This idea is one of those used to write > code that will run on both 2.x and 3.x > 1. I think that unittest2 is a simple superset of unittest, but unittest2 is a backport of unittest module in Python 2.7, that's the point, so I don't see how I should replace it with the union.. 2. good idea thanks From ladasky at my-deja.com Sun Mar 18 17:30:15 2012 From: ladasky at my-deja.com (John Ladasky) Date: Sun, 18 Mar 2012 14:30:15 -0700 (PDT) Subject: Python is readable References: <4f612b19$0$1379$4fafbaef@reader2.news.tin.it> <8e72d74f-c844-4de3-8a37-f6b1fdc2291f@y27g2000yqy.googlegroups.com> <50e9ceec-40f1-4ead-b2b6-87328b30d084@ow8g2000pbc.googlegroups.com> Message-ID: On Mar 14, 11:23?pm, alex23 wrote: > The idea that Python code has to be obvious to non-programmers is an > incorrect and dangerous one. Incorrect? Probably. Dangerous? You'll have to explain what you mean. What I would say is that, when PROGRAMMERS look at Python code for the first time, they will understand what it does more readily than they would understand other unfamiliar programming languages. That has value. From tjreedy at udel.edu Sun Mar 18 17:58:55 2012 From: tjreedy at udel.edu (Terry Reedy) Date: Sun, 18 Mar 2012 17:58:55 -0400 Subject: Unittest2 on python 2.6 In-Reply-To: <4F664BA8.8090800@gmail.com> References: <4F65E3C6.2020405@gmail.com> <4F664BA8.8090800@gmail.com> Message-ID: On 3/18/2012 4:55 PM, Andrea Crotti wrote: > On 03/18/2012 03:46 PM, Terry Reedy wrote: >> 1. If the difference between unittest and unittest2 is strictly a >> matter of deletions and addition, replace unittest with the union of >> the two. >> >> 2. Put the try/except dance in a compat file. Then everywhere else >> 'from compat import unittest'. This idea is one of those used to write >> code that will run on both 2.x and 3.x >> > > 1. I think that unittest2 is a simple superset of unittest, but > unittest2 is a backport of unittest module in Python 2.7, that's the point, > so I don't see how I should replace it with the union. If set A contains set B, then A is the union of the two. The danger of replacing unittest with unittest2 in a 2.6 installation is that 2.6 code that used the new features will not run in a 'normal' 2.6 installation. Whether that is a potential problem depends on whether you ever expect the code to escape from the altered environment. I said 'union' because I was not familiar with its details. I was allowing for the possibility that features were both deleted and added, in which case the union would include all features and work with multiple versions. That is moot for this case but not some others. > 2. good idea thanks The advantage of even one explicit unittest2 import, even if hidden away, is that you get a proper error message if you run the code where unittest2 is not present. -- Terry Jan Reedy From rosuav at gmail.com Sun Mar 18 18:02:06 2012 From: rosuav at gmail.com (Chris Angelico) Date: Mon, 19 Mar 2012 09:02:06 +1100 Subject: Python is readable In-Reply-To: References: <4f612b19$0$1379$4fafbaef@reader2.news.tin.it> <8e72d74f-c844-4de3-8a37-f6b1fdc2291f@y27g2000yqy.googlegroups.com> <50e9ceec-40f1-4ead-b2b6-87328b30d084@ow8g2000pbc.googlegroups.com> Message-ID: On Mon, Mar 19, 2012 at 8:30 AM, John Ladasky wrote: > What I would say is that, when PROGRAMMERS look at Python code for the > first time, they will understand what it does more readily than they > would understand other unfamiliar programming languages. ?That has > value. This is something that's never truly defined. Everyone talks of how this language or that language is readable, but if you mean that you can look at a line of code and know what *that line* does, then Python suffers badly and assembly language wins out; but if you mean that you should be able to glance over an entire function and comprehend its algorithm, then I have yet to see any language in which it's not plainly easy to write bad code. Even with good code, anything more than trivial can't be eyeballed in that way - if you could, what would docstrings be for? Really, the metric MUST be Python programmers. Intuitiveness is of value, but readability among experienced programmers is far more useful. If I write a whole lot of code today, and next year I'm dead and someone else has replaced me, I frankly don't mind if he has to learn the language before he can grok my code. I _do_ mind if, even after he's learned the language, he can't figure out what my code's doing; and that's where Python's placed itself at about the right level - not so high that it's all in airy-fairy conceptual work, but not so low that it gets bogged down. There's a handful of other languages that are similarly placed, and they're the languages that I would call "readable". Here's an analogy: One statement (aka line of code, etc) corresponds to one sentence in English. Massive one-liners are like some of the sentences in Paul's epistles; assembly language is like "The cat sat on the mat". Both are valid; both are hard to read. There, have fun tearing thaat to shreds :) ChrisA From bernhard.heijstek at yahoo.com Sun Mar 18 18:27:09 2012 From: bernhard.heijstek at yahoo.com (Bernhard Heijstek) Date: Mon, 19 Mar 2012 03:57:09 +0530 (IST) Subject: Problem with special characters in the password field (urllib) Message-ID: <1332109629.87336.YahooMailNeo@web137616.mail.in.yahoo.com> Hi, I'm having problems getting a script that I wrote to check the unread Gmail feed work (http://pastebin.com/FAGyedH0). The script fetches the unread mail feed (https://mail.google.com/mail/feed/atom/) and then parses it using python-feedparser. The script seems to work fine if I'm not using any special characters like !@#$%^&*() in the password. I tried some pretty basic debugging and saw that the execution stops beyond line 35 which is where the authentication happens. So I figured that this has got to do something with urrllib and special characters in the password field. I've also tried prefixing the string with 'r' without any success. Any help is appreciated. Cheers! Bernhard. From kiuhnm03.4t.yahoo.it Sun Mar 18 19:49:59 2012 From: kiuhnm03.4t.yahoo.it (Kiuhnm) Date: Mon, 19 Mar 2012 00:49:59 +0100 Subject: Currying in Python In-Reply-To: <4f63e724$0$1386$4fafbaef@reader1.news.tin.it> References: <4f63e724$0$1386$4fafbaef@reader1.news.tin.it> Message-ID: <4f6674aa$0$1385$4fafbaef@reader2.news.tin.it> On 3/17/2012 2:21, Kiuhnm wrote: > Here we go. I wrote an article about my approach to currying: http://mtomassoli.wordpress.com/2012/03/18/currying-in-python/ Beginners should be able to understand it as well. Experienced programmers will probably want to skip some sections. Kiuhnm From kiuhnm03.4t.yahoo.it Sun Mar 18 21:02:23 2012 From: kiuhnm03.4t.yahoo.it (Kiuhnm) Date: Mon, 19 Mar 2012 02:02:23 +0100 Subject: Programming D. E. Knuth in Python with the Deterministic Finite Automaton construct In-Reply-To: References: <4f64a3a0$0$1386$4fafbaef@reader2.news.tin.it> <4f64a9e5$0$1385$4fafbaef@reader2.news.tin.it> <4f64d00a$0$1390$4fafbaef@reader1.news.tin.it> Message-ID: <4f6685a2$0$1389$4fafbaef@reader2.news.tin.it> On 3/18/2012 0:28, Michael Torrie wrote: > I am familiar with how one > might implement a decompiler, as well as a compiler (having written a > simple one in the past), but even now I don't see a connection between a > decompiler and the process of converting a knuth algorithm into a python > python implementation. I was hoping you would shed some light on that. > But alas, I'm not really as much of an "interested reader" as you would > like me to be. Many ASM languages don't have structured control flow statements but only jmps, which are roughly equivalent to gotos. A good decompiler will need to analize the net of jmps and try to rewrite the code using structured control flow statements. The idea is to maximize readability, of course. >> Here's an example of rewriting: >> > > Thank you. Your example makes more clear your assertion about "labels" > and how really A1 and A5 were the only real labels in the example. > Though I still do not really see why "states" is not a good equivalence > for labels in this case. As well, Roy's idea for doing the state > machines, which works equally well as the nested if statements, is more > pythonic, which is generally preferred in Python. What I don't like about the entire issue is that (pseudo-)code shouldn't be cut and pasted or blindly ported to another language. Python is a very expressive language. I don't think you like it when someone writes C code in Python. Now we're writing ASM code in Python! If you want to emulate a DFA, do it, but if you want to implement an algorithm whose pseudo-code happens to use labels and gotos, please use higher-level control flow statements (unless you're pressed on time and you need it done yesterday, of course). Regarding labels and state, I simply meant that they're completely different things, in fact this program has two labels but infinitely many states: A1: cur = cur + 1 A2: goto A1 I was being pedantic, to say it your way ;) Kiuhnm From steve+comp.lang.python at pearwood.info Sun Mar 18 21:23:42 2012 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 19 Mar 2012 01:23:42 GMT Subject: Python is readable References: <4f612b19$0$1379$4fafbaef@reader2.news.tin.it> <8e72d74f-c844-4de3-8a37-f6b1fdc2291f@y27g2000yqy.googlegroups.com> <50e9ceec-40f1-4ead-b2b6-87328b30d084@ow8g2000pbc.googlegroups.com> Message-ID: <4f668a9d$0$29981$c3e8da3$5496439d@news.astraweb.com> On Mon, 19 Mar 2012 09:02:06 +1100, Chris Angelico wrote: > On Mon, Mar 19, 2012 at 8:30 AM, John Ladasky > wrote: >> What I would say is that, when PROGRAMMERS look at Python code for the >> first time, they will understand what it does more readily than they >> would understand other unfamiliar programming languages. ?That has >> value. > > This is something that's never truly defined. I'm sorry, I don't understand what part of John's sentence you mean by "this". "Programmers"? "Value"? "Understand"? > Everyone talks of how this > language or that language is readable, but if you mean that you can look > at a line of code and know what *that line* does then Python suffers > badly and assembly language wins out; This is at least the second time you've alleged that assembly language is more readable than Python. I think you're a raving nutter, no offence Chris :-) Assignment (name binding) is close to the absolute simplest thing you can do in a programming language. In Python, the syntax is intuitive to anyone who has gone through high school, or possibly even primary school, and been introduced to the equals sign. x = 1234 y = "Hello" In assembly language, not so much. I wouldn't even have begun to guess how to assign variables in assembly, or even whether such a thing is possible, but a few minutes of googling gave me this: # 8086 assembly x dw 1234 y db 'Hello', 0 # MIPS assembly x: .word 1234 y: .asciiz "Hello" I don't know about anyone else, but I wouldn't have guessed that the way to get x=1234 was with "x dw 1234". What's more, with Python, one example hints on how to do other examples. Having seen x=1234, most people would guess that x=1.234 would also work. I'm pretty sure that "x dw 1.234" will do something surprising, although I don't know what, but it certainly won't be to assign the float 1.234 to a variable x. So there we have another measure of "readability" -- discoverability. Having seen one example, how easy is it to predict slightly modified examples? In assembly's case, not very predictable. What's the difference between these two lines? a db 127 b db 327 For that matter, what will the second line actually do? The thing is, these aren't "advanced features" of assembly language. It's not like trying to understand metaclasses in Python. These are the basic foundations. You can read vast swathes of simple Python code without needing to learn the gory details of Python's data model (name binding of objects, everything is an object), but you can't even *begin* reading assembly language without a good grasp of the data model and jargon. Assembly has a very steep learning curve. Python has a shallow curve. Here's another indication of readability. There have been occasional suggestions on Wikipedia that they standardize on Python as "executable pseudo-code" for code samples. Now replace "Python" with assembly language. Unless you're Donald Knuth, the idea is ridiculous. Another factor related to readability is the primitiveness of the toolset. Assembly has a very low-level, primitive toolset. How would you write this in assembly? print(sorted(somelist)) If all you have is a hammer, the instructions you get are easy to understand because there's not much you can do with it. How complicated can "hit the nail with the hammer" get? But the right measure is not the simplicity of the tasks you *can* do, but the comprehensibility of the tasks you *want* to do. "How do I build a tree house using nothing but a hammer?" I'm sure that, given sufficient ingenuity, you could build a tree house with nothing but a hammer, lumber and nails, but the detailed instructions would be complicated and difficult. How much simpler it becomes with a more powerful set of tools. Assembly is simple, like a hammer. (Well, perhaps not *quite* as simple as a hammer.) > but if you mean that you should be > able to glance over an entire function and comprehend its algorithm, > then I have yet to see any language in which it's not plainly easy to > write bad code. Even with good code, anything more than trivial can't be > eyeballed in that way - if you could, what would docstrings be for? The measure of the readability of a language should not be obfuscated or badly written code, but good, idiomatic code written by an experienced practitioner in the art. Note that there is a deliberate asymmetry there: when judging "readability" (comprehensibility), we take idiomatic code written by somebody who knows the language well, and give it to a novice to interpret it. On this measure, Python has actually become *less* readable in recent years, with the addition of powerful new idioms such as generators, list comprehensions, with statement, etc. They are very expressive, and Python is much better off with them, but they are less readable in the sense I am talking about: readable to somebody who is not an expert in the language. For this reason, when dealing with beginners, or writing code intended as "executable pseudo-code", I try to stick with features that worked in Python 1.5 where possible. E.g. for-loops rather than list comprehensions. > Really, the metric MUST be Python programmers. Intuitiveness is of > value, but readability among experienced programmers is far more useful. But by that metric, Brainf*** is readable, since an experienced expert in the art of writing BF code will be able to recognise BF idioms and interpret them correctly. No, I'm sorry, I disagree that the standard of readability should be the experienced programmer. By that standard, "readability" is a no-op. All languages are, more or less, equally readable, to those who can read them well. I don't think it is useful to judge the readability of Forth on the ability of Charles Moore to read it. How does that help me decide whether to use Forth for my next project? > If I write a whole lot of code today, and next year I'm dead and someone > else has replaced me, I frankly don't mind if he has to learn the > language before he can grok my code. I _do_ mind if, even after he's > learned the language, he can't figure out what my code's doing; Then he hasn't learned the language *sufficiently well*. Either that, or your code is obfuscated, unidiomatic crap. Perhaps you're trying to write BF in Python :) -- Steven From benjamin at python.org Sun Mar 18 21:43:56 2012 From: benjamin at python.org (Benjamin Peterson) Date: Sun, 18 Mar 2012 20:43:56 -0500 Subject: [RELEASED] Second release candidates for Python 2.6.8, 2.7.3, 3.1.5, and 3.2.3 Message-ID: We're chuffed to announce the immediate availability of the second release candidates for Python 2.6.8, 2.7.3, 3.1.5, and 3.2.3. The only change from the first release candidates is the patching of an additional security hole. The security issue fixed in the second release candidates is in the expat XML parsing library. expat had the same hash security issue detailed below as Python's core types. The hashing algorithm used in the expat library is now randomized. A more thorough explanation of the "hash attack" security hole follows. The main impetus for these releases is fixing a security issue in Python's hash based types, dict and set, as described below. Python 2.7.3 and 3.2.3 include the security patch and the normal set of bug fixes. Since Python 2.6 and 3.1 are maintained only for security issues, 2.6.8 and 3.1.5 contain only various security patches. The security issue exploits Python's dict and set implementations. Carefully crafted input can lead to extremely long computation times and denials of service. [1] Python dict and set types use hash tables to provide amortized constant time operations. Hash tables require a well-distributed hash function to spread data evenly across the hash table. The security issue is that an attacker could compute thousands of keys with colliding hashes; this causes quadratic algorithmic complexity when the hash table is constructed. To alleviate the problem, the new releases add randomization to the hashing of Python's string types (bytes/str in Python 3 and str/unicode in Python 2), datetime.date, and datetime.datetime. This prevents an attacker from computing colliding keys of these types without access to the Python process. Hash randomization causes the iteration order of dicts and sets to be unpredictable and differ across Python runs. Python has never guaranteed iteration order of keys in a dict or set, and applications are advised to never rely on it. Historically, dict iteration order has not changed very often across releases and has always remained consistent between successive executions of Python. Thus, some existing applications may be relying on dict or set ordering. Because of this and the fact that many Python applications which don't accept untrusted input are not vulnerable to this attack, in all stable Python releases mentioned here, HASH RANDOMIZATION IS DISABLED BY DEFAULT. There are two ways to enable it. The -R commandline option can be passed to the python executable. It can also be enabled by setting an environmental variable PYTHONHASHSEED to "random". (Other values are accepted, too; pass -h to python for complete description.) More details about the issue and the patch can be found in the oCERT advisory [1] and the Python bug tracker [2]. These releases are releases candidates and thus not recommended for production use. Please test your applications and libraries with them, and report any bugs you encounter. We are especially interested in any buggy behavior observed using hash randomization. Excepting major calamity, final versions should appear after several weeks. Downloads are at http://python.org/download/releases/2.6.8/ http://python.org/download/releases/2.7.3/ http://python.org/download/releases/3.1.5/ http://python.org/download/releases/3.2.3/ Please test these candidates and report bugs to http://bugs.python.org/ With regards, The Python release team Barry Warsaw (2.6), Georg Brandl (3.2), Benjamin Peterson (2.7 and 3.1) [1] http://www.ocert.org/advisories/ocert-2011-003.html [2] http://bugs.python.org/issue13703 From wuwei23 at gmail.com Sun Mar 18 23:15:56 2012 From: wuwei23 at gmail.com (alex23) Date: Sun, 18 Mar 2012 20:15:56 -0700 (PDT) Subject: Python is readable References: <4f612b19$0$1379$4fafbaef@reader2.news.tin.it> <8e72d74f-c844-4de3-8a37-f6b1fdc2291f@y27g2000yqy.googlegroups.com> <50e9ceec-40f1-4ead-b2b6-87328b30d084@ow8g2000pbc.googlegroups.com> Message-ID: <3904be71-335e-43a9-9e82-024abb1729b5@ni10g2000pbc.googlegroups.com> John Ladasky wrote: > > The idea that Python code has to be obvious to non-programmers is an > > incorrect and dangerous one. > > Incorrect? ?Probably. ?Dangerous? ?You'll have to explain what you > mean. The classic "obvious" behaviour to new Python programmers that causes problems would be mutable default arguments. At this point you have two options: improve the "readability" to new users so their expectations are met, or ask them to modify those expectations and understand what's really happening under the surface. As it stands, you tend to hit this problem pretty early on, learn about it, and walk away with a deeper knowledge of Python's mechanics. The danger, I feel, is that changing it to better fit the mind-set that non-Python programmers bring with them could mask that necessary understanding for longer. From clp2 at rebertia.com Mon Mar 19 00:14:27 2012 From: clp2 at rebertia.com (Chris Rebert) Date: Sun, 18 Mar 2012 21:14:27 -0700 Subject: Python is readable In-Reply-To: <3904be71-335e-43a9-9e82-024abb1729b5@ni10g2000pbc.googlegroups.com> References: <4f612b19$0$1379$4fafbaef@reader2.news.tin.it> <8e72d74f-c844-4de3-8a37-f6b1fdc2291f@y27g2000yqy.googlegroups.com> <50e9ceec-40f1-4ead-b2b6-87328b30d084@ow8g2000pbc.googlegroups.com> <3904be71-335e-43a9-9e82-024abb1729b5@ni10g2000pbc.googlegroups.com> Message-ID: On Sun, Mar 18, 2012 at 8:15 PM, alex23 wrote: > John Ladasky wrote: >> > The idea that Python code has to be obvious to non-programmers is an >> > incorrect and dangerous one. >> >> Incorrect? ?Probably. ?Dangerous? ?You'll have to explain what you >> mean. > > The classic "obvious" behaviour to new Python programmers that causes > problems would be mutable default arguments. At this point you have > two options: improve the "readability" to new users so their > expectations are met, or ask them to modify those expectations and > understand what's really happening under the surface. As it stands, > you tend to hit this problem pretty early on, learn about it, and walk > away with a deeper knowledge of Python's mechanics. The mechanics of default arguments maybe, but that's tautological. If you mean call-by-object, any time you pass both mutable and immutable things around, you will learn the same lesson. If you mean the more general principle that "Python doesn't ever copy things unless you explicitly ask", working with lists (and particularly their multiplication operator) again tends to also teach that lesson. > The danger, I > feel, is that changing it to better fit the mind-set that non-Python > programmers bring with them could mask that necessary understanding > for longer. I disagree. Just add a keyword for each default argument evaluation behavior (evaluate-once-at-definition-time [e.g. "once", "static"] and evaluate-at-call-time [e.g. "fresh"]) and don't have there be a default behavior; make the choice explicit. They'll be confronted with the issue as soon as they're shown default arguments, and keywords are easy to look up the meaning of. And as I said previously, there are other common ways to learn any of the "lessons" that default arguments might "teach". If-I-had-my-druthers-ly yours, Chris (R.) From rosuav at gmail.com Mon Mar 19 00:33:51 2012 From: rosuav at gmail.com (Chris Angelico) Date: Mon, 19 Mar 2012 15:33:51 +1100 Subject: Python is readable In-Reply-To: <4f668a9d$0$29981$c3e8da3$5496439d@news.astraweb.com> References: <4f612b19$0$1379$4fafbaef@reader2.news.tin.it> <8e72d74f-c844-4de3-8a37-f6b1fdc2291f@y27g2000yqy.googlegroups.com> <50e9ceec-40f1-4ead-b2b6-87328b30d084@ow8g2000pbc.googlegroups.com> <4f668a9d$0$29981$c3e8da3$5496439d@news.astraweb.com> Message-ID: On Mon, Mar 19, 2012 at 12:23 PM, Steven D'Aprano wrote: > On Mon, 19 Mar 2012 09:02:06 +1100, Chris Angelico wrote: > >> On Mon, Mar 19, 2012 at 8:30 AM, John Ladasky >> wrote: >>> What I would say is that, when PROGRAMMERS look at Python code for the >>> first time, they will understand what it does more readily than they >>> would understand other unfamiliar programming languages. ?That has >>> value. >> >> This is something that's never truly defined. > > I'm sorry, I don't understand what part of John's sentence you mean by > "this". "Programmers"? "Value"? "Understand"? I should have rewritten that into the next paragraph. Anyhow. Further explanation below. >> Everyone talks of how this >> language or that language is readable, but if you mean that you can look >> at a line of code and know what *that line* does then Python suffers >> badly and assembly language wins out; > > This is at least the second time you've alleged that assembly language is > more readable than Python. I think you're a raving nutter, no offence > Chris :-) None taken; guilty as charged. And unashamedly so. With that dealt with, though: My calling assembly "readable" is a form of argument by drawing to logical, but absurd, conclusion - by the given definition of readability, assembly is readable, ergo the definition sucks. (That's a term all logicians use, you know. Proper and formal jargon.) > Assignment (name binding) is close to the absolute simplest thing you can > do in a programming language. In Python, the syntax is intuitive to > anyone who has gone through high school, or possibly even primary school, > and been introduced to the equals sign. > > x = 1234 > y = "Hello" Not quite. In mathematics, "x = 1234" is either a declaration of fact, or a statement that can be either true or false. In mathematics, "x = x + 1" is absurd and/or simply false. That's why Pascal has its := operator, supposed to be read as "becomes" and not "equals". IMHO this is simply proof of one of the differences between programming and mathematics. > I don't know about anyone else, but I wouldn't have guessed that the way > to get x=1234 was with "x dw 1234". Except that it's not quite the same thing. That 8086 Assembly statement is more like the C statement: int x=1234; The nearest equivalent of assignment is: mov x,1234 although that differs slightly from assembler to assembler (NASM, if I recall correctly, calls for "mov [x],1234"). You're right, though, that it's nothing like as clear. > What's more, with Python, one example hints on how to do other examples. > Having seen x=1234, most people would guess that x=1.234 would also work. Yes, which brings up the old favorite arguments about whether computers work with integers, floats, rationals, Real Numbers, or Numbers. But, that aside... > I'm pretty sure that "x dw 1.234" will do something surprising, although > I don't know what, but it certainly won't be to assign the float 1.234 to > a variable x. Perhaps not usefully, but "x dd 1.234" ought to work. You just can't fit a float into a dw. (NASM does support "half precision", but most operations want a doubleword for a float.) Assembly language requires variable sizes to be declared. Of course, what it *really* does is declare a doubleword-sized patch of memory, initializes it to the IEEE representation of the nearest possible float to the real number 1.234, and assigns the label 'x' to point to the lowest memory address used by that doubleword... but mostly you don't need to care about that. > So there we have another measure of "readability" -- discoverability. > Having seen one example, how easy is it to predict slightly modified > examples? > > In assembly's case, not very predictable. What's the difference between > these two lines? > > a db 127 > b db 327 > > For that matter, what will the second line actually do? I'm not 100% sure, but since assembly is much stricter than most HLLs with data sizes, it's a concern that you don't have with Python's long ints. But the same thing can come up in a HLL - struct.pack("i") can't handle a long int, because, like an assembler, it's concerned about exact byte sizes. > Assembly has a very steep learning curve. Python has a shallow curve. Of course. But computer programming generally has a fairly stiff learning curve; you have to get your head around all sorts of concepts that simply do not exist anywhere else. > Here's another indication of readability. There have been occasional > suggestions on Wikipedia that they standardize on Python as "executable > pseudo-code" for code samples. Now replace "Python" with assembly > language. Unless you're Donald Knuth, the idea is ridiculous. I am not, and it is. But I could make you a set of NASM macros that allow you to write assembly code that looks like pseudo-code. Does that make assembly code readable? Maybe. Does it make it worth using as a HLL? No. > If all you have is a hammer, the instructions you get are easy to > understand because there's not much you can do with it. How complicated > can "hit the nail with the hammer" get? But the right measure is not the > simplicity of the tasks you *can* do, but the comprehensibility of the > tasks you *want* to do. Right, which is why NO language can be described as "readable" or "easy to work with" unless you define a problem domain. SQL is an excellent language... as long as you want to query a relational database. > The measure of the readability of a language should not be obfuscated or > badly written code, but good, idiomatic code written by an experienced > practitioner in the art. Note that there is a deliberate asymmetry there: > when judging "readability" (comprehensibility), we take idiomatic code > written by somebody who knows the language well, and give it to a novice > to interpret it. Sure. You can write bad code in any language, and that doesn't mean anything. But still, if you're writing for a novice, you write quite different code from what you'd write normally. Language tutorials are written by experts for novices; language tutorials do not look like the language's own standard library (assuming it has one written in itself). >> Really, the metric MUST be Python programmers. Intuitiveness is of >> value, but readability among experienced programmers is far more useful. > > But by that metric, Brainf*** is readable, since an experienced expert in > the art of writing BF code will be able to recognise BF idioms and > interpret them correctly. Not really. The BF code to do one simple high level operation could easily span several pages. You can't "recognize" those. Now, BF with macros/subroutines might be more plausible - if you could define a new opcode that represents some huge slab of BF code and use that - but in its native form, I don't think anyone could recognize what BF is doing. > No, I'm sorry, I disagree that the standard of readability should be the > experienced programmer. By that standard, "readability" is a no-op. All > languages are, more or less, equally readable, to those who can read them > well. I don't think it is useful to judge the readability of Forth on the > ability of Charles Moore to read it. How does that help me decide whether > to use Forth for my next project? > >> If I write a whole lot of code today, and next year I'm dead and someone >> else has replaced me, I frankly don't mind if he has to learn the >> language before he can grok my code. I _do_ mind if, even after he's >> learned the language, he can't figure out what my code's doing; > > Then he hasn't learned the language *sufficiently well*. Either that, or > your code is obfuscated, unidiomatic crap. Perhaps you're trying to write > BF in Python :) And that's where the nub of the question is. How well is sufficiently well? Clearly you do not require your code to be comprehensible to a non-programmer, or you would not write code at all. If you don't demand that the reader learn basic keywords of the language, then it's equally impossible to expect them to comprehend your code. If you're writing production code, I see no reason to avoid language features like Python's list comps, Pike's %{ %} sprintf codes, or C's pointer arithmetic, just because they can confuse people. Learn the language, THEN start hacking on the code. ChrisA From anntzer.lee at gmail.com Mon Mar 19 01:11:13 2012 From: anntzer.lee at gmail.com (anntzer.lee at gmail.com) Date: Sun, 18 Mar 2012 22:11:13 -0700 (PDT) Subject: ANN: cmd2, an extenstion of cmd that parses its argument line Message-ID: <20285780.118.1332133873462.JavaMail.geo-discussion-forums@pbcwe9> Dear all, I would like to announce the first public release of cmd2, an extension of the standard library's cmd with argument parsing, here: https://github.com/anntzer/cmd2. Cmd2 is an extension built around the excellent cmd module of the standard library. Cmd allows one to build simple custom shells using ``do_*`` methods, taking care in particular of the REPL loop and the interactive help. However, no facility is given for parsing the argument line (do_* methods are passed the rest of the line as a single string argument). With Cmd2, ``do_*`` methods are type-annotated, either using Python 3's function annotation syntax, or with an ad-hoc ``annotate`` decorator, allowing the dispatcher to parse the argument list for them. Antony Lee From xianming.yan at gmail.com Mon Mar 19 02:30:09 2012 From: xianming.yan at gmail.com (yan xianming) Date: Sun, 18 Mar 2012 23:30:09 -0700 (PDT) Subject: New learner of Python--any suggestion on studying it? Message-ID: Hello all, I'm a new learning of Python. Can someone give me some suggestion about it? thanks xianming From clp2 at rebertia.com Mon Mar 19 02:58:38 2012 From: clp2 at rebertia.com (Chris Rebert) Date: Sun, 18 Mar 2012 23:58:38 -0700 Subject: New learner of Python--any suggestion on studying it? In-Reply-To: References: Message-ID: On Sun, Mar 18, 2012 at 11:30 PM, yan xianming wrote: > Hello all, > > I'm a new learning of Python. > > Can someone give me some suggestion about it? http://docs.python.org/tutorial/index.html http://wiki.python.org/moin/BeginnersGuide/NonProgrammers http://wiki.python.org/moin/BeginnersGuide/Programmers http://www.quora.com/How-can-I-learn-to-program-in-Python Cheers, Chris From mining.facts at googlemail.com Mon Mar 19 03:26:25 2012 From: mining.facts at googlemail.com (Christian) Date: Mon, 19 Mar 2012 00:26:25 -0700 (PDT) Subject: filter max from iterable for grouped element Message-ID: <0184870c-e30a-4865-aa24-c6cb9a661aed@gr6g2000vbb.googlegroups.com> Hi, as beginner in python , I struggle somewhat to filter out only the maximum in the values for and get hmax. Maybe it easier when i change the structure of h? Many thanks in advance Christian h = {'abvjv': ('asyak', 0.9014230420411024), 'afqes': ('jarbm', 0.9327883839839753), 'aikdj': ('jarbm', 0.9503941616408824), 'ajbhn': ('jarbm', 0.9323583083061541), 'ajrje': ('jbhdj', 0.9825125732711598), 'anbrw': ('jarbm', 0.950801828672098)} hmax = {'abvjv': ('asyak', 0.9014230420411024), 'ajrje': ('jbhdj', 0.9825125732711598), 'anbrw': ('jarbm', 0.950801828672098)} From antti.ylikoski at tkk.fi Mon Mar 19 03:46:22 2012 From: antti.ylikoski at tkk.fi (Antti J Ylikoski) Date: Mon, 19 Mar 2012 09:46:22 +0200 Subject: New learner of Python--any suggestion on studying it? In-Reply-To: References: Message-ID: On 19.3.2012 8:30, yan xianming wrote: > Hello all, > > I'm a new learning of Python. > > > > Can someone give me some suggestion about it? > > thanks > xianming The best textbooks on Python that I have come across are: Learning Python by Mark Lutz, O'Reilly, http://oreilly.com, ISBN 978-0-596-15806-4 Programming Python by Mark Lutz, O'Reilly, http://oreilly.com, ISBN 978-0-596-15810-1 regards, Antti "Andy" Ylikoski Helsinki, Finland, the EU From gandalf at shopzeus.com Mon Mar 19 03:55:51 2012 From: gandalf at shopzeus.com (Laszlo Nagy) Date: Mon, 19 Mar 2012 08:55:51 +0100 Subject: urllib.urlretrieve never returns??? In-Reply-To: References: <4F649BFC.1080601@shopzeus.com> Message-ID: <4F66E687.2050008@shopzeus.com> On 2012-03-17 19:18, Christian Heimes wrote: > Am 17.03.2012 15:13, schrieb Laszlo Nagy: >> See attached example code. I have a program that calls exactly the same >> code, and here is the strange thing about it: >> >> * Program is started as "start.py", e.g. with an open console. In this >> case, the program works! >> * Program is started as "start.pyw", e.g. with no open console under >> Windows 7 64bit - the program does not work! > The pythonw.exe may not have the rights to access network resources. > Have you set a default timeout for sockets? > > import socket > socket.setdefaulttimeout(10) # 10 seconds > > A pyw Python doesn't have stdout, stderr or stdin. Any attempt to write > to them (e.g. print statement, default exception logger) can cause an > exception. Yes, that is why I started the app with wx.PySimpleApp(redirect=True) so stdout is redirected into a window. Unfortunately, nothing is logged. I'm going to turn off the firewall and start as admin today. That might be the solution. Thanks! From jeanpierreda at gmail.com Mon Mar 19 04:00:06 2012 From: jeanpierreda at gmail.com (Devin Jeanpierre) Date: Mon, 19 Mar 2012 04:00:06 -0400 Subject: ANN: cmd2, an extenstion of cmd that parses its argument line In-Reply-To: <20285780.118.1332133873462.JavaMail.geo-discussion-forums@pbcwe9> References: <20285780.118.1332133873462.JavaMail.geo-discussion-forums@pbcwe9> Message-ID: There already is a module named cmd2: http://pypi.python.org/pypi/cmd2 -- Devin On Mon, Mar 19, 2012 at 1:11 AM, wrote: > Dear all, > > I would like to announce the first public release of cmd2, an extension of > the standard library's cmd with argument parsing, here: > https://github.com/anntzer/cmd2. > > Cmd2 is an extension built around the excellent cmd module of the standard > library. Cmd allows one to build simple custom shells using ``do_*`` > methods, > taking care in particular of the REPL loop and the interactive help. > However, > no facility is given for parsing the argument line (do_* methods are > passed the > rest of the line as a single string argument). > > With Cmd2, ``do_*`` methods are type-annotated, either using Python 3's > function annotation syntax, or with an ad-hoc ``annotate`` decorator, > allowing > the dispatcher to parse the argument list for them. > > Antony Lee > -- > http://mail.python.org/mailman/listinfo/python-list > -------------- next part -------------- An HTML attachment was scrubbed... URL: From __peter__ at web.de Mon Mar 19 04:45:54 2012 From: __peter__ at web.de (Peter Otten) Date: Mon, 19 Mar 2012 09:45:54 +0100 Subject: filter max from iterable for grouped element References: <0184870c-e30a-4865-aa24-c6cb9a661aed@gr6g2000vbb.googlegroups.com> Message-ID: Christian wrote: > as beginner in python , I struggle somewhat to filter out only the > maximum in the values for and get hmax. > h = {'abvjv': ('asyak', 0.9014230420411024), > 'afqes': ('jarbm', 0.9327883839839753), > 'aikdj': ('jarbm', 0.9503941616408824), > 'ajbhn': ('jarbm', 0.9323583083061541), > 'ajrje': ('jbhdj', 0.9825125732711598), > 'anbrw': ('jarbm', 0.950801828672098)} > > > hmax = {'abvjv': ('asyak', 0.9014230420411024), > 'ajrje': ('jbhdj', 0.9825125732711598), > 'anbrw': ('jarbm', 0.950801828672098)} You can create an intermediate dict: >>> d = {} >>> for k, (k2, v) in h.items(): ... d.setdefault(k2, []).append((v, k)) ... >>> import pprint >>> pprint.pprint(d) {'asyak': [(0.9014230420411024, 'abvjv')], 'jarbm': [(0.9323583083061541, 'ajbhn'), (0.950801828672098, 'anbrw'), (0.9327883839839753, 'afqes'), (0.9503941616408824, 'aikdj')], 'jbhdj': [(0.9825125732711598, 'ajrje')]} Now find the maximum values: >>> for k, pairs in d.items(): ... v, k2 = max(pairs) ... assert k2 not in hmax ... hmax[k2] = k, v ... >>> pprint.pprint(hmax) {'abvjv': ('asyak', 0.9014230420411024), 'ajrje': ('jbhdj', 0.9825125732711598), 'anbrw': ('jarbm', 0.950801828672098)} > Maybe it easier when i change the structure of h? Maybe. Here's one option: >>> pprint.pprint(data) [('jarbm', 0.9323583083061541, 'ajbhn'), ('jarbm', 0.950801828672098, 'anbrw'), ('jarbm', 0.9327883839839753, 'afqes'), ('asyak', 0.9014230420411024, 'abvjv'), ('jbhdj', 0.9825125732711598, 'ajrje'), ('jarbm', 0.9503941616408824, 'aikdj')] >>> data.sort() >>> from itertools import groupby >>> def last(items): ... for item in items: pass ... return item ... >>> dmax = [last(group) for key, group in groupby(data, key=lambda item: item[0])] >>> pprint.pprint(dmax) [('asyak', 0.9014230420411024, 'abvjv'), ('jarbm', 0.950801828672098, 'anbrw'), ('jbhdj', 0.9825125732711598, 'ajrje')] From mining.facts at googlemail.com Mon Mar 19 05:29:57 2012 From: mining.facts at googlemail.com (Christian) Date: Mon, 19 Mar 2012 02:29:57 -0700 (PDT) Subject: filter max from iterable for grouped element References: <0184870c-e30a-4865-aa24-c6cb9a661aed@gr6g2000vbb.googlegroups.com> Message-ID: <08542ab5-feb5-476c-827b-f7eb73cef4e9@v22g2000vby.googlegroups.com> On 19 Mrz., 09:45, Peter Otten <__pete... at web.de> wrote: > Christian wrote: > > as beginner in python , I struggle ?somewhat to filter out only the > > maximum in the values for ?and get hmax. > > h = {'abvjv': ('asyak', 0.9014230420411024), > > ?'afqes': ('jarbm', 0.9327883839839753), > > ?'aikdj': ('jarbm', 0.9503941616408824), > > ?'ajbhn': ('jarbm', 0.9323583083061541), > > ?'ajrje': ('jbhdj', 0.9825125732711598), > > ?'anbrw': ('jarbm', 0.950801828672098)} > > > hmax = {'abvjv': ('asyak', 0.9014230420411024), > > ?'ajrje': ('jbhdj', 0.9825125732711598), > > ?'anbrw': ('jarbm', 0.950801828672098)} > > You can create an intermediate dict: > > >>> d = {} > >>> for k, (k2, v) in h.items(): > > ... ? ? d.setdefault(k2, []).append((v, k)) > ...>>> import pprint > >>> pprint.pprint(d) > > {'asyak': [(0.9014230420411024, 'abvjv')], > ?'jarbm': [(0.9323583083061541, 'ajbhn'), > ? ? ? ? ? ?(0.950801828672098, 'anbrw'), > ? ? ? ? ? ?(0.9327883839839753, 'afqes'), > ? ? ? ? ? ?(0.9503941616408824, 'aikdj')], > ?'jbhdj': [(0.9825125732711598, 'ajrje')]} > > Now find the maximum values: > > >>> for k, pairs in d.items(): > > ... ? ? v, k2 = max(pairs) > ... ? ? assert k2 not in hmax > ... ? ? hmax[k2] = k, v > ...>>> pprint.pprint(hmax) > > {'abvjv': ('asyak', 0.9014230420411024), > ?'ajrje': ('jbhdj', 0.9825125732711598), > ?'anbrw': ('jarbm', 0.950801828672098)} > > > Maybe it easier when i change the structure of h? > > Maybe. Here's one option: > > >>> pprint.pprint(data) > > [('jarbm', 0.9323583083061541, 'ajbhn'), > ?('jarbm', 0.950801828672098, 'anbrw'), > ?('jarbm', 0.9327883839839753, 'afqes'), > ?('asyak', 0.9014230420411024, 'abvjv'), > ?('jbhdj', 0.9825125732711598, 'ajrje'), > ?('jarbm', 0.9503941616408824, 'aikdj')]>>> data.sort() > >>> from itertools import groupby > >>> def last(items): > > ... ? ? for item in items: pass > ... ? ? return item > ...>>> dmax = [last(group) for key, group in groupby(data, key=lambda item: > item[0])] > >>> pprint.pprint(dmax) > > [('asyak', 0.9014230420411024, 'abvjv'), > ?('jarbm', 0.950801828672098, 'anbrw'), > ?('jbhdj', 0.9825125732711598, 'ajrje')] Thanks a lot. From kiuhnm03.4t.yahoo.it Mon Mar 19 06:24:40 2012 From: kiuhnm03.4t.yahoo.it (Kiuhnm) Date: Mon, 19 Mar 2012 11:24:40 +0100 Subject: Programming D. E. Knuth in Python with the Deterministic Finite Automaton construct In-Reply-To: References: <4f64a3a0$0$1386$4fafbaef@reader2.news.tin.it> <4f64a9e5$0$1385$4fafbaef@reader2.news.tin.it> <4f64d00a$0$1390$4fafbaef@reader1.news.tin.it> <4f6685a2$0$1389$4fafbaef@reader2.news.tin.it> Message-ID: <4f670968$0$1379$4fafbaef@reader2.news.tin.it> On 3/19/2012 6:02, Dennis Lee Bieber wrote: > On Mon, 19 Mar 2012 02:02:23 +0100, Kiuhnm > declaimed the following in > gmane.comp.python.general: > >> >> Many ASM languages don't have structured control flow statements but >> only jmps, which are roughly equivalent to gotos. A good decompiler will >> need to analize the net of jmps and try to rewrite the code using >> structured control flow statements. >> The idea is to maximize readability, of course. >> > Never met Sigma's Meta-Symbol > > Okay, the machine level code was limited to basic condition/jump... > But a master of Meta-Symbol (I wasn't such -- not in a trimester college > course) could create macros that would make it structured. You can do that in MASM (and others) as well. Kiuhnm From kiuhnm03.4t.yahoo.it Mon Mar 19 07:15:07 2012 From: kiuhnm03.4t.yahoo.it (Kiuhnm) Date: Mon, 19 Mar 2012 12:15:07 +0100 Subject: Python is readable In-Reply-To: References: <4f612b19$0$1379$4fafbaef@reader2.news.tin.it> <8e72d74f-c844-4de3-8a37-f6b1fdc2291f@y27g2000yqy.googlegroups.com> <50e9ceec-40f1-4ead-b2b6-87328b30d084@ow8g2000pbc.googlegroups.com> <4f61c828$0$1390$4fafbaef@reader2.news.tin.it> <4f61d728$0$1375$4fafbaef@reader2.news.tin.it> <4f61fd0a$0$1389$4fafbaef@reader2.news.tin.it> <4f620837$0$1382$4fafbaef@reader2.news.tin.it> <4f627c25$0$1381$4fafbaef@reader2.news.tin.it> <4f62b9be$0$29981$c3e8da3$5496439d@news.astraweb.com> <4f632da5$0$1375$4fafbaef@reader1.news.tin.it> <4f636ed5$0$29981$c3e8da3$5496439d@news.astraweb.com> <4f64ed2e$0$1389$4fafbaef@reader1.news.tin.it> <4f650213$0$1375$4fafbaef@reader1.news.tin.it> Message-ID: <4f67153b$0$1383$4fafbaef@reader2.news.tin.it> On 3/18/2012 0:04, Michael Torrie wrote: > On 03/17/2012 03:28 PM, Kiuhnm wrote: >>> They are equally readable. The first one sets EAX to 3; the second >>> displays all elements of x on the console. Assembly is readable on a >>> very low level, but it's by nature verbose at a high level, and thus >>> less readable (you can't eyeball a function and know exactly what it >>> does, especially if that function spans more than a screenful of >>> code). >> >> Welcome in the realm of trolling. > > Seems like you're the one trolling. At least I hope that ChrisA understood what I meant. I'll spell it out for you trollmonger (is that even a word?): 1) I read Steve's posts but I found his answers inconsistent. 2) He accused me of misrepresenting his view and you called me a troll. 3) I suspect that you didn't follow the entire discussion or you'd have noticed the inconsistencies yourself... but I understand that calling someone you don't agree with a troll is easier. 4) ChrisA gave the right answer which was the point I was trying to make all along. 5) I could have said "I second that" or "I agree with you", but I thought that "Welcome to the realm of trolling" was more amusing. I thought that people who agree with me were supposed to be troll as well. But I should've consulted with you about that. Sorry. Kiuhnm From neilc at norwich.edu Mon Mar 19 07:26:10 2012 From: neilc at norwich.edu (Neil Cerutti) Date: 19 Mar 2012 11:26:10 GMT Subject: Python is readable References: <4f612b19$0$1379$4fafbaef@reader2.news.tin.it> <8e72d74f-c844-4de3-8a37-f6b1fdc2291f@y27g2000yqy.googlegroups.com> <50e9ceec-40f1-4ead-b2b6-87328b30d084@ow8g2000pbc.googlegroups.com> <4f61c828$0$1390$4fafbaef@reader2.news.tin.it> <4f61d728$0$1375$4fafbaef@reader2.news.tin.it> <4f61fd0a$0$1389$4fafbaef@reader2.news.tin.it> <4f6280a0$0$29981$c3e8da3$5496439d@news.astraweb.com> <4f6333ca$0$1392$4fafbaef@reader1.news.tin.it> <4f633a1a$0$29981$c3e8da3$5496439d@news.astraweb.com> <9sgsb1FsbpU1@mid.individual.net> Message-ID: <9sojehFi09U2@mid.individual.net> On 2012-03-17, Terry Reedy wrote: > On 3/16/2012 9:08 AM, Neil Cerutti wrote: > >> A grammarian always uses complete sentence before a colon, even >> when introducing a list. > > The Chicago Manual of Style*, 13th edition, says "The colon is > used to mark a discontinuity of grammatical construction > greater than that indicated by the semicolon and less than that > indicated by the period." > > While most of the examples in that section have what would be a > complete sentence before the colon, not all do. Not in that > section is this, from the Table of Contents: "Documentation: > References, Notes, and Bibliographies". Here are a couple more > from their Library of Congress Cataloging in Publication data: > "Rev. ed. of: A manual of style." and "Bibliography: p.". And > in letters: "To:", "From:", and "Date:" > > *A major style guide for general American writing and > publication: used by some as the 'Bible'. Thanks for the discussion and corrections. My apologies to Steven for pushing my apparnetly overly narrow view. There are plenty of valid use cases for a colon without an independent clause. -- Neil Cerutti From kiuhnm03.4t.yahoo.it Mon Mar 19 07:34:58 2012 From: kiuhnm03.4t.yahoo.it (Kiuhnm) Date: Mon, 19 Mar 2012 12:34:58 +0100 Subject: Python is readable In-Reply-To: <4f653c1e$0$29981$c3e8da3$5496439d@news.astraweb.com> References: <4f612b19$0$1379$4fafbaef@reader2.news.tin.it> <8e72d74f-c844-4de3-8a37-f6b1fdc2291f@y27g2000yqy.googlegroups.com> <50e9ceec-40f1-4ead-b2b6-87328b30d084@ow8g2000pbc.googlegroups.com> <4f61c828$0$1390$4fafbaef@reader2.news.tin.it> <4f61d728$0$1375$4fafbaef@reader2.news.tin.it> <4f61fd0a$0$1389$4fafbaef@reader2.news.tin.it> <4f620837$0$1382$4fafbaef@reader2.news.tin.it> <4f627c25$0$1381$4fafbaef@reader2.news.tin.it> <4f62b9be$0$29981$c3e8da3$5496439d@news.astraweb.com> <4f632da5$0$1375$4fafbaef@reader1.news.tin.it> <4f636ed5$0$29981$c3e8da3$5496439d@news.astraweb.com> <4f64ed2e$0$1389$4fafbaef@reader1.news.tin.it> <4f653c1e$0$29981$c3e8da3$5496439d@news.astraweb.com> Message-ID: <4f6719e2$0$1384$4fafbaef@reader2.news.tin.it> On 3/18/2012 2:36, Steven D'Aprano wrote: > On Sat, 17 Mar 2012 20:59:34 +0100, Kiuhnm wrote: > >> Ok, so length and readability are orthogonal properties. Could you >> please explain to me in which way >> mov eax, 3 >> should be less readable than >> for i in x: print(i) >> ? > > "mov eax, 3" requires more domain-specific knowledge. It operates at a > very low level, that of memory locations and bytes, rather than at a > level which most people can reason about efficiently. > > English speakers would probably guess that "mov" was an abbreviation of > "move", but what is being moved, and from where to where, for what > purpose? > > They're also likely to flounder on the analogy of "moving" bytes. When > you move a book from here to there, you leave a space in the row of books > where there is no longer a book. (You might choose to move a second book > into that gap, but first there is a gap.) But when you move bytes, you > don't leave a gap. There are always bytes at every valid address. The > average non-programmer is likely to have the wrong data model to > understand what "mov eax, 3" does. > > In the second example, most English speakers would intuit that "print(i)" > prints i, whatever i is. "for i in x" is more cryptic, but if it were > written with less jargon-like names, such as "for item in list" or "for > person in family" or similar, they would likely guess that it means to > repeat the following instructions for each item in the set: > > "For each person at the table, place a plate, knife and fork." > > And even if the reader can't guess the meaning of the for-loop, it is a > concept easy enough for most people to grasp given some explanations and > examples. It's neither too low level (assembly language), nor too high > level (monads, functors) but is at just the right level of abstraction > versus concreteness for the average person to follow. Would you be so kind to give me your final definition of readability and /stick/ to it? You keep changing it every time I point out a flaw in it. Kiuhnm From ovidiudeac at gmail.com Mon Mar 19 07:41:20 2012 From: ovidiudeac at gmail.com (Ovidiu Deac) Date: Mon, 19 Mar 2012 13:41:20 +0200 Subject: debugging ssl handshake failure Message-ID: I have an HTTPS server written in python, based on ssl package. This application is running on 3 virtual machines which were created by clonning. The application works perfectly on 2 machines but on the third it doesn't. Instead of the normal "Server Hello" message it gives me an Alert Level: Fatal, Description: "Handshake failure" Anybody here has any idea what the problem could be? My main problem here is that I don't have any means to debug the problem. My next option is to look into ssl sources which I'm not really happy to do. Also anybody has any suggestion for debugging? Thanks, Ovidiu From kiuhnm03.4t.yahoo.it Mon Mar 19 07:44:53 2012 From: kiuhnm03.4t.yahoo.it (Kiuhnm) Date: Mon, 19 Mar 2012 12:44:53 +0100 Subject: Python is readable In-Reply-To: <4f653e5c$0$29981$c3e8da3$5496439d@news.astraweb.com> References: <4f612b19$0$1379$4fafbaef@reader2.news.tin.it> <8e72d74f-c844-4de3-8a37-f6b1fdc2291f@y27g2000yqy.googlegroups.com> <50e9ceec-40f1-4ead-b2b6-87328b30d084@ow8g2000pbc.googlegroups.com> <4f61c828$0$1390$4fafbaef@reader2.news.tin.it> <4f61d728$0$1375$4fafbaef@reader2.news.tin.it> <4f61fd0a$0$1389$4fafbaef@reader2.news.tin.it> <4f6280a0$0$29981$c3e8da3$5496439d@news.astraweb.com> <4f6333ca$0$1392$4fafbaef@reader1.news.tin.it> <4f633a1a$0$29981$c3e8da3$5496439d@news.astraweb.com> <4f64f2d8$0$1393$4fafbaef@reader1.news.tin.it> <4f653e5c$0$29981$c3e8da3$5496439d@news.astraweb.com> Message-ID: <4f671c36$0$1386$4fafbaef@reader2.news.tin.it> On 3/18/2012 2:46, Steven D'Aprano wrote: > On Sat, 17 Mar 2012 21:23:45 +0100, Kiuhnm wrote: > >> On 3/16/2012 14:03, Steven D'Aprano wrote: >>> A one line routine is still a routine. There is nothing ungrammatical >>> about "If you can: take the bus.", although it is non-idiomatic >>> English. >> >> In another post you wrote >> "Sorry, I was talking about the other sort, the ones who apply the >> grammatical rules used by people in real life. You know the ones: >> linguists." >> >> Then how do you know that there's nothing ungrammatical about "If you >> can: take the bus" if people don't use it? > > Who says it is ungrammatical? You did. You're not a prescriptivist, thus you're probably a descriptivist. Beeing a descriptivist, you must agree on the fact that "If ...: do this" is ungrammatical, because nobody says that. On the other hand, a prescriptivist might accept that. BTW, I asked a few teachers of English whether "If ...: do this" is correct or not and they, surprisingly, said "no". Kiuhnm From steve+comp.lang.python at pearwood.info Mon Mar 19 07:51:14 2012 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 19 Mar 2012 11:51:14 GMT Subject: Python is readable References: <4f612b19$0$1379$4fafbaef@reader2.news.tin.it> <8e72d74f-c844-4de3-8a37-f6b1fdc2291f@y27g2000yqy.googlegroups.com> <50e9ceec-40f1-4ead-b2b6-87328b30d084@ow8g2000pbc.googlegroups.com> <4f61c828$0$1390$4fafbaef@reader2.news.tin.it> <4f61d728$0$1375$4fafbaef@reader2.news.tin.it> <4f61fd0a$0$1389$4fafbaef@reader2.news.tin.it> <4f6280a0$0$29981$c3e8da3$5496439d@news.astraweb.com> <4f6333ca$0$1392$4fafbaef@reader1.news.tin.it> <4f633a1a$0$29981$c3e8da3$5496439d@news.astraweb.com> <9sgsb1FsbpU1@mid.individual.net> <9sojehFi09U2@mid.individual.net> Message-ID: <4f671db2$0$29981$c3e8da3$5496439d@news.astraweb.com> On Mon, 19 Mar 2012 11:26:10 +0000, Neil Cerutti wrote: [...] >> *A major style guide for general American writing and publication: used >> by some as the 'Bible'. > > Thanks for the discussion and corrections. My apologies to Steven for > pushing my apparnetly overly narrow view. There are plenty of valid use > cases for a colon without an independent clause. No apology necessary, I like a good argument :) http://www.mindspring.com/~mfpatton/sketch.htm One observation that amuses me though... it seems to me that the widespread practice of people writing colons following sentence fragments isn't sufficient to convince you that this is grammatical, but a self- declared authority prescribing it as allowed is. That makes you a grammar prescriptivist :) We're-all-a-little-bit-prescriptivists-when-it-comes-to-grammar-ly y'rs, -- Steven From steve+comp.lang.python at pearwood.info Mon Mar 19 07:57:09 2012 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 19 Mar 2012 11:57:09 GMT Subject: Python is readable References: <4f612b19$0$1379$4fafbaef@reader2.news.tin.it> <50e9ceec-40f1-4ead-b2b6-87328b30d084@ow8g2000pbc.googlegroups.com> <4f61c828$0$1390$4fafbaef@reader2.news.tin.it> <4f61d728$0$1375$4fafbaef@reader2.news.tin.it> <4f61fd0a$0$1389$4fafbaef@reader2.news.tin.it> <4f620837$0$1382$4fafbaef@reader2.news.tin.it> <4f627c25$0$1381$4fafbaef@reader2.news.tin.it> <4f62b9be$0$29981$c3e8da3$5496439d@news.astraweb.com> <4f632da5$0$1375$4fafbaef@reader1.news.tin.it> <4f636ed5$0$29981$c3e8da3$5496439d@news.astraweb.com> <4f64ed2e$0$1389$4fafbaef@reader1.news.tin.it> <4f650213$0$1375$4fafbaef@reader1.news.tin.it> <4f67153b$0$1383$4fafbaef@reader2.news.tin.it> Message-ID: <4f671f15$0$29981$c3e8da3$5496439d@news.astraweb.com> On Mon, 19 Mar 2012 12:15:07 +0100, Kiuhnm wrote: > On 3/18/2012 0:04, Michael Torrie wrote: >> On 03/17/2012 03:28 PM, Kiuhnm wrote: >>>> They are equally readable. The first one sets EAX to 3; the second >>>> displays all elements of x on the console. Assembly is readable on a >>>> very low level, but it's by nature verbose at a high level, and thus >>>> less readable (you can't eyeball a function and know exactly what it >>>> does, especially if that function spans more than a screenful of >>>> code). >>> >>> Welcome in the realm of trolling. >> >> Seems like you're the one trolling. > > At least I hope that ChrisA understood what I meant. I'll spell it out > for you trollmonger (is that even a word?): Sure, why not? A trollmonger would be someone who deals in the buying and selling of trolls. Presumably this would be meant figuratively, like an argument-monger (someone who starts and gets involved in arguments). > 1) I read Steve's posts but I found his answers inconsistent. I don't think they are, but I'm happy to either clarify or concede any points that are contradictory or inconsistent, if you tell me what they are. -- Steven From jmwebaze at gmail.com Mon Mar 19 08:38:27 2012 From: jmwebaze at gmail.com (J. Mwebaze) Date: Mon, 19 Mar 2012 13:38:27 +0100 Subject: Message passing between python objects Message-ID: I am trying to learn about the interaction between python objects. One thing i have often read is that objects interact by sending messages to other objects to invoke corresponding methods. I am specifically interested in tracing these messages and also probably log the messages for further scrutiny. I would like to build a provenance kind of system. Regards -- *Mob UG: +256 (0) 70 1735800 | NL +31 (0) 6 852 841 38 | Gtalk: jmwebaze | skype: mwebazej | URL: www.astro.rug.nl/~jmwebaze /* Life runs on code */* -------------- next part -------------- An HTML attachment was scrubbed... URL: From neilc at norwich.edu Mon Mar 19 08:53:23 2012 From: neilc at norwich.edu (Neil Cerutti) Date: 19 Mar 2012 12:53:23 GMT Subject: Python is readable References: <4f612b19$0$1379$4fafbaef@reader2.news.tin.it> <8e72d74f-c844-4de3-8a37-f6b1fdc2291f@y27g2000yqy.googlegroups.com> <50e9ceec-40f1-4ead-b2b6-87328b30d084@ow8g2000pbc.googlegroups.com> <4f61c828$0$1390$4fafbaef@reader2.news.tin.it> <4f61d728$0$1375$4fafbaef@reader2.news.tin.it> <4f61fd0a$0$1389$4fafbaef@reader2.news.tin.it> <4f6280a0$0$29981$c3e8da3$5496439d@news.astraweb.com> <4f6333ca$0$1392$4fafbaef@reader1.news.tin.it> <4f633a1a$0$29981$c3e8da3$5496439d@news.astraweb.com> <9sgsb1FsbpU1@mid.individual.net> <9sojehFi09U2@mid.individual.net> <4f671db2$0$29981$c3e8da3$5496439d@news.astraweb.com> Message-ID: <9sooi3F682U1@mid.individual.net> On 2012-03-19, Steven D'Aprano wrote: > On Mon, 19 Mar 2012 11:26:10 +0000, Neil Cerutti wrote: > [...] >>> *A major style guide for general American writing and >>> publication: used by some as the 'Bible'. >> >> Thanks for the discussion and corrections. My apologies to >> Steven for pushing my apparnetly overly narrow view. There are >> plenty of valid use cases for a colon without an independent >> clause. > > No apology necessary, I like a good argument :) > > http://www.mindspring.com/~mfpatton/sketch.htm > > One observation that amuses me though... it seems to me that > the widespread practice of people writing colons following > sentence fragments isn't sufficient to convince you that this > is grammatical, but a self- declared authority prescribing it > as allowed is. That makes you a grammar prescriptivist :) There are certain uses of colon that are worse than others, in my mind. It's a matter of taste, and that's going to be impossible to find references for. My birthday cake had three kinds of frosting: chocolate, vanilla and raspberry. I checked only one reference before diving in (www.wsu.edu/~brians/errors/), but it's a guide that concentrates on presenting yourself well through widely acceptable grammar. It's not an exhaustive taxonomy of all valid usages. So I looked in the wrong place. I still think sentence fragments before a colon introducing a list often looks bad, and may be taken for an error. But it doesn't always look bad, and I didn't think about it enough. > We're-all-a-little-bit-prescriptivists-when-it-comes-to-grammar-ly y'rs, Yep: my clever usage is another's abomination. -- Neil Cerutti From andrea.crotti.0 at gmail.com Mon Mar 19 08:59:43 2012 From: andrea.crotti.0 at gmail.com (Andrea Crotti) Date: Mon, 19 Mar 2012 12:59:43 +0000 Subject: configobj validation Message-ID: <4F672DBF.5060506@gmail.com> I seemed to remember that type validation and type conversion worked out of the box, but now I can't get it working anymore. Shouldn't this simple example actually fail the parsing (instead it parses perfectly port to a string)? sample.py: from configobj import ConfigObj conf = ConfigObj('sample.conf', configspec='sample.spec') sample.conf: port = some_string sample.spec: port = integer(0, 10) PS. using configobj 4.7.2 From thudfoo at gmail.com Mon Mar 19 09:14:44 2012 From: thudfoo at gmail.com (xDog Walker) Date: Mon, 19 Mar 2012 06:14:44 -0700 Subject: ANN: cmd2, an extenstion of cmd that parses its argument line In-Reply-To: <20285780.118.1332133873462.JavaMail.geo-discussion-forums@pbcwe9> References: <20285780.118.1332133873462.JavaMail.geo-discussion-forums@pbcwe9> Message-ID: <201203190614.44110.thudfoo@gmail.com> On Sunday 2012 March 18 22:11, anntzer.lee at gmail.com wrote: > I would like to announce the first public release of cmd2, an extension of > the standard library's cmd with argument parsing, here: > https://github.com/anntzer/cmd2. There already is a cmd2 package at PyPI and has been for a long time. http://packages.python.org/cmd2/ -- I have seen the future and I am not in it. From brian.wilkinson at ssfs.org Mon Mar 19 09:20:06 2012 From: brian.wilkinson at ssfs.org (Brian Wilkinson) Date: Mon, 19 Mar 2012 06:20:06 -0700 (PDT) Subject: New learner of Python--any suggestion on studying it? References: Message-ID: <5cf01d60-c5d9-4a38-84c4-aac517bfc2af@i18g2000vbx.googlegroups.com> On Mar 19, 2:30?am, yan xianming wrote: > Hello all, > > I'm a new learning of Python. > > Can someone give me some suggestion about it? > > thanks > xianming Once you have a few of the basics down (using the resources others have suggested), a good way to practice those skills is to visit Project Euler (http://projecteuler.net/) or The Python Challenge (http://www.pythonchallenge.com/). Project Euler is a site with math problems that can be best solved using basic programming skills. The first problem asks for the sum of all the multiples of 3 or 5 below 1000. The problems build in difficulty and in the programming skills you need. The Python Challenge (best completed using version 2.7 of Python) is hard to explain, but a lot of fun to do. Good luck! Brian From __peter__ at web.de Mon Mar 19 09:27:11 2012 From: __peter__ at web.de (Peter Otten) Date: Mon, 19 Mar 2012 14:27:11 +0100 Subject: Message passing between python objects References: Message-ID: J. Mwebaze wrote: > I am trying to learn about the interaction between python objects. One > thing i have often read is that objects interact by sending messages to > other objects to invoke corresponding methods. I am specifically > interested in tracing these messages and also probably log the messages > for further scrutiny. I would like to build a provenance kind of system. The term "message" occurs in various contexts in computing. You have probably encountered these http://en.wikipedia.org/wiki/Smalltalk#Messages http://en.wikipedia.org/wiki/Message_loop_in_Microsoft_Windows and are mixing the two meanings. However, methods in Python are ordinary functions that know about "their" instance. Given a = A() a.method(1, 2) and A.method(a, 1, 2) are equivalent, no animals are hurt and no messages passed. From steve+comp.lang.python at pearwood.info Mon Mar 19 09:37:05 2012 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 19 Mar 2012 13:37:05 GMT Subject: Python is readable References: <4f612b19$0$1379$4fafbaef@reader2.news.tin.it> <8e72d74f-c844-4de3-8a37-f6b1fdc2291f@y27g2000yqy.googlegroups.com> <50e9ceec-40f1-4ead-b2b6-87328b30d084@ow8g2000pbc.googlegroups.com> <4f668a9d$0$29981$c3e8da3$5496439d@news.astraweb.com> Message-ID: <4f673680$0$29981$c3e8da3$5496439d@news.astraweb.com> On Mon, 19 Mar 2012 15:33:51 +1100, Chris Angelico wrote: >> This is at least the second time you've alleged that assembly language >> is more readable than Python. I think you're a raving nutter, no >> offence Chris :-) > > None taken; guilty as charged. And unashamedly so. With that dealt with, > though: My calling assembly "readable" is a form of argument by drawing > to logical, but absurd, conclusion - by the given definition of > readability, assembly is readable, ergo the definition sucks. (That's a > term all logicians use, you know. Proper and formal jargon.) Which definition of readability are you using? Because I have given, if not a formal definition, at least a good explanation of what I consider to be the usual meaning of "readability" in the context of programming languages. I haven't seen anyone propose an alternative. Readability, as I see it, is a misnomer. What people actually mean by "Ruby is more readable than Forth" (say) is that Ruby is more comprehensible to some idealised non-expert reader. I also gave a list of characteristics of this idealised reader -- check the archives. I don't see how "assembly is readable" is the logical conclusion of my definition. It certainly is the logical conclusion if you make expert practitioners in the language as the judge of readability, but that's not my argument, that's yours. >> Assignment (name binding) is close to the absolute simplest thing you >> can do in a programming language. In Python, the syntax is intuitive to >> anyone who has gone through high school, or possibly even primary >> school, and been introduced to the equals sign. >> >> x = 1234 >> y = "Hello" > > Not quite. In mathematics, "x = 1234" is either a declaration of fact, > or a statement that can be either true or false. [snip differences between assignment and equality] Granted there are differences. Nevertheless, even mathematicians have a form of assignment, using almost the same notation many programming languages use: let c = 42 Sometimes the "let" is left out. The point is not that programming assignment and mathematical equality are identical, but that most people have been exposed to maths = in school and so can intuit the meaning of programming = . Admittedly not always *correctly* :) [...] >> Assembly has a very steep learning curve. Python has a shallow curve. > > Of course. But computer programming generally has a fairly stiff > learning curve; you have to get your head around all sorts of concepts > that simply do not exist anywhere else. Sure. That brings us to the perennial conflict between power/ expressibility versus readability/comprehensibility. Except for languages aimed purely as a teaching language for beginners, or perhaps an application scripting language, readability should not be the *only* aim in a language. The trick is to add as much power as you need without losing too much readability. The more powerful an abstraction or programming construct, the less non- experts will be able to intuit what it does. Or for that matter, the less likely they will be able to understand it even after explanations. I still have no idea what Haskell monads are. Contrariwise, the simpler and more comprehensible a tool is for non- experts, the less likely it will be interesting to experts. Either there will be too much syntactic sugar (e.g. "add 3 to x" instead of x += 3) or it simply won't do much ("x + 3" is understandable but not very interesting, and it doesn't help you talk to a database). Somewhere between those extremes of Forth and Hypertalk is a happy medium. It is my position that Python is somewhat closer to that peak than close neighbours like Ruby and Javascript, but I'm willing to accept that a certain amount of that is mere personal taste. Of course my personal taste is right and theirs is wrong. *wink* >> If all you have is a hammer, the instructions you get are easy to >> understand because there's not much you can do with it. How complicated >> can "hit the nail with the hammer" get? But the right measure is not >> the simplicity of the tasks you *can* do, but the comprehensibility of >> the tasks you *want* to do. > > Right, which is why NO language can be described as "readable" or "easy > to work with" unless you define a problem domain. SQL is an excellent > language... as long as you want to query a relational database. And so long as you stick to simple examples, it is relatively comprehensible: SELECT COLUMN2 FROM TABLE WHERE COLUMN1 = 42; But then you have stuff like this: SELECT * FROM ( SELECT RANK() OVER (ORDER BY age ASC) AS ranking, person_id, person_name, age FROM person ) foo WHERE ranking <= 10 Try asking your dear ol' granny to explain what that does. >> The measure of the readability of a language should not be obfuscated >> or badly written code, but good, idiomatic code written by an >> experienced practitioner in the art. Note that there is a deliberate >> asymmetry there: when judging "readability" (comprehensibility), we >> take idiomatic code written by somebody who knows the language well, >> and give it to a novice to interpret it. > > Sure. You can write bad code in any language, and that doesn't mean > anything. But still, if you're writing for a novice, you write quite > different code from what you'd write normally. Language tutorials are > written by experts for novices; language tutorials do not look like the > language's own standard library (assuming it has one written in itself). Absolutely. One of my pet peeves is the number of people who give answers to questions *far* over the experience level of the person asking the question. Like if Joe Noob asked how to read a number from three files and calculate the sum, and I gave an answer involving spawning a bunch of threads to read the files. If your aim is to *teach*, then "that's how I would do it" is not necessarily a good answer is the person you are trying to teach knows less than you. >>> Really, the metric MUST be Python programmers. Intuitiveness is of >>> value, but readability among experienced programmers is far more >>> useful. >> >> But by that metric, Brainf*** is readable, since an experienced expert >> in the art of writing BF code will be able to recognise BF idioms and >> interpret them correctly. > > Not really. The BF code to do one simple high level operation could > easily span several pages. You can't "recognize" those. Now, BF with > macros/subroutines might be more plausible - if you could define a new > opcode that represents some huge slab of BF code and use that - but in > its native form, I don't think anyone could recognize what BF is doing. Dude, there are people who can recite pi to ten thousand digits, or tell you the 23rd phone number on page 348 of the White Pages from memory. Somewhere out there is a guy who can glance at eight pages of BF code and tell you what it does and where the bugs are. >> No, I'm sorry, I disagree that the standard of readability should be >> the experienced programmer. By that standard, "readability" is a no-op. >> All languages are, more or less, equally readable, to those who can >> read them well. I don't think it is useful to judge the readability of >> Forth on the ability of Charles Moore to read it. How does that help me >> decide whether to use Forth for my next project? >> >>> If I write a whole lot of code today, and next year I'm dead and >>> someone else has replaced me, I frankly don't mind if he has to learn >>> the language before he can grok my code. I _do_ mind if, even after >>> he's learned the language, he can't figure out what my code's doing; >> >> Then he hasn't learned the language *sufficiently well*. Either that, >> or your code is obfuscated, unidiomatic crap. Perhaps you're trying to >> write BF in Python :) > > And that's where the nub of the question is. How well is sufficiently > well? Clearly you do not require your code to be comprehensible to a > non-programmer, or you would not write code at all. If you don't demand > that the reader learn basic keywords of the language, then it's equally > impossible to expect them to comprehend your code. If you're writing > production code, I see no reason to avoid language features like > Python's list comps, Pike's %{ %} sprintf codes, or C's pointer > arithmetic, just because they can confuse people. Learn the language, > THEN start hacking on the code. Certainly. I don't mean to imply that code should always be written for beginners. Code is primarily written for other programmers, and only secondly for the compiler, so you must choose your audience. Every piece of code needs to weigh up many different characteristics, some of which are in conflict: * fast to run * fast to write * efficient use of memory or other resources * easy to add functionality * easy to debug * understandable to non-experts * useful * correct The last two are especially interesting. Some problems can't be solved correctly in any reasonable timeframe, but heuristics can give an answer which may not be strictly correct but still useful. Many optimization problems are like that. Sometimes a close answer is better than no answer at all. -- Steven From neilc at norwich.edu Mon Mar 19 10:33:25 2012 From: neilc at norwich.edu (Neil Cerutti) Date: 19 Mar 2012 14:33:25 GMT Subject: A debugging story. Message-ID: <9soudlFimvU1@mid.individual.net> I just spent two hours debugging a crucial, though fairly simple, program. As part of the processing of an admissions report, I use difflib to compare two csv files. I compare the current file with one from the immediate past. The file changes over time as new students are accepted, and current students change major and so forth. I next comb through the generated diff to find the actually changed fields, keeping a log of critical changes. I found I had not accounted for field names changing between runs of the admissions report, as recently happened when something had to be added to the report. I finally got it working and tested, and then was horrified when a slip of my finger caused me to have to revert to a previous version of the file from rcs. Two hours of work, down the bit-bucket! My horror abated when I found I was able to make the necessary changes again in roughly 30 seconds. This message brought to you by the Debugging is Mostly Comprehending Old Code and Testing Council. -- Neil Cerutti From robert.kern at gmail.com Mon Mar 19 10:38:33 2012 From: robert.kern at gmail.com (Robert Kern) Date: Mon, 19 Mar 2012 14:38:33 +0000 Subject: Python is readable In-Reply-To: <9sooi3F682U1@mid.individual.net> References: <4f612b19$0$1379$4fafbaef@reader2.news.tin.it> <8e72d74f-c844-4de3-8a37-f6b1fdc2291f@y27g2000yqy.googlegroups.com> <50e9ceec-40f1-4ead-b2b6-87328b30d084@ow8g2000pbc.googlegroups.com> <4f61c828$0$1390$4fafbaef@reader2.news.tin.it> <4f61d728$0$1375$4fafbaef@reader2.news.tin.it> <4f61fd0a$0$1389$4fafbaef@reader2.news.tin.it> <4f6280a0$0$29981$c3e8da3$5496439d@news.astraweb.com> <4f6333ca$0$1392$4fafbaef@reader1.news.tin.it> <4f633a1a$0$29981$c3e8da3$5496439d@news.astraweb.com> <9sgsb1FsbpU1@mid.individual.net> <9sojehFi09U2@mid.individual.net> <4f671db2$0$29981$c3e8da3$5496439d@news.astraweb.com> <9sooi3F682U1@mid.individual.net> Message-ID: On 3/19/12 12:53 PM, Neil Cerutti wrote: > I still think sentence fragments before a colon introducing a > list often looks bad, and may be taken for an error. But it > doesn't always look bad, and I didn't think about it enough. One of my English teachers suggested a rule that seems to accord (descriptively) with the uses the "look good" and "look bad" to me: don't use a colon to separate a transitive verb from its objects. -- Robert Kern "I have come to believe that the whole world is an enigma, a harmless enigma that is made terrible by our own mad attempt to interpret it as though it had an underlying truth." -- Umberto Eco From andrea.crotti.0 at gmail.com Mon Mar 19 10:44:21 2012 From: andrea.crotti.0 at gmail.com (Andrea Crotti) Date: Mon, 19 Mar 2012 14:44:21 +0000 Subject: configobj validation In-Reply-To: <4F672DBF.5060506@gmail.com> References: <4F672DBF.5060506@gmail.com> Message-ID: <4F674645.4070600@gmail.com> On 03/19/2012 12:59 PM, Andrea Crotti wrote: > I seemed to remember that type validation and type conversion worked > out of the box, but now > I can't get it working anymore. > > Shouldn't this simple example actually fail the parsing (instead it > parses perfectly port to a string)? > > sample.py: > from configobj import ConfigObj > > conf = ConfigObj('sample.conf', configspec='sample.spec') > > sample.conf: > port = some_string > > sample.spec: > port = integer(0, 10) > > PS. using configobj 4.7.2 I now checked the repo and configobj seems also quite dead (2 years ago last version), it's a pity because it's a really nice library. Any other alternatives for validation/configuration systems otherwise? From steve+comp.lang.python at pearwood.info Mon Mar 19 11:27:39 2012 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 19 Mar 2012 15:27:39 GMT Subject: Python is readable References: <4f612b19$0$1379$4fafbaef@reader2.news.tin.it> <8e72d74f-c844-4de3-8a37-f6b1fdc2291f@y27g2000yqy.googlegroups.com> <50e9ceec-40f1-4ead-b2b6-87328b30d084@ow8g2000pbc.googlegroups.com> <4f61c828$0$1390$4fafbaef@reader2.news.tin.it> <4f61d728$0$1375$4fafbaef@reader2.news.tin.it> <4f61fd0a$0$1389$4fafbaef@reader2.news.tin.it> <4f6280a0$0$29981$c3e8da3$5496439d@news.astraweb.com> <4f6333ca$0$1392$4fafbaef@reader1.news.tin.it> <4f633a1a$0$29981$c3e8da3$5496439d@news.astraweb.com> <4f64f2d8$0$1393$4fafbaef@reader1.news.tin.it> <4f653e5c$0$29981$c3e8da3$5496439d@news.astraweb.com> <4f671c36$0$1386$4fafbaef@reader2.news.tin.it> Message-ID: <4f67506b$0$29981$c3e8da3$5496439d@news.astraweb.com> On Mon, 19 Mar 2012 12:44:53 +0100, Kiuhnm wrote: > On 3/18/2012 2:46, Steven D'Aprano wrote: >> On Sat, 17 Mar 2012 21:23:45 +0100, Kiuhnm wrote: >> >>> On 3/16/2012 14:03, Steven D'Aprano wrote: >>>> A one line routine is still a routine. There is nothing ungrammatical >>>> about "If you can: take the bus.", although it is non-idiomatic >>>> English. >>> >>> In another post you wrote >>> "Sorry, I was talking about the other sort, the ones who apply the >>> grammatical rules used by people in real life. You know the ones: >>> linguists." >>> >>> Then how do you know that there's nothing ungrammatical about "If you >>> can: take the bus" if people don't use it? >> >> Who says it is ungrammatical? > > You did. > You're not a prescriptivist, thus you're probably a descriptivist. > Beeing a descriptivist, you must agree on the fact that > "If ...: do this" > is ungrammatical, because nobody says that. I believe that you are misunderstanding the descriptivist position. There are many sentences which are never said, or perhaps only said once. Most non-trivial spoken or written sentences are unique. That doesn't make them wrong or erroneous because "nobody says them". Nobody says "hesitant teapots sleep artistically". It's a meaningless sentence, but it is grammatically correct: it obeys the same grammatical rule as "hungry dogs howl pitifully" or "devote saints suffer silently": ADJECTIVE NOUN VERB ADVERB. This pattern is common in English: nearly everyone uses it, and therefore any sentence matching the pattern is *grammatically* correct for English even if it is semantically meaningless. On the other hand, "pitifully dogs hungry howl" is incorrect because virtually no English speaker writes sentences using the rule ADVERB NOUN ADJECTIVE VERB, and on such rare times that somebody does, people will notice and declare that it is "wrong" or "doesn't make sense", or otherwise correct it. In my opinion, "If ...: do this" matches a grammatical pattern which I see very frequently. I've already given my reasons for this. > On the other hand, a > prescriptivist might accept that. BTW, I asked a few teachers of English > whether "If ...: do this" is correct or not and they, surprisingly, said > "no". What matters is not the authorities who say something is right or wrong, but their reasons for doing so. -- Steven From waitmeforever at hotmail.com Mon Mar 19 12:04:24 2012 From: waitmeforever at hotmail.com (Yang Chun-Kai) Date: Tue, 20 Mar 2012 00:04:24 +0800 Subject: Please recommend a open source for Python ACLs function Message-ID: Hello Dear All: I would like to write some simple python test code with ACL(Access Control List) functions. Now simply I aim to use MAC address as ACL parameters, is there any good ACL open source recommended for using? Simple one is better. Any tips or suggestions welcomed and appreciated. Thank you. Kay -------------- next part -------------- An HTML attachment was scrubbed... URL: From andrea.crotti.0 at gmail.com Mon Mar 19 12:54:03 2012 From: andrea.crotti.0 at gmail.com (Andrea Crotti) Date: Mon, 19 Mar 2012 16:54:03 +0000 Subject: pypi and dependencies Message-ID: <4F6764AB.7060008@gmail.com> When I publish something on Pypi, is there a way to make it fetch the list of dependencies needed by my project automatically? It would be nice to have it in the Pypi page, without having to look at the actual code.. Any other possible solution? From ichels.moabit at gmail.com Mon Mar 19 13:59:21 2012 From: ichels.moabit at gmail.com (Wim M) Date: 19 Mar 2012 17:59:21 GMT Subject: New learner of Python--any suggestion on studying it? References: Message-ID: <4f6773f9$0$7628$9b4e6d93@newsspool1.arcor-online.net> Hi, this might be of interest to you: http://www.udacity.com/overview/Course/cs101 All the best Wimm On 2012-03-19, yan xianming wrote: > Hello all, > > I'm a new learning of Python. > > > > Can someone give me some suggestion about it? > > thanks > xianming -- Wim. From gandalf at shopzeus.com Mon Mar 19 15:32:03 2012 From: gandalf at shopzeus.com (Laszlo Nagy) Date: Mon, 19 Mar 2012 20:32:03 +0100 Subject: urllib.urlretrieve never returns??? In-Reply-To: <4F66E687.2050008@shopzeus.com> References: <4F649BFC.1080601@shopzeus.com> <4F66E687.2050008@shopzeus.com> Message-ID: <4F6789B3.30907@shopzeus.com> The pythonw.exe may not have the rights to access network resources. >> Have you set a default timeout for sockets? >> >> import socket >> socket.setdefaulttimeout(10) # 10 seconds I have added pythonw.exe to allowed exceptions. Disabled firewall completely. Set socket timeout to 10 seconds. Still nothing. urllib.urlretrieve does not return from call.... any other ideas? From joncle at googlemail.com Mon Mar 19 19:04:54 2012 From: joncle at googlemail.com (Jon Clements) Date: Mon, 19 Mar 2012 16:04:54 -0700 (PDT) Subject: urllib.urlretrieve never returns??? In-Reply-To: References: <4F649BFC.1080601@shopzeus.com> <4F66E687.2050008@shopzeus.com> Message-ID: <11279707.1159.1332198294121.JavaMail.geo-discussion-forums@vbfl9> On Monday, 19 March 2012 19:32:03 UTC, Laszlo Nagy wrote: > The pythonw.exe may not have the rights to access network resources. > >> Have you set a default timeout for sockets? > >> > >> import socket > >> socket.setdefaulttimeout(10) # 10 seconds > I have added pythonw.exe to allowed exceptions. Disabled firewall > completely. Set socket timeout to 10 seconds. Still nothing. > > urllib.urlretrieve does not return from call.... > > any other ideas? Maybe try using the reporthook option for urlretrieve, just to see if that does anything... If it constantly calls the hook or never calls it, that's one thing. Alternately, tcpdump/wireshark whatever, to see what the heck is going on with traffic - if any. hth Jon From joncle at googlemail.com Mon Mar 19 19:04:54 2012 From: joncle at googlemail.com (Jon Clements) Date: Mon, 19 Mar 2012 16:04:54 -0700 (PDT) Subject: urllib.urlretrieve never returns??? In-Reply-To: References: <4F649BFC.1080601@shopzeus.com> <4F66E687.2050008@shopzeus.com> Message-ID: <11279707.1159.1332198294121.JavaMail.geo-discussion-forums@vbfl9> On Monday, 19 March 2012 19:32:03 UTC, Laszlo Nagy wrote: > The pythonw.exe may not have the rights to access network resources. > >> Have you set a default timeout for sockets? > >> > >> import socket > >> socket.setdefaulttimeout(10) # 10 seconds > I have added pythonw.exe to allowed exceptions. Disabled firewall > completely. Set socket timeout to 10 seconds. Still nothing. > > urllib.urlretrieve does not return from call.... > > any other ideas? Maybe try using the reporthook option for urlretrieve, just to see if that does anything... If it constantly calls the hook or never calls it, that's one thing. Alternately, tcpdump/wireshark whatever, to see what the heck is going on with traffic - if any. hth Jon From ian.g.kelly at gmail.com Mon Mar 19 19:20:43 2012 From: ian.g.kelly at gmail.com (Ian Kelly) Date: Mon, 19 Mar 2012 17:20:43 -0600 Subject: Currying in Python In-Reply-To: <4f63e724$0$1386$4fafbaef@reader1.news.tin.it> References: <4f63e724$0$1386$4fafbaef@reader1.news.tin.it> Message-ID: I hope you don't mind if I critique your code a bit! On Fri, Mar 16, 2012 at 7:21 PM, Kiuhnm wrote: > Here we go. > > ---> > def genCur(f, unique = True, minArgs = -1): It is customary in Python for unsupplied arguments with no default to use the value None, not -1. That's what it exists for. > ? ?""" Generates a 'curried' version of a function. """ > ? ?def geng(curArgs, curKwargs): > ? ? ? ?def g(*args, **kwargs): > ? ? ? ? ? ?nonlocal f, curArgs, curKwargs, minArgs; ? ?# our STATIC data > > ? ? ? ? ? ?if len(args) or len(kwargs): Collections evaluate as true if they are not empty, so this could just be: if args or kwargs: > ? ? ? ? ? ? ? ?# Allocates data for the next 'g'. We don't want to modify our > ? ? ? ? ? ? ? ?# static data. > ? ? ? ? ? ? ? ?newArgs = curArgs[:]; > ? ? ? ? ? ? ? ?newKwargs = dict.copy(curKwargs); > > ? ? ? ? ? ? ? ?# Adds positional arguments. > ? ? ? ? ? ? ? ?newArgs += args; > > ? ? ? ? ? ? ? ?# Adds/updates keyword arguments. > ? ? ? ? ? ? ? ?if unique: > ? ? ? ? ? ? ? ? ? ?# We don't want repeated keyword arguments. > ? ? ? ? ? ? ? ? ? ?for k in kwargs.keys(): > ? ? ? ? ? ? ? ? ? ? ? ?if k in newKwargs: > ? ? ? ? ? ? ? ? ? ? ? ? ? ?raise(Exception("Repeated kw arg while unique = True")); > ? ? ? ? ? ? ? ?newKwargs.update(kwargs); Since you're writing this for Python 3 (as evidenced by the use of the nonlocal keyword), you could take advantage here of the fact that Python 3 dictionary views behave like sets. Also, you should use a more specific exception type: if unique and not kwargs.keys().isdisjoint(newKwargs): raise ValueError("A repeated keyword argument was supplied") > ? ? ? ? ? ? ? ?# Checks whether it's time to evaluate f. > ? ? ? ? ? ? ? ?if minArgs >= 0 and minArgs <= len(newArgs) + len(newKwargs): With minArgs defaulting to None, that would be: if minArgs is not None and minArgs <= len(newArgs) + len(newKwargs): > ? ? ? ? ? ? ? ? ? ?return f(*newArgs, **newKwargs); ? ?# f has enough args > ? ? ? ? ? ? ? ?else: > ? ? ? ? ? ? ? ? ? ?return geng(newArgs, newKwargs); ? ?# f needs some more args > ? ? ? ? ? ?else: > ? ? ? ? ? ? ? ?return f(*curArgs, **curKwargs); ? ?# the caller forced the evaluation > ? ? ? ?return g; > ? ?return geng([], {}); > > def cur(f, minArgs = -1): > ? ?return genCur(f, True, minArgs); > > def curr(f, minArgs = -1): > ? ?return genCur(f, False, minArgs); The names "cur" and "curr" are terrible. Good names should describe what the function does without being too onerous to type, and the addition of the duplicate "r" is not an obvious mnemonic for remembering that the first one prohibits duplicate keyword arguments and the second one allows them. Why not more descriptive names like "curry" and "curry_unique"? That's all I've got. All in all, it's pretty decent for a Python newbie. Cheers, Ian From steve+comp.lang.python at pearwood.info Mon Mar 19 19:26:20 2012 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 19 Mar 2012 23:26:20 GMT Subject: urllib.urlretrieve never returns??? References: <4F649BFC.1080601@shopzeus.com> <4F66E687.2050008@shopzeus.com> Message-ID: <4f67c09b$0$29981$c3e8da3$5496439d@news.astraweb.com> On Mon, 19 Mar 2012 20:32:03 +0100, Laszlo Nagy wrote: > The pythonw.exe may not have the rights to access network resources. >>> Have you set a default timeout for sockets? >>> >>> import socket >>> socket.setdefaulttimeout(10) # 10 seconds > I have added pythonw.exe to allowed exceptions. Disabled firewall > completely. Set socket timeout to 10 seconds. Still nothing. > > urllib.urlretrieve does not return from call.... > > any other ideas? I'm sorry if I have missed something, or making suggestions you have already tried, but your original post describing the problem is missing from my news server. I gather you are running urlretrieve in a separate thread, inside a GUI? I have learned that whenever I have inexplicable behaviour in a function, I should check my assumptions. In this case, (1) are you sure you have the right urlretrieve, and (2) are you sure that your self.Log() method is working correctly? Just before the problematic call, do this: # was: fpath = urllib.urlretrieve(imgurl)[0] # becomes: print(urllib.__file__, urlretrieve) self.Log(urllib.__file__, urlretrieve) fpath = urllib.urlretrieve(imgurl)[0] and ensure that you haven't accidentally shadowed them with something unexpected. Does the output printed to the console match the output logged? What happens if you take the call to urlretrieve out of the thread and call it by hand? Run urllib.urlretrieve(imgurl) directly in the interactive interpreter. Does it still hang forever? When you say it "never" returns, do you mean *never* or do you mean "I gave up waiting after five minutes"? What happens if you leave it to run all day? Perhaps it returns after e.g. seven hours, which would be a mystery in itself, but at least you have perturbed the problem and have another data point. Maybe it isn't dead, just really slow. How big are the files you are trying to retrieve? Try retrieving a really small file. Then try retrieving a non-existent file. What happens if you call urlretrieve with a reporthook argument? Does it print anything? What happens if you try to browse to imgurl in your web browser? Are you sure the problem is with urlretrieve and not the source? -- Steven From kiuhnm03.4t.yahoo.it Mon Mar 19 20:24:22 2012 From: kiuhnm03.4t.yahoo.it (Kiuhnm) Date: Tue, 20 Mar 2012 01:24:22 +0100 Subject: Currying in Python In-Reply-To: References: <4f63e724$0$1386$4fafbaef@reader1.news.tin.it> Message-ID: <4f67ce36$0$1377$4fafbaef@reader2.news.tin.it> On 3/20/2012 0:20, Ian Kelly wrote: > I hope you don't mind if I critique your code a bit! Not at all. Thank you for your time. > On Fri, Mar 16, 2012 at 7:21 PM, Kiuhnm > wrote: >> Here we go. >> >> ---> >> def genCur(f, unique = True, minArgs = -1): [...] I'll update my code following your corrections, but will keep "curr" :) Kiuhnm From kiuhnm03.4t.yahoo.it Mon Mar 19 21:13:55 2012 From: kiuhnm03.4t.yahoo.it (Kiuhnm) Date: Tue, 20 Mar 2012 02:13:55 +0100 Subject: Currying in Python In-Reply-To: References: <4f63e724$0$1386$4fafbaef@reader1.news.tin.it> Message-ID: <4f67d9d3$0$1386$4fafbaef@reader2.news.tin.it> On 3/20/2012 0:20, Ian Kelly wrote: > I hope you don't mind if I critique your code a bit! And I hope you don't mind that I included your name in my code. Let me know if I should remove it. Kiuhnm From _spice at mail.ru Mon Mar 19 23:19:40 2012 From: _spice at mail.ru (=?UTF-8?B?0JDRgNGC0ZHQvCDQndCw0LfQsNGA0L7Qsg==?=) Date: Tue, 20 Mar 2012 07:19:40 +0400 Subject: =?UTF-8?B?c19wdXNoIHBhcnNlciBzdGFjayBvdmVyZmxvdw==?= Message-ID: Hi. Sorry of my english :-) code: print (((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((0)))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))" message from python is: s_push parser stack overflow Can i configure phyton to solve this problem without change MAXSTACK in " parser.c" and re-build the python? From python at mrabarnett.plus.com Tue Mar 20 00:30:51 2012 From: python at mrabarnett.plus.com (MRAB) Date: Tue, 20 Mar 2012 04:30:51 +0000 Subject: s_push parser stack overflow In-Reply-To: References: Message-ID: <4F6807FB.8010604@mrabarnett.plus.com> On 20/03/2012 03:19, ????? ??????? wrote: > Hi. > Sorry of my english :-) > > code: > print (((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((0)))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))" > > message from python is: s_push parser stack overflow > > Can i configure phyton to solve this problem without change MAXSTACK in " parser.c" and re-build the python? A quick look at parser.h tells me that it's a hard-coded limit: typedef struct { stackentry *s_top; /* Top entry */ stackentry s_base[MAXSTACK];/* Array of stack entries */ /* NB The stack grows down */ } stack; From prince.ram85 at gmail.com Tue Mar 20 00:31:39 2012 From: prince.ram85 at gmail.com (prince.pangeni) Date: Mon, 19 Mar 2012 21:31:39 -0700 (PDT) Subject: Distribution Message-ID: <33044d51-c481-4796-a722-406f412cf994@x7g2000pbi.googlegroups.com> Hi all, I am doing a simulation project using Python. In my project, I want to use some short of distribution to generate requests to a server. The request should have two distributions. One for request arrival rate (should be poisson) and another for request mix (i.e. out of the total requests defined in request arrival rate, how many requests are of which type). Example: Suppose the request rate is - 90 req/sec (generated using poisson distribution) at time t and we have 3 types of requests (i.e. r1, r2, r2). The request mix distribution output should be similar to: {r1 : 50 , r2 : 30 , r3 : 10} (i.e. out of 90 requests - 50 are of r1 type, 30 are of r2 type and 10 are of r3 type). As I an new to python distribution module, I am not getting how to code this situation. Please help me out for the same. Thanks in advance Prince From gojosupra at gmail.com Tue Mar 20 01:46:07 2012 From: gojosupra at gmail.com (jothi) Date: Mon, 19 Mar 2012 22:46:07 -0700 (PDT) Subject: with out invesment Message-ID: http://123maza.com/46/golden756/ From medina.rc at gmail.com Tue Mar 20 02:00:50 2012 From: medina.rc at gmail.com (Richard Medina Calderon) Date: Mon, 19 Mar 2012 23:00:50 -0700 (PDT) Subject: Eclipse, C, and Python Message-ID: <6023956.2302.1332223250728.JavaMail.geo-discussion-forums@ynlp3> Hello Forum. I have installed Python comnpiler in Eclipse Classic for Windows. After a while I have installed the C compiler. However, somehow now when I try to run my code in Python it shows me for default Ant Run -->Ant Build I switched my workspace but still. Do you know how to solve this?.. Thanks From gandalf at shopzeus.com Tue Mar 20 03:08:12 2012 From: gandalf at shopzeus.com (Laszlo Nagy) Date: Tue, 20 Mar 2012 08:08:12 +0100 Subject: urllib.urlretrieve never returns??? In-Reply-To: <4f67c09b$0$29981$c3e8da3$5496439d@news.astraweb.com> References: <4F649BFC.1080601@shopzeus.com> <4F66E687.2050008@shopzeus.com> <4f67c09b$0$29981$c3e8da3$5496439d@news.astraweb.com> Message-ID: <4F682CDC.5000703@shopzeus.com> Here you can find the example program and the original post. http://code.activestate.com/lists/python-list/617894/ > > I gather you are running urlretrieve in a separate thread, inside a GUI? Yes. > > I have learned that whenever I have inexplicable behaviour in a function, > I should check my assumptions. In this case, (1) are you sure you have > the right urlretrieve, and (2) are you sure that your self.Log() method > is working correctly? Just before the problematic call, do this: > > # was: > fpath = urllib.urlretrieve(imgurl)[0] > > # becomes: > print(urllib.__file__, urlretrieve) > self.Log(urllib.__file__, urlretrieve) > fpath = urllib.urlretrieve(imgurl)[0] I called self.Log() after each line, and also from a general "except:" clause. Definitely, the line after urlretrieve is not executed, and no exception is raised. Number of threads goes up (visible from task manager). It is true that the program uses another module that uses the socket module and multiple threads. (These are written in pure python.) If I remove the other module, then there is no error, however it renders the application useless. If I start the program with a console (e.g. with python.exe instead of pythonw.exe) then it works. Looks like opening a console solves the problem, although nothing is ever printed on the console. > and ensure that you haven't accidentally shadowed them with something > unexpected. Does the output printed to the console match the output > logged? Well, this cannot be tested. If there is a console, then there is no problem. > > What happens if you take the call to urlretrieve out of the thread and > call it by hand? Then it works. > Run urllib.urlretrieve(imgurl) directly in the > interactive interpreter. Does it still hang forever? Then it works perfectly. > > When you say it "never" returns, do you mean *never* or do you mean "I > gave up waiting after five minutes"? What happens if you leave it to run > all day? I did not try that. But I have already set socket timeout to 10 seconds, and definitely it is not waiting for a response from the server. > > How big are the files you are trying to retrieve? 34 KB > Try retrieving a really small file. Then try retrieving a non-existent file. Good point. I'll try to retrieve a nonexistent file when I get home. :) > > What happens if you call urlretrieve with a reporthook argument? Does it > print anything? I'll try this too. I'll also try using pycurl or the low level socket module instead. > > What happens if you try to browse to imgurl in your web browser? Are you > sure the problem is with urlretrieve and not the source? Yes. From arnodel at gmail.com Tue Mar 20 03:11:59 2012 From: arnodel at gmail.com (Arnaud Delobelle) Date: Tue, 20 Mar 2012 07:11:59 +0000 Subject: Currying in Python In-Reply-To: References: <4f63e724$0$1386$4fafbaef@reader1.news.tin.it> Message-ID: On 19 March 2012 23:20, Ian Kelly wrote: > I hope you don't mind if I critique your code a bit! > > On Fri, Mar 16, 2012 at 7:21 PM, Kiuhnm > wrote: >> Here we go. >> >> ---> >> def genCur(f, unique = True, minArgs = -1): > > It is customary in Python for unsupplied arguments with no default to > use the value None, not -1. ?That's what it exists for. > >> ? ?""" Generates a 'curried' version of a function. """ >> ? ?def geng(curArgs, curKwargs): >> ? ? ? ?def g(*args, **kwargs): >> ? ? ? ? ? ?nonlocal f, curArgs, curKwargs, minArgs; ? ?# our STATIC data I don't know if all the rest of the code is below, but this line above would only be necessary if you want to rebind f, curArgs, minArgs. You don't seem to do it, so I think this line is unnecessary. Also, your naming of variables disagrees with PEP 8 :) >> ? ? ? ? ? ?if len(args) or len(kwargs): > > Collections evaluate as true if they are not empty, so this could just be: > > ? ? ? ? ? ?if args or kwargs: > >> ? ? ? ? ? ? ? ?# Allocates data for the next 'g'. We don't want to modify our >> ? ? ? ? ? ? ? ?# static data. >> ? ? ? ? ? ? ? ?newArgs = curArgs[:]; Semicolon to end a statement? >> ? ? ? ? ? ? ? ?newKwargs = dict.copy(curKwargs); >> >> ? ? ? ? ? ? ? ?# Adds positional arguments. >> ? ? ? ? ? ? ? ?newArgs += args; >> >> ? ? ? ? ? ? ? ?# Adds/updates keyword arguments. >> ? ? ? ? ? ? ? ?if unique: >> ? ? ? ? ? ? ? ? ? ?# We don't want repeated keyword arguments. >> ? ? ? ? ? ? ? ? ? ?for k in kwargs.keys(): >> ? ? ? ? ? ? ? ? ? ? ? ?if k in newKwargs: >> ? ? ? ? ? ? ? ? ? ? ? ? ? ?raise(Exception("Repeated kw arg while unique = True")); >> ? ? ? ? ? ? ? ?newKwargs.update(kwargs); > > Since you're writing this for Python 3 (as evidenced by the use of the > nonlocal keyword), you could take advantage here of the fact that > Python 3 dictionary views behave like sets. ?Also, you should use a > more specific exception type: > > ? ? ? ? ? ? ? ?if unique and not kwargs.keys().isdisjoint(newKwargs): > ? ? ? ? ? ? ? ? ? ?raise ValueError("A repeated keyword argument was supplied") > >> ? ? ? ? ? ? ? ?# Checks whether it's time to evaluate f. >> ? ? ? ? ? ? ? ?if minArgs >= 0 and minArgs <= len(newArgs) + len(newKwargs): > > With minArgs defaulting to None, that would be: > > ? ? ? ? ? ? ? ?if minArgs is not None and minArgs <= len(newArgs) + > len(newKwargs): > >> ? ? ? ? ? ? ? ? ? ?return f(*newArgs, **newKwargs); ? ?# f has enough args >> ? ? ? ? ? ? ? ?else: >> ? ? ? ? ? ? ? ? ? ?return geng(newArgs, newKwargs); ? ?# f needs some more args >> ? ? ? ? ? ?else: >> ? ? ? ? ? ? ? ?return f(*curArgs, **curKwargs); ? ?# the caller forced the evaluation >> ? ? ? ?return g; >> ? ?return geng([], {}); >> >> def cur(f, minArgs = -1): >> ? ?return genCur(f, True, minArgs); >> >> def curr(f, minArgs = -1): >> ? ?return genCur(f, False, minArgs); > > The names "cur" and "curr" are terrible. ?Good names should describe > what the function does without being too onerous to type, and the > addition of the duplicate "r" is not an obvious mnemonic for > remembering that the first one prohibits duplicate keyword arguments > and the second one allows them. ?Why not more descriptive names like > "curry" and "curry_unique"? > > That's all I've got. ?All in all, it's pretty decent for a Python newbie. > > Cheers, > Ian > -- > http://mail.python.org/mailman/listinfo/python-list From __peter__ at web.de Tue Mar 20 05:15:01 2012 From: __peter__ at web.de (Peter Otten) Date: Tue, 20 Mar 2012 10:15:01 +0100 Subject: Distribution References: <33044d51-c481-4796-a722-406f412cf994@x7g2000pbi.googlegroups.com> Message-ID: prince.pangeni wrote: > Hi all, > I am doing a simulation project using Python. In my project, I want > to use some short of distribution to generate requests to a server. > The request should have two distributions. One for request arrival > rate (should be poisson) and another for request mix (i.e. out of the > total requests defined in request arrival rate, how many requests are > of which type). > Example: Suppose the request rate is - 90 req/sec (generated using > poisson distribution) at time t and we have 3 types of requests (i.e. > r1, r2, r2). The request mix distribution output should be similar to: > {r1 : 50 , r2 : 30 , r3 : 10} (i.e. out of 90 requests - 50 are of r1 > type, 30 are of r2 type and 10 are of r3 type). > As I an new to python distribution module, I am not getting how to > code this situation. Please help me out for the same. You don't say what distribution module you're talking of, and I guess I'm not the only one who'd need to know that detail. However, with sufficient resolution and duration the naive approach sketched below might be good enough. # untested DURATION = 3600 # run for one hour RATE = 90 # requests/sec RESOLUTION = 1000 # one msec requests = ([r1]*50 + [r2]*30 + [r3]*10) time_slots = [0]*(RESOLUTION*DURATION) times = range(RESOLUTION*DURATION) for _ in range(DURATION*RATE): time_slots[random.choice(times)] += 1 for time, count in enumerate(time_slots): for _ in range(count): issue_request_at(random.choice(requests), time) From kiuhnm03.4t.yahoo.it Tue Mar 20 06:06:42 2012 From: kiuhnm03.4t.yahoo.it (Kiuhnm) Date: Tue, 20 Mar 2012 11:06:42 +0100 Subject: Currying in Python In-Reply-To: References: <4f63e724$0$1386$4fafbaef@reader1.news.tin.it> Message-ID: <4f6856b2$0$1392$4fafbaef@reader1.news.tin.it> On 3/20/2012 0:20, Ian Kelly wrote: > Since you're writing this for Python 3 (as evidenced by the use of the > nonlocal keyword), you could take advantage here of the fact that > Python 3 dictionary views behave like sets. Also, you should use a > more specific exception type: As a side note, "nonlocal" isn't needed in my code, in fact I removed it right after my first post. Kiuhnm From kiuhnm03.4t.yahoo.it Tue Mar 20 06:13:23 2012 From: kiuhnm03.4t.yahoo.it (Kiuhnm) Date: Tue, 20 Mar 2012 11:13:23 +0100 Subject: Currying in Python In-Reply-To: References: <4f63e724$0$1386$4fafbaef@reader1.news.tin.it> Message-ID: <4f685843$0$1374$4fafbaef@reader1.news.tin.it> On 3/20/2012 8:11, Arnaud Delobelle wrote: > On 19 March 2012 23:20, Ian Kelly wrote: >> I hope you don't mind if I critique your code a bit! >> >> On Fri, Mar 16, 2012 at 7:21 PM, Kiuhnm >> wrote: >>> Here we go. >>> >>> ---> >>> def genCur(f, unique = True, minArgs = -1): >> >> It is customary in Python for unsupplied arguments with no default to >> use the value None, not -1. That's what it exists for. >> >>> """ Generates a 'curried' version of a function. """ >>> def geng(curArgs, curKwargs): >>> def g(*args, **kwargs): >>> nonlocal f, curArgs, curKwargs, minArgs; # our STATIC data > > I don't know if all the rest of the code is below, but this line above > would only be necessary if you want to rebind f, curArgs, minArgs. > You don't seem to do it, so I think this line is unnecessary. What a coincidence. I was just telling that to Ian Kelly. I removed it from the code in my article a few days ago but forgot to update my post on this ng. > Also, your naming of variables disagrees with PEP 8 :) > >>> if len(args) or len(kwargs): >> >> Collections evaluate as true if they are not empty, so this could just be: >> >> if args or kwargs: >> >>> # Allocates data for the next 'g'. We don't want to modify our >>> # static data. >>> newArgs = curArgs[:]; > > Semicolon to end a statement? As above. Too many years of C++. Kiuhnm From martin.hellwig at gmail.com Tue Mar 20 06:19:31 2012 From: martin.hellwig at gmail.com (Martin P. Hellwig) Date: Tue, 20 Mar 2012 10:19:31 +0000 Subject: Eclipse, C, and Python In-Reply-To: <6023956.2302.1332223250728.JavaMail.geo-discussion-forums@ynlp3> References: <6023956.2302.1332223250728.JavaMail.geo-discussion-forums@ynlp3> Message-ID: On 20/03/2012 06:00, Richard Medina Calderon wrote: > Hello Forum. I have installed Python comnpiler in Eclipse Classic for Windows. > After a while I have installed the C compiler. However, somehow now when I try to run my code in Python it shows me for default Ant > > Run -->Ant Build > > I switched my workspace but still. Do you know how to solve this?.. > > Thanks You might want to install the PyDev plugin and switch to that perspective (after configuring it). Cheers, MArtin From ben+python at benfinney.id.au Tue Mar 20 07:18:39 2012 From: ben+python at benfinney.id.au (Ben Finney) Date: Tue, 20 Mar 2012 22:18:39 +1100 Subject: pypi and dependencies References: Message-ID: <87bonrmsfk.fsf@benfinney.id.au> Andrea Crotti writes: > When I publish something on Pypi, is there a way to make it fetch the list > of dependencies needed by my project automatically? > > It would be nice to have it in the Pypi page, without having to look at the > actual code.. Sadly, no. The metadata available for packages on PyPI does not include information about the dependencies. (I'd love to be wrong about that, but I'm pretty certain that for most, if not all, packages that's the case.) > Any other possible solution? All the solutions I've seen involve fetching the full package in order to unpack it and *then* parse it for dependencies. This is very sub-optimal, and I believe people are working on it; but fixing it will at least require adjustment to all existing packages that don't have dependencies in their metadata. -- \ ?Some people have a problem, and they think ?I know, I'll use | `\ Perl!?. Now they have some number of problems but they're not | _o__) sure whether it's a string or an integer.? ?Benno Rice, 2011 | Ben Finney From ben+python at benfinney.id.au Tue Mar 20 07:21:02 2012 From: ben+python at benfinney.id.au (Ben Finney) Date: Tue, 20 Mar 2012 22:21:02 +1100 Subject: Distribution References: <33044d51-c481-4796-a722-406f412cf994@x7g2000pbi.googlegroups.com> Message-ID: <877gyfmsbl.fsf@benfinney.id.au> "prince.pangeni" writes: > I am doing a simulation project using Python. In my project, I want > to use some short of distribution to generate requests to a server. What is a distribution? That term already means something in Python jargon, and it doesn't match the rest of your use case. So what do you mean by ?distribution?? Maybe we can find a less confusing term. -- \ ?I used to think that the brain was the most wonderful organ in | `\ my body. Then I realized who was telling me this.? ?Emo Philips | _o__) | Ben Finney From robert.kern at gmail.com Tue Mar 20 08:00:50 2012 From: robert.kern at gmail.com (Robert Kern) Date: Tue, 20 Mar 2012 12:00:50 +0000 Subject: Distribution In-Reply-To: <877gyfmsbl.fsf@benfinney.id.au> References: <33044d51-c481-4796-a722-406f412cf994@x7g2000pbi.googlegroups.com> <877gyfmsbl.fsf@benfinney.id.au> Message-ID: On 3/20/12 11:21 AM, Ben Finney wrote: > "prince.pangeni" writes: > >> I am doing a simulation project using Python. In my project, I want >> to use some short of distribution to generate requests to a server. > > What is a distribution? That term already means something in Python > jargon, and it doesn't match the rest of your use case. > > So what do you mean by ?distribution?? Maybe we can find a less > confusing term. Judging from the context, he means a probability distribution. -- Robert Kern "I have come to believe that the whole world is an enigma, a harmless enigma that is made terrible by our own mad attempt to interpret it as though it had an underlying truth." -- Umberto Eco From andrea.crotti.0 at gmail.com Tue Mar 20 08:01:47 2012 From: andrea.crotti.0 at gmail.com (Andrea Crotti) Date: Tue, 20 Mar 2012 12:01:47 +0000 Subject: pypi and dependencies In-Reply-To: <87bonrmsfk.fsf@benfinney.id.au> References: <87bonrmsfk.fsf@benfinney.id.au> Message-ID: <4F6871AB.6030401@gmail.com> On 03/20/2012 11:18 AM, Ben Finney wrote: > Andrea Crotti writes: > >> When I publish something on Pypi, is there a way to make it fetch the list >> of dependencies needed by my project automatically? >> >> It would be nice to have it in the Pypi page, without having to look at the >> actual code.. > Sadly, no. The metadata available for packages on PyPI does not include > information about the dependencies. > > (I'd love to be wrong about that, but I'm pretty certain that for most, > if not all, packages that's the case.) > >> Any other possible solution? > All the solutions I've seen involve fetching the full package in order > to unpack it and *then* parse it for dependencies. > > This is very sub-optimal, and I believe people are working on it; but > fixing it will at least require adjustment to all existing packages that > don't have dependencies in their metadata. > Yes that's not so nice, many projects write clearly the dependencies in the README file, but that's annoying because it might get outdated. And it's also sad that it's not automatically fetched from setuptools, because it's just python setup.py egg-info && cat package.egg-info/requirements.txt to actually extract them. Should I file a bug maybe or is completely not feasible? From donald.stufft at gmail.com Tue Mar 20 08:13:36 2012 From: donald.stufft at gmail.com (Donald Stufft) Date: Tue, 20 Mar 2012 08:13:36 -0400 Subject: pypi and dependencies In-Reply-To: <4F6871AB.6030401@gmail.com> References: <87bonrmsfk.fsf@benfinney.id.au> <4F6871AB.6030401@gmail.com> Message-ID: <899C4AC6C8EB4E3FA0393A24FA96E690@gmail.com> packaging (in 3.3) and distutils2 (2.x-3.2) is a new metadata format for python packages. It gets rid of setup.py and it includes a way to specify the requirements that your package needs. This will show up on PyPI/Crate. On Tuesday, March 20, 2012 at 8:01 AM, Andrea Crotti wrote: > On 03/20/2012 11:18 AM, Ben Finney wrote: > > Andrea Crotti writes: > > > > > When I publish something on Pypi, is there a way to make it fetch the list > > > of dependencies needed by my project automatically? > > > > > > It would be nice to have it in the Pypi page, without having to look at the > > > actual code.. > > > > > > > Sadly, no. The metadata available for packages on PyPI does not include > > information about the dependencies. > > > > (I'd love to be wrong about that, but I'm pretty certain that for most, > > if not all, packages that's the case.) > > > > > Any other possible solution? > > All the solutions I've seen involve fetching the full package in order > > to unpack it and *then* parse it for dependencies. > > > > This is very sub-optimal, and I believe people are working on it; but > > fixing it will at least require adjustment to all existing packages that > > don't have dependencies in their metadata. > > > > > Yes that's not so nice, many projects write clearly the dependencies in > the README file, > but that's annoying because it might get outdated. > > And it's also sad that it's not automatically fetched from setuptools, > because it's just > > python setup.py egg-info && cat package.egg-info/requirements.txt > > to actually extract them. > Should I file a bug maybe or is completely not feasible? > -- > http://mail.python.org/mailman/listinfo/python-list > > -------------- next part -------------- An HTML attachment was scrubbed... URL: From albert at spenarnc.xs4all.nl Tue Mar 20 08:20:02 2012 From: albert at spenarnc.xs4all.nl (Albert van der Horst) Date: 20 Mar 2012 12:20:02 GMT Subject: Python is readable References: <4f612b19$0$1379$4fafbaef@reader2.news.tin.it> <4f668a9d$0$29981$c3e8da3$5496439d@news.astraweb.com> Message-ID: In article , Chris Angelico wrote: >On Mon, Mar 19, 2012 at 12:23 PM, Steven D'Aprano > wrote: >> On Mon, 19 Mar 2012 09:02:06 +1100, Chris Angelico wrote: >> >>> On Mon, Mar 19, 2012 at 8:30 AM, John Ladasky >>> wrote: >>>> What I would say is that, when PROGRAMMERS look at Python code for the >>>> first time, they will understand what it does more readily than they >>>> would understand other unfamiliar programming languages. =A0That has >>>> value. >>> >>> This is something that's never truly defined. >> >> I'm sorry, I don't understand what part of John's sentence you mean by >> "this". "Programmers"? "Value"? "Understand"? > >I should have rewritten that into the next paragraph. Anyhow. Further >explanation below. > >>> Everyone talks of how this >>> language or that language is readable, but if you mean that you can look >>> at a line of code and know what *that line* does then Python suffers >>> badly and assembly language wins out; >> >> This is at least the second time you've alleged that assembly language is >> more readable than Python. I think you're a raving nutter, no offence >> Chris :-) > >None taken; guilty as charged. And unashamedly so. With that dealt >with, though: My calling assembly "readable" is a form of argument by >drawing to logical, but absurd, conclusion - by the given definition >of readability, assembly is readable, ergo the definition sucks. >(That's a term all logicians use, you know. Proper and formal jargon.) > >> Assignment (name binding) is close to the absolute simplest thing you can >> do in a programming language. In Python, the syntax is intuitive to >> anyone who has gone through high school, or possibly even primary school, >> and been introduced to the equals sign. >> >> x =3D 1234 >> y =3D "Hello" > >Not quite. In mathematics, "x =3D 1234" is either a declaration of fact, >or a statement that can be either true or false. In mathematics, "x =3D >x + 1" is absurd and/or simply false. That's why Pascal has its :=3D >operator, supposed to be read as "becomes" and not "equals". IMHO this >is simply proof of one of the differences between programming and >mathematics. > >> I don't know about anyone else, but I wouldn't have guessed that the way >> to get x=3D1234 was with "x dw 1234". > >Except that it's not quite the same thing. That 8086 Assembly >statement is more like the C statement: >int x=3D1234; >The nearest equivalent of assignment is: >mov x,1234 I tried to mentally translate that to my ciasdis assembler syntax and discovered that there is no instruction in the 8086 for that. It would require using a scratch register like AX. In my very precise ciasdis assembler syntax it would be 1] XXXXXX: DL 0 MOVI, X| R| AX| 1234 IL, MOV, X| F| R| [AX] XXXXXX L, If you were restricted to the 8086, (not 80386 or better) you could not have chosen AX, and you would have used BX instead. [ The first MOVI, could be replaced by a LEA, instruction LEA, AX'| MEM| XXXXXX L, (Go figure!) ] So a realistic fragment could have been PUSH|X BX, MOVI, X| R| BX| 1234 IL,, MOV, X| F| R| [BX] XXXXXX L, POP|X BX, The real unreadability comes from the fact that the novice would ask herself why on earth the BX register was freed while the AX register was free to use. And she is lucky, because no flags were harmed in this sequence, another pitfall. You can't blame me for the unreadibility of the ciasdis-syntax. It merely reflects the abomination that the 8086/80386/Pentium is. Bottom line. A comparison between a HLL where the goal is abstraction and assembly where the goal is precision and control, is unproductive. And if you insist to do it, you better be a real expert. > >And that's where the nub of the question is. How well is sufficiently >well? Clearly you do not require your code to be comprehensible to a >non-programmer, or you would not write code at all. If you don't >demand that the reader learn basic keywords of the language, then it's >equally impossible to expect them to comprehend your code. If you're >writing production code, I see no reason to avoid language features >like Python's list comps, Pike's %{ %} sprintf codes, or C's pointer >arithmetic, just because they can confuse people. Learn the language, >THEN start hacking on the code. Can we just agree, that it is a compromise? > >ChrisA 1] ciasdis.html on the site in my sig. Groetjes Albert -- -- Albert van der Horst, UTRECHT,THE NETHERLANDS Economic growth -- being exponential -- ultimately falters. albert at spe&ar&c.xs4all.nl &=n http://home.hccnet.nl/a.w.m.van.der.horst From robert.kern at gmail.com Tue Mar 20 08:52:46 2012 From: robert.kern at gmail.com (Robert Kern) Date: Tue, 20 Mar 2012 12:52:46 +0000 Subject: Distribution In-Reply-To: <33044d51-c481-4796-a722-406f412cf994@x7g2000pbi.googlegroups.com> References: <33044d51-c481-4796-a722-406f412cf994@x7g2000pbi.googlegroups.com> Message-ID: On 3/20/12 4:31 AM, prince.pangeni wrote: > Hi all, > I am doing a simulation project using Python. In my project, I want > to use some short of distribution to generate requests to a server. > The request should have two distributions. One for request arrival > rate (should be poisson) and another for request mix (i.e. out of the > total requests defined in request arrival rate, how many requests are > of which type). > Example: Suppose the request rate is - 90 req/sec (generated using > poisson distribution) Just a note on terminology to be sure we're clear: a Poisson *distribution* models the number of arrivals in a given time period if the events are from a Poisson *process* with a given mean rate. To model the inter-event arrival times, you use an exponential distribution. If you want to handle events individually in your simulation, you will need to use the exponential distribution to figure out the exact times for each. If you are handling all of the events in each second "in bulk" without regard to the exact times or ordering within that second, then you can use a Poisson distribution. > at time t and we have 3 types of requests (i.e. > r1, r2, r2). The request mix distribution output should be similar to: > {r1 : 50 , r2 : 30 , r3 : 10} (i.e. out of 90 requests - 50 are of r1 > type, 30 are of r2 type and 10 are of r3 type). > As I an new to python distribution module, I am not getting how to > code this situation. Please help me out for the same. I am going to assume that you want to handle each event independently. A basic strategy is to keep a time variable starting at 0 and use a while loop until the time reaches the end of the simulation time. Increment it using a draw from the exponential distribution each loop. Each iteration of the loop is an event. To determine the kind of event, you will need to draw from a weighted discrete distribution. What you want to do here is to do a cumulative sum of the weights, draw a uniform number from 0 to the total sum, then use bisect to find the item that matches. import bisect import random # Use a seeded PRNG for repeatability. Use the methods on the Random # object rather than the functions in the random module. prng = random.Random(1234567890) avg_rate = 90.0 # reqs/sec kind_weights = [50.0, 30.0, 10.0] kind_cumsum = [sum(kind_weights[:i+1]) for i in range(len(kind_weights))] kind_max = kind_cumsum[-1] max_time = 10.0 # sec t = 0.0 # sec events = [] # (t, kind) while t < max_time: dt = prng.expovariate(avg_rate) u = prng.uniform(0.0, kind_max) kind = bisect.bisect_left(kind_cumsum, u) events.append((t, kind)) t += dt -- Robert Kern "I have come to believe that the whole world is an enigma, a harmless enigma that is made terrible by our own mad attempt to interpret it as though it had an underlying truth." -- Umberto Eco From steve+comp.lang.python at pearwood.info Tue Mar 20 09:54:45 2012 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 20 Mar 2012 13:54:45 GMT Subject: Eclipse, C, and Python References: <6023956.2302.1332223250728.JavaMail.geo-discussion-forums@ynlp3> Message-ID: <4f688c25$0$29981$c3e8da3$5496439d@news.astraweb.com> On Mon, 19 Mar 2012 23:00:50 -0700, Richard Medina Calderon wrote: > Hello Forum. I have installed Python comnpiler in Eclipse Classic for > Windows. After a while I have installed the C compiler. However, somehow > now when I try to run my code in Python it shows me for default Ant > > Run -->Ant Build > > I switched my workspace but still. Do you know how to solve this?.. This is an Eclipse problem, not a Python problem. Most people here don't use Eclipse. You might have better luck asking on a forum for Eclipse. -- Steven From alister.ware at ntlworld.com Tue Mar 20 10:39:22 2012 From: alister.ware at ntlworld.com (alister ware) Date: Tue, 20 Mar 2012 14:39:22 GMT Subject: s_push parser stack overflow References: Message-ID: On Tue, 20 Mar 2012 04:30:51 +0000, MRAB wrote: > On 20/03/2012 03:19, ????? ??????? wrote: >> Hi. >> Sorry of my english :-) >> >> code: >> print >> (((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((0)))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))" >> >> message from python is: s_push parser stack overflow >> >> Can i configure phyton to solve this problem without change MAXSTACK in >> " parser.c" and re-build the python? > > A quick look at parser.h tells me that it's a hard-coded limit: > > typedef struct { > stackentry *s_top; /* Top entry */ > stackentry s_base[MAXSTACK];/* Array of stack entries */ > /* NB The stack grows down */ > } stack; But why such an obscure print statement anyway? is it purely to show the issue or is there some actual reason behind it? -- divorce, n: A change of wife. From marksmensocom at yahoo.com Tue Mar 20 10:59:05 2012 From: marksmensocom at yahoo.com (Joi Mond) Date: Tue, 20 Mar 2012 07:59:05 -0700 (PDT) Subject: code for computing and printing list of combinations Message-ID: <1332255545.34960.YahooMailClassic@web126001.mail.ne1.yahoo.com> To All, Can someone help me with the proper code to compute combinations for n=7, r=5 for the following list of numbers: 7, 8, 10, 29, 41, 48, 55. There should be 21 combination. Also once there list is made can a code be written to add (sum) each of the set of five number in the the list. For example list: 8, 10, 29, 48, 55, = 150. Thanks -------------- next part -------------- An HTML attachment was scrubbed... URL: From __peter__ at web.de Tue Mar 20 11:20:32 2012 From: __peter__ at web.de (Peter Otten) Date: Tue, 20 Mar 2012 16:20:32 +0100 Subject: code for computing and printing list of combinations References: <1332255545.34960.YahooMailClassic@web126001.mail.ne1.yahoo.com> Message-ID: Joi Mond wrote: > Can someone help me with the proper code to compute combinations for n=7, > r=5 for the following list of numbers: 7, 8, 10, 29, 41, 48, 55. There > should be 21 combination. Also once there list is made can a code be > written to add (sum) each of the set of five number in the the list. For > example list: 8, 10, 29, 48, 55, = 150. Thanks >>> [sum(x) for x in itertools.combinations([7,8,10,29,41,48,55], 5)] [95, 102, 109, 114, 121, 128, 133, 140, 147, 159, 135, 142, 149, 161, 180, 136, 143, 150, 162, 181, 183] Best wishes to your teacher... From python.list at tim.thechases.com Tue Mar 20 11:33:10 2012 From: python.list at tim.thechases.com (Tim Chase) Date: Tue, 20 Mar 2012 10:33:10 -0500 Subject: code for computing and printing list of combinations In-Reply-To: <1332255545.34960.YahooMailClassic@web126001.mail.ne1.yahoo.com> References: <1332255545.34960.YahooMailClassic@web126001.mail.ne1.yahoo.com> Message-ID: <4F68A336.4060406@tim.thechases.com> On 03/20/12 09:59, Joi Mond wrote: > To All, Can someone help me with the proper code to compute > combinations for n=7, r=5 for the following list of numbers: > 7, 8, 10, 29, 41, 48, 55. There should be 21 combination. Also > once there list is made can a code be written to add (sum) > each of the set of five number in the the list. For example > list: 8, 10, 29, 48, 55, = 150. Thanks Sounds like you want to read up on itertools.combinations() and the sum() function. http://docs.python.org/library/itertools.html#itertools.combinations or >>> import itertools >>> help(itertools.combinations) This sounds like a homework problem, so I won't hand you the answer, but you pass your list to combinations() with the grouping-size (r). You then iterate over the results of that, and use sum() on the results. -tkc From technovegas at gmail.com Tue Mar 20 12:51:09 2012 From: technovegas at gmail.com (Fabric Paul) Date: Tue, 20 Mar 2012 09:51:09 -0700 (PDT) Subject: Fabric Engine v1.0 released under AGPL Message-ID: <549b3a51-5bd9-4ea1-aae0-8f7b09206046@tx8g2000pbc.googlegroups.com> Hi everyone - just letting you know that we released v1.0 of Fabric Engine today. We've open-sourced the core under AGPL, so I hope that gives you an incentive to get started with high-performance for Python :) http://fabricengine.com/technology/benchmarks/ - to give you an idea of the kind of performance possible. Most of these are with node, but the core engine is the same - we just bound it to Python. For those of you using Python on the desktop (particularly if you're working with 3D), we've started a closed beta on a PyQt framework - you can see more here: http://fabricengine.com/2012/03/pyqt-framework-for-fabric-engine/ - email beta at fabricengine.com if you'd like to take part in the testing program. Thanks for your time, Paul From nathan.alexander.rice at gmail.com Tue Mar 20 12:55:07 2012 From: nathan.alexander.rice at gmail.com (Nathan Rice) Date: Tue, 20 Mar 2012 12:55:07 -0400 Subject: Python is readable In-Reply-To: References: <4f612b19$0$1379$4fafbaef@reader2.news.tin.it> <8e72d74f-c844-4de3-8a37-f6b1fdc2291f@y27g2000yqy.googlegroups.com> <50e9ceec-40f1-4ead-b2b6-87328b30d084@ow8g2000pbc.googlegroups.com> Message-ID: Just to troll the discussion a little bit more... On Sun, Mar 18, 2012 at 6:02 PM, Chris Angelico wrote: > On Mon, Mar 19, 2012 at 8:30 AM, John Ladasky wrote: >> What I would say is that, when PROGRAMMERS look at Python code for the >> first time, they will understand what it does more readily than they >> would understand other unfamiliar programming languages. ?That has >> value. > > This is something that's never truly defined. Everyone talks of how > this language or that language is readable, but if you mean that you > can look at a line of code and know what *that line* does, then Python > suffers badly and assembly language wins out; but if you mean that you > should be able to glance over an entire function and comprehend its > algorithm, then I have yet to see any language in which it's not > plainly easy to write bad code. Even with good code, anything more > than trivial can't be eyeballed in that way - if you could, what would > docstrings be for? I agree, docstrings/code comments are a pretty obvious indication that code (as it exists currently) fails as a human communication medium. I suppose that I could make an exception for elaboration on statement with subtle implications. This seems like something people should think more about fixing. > Really, the metric MUST be Python programmers. Intuitiveness is of > value, but readability among experienced programmers is far more > useful. If I write a whole lot of code today, and next year I'm dead > and someone else has replaced me, I frankly don't mind if he has to > learn the language before he can grok my code. I _do_ mind if, even > after he's learned the language, he can't figure out what my code's > doing; and that's where Python's placed itself at about the right > level - not so high that it's all in airy-fairy conceptual work, but > not so low that it gets bogged down. There's a handful of other > languages that are similarly placed, and they're the languages that I > would call "readable". In mathematics, when you perform global optimization you must be willing to make moves in the solution space that may result in a temporary reduction of your optimality condition. If you just perform naive gradient decent, only looking to the change that will induce the greatest immediate improvement in optimality, you will usually end up orbiting around a solution which is not globally optimal. I mention this because any readability or usability information gained using trained programmers is simultaneously measuring the readability or usability and its conformance to the programmer's cognitive model of programming. The result is local optimization around the current-paradigm minimum. This is why we have so many nearly identical curly brace C-like languages. In my opinion, language readability and usability should be determined based on the following tests: - Given users with no programming experience: -- What is the probability that they can correctly guess the result of a program, and how long does it take? -- What is the probability that they can take a program and correctly modify it to change its output to another specified output, or modify it to support another input representation, and how long does it take? - Given users with no programming experience who are provided with a controlled training period: -- What is the probability that they can produce a program that correctly implements a simple, completely described algorithm for solving a puzzle or winning a game, and how long does it take? - Given users with previous (but not extensive) programming experience who are provided with a controlled training period: -- What is the probability that they can produce a program that correctly implements a simple, partially described algorithm for solving a puzzle or winning a game, and how long does it take? -- What is the probability that they can produce a program that correctly implements a complex, completely described algorithm for solving a puzzle or winning a game, and how long does it take? It would probably also be worth examining user behavior relating to code organization and composition under a variety of circumstances. It seems likely that if proper organization and composition are intuitive, productivity would scale well with program size. > Here's an analogy: One statement (aka line of code, etc) corresponds > to one sentence in English. Massive one-liners are like some of the > sentences in Paul's epistles; assembly language is like "The cat sat > on the mat". Both are valid; both are hard to read. This is one of my gripes with the dogmatic application of the "break it into multiple statements" mantra of Python. Not only are you forced to use generators to maintain semantic equivalence in many cases, in some cases a partial statement fragment doesn't have any intuitive meaning. The result is that readers are forced to hold the value of intermediate_variable in their head while reading another statement, then translate the statement to the conceptually complete form. A statement should be an encoding from a conceptual space to a operation space, and ideally the two should be as similar as possible. If a concept is atomic, it should not be comprised of multiple statements. From moky.math at gmail.com Tue Mar 20 13:00:25 2012 From: moky.math at gmail.com (Laurent Claessens) Date: Tue, 20 Mar 2012 18:00:25 +0100 Subject: Distribution In-Reply-To: <877gyfmsbl.fsf@benfinney.id.au> References: <33044d51-c481-4796-a722-406f412cf994@x7g2000pbi.googlegroups.com> <877gyfmsbl.fsf@benfinney.id.au> Message-ID: Il 20/03/2012 12:21, Ben Finney ha scritto: > "prince.pangeni" writes: > >> I am doing a simulation project using Python. In my project, I want >> to use some short of distribution to generate requests to a server. I guess scipy is also available in plain python (didn't check), but the following works with Sage : ---------------------------------------------------------------------- | Sage Version 4.8, Release Date: 2012-01-20 | | Type notebook() for the GUI, and license() for information. | ---------------------------------------------------------------------- sage: from scipy import stats sage: X=stats.poisson.rvs sage: X(4) 5 sage: X(4) 2 sage: X(4) 3 Hope it helps Laurent From steve+comp.lang.python at pearwood.info Tue Mar 20 13:48:11 2012 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 20 Mar 2012 17:48:11 GMT Subject: Python is readable References: <4f612b19$0$1379$4fafbaef@reader2.news.tin.it> <8e72d74f-c844-4de3-8a37-f6b1fdc2291f@y27g2000yqy.googlegroups.com> <50e9ceec-40f1-4ead-b2b6-87328b30d084@ow8g2000pbc.googlegroups.com> Message-ID: <4f68c2db$0$29981$c3e8da3$5496439d@news.astraweb.com> On Tue, 20 Mar 2012 12:55:07 -0400, Nathan Rice wrote: > This is one of my gripes with the dogmatic application of the "break it > into multiple statements" mantra of Python. I must admit I don't recognise that one, unless you're talking about "not everything needs to be a one liner". > Not only are you forced to > use generators to maintain semantic equivalence in many cases, in some > cases a partial statement fragment doesn't have any intuitive meaning. > The result is that readers are forced to hold the value of > intermediate_variable in their head while reading another statement, > then translate the statement to the conceptually complete form. A > statement should be an encoding from a conceptual space to a operation > space, and ideally the two should be as similar as possible. > If a concept is atomic, it should not be comprised of multiple > statements. Perhaps you could give some examples (actual or contrived) of stuff where "breaking it into multiple statements" is a bad thing? -- Steven From tjreedy at udel.edu Tue Mar 20 14:09:11 2012 From: tjreedy at udel.edu (Terry Reedy) Date: Tue, 20 Mar 2012 14:09:11 -0400 Subject: Python is readable In-Reply-To: References: <4f612b19$0$1379$4fafbaef@reader2.news.tin.it> <8e72d74f-c844-4de3-8a37-f6b1fdc2291f@y27g2000yqy.googlegroups.com> <50e9ceec-40f1-4ead-b2b6-87328b30d084@ow8g2000pbc.googlegroups.com> Message-ID: On 3/20/2012 12:55 PM, Nathan Rice wrote: > I agree, docstrings/code comments are a pretty obvious indication that > code (as it exists currently) fails as a human communication medium. The fact that scientific journal articles start with a documentation string called an abstract does not indicate that scientific English fails as a human communication medium. Function docstrings say what the function does and how to use it without reading the code. They can be pulled out and displayed elsewhere. They also guide the reading of the code. Abstracts serve the same functions. -- Terry Jan Reedy From michael at stroeder.com Tue Mar 20 14:49:55 2012 From: michael at stroeder.com (=?UTF-8?B?TWljaGFlbCBTdHLDtmRlcg==?=) Date: Tue, 20 Mar 2012 19:49:55 +0100 Subject: Enforcing hash randomization (was: [RELEASED] Second release candidates for Python 2.6.8, 2.7.3, 3.1.5, and 3.2.3) In-Reply-To: References: Message-ID: Benjamin Peterson wrote: > Hash randomization causes the iteration order of dicts and sets to be > unpredictable and differ across Python runs. Python has never guaranteed > iteration order of keys in a dict or set, and applications are advised to never > rely on it. Historically, dict iteration order has not changed very often across > releases and has always remained consistent between successive executions of > Python. Thus, some existing applications may be relying on dict or set ordering. > Because of this and the fact that many Python applications which don't accept > untrusted input are not vulnerable to this attack, in all stable Python releases > mentioned here, HASH RANDOMIZATION IS DISABLED BY DEFAULT. There are two ways to > enable it. The -R commandline option can be passed to the python executable. It > can also be enabled by setting an environmental variable PYTHONHASHSEED to > "random". (Other values are accepted, too; pass -h to python for complete > description.) I wonder how I could enforce hash randomization from within a Python app without too much hassle. I'd like to avoid having to rely on sys-admins doing the right thing when installing my web2ldap. I guess os.environ['PYTHONHASHSEED'] = 'random' before forking a process would be a solution. But is there another way? Ciao, Michael. From nathan.alexander.rice at gmail.com Tue Mar 20 15:28:25 2012 From: nathan.alexander.rice at gmail.com (Nathan Rice) Date: Tue, 20 Mar 2012 15:28:25 -0400 Subject: Python is readable In-Reply-To: References: <4f612b19$0$1379$4fafbaef@reader2.news.tin.it> <8e72d74f-c844-4de3-8a37-f6b1fdc2291f@y27g2000yqy.googlegroups.com> <50e9ceec-40f1-4ead-b2b6-87328b30d084@ow8g2000pbc.googlegroups.com> Message-ID: >> This is one of my gripes with the dogmatic application of the "break it >> into multiple statements" mantra of Python. > > I must admit I don't recognise that one, unless you're talking about "not > everything needs to be a one liner". > ... > Perhaps you could give some examples (actual or contrived) of stuff where > "breaking it into multiple statements" is a bad thing? One example is performing a series of transformations on a collection of data, with the intent of finding an element of that collection that satisfies a particular criterion. If you separate out the individual transformations, you need to understand generators or you will waste space and perform many unnecessary calculations. If you only ever do a single transformation with a clear conceptual meaning, you could create a "master transformation function," but what if you have a large number of potential permutations of that function? What if you are composing three or four functions, each of which is conditional on the data? If you extract things from a statement and assign them somewhat arbitrary names, you've just traded horizontal bloat for vertical bloat (with a net increase in volume), while forcing a reader to scan back and forth to different statements to understand what is happening. To steal a line from Einstein, "Make things as simple as possible, but not simpler" >> I agree, docstrings/code comments are a pretty obvious indication that >> code (as it exists currently) fails as a human communication medium. > > > The fact that scientific journal articles start with a documentation string > called an abstract does not indicate that scientific English fails as a > human communication medium. Function docstrings say what the function does > and how to use it without reading the code. They can be pulled out and > displayed elsewhere. They also guide the reading of the code. Abstracts > serve the same functions. A paper, with topic introduction, methods exposition, data/results description and discussion is a poor analog to a function. I would compare the abstract of a scientific paper to the overview section of a program's documentation. The great majority of the docstrings I see are basically signature rehashes with added type information and assertions, followed by a single sentence English gloss-over. If the code were sufficiently intuitive and expressive, that would be redundant. Of course, there will always be morbidly obese functions and coders that like to wax philosophical or give history lessons in comments. Also, because of Sphinx, it is very common in the Python community weave documents and code together in a way that is convenient for authors but irritating for readers. I personally would prefer not to have to scroll past 100 lines of a tutorial with examples, tests and what not in order to go from one function to another. It would be really awesome if everyone used links to that material in docstrings, and the default sphinx theme created an inline collapsible iframe that included that material for the HTML version. Don't get me wrong, I adore Sphinx, the problem here is people who are lazy or don't know the right way to structure docs. From tjreedy at udel.edu Tue Mar 20 16:01:08 2012 From: tjreedy at udel.edu (Terry Reedy) Date: Tue, 20 Mar 2012 16:01:08 -0400 Subject: Python is readable In-Reply-To: References: <4f612b19$0$1379$4fafbaef@reader2.news.tin.it> <8e72d74f-c844-4de3-8a37-f6b1fdc2291f@y27g2000yqy.googlegroups.com> <50e9ceec-40f1-4ead-b2b6-87328b30d084@ow8g2000pbc.googlegroups.com> Message-ID: On 3/20/2012 3:28 PM, Nathan Rice wrote: >>> This is one of my gripes with the dogmatic application of the "break it >>> into multiple statements" mantra of Python. >> >> I must admit I don't recognise that one, unless you're talking about "not >> everything needs to be a one liner". >> ... >> Perhaps you could give some examples (actual or contrived) of stuff where >> "breaking it into multiple statements" is a bad thing? > > One example is performing a series of transformations on a collection > of data, with the intent of finding an element of that collection that > satisfies a particular criterion. If you separate out the individual > transformations, you need to understand generators or you will waste > space and perform many unnecessary calculations. If you only ever do > a single transformation with a clear conceptual meaning, you could > create a "master transformation function," but what if you have a > large number of potential permutations of that function? What if you > are composing three or four functions, each of which is conditional on > the data? If you extract things from a statement and assign them > somewhat arbitrary names, you've just traded horizontal bloat for > vertical bloat (with a net increase in volume), while forcing a reader > to scan back and forth to different statements to understand what is > happening. > > To steal a line from Einstein, "Make things as simple as possible, but > not simpler" > >>> I agree, docstrings/code comments are a pretty obvious indication that >>> code (as it exists currently) fails as a human communication medium. >> >> >> The fact that scientific journal articles start with a documentation string >> called an abstract does not indicate that scientific English fails as a >> human communication medium. Function docstrings say what the function does >> and how to use it without reading the code. They can be pulled out and >> displayed elsewhere. They also guide the reading of the code. Abstracts >> serve the same functions. > > A paper, with topic introduction, methods exposition, data/results > description and discussion is a poor analog to a function. I would > compare the abstract of a scientific paper to the overview section of > a program's documentation. The great majority of the docstrings I see > are basically signature rehashes with added type information and > assertions, followed by a single sentence English gloss-over. If the > code were sufficiently intuitive and expressive, that would be > redundant. Of course, there will always be morbidly obese functions > and coders that like to wax philosophical or give history lessons in > comments. Both abstracts and doc strings are designed to be and are read independently of the stuff they summarize. Perhaps you do not use help(obj) as often as some other people do. > Also, because of Sphinx, it is very common in the Python community > weave documents and code together in a way that is convenient for > authors but irritating for readers. I personally would prefer not to > have to scroll past 100 lines of a tutorial with examples, tests and > what not in order to go from one function to another. If I understand you, some devs agree. Hence the increasing use of How-to docs with tutorial and example material for a module separate from the reference entries in its section of the Library Reference. -- Terry Jan Reedy From gandalf at shopzeus.com Tue Mar 20 16:12:12 2012 From: gandalf at shopzeus.com (Laszlo Nagy) Date: Tue, 20 Mar 2012 21:12:12 +0100 Subject: urllib.urlretrieve never returns??? In-Reply-To: <4F682CDC.5000703@shopzeus.com> References: <4F649BFC.1080601@shopzeus.com> <4F66E687.2050008@shopzeus.com> <4f67c09b$0$29981$c3e8da3$5496439d@news.astraweb.com> <4F682CDC.5000703@shopzeus.com> Message-ID: <4F68E49C.2060000@shopzeus.com> 2012.03.20. 8:08 keltez?ssel, Laszlo Nagy ?rta: > Here you can find the example program and the original post. > > http://code.activestate.com/lists/python-list/617894/ >> >> I gather you are running urlretrieve in a separate thread, inside a GUI? > Yes. >> >> I have learned that whenever I have inexplicable behaviour in a >> function, >> I should check my assumptions. In this case, (1) are you sure you have >> the right urlretrieve, and (2) are you sure that your self.Log() method >> is working correctly? Just before the problematic call, do this: >> >> # was: >> fpath = urllib.urlretrieve(imgurl)[0] >> >> # becomes: >> print(urllib.__file__, urlretrieve) >> self.Log(urllib.__file__, urlretrieve) >> fpath = urllib.urlretrieve(imgurl)[0] > I called self.Log() after each line, and also from a general "except:" > clause. Definitely, the line after urlretrieve is not executed, and no > exception is raised. Number of threads goes up (visible from task > manager). > > It is true that the program uses another module that uses the socket > module and multiple threads. (These are written in pure python.) > > If I remove the other module, then there is no error, however it > renders the application useless. If I start the program with a console > (e.g. with python.exe instead of pythonw.exe) then it works. Looks > like opening a console solves the problem, although nothing is ever > printed on the console. >> and ensure that you haven't accidentally shadowed them with something >> unexpected. Does the output printed to the console match the output >> logged? > Well, this cannot be tested. If there is a console, then there is no > problem. >> >> What happens if you take the call to urlretrieve out of the thread and >> call it by hand? > Then it works. >> Run urllib.urlretrieve(imgurl) directly in the >> interactive interpreter. Does it still hang forever? > Then it works perfectly. >> >> When you say it "never" returns, do you mean *never* or do you mean "I >> gave up waiting after five minutes"? What happens if you leave it to run >> all day? > I did not try that. But I have already set socket timeout to 10 > seconds, and definitely it is not waiting for a response from the server. >> >> How big are the files you are trying to retrieve? > 34 KB >> Try retrieving a really small file. Then try retrieving a >> non-existent file. > Good point. I'll try to retrieve a nonexistent file when I get home. :) Today I got a different error message printed on console (program started with python.exe) Unhandled exception in thread started by >>Unhandled exception in thread started by >>Unhandled exception in thread started by >>Unhandled exception in thread started by Traceback (most recent call last): Traceback (most recent call last): Traceback (most recent call last): >> File "C:\Python\Projects\Warehouserclient_v3\locedit.py", line 917, in GetThumbnail File "C:\Python\Projects\Warehouserclient_v3\locedit.py", line 917, in GetThumbnail File "C:\Python\Projects\Warehouserclient_v3\locedit.py", line 917, in GetThumbnail sys.excepthook is missing Traceback (most recent call last): I have never seen a traceback like this before. I didn't install any excepthook myself. Program is using wxPython, socket, threads, threading, PIL. Here is something even more strange. If I click on the button three times, then absolutely nothing gets printed on stdout. However, if I close the program with file/exit (actually, calling wx.PySimpleApp.ExitMainLoop) then suddenly three stack traces are printed on stdout, all lines mixed up: Unhandled exception in thread started by >>Unhandled exception in thread started by Unhandled exception in thread started by >>Unhandled exception in thread started by Unhandled exception in thread started by >>Traceback (most recent call last): >>Traceback (most recent call last): >>Traceback (most recent call last): File "C:\Python\Projects\Warehouserclient_v3\locedit.py", line 917, in GetThumbnail Traceback (most recent call last): File "C:\Python\Projects\Warehouserclient_v3\locedit.py", line 917, in GetThumbnail Traceback (most recent call last): File "C:\Python\Projects\Warehouserclient_v3\locedit.py", line 917, in GetThumbnail File "C:\Python\Projects\Warehouserclient_v3\locedit.py", line 917, in GetThumbnail File "C:\Python\Projects\Warehouserclient_v3\locedit.py", line 917, in GetThumbnail self.Log(traceback.format_exc()) self.Log(traceback.format_exc()) self.Log(traceback.format_exc()) AttributeErrorself.Log(traceback.format_exc()) AttributeErrorself.Log(traceback.format_exc()) AttributeError: AttributeError: AttributeError: C:\Python\Projects\Warehouserclient_v3> And the last attributerror doesn't tell what attribute is missing. Probably I'll have to use a different library (pycurl, for example). But the error itself is getting more interesting. Also tried to use an invalid file (that should return with HTTP 404 not found) but the effect is exactly the same. Nothing is printed on stdout until I try to close the program (stop wxPython's mainloop). Then all previously threads throw an AttributeError and all of them print a stack trace (at the same time, lines mixed up). I'll be experimenting with pyCurl now. Thanks, Laszlo From nagle at animats.com Tue Mar 20 16:18:24 2012 From: nagle at animats.com (John Nagle) Date: Tue, 20 Mar 2012 13:18:24 -0700 Subject: urllib.urlretrieve never returns??? In-Reply-To: References: <4F649BFC.1080601@shopzeus.com> Message-ID: <4f68e60f$0$11987$742ec2ed@news.sonic.net> On 3/17/2012 9:34 AM, Chris Angelico wrote: > 2012/3/18 Laszlo Nagy: >> In the later case, "log.txt" only contains "#1" and nothing else. If I look >> at pythonw.exe from task manager, then its shows +1 thread every time I >> click the button, and "#1" is appended to the file. Does it fail to retrieve on all URLs, or only on some of them? Running a web crawler, I've seen some pathological cases. There are a very few sites that emit data very, very slowly, but don't time out because they are making progress. There are also some sites where attempting to negotiate a SSL connection results in the SSL protocol reaching a point where the host end is supposed to finish the handshake, but it doesn't. The odds are against this being the problem. I see problems like that in maybe 1 in 100,000 URLs. John Nagle From buzzard at urubu.freeserve.co.uk Tue Mar 20 16:19:28 2012 From: buzzard at urubu.freeserve.co.uk (duncan smith) Date: Tue, 20 Mar 2012 20:19:28 +0000 Subject: Distribution In-Reply-To: <33044d51-c481-4796-a722-406f412cf994@x7g2000pbi.googlegroups.com> References: <33044d51-c481-4796-a722-406f412cf994@x7g2000pbi.googlegroups.com> Message-ID: On 20/03/12 04:31, prince.pangeni wrote: > Hi all, > I am doing a simulation project using Python. In my project, I want > to use some short of distribution to generate requests to a server. > The request should have two distributions. One for request arrival > rate (should be poisson) and another for request mix (i.e. out of the > total requests defined in request arrival rate, how many requests are > of which type). > Example: Suppose the request rate is - 90 req/sec (generated using > poisson distribution) at time t and we have 3 types of requests (i.e. > r1, r2, r2). The request mix distribution output should be similar to: > {r1 : 50 , r2 : 30 , r3 : 10} (i.e. out of 90 requests - 50 are of r1 > type, 30 are of r2 type and 10 are of r3 type). > As I an new to python distribution module, I am not getting how to > code this situation. Please help me out for the same. > > Thanks in advance > > Prince Robert has given you a very good answer. The easiest way is to generate interarrival times using an exponential distribution, then for each event select the type from a categorical probability mass function. Perhaps the easiest and most efficient approach for the latter using your 'mix distribution' above is to create a list containing 5 instances of r1, 3 of r2 and 1 of r3. Then select the type by generating a random index into the list. It is not an ideal solution generally, but good when the parameters do not change and the required list is small. Duncan From jcd at sdf.lonestar.org Tue Mar 20 16:23:22 2012 From: jcd at sdf.lonestar.org (J. Cliff Dyer) Date: Tue, 20 Mar 2012 16:23:22 -0400 Subject: List comprehension/genexp inconsistency. Message-ID: <1332275002.10958.7.camel@jcdyer-laptop> One of my coworkers just stumbled across an interesting issue. I'm hoping someone here can explain why it's happening. When trying to create a class with a dual-loop generator expression in a class definition, there is a strange scoping issue where the inner variable is not found, (but the outer loop variable is found), while a list comprehension has no problem finding both variables. Demonstration: >>> class Spam: ... foo, bar = 4, 4 ... baz = dict(((x, y), x+y) for x in range(foo) for y in range(bar)) ... Traceback (most recent call last): File "", line 1, in File "", line 3, in Spam File "", line 3, in NameError: global name 'bar' is not defined >>> class Eggs(object): ... foo, bar = 4, 4 ... baz = dict([((x, y), x+y) for x in range(foo) for y in range(bar)]) ... >>> This was discovered in python 2.6. In python 3.2, both versions fail with the same NameError. Obviously, this is easy enough to work around. I'm curious though: What's going on under the hood to cause the nested generator expression to fail while the list comprehension succeeds? Cheers, Cliff From cjw at ncf.ca Tue Mar 20 16:28:33 2012 From: cjw at ncf.ca (Colin J. Williams) Date: Tue, 20 Mar 2012 16:28:33 -0400 Subject: Fabric Engine v1.0 released under AGPL In-Reply-To: <549b3a51-5bd9-4ea1-aae0-8f7b09206046@tx8g2000pbc.googlegroups.com> References: <549b3a51-5bd9-4ea1-aae0-8f7b09206046@tx8g2000pbc.googlegroups.com> Message-ID: On 20/03/2012 12:51 PM, Fabric Paul wrote: > Hi everyone - just letting you know that we released v1.0 of Fabric > Engine today. We've open-sourced the core under AGPL, so I hope that > gives you an incentive to get started with high-performance for > Python :) > > http://fabricengine.com/technology/benchmarks/ - to give you an idea > of the kind of performance possible. Most of these are with node, but > the core engine is the same - we just bound it to Python. > > For those of you using Python on the desktop (particularly if you're > working with 3D), we've started a closed beta on a PyQt framework - > you can see more here: http://fabricengine.com/2012/03/pyqt-framework-for-fabric-engine/ > - email beta at fabricengine.com if you'd like to take part in the > testing program. > > Thanks for your time, > > Paul It seems that sing;e dimension arrays are used in KL. How does this compare with Numpy? Colin W. From nathan.alexander.rice at gmail.com Tue Mar 20 16:34:21 2012 From: nathan.alexander.rice at gmail.com (Nathan Rice) Date: Tue, 20 Mar 2012 16:34:21 -0400 Subject: Python is readable In-Reply-To: References: <4f612b19$0$1379$4fafbaef@reader2.news.tin.it> <8e72d74f-c844-4de3-8a37-f6b1fdc2291f@y27g2000yqy.googlegroups.com> <50e9ceec-40f1-4ead-b2b6-87328b30d084@ow8g2000pbc.googlegroups.com> Message-ID: >>> The fact that scientific journal articles start with a documentation >>> string >>> called an abstract does not indicate that scientific English fails as a >>> human communication medium. Function docstrings say what the function >>> does >>> and how to use it without reading the code. They can be pulled out and >>> displayed elsewhere. They also guide the reading of the code. Abstracts >>> serve the same functions. >> >> >> A paper, with topic introduction, methods exposition, data/results >> description and discussion is a poor analog to a function. ?I would >> compare the abstract of a scientific paper to the overview section of >> a program's documentation. ?The great majority of the docstrings I see >> are basically signature rehashes with added type information and >> assertions, followed by a single sentence English gloss-over. ?If the >> code were sufficiently intuitive and expressive, that would be >> redundant. ?Of course, there will always be morbidly obese functions >> and coders that like to wax philosophical or give history lessons in >> comments. > > > Both abstracts and doc strings are designed to be and are read independently > of the stuff they summarize. Perhaps you do not use help(obj) as often as > some other people do. I find help() to be mostly useless because of the clutter induced by double under methods. I use IPython, and I typically will either use tab name completion with the "?" feature or %edit if I really need to dig around. I teach Python to groups from time to time as part of my job, and I usually only mention help() as something of an afterthought, since typically people react to the output like a deer in headlights. Some sort of semantic function and class search from the interpreter would probably win a lot of fans, but I don't know that it is possible without a standard annotation format and the addition of a namespace cache to pyc files. From roy at panix.com Tue Mar 20 16:38:19 2012 From: roy at panix.com (Roy Smith) Date: Tue, 20 Mar 2012 13:38:19 -0700 (PDT) Subject: Released: stackprint -- analyze python stack dumps in server logs Message-ID: <42e5d5ea-ff53-49e8-935e-184e9430327a@b18g2000vbz.googlegroups.com> Stackprint is a little tool for finding, formatting, and categorizing python stack dumps in server log files. We've found it useful for monitoring the health of our django applications. https://bitbucket.org/roysmith/python-tools. BSD license. From gandalf at shopzeus.com Tue Mar 20 16:42:28 2012 From: gandalf at shopzeus.com (Laszlo Nagy) Date: Tue, 20 Mar 2012 21:42:28 +0100 Subject: urllib.urlretrieve never returns??? [SOLVED] - workaround In-Reply-To: <4F68E49C.2060000@shopzeus.com> References: <4F649BFC.1080601@shopzeus.com> <4F66E687.2050008@shopzeus.com> <4f67c09b$0$29981$c3e8da3$5496439d@news.astraweb.com> <4F682CDC.5000703@shopzeus.com> <4F68E49C.2060000@shopzeus.com> Message-ID: <4F68EBB4.6060606@shopzeus.com> > I'll be experimenting with pyCurl now. By replacing the GetThumbnail method with this brainless example, taken from the pyCurl demo: def GetThumbnail(self,imgurl): class Test: def __init__(self): self.contents = '' def body_callback(self, buf): self.contents = self.contents + buf self.Log("#1: "+repr(imgurl)) try: t = Test() c = pycurl.Curl() c.setopt(c.URL, imgurl) c.setopt(c.WRITEFUNCTION, t.body_callback) self.Log("#2") c.perform() self.Log("#3") c.close() self.Log("#4") fpath = os.path.join(os.environ["TEMP"],"thumbnail.jpg") fout = open(fpath,"wb+") self.Log("#5: "+repr(fpath)) try: fout.write(t.contents) finally: fout.close() self.Log("#6") except: self.Log(traceback.format_exc()) return self.Log("#7") wx.CallAfter(self.imgProduct.SetPage,""""""%fpath) self.Log("#8") Everything works perfectly, in all modes: console, no console, started directly and started in separate thread. So the problem with urllib must be. Maybe wxPython installs some except hooks, or who knows? If somebody feels up to it, I can start narrowing down the problem to the smallest possible application. But only if someone knows how to debug core code because I don't. Otherwise I'll just use pyCURL. Thank you for your help! Laszlo From ramit.prasad at jpmorgan.com Tue Mar 20 16:52:00 2012 From: ramit.prasad at jpmorgan.com (Prasad, Ramit) Date: Tue, 20 Mar 2012 20:52:00 +0000 Subject: urllib.urlretrieve never returns??? In-Reply-To: <4F68E49C.2060000@shopzeus.com> References: <4F649BFC.1080601@shopzeus.com> <4F66E687.2050008@shopzeus.com> <4f67c09b$0$29981$c3e8da3$5496439d@news.astraweb.com> <4F682CDC.5000703@shopzeus.com> <4F68E49C.2060000@shopzeus.com> Message-ID: <5B80DD153D7D744689F57F4FB69AF474026C4BD8@SCACMX008.exchad.jpmchase.net> > Today I got a different error message printed on console (program > started with python.exe) > > > > Unhandled exception in thread started by FrameLocEdit.GetThumbnail of Object of type 'wxPanel *' at 0x4f85300> > >>Unhandled exception in thread started by FrameLocEdit.GetThumbnail of Object of type 'wxPanel *' at 0x4f85300> > >>Unhandled exception in thread started by FrameLocEdit.GetThumbnail of Object of type 'wxPanel *' at 0x4f85300> > >>Unhandled exception in thread started by > Traceback (most recent call last): > > Traceback (most recent call last): > > Traceback (most recent call last): > of > >> File "C:\Python\Projects\Warehouserclient_v3\locedit.py", line 917, > in GetThumbnail > File "C:\Python\Projects\Warehouserclient_v3\locedit.py", line 917, > in GetThumbnail > File "C:\Python\Projects\Warehouserclient_v3\locedit.py", line 917, > in GetThumbnail > > sys.excepthook is missing > Traceback (most recent call last): > > I have never seen a traceback like this before. I didn't install any > excepthook myself. > > Program is using wxPython, socket, threads, threading, PIL. > > Here is something even more strange. If I click on the button three > times, then absolutely nothing gets printed on stdout. However, if I > close the program with file/exit (actually, calling > wx.PySimpleApp.ExitMainLoop) then suddenly three stack traces are > printed on stdout, all lines mixed up: > Maybe in self.Log you should add a sys.stdout.flush and sys.stderr.flush(). I am not very familiar with stdin/out but maybe it will help. > Unhandled exception in thread started by FrameLocEdit.GetThumbnail of Object of type 'wxPanel *' at 0x4fb530 > 0> > >>Unhandled exception in thread started by Unhandled exception in > thread started by 0x4fb5300> > >>Unhandled exception in thread started by Unhandled exception in > thread started by 0x4fb5300> > >>Traceback (most recent call last): FrameLocEdit.GetThumbnail of Object of type 'wxPanel *' at 0x4fb5300> > >>Traceback (most recent call last): FrameLocEdit.GetThumbnail of Object of type 'wxPanel *' at 0x4fb5300> > >>Traceback (most recent call last): File > "C:\Python\Projects\Warehouserclient_v3\locedit.py", line 917, in > GetThumbnail > > > Traceback (most recent call last): > > File "C:\Python\Projects\Warehouserclient_v3\locedit.py", line 917, > in GetThumbnail > Traceback (most recent call last): > File "C:\Python\Projects\Warehouserclient_v3\locedit.py", line 917, > in GetThumbnail > File "C:\Python\Projects\Warehouserclient_v3\locedit.py", line > 917, in GetThumbnail > File "C:\Python\Projects\Warehouserclient_v3\locedit.py", line > 917, in GetThumbnail > self.Log(traceback.format_exc()) > self.Log(traceback.format_exc()) > self.Log(traceback.format_exc()) > AttributeErrorself.Log(traceback.format_exc()) > AttributeErrorself.Log(traceback.format_exc()) > AttributeError: AttributeError: AttributeError: > C:\Python\Projects\Warehouserclient_v3> > > > And the last attributerror doesn't tell what attribute is missing. > Probably I'll have to use a different library (pycurl, for example). But > the error itself is getting more interesting. This makes me think self does not have a .Log() or the traceback import is being overridden by something else that does not have .format_exc(). Or possibly this is in a function that does not have a self (maybe a typo in the function def?). > > Also tried to use an invalid file (that should return with HTTP 404 not > found) but the effect is exactly the same. Nothing is printed on stdout > until I try to close the program (stop wxPython's mainloop). Then all > previously threads throw an AttributeError and all of them print a stack > trace (at the same time, lines mixed up). > > I'll be experimenting with pyCurl now. Ramit Ramit Prasad | JPMorgan Chase Investment Bank | Currencies Technology 712 Main Street | Houston, TX 77002 work phone: 713 - 216 - 5423 -- This email is confidential and subject to important disclaimers and conditions including on offers for the purchase or sale of securities, accuracy and completeness of information, viruses, confidentiality, legal privilege, and legal entity disclaimers, available at http://www.jpmorgan.com/pages/disclosures/email. From ramit.prasad at jpmorgan.com Tue Mar 20 17:01:58 2012 From: ramit.prasad at jpmorgan.com (Prasad, Ramit) Date: Tue, 20 Mar 2012 21:01:58 +0000 Subject: urllib.urlretrieve never returns??? [SOLVED] - workaround In-Reply-To: <4F68EBB4.6060606@shopzeus.com> References: <4F649BFC.1080601@shopzeus.com> <4F66E687.2050008@shopzeus.com> <4f67c09b$0$29981$c3e8da3$5496439d@news.astraweb.com> <4F682CDC.5000703@shopzeus.com> <4F68E49C.2060000@shopzeus.com> <4F68EBB4.6060606@shopzeus.com> Message-ID: <5B80DD153D7D744689F57F4FB69AF474026C4BF3@SCACMX008.exchad.jpmchase.net> > Everything works perfectly, in all modes: console, no console, started > directly and started in separate thread. > > So the problem with urllib must be. Maybe wxPython installs some except > hooks, or who knows? If somebody feels up to it, I can start narrowing > down the problem to the smallest possible application. But only if > someone knows how to debug core code because I don't. Otherwise I'll > just use pyCURL. Have you tried urllib2? Have you tried a small program without using wx? To be honest, I doubt the problem is wx or urllib as they are both fairly broadly used. Try to come up with an example that is as minimal as possible. >>> imgurl = "http://www.shopzeus.hu/thumbnail.php?width=200&image=pyramid/PP0830.jpg" >>> urllib.urlretrieve( imgurl ) ('c:\\[...]\\tmpkhixgt.php', ) And I have Windows 7 64 with Python 2.6.6 (32 bit) and wx installed. Ramit Ramit Prasad | JPMorgan Chase Investment Bank | Currencies Technology 712 Main Street | Houston, TX 77002 work phone: 713 - 216 - 5423 -- This email is confidential and subject to important disclaimers and conditions including on offers for the purchase or sale of securities, accuracy and completeness of information, viruses, confidentiality, legal privilege, and legal entity disclaimers, available at http://www.jpmorgan.com/pages/disclosures/email. From ramit.prasad at jpmorgan.com Tue Mar 20 17:25:07 2012 From: ramit.prasad at jpmorgan.com (Prasad, Ramit) Date: Tue, 20 Mar 2012 21:25:07 +0000 Subject: urllib.urlretrieve never returns??? [SOLVED] - workaround References: <4F649BFC.1080601@shopzeus.com> <4F66E687.2050008@shopzeus.com> <4f67c09b$0$29981$c3e8da3$5496439d@news.astraweb.com> <4F682CDC.5000703@shopzeus.com> <4F68E49C.2060000@shopzeus.com> <4F68EBB4.6060606@shopzeus.com> Message-ID: <5B80DD153D7D744689F57F4FB69AF474026C4C73@SCACMX008.exchad.jpmchase.net> > > Everything works perfectly, in all modes: console, no console, started > > directly and started in separate thread. > > > > So the problem with urllib must be. Maybe wxPython installs some except > > hooks, or who knows? If somebody feels up to it, I can start narrowing > > down the problem to the smallest possible application. But only if > > someone knows how to debug core code because I don't. Otherwise I'll > > just use pyCURL. > > Have you tried urllib2? Have you tried a small program without using wx? > > To be honest, I doubt the problem is wx or urllib as they are both fairly > broadly used. Try to come up with an example that is as minimal as > possible. > > >>> imgurl = > "http://www.shopzeus.hu/thumbnail.php?width=200&image=pyramid/PP0830.jpg" > >>> urllib.urlretrieve( imgurl ) > ('c:\\[...]\\tmpkhixgt.php', ) > > And I have Windows 7 64 with Python 2.6.6 (32 bit) and wx installed. > Your program on ActiveState worked for me which tells me that it might be a network or machine specific problem. You are missing an import which I mentioned in another post. Fixing that should tell what the error you are getting is; you would not be getting the AttributeError without some other error first. Ramit Ramit Prasad | JPMorgan Chase Investment Bank | Currencies Technology 712 Main Street | Houston, TX 77002 work phone: 713 - 216 - 5423 -- This email is confidential and subject to important disclaimers and conditions including on offers for the purchase or sale of securities, accuracy and completeness of information, viruses, confidentiality, legal privilege, and legal entity disclaimers, available at http://www.jpmorgan.com/pages/disclosures/email. From ramit.prasad at jpmorgan.com Tue Mar 20 17:26:51 2012 From: ramit.prasad at jpmorgan.com (Prasad, Ramit) Date: Tue, 20 Mar 2012 21:26:51 +0000 Subject: urllib.urlretrieve never returns??? In-Reply-To: <5B80DD153D7D744689F57F4FB69AF474026C4BD8@SCACMX008.exchad.jpmchase.net> References: <4F649BFC.1080601@shopzeus.com> <4F66E687.2050008@shopzeus.com> <4f67c09b$0$29981$c3e8da3$5496439d@news.astraweb.com> <4F682CDC.5000703@shopzeus.com> <4F68E49C.2060000@shopzeus.com> <5B80DD153D7D744689F57F4FB69AF474026C4BD8@SCACMX008.exchad.jpmchase.net> Message-ID: <5B80DD153D7D744689F57F4FB69AF474026C4C97@SCACMX008.exchad.jpmchase.net> > > Traceback (most recent call last): > > > > File "C:\Python\Projects\Warehouserclient_v3\locedit.py", line 917, > > in GetThumbnail > > Traceback (most recent call last): > > File "C:\Python\Projects\Warehouserclient_v3\locedit.py", line 917, > > in GetThumbnail > > File "C:\Python\Projects\Warehouserclient_v3\locedit.py", line > > 917, in GetThumbnail > > File "C:\Python\Projects\Warehouserclient_v3\locedit.py", line > > 917, in GetThumbnail > > self.Log(traceback.format_exc()) > > self.Log(traceback.format_exc()) > > self.Log(traceback.format_exc()) > > AttributeErrorself.Log(traceback.format_exc()) > > AttributeErrorself.Log(traceback.format_exc()) > > AttributeError: AttributeError: AttributeError: > > C:\Python\Projects\Warehouserclient_v3> > > > > > > And the last attributerror doesn't tell what attribute is missing. > > Probably I'll have to use a different library (pycurl, for example). But > > the error itself is getting more interesting. > > This makes me think self does not have a .Log() or the traceback > import is being overridden by something else that does not have > .format_exc(). Or possibly this is in a function that does not have a > self (maybe a typo in the function def?). > Here you can find the example program and the original post. > > http://code.activestate.com/lists/python-list/617894/ I just looked at your source file on ActiveState and noticed that you do not import traceback. That is why you are getting the AttributeError. Now you should be getting a much better error once you import it :) Ramit Ramit Prasad | JPMorgan Chase Investment Bank | Currencies Technology 712 Main Street | Houston, TX 77002 work phone: 713 - 216 - 5423 -- > -----Original Message----- > From: python-list-bounces+ramit.prasad=jpmorgan.com at python.org > [mailto:python-list-bounces+ramit.prasad=jpmorgan.com at python.org] On Behalf > Of Prasad, Ramit > Sent: Tuesday, March 20, 2012 3:52 PM > To: python-list at python.org > Subject: RE: urllib.urlretrieve never returns??? > > > Today I got a different error message printed on console (program > > started with python.exe) > > > > > > > > Unhandled exception in thread started by > FrameLocEdit.GetThumbnail of > Object of type 'wxPanel *' at 0x4f85300> > > >>Unhandled exception in thread started by > FrameLocEdit.GetThumbnail of > Object of type 'wxPanel *' at 0x4f85300> > > >>Unhandled exception in thread started by > FrameLocEdit.GetThumbnail of > Object of type 'wxPanel *' at 0x4f85300> > > >>Unhandled exception in thread started by > > Traceback (most recent call last): > > > > Traceback (most recent call last): > > > > Traceback (most recent call last): > > > of > > >> File "C:\Python\Projects\Warehouserclient_v3\locedit.py", line 917, > > in GetThumbnail > > File "C:\Python\Projects\Warehouserclient_v3\locedit.py", line 917, > > in GetThumbnail > > File "C:\Python\Projects\Warehouserclient_v3\locedit.py", line 917, > > in GetThumbnail > > > > sys.excepthook is missing > > Traceback (most recent call last): > > > > I have never seen a traceback like this before. I didn't install any > > excepthook myself. > > > > Program is using wxPython, socket, threads, threading, PIL. > > > > Here is something even more strange. If I click on the button three > > times, then absolutely nothing gets printed on stdout. However, if I > > close the program with file/exit (actually, calling > > wx.PySimpleApp.ExitMainLoop) then suddenly three stack traces are > > printed on stdout, all lines mixed up: > > > > Maybe in self.Log you should add a sys.stdout.flush and > sys.stderr.flush(). I am not very familiar with stdin/out but > maybe it will help. > > > Unhandled exception in thread started by > FrameLocEdit.GetThumbnail of > Object of type 'wxPanel *' at 0x4fb530 > > 0> > > >>Unhandled exception in thread started by Unhandled exception in > > thread started by > > 0x4fb5300> > > >>Unhandled exception in thread started by Unhandled exception in > > thread started by > > 0x4fb5300> > > >>Traceback (most recent call last): > FrameLocEdit.GetThumbnail of > Object of type 'wxPanel *' at 0x4fb5300> > > >>Traceback (most recent call last): > FrameLocEdit.GetThumbnail of > Object of type 'wxPanel *' at 0x4fb5300> > > >>Traceback (most recent call last): File > > "C:\Python\Projects\Warehouserclient_v3\locedit.py", line 917, in > > GetThumbnail > > > > > > > > > Also tried to use an invalid file (that should return with HTTP 404 not > > found) but the effect is exactly the same. Nothing is printed on stdout > > until I try to close the program (stop wxPython's mainloop). Then all > > previously threads throw an AttributeError and all of them print a stack > > trace (at the same time, lines mixed up). > > > > I'll be experimenting with pyCurl now. > > > Ramit > > > Ramit Prasad | JPMorgan Chase Investment Bank | Currencies Technology > 712 Main Street | Houston, TX 77002 > work phone: 713 - 216 - 5423 > > -- > > This email is confidential and subject to important disclaimers and > conditions including on offers for the purchase or sale of > securities, accuracy and completeness of information, viruses, > confidentiality, legal privilege, and legal entity disclaimers, > available at http://www.jpmorgan.com/pages/disclosures/email. > -- > http://mail.python.org/mailman/listinfo/python-list From paul at fabric-engine.com Tue Mar 20 18:24:28 2012 From: paul at fabric-engine.com (Paul Doyle) Date: Tue, 20 Mar 2012 15:24:28 -0700 (PDT) Subject: Fabric Engine v1.0 released under AGPL References: <549b3a51-5bd9-4ea1-aae0-8f7b09206046@tx8g2000pbc.googlegroups.com> Message-ID: <0c86f051-e519-4638-9914-110ea02a75a8@db5g2000vbb.googlegroups.com> Hi Colin, Fabric supports multi-dimensional arrays, and also provides support for dictionaries. You can read more here: http://documentation.fabric-engine.com/latest/FabricEngine-KLProgrammingGuide.html In terms of comparison to Numpy - I'm not familiar with that product, but some surface level similarities/differences: - we don't provide high-level functions for scientific computing. This is something we're looking at now. - both products provide methods for including existing libraries (http://documentation.fabric-engine.com/latest/FabricEngine- ExtensionsReference.html) - Fabric is a high-performance framework - http://documentation.fabric-engine.com/latest/FabricEngine-Overview.html - we haven't benchmarked against R, MatLab etc but we run at the same speed as multi-threaded compiled code (since that's essentially what we're doing). Hope that helps, Paul > > It seems that sing;e dimension arrays are used in KL. ?How does this > compare with Numpy? > > Colin W. From ian.g.kelly at gmail.com Tue Mar 20 18:50:03 2012 From: ian.g.kelly at gmail.com (Ian Kelly) Date: Tue, 20 Mar 2012 16:50:03 -0600 Subject: List comprehension/genexp inconsistency. In-Reply-To: References: <1332275002.10958.7.camel@jcdyer-laptop> Message-ID: On Tue, Mar 20, 2012 at 3:16 PM, Dennis Lee Bieber wrote: > On Tue, 20 Mar 2012 16:23:22 -0400, "J. Cliff Dyer" > declaimed the following in > gmane.comp.python.general: > >> >> When trying to create a class with a dual-loop generator expression in a >> class definition, there is a strange scoping issue where the inner >> variable is not found, (but the outer loop variable is found), while a >> list comprehension has no problem finding both variables. >> > ? ? ? ?Read http://www.python.org/dev/peps/pep-0289/ -- in particular, look > for the word "leak" No, this has nothing to do with the loop variable leaking. It appears to have to do with the fact that the variables and the generator expression are inside a class block. I think that it's related to the reason that this doesn't work: class Foo(object): x = 42 def foo(): print(x) foo() In this case, x is not a local variable of foo, nor is it a global. In order for foo to access x, it would have to be a closure -- but Python can't make it a closure in this case, because the variable it accesses is (or rather, will become) a class attribute, not a local variable of a function that can be stored in a cell. Instead, the compiler just makes it a global reference in the hope that such a global will actually be defined when the code is run. For that reason, what surprises me about Cliff's example is that a generator expression works at all in that context. It seems to work as long as it contains only one loop, but not if it contains two. To find out why, I tried disassembling one: >>> class Foo(object): ... x = 42 ... y = 12 ... g = (a+b for a in range(x) for b in range(y)) ... >>> dis.dis(Foo.g.gi_code) 4 0 LOAD_FAST 0 (.0) >> 3 FOR_ITER 34 (to 40) 6 STORE_FAST 1 (a) 9 LOAD_GLOBAL 0 (range) 12 LOAD_GLOBAL 1 (y) 15 CALL_FUNCTION 1 18 GET_ITER >> 19 FOR_ITER 15 (to 37) 22 STORE_FAST 2 (b) 25 LOAD_FAST 1 (a) 28 LOAD_FAST 2 (b) 31 BINARY_ADD 32 YIELD_VALUE 33 POP_TOP 34 JUMP_ABSOLUTE 19 >> 37 JUMP_ABSOLUTE 3 >> 40 LOAD_CONST 0 (None) 43 RETURN_VALUE So that explains it. Notice that "x" is never actually accessed in that disassembly; only "y" is. It turns out that the first iterator [range(x)] is actually created before the generator ever starts executing, and is stored as an anonymous local variable on the generator's stack frame -- so it's created in the class scope, not in the generator scope. The second iterator, however, is recreated on every iteration of the first iterator, so it can't be pre-built in that manner. It does get created in the generator scope, and when that happens it blows up because it can't find the variable, just like the function example above. Cheers, Ian From kiuhnm03.4t.yahoo.it Tue Mar 20 19:27:26 2012 From: kiuhnm03.4t.yahoo.it (Kiuhnm) Date: Wed, 21 Mar 2012 00:27:26 +0100 Subject: Python is readable In-Reply-To: <4f67506b$0$29981$c3e8da3$5496439d@news.astraweb.com> References: <4f612b19$0$1379$4fafbaef@reader2.news.tin.it> <8e72d74f-c844-4de3-8a37-f6b1fdc2291f@y27g2000yqy.googlegroups.com> <50e9ceec-40f1-4ead-b2b6-87328b30d084@ow8g2000pbc.googlegroups.com> <4f61c828$0$1390$4fafbaef@reader2.news.tin.it> <4f61d728$0$1375$4fafbaef@reader2.news.tin.it> <4f61fd0a$0$1389$4fafbaef@reader2.news.tin.it> <4f6280a0$0$29981$c3e8da3$5496439d@news.astraweb.com> <4f6333ca$0$1392$4fafbaef@reader1.news.tin.it> <4f633a1a$0$29981$c3e8da3$5496439d@news.astraweb.com> <4f64f2d8$0$1393$4fafbaef@reader1.news.tin.it> <4f653e5c$0$29981$c3e8da3$5496439d@news.astraweb.com> <4f671c36$0$1386$4fafbaef@reader2.news.tin.it> <4f67506b$0$29981$c3e8da3$5496439d@news.astraweb.com> Message-ID: <4f69125e$0$1380$4fafbaef@reader2.news.tin.it> On 3/19/2012 16:27, Steven D'Aprano wrote: > I believe that you are misunderstanding the descriptivist position. There > are many sentences which are never said, or perhaps only said once. Most > non-trivial spoken or written sentences are unique. That doesn't make > them wrong or erroneous because "nobody says them". > > Nobody says "hesitant teapots sleep artistically". Let's not mix syntax with semantics. "If I'm ok: I'll go." represents all the possible sentences where the if-clause and the then-clause are separated by a colon. I believe that none of those are grammatically correct. Kiuhnm From kiuhnm03.4t.yahoo.it Tue Mar 20 19:57:17 2012 From: kiuhnm03.4t.yahoo.it (Kiuhnm) Date: Wed, 21 Mar 2012 00:57:17 +0100 Subject: Python is readable In-Reply-To: <4f6532e7$0$29981$c3e8da3$5496439d@news.astraweb.com> References: <4f612b19$0$1379$4fafbaef@reader2.news.tin.it> <8e72d74f-c844-4de3-8a37-f6b1fdc2291f@y27g2000yqy.googlegroups.com> <50e9ceec-40f1-4ead-b2b6-87328b30d084@ow8g2000pbc.googlegroups.com> <4f61c828$0$1390$4fafbaef@reader2.news.tin.it> <4f61d728$0$1375$4fafbaef@reader2.news.tin.it> <4f61fd0a$0$1389$4fafbaef@reader2.news.tin.it> <4f6280a0$0$29981$c3e8da3$5496439d@news.astraweb.com> <4f6333ca$0$1392$4fafbaef@reader1.news.tin.it> <4f633a1a$0$29981$c3e8da3$5496439d@news.astraweb.com> <9sgsb1FsbpU1@mid.individual.net> <4f636a38$0$29981$c3e8da3$5496439d@news.astraweb.com> <9shd0kFvgbU1@mid.individual.net> <4f638b76$0$29981$c3e8da3$5496439d@news.astraweb.com> <9shj05FabeU1@mid.individual.net> <4f64fa18$0$1392$4fafbaef@reader1.news.tin.it> <4f6532e7$0$29981$c3e8da3$5496439d@news.astraweb.com> Message-ID: <4f69195d$0$1388$4fafbaef@reader2.news.tin.it> On 3/18/2012 1:57, Steven D'Aprano wrote: >> On 3/16/2012 21:04, Prasad, Ramit wrote: >>>> People spell your name Stephen, sometimes too. Thinking of changing >>>> it? Gore Vidal's quote has panache, a valid compensation for breaking >>> the usual rule. How many other uses on that page are similar? >>> >>> >>> He provided common examples and reference links. Seems like a pretty >>> reasonable way of trying to prove a point. If you don't like reference >>> links, what would convince you that the point was correct? I have not >>> seen any counter examples or counter references on your behalf... >> >> He's referring to this "rule": >> "A colon should not precede a list unless it follows a complete >> sentence; however, the colon is a style choice that some publications >> allow." >> http://www.grammarbook.com/punctuation/colons.asp > > > That is an invented prescriptivist rule and not based on English grammar > as it actually is used by native English speakers. It is *bullshit*. Even > the author of that page breaks it. Immediately following the above > prohibition, she follows it with the sentence fragment: > > "Examples:" > > and then a list -- exactly what she says you may not do. I never said that rule is acceptable. I agree with you on that. > People *do* precede lists by a colon following a sentence fragment. This > is unremarkable English grammar, with only a tiny number of arse-plugged > prescriptivists finding anything to complain about it, and even they > break their own bullshit made-up so-called rule. > > The vast majority of English speakers write things like: > > TO DO: > - mow the lawn > - wash the car > - take kids to the zoo > - write book on grammar > > and there is nothing wrong with doing so. That's perfectly acceptable. Robert Kern put it very well in his post: "don't use a colon to separate a transitive verb from its objects". You can't say TO DO - mow the lawn - ... because "TO DO mow the lawn" doesn't "flow". But why should we break a sentence when there's no need to do so? Why should you write The matrix: .... is equal to.... Why the colon? Why break the flow of a sentence without reason? I would generalize Robert Kern's rule a little: "don't put a colon into a sentence which is fine already". Example: You should - mow the lawn - do the dishes - walk the dog That's perfectly fine. Commas are conveniently omitted. As a side note, titles of movies, newspapers etc... don't follow common rules. Articles may be omitted, verbs may be missing, etc... They're just titles. Kiuhnm From steve+comp.lang.python at pearwood.info Tue Mar 20 20:01:25 2012 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 21 Mar 2012 00:01:25 GMT Subject: Python is readable References: <4f612b19$0$1379$4fafbaef@reader2.news.tin.it> <8e72d74f-c844-4de3-8a37-f6b1fdc2291f@y27g2000yqy.googlegroups.com> <50e9ceec-40f1-4ead-b2b6-87328b30d084@ow8g2000pbc.googlegroups.com> Message-ID: <4f691a55$0$29981$c3e8da3$5496439d@news.astraweb.com> On Tue, 20 Mar 2012 16:34:21 -0400, Nathan Rice wrote: > I find help() to be mostly useless because of the clutter induced by > double under methods. I feel your pain, but perhaps I've just learned how to skim the output without being bogged down in reading every line, or perhaps because I mostly call it on methods rather than on the class itself, I find help() is absolutely invaluable and would be lost without it. -- Steven From steve+comp.lang.python at pearwood.info Tue Mar 20 20:22:22 2012 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 21 Mar 2012 00:22:22 GMT Subject: Python is readable References: <4f612b19$0$1379$4fafbaef@reader2.news.tin.it> <8e72d74f-c844-4de3-8a37-f6b1fdc2291f@y27g2000yqy.googlegroups.com> <50e9ceec-40f1-4ead-b2b6-87328b30d084@ow8g2000pbc.googlegroups.com> Message-ID: <4f691f3d$0$29981$c3e8da3$5496439d@news.astraweb.com> On Tue, 20 Mar 2012 15:28:25 -0400, Nathan Rice wrote: >>> This is one of my gripes with the dogmatic application of the "break >>> it into multiple statements" mantra of Python. >> >> I must admit I don't recognise that one, unless you're talking about >> "not everything needs to be a one liner". >> ... >> Perhaps you could give some examples (actual or contrived) of stuff >> where "breaking it into multiple statements" is a bad thing? > > One example is performing a series of transformations on a collection of > data, with the intent of finding an element of that collection that > satisfies a particular criterion. If you separate out the individual > transformations, you need to understand generators or you will waste > space and perform many unnecessary calculations. If you only ever do a > single transformation with a clear conceptual meaning, you could create > a "master transformation function," but what if you have a large number > of potential permutations of that function? I'm sorry, that is far too abstract for me. Do you have a *concrete* example, even an trivial one? > What if you are composing > three or four functions, each of which is conditional on the data? If > you extract things from a statement and assign them somewhat arbitrary > names, you've just traded horizontal bloat for vertical bloat (with a > net increase in volume), while forcing a reader to scan back and forth > to different statements to understand what is happening. First off, vertical bloat is easier to cope with than horizontal bloat, at least for people used to reading left-to-right rather than vertically. There are few anti-patterns worse that horizontal scrolling, especially for text. Secondly, the human brain can only deal with a limited number of tokens at any one time. It's easier to remember large numbers when they are broken up into chunks: 824-791-259-401 versus 824791259401 (three tokens, versus twelve) Likewise for reading code. Chunking code into multiple lines instead of one long expression, and temporary variables, make things easier to understand, not harder. http://en.wikipedia.org/wiki/The_Magical_Number_Seven,_Plus_or_Minus_Two And thirdly, you're not "forcing" the reader to scan back and forth -- or at least if you are, then you've chosen your functions badly. Functions should have descriptive names and should perform a meaningful task, not just an arbitrary collection of code. When you read: x = range(3, len(sequence), 5) you're not forced to scan back and forth between that line and the code for range and len to understand it, because range and len are good abstractions that make sensible functions. There is a lot of badly written code in existence. Don't blame poor execution of design principles on the design principle itself. [...] > Also, because of Sphinx, it is very common in the Python community weave > documents and code together in a way that is convenient for authors but > irritating for readers. I don't know about "very common". I suspect, given the general paucity of documentation in the average software package, it is more like "very rare, but memorable when it does happen". > I personally would prefer not to have to scroll > past 100 lines of a tutorial with examples, tests and what not in order > to go from one function to another. Agreed. Docstrings should use a minimal number of examples and tests. Tutorials and extensive tests should be extracted into external documents. > It would be really awesome if > everyone used links to that material in docstrings, and the default > sphinx theme created an inline collapsible iframe that included that > material for the HTML version. Don't get me wrong, I adore Sphinx, the > problem here is people who are lazy or don't know the right way to > structure docs. +1000 -- Steven From showell30 at yahoo.com Tue Mar 20 21:28:25 2012 From: showell30 at yahoo.com (Steve Howell) Date: Tue, 20 Mar 2012 18:28:25 -0700 (PDT) Subject: Python is readable References: <4f612b19$0$1379$4fafbaef@reader2.news.tin.it> <8e72d74f-c844-4de3-8a37-f6b1fdc2291f@y27g2000yqy.googlegroups.com> <50e9ceec-40f1-4ead-b2b6-87328b30d084@ow8g2000pbc.googlegroups.com> <4f691f3d$0$29981$c3e8da3$5496439d@news.astraweb.com> Message-ID: On Mar 20, 5:22?pm, Steven D'Aprano wrote: > On Tue, 20 Mar 2012 15:28:25 -0400, Nathan Rice wrote: > > > What if you are composing > > three or four functions, each of which is conditional on the data? ?If > > you extract things from a statement and assign them somewhat arbitrary > > names, you've just traded horizontal bloat for vertical bloat (with a > > net increase in volume), while forcing a reader to scan back and forth > > to different statements to understand what is happening. > > First off, vertical bloat is easier to cope with than horizontal bloat, > at least for people used to reading left-to-right rather than vertically. > There are few anti-patterns worse that horizontal scrolling, especially > for text. > I agree with Steven that horizontal bloat hurts readability more than vertical bloat. Of course, it's a subjective thing, and I get the fact that the remedy to horizontal bloat often means more volume of code overalls (i.e. introducing locals). My main problem with horizontal bloat is that you often have to read inside-outside or right to left: verb3(verb2(verb1(noun))) verb2(verb1(noun, adverb1), adverb2) The vertical versions tend to be more verbose, but entirely sequential: noun1 = verb1(noun) noun2 = verb2(noun1) verb3(noun2) and noun1 = verb1(noun, adverb1) verb2(noun1, adverb2) There is a bit of an inflection point when the number of lines in the "local" code exceeds the vertical real estate of your monitor. I feel like vertical real estate is still mostly constrained by the way we build our monitors and our editors, and it's not so much a "human brain" limitation. With horizontally stretched code, I always feel like my brain is the bottleneck. The one place where I don't mind the horizontal approach is when code is truly laid out in the order of execution: noun.verb1(adverb1).verb2(adverb2).verb3(adverb3).verb4(adverb4) Even then, I'd prefer it to read vertically. Also, while the above idiom puts the verbs in the right order, it is still backward to me to say "noun.verb." You don't noun a verb. You verb a noun. From ben+python at benfinney.id.au Tue Mar 20 22:28:53 2012 From: ben+python at benfinney.id.au (Ben Finney) Date: Wed, 21 Mar 2012 13:28:53 +1100 Subject: Python is readable References: <4f612b19$0$1379$4fafbaef@reader2.news.tin.it> <8e72d74f-c844-4de3-8a37-f6b1fdc2291f@y27g2000yqy.googlegroups.com> <50e9ceec-40f1-4ead-b2b6-87328b30d084@ow8g2000pbc.googlegroups.com> <4f691f3d$0$29981$c3e8da3$5496439d@news.astraweb.com> Message-ID: <87d386lmai.fsf@benfinney.id.au> Steve Howell writes: > Also, while the above idiom puts the verbs in the right order, it is > still backward to me to say "noun.verb." You don't noun a verb. You > verb a noun. When calling a method, the program object is the grammatical subject. You don't verb the noun, and you don't noun a verb. The noun verbs. -- \ ?Last year I went fishing with Salvador Dali. He was using a | `\ dotted line. He caught every other fish.? ?Steven Wright | _o__) | Ben Finney From showell30 at yahoo.com Tue Mar 20 22:44:38 2012 From: showell30 at yahoo.com (Steve Howell) Date: Tue, 20 Mar 2012 19:44:38 -0700 (PDT) Subject: Python is readable References: <4f612b19$0$1379$4fafbaef@reader2.news.tin.it> <8e72d74f-c844-4de3-8a37-f6b1fdc2291f@y27g2000yqy.googlegroups.com> <50e9ceec-40f1-4ead-b2b6-87328b30d084@ow8g2000pbc.googlegroups.com> <4f691f3d$0$29981$c3e8da3$5496439d@news.astraweb.com> <87d386lmai.fsf@benfinney.id.au> Message-ID: <8a77bf8d-b12f-442b-a1a3-479b5d66d366@tx8g2000pbc.googlegroups.com> On Mar 20, 7:28?pm, Ben Finney wrote: > Steve Howell writes: > > Also, while the above idiom puts the verbs in the right order, it is > > still backward to me to say "noun.verb." You don't noun a verb. You > > verb a noun. > > When calling a method, the program object is the grammatical subject. > You don't verb the noun, and you don't noun a verb. The noun verbs. > I think it's a matter of perspective, so there's no right answer, but I always think of the program object as also being the grammatical object, with the implied subject/actor being Python itself. For example, consider this code: stack.push(item) It's not the stack that's pushing. It's the stack being pushed on to. So "stack" is the direct object, and "item" is the indirect object. When you say "stack.push(item)", I think of it as being that Python pushes an item on to the stack. I suppose you would argue that the stack pushes item on to itself? And even then, isn't it still the grammatical object in the "itself" case? Also, don't they call those thingies "object" for a reason? ;) From showell30 at yahoo.com Tue Mar 20 23:07:52 2012 From: showell30 at yahoo.com (Steve Howell) Date: Tue, 20 Mar 2012 20:07:52 -0700 (PDT) Subject: List comprehension/genexp inconsistency. References: <1332275002.10958.7.camel@jcdyer-laptop> Message-ID: <0d1d9544-fc2b-4938-b341-eb912882c13b@ur9g2000pbc.googlegroups.com> On Mar 20, 3:50?pm, Ian Kelly wrote: > On Tue, Mar 20, 2012 at 3:16 PM, Dennis Lee Bieber > > wrote: > > On Tue, 20 Mar 2012 16:23:22 -0400, "J. Cliff Dyer" > > declaimed the following in > > gmane.comp.python.general: > > >> When trying to create a class with a dual-loop generator expression in a > >> class definition, there is a strange scoping issue where the inner > >> variable is not found, (but the outer loop variable is found), while a > >> list comprehension has no problem finding both variables. > > > ? ? ? ?Readhttp://www.python.org/dev/peps/pep-0289/-- in particular, look > > for the word "leak" > > No, this has nothing to do with the loop variable leaking. ?It appears > to have to do with the fact that the variables and the generator > expression are inside a class block. Interesting. Just for completeness, the code does seem to work fine when you take it out of the class: Python 2.6.1 (r261:67515, Jun 24 2010, 21:47:49) [GCC 4.2.1 (Apple Inc. build 5646)] on darwin Type "help", "copyright", "credits" or "license" for more information. >>> foo, bar = 4, 4 >>> g = (((x, y), x+y) for x in range(foo) for y in range(bar)) >>> dict(g) {(0, 1): 1, (1, 2): 3, (3, 2): 5, (0, 0): 0, (3, 3): 6, (3, 0): 3, (3, 1): 4, (2, 1): 3, (0, 2): 2, (2, 0): 2, (1, 3): 4, (2, 3): 5, (2, 2): 4, (1, 0): 1, (0, 3): 3, (1, 1): 2} >>> import dis >>> dis.dis(g.gi_code) 1 0 SETUP_LOOP 57 (to 60) 3 LOAD_FAST 0 (.0) >> 6 FOR_ITER 50 (to 59) 9 STORE_FAST 1 (x) 12 SETUP_LOOP 41 (to 56) 15 LOAD_GLOBAL 0 (range) 18 LOAD_GLOBAL 1 (bar) 21 CALL_FUNCTION 1 24 GET_ITER >> 25 FOR_ITER 27 (to 55) 28 STORE_FAST 2 (y) 31 LOAD_FAST 1 (x) 34 LOAD_FAST 2 (y) 37 BUILD_TUPLE 2 40 LOAD_FAST 1 (x) 43 LOAD_FAST 2 (y) 46 BINARY_ADD 47 BUILD_TUPLE 2 50 YIELD_VALUE 51 POP_TOP 52 JUMP_ABSOLUTE 25 >> 55 POP_BLOCK >> 56 JUMP_ABSOLUTE 6 >> 59 POP_BLOCK >> 60 LOAD_CONST 0 (None) 63 RETURN_VALUE From p_s_d_a_s_i_l_v_a at netcabo.pt Wed Mar 21 00:09:14 2012 From: p_s_d_a_s_i_l_v_a at netcabo.pt (Paulo da Silva) Date: Wed, 21 Mar 2012 04:09:14 +0000 Subject: setup.py for an extension Message-ID: Hi all. I have a python extension (bindings for a C lib - no swig) and I would like to write a setup.py to build a source distribution pack. The extension consists of 3 files: foo.h foo.c foo.py that are placed in a eclipse directory /home//ECLIPSE/workspace/ext/src foo.h+foo.c are to be compiled into _foo.so shared lib. _foo.so is itself a module only called from foo.py. The dir I wrote the setup.py is any arbitrary dir. I don't want to put packaging stuff into the eclipse source. I read the docs but have no idea on how to do this. Some tentatives I did completely failed. Any help? Thanks in advance. From rosuav at gmail.com Wed Mar 21 00:16:36 2012 From: rosuav at gmail.com (Chris Angelico) Date: Wed, 21 Mar 2012 15:16:36 +1100 Subject: Python is readable In-Reply-To: <8a77bf8d-b12f-442b-a1a3-479b5d66d366@tx8g2000pbc.googlegroups.com> References: <4f612b19$0$1379$4fafbaef@reader2.news.tin.it> <8e72d74f-c844-4de3-8a37-f6b1fdc2291f@y27g2000yqy.googlegroups.com> <50e9ceec-40f1-4ead-b2b6-87328b30d084@ow8g2000pbc.googlegroups.com> <4f691f3d$0$29981$c3e8da3$5496439d@news.astraweb.com> <87d386lmai.fsf@benfinney.id.au> <8a77bf8d-b12f-442b-a1a3-479b5d66d366@tx8g2000pbc.googlegroups.com> Message-ID: On Wed, Mar 21, 2012 at 1:44 PM, Steve Howell wrote: > I think it's a matter of perspective, so there's no right answer, but > I always think of the program object as also being the grammatical > object, with the implied subject/actor being Python itself. ?For > example, consider this code: > > ?stack.push(item) > > It's not the stack that's pushing. ?It's the stack being pushed on > to. In code, though, the push() method is defined in and on the stack object (or more likely, on the class that instantiated it, but near enough). So the stack is being asked to push something onto itself. It is still viably the subject. Yes, the implied subject could be the language interpreter; but it could just as easily be the CPU, or those friendly nanobots, or that guy moving the rocks in XKCD 505. But in the abstraction of the line of code, you don't care how CPython goes about loading globals, calling bound methods, and incrementing object reference counts - you just care that the stack is pushing this item onto itself. Some method names are definitely written as though their primary argument is the object, not the subject. Either option works. Do you think about code as the subject+verb and a data structure as the object, or the object as the subject and the method as the verb? Fundamentally no difference. ChrisA From nathan.alexander.rice at gmail.com Wed Mar 21 00:55:51 2012 From: nathan.alexander.rice at gmail.com (Nathan Rice) Date: Wed, 21 Mar 2012 00:55:51 -0400 Subject: Python is readable In-Reply-To: <4f691f3d$0$29981$c3e8da3$5496439d@news.astraweb.com> References: <4f612b19$0$1379$4fafbaef@reader2.news.tin.it> <8e72d74f-c844-4de3-8a37-f6b1fdc2291f@y27g2000yqy.googlegroups.com> <50e9ceec-40f1-4ead-b2b6-87328b30d084@ow8g2000pbc.googlegroups.com> <4f691f3d$0$29981$c3e8da3$5496439d@news.astraweb.com> Message-ID: >> One example is performing a series of transformations on a collection of >> data, with the intent of finding an element of that collection that >> satisfies a particular criterion. ?If you separate out the individual >> transformations, you need to understand generators or you will waste >> space and perform many unnecessary calculations. ?If you only ever do a >> single transformation with a clear conceptual meaning, you could create >> a "master transformation function," but what if you have a large number >> of potential permutations of that function? > > I'm sorry, that is far too abstract for me. Do you have a *concrete* > example, even an trivial one? How about a hypothetical log analyzer that parses a log file that is aggregated from multiple event sources with disparate record structures. You will need to perform a series of transformations on the data to convert record elements from text to specific formats, and your function for identifying "alarm" records is also dependent on record structure (and possibly system state, imagining an intrusion detection system). Of course you could go through a lot of trouble to dispatch and detect alarms over 6-7 statements, however given the description "for each log record you receive, convert text elements to native data types based on the value of the first three fields of the record, then trigger an alert if that record meets defined requirements" and assuming you have maps from record values to conversion functions for record elements, and a map from record types to alert criteria functions for record types already constructed, it seems like a one liner to me. >> What if you are composing >> three or four functions, each of which is conditional on the data? ?If >> you extract things from a statement and assign them somewhat arbitrary >> names, you've just traded horizontal bloat for vertical bloat (with a >> net increase in volume), while forcing a reader to scan back and forth >> to different statements to understand what is happening. > > First off, vertical bloat is easier to cope with than horizontal bloat, > at least for people used to reading left-to-right rather than vertically. > There are few anti-patterns worse that horizontal scrolling, especially > for text. I agree that if a line goes into horizontal scroll buffer, you have a problem. Of course, I often rail on parenthesized function-taking-arguments expression structure for the fact that it forces you to read inside out and right to left, and I'd prefer not to conflate the two issues here. My assertion is that given an expression structure that reads naturally regardless, horizontal bloat is better than larger vertical bloat, in particular when the vertical bloat does not fall along clean semantic boundaries. > Secondly, the human brain can only deal with a limited number of tokens > at any one time. It's easier to remember large numbers when they are > broken up into chunks: > > 824-791-259-401 versus 824791259401 > > (three tokens, versus twelve) > > Likewise for reading code. Chunking code into multiple lines instead of > one long expression, and temporary variables, make things easier to > understand, not harder. This is true, when the tokens are an abstraction. I read some of the research on chunking, basically it came down to people being able to remember multiple numbers efficiently in an auditory fashion using phonemes. Words versus random letter combinations have the same effect, only with visual images (which is why I think Paul Graham is full of shit with regards to his "shorter is better than descriptive" mantra in old essays). This doesn't really apply if storing the elements in batches doesn't provide a more efficient representation. Of course, if you can get your statements to read like sensible English sentences, there is definitely a reduction in cognitive load. > And thirdly, you're not "forcing" the reader to scan back and forth -- or > at least if you are, then you've chosen your functions badly. Functions > should have descriptive names and should perform a meaningful task, not > just an arbitrary collection of code. This is why I quoted Einstein. I support breaking compound logical statements down to simple statements, then combining those simple statements. The problem arises when your compound statement still looks like "A B C D E F G H I J K L M N", and portions of that compound statement don't have a lot of meaning outside the larger statement. You could say X = A B C D E, Y = F G H I J, Z = K L M N, then say X Y Z, but now you've created bloat and forced the reader to backtrack. > > When you read: > > x = range(3, len(sequence), 5) > > you're not forced to scan back and forth between that line and the code > for range and len to understand it, because range and len are good > abstractions that make sensible functions. > > There is a lot of badly written code in existence. Don't blame poor > execution of design principles on the design principle itself. I like to be fair and even handed, and I recognize that tool and language creators don't control users. At the same time, it is a fundamental truth that people are much more inclined to laziness and ignorance than their complements. Any exceptional design will recognize this and make doing the right thing the intuitive, expedient choice. From this perspective I feel morally obligated to lay some blame at the feet of language or tool creator when a person misuses their creation in a way easily predicted given his or her nature. > [...] >> Also, because of Sphinx, it is very common in the Python community weave >> documents and code together in a way that is convenient for authors but >> irritating for readers. > > I don't know about "very common". I suspect, given the general paucity of > documentation in the average software package, it is more like "very > rare, but memorable when it does happen". Well, as a textbook example, the Pocoo projects tend to this. FormAlchemy is another offender. This is just off the top of my head. >> I personally would prefer not to have to scroll >> past 100 lines of a tutorial with examples, tests and what not in order >> to go from one function to another. > > Agreed. Docstrings should use a minimal number of examples and tests. > Tutorials and extensive tests should be extracted into external documents. I don't even mind having tutorials and doctests in the same file, I just don't like them to be interleaved. I really like module level docstrings, and class docstrings are sometimes useful; it is function docstrings that I usually find irritating. From showell30 at yahoo.com Wed Mar 21 00:58:14 2012 From: showell30 at yahoo.com (Steve Howell) Date: Tue, 20 Mar 2012 21:58:14 -0700 (PDT) Subject: Python is readable References: <4f612b19$0$1379$4fafbaef@reader2.news.tin.it> <8e72d74f-c844-4de3-8a37-f6b1fdc2291f@y27g2000yqy.googlegroups.com> <50e9ceec-40f1-4ead-b2b6-87328b30d084@ow8g2000pbc.googlegroups.com> <4f691f3d$0$29981$c3e8da3$5496439d@news.astraweb.com> <87d386lmai.fsf@benfinney.id.au> <8a77bf8d-b12f-442b-a1a3-479b5d66d366@tx8g2000pbc.googlegroups.com> Message-ID: On Mar 20, 9:16?pm, Chris Angelico wrote: > On Wed, Mar 21, 2012 at 1:44 PM, Steve Howell wrote: > > I think it's a matter of perspective, so there's no right answer, but > > I always think of the program object as also being the grammatical > > object, with the implied subject/actor being Python itself. ?For > > example, consider this code: > > > ?stack.push(item) > > > It's not the stack that's pushing. ?It's the stack being pushed on > > to. > > In code, though, the push() method is defined in and on the stack > object (or more likely, on the class that instantiated it, but near > enough). [...] The interpretation that the "subject" is the Stack class itself leads to this coding style: Stack.push(stack, item) The above code takes duck-typing to an extreme--you don't have to assume that "stack" was instantiated from "Stack" in order to apply "Stack.push" to "stack" (where "Stack" acts a the subject and "stack" acts as a grammatical direct object). Of course, 99% of the time, we want some sugar that makes Stack be the implicit subject (given that "stack" was instantiated from "Stack"): stack.push(item) # push comes from Stack via stack > Yes, the implied subject could be the > language interpreter; but it could just as easily be the CPU, or those > friendly nanobots, or that guy moving the rocks in XKCD 505. But in > the abstraction of the line of code, you don't care how CPython goes > about loading globals, calling bound methods, and incrementing object > reference counts - you just care that the stack is pushing this item > onto itself. Sure, that's all good, but, colloquially, I bet you've probably said at one time in your life, "And, here, we are pushing the item on to the stack." The subject is vague ("we"), but there is no assumption of friendly nanobots (or vigorous hamsters, or CPUs, or any specific mechanisms), just the idea that the stack is the object, not the subject. > Some method names are definitely written as though their primary > argument is the object, not the subject. Either option works. Do you > think about code as the subject+verb and a data structure as the > object, or the object as the subject and the method as the verb? > Fundamentally no difference. At a certain fundamental level, sure, of course it's all just data structure and code, so we shouldn't be quibbling about syntax or grammar, and we certainly shouldn't be throwing around strained analogies to natural languages. But in this context, we are musing about grammar, so I would propose this question: What's more important, the object or the method? IMHO the method is usually more interesting than the object itself. Of course, the "stack" itself is important, but on any given line of code, the action is more interesting, so I'd want to lead with "push" or "pop." Verb-first gets a bad rap, because people tend to associate verb-first syntax with early, primitive imperative/functional languages that had no OO syntax. Assembly tends to be very imperative: MOV AX, BX So saying "push(stack, item)" or "push(item, stack)" seems very unsophisticated, almost assembly-like in syntax, albeit at a higher level conceptually than assembly. From rosuav at gmail.com Wed Mar 21 01:40:18 2012 From: rosuav at gmail.com (Chris Angelico) Date: Wed, 21 Mar 2012 16:40:18 +1100 Subject: Python is readable In-Reply-To: References: <4f612b19$0$1379$4fafbaef@reader2.news.tin.it> <8e72d74f-c844-4de3-8a37-f6b1fdc2291f@y27g2000yqy.googlegroups.com> <50e9ceec-40f1-4ead-b2b6-87328b30d084@ow8g2000pbc.googlegroups.com> <4f691f3d$0$29981$c3e8da3$5496439d@news.astraweb.com> <87d386lmai.fsf@benfinney.id.au> <8a77bf8d-b12f-442b-a1a3-479b5d66d366@tx8g2000pbc.googlegroups.com> Message-ID: On Wed, Mar 21, 2012 at 3:58 PM, Steve Howell wrote: > So saying "push(stack, item)" or "push(item, stack)" seems very > unsophisticated, almost assembly-like in syntax, albeit at a higher > level conceptually than assembly. Perhaps it does, but "push(stack, item)" and "stack.push(item)" are so close to identical as makes no odds (in a number of languages, the latter is just syntactic sugar for something like the former) - yet they "read" quite differently, one with verb first, one with noun first. Code doesn't follow the same grammar as English prose, and forcing it to usually makes it sound odd. Reader.can_comprehend(code) is True. ChrisA From showell30 at yahoo.com Wed Mar 21 02:52:47 2012 From: showell30 at yahoo.com (Steve Howell) Date: Tue, 20 Mar 2012 23:52:47 -0700 (PDT) Subject: Python is readable References: <4f612b19$0$1379$4fafbaef@reader2.news.tin.it> <50e9ceec-40f1-4ead-b2b6-87328b30d084@ow8g2000pbc.googlegroups.com> <4f691f3d$0$29981$c3e8da3$5496439d@news.astraweb.com> <87d386lmai.fsf@benfinney.id.au> <8a77bf8d-b12f-442b-a1a3-479b5d66d366@tx8g2000pbc.googlegroups.com> Message-ID: <6af70db0-dc4a-48ee-9ee2-1a934846d5f2@r2g2000pbs.googlegroups.com> On Mar 20, 10:40?pm, Chris Angelico wrote: > On Wed, Mar 21, 2012 at 3:58 PM, Steve Howell wrote: > > So saying "push(stack, item)" or "push(item, stack)" seems very > > unsophisticated, almost assembly-like in syntax, albeit at a higher > > level conceptually than assembly. > > Perhaps it does, but "push(stack, item)" and "stack.push(item)" are so > close to identical as makes no odds (in a number of languages, the > latter is just syntactic sugar for something like the former) - yet > they "read" quite differently, one with verb first, one with noun > first. > On the one hand, you say that "push(stack, item)" reads quite differently from "stack.push(item)". On the other hand, you say they are "so close to identical as makes no odds." I'm trying to make sense of that. Are you saying that the way the two idioms read makes no odds, despite reading quite differently? > Code doesn't follow the same grammar as English prose, and forcing it > to usually makes it sound odd. Reader.can_comprehend(code) is True. > Code shouldn't necessarily follow the example of English prose, but it seems that English has had some influence: 1 push(stack, item) # Push on the stack the item 2 push(item, stack) # Push the item on the stack 3 stack.push(item) # On the stack, push the item 4 stack item push # On the stack, take the item and push it 5 item stack push # Take the item and on the stack, push the former. 6 item push stack # Take the item; push it on the stack. The first three ways are the most common ways of arranging the grammar in mainstream programming languages, and they are also the three most natural ways in English (no pronouns required). #1/2 are imperative. #3 is OO. #4 and #5 are sort of Forth-like, maybe? #6 is just downright strange. From rosuav at gmail.com Wed Mar 21 02:59:23 2012 From: rosuav at gmail.com (Chris Angelico) Date: Wed, 21 Mar 2012 17:59:23 +1100 Subject: Python is readable In-Reply-To: <6af70db0-dc4a-48ee-9ee2-1a934846d5f2@r2g2000pbs.googlegroups.com> References: <4f612b19$0$1379$4fafbaef@reader2.news.tin.it> <50e9ceec-40f1-4ead-b2b6-87328b30d084@ow8g2000pbc.googlegroups.com> <4f691f3d$0$29981$c3e8da3$5496439d@news.astraweb.com> <87d386lmai.fsf@benfinney.id.au> <8a77bf8d-b12f-442b-a1a3-479b5d66d366@tx8g2000pbc.googlegroups.com> <6af70db0-dc4a-48ee-9ee2-1a934846d5f2@r2g2000pbs.googlegroups.com> Message-ID: On Wed, Mar 21, 2012 at 5:52 PM, Steve Howell wrote: > On the one hand, you say that "push(stack, item)" reads quite > differently from "stack.push(item)". > > On the other hand, you say they are "so close to identical as makes no > odds." > > I'm trying to make sense of that. ?Are you saying that the way the two > idioms read makes no odds, despite reading quite differently? If you're designing a language (or, often, a library/module), you can choose either option without greatly annoying your users. As a programmer, I use both types of API all the time. Yes, they read differently, but neither is confusing, and you can easily grok that they do the same thing. ChrisA From clp2 at rebertia.com Wed Mar 21 03:16:49 2012 From: clp2 at rebertia.com (Chris Rebert) Date: Wed, 21 Mar 2012 00:16:49 -0700 Subject: Python is readable In-Reply-To: <6af70db0-dc4a-48ee-9ee2-1a934846d5f2@r2g2000pbs.googlegroups.com> References: <4f612b19$0$1379$4fafbaef@reader2.news.tin.it> <50e9ceec-40f1-4ead-b2b6-87328b30d084@ow8g2000pbc.googlegroups.com> <4f691f3d$0$29981$c3e8da3$5496439d@news.astraweb.com> <87d386lmai.fsf@benfinney.id.au> <8a77bf8d-b12f-442b-a1a3-479b5d66d366@tx8g2000pbc.googlegroups.com> <6af70db0-dc4a-48ee-9ee2-1a934846d5f2@r2g2000pbs.googlegroups.com> Message-ID: On Tue, Mar 20, 2012 at 11:52 PM, Steve Howell wrote: > On Mar 20, 10:40?pm, Chris Angelico wrote: >> On Wed, Mar 21, 2012 at 3:58 PM, Steve Howell wrote: >> > So saying "push(stack, item)" or "push(item, stack)" seems very >> > unsophisticated, almost assembly-like in syntax, albeit at a higher >> > level conceptually than assembly. >> >> Perhaps it does, but "push(stack, item)" and "stack.push(item)" are so >> close to identical as makes no odds (in a number of languages, the >> latter is just syntactic sugar for something like the former) - yet >> they "read" quite differently, one with verb first, one with noun >> first. > > On the one hand, you say that "push(stack, item)" reads quite > differently from "stack.push(item)". > > On the other hand, you say they are "so close to identical as makes no > odds." > > I'm trying to make sense of that. ?Are you saying that the way the two > idioms read makes no odds, despite reading quite differently? > >> Code doesn't follow the same grammar as English prose, and forcing it >> to usually makes it sound odd. Reader.can_comprehend(code) is True. > > Code shouldn't necessarily follow the example of English prose, but it > seems that English has had some influence: > > ?1 ?push(stack, item) # Push on the stack the item > ?2 ?push(item, stack) # Push the item on the stack > 3 stack.push(item) # On the stack, push the item > ?6 ?item push stack ? # Take the item; push it on the stack. > #4 and #5 are sort of Forth-like, maybe? ?#6 is just downright > strange. #6 is just an infix binary operator (likewise with its cousin #3, just remove the punctuation). If you change the name slightly, it becomes more sensical. One could easily write in Haskell: item `pushOnto` stack which would just be syntactic sugar for #2. Not that I endorse #6, merely saying it's less weird than you think. Cheers, Chris From chardster at gmail.com Wed Mar 21 03:42:19 2012 From: chardster at gmail.com (Richard Thomas) Date: Wed, 21 Mar 2012 00:42:19 -0700 (PDT) Subject: setup.py for an extension In-Reply-To: References: Message-ID: <13339221.934.1332315740021.JavaMail.geo-discussion-forums@ynim7> Assuming you have: lib/__init__.py lib/foo.py lib/foo.c Then: from distutils.core import setup, Extension setup(name="lib", packages=["lib"], ext_modules=[Extension("lib._foo", ["lib/foo.c"])]) From showell30 at yahoo.com Wed Mar 21 03:57:36 2012 From: showell30 at yahoo.com (Steve Howell) Date: Wed, 21 Mar 2012 00:57:36 -0700 (PDT) Subject: Python is readable References: <4f612b19$0$1379$4fafbaef@reader2.news.tin.it> <4f691f3d$0$29981$c3e8da3$5496439d@news.astraweb.com> <87d386lmai.fsf@benfinney.id.au> <8a77bf8d-b12f-442b-a1a3-479b5d66d366@tx8g2000pbc.googlegroups.com> <6af70db0-dc4a-48ee-9ee2-1a934846d5f2@r2g2000pbs.googlegroups.com> Message-ID: <6a4c821e-3672-401a-9a35-e0950734c22f@ms3g2000pbb.googlegroups.com> On Mar 21, 12:16?am, Chris Rebert wrote: > On Tue, Mar 20, 2012 at 11:52 PM, Steve Howell wrote: > > On Mar 20, 10:40?pm, Chris Angelico wrote: > >> On Wed, Mar 21, 2012 at 3:58 PM, Steve Howell wrote: > >> > So saying "push(stack, item)" or "push(item, stack)" seems very > >> > unsophisticated, almost assembly-like in syntax, albeit at a higher > >> > level conceptually than assembly. > > >> Perhaps it does, but "push(stack, item)" and "stack.push(item)" are so > >> close to identical as makes no odds (in a number of languages, the > >> latter is just syntactic sugar for something like the former) - yet > >> they "read" quite differently, one with verb first, one with noun > >> first. > > > On the one hand, you say that "push(stack, item)" reads quite > > differently from "stack.push(item)". > > > On the other hand, you say they are "so close to identical as makes no > > odds." > > > I'm trying to make sense of that. ?Are you saying that the way the two > > idioms read makes no odds, despite reading quite differently? > > >> Code doesn't follow the same grammar as English prose, and forcing it > >> to usually makes it sound odd. Reader.can_comprehend(code) is True. > > > Code shouldn't necessarily follow the example of English prose, but it > > seems that English has had some influence: > > > ?1 ?push(stack, item) # Push on the stack the item > > ?2 ?push(item, stack) # Push the item on the stack > > ?3 ?stack.push(item) ?# On the stack, push the item > > > ?6 ?item push stack ? # Take the item; push it on the stack. > > > #4 and #5 are sort of Forth-like, maybe? ?#6 is just downright > > strange. > > #6 is just an infix binary operator (likewise with its cousin #3, just > remove the punctuation). If you change the name slightly, it becomes > more sensical. One could easily write in Haskell: > ? ? item `pushOnto` stack > which would just be syntactic sugar for #2. Not that I endorse #6, > merely saying it's less weird than you think. > Ha, you're right, verb-in-the-middle is just infix. So, if you don't care about the order of the nouns, you have three forms: verb first: English-imperative ("boil water", "add noodles/salt", "serve in dish") or math-functional, e.g. sum(a,b,c) verb middle: infix, arithmetic-like ("5 plus 4", "10 divided by 2") or English-descriptive ("Dog bites man") verb last: Forth-like, maps well to simple underlying implementation I guess the OO syntax is really verb-first when you think of "stack.push" as the verb. From rosuav at gmail.com Wed Mar 21 04:15:22 2012 From: rosuav at gmail.com (Chris Angelico) Date: Wed, 21 Mar 2012 19:15:22 +1100 Subject: Python is readable In-Reply-To: <6a4c821e-3672-401a-9a35-e0950734c22f@ms3g2000pbb.googlegroups.com> References: <4f612b19$0$1379$4fafbaef@reader2.news.tin.it> <4f691f3d$0$29981$c3e8da3$5496439d@news.astraweb.com> <87d386lmai.fsf@benfinney.id.au> <8a77bf8d-b12f-442b-a1a3-479b5d66d366@tx8g2000pbc.googlegroups.com> <6af70db0-dc4a-48ee-9ee2-1a934846d5f2@r2g2000pbs.googlegroups.com> <6a4c821e-3672-401a-9a35-e0950734c22f@ms3g2000pbb.googlegroups.com> Message-ID: On Wed, Mar 21, 2012 at 6:57 PM, Steve Howell wrote: > ?verb first: English-imperative ("boil water", "add noodles/salt", > "serve in dish") or math-functional, e.g. sum(a,b,c) > ?verb middle: infix, arithmetic-like ("5 plus 4", "10 divided by 2") > or English-descriptive ("Dog bites man") In English, verb-first imperative is just verb-middle descriptive with an implied "You" as the subject. Its nearest equivalent in code, then, is the common idiom of omitting the 'this' argument (eg in C++), which Python doesn't support. ChrisA From deets at web.de Wed Mar 21 07:38:03 2012 From: deets at web.de (Diez B. Roggisch) Date: Wed, 21 Mar 2012 12:38:03 +0100 Subject: pypi and dependencies References: Message-ID: Andrea Crotti writes: > When I publish something on Pypi, is there a way to make it fetch the > list of dependencies needed by my project automatically? > > It would be nice to have it in the Pypi page, without having to look > at the actual code.. > Any other possible solution? I don't understand this - if you declare the dependencies of your published package in the requires-section of the setup()-call, easy_install (and I guess pip as well, no experience with it) will automatically fetch these. Is that what you wanted to know? Diez From deets at web.de Wed Mar 21 07:40:56 2012 From: deets at web.de (Diez B. Roggisch) Date: Wed, 21 Mar 2012 12:40:56 +0100 Subject: configobj validation References: <4F672DBF.5060506@gmail.com> Message-ID: Andrea Crotti writes: > On 03/19/2012 12:59 PM, Andrea Crotti wrote: >> I seemed to remember that type validation and type conversion worked >> out of the box, but now >> I can't get it working anymore. >> >> Shouldn't this simple example actually fail the parsing (instead it >> parses perfectly port to a string)? >> >> sample.py: >> from configobj import ConfigObj >> >> conf = ConfigObj('sample.conf', configspec='sample.spec') >> >> sample.conf: >> port = some_string >> >> sample.spec: >> port = integer(0, 10) >> >> PS. using configobj 4.7.2 > > I now checked the repo and configobj seems also quite dead (2 years > ago last version), it's a pity because it's a really nice library. > Any other alternatives for validation/configuration systems otherwise? It works - so why do you bother? And I'm not sure about the above code - AFAIK, validation is a two-step thing: http://www.voidspace.org.uk/python/articles/configobj.shtml#validation Diez From gandalf at shopzeus.com Wed Mar 21 08:38:10 2012 From: gandalf at shopzeus.com (Laszlo Nagy) Date: Wed, 21 Mar 2012 13:38:10 +0100 Subject: urllib.urlretrieve never returns??? In-Reply-To: <5B80DD153D7D744689F57F4FB69AF474026C4C97@SCACMX008.exchad.jpmchase.net> References: <4F649BFC.1080601@shopzeus.com> <4F66E687.2050008@shopzeus.com> <4f67c09b$0$29981$c3e8da3$5496439d@news.astraweb.com> <4F682CDC.5000703@shopzeus.com> <4F68E49C.2060000@shopzeus.com> <5B80DD153D7D744689F57F4FB69AF474026C4BD8@SCACMX008.exchad.jpmchase.net> <5B80DD153D7D744689F57F4FB69AF474026C4C97@SCACMX008.exchad.jpmchase.net> Message-ID: <4F69CBB2.6060801@shopzeus.com> On 2012-03-20 22:26, Prasad, Ramit wrote: > I just looked at your source file on ActiveState and noticed that > you do not import traceback. That is why you are getting the > AttributeError. Now you should be getting a much better error > once you import it:) Nope. That would result in a NameError. After adding "import traceback", I still get several AttributeError messages. The traceback should contain the exact line number, and a description about what object is missing what attribute anyway. My code is pure Python, and under no circumstances should it be able to start a blocked call for a system library function. From andrea.crotti.0 at gmail.com Wed Mar 21 09:03:44 2012 From: andrea.crotti.0 at gmail.com (Andrea Crotti) Date: Wed, 21 Mar 2012 13:03:44 +0000 Subject: pypi and dependencies In-Reply-To: References: Message-ID: <4F69D1B0.9030102@gmail.com> On 03/21/2012 11:38 AM, Diez B. Roggisch wrote: > Andrea Crotti writes: > >> When I publish something on Pypi, is there a way to make it fetch the >> list of dependencies needed by my project automatically? >> >> It would be nice to have it in the Pypi page, without having to look >> at the actual code.. >> Any other possible solution? > I don't understand this - if you declare the dependencies of your > published package in the requires-section of the setup()-call, > easy_install (and I guess pip as well, no experience with it) will > automatically fetch these. > > Is that what you wanted to know? > > Diez It would be nice to know the dependencies *before* you actually try to install it ;) From andrea.crotti.0 at gmail.com Wed Mar 21 09:06:06 2012 From: andrea.crotti.0 at gmail.com (Andrea Crotti) Date: Wed, 21 Mar 2012 13:06:06 +0000 Subject: configobj validation In-Reply-To: References: <4F672DBF.5060506@gmail.com> Message-ID: <4F69D23E.8020905@gmail.com> On 03/21/2012 11:40 AM, Diez B. Roggisch wrote: > Andrea Crotti writes: > > It works - so why do you bother? And I'm not sure about the above code - > AFAIK, validation is a two-step thing: > > http://www.voidspace.org.uk/python/articles/configobj.shtml#validation > > Diez I don't agree, if you write code that is supposed to work with Python3, using a library which is not developed and will probably never support Python3 is quite a stupid idea ;) Any other validation mechanism that can be plugged in ConfigParser for example? From what I've understood from the doc and what I remembered I thought that validation is automatically done when passing the configspec, but I'll check if the two steps work.. From jcd at sdf.lonestar.org Wed Mar 21 09:50:54 2012 From: jcd at sdf.lonestar.org (J. Cliff Dyer) Date: Wed, 21 Mar 2012 09:50:54 -0400 Subject: List comprehension/genexp inconsistency. In-Reply-To: References: <1332275002.10958.7.camel@jcdyer-laptop> Message-ID: <1332337854.2737.4.camel@jcdyer-laptop> Thanks, Ian. That does seem to explain it. The inner loop doesn't have access to the class's name space, and of course you can't fix it by referencing Foo.y explicitly, because the class isn't fully defined yet. Ultimately, we realized that the dict should be created in the __init__ method, so that it gets the appropriate values of the foo and bar attributes if the class is subclassed, which obviates the problem, but it's a fascinating peek into python internals. It looks like this is explained in the section of the pep entitled "Early Binding versus Late Binding" http://www.python.org/dev/peps/pep-0289/#early-binding-versus-late-binding Cheers, Cliff On Tue, 2012-03-20 at 16:50 -0600, Ian Kelly wrote: > On Tue, Mar 20, 2012 at 3:16 PM, Dennis Lee Bieber > wrote: > > On Tue, 20 Mar 2012 16:23:22 -0400, "J. Cliff Dyer" > > declaimed the following in > > gmane.comp.python.general: > > > >> > >> When trying to create a class with a dual-loop generator expression in a > >> class definition, there is a strange scoping issue where the inner > >> variable is not found, (but the outer loop variable is found), while a > >> list comprehension has no problem finding both variables. > >> > > Read http://www.python.org/dev/peps/pep-0289/ -- in particular, look > > for the word "leak" > > No, this has nothing to do with the loop variable leaking. It appears > to have to do with the fact that the variables and the generator > expression are inside a class block. I think that it's related to the > reason that this doesn't work: > > class Foo(object): > x = 42 > def foo(): > print(x) > foo() > > In this case, x is not a local variable of foo, nor is it a global. > In order for foo to access x, it would have to be a closure -- but > Python can't make it a closure in this case, because the variable it > accesses is (or rather, will become) a class attribute, not a local > variable of a function that can be stored in a cell. Instead, the > compiler just makes it a global reference in the hope that such a > global will actually be defined when the code is run. > > For that reason, what surprises me about Cliff's example is that a > generator expression works at all in that context. It seems to work > as long as it contains only one loop, but not if it contains two. To > find out why, I tried disassembling one: > > >>> class Foo(object): > ... x = 42 > ... y = 12 > ... g = (a+b for a in range(x) for b in range(y)) > ... > >>> dis.dis(Foo.g.gi_code) > 4 0 LOAD_FAST 0 (.0) > >> 3 FOR_ITER 34 (to 40) > 6 STORE_FAST 1 (a) > 9 LOAD_GLOBAL 0 (range) > 12 LOAD_GLOBAL 1 (y) > 15 CALL_FUNCTION 1 > 18 GET_ITER > >> 19 FOR_ITER 15 (to 37) > 22 STORE_FAST 2 (b) > 25 LOAD_FAST 1 (a) > 28 LOAD_FAST 2 (b) > 31 BINARY_ADD > 32 YIELD_VALUE > 33 POP_TOP > 34 JUMP_ABSOLUTE 19 > >> 37 JUMP_ABSOLUTE 3 > >> 40 LOAD_CONST 0 (None) > 43 RETURN_VALUE > > So that explains it. Notice that "x" is never actually accessed in > that disassembly; only "y" is. It turns out that the first iterator > [range(x)] is actually created before the generator ever starts > executing, and is stored as an anonymous local variable on the > generator's stack frame -- so it's created in the class scope, not in > the generator scope. The second iterator, however, is recreated on > every iteration of the first iterator, so it can't be pre-built in > that manner. It does get created in the generator scope, and when > that happens it blows up because it can't find the variable, just like > the function example above. > > Cheers, > Ian From ralph.heinkel at web.de Wed Mar 21 11:06:47 2012 From: ralph.heinkel at web.de (Ralph Heinkel) Date: Wed, 21 Mar 2012 08:06:47 -0700 (PDT) Subject: Compiling Python (modules) on 64bit Windows - which compiler suite? Message-ID: <808abad4-3ab3-4336-8a31-2f88eb28be01@v22g2000vby.googlegroups.com> Hi, when processing our mass spectrometry data we are running against the 2GB memory limit on our 32 bit machines. So we are planning to move to 64bit. Downloading and installing the 64bit version of Python for Windows is trivial, but how do we compile our own C extension? Visual C ++ 2008 express comes for free, but only compiles for 32 bit. What has been used to compile the downloadable Python Win64 bit version? Visual Studio professional? The problem with the professional edition is that it is hard to obtain and it is sort of out-of-date - nowadays everyone uses Visual Studio 2010 (or even 2011 coming soon). So if Visual Studio 2008 professional is required for compiling 64bit modules, we would have to spend $1200 for a license which is actually rather out of date. Any hints or suggestions are very welcome. Thanks, Ralph From esyrkina at gmail.com Wed Mar 21 11:15:52 2012 From: esyrkina at gmail.com (Katya) Date: Wed, 21 Mar 2012 08:15:52 -0700 (PDT) Subject: ReportLab alternative for Python3 Message-ID: <24078051.142.1332342952564.JavaMail.geo-discussion-forums@vbat19> I have a Python3 GUI, where user selects certain values to be statistically evaluated and/or plotted (matplotlib hist). Out of this GUI on user's request I want to create a report, prefferebly in DOC or/and ODT or/and PDF or/and HTML formats. The layout of the report is pretty much fixed, what will change is: the names of the selected measures and the corresponding values (there are always three measures to display - user selects which), matplotlib histogram (only image will change depending on the selected settings, but not its size/location), user name, date etc. ReportLab which seems to be suitable is not ready for Python3. I also found a reference to pod package (http://appyframework.org/pod.html) which looks very close to my needs. But pod does NOT support Python3, also after 2to3 convertion and couple of small fixes. Any suggestions are greatly appreciated since the rest of the project is nearly done and this is the last big unsolved problem! Thanks, Katya From rodperson at rodperson.com Wed Mar 21 11:25:03 2012 From: rodperson at rodperson.com (Rod Person) Date: Wed, 21 Mar 2012 11:25:03 -0400 Subject: class checking its own module for an attribute Message-ID: <20120321112503.00006eb5@unknown> We have a module called constants.py, which contains related to server names, databases, service account users and there passwords. In order to be able to use constants as command line parameters for calling from our batch files I created the class below that checks to make sure the parameter value is a valid constant and if so return it's value. class ConstantParameterCheck(Action): def __call__(self, parser, namespace, value, option_string=None): if value: if not hasattr(CCBH.constants, value): message = ("Invalid parameter value: {0!r}. Value must be a value constant in CCBH.constants.".format(value)) raise ArgumentError(self, message) setattr(namespace, self.dest, getattr(CCBH.constants, value)) This works great, but it has to be placed in every script, so I decided why not place this in the constants.py module so it can just be imported. So I did that and got it to work like this: class ConstantParameterCheck(Action): def __call__(self, parser, namespace, value, option_string=None): from CCBH import constants if value: if not hasattr(constants, value): message = ("Invalid parameter value: {0!r}. Value must be a value constant in CCBH.constants.".format(value)) raise ArgumentError(self, message) setattr(namespace, self.dest, getattr(CCBH.constants, value)) The question is there a way I can do this with out having to import constants when what it's doing is importing itself. It would seem to me that there should be a way for a module to reference itself. In that thinking I have tried if not(hasattr(__file__, value): if not(hasattr(__name__, value): and even: this = sys.argv[0] if not(hasattr(this, value): None of which works. -- Rod Person http://www.rodperson.com rodperson at rodperson.com 'Silence is a fence around wisdom' From driscoll at cs.wisc.edu Wed Mar 21 12:22:01 2012 From: driscoll at cs.wisc.edu (Evan Driscoll) Date: Wed, 21 Mar 2012 11:22:01 -0500 Subject: Python is readable In-Reply-To: <6af70db0-dc4a-48ee-9ee2-1a934846d5f2@r2g2000pbs.googlegroups.com> References: <4f612b19$0$1379$4fafbaef@reader2.news.tin.it> <50e9ceec-40f1-4ead-b2b6-87328b30d084@ow8g2000pbc.googlegroups.com> <4f691f3d$0$29981$c3e8da3$5496439d@news.astraweb.com> <87d386lmai.fsf@benfinney.id.au> <8a77bf8d-b12f-442b-a1a3-479b5d66d366@tx8g2000pbc.googlegroups.com> <6af70db0-dc4a-48ee-9ee2-1a934846d5f2@r2g2000pbs.googlegroups.com> Message-ID: <4F6A0029.6090702@cs.wisc.edu> On 01/-10/-28163 01:59 PM, Steve Howell wrote: > Code shouldn't necessarily follow the example of English prose, but it > seems that English has had some influence: > > 1 push(stack, item) # Push on the stack the item > 2 push(item, stack) # Push the item on the stack > 3 stack.push(item) # On the stack, push the item > 4 stack item push # On the stack, take the item and push it > 5 item stack push # Take the item and on the stack, push the > former. > 6 item push stack # Take the item; push it on the stack. > > The first three ways are the most common ways of arranging the grammar > in mainstream programming languages, and they are also the three most > natural ways in English (no pronouns required). > > #1/2 are imperative. #3 is OO. In my opinion, people who make statements such as "#1/2 are imperative, #3 is OO" are missing pretty much the entire point of what OO is. OO is much more about semantics and the way code is structured. The difference between #1/2 (especially #1, of course) and #3 is surface-level syntax only. About the strongest statement you can make along those lines is that #3 will allow you to do dynamic dispatch on the type of 'stack' while #1/2 won't, but even that isn't true of course. For instance, CLOS will let you write '(push stack item)' (which is the direct analogy in that language to #1) and do even more powerful dynamic dispatch than what a language like C++, Java, or Python will let you do. Evan From showell30 at yahoo.com Wed Mar 21 12:30:07 2012 From: showell30 at yahoo.com (Steve Howell) Date: Wed, 21 Mar 2012 09:30:07 -0700 (PDT) Subject: Python is readable References: <4f612b19$0$1379$4fafbaef@reader2.news.tin.it> <4f691f3d$0$29981$c3e8da3$5496439d@news.astraweb.com> <87d386lmai.fsf@benfinney.id.au> <8a77bf8d-b12f-442b-a1a3-479b5d66d366@tx8g2000pbc.googlegroups.com> <6af70db0-dc4a-48ee-9ee2-1a934846d5f2@r2g2000pbs.googlegroups.com> Message-ID: On Mar 21, 9:22?am, Evan Driscoll wrote: > On 01/-10/-28163 01:59 PM, Steve Howell wrote: > > > > > > > > > > > Code shouldn't necessarily follow the example of English prose, but it > > seems that English has had some influence: > > > ? 1 ?push(stack, item) # Push on the stack the item > > ? 2 ?push(item, stack) # Push the item on the stack > > ? 3 ?stack.push(item) ?# On the stack, push the item > > ? 4 ?stack item push ? # On the stack, take the item and push it > > ? 5 ?item stack push ? # Take the item and on the stack, push the > > former. > > ? 6 ?item push stack ? # Take the item; push it on the stack. > > > The first three ways are the most common ways of arranging the grammar > > in mainstream programming languages, and they are also the three most > > natural ways in English (no pronouns required). > > > #1/2 are imperative. ?#3 is OO. > > In my opinion, people who make statements such as "#1/2 are imperative, > #3 is OO" are missing pretty much the entire point of what OO is. > > OO is much more about semantics and the way code is structured. The > difference between #1/2 (especially #1, of course) and #3 is > surface-level syntax only. > > About the strongest statement you can make along those lines is that #3 > will allow you to do dynamic dispatch on the type of 'stack' while #1/2 > won't, but even that isn't true of course. For instance, CLOS will let > you write '(push stack item)' (which is the direct analogy in that > language to #1) and do even more powerful dynamic dispatch than what a > language like C++, Java, or Python will let you do. > In the grand scheme of things, of course code structure and semantics are more important the surface-level syntax. If you take it as a given that structure/semantics are sound (big assumption, I know), then the next issue with regards to "readability" is the syntax itself. From stefan_ml at behnel.de Wed Mar 21 12:32:33 2012 From: stefan_ml at behnel.de (Stefan Behnel) Date: Wed, 21 Mar 2012 17:32:33 +0100 Subject: Fast file data retrieval? In-Reply-To: References: <4F5E50F6.9070309@it.uu.se> Message-ID: Jorgen Grahn, 13.03.2012 21:44: > On Mon, 2012-03-12, MRAB wrote: >> Probably the best solution is to put it into a database. Have a look at >> the sqlite3 module. > > Some people like to use databases for everything, others never use > them. I'm in the latter crowd, so to me this sounds as overkill Well, there's databases and databases. I agree that the complexity of a SQL database is likely unnecessary here since a key-value database (any of the dbm modules) appears to be sufficient from what the OP wrote. Stefan From clp2 at rebertia.com Wed Mar 21 12:56:57 2012 From: clp2 at rebertia.com (Chris Rebert) Date: Wed, 21 Mar 2012 09:56:57 -0700 Subject: class checking its own module for an attribute In-Reply-To: <20120321112503.00006eb5@unknown> References: <20120321112503.00006eb5@unknown> Message-ID: On Wed, Mar 21, 2012 at 8:25 AM, Rod Person wrote: > The question is there a way I can do this with out having to import > constants when what it's doing is importing itself. It would seem to me > that there should be a way for a module to reference itself. In that > thinking I have tried > > ?if not(hasattr(__file__, value): > ?if not(hasattr(__name__, value): > > and even: > > ?this = sys.argv[0] > ?if not(hasattr(this, value): > > None of which works. http://stackoverflow.com/questions/2933470/how-do-i-call-setattr-on-the-current-module Cheers, Chris From __peter__ at web.de Wed Mar 21 12:59:56 2012 From: __peter__ at web.de (Peter Otten) Date: Wed, 21 Mar 2012 17:59:56 +0100 Subject: class checking its own module for an attribute References: <20120321112503.00006eb5@unknown> Message-ID: Rod Person wrote: > We have a module called constants.py, which contains [whatever] related to > server names, databases, service account users and their passwords. Passwords? > In order to be able to use constants as command line parameters for > calling from our batch files I created the class below that checks to > make sure the parameter value is a valid constant and if so return its > value. Instead of > from CCBH import constants ... > if not hasattr(constants, value): ... You can look up the name in the global namespace: if value not in globals(): ... From rodperson at rodperson.com Wed Mar 21 13:06:55 2012 From: rodperson at rodperson.com (Rod Person) Date: Wed, 21 Mar 2012 13:06:55 -0400 Subject: class checking its own module for an attribute In-Reply-To: References: <20120321112503.00006eb5@unknown> Message-ID: <20120321130655.000040a2@unknown> On Wed, 21 Mar 2012 09:56:57 -0700 Chris Rebert wrote: > On Wed, Mar 21, 2012 at 8:25 AM, Rod Person > wrote: > > The question is there a way I can do this with out having to import > > constants when what it's doing is importing itself. It would seem > > to me that there should be a way for a module to reference itself. > > In that thinking I have tried > > > > ?if not(hasattr(__file__, value): > > ?if not(hasattr(__name__, value): > > > > and even: > > > > ?this = sys.argv[0] > > ?if not(hasattr(this, value): > > > > None of which works. > > http://stackoverflow.com/questions/2933470/how-do-i-call-setattr-on-the-current-module > > Cheers, > Chris Thank you! -- Rod Person http://www.rodperson.com rodperson at rodperson.com 'Silence is a fence around wisdom' From rodperson at rodperson.com Wed Mar 21 13:10:41 2012 From: rodperson at rodperson.com (Rod Person) Date: Wed, 21 Mar 2012 13:10:41 -0400 Subject: class checking its own module for an attribute In-Reply-To: References: <20120321112503.00006eb5@unknown> Message-ID: <20120321131041.00001dde@unknown> On Wed, 21 Mar 2012 17:59:56 +0100 Peter Otten <__peter__ at web.de> wrote: > Rod Person wrote: > > > We have a module called constants.py, which contains [whatever] > > related to server names, databases, service account users and their > > passwords. > > Passwords? > Yes, not the best thing, but they are only service account that run nightly batch jobs. Everyone in our IT department knows these password and users. I only deploy the .pyo or .pyc files for this module, although I'm looking into a better way than that. -- Rod Person http://www.rodperson.com rodperson at rodperson.com 'Silence is a fence around wisdom' From tjreedy at udel.edu Wed Mar 21 13:56:20 2012 From: tjreedy at udel.edu (Terry Reedy) Date: Wed, 21 Mar 2012 13:56:20 -0400 Subject: Compiling Python (modules) on 64bit Windows - which compiler suite? In-Reply-To: <808abad4-3ab3-4336-8a31-2f88eb28be01@v22g2000vby.googlegroups.com> References: <808abad4-3ab3-4336-8a31-2f88eb28be01@v22g2000vby.googlegroups.com> Message-ID: On 3/21/2012 11:06 AM, Ralph Heinkel wrote: > when processing our mass spectrometry data we are running against the > 2GB memory limit on our 32 bit machines. So we are planning to move to > 64bit. Downloading and installing the 64bit version of Python for > Windows is trivial, but how do we compile our own C extension? Visual C > ++ 2008 express comes for free, but only compiles for 32 bit. > > What has been used to compile the downloadable Python Win64 bit > version? Visual Studio professional? Yes. Python Windows devs get it for free from MS. > The problem with the professional edition is that it is hard to obtain > and it is sort of out-of-date - nowadays everyone uses Visual Studio > 2010 (or even 2011 coming soon). So if Visual Studio 2008 professional > is required for compiling 64bit modules, we would have to spend $1200 > for a license which is actually rather out of date. > > Any hints or suggestions are very welcome. I believe the intention is to release 3.3 compiled with VS 2010. Brian Curtin and Martin Loewis are working on that. I believe people have successfully built at least the basics with VS2010. You could also dual boot to Linux and get 64 bit gcc for free. -- Terry Jan Reedy From nathan.alexander.rice at gmail.com Wed Mar 21 14:06:50 2012 From: nathan.alexander.rice at gmail.com (Nathan Rice) Date: Wed, 21 Mar 2012 14:06:50 -0400 Subject: Python is readable In-Reply-To: References: <4f612b19$0$1379$4fafbaef@reader2.news.tin.it> <4f691f3d$0$29981$c3e8da3$5496439d@news.astraweb.com> <87d386lmai.fsf@benfinney.id.au> <8a77bf8d-b12f-442b-a1a3-479b5d66d366@tx8g2000pbc.googlegroups.com> <6af70db0-dc4a-48ee-9ee2-1a934846d5f2@r2g2000pbs.googlegroups.com> Message-ID: MOAR TROLLING... >> In my opinion, people who make statements such as "#1/2 are imperative, >> #3 is OO" are missing pretty much the entire point of what OO is. >> >> OO is much more about semantics and the way code is structured. The >> difference between #1/2 (especially #1, of course) and #3 is >> surface-level syntax only. The idea of actions as concrete attributes of entities is probably the worst bit of object oriented programming, except perhaps inheritance. Events occur in the context of multiple entities, but they are conceptually distinct and should not be subordinated. Furthermore, if you have an explicit self or this context, your ability to override elements of an event is limited to things which are directly encapsulated in that context. Additionally, dynamic dispatch induces overhead and the possibility of action at a distance. Reflective template meta-programming and explicit attribute delegation are VASTLY superior. To rant about inheritance, outside of mathematics platonic ideals are bullshit. Natural kinds are the closest we might actually be able to come to ideals, and philosophers still debate whether atomic elements and subatomic particles should have this designation. On the macro scale, classes or types are dynamic, fuzzy unions of structure, context and intent. Making any sort of invariant categorical statement about real things is just begging to be proven wrong. Programmers would be much better off if we made assertions about relationships and structure with an explicit, contextual reference. I think this would simplify code reuse, since you would be able to compare contexts to know if program elements were compatible and programs could be assembled by the union or intersection of sets of assertions. >> About the strongest statement you can make along those lines is that #3 >> will allow you to do dynamic dispatch on the type of 'stack' while #1/2 >> won't, but even that isn't true of course. For instance, CLOS will let >> you write '(push stack item)' (which is the direct analogy in that >> language to #1) and do even more powerful dynamic dispatch than what a >> language like C++, Java, or Python will let you do. >> > > In the grand scheme of things, of course code structure and semantics > are more important the surface-level syntax. > > If you take it as a given that structure/semantics are sound (big > assumption, I know), then the next issue with regards to "readability" > is the syntax itself. Sadly, defining sound (i.e. valid) language semantics is not terribly difficult; Turing complete systems occur spontaneously with surprising frequency in nature. The problem is that fundamentally, languages model the conceptual space at large, but language designers choose a semantic vocabulary that models their minuscule subset of that space. This semantic vocabulary is by its nature static, while the conceptual space is dynamic. We aren't going to get semantics really right until we model the dynamical meta structure of the concept space, and put abstract structure, context and intent at the fore. As for syntax, we have a lot of "real" domain specific languages, such as English, math and logic. They are vetted, understood and useful outside the context of programming. We should approach the discussion of language syntax from the perspective of trying to define a unified syntactical structure for real these DSLs. Ideally it would allow representation of things in a familiar way where possible, while providing an elegant mechanism for descriptions that cut across domains and eliminating redundancy/ambiguity. This is clearly possible, though a truly successful attempt would probably be a work of art for the ages. From emile at fenx.com Wed Mar 21 14:50:56 2012 From: emile at fenx.com (Emile van Sebille) Date: Wed, 21 Mar 2012 11:50:56 -0700 Subject: ReportLab alternative for Python3 In-Reply-To: <24078051.142.1332342952564.JavaMail.geo-discussion-forums@vbat19> References: <24078051.142.1332342952564.JavaMail.geo-discussion-forums@vbat19> Message-ID: On 3/21/2012 8:15 AM Katya said... > Out of this GUI on user's request I want to create a report, > prefferebly in DOC or/and ODT or/and PDF or/and HTML formats. > ReportLab which seems to be suitable is not ready for Python3. So, any reason why not to just run that part under python2 -- they typically live side-by-side without issues. Emile From thbach at students.uni-mainz.de Wed Mar 21 15:03:01 2012 From: thbach at students.uni-mainz.de (Thomas Bach) Date: Wed, 21 Mar 2012 20:03:01 +0100 Subject: Compiling Python (modules) on 64bit Windows - which compiler suite? In-Reply-To: <808abad4-3ab3-4336-8a31-2f88eb28be01@v22g2000vby.googlegroups.com> (Ralph Heinkel's message of "Wed, 21 Mar 2012 08:06:47 -0700") References: <808abad4-3ab3-4336-8a31-2f88eb28be01@v22g2000vby.googlegroups.com> Message-ID: <874nthu68q.fsf@jubold.box> Hi, Ralph Heinkel writes: > Hi, > > when processing our mass spectrometry data we are running against the > 2GB memory limit on our 32 bit machines. So we are planning to move to > 64bit. Downloading and installing the 64bit version of Python for > Windows is trivial, but how do we compile our own C extension? What about installing Cygwin and using the shipped GCC? Regards, Thomas Bach. From gordon at panix.com Wed Mar 21 15:30:16 2012 From: gordon at panix.com (John Gordon) Date: Wed, 21 Mar 2012 19:30:16 +0000 (UTC) Subject: Best way to disconnect from ldap? Message-ID: I'm writing an application that interacts with ldap, and I'm looking for advice on how to handle the connection. Specifically, how to close the ldap connection when the application is done. I wrote a class to wrap an LDAP connection, similar to this: import ldap import ConfigParser class MyLDAPWrapper(object): def __init__(self): config = ConfigParser.SafeConfigParser() config.read('sample.conf') uri = config.get('LDAP', 'uri') user = config.get('LDAP', 'user') password = config.get('LDAP', 'password') self.ldapClient = ldap.initialize(uri) self.ldapClient.simple_bind_s(user, password) My question is this: what is the best way to ensure the ldap connection gets closed when it should? I could write an explicit close() method, but that seems a bit messy; there would end up being lots of calls to close() scattered around in my code (primarily inside exception handlers.) Or I could write a __del__ method: def __del__(self): self.ldapClient.unbind_s() This seems like a much cleaner solution, as I don't ever have to worry about closing the connection; it gets done automatically. I haven't ever used __del__ before. Are there any 'gotchas' I need to worry about? Thanks! -- 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 jcd at sdf.lonestar.org Wed Mar 21 16:21:52 2012 From: jcd at sdf.lonestar.org (J. Cliff Dyer) Date: Wed, 21 Mar 2012 16:21:52 -0400 Subject: Best way to disconnect from ldap? In-Reply-To: References: Message-ID: <1332361312.7320.2.camel@jcdyer-laptop> Write a context manager. Then you just do with MyLDAPWrapper() as ldap ldap.this() ldap.that() and when you leave the scope of the with statement, your ldap __exit__ method will get called regardless of how you left. Cheers, Cliff On Wed, 2012-03-21 at 19:30 +0000, John Gordon wrote: > I'm writing an application that interacts with ldap, and I'm looking > for advice on how to handle the connection. Specifically, how to > close the ldap connection when the application is done. > > I wrote a class to wrap an LDAP connection, similar to this:LDAP > > import ldap > import ConfigParser > > class MyLDAPWrapper(object): > > def __init__(self): > > config = ConfigParser.SafeConfigParser() > config.read('sample.conf') > > uri = config.get('LDAP', 'uri') > user = config.get('LDAP', 'user') > password = config.get('LDAP', 'password') > > self.ldapClient = ldap.initialize(uri) > self.ldapClient.simple_bind_s(user, password) > > My question is this: what is the best way to ensure the ldap connection > gets closed when it should? I could write an explicit close() method, > but that seems a bit messy; there would end up being lots of calls to > close() scattered around in my code (primarily inside exception handlers.) > > Or I could write a __del__ method: > > def __del__(self): > self.ldapClient.unbind_s() > > This seems like a much cleaner solution, as I don't ever have to worry > about closing the connection; it gets done automatically. > > I haven't ever used __del__ before. Are there any 'gotchas' I need to > worry about? > > Thanks! > > -- > 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 clp2 at rebertia.com Wed Mar 21 16:34:29 2012 From: clp2 at rebertia.com (Chris Rebert) Date: Wed, 21 Mar 2012 13:34:29 -0700 Subject: Best way to disconnect from ldap? In-Reply-To: References: Message-ID: On Wed, Mar 21, 2012 at 12:30 PM, John Gordon wrote: > I'm writing an application that interacts with ldap, and I'm looking > for advice on how to handle the connection. ?Specifically, how to > close the ldap connection when the application is done. > > I wrote a class to wrap an LDAP connection, similar to this: > > ? ?import ldap > ? ?import ConfigParser > > ? ?class MyLDAPWrapper(object): > > ? ? ? ?def __init__(self): > > ? ? ? ? ? ?config = ConfigParser.SafeConfigParser() > ? ? ? ? ? ?config.read('sample.conf') > > ? ? ? ? ? ?uri = config.get('LDAP', 'uri') > ? ? ? ? ? ?user = config.get('LDAP', 'user') > ? ? ? ? ? ?password = config.get('LDAP', 'password') > > ? ? ? ? ? ?self.ldapClient = ldap.initialize(uri) > ? ? ? ? ? ?self.ldapClient.simple_bind_s(user, password) > > My question is this: what is the best way to ensure the ldap connection > gets closed when it should? ?I could write an explicit close() method, > but that seems a bit messy; there would end up being lots of calls to > close() scattered around in my code (primarily inside exception handlers.) > > Or I could write a __del__ method: > > ? ? ? ?def __del__(self): > ? ? ? ? ? ?self.ldapClient.unbind_s() > > This seems like a much cleaner solution, as I don't ever have to worry > about closing the connection; it gets done automatically. Yes, but not necessarily in a timely manner. Since its uses reference counting, CPython /just so happens/ to finalize non-cyclically-referenced objects promptly when they go out of scope, but Python-the-language makes no such guarantee, and indeed some of the other Python implementations explicitly disclaim that there may be a significant delay before finalization is performed. > I haven't ever used __del__ before. ?Are there any 'gotchas' I need to > worry about? In addition to the aforementioned problem regarding portability to other Python implementations, see also the Warning box under: http://docs.python.org/reference/datamodel.html#object.__del__ I concur with J.'s context manager suggestion. Cheers, Chris From ckaynor at zindagigames.com Wed Mar 21 16:54:13 2012 From: ckaynor at zindagigames.com (Chris Kaynor) Date: Wed, 21 Mar 2012 13:54:13 -0700 Subject: Best way to disconnect from ldap? In-Reply-To: References: Message-ID: On Wed, Mar 21, 2012 at 1:34 PM, Chris Rebert wrote: > > On Wed, Mar 21, 2012 at 12:30 PM, John Gordon wrote: > > I'm writing an application that interacts with ldap, and I'm looking > > for advice on how to handle the connection. ?Specifically, how to > > close the ldap connection when the application is done. > > > > I wrote a class to wrap an LDAP connection, similar to this: > > > > ? ?import ldap > > ? ?import ConfigParser > > > > ? ?class MyLDAPWrapper(object): > > > > ? ? ? ?def __init__(self): > > > > ? ? ? ? ? ?config = ConfigParser.SafeConfigParser() > > ? ? ? ? ? ?config.read('sample.conf') > > > > ? ? ? ? ? ?uri = config.get('LDAP', 'uri') > > ? ? ? ? ? ?user = config.get('LDAP', 'user') > > ? ? ? ? ? ?password = config.get('LDAP', 'password') > > > > ? ? ? ? ? ?self.ldapClient = ldap.initialize(uri) > > ? ? ? ? ? ?self.ldapClient.simple_bind_s(user, password) > > > > My question is this: what is the best way to ensure the ldap connection > > gets closed when it should? ?I could write an explicit close() method, > > but that seems a bit messy; there would end up being lots of calls to > > close() scattered around in my code (primarily inside exception handlers.) > > > > Or I could write a __del__ method: > > > > ? ? ? ?def __del__(self): > > ? ? ? ? ? ?self.ldapClient.unbind_s() > > > > This seems like a much cleaner solution, as I don't ever have to worry > > about closing the connection; it gets done automatically. > > Yes, but not necessarily in a timely manner. Since its uses reference > counting, CPython /just so happens/ to finalize > non-cyclically-referenced objects promptly when they go out of scope, > but Python-the-language makes no such guarantee, and indeed some of > the other Python implementations explicitly disclaim that there may be > a significant delay before finalization is performed. > > > I haven't ever used __del__ before. ?Are there any 'gotchas' I need to > > worry about? > > In addition to the aforementioned problem regarding portability to > other Python implementations, see also the Warning box under: > http://docs.python.org/reference/datamodel.html#object.__del__ > > I concur with J.'s context manager suggestion. Personally, I would combine both methods (and maybe throw in a close option as well). The standard interface would be to use the with context, however in cases where that is not possible, an explicit close is useful, and just in-case that is forgotten or missed, the __del__ is there as a final backup. The main case that context managers fail is when you need to break the creation and teardown into separate methods, such as when writing a more complex context manager. As Chris Rebert pointed out, there is no guarantee as to when the __del__ method is called. CPython will generally call it immediately, however if there are reference cycles it may never call it: class O(object): def __del__(self): print 'del' a = O() b = O() a.obj = b b.obj = a del a del b # After this, all references should be gone. Netiher a nor b are accessable anymore, right? # Yet del was never printed. Maybe a full garbage collection will help? import gc gc.collect() # Nope... Also, if the object exists and an exception is thrown, the object may be held onto for extended periods of time, or may never get cleaned up. A quick example of this issue: >>> class O(object): ... def __del__(self): ... print 'del' ... >>> def F(): ... o = O() ... raise RuntimeError() ... >>> F() # o is not garbage collected as sys.exc_info holds a reference to it still in the traceback object. RuntimeError Traceback (most recent call last): File "", line 1, in File "", line 3, in F RuntimeError >>> raise ValueError() # When another exception got thrown, it will get cleaned up.... del ValueError Traceback (most recent call last): File "", line 1, in ValueError In any case, it still makes a decent fall-back in case the user of your code fails to properly clean-up. It will cover many of the common cases, though you do need to be careful to never get into a reference cycle if you have __del__ methods, or you get memory leaks. > > > Cheers, > Chris > -- > http://mail.python.org/mailman/listinfo/python-list From python.list at tim.thechases.com Wed Mar 21 17:49:54 2012 From: python.list at tim.thechases.com (Tim Chase) Date: Wed, 21 Mar 2012 16:49:54 -0500 Subject: Best way to disconnect from ldap? In-Reply-To: References: Message-ID: <4F6A4D02.6020403@tim.thechases.com> On 03/21/12 15:54, Chris Kaynor wrote: > As Chris Rebert pointed out, there is no guarantee as to when the > __del__ method is called. CPython will generally call it immediately, > however if there are reference cycles it may never call it And more maddeningly, modules/objects used/called from within the __del__ may have already gone out of scope, producing head-scratching errors. I've been bitten by this enough times that I just stopped using __del__ completely. -tkc From steve+comp.lang.python at pearwood.info Wed Mar 21 19:34:28 2012 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 21 Mar 2012 23:34:28 GMT Subject: Python is readable References: <4f612b19$0$1379$4fafbaef@reader2.news.tin.it> <50e9ceec-40f1-4ead-b2b6-87328b30d084@ow8g2000pbc.googlegroups.com> <4f691f3d$0$29981$c3e8da3$5496439d@news.astraweb.com> <87d386lmai.fsf@benfinney.id.au> <8a77bf8d-b12f-442b-a1a3-479b5d66d366@tx8g2000pbc.googlegroups.com> <6af70db0-dc4a-48ee-9ee2-1a934846d5f2@r2g2000pbs.googlegroups.com> Message-ID: <4f6a6584$0$29981$c3e8da3$5496439d@news.astraweb.com> On Wed, 21 Mar 2012 11:22:01 -0500, Evan Driscoll wrote: > On 01/-10/-28163 01:59 PM, Steve Howell wrote: >> Code shouldn't necessarily follow the example of English prose, but it >> seems that English has had some influence: >> >> 1 push(stack, item) # Push on the stack the item >> 2 push(item, stack) # Push the item on the stack >> 3 stack.push(item) # On the stack, push the item >> 4 stack item push # On the stack, take the item and push it >> 5 item stack push # Take the item and on the stack, push the >> former. >> 6 item push stack # Take the item; push it on the stack. >> >> The first three ways are the most common ways of arranging the grammar >> in mainstream programming languages, and they are also the three most >> natural ways in English (no pronouns required). >> >> #1/2 are imperative. #3 is OO. > > In my opinion, people who make statements such as "#1/2 are imperative, > #3 is OO" are missing pretty much the entire point of what OO is. > > OO is much more about semantics and the way code is structured. The > difference between #1/2 (especially #1, of course) and #3 is > surface-level syntax only. +1000 I like to talk about "object oriented SYNTAX" (emphasis added) to distinguish the typical OO dotted syntax obj.attr (or obj->attr) from other syntax varieties. But this must be understood as mere convention. One could invent an OO language which used syntax "push(stack, item)" or even something exotic like "item!push~stack" and it would remain OO, only with unusual syntax. Contrariwise, a purely functional language might use declarative or OO- like syntax. Syntax is orthogonal to the data model, although some data models naturally suggest some syntaxes over others. (Syntaxes? Syntaxen? Syntacies?) The first OO language I ever used was Hypertalk, which used a message- passing model: send mouseUp to button OK of card Prefs and an optional function-call syntax like this: put the average of field Values into field Average which I guess makes Hypertalk a message-passing OO language with imperative syntax. > About the strongest statement you can make along those lines is that #3 > will allow you to do dynamic dispatch on the type of 'stack' while #1/2 > won't, but even that isn't true of course. Of course. At runtime, the interpreter is able to dispatch to the correct method of 'stack' regardless of where the tokens are in the source code. -- Steven From cjgohlke at gmail.com Wed Mar 21 20:06:18 2012 From: cjgohlke at gmail.com (cjgohlke at gmail.com) Date: Wed, 21 Mar 2012 17:06:18 -0700 (PDT) Subject: Compiling Python (modules) on 64bit Windows - which compiler suite? In-Reply-To: <808abad4-3ab3-4336-8a31-2f88eb28be01@v22g2000vby.googlegroups.com> References: <808abad4-3ab3-4336-8a31-2f88eb28be01@v22g2000vby.googlegroups.com> Message-ID: <13033772.7.1332374778471.JavaMail.geo-discussion-forums@ynjk1> On Wednesday, March 21, 2012 8:06:47 AM UTC-7, Ralph Heinkel wrote: > Hi, > > when processing our mass spectrometry data we are running against the > 2GB memory limit on our 32 bit machines. So we are planning to move to > 64bit. Downloading and installing the 64bit version of Python for > Windows is trivial, but how do we compile our own C extension? Visual C > ++ 2008 express comes for free, but only compiles for 32 bit. > > What has been used to compile the downloadable Python Win64 bit > version? Visual Studio professional? > The problem with the professional edition is that it is hard to obtain > and it is sort of out-of-date - nowadays everyone uses Visual Studio > 2010 (or even 2011 coming soon). So if Visual Studio 2008 professional > is required for compiling 64bit modules, we would have to spend $1200 > for a license which is actually rather out of date. > > Any hints or suggestions are very welcome. > > Thanks, > > Ralph See "Compiling 64-bit extension modules on Windows" at . It applies to non-Cython extensions as well. MinGW-w64 also works, but you'll have to generate and use libpythonXX.a and libmsvcr90.a link libraries. Christoph From showell30 at yahoo.com Wed Mar 21 20:54:14 2012 From: showell30 at yahoo.com (Steve Howell) Date: Wed, 21 Mar 2012 17:54:14 -0700 (PDT) Subject: Python is readable References: <4f612b19$0$1379$4fafbaef@reader2.news.tin.it> <4f691f3d$0$29981$c3e8da3$5496439d@news.astraweb.com> <87d386lmai.fsf@benfinney.id.au> <8a77bf8d-b12f-442b-a1a3-479b5d66d366@tx8g2000pbc.googlegroups.com> <6af70db0-dc4a-48ee-9ee2-1a934846d5f2@r2g2000pbs.googlegroups.com> <4f6a6584$0$29981$c3e8da3$5496439d@news.astraweb.com> Message-ID: On Mar 21, 4:34?pm, Steven D'Aprano wrote: > On Wed, 21 Mar 2012 11:22:01 -0500, Evan Driscoll wrote: > > On 01/-10/-28163 01:59 PM, Steve Howell wrote: > >> Code shouldn't necessarily follow the example of English prose, but it > >> seems that English has had some influence: > > >> ? 1 ?push(stack, item) # Push on the stack the item > >> ? 2 ?push(item, stack) # Push the item on the stack > >> ? 3 ?stack.push(item) ?# On the stack, push the item > >> ? 4 ?stack item push ? # On the stack, take the item and push it > >> ? 5 ?item stack push ? # Take the item and on the stack, push the > >> ? ? ?former. > >> ? 6 ?item push stack ? # Take the item; push it on the stack. > > >> The first three ways are the most common ways of arranging the grammar > >> in mainstream programming languages, and they are also the three most > >> natural ways in English (no pronouns required). > > >> #1/2 are imperative. ?#3 is OO. > > > In my opinion, people who make statements such as "#1/2 are imperative, > > #3 is OO" are missing pretty much the entire point of what OO is. > > > OO is much more about semantics and the way code is structured. The > > difference between #1/2 (especially #1, of course) and #3 is > > surface-level syntax only. > > +1000 > > I like to talk about "object oriented SYNTAX" (emphasis added) to > distinguish the typical OO dotted syntax obj.attr (or obj->attr) from > other syntax varieties. But this must be understood as mere convention. > One could invent an OO language which used syntax "push(stack, item)" or > even something exotic like "item!push~stack" and it would remain OO, only > with unusual syntax. > Sorry if I caused confusion here. When I labelled certain syntaxes as "imperative" and certain syntaxes as "object-oriented," I never meant to imply anything about the semantic layer. (I think Evan misread my post a bit, and then went a little overboard with his comment that people like me "are missing the entire point of OO.") Clearly, I get the fact that there can be multiple valid syntaxes to express the same underlying operation, as evidenced by my presenting six permutations of stack/push/item. The discussion that I thought would be interesting is this--given six seemingly arbitrary ways of expressing the same idea, how do you decide? My hypothesis is that we all have prior conditioning such that the arrangement of words actually *does* matter. And the conditioning comes from multiple realms--we speak natural languages, we have familiarity with arithmetic notation, and we have traditions from programming itself. The place where token arrangement resonates best with me is arithmetic. I can deal with all of the expressions on a semantic level: 5 + 3 5 3 + + 5 3 On a purely theoretical level, the choice of syntax doesn't really matter (it's just a convention), but the convention is so strong, it matters on a readability level. Even though I can grok prefix/ postfix, I feel uncomfortable in programming languages that don't have "infix" sugar. Imagine if Python didn't support infix sugar. No semantic change, right? But it would still matter for some... From showell30 at yahoo.com Wed Mar 21 21:35:16 2012 From: showell30 at yahoo.com (Steve Howell) Date: Wed, 21 Mar 2012 18:35:16 -0700 (PDT) Subject: Python is readable References: <4f612b19$0$1379$4fafbaef@reader2.news.tin.it> <4f691f3d$0$29981$c3e8da3$5496439d@news.astraweb.com> <87d386lmai.fsf@benfinney.id.au> <8a77bf8d-b12f-442b-a1a3-479b5d66d366@tx8g2000pbc.googlegroups.com> <6af70db0-dc4a-48ee-9ee2-1a934846d5f2@r2g2000pbs.googlegroups.com> Message-ID: <32b8c4ae-2509-43df-abf0-0fb308be398f@oq7g2000pbb.googlegroups.com> On Mar 21, 11:06?am, Nathan Rice wrote: > As for syntax, we have a lot of "real" domain specific languages, such > as English, math and logic. They are vetted, understood and useful > outside the context of programming. ?We should approach the discussion > of language syntax from the perspective of trying to define a unified > syntactical structure for real these DSLs. ? ?Ideally it would allow > representation of things in a familiar way where possible, while > providing an elegant mechanism for descriptions that cut across > domains and eliminating redundancy/ambiguity. ?This is clearly > possible, though a truly successful attempt would probably be a work > of art for the ages. If I'm reading you correctly, you're expressing frustration with the state of language syntax unification in 2012. You mention language in a broad sense (not just programming languages, but also English, math, logic, etc.), but even in the narrow context of programming languages, the current state of the world is pretty chaotic. My position is that mankind is stuck in a painful, but inevitable, part of the evolutionary process of building programming languages. If there are quantum leaps of expressiveness/elegance/familiarity around the corner, I haven't seen them. My take is that the landscape in 2032 won't be vastly different than 2012. Languages will be better incrementally, but Python 4 or Python 5, or whatever eclipses Python in two decades, won't look vastly different than the Python we have now. If you look back to 1992, things weren't vastly different than now. In 1992 you already had Perl, C/C++, Python, Haskell, LISP, etc. Some of the languages we have in 2012 were still a glimmer in the eye back then (notably Java and Ruby), and some were quite young (notably Python), but most of them can at least trace their roots to earlier days. The optimistic view is that there will be some kind of inflection point around 2020 or so. I could imagine a perfect storm of good things happening, like convergence on a single browser platform, nearly complete migration to Python 3, further maturity of JVM-based languages, etc., where the bar gets a little higher from what people expect from languages. Instead of fighting semicolons and braces, we start thinking bigger. It could also be some sort of hardware advance, like screen resolutions that are so amazing they let us completely rethink our views on terseness, punctuation, code organization, etc. From java at leeclemens.net Wed Mar 21 21:37:25 2012 From: java at leeclemens.net (Lee Clemens) Date: Wed, 21 Mar 2012 21:37:25 -0400 Subject: Daemonization / Popen / pipe issue In-Reply-To: <20120318041548.GA15675@cskk.homeip.net> References: <20120318123516.0c13a6345c333a040568b95a@johnohagan.com> <20120318041548.GA15675@cskk.homeip.net> Message-ID: <4F6A8255.1090607@leeclemens.net> On 03/18/2012 12:15 AM, Cameron Simpson wrote: > BTW, Lee, there is an external module for daemonising things in the UNIX > sense: > http://pypi.python.org/pypi/python-daemon > I recommend you use it. > > Cheers, I haven't updated the gist yet, but I did try it with the code below - but I get the same results (inconsistent termination, logs still match up as though everything worked fine. If I'm not in DAEMONIZE mode and hold down enter, I can get stdout from the Popen process too - which I have seen with and without the DaemonContext package. There seems to be something odd going on with the way pipes are handled... Added after if __name__ == "__main__": if DAEMONIZE: import daemon myDaemon = daemon.DaemonContext() myDaemon.open() ... From stefan_ml at behnel.de Thu Mar 22 03:06:17 2012 From: stefan_ml at behnel.de (Stefan Behnel) Date: Thu, 22 Mar 2012 08:06:17 +0100 Subject: Compiling Python (modules) on 64bit Windows - which compiler suite? In-Reply-To: <874nthu68q.fsf@jubold.box> References: <808abad4-3ab3-4336-8a31-2f88eb28be01@v22g2000vby.googlegroups.com> <874nthu68q.fsf@jubold.box> Message-ID: Thomas Bach, 21.03.2012 20:03: > Ralph Heinkel writes: >> when processing our mass spectrometry data we are running against the >> 2GB memory limit on our 32 bit machines. So we are planning to move to >> 64bit. Downloading and installing the 64bit version of Python for >> Windows is trivial, but how do we compile our own C extension? > > What about installing Cygwin and using the shipped GCC? I'm pretty sure it doesn't cross compile to native Windows. It certainly won't build against a native Windows Python installation, and given the overhead that cygwin induces into a lot of common OS operations (such as fork(), I/O operations or file system access), a native Windows Python installation has serious advantages in most cases. If the choice is GCC, then MinGW is the right tool. Stefan From steve+comp.lang.python at pearwood.info Thu Mar 22 04:56:17 2012 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 22 Mar 2012 08:56:17 GMT Subject: Python is readable References: <4f612b19$0$1379$4fafbaef@reader2.news.tin.it> <4f691f3d$0$29981$c3e8da3$5496439d@news.astraweb.com> <87d386lmai.fsf@benfinney.id.au> <8a77bf8d-b12f-442b-a1a3-479b5d66d366@tx8g2000pbc.googlegroups.com> <6af70db0-dc4a-48ee-9ee2-1a934846d5f2@r2g2000pbs.googlegroups.com> <32b8c4ae-2509-43df-abf0-0fb308be398f@oq7g2000pbb.googlegroups.com> Message-ID: <4f6ae931$0$29883$c3e8da3$5496439d@news.astraweb.com> On Wed, 21 Mar 2012 18:35:16 -0700, Steve Howell wrote: > On Mar 21, 11:06?am, Nathan Rice > wrote: >> As for syntax, we have a lot of "real" domain specific languages, such >> as English, math and logic. They are vetted, understood and useful >> outside the context of programming. ?We should approach the discussion >> of language syntax from the perspective of trying to define a unified >> syntactical structure for real these DSLs. ? ?Ideally it would allow >> representation of things in a familiar way where possible, while >> providing an elegant mechanism for descriptions that cut across domains >> and eliminating redundancy/ambiguity. ?This is clearly possible, though >> a truly successful attempt would probably be a work of art for the >> ages. > > If I'm reading you correctly, you're expressing frustration with the > state of language syntax unification in 2012. You mention language in a > broad sense (not just programming languages, but also English, math, > logic, etc.), but even in the narrow context of programming languages, > the current state of the world is pretty chaotic. And this is a good thing. Programming languages are chaotic because the universe of programming problems is chaotic, and the strategies available to solve those problems are many and varied. Different programming languages are good for different things because they have been designed to work in different problem/solution spaces. Although I dislike C with a passion, I do recognise that it is good for when the programmer needs fine control over the smallest details. It is, after all, a high-level assembler. Likewise for Forth, which lets you modify the compiler and language as you go. Some languages are optimized for the compiler, some for the writer, and some for the reader. So are optimized for numeric work, others for database access. Some are Jack-Of-All-Trades. Each language encourages its own idioms and ways of thinking about programming. When it comes to programming, I say, let a thousand voices shout out. Instead of imagining a single language so wonderful that every other language is overshadowed and forgotten, imagine that the single language is the next Java, or C, or even for that matter Python, but whatever it is, it's not ideal for the problems you care about, or the way you think about them. Not so attractive now, is it? > The optimistic view is that there will be some kind of inflection point > around 2020 or so. I could imagine a perfect storm of good things > happening, like convergence on a single browser platform, You call that a perfect storm of good things. I call that sort of intellectual and software monoculture a nightmare. I want a dozen browsers, not one of which is so common that web designers can design for it and ignore the rest, not one browser so common that nobody dares try anything new. > nearly > complete migration to Python 3, further maturity of JVM-based languages, > etc., where the bar gets a little higher from what people expect from > languages. Instead of fighting semicolons and braces, we start thinking > bigger. It could also be some sort of hardware advance, like screen > resolutions that are so amazing they let us completely rethink our views > on terseness, punctuation, code organization, etc. And what of those with poor eyesight, or the blind? Are they to be excluded from your "bigger" brave new world? -- Steven From slehar at gmail.com Thu Mar 22 06:51:05 2012 From: slehar at gmail.com (Steven Lehar) Date: Thu, 22 Mar 2012 06:51:05 -0400 Subject: Python classes: Simplify? Message-ID: It seems to me that the Python class system is needlessly confusing. Am I missing something? For example in the class Complex given in the documentation *class Complex:* * def __init__(self, realpart, imagpart):* * self.r = realpart* * self.i = imagpart* * * *x = Complex(3.0, -4.5)* I initially found it profoundly confusing that __init__( ) calls for 3 arguments, but you call Complex( ) with 2. Furthermore, why not call the initialization function after the class name as is done in other languages? Isn't that the simplest conceptually? Demonstrating with the above example: *class Complex:* * def Complex(realpart, imagpart):* * Complex.r = realpart* * Complex.i = imagpart* * * *x = Complex(3.0, -4.5)* * * Is there a good reason why classes cannot be defined that way? (Besides the problem of backward-compatibility) -------------- next part -------------- An HTML attachment was scrubbed... URL: From rosuav at gmail.com Thu Mar 22 07:10:53 2012 From: rosuav at gmail.com (Chris Angelico) Date: Thu, 22 Mar 2012 22:10:53 +1100 Subject: Python classes: Simplify? In-Reply-To: References: Message-ID: On Thu, Mar 22, 2012 at 9:51 PM, Steven Lehar wrote: > It seems to me that the Python class system is needlessly confusing. Am I > missing something? > > For example in the class Complex given in the documentation > > class Complex: > ? ? def __init__(self, realpart, imagpart): > ? ? ? ? self.r = realpart > ? ? ? ? self.i = imagpart > > x = Complex(3.0, -4.5) > > I initially found it profoundly confusing that __init__( ) calls for 3 > arguments, but you call Complex( ) with 2. Furthermore, why not call the > initialization function after the class name as is done in other languages? > Isn't that the simplest conceptually? Demonstrating with the above example: Why doesn't Python do things the way Java does? Because Python isn't Java. Different language, different choices. :) Methods are called with an explicit first argument (the object being acted upon). Constructors need that argument too, even though it's not given in the invocation. With your example alternate syntax: > class Complex: > ? ? def Complex(realpart, imagpart): > ? ? ? ? Complex.r = realpart > ? ? ? ? Complex.i = imagpart there's no way to distinguish between assigning to the newly-created object's attributes and assigning to the class's own attributes. Especially since the latter is a truly viable option in Python, this can't be done; consequently, there needs to be either an explicit or an implicit "self" argument (C++ does this with an implicit 'this' pointer); the Python choice is to make it explicit. There's really no reason to have the name of the constructor change when the class is renamed. The way Python does things, you can rename a class by changing just one thing, the "class Foo:" line. In C++, you have to also rename all your constructors. And bear in mind, a class is an object, same as any other: >>> class Foo: def __init__(self,x): self.x=x def speak(self): print("x = "+self.x) >>> a=Foo("Hello") >>> a.speak() x = Hello >>> Bar=Foo >>> b=Bar("World") >>> b.speak() x = World If the constructor is named the same as the class, how would this sort of thing function? ChrisA From clp2 at rebertia.com Thu Mar 22 07:17:35 2012 From: clp2 at rebertia.com (Chris Rebert) Date: Thu, 22 Mar 2012 04:17:35 -0700 Subject: Python classes: Simplify? In-Reply-To: References: Message-ID: On Thu, Mar 22, 2012 at 3:51 AM, Steven Lehar wrote: > It seems to me that the Python class system is needlessly confusing. Am I > missing something? Explicit `self` is slightly annoying, but you'll get over it quickly (trust me). > For example in the class Complex given in the documentation > > class Complex: > ? ? def __init__(self, realpart, imagpart): > ? ? ? ? self.r = realpart > ? ? ? ? self.i = imagpart > > x = Complex(3.0, -4.5) > > I initially found it profoundly confusing that __init__( ) calls for 3 > arguments, but you call Complex( ) with 2. That's not at all unique to __init__(). > Furthermore, why not call the > initialization function after the class name as is done in other languages? Yech. That would add another step to renaming a class and make referring to the superclass initializer method rather difficult. It would also break the "all special methods have underscored names" rule. Perhaps you'll find the following instructive: Python 2.7.1 (r271:86832, Jul 31 2011, 19:30:53) >>> class Foo(object): ... def __init__(self): ... pass ... >>> Foo() <__main__.Foo object at 0x100fd5750> >>> Bar = Foo >>> Bar.__name__ = "Bar" >>> del Foo >>> # look Ma, I've renamed the class! >>> Bar() <__main__.Bar object at 0x100fd57d0> How would your scheme account for this possibility? > Isn't that the simplest conceptually? Demonstrating with the above example: > > class Complex: > ? ? def Complex(realpart, imagpart): > ? ? ? ? Complex.r = realpart > ? ? ? ? Complex.i = imagpart Your change of "self" to "Complex" in the method body here makes no sense to me. > x = Complex(3.0, -4.5) > > Is there a good reason why classes cannot be defined that way? (Besides the > problem of backward-compatibility) Mostly historical, IMO. But here are some justifications for explicit `self`: http://docs.python.org/faq/design.html#why-must-self-be-used-explicitly-in-method-definitions-and-calls http://neopythonic.blogspot.com/2008/10/why-explicit-self-has-to-stay.html Cheers, Chris R. -- http://blog.rebertia.com From joncle at googlemail.com Thu Mar 22 07:18:02 2012 From: joncle at googlemail.com (Jon Clements) Date: Thu, 22 Mar 2012 04:18:02 -0700 (PDT) Subject: Python is readable (OT) In-Reply-To: <4f6ae931$0$29883$c3e8da3$5496439d@news.astraweb.com> References: <4f612b19$0$1379$4fafbaef@reader2.news.tin.it> <4f691f3d$0$29981$c3e8da3$5496439d@news.astraweb.com> <87d386lmai.fsf@benfinney.id.au> <8a77bf8d-b12f-442b-a1a3-479b5d66d366@tx8g2000pbc.googlegroups.com> <6af70db0-dc4a-48ee-9ee2-1a934846d5f2@r2g2000pbs.googlegroups.com> <32b8c4ae-2509-43df-abf0-0fb308be398f@oq7g2000pbb.googlegroups.com> <4f6ae931$0$29883$c3e8da3$5496439d@news.astraweb.com> Message-ID: <33536194.2563.1332415082529.JavaMail.geo-discussion-forums@ynlt15> On Thursday, 22 March 2012 08:56:17 UTC, Steven D'Aprano wrote: > On Wed, 21 Mar 2012 18:35:16 -0700, Steve Howell wrote: > > > On Mar 21, 11:06?am, Nathan Rice > > wrote: [snip]. > > Different programming languages are good for different things because > they have been designed to work in different problem/solution spaces. > Although I dislike C with a passion, I do recognise that it is good for > when the programmer needs fine control over the smallest details. It is, > after all, a high-level assembler. Likewise for Forth, which lets you > modify the compiler and language as you go. > > Some languages are optimized for the compiler, some for the writer, and > some for the reader. So are optimized for numeric work, others for > database access. Some are Jack-Of-All-Trades. Each language encourages > its own idioms and ways of thinking about programming. > > When it comes to programming, I say, let a thousand voices shout out. > Instead of imagining a single language so wonderful that every other > language is overshadowed and forgotten, imagine that the single language > is the next Java, or C, or even for that matter Python, but whatever it > is, it's not ideal for the problems you care about, or the way you think > about them. Not so attractive now, is it? > > > > The optimistic view is that there will be some kind of inflection point > > around 2020 or so. I could imagine a perfect storm of good things > > happening, like convergence on a single browser platform, > > You call that a perfect storm of good things. I call that sort of > intellectual and software monoculture a nightmare. > > I want a dozen browsers, not one of which is so common that web designers > can design for it and ignore the rest, not one browser so common that > nobody dares try anything new. > > > > nearly > > complete migration to Python 3, further maturity of JVM-based languages, > > etc., where the bar gets a little higher from what people expect from > > languages. Instead of fighting semicolons and braces, we start thinking > > bigger. It could also be some sort of hardware advance, like screen > > resolutions that are so amazing they let us completely rethink our views > > on terseness, punctuation, code organization, etc. > > And what of those with poor eyesight, or the blind? Are they to be > excluded from your "bigger" brave new world? > > > > -- > Steven On Thursday, 22 March 2012 08:56:17 UTC, Steven D'Aprano wrote: > On Wed, 21 Mar 2012 18:35:16 -0700, Steve Howell wrote: > > > On Mar 21, 11:06?am, Nathan Rice > > wrote: > >> As for syntax, we have a lot of "real" domain specific languages, such > >> as English, math and logic. They are vetted, understood and useful > >> outside the context of programming. ?We should approach the discussion > >> of language syntax from the perspective of trying to define a unified > >> syntactical structure for real these DSLs. ? ?Ideally it would allow > >> representation of things in a familiar way where possible, while > >> providing an elegant mechanism for descriptions that cut across domains > >> and eliminating redundancy/ambiguity. ?This is clearly possible, though > >> a truly successful attempt would probably be a work of art for the > >> ages. > > > > If I'm reading you correctly, you're expressing frustration with the > > state of language syntax unification in 2012. You mention language in a > > broad sense (not just programming languages, but also English, math, > > logic, etc.), but even in the narrow context of programming languages, > > the current state of the world is pretty chaotic. > > And this is a good thing. Programming languages are chaotic because the > universe of programming problems is chaotic, and the strategies available > to solve those problems are many and varied. > > Different programming languages are good for different things because > they have been designed to work in different problem/solution spaces. > Although I dislike C with a passion, I do recognise that it is good for > when the programmer needs fine control over the smallest details. It is, > after all, a high-level assembler. Likewise for Forth, which lets you > modify the compiler and language as you go. > > Some languages are optimized for the compiler, some for the writer, and > some for the reader. So are optimized for numeric work, others for > database access. Some are Jack-Of-All-Trades. Each language encourages > its own idioms and ways of thinking about programming. > > When it comes to programming, I say, let a thousand voices shout out. > Instead of imagining a single language so wonderful that every other > language is overshadowed and forgotten, imagine that the single language > is the next Java, or C, or even for that matter Python, but whatever it > is, it's not ideal for the problems you care about, or the way you think > about them. Not so attractive now, is it? > > > > The optimistic view is that there will be some kind of inflection point > > around 2020 or so. I could imagine a perfect storm of good things > > happening, like convergence on a single browser platform, > > You call that a perfect storm of good things. I call that sort of > intellectual and software monoculture a nightmare. > > I want a dozen browsers, not one of which is so common that web designers > can design for it and ignore the rest, not one browser so common that > nobody dares try anything new. > > > > nearly > > complete migration to Python 3, further maturity of JVM-based languages, > > etc., where the bar gets a little higher from what people expect from > > languages. Instead of fighting semicolons and braces, we start thinking > > bigger. It could also be some sort of hardware advance, like screen > > resolutions that are so amazing they let us completely rethink our views > > on terseness, punctuation, code organization, etc. > > And what of those with poor eyesight, or the blind? Are they to be > excluded from your "bigger" brave new world? > > > > -- > Steven Completely not related to this discussion, but, I just have to say to Steven, I could not have expressed that better. +1 QOTW (albeit a long one) Jon. From mrsangeet at gmail.com Thu Mar 22 07:33:46 2012 From: mrsangeet at gmail.com (Sangeet) Date: Thu, 22 Mar 2012 04:33:46 -0700 (PDT) Subject: Accessing the files by last modified time Message-ID: <26215939.1574.1332416026298.JavaMail.geo-discussion-forums@ynlt17> Hi I am new to the python programming language. I've been trying to write a script that would access the last modified file in one of my directories. I'm using Win XP. I saw a similar topic, on the forum before, however the reply using (os.popen) didn't work out for me. I'm not sure whether it was due to syntax errors either. Thanks, Sangeet From clp2 at rebertia.com Thu Mar 22 07:49:23 2012 From: clp2 at rebertia.com (Chris Rebert) Date: Thu, 22 Mar 2012 04:49:23 -0700 Subject: Accessing the files by last modified time In-Reply-To: <26215939.1574.1332416026298.JavaMail.geo-discussion-forums@ynlt17> References: <26215939.1574.1332416026298.JavaMail.geo-discussion-forums@ynlt17> Message-ID: On Thu, Mar 22, 2012 at 4:33 AM, Sangeet wrote: > Hi > > I am new to the python programming language. > > I've been trying to write a script that would access the last modified file in one of my directories. I'm using Win XP. > > I saw a similar topic, on the forum before, however the reply using (os.popen) didn't work out for me. I'm not sure whether it was due to syntax errors either. Recursively or non-recursively? Live monitoring or just one-time? What was the forum post in question? In the simple case, you just need to stitch together these functions: http://docs.python.org/library/os.html#os.stat (note the .st_mtime attribute of the result) http://docs.python.org/library/os.path.html#os.path.join with one of these functions: http://docs.python.org/library/os.html#os.listdir http://docs.python.org/library/os.html#os.walk Cheers, Chris From tjandacw at cox.net Thu Mar 22 08:04:43 2012 From: tjandacw at cox.net (Tim Williams) Date: Thu, 22 Mar 2012 05:04:43 -0700 (PDT) Subject: Accessing the files by last modified time References: <26215939.1574.1332416026298.JavaMail.geo-discussion-forums@ynlt17> Message-ID: <8cbfb1b2-94ed-4830-90fa-976a831ebb97@l14g2000vbe.googlegroups.com> On Mar 22, 7:33?am, Sangeet wrote: > Hi > > I am new to the python programming language. > > I've been trying to write a script that would access the last modified file in one of my directories. I'm using Win XP. > > I saw a similar topic, on the forum before, however the reply using (os.popen) didn't work out for me. I'm not sure whether it was due to syntax errors either. > > Thanks, > Sangeet Check out os.stat() From __peter__ at web.de Thu Mar 22 08:38:00 2012 From: __peter__ at web.de (Peter Otten) Date: Thu, 22 Mar 2012 13:38 +0100 Subject: Accessing the files by last modified time References: <26215939.1574.1332416026298.JavaMail.geo-discussion-forums@ynlt17> Message-ID: Sangeet wrote: > I've been trying to write a script that would access the last modified > file in one of my directories. I'm using Win XP. import os import glob path = r"c:\one\of\my directories\*" youngest_file = max(glob.glob(path), key=os.path.getmtime) From nathan.alexander.rice at gmail.com Thu Mar 22 08:47:15 2012 From: nathan.alexander.rice at gmail.com (Nathan Rice) Date: Thu, 22 Mar 2012 08:47:15 -0400 Subject: Python is readable In-Reply-To: <4f6ae931$0$29883$c3e8da3$5496439d@news.astraweb.com> References: <4f612b19$0$1379$4fafbaef@reader2.news.tin.it> <4f691f3d$0$29981$c3e8da3$5496439d@news.astraweb.com> <87d386lmai.fsf@benfinney.id.au> <8a77bf8d-b12f-442b-a1a3-479b5d66d366@tx8g2000pbc.googlegroups.com> <6af70db0-dc4a-48ee-9ee2-1a934846d5f2@r2g2000pbs.googlegroups.com> <32b8c4ae-2509-43df-abf0-0fb308be398f@oq7g2000pbb.googlegroups.com> <4f6ae931$0$29883$c3e8da3$5496439d@news.astraweb.com> Message-ID: >> If I'm reading you correctly, you're expressing frustration with the >> state of language syntax unification in 2012. You mention language in a >> broad sense (not just programming languages, but also English, math, >> logic, etc.), but even in the narrow context of programming languages, >> the current state of the world is pretty chaotic. > > And this is a good thing. Programming languages are chaotic because the > universe of programming problems is chaotic, and the strategies available > to solve those problems are many and varied. > > Different programming languages are good for different things because > they have been designed to work in different problem/solution spaces. > Although I dislike C with a passion, I do recognise that it is good for > when the programmer needs fine control over the smallest details. It is, > after all, a high-level assembler. Likewise for Forth, which lets you > modify the compiler and language as you go. There is a concept in statistical/mathematical modeling called minimum message length (a close analog is minimum description length), which asserts that the optimum model for some set of information is the one that minimizes the sum of the length of the model and the length of the set described by that model. Clearly no model is going to be optimal for every set of information. What I was alluding to in the post that Steve Howell replied to was that we need to have a programming language that is a model of models, then include a second order model as part of the program. Having one core language with many DSLs that can interoperate is infinitely better than having many languages that cannot. A language designed in such a way would also prevent issues like the Python 2 -> 3 fiasco, because two versions of a DSL can be separate, and code can reference them independently while being able to interoperate. > Some languages are optimized for the compiler, some for the writer, and > some for the reader. So are optimized for numeric work, others for > database access. Some are Jack-Of-All-Trades. Each language encourages > its own idioms and ways of thinking about programming. The difference between compiler optimized and writer optimized languages is how many assertions they require about the thing being modeled to be a "valid" program, given its deductive rules. Ideally, the number of assertions should be flexible, and the interpreter/compiler should try and figure out the best way to implement it given the information it has. > When it comes to programming, I say, let a thousand voices shout out. > Instead of imagining a single language so wonderful that every other > language is overshadowed and forgotten, imagine that the single language > is the next Java, or C, or even for that matter Python, but whatever it > is, it's not ideal for the problems you care about, or the way you think > about them. Not so attractive now, is it? I agree about letting a thousand voices shout out, in the context of an embedding language that guarantees code interoperability. Additionally, the size of optimal DSLs for different areas is actually quite small, yet having separate languages for each DSL requires the user to re-learn common patterns such as collection manipulation, IO, etc. Pretty horrible all around. >> The optimistic view is that there will be some kind of inflection point >> around 2020 or so. I could imagine a perfect storm of good things >> happening, like convergence on a single browser platform, > > You call that a perfect storm of good things. I call that sort of > intellectual and software monoculture a nightmare. The cores of English and math are pretty much singularly represented. At more nuanced or abstract levels, there is divergence in order to simplify the process of describing complicated things. How would you like it if linear algebra or algebraic geometry re-invented addition, multiplication, etc with completely different syntax and semantics (I'm ignoring non-commutativity of vector space multiplication) > I want a dozen browsers, not one of which is so common that web designers > can design for it and ignore the rest, not one browser so common that > nobody dares try anything new. How about one browser that is infinitely configurable? That way if someone tries something new, you can try it as well without precluding anything else you already do. The CLI/JVM provide some flexibility, but they are not the correct path. They model the executable machine representations of language, rather than modeling the meta structure of language. This means that you still lack flexibility and dynamism. At least things are moving in the right direction. From neilc at norwich.edu Thu Mar 22 09:06:36 2012 From: neilc at norwich.edu (Neil Cerutti) Date: 22 Mar 2012 13:06:36 GMT Subject: Accessing the files by last modified time References: <26215939.1574.1332416026298.JavaMail.geo-discussion-forums@ynlt17> <8cbfb1b2-94ed-4830-90fa-976a831ebb97@l14g2000vbe.googlegroups.com> Message-ID: <9t0mesFnj3U1@mid.individual.net> On 2012-03-22, Tim Williams wrote: > On Mar 22, 7:33?am, Sangeet wrote: >> Hi >> >> I am new to the python programming language. >> >> I've been trying to write a script that would access the last >> modified file in one of my directories. I'm using Win XP. >> >> I saw a similar topic, on the forum before, however the reply >> using (os.popen) didn't work out for me. I'm not sure whether >> it was due to syntax errors either. >> >> Thanks, >> Sangeet > > Check out os.stat() I've been using os.path.getmtime, and converting that to a datetime object using datetime.datetime.fromtimestamp. Surprisingly, perhaps, this has been working. According to the docs, to avoid making any assumptiong, I might need to do: tm = os.path.getmtime(apath) lt = time.localtime(tm) datetime.datetime(lt.tm_year, lt.tm_mon, lt.tm_mday) Here's where I'm confused about the functioning of my original plan. The docs say: os.path.getmtime [...] The return value is a number giving the number of seconds since the epoch (see the time module). [...] classmethod datetime.fromtimestamp Return the local date and time corresponding to the POSIX timestamp, such as returned by time.time(). [...] time.time Return the time as a floating point number expressed as seconds since the epoch, in UTC. [...] I'm not completely sure the return type of getmtime and the argument type of fromtimestamp are really the same or not. I guess I came to that conclusion some time in the past, and it does seem to work. It may be a simple case of just different aspects the exact same type being being highlighted in each definition. -- Neil Cerutti From tycho at tycho.ws Thu Mar 22 09:14:47 2012 From: tycho at tycho.ws (Tycho Andersen) Date: Thu, 22 Mar 2012 08:14:47 -0500 Subject: Best way to disconnect from ldap? In-Reply-To: <4F6A4D02.6020403@tim.thechases.com> References: <4F6A4D02.6020403@tim.thechases.com> Message-ID: <20120322131447.GG19657@ccapuser-ubuntu.WICOURTS.GOV> On Wed, Mar 21, 2012 at 04:49:54PM -0500, Tim Chase wrote: > On 03/21/12 15:54, Chris Kaynor wrote: > >As Chris Rebert pointed out, there is no guarantee as to when the > >__del__ method is called. CPython will generally call it immediately, > >however if there are reference cycles it may never call it > > And more maddeningly, modules/objects used/called from within the > __del__ may have already gone out of scope, producing > head-scratching errors. I've been bitten by this enough times that > I just stopped using __del__ completely. I've had similar experiences. In fact, in light of all this - why does __del__ exist at all? Novice python users may (reasonably) assume it behaves similarly to a C++ destructor (even though the docs warn otherwise). Given that you can't trust __del__, is there a legitimate use case for it? \t From andrea.crotti.0 at gmail.com Thu Mar 22 09:15:03 2012 From: andrea.crotti.0 at gmail.com (Andrea Crotti) Date: Thu, 22 Mar 2012 13:15:03 +0000 Subject: Python classes: Simplify? In-Reply-To: References: Message-ID: <4F6B25D7.9020002@gmail.com> On 03/22/2012 10:51 AM, Steven Lehar wrote: > It seems to me that the Python class system is needlessly confusing. > Am I missing something? > > For example in the class Complex given in the documentation > > *class Complex:* > * def __init__(self, realpart, imagpart):* > * self.r = realpart* > * self.i = imagpart* > * > * > *x = Complex(3.0, -4.5)* > > I initially found it profoundly confusing that __init__( ) calls for 3 > arguments, but you call Complex( ) with 2. Furthermore, why not call > the initialization function after the class name as is done in other > languages? Isn't that the simplest conceptually? Demonstrating with > the above example: > > *class Complex:* > * def Complex(realpart, imagpart):* > * Complex.r = realpart* > * Complex.i = imagpart* > * > * > *x = Complex(3.0, -4.5)* > * > * > Is there a good reason why classes cannot be defined that way? > (Besides the problem of backward-compatibility) > Some time ago I saw some nasty hack that allowed you to drop the self in the method declaration, using some crazy metaclass trick, but that's really not a good idea ;) I agree that is counter-intuitive but just set your editor to do that for you and you will be fine.. in my emacs - s TAB -> self - . TAB -> self. - m TAB -> def ${1:method}(self$2): $0 so I never actually write the self.. -------------- next part -------------- An HTML attachment was scrubbed... URL: From rosuav at gmail.com Thu Mar 22 09:17:49 2012 From: rosuav at gmail.com (Chris Angelico) Date: Fri, 23 Mar 2012 00:17:49 +1100 Subject: Python is readable In-Reply-To: References: <4f612b19$0$1379$4fafbaef@reader2.news.tin.it> <4f691f3d$0$29981$c3e8da3$5496439d@news.astraweb.com> <87d386lmai.fsf@benfinney.id.au> <8a77bf8d-b12f-442b-a1a3-479b5d66d366@tx8g2000pbc.googlegroups.com> <6af70db0-dc4a-48ee-9ee2-1a934846d5f2@r2g2000pbs.googlegroups.com> <32b8c4ae-2509-43df-abf0-0fb308be398f@oq7g2000pbb.googlegroups.com> <4f6ae931$0$29883$c3e8da3$5496439d@news.astraweb.com> Message-ID: On Thu, Mar 22, 2012 at 11:47 PM, Nathan Rice wrote: > Having one core language with > many DSLs that can interoperate is infinitely better than having many > languages that cannot. ?A language designed in such a way would also > prevent issues like the Python 2 -> 3 fiasco, because two versions of > a DSL can be separate, and code can reference them independently while > being able to interoperate. This is either utterly impossible, or already available, depending on your point of view. To have an infinitely-configurable program, you must make its configuration equivalent to writing code. There is already an infinitely-configurable program in Unix: "gcc config.c; ./a.out" takes a simple-format text file called "config.c" and processes it. You want infinite DSLs? Behold! $ ./module1 | ./module2 | ./module3 | ./module4 Each one has a shebang that tells you what they are (Python 2, Python 3, something else entirely). There's a very strict interoperability protocol between the modules - they pass information around through stdout and stdin. You can write any module in any language, and you can rewrite module1 for Python 3 without affecting any other or the invocation sequence. Problems always come when you want to share data between dissimilar modules. There's no single perfect data-transfer protocol that works across all languages. What does it mean to "call a function"? If you truly want this level of flexibility, the best thing to do is to separate sections cleanly. In fact, the pipe system I show above could be used that way, although it's stupidly ugly. Everything going on stdout/stdin has a two-word dispatch envelope with a from and a to, and each module reads a line, and if it's not addressed to it, passes it on to stdout. Responses get sent out with their from and to reversed. All you need is for the last module's stdout to be linked back into the first module's stdin (not sure if you can do that or not - it has the feeling of plugging a power strip into itself), and it'll work perfectly. Add a bit of boilerplate so that the application developers don't see what's happening underneath, and you could pretend that dissimilar languages are able to call into each other. Doesn't mean it's efficient though! TLDR version: Infinite flexibility means you're doing nothing. ChrisA From clp2 at rebertia.com Thu Mar 22 09:27:45 2012 From: clp2 at rebertia.com (Chris Rebert) Date: Thu, 22 Mar 2012 06:27:45 -0700 Subject: Best way to disconnect from ldap? In-Reply-To: <20120322131447.GG19657@ccapuser-ubuntu.WICOURTS.GOV> References: <4F6A4D02.6020403@tim.thechases.com> <20120322131447.GG19657@ccapuser-ubuntu.WICOURTS.GOV> Message-ID: On Thu, Mar 22, 2012 at 6:14 AM, Tycho Andersen wrote: > On Wed, Mar 21, 2012 at 04:49:54PM -0500, Tim Chase wrote: >> On 03/21/12 15:54, Chris Kaynor wrote: >> >As Chris Rebert pointed out, there is no guarantee as to when the >> >__del__ method is called. CPython will generally call it immediately, >> >however if there are reference cycles it may never call it >> >> And more maddeningly, modules/objects used/called from within the >> __del__ may have already gone out of scope, producing >> head-scratching errors. ?I've been bitten by this enough times that >> I just stopped using __del__ completely. > > I've had similar experiences. In fact, in light of all this - why does > __del__ exist at all? Novice python users may (reasonably) assume it > behaves similarly to a C++ destructor (even though the docs warn > otherwise). > > Given that you can't trust __del__, is there a legitimate use case for > it? Writing resource classes (like `file`) in C? Their __del__()s typically involve little/less Python-level stuff and thus less paranoia need be exercised. There is somewhat of a perverse incentive in having such last-ditch clean-up mechanisms though. "This code seems to work fine without `with`, so why bother changing it?" Cheers, Chris From tycho at tycho.ws Thu Mar 22 10:00:50 2012 From: tycho at tycho.ws (Tycho Andersen) Date: Thu, 22 Mar 2012 09:00:50 -0500 Subject: Best way to disconnect from ldap? In-Reply-To: References: <4F6A4D02.6020403@tim.thechases.com> <20120322131447.GG19657@ccapuser-ubuntu.WICOURTS.GOV> Message-ID: <20120322140050.GI19657@ccapuser-ubuntu.WICOURTS.GOV> On Thu, Mar 22, 2012 at 06:27:45AM -0700, Chris Rebert wrote: > On Thu, Mar 22, 2012 at 6:14 AM, Tycho Andersen wrote: > > On Wed, Mar 21, 2012 at 04:49:54PM -0500, Tim Chase wrote: > >> On 03/21/12 15:54, Chris Kaynor wrote: > >> >As Chris Rebert pointed out, there is no guarantee as to when the > >> >__del__ method is called. CPython will generally call it immediately, > >> >however if there are reference cycles it may never call it > >> > >> And more maddeningly, modules/objects used/called from within the > >> __del__ may have already gone out of scope, producing > >> head-scratching errors. ?I've been bitten by this enough times that > >> I just stopped using __del__ completely. > > > > I've had similar experiences. In fact, in light of all this - why does > > __del__ exist at all? Novice python users may (reasonably) assume it > > behaves similarly to a C++ destructor (even though the docs warn > > otherwise). > > > > Given that you can't trust __del__, is there a legitimate use case for > > it? > > Writing resource classes (like `file`) in C? Their __del__()s > typically involve little/less Python-level stuff and thus less > paranoia need be exercised. Sure, but you still have no guarantee that __del__ will ever be called, so it's a bad idea to rely on it to clean up anything. > There is somewhat of a perverse incentive in having such last-ditch > clean-up mechanisms though. "This code seems to work fine without > `with`, so why bother changing it?" Yeah, I guess I can see doing something like: __del__ = __exit__ but anything beyond that seems risky... \t From nathan.alexander.rice at gmail.com Thu Mar 22 10:29:48 2012 From: nathan.alexander.rice at gmail.com (Nathan Rice) Date: Thu, 22 Mar 2012 10:29:48 -0400 Subject: Python is readable In-Reply-To: References: <4f612b19$0$1379$4fafbaef@reader2.news.tin.it> <4f691f3d$0$29981$c3e8da3$5496439d@news.astraweb.com> <87d386lmai.fsf@benfinney.id.au> <8a77bf8d-b12f-442b-a1a3-479b5d66d366@tx8g2000pbc.googlegroups.com> <6af70db0-dc4a-48ee-9ee2-1a934846d5f2@r2g2000pbs.googlegroups.com> <32b8c4ae-2509-43df-abf0-0fb308be398f@oq7g2000pbb.googlegroups.com> <4f6ae931$0$29883$c3e8da3$5496439d@news.astraweb.com> Message-ID: On Thu, Mar 22, 2012 at 9:17 AM, Chris Angelico wrote: > On Thu, Mar 22, 2012 at 11:47 PM, Nathan Rice > wrote: >> Having one core language with >> many DSLs that can interoperate is infinitely better than having many >> languages that cannot. ?A language designed in such a way would also >> prevent issues like the Python 2 -> 3 fiasco, because two versions of >> a DSL can be separate, and code can reference them independently while >> being able to interoperate. > > This is either utterly impossible, or already available, depending on > your point of view. Of course it is already available. It is called the laws of physics. Everything we know of inter-operates in the context of physical reality perfectly. > To have an infinitely-configurable program, you must make its > configuration equivalent to writing code. There is already an > infinitely-configurable program in Unix: "gcc config.c; ./a.out" takes > a simple-format text file called "config.c" and processes it. It is true that infinite configuration requires that the configuration be specified in the language of the program. What's the problem? > You want infinite DSLs? Behold! > > $ ./module1 | ./module2 | ./module3 | ./module4 > > Each one has a shebang that tells you what they are (Python 2, Python > 3, something else entirely). There's a very strict interoperability > protocol between the modules - they pass information around through > stdout and stdin. You can write any module in any language, and you > can rewrite module1 for Python 3 without affecting any other or the > invocation sequence. It has always been possible to get from one point in space to another point in space in finite time. Was the invention of the automobile was redundant and unimportant? Obviously not, the characteristics of the process matter. For example, your ability to reason about the behavior of the system you posited as a whole is limited. Are there parts of the different modules that can execute concurrently? Is the output of module1 guaranteed to be acceptable as the input for module2? Is part of module3 redundant (and thus avoidable) given some conditions in module1? If you make a change in module2 what effect does that have on module3 and module4? What if you need to go back and forth between module2 and module3 until some criterion is met before you transition to module4? What if you sometimes want to run module2b instead of module2? > Problems always come when you want to share data between dissimilar > modules. There's no single perfect data-transfer protocol that works > across all languages. What does it mean to "call a function"? If you > truly want this level of flexibility, the best thing to do is to > separate sections cleanly. In fact, the pipe system I show above could > be used that way, although it's stupidly ugly. Everything going on > stdout/stdin has a two-word dispatch envelope with a from and a to, > and each module reads a line, and if it's not addressed to it, passes > it on to stdout. Responses get sent out with their from and to > reversed. All you need is for the last module's stdout to be linked > back into the first module's stdin (not sure if you can do that or not > - it has the feeling of plugging a power strip into itself), and it'll > work perfectly. Add a bit of boilerplate so that the application > developers don't see what's happening underneath, and you could > pretend that dissimilar languages are able to call into each other. > Doesn't mean it's efficient though! What is a function? You could say that it is a sequence of logical statements that relates some assertion with another. You can make a big deal about call by name versus call by value, but it only really matters on a conceptual level when dealing with infinite objects that do not have an analytic closure. You can make a big deal about data format, but scientists have been communicating using different unit systems for hundreds of years, I don't see assertions of relationship between structures as different from unit conversions from imperial to metric; it's all data. There are of course a few snags such as cardinality of the set represented by the integer data type in one case versus another, but that is a low level detail that would be a problem if DSLs were embedded in an expressive modelling language. Data structures ultimately boil down to assertions, assertions about those assertions and relations between assertions. > TLDR version: Infinite flexibility means you're doing nothing. I could address that from a number of ways. First off, anything that is Turing complete is basically "infinitely flexible" but the difference in expressiveness (as measured by the combined length of the program and its input required to generate some output) varies over orders of magnitudes. So, we're actually discussing "infinitely expressive" though in fact we don't need to appeal to infinity here, so that is a strawman. The reason for that is the system in which concepts are generated (physical reality) is finite on some levels. Much like a fractal, though there is infinite "detail", it is the result of the recursive application and composition of a small set of motifs. This is why I keep harping on the importance of a meta-model. Given a description of the fractal system and starting state, I can predict the structure of any portion of the fractal at any time with complete accuracy (assuming it is not a stochastic system, in which case I can only predict the distribution of states). If you try to model a fractal system at a particular point by describing its geometry you will be busy for a VERY long time, and if I asked you anything about the state of the fractal at a different time you would be at a loss. All I'm trying to advocate is that people stop modelling the geometry of the system at time t and start modelling the dynamics of the system. Seems pretty reasonable to me. TL;DR there are a huge number of incompatible programming languages because people are modeling a permutation rather than the input to a permutation generating function. Nathan From anacrolix at gmail.com Thu Mar 22 10:53:51 2012 From: anacrolix at gmail.com (Matt Joiner) Date: Thu, 22 Mar 2012 22:53:51 +0800 Subject: Condition in C API Message-ID: Is there a Condition-like object exposed in the CPython C API? I've found PyThread_lock_type, but nothing condition-like. From ramit.prasad at jpmorgan.com Thu Mar 22 11:25:04 2012 From: ramit.prasad at jpmorgan.com (Prasad, Ramit) Date: Thu, 22 Mar 2012 15:25:04 +0000 Subject: urllib.urlretrieve never returns??? In-Reply-To: <4F69CBB2.6060801@shopzeus.com> References: <4F649BFC.1080601@shopzeus.com> <4F66E687.2050008@shopzeus.com> <4f67c09b$0$29981$c3e8da3$5496439d@news.astraweb.com> <4F682CDC.5000703@shopzeus.com> <4F68E49C.2060000@shopzeus.com> <5B80DD153D7D744689F57F4FB69AF474026C4BD8@SCACMX008.exchad.jpmchase.net> <5B80DD153D7D744689F57F4FB69AF474026C4C97@SCACMX008.exchad.jpmchase.net> <4F69CBB2.6060801@shopzeus.com> Message-ID: <5B80DD153D7D744689F57F4FB69AF474026C646B@SCACMX008.exchad.jpmchase.net> > > I just looked at your source file on ActiveState and noticed that > > you do not import traceback. That is why you are getting the > > AttributeError. Now you should be getting a much better error > > once you import it:) > Nope. That would result in a NameError. After adding "import traceback", > I still get several AttributeError messages. The traceback should > contain the exact line number, and a description about what object is > missing what attribute anyway. My code is pure Python, and under no > circumstances should it be able to start a blocked call for a system > library function. Your code works for me, so the problem should be your system and/or network. Try a different Python version? I tested using 2.6.6. Also, check your proxy or firewall. If you are using Python 2.x try using urllib2. Ramit Ramit Prasad | JPMorgan Chase Investment Bank | Currencies Technology 712 Main Street | Houston, TX 77002 work phone: 713 - 216 - 5423 This email is confidential and subject to important disclaimers and conditions including on offers for the purchase or sale of securities, accuracy and completeness of information, viruses, confidentiality, legal privilege, and legal entity disclaimers, available at http://www.jpmorgan.com/pages/disclosures/email. From showell30 at yahoo.com Thu Mar 22 11:33:34 2012 From: showell30 at yahoo.com (Steve Howell) Date: Thu, 22 Mar 2012 08:33:34 -0700 (PDT) Subject: Python is readable References: <4f612b19$0$1379$4fafbaef@reader2.news.tin.it> <4f691f3d$0$29981$c3e8da3$5496439d@news.astraweb.com> <87d386lmai.fsf@benfinney.id.au> <8a77bf8d-b12f-442b-a1a3-479b5d66d366@tx8g2000pbc.googlegroups.com> <6af70db0-dc4a-48ee-9ee2-1a934846d5f2@r2g2000pbs.googlegroups.com> <32b8c4ae-2509-43df-abf0-0fb308be398f@oq7g2000pbb.googlegroups.com> <4f6ae931$0$29883$c3e8da3$5496439d@news.astraweb.com> Message-ID: <3d27a54d-b790-4c73-8fd1-05fcbe9abf7e@r2g2000pbs.googlegroups.com> On Mar 22, 1:56?am, Steven D'Aprano wrote: > On Wed, 21 Mar 2012 18:35:16 -0700, Steve Howell wrote: > > On Mar 21, 11:06?am, Nathan Rice > > wrote: > >> As for syntax, we have a lot of "real" domain specific languages, such > >> as English, math and logic. They are vetted, understood and useful > >> outside the context of programming. ?We should approach the discussion > >> of language syntax from the perspective of trying to define a unified > >> syntactical structure for real these DSLs. ? ?Ideally it would allow > >> representation of things in a familiar way where possible, while > >> providing an elegant mechanism for descriptions that cut across domains > >> and eliminating redundancy/ambiguity. ?This is clearly possible, though > >> a truly successful attempt would probably be a work of art for the > >> ages. > > > If I'm reading you correctly, you're expressing frustration with the > > state of language syntax unification in 2012. ?You mention language in a > > broad sense (not just programming languages, but also English, math, > > logic, etc.), but even in the narrow context of programming languages, > > the current state of the world is pretty chaotic. > > And this is a good thing. Programming languages are chaotic because the > universe of programming problems is chaotic, and the strategies available > to solve those problems are many and varied. > > Different programming languages are good for different things because > they have been designed to work in different problem/solution spaces. > Although I dislike C with a passion, I do recognise that it is good for > when the programmer needs fine control over the smallest details. It is, > after all, a high-level assembler. Likewise for Forth, which lets you > modify the compiler and language as you go. > > Some languages are optimized for the compiler, some for the writer, and > some for the reader. So are optimized for numeric work, others for > database access. Some are Jack-Of-All-Trades. Each language encourages > its own idioms and ways of thinking about programming. > > When it comes to programming, I say, let a thousand voices shout out. > Instead of imagining a single language so wonderful that every other > language is overshadowed and forgotten, imagine that the single language > is the next Java, or C, or even for that matter Python, but whatever it > is, it's not ideal for the problems you care about, or the way you think > about them. Not so attractive now, is it? > I'm not imagining a world where a single, imperfect programming language crowds out other useful solutions. What I am hoping for is a more purposeful diversity. It would be great if the top 20 languages in the future had the same expressive power as say the top 200 do now. In other words, by the time you investigated the 21st best language for your needs, it would be something really interesting and cutting edge, instead of PHP. It's hard to imagine the *specific* form of progress we'll have in the future, but I'd imagine that some day we'll have something more interesting than a best-of-breed Algol derivative dominating the scene. > > The optimistic view is that there will be some kind of inflection point > > around 2020 or so. ?I could imagine a perfect storm of good things > > happening, like convergence on a single browser platform, > > You call that a perfect storm of good things. I call that sort of > intellectual and software monoculture a nightmare. > > I want a dozen browsers, not one of which is so common that web designers > can design for it and ignore the rest, not one browser so common that > nobody dares try anything new. > I don't want a monoculture any more than you do. When I talk about "convergence on a single browser platform", the thought was that web designers might not to have waste brain cycles on IE6 workarounds in 2020; instead, they could be working on actual, cutting edge design. By "convergence on a single browser platform", I was hoping for something like the Unix situation that we have now--there's still competition, there's still innovation around the edges, but you can generally rely on 90% of the platform to be predictable. > > nearly > > complete migration to Python 3, further maturity of JVM-based languages, > > etc., where the bar gets a little higher from what people expect from > > languages. ?Instead of fighting semicolons and braces, we start thinking > > bigger. ?It could also be some sort of hardware advance, like screen > > resolutions that are so amazing they let us completely rethink our views > > on terseness, punctuation, code organization, etc. > > And what of those with poor eyesight, or the blind? Are they to be > excluded from your "bigger" brave new world? I made my hypothetical advance ("screen resolutions") a little too narrow and hardware-focused. What I really meant to imagine is a world where eyesight and monitors stop being a bottleneck. Suppose people with normal eyesight had way, way better monitors, and suppose people with less than perfect eyesight had way more remedies available (laser surgery, brain implants, whatever). With those constraints removed, how would it change our view on what code should "look" like? Also, far more people are already held back by a lack of vision than a lack of eyesight. They can only imagine the worst scenarios with any suggestion of progress, they embrace the status quo despite its obvious shortcomings, etc. From showell30 at yahoo.com Thu Mar 22 12:12:59 2012 From: showell30 at yahoo.com (Steve Howell) Date: Thu, 22 Mar 2012 09:12:59 -0700 (PDT) Subject: Python is readable References: <4f612b19$0$1379$4fafbaef@reader2.news.tin.it> <8a77bf8d-b12f-442b-a1a3-479b5d66d366@tx8g2000pbc.googlegroups.com> <6af70db0-dc4a-48ee-9ee2-1a934846d5f2@r2g2000pbs.googlegroups.com> <32b8c4ae-2509-43df-abf0-0fb308be398f@oq7g2000pbb.googlegroups.com> <4f6ae931$0$29883$c3e8da3$5496439d@news.astraweb.com> Message-ID: <887ca72d-72f6-46f4-9af2-2cfd72d10212@t8g2000pbe.googlegroups.com> On Mar 22, 7:29?am, Nathan Rice wrote: > On Thu, Mar 22, 2012 at 9:17 AM, Chris Angelico wrote: > > On Thu, Mar 22, 2012 at 11:47 PM, Nathan Rice > > wrote: > >> Having one core language with > >> many DSLs that can interoperate is infinitely better than having many > >> languages that cannot. ?A language designed in such a way would also > >> prevent issues like the Python 2 -> 3 fiasco, because two versions of > >> a DSL can be separate, and code can reference them independently while > >> being able to interoperate. > > > This is either utterly impossible, or already available, depending on > > your point of view. > > Of course it is already available. ?It is called the laws of physics. > Everything we know of inter-operates in the context of physical > reality perfectly. > > > To have an infinitely-configurable program, you must make its > > configuration equivalent to writing code. There is already an > > infinitely-configurable program in Unix: "gcc config.c; ./a.out" takes > > a simple-format text file called "config.c" and processes it. > > It is true that infinite configuration requires that the configuration > be specified in the language of the program. ?What's the problem? > > > You want infinite DSLs? Behold! > > > $ ./module1 | ./module2 | ./module3 | ./module4 > > > Each one has a shebang that tells you what they are (Python 2, Python > > 3, something else entirely). There's a very strict interoperability > > protocol between the modules - they pass information around through > > stdout and stdin. You can write any module in any language, and you > > can rewrite module1 for Python 3 without affecting any other or the > > invocation sequence. > > It has always been possible to get from one point in space to another > point in space in finite time. ?Was the invention of the automobile > was redundant and unimportant? ?Obviously not, the characteristics of > the process matter. > The funny thing about the "automobile" is that, for all its impact, it's really just a better horse. Imagine in 1750 three futurists pondering how people in the future could solve the problem of physical separation: Futurist A: We'll breed a better horse. Futurist B: No, we should build a mechanical machine that's faster than a horse. Futurist C: What if we make it so that two people 10,000 miles away from each other can talk to each other like they're next door? The ironic thing is that telecommunication was more or less solved in the late 1800s or so, but in the 21 century, we still talk about "horsepower" for our people-moving machines. I think in 2012, when it comes to programming languages, we're still mostly breeding better horses. Nothing wrong with that, just an observation. From edreamleo at gmail.com Thu Mar 22 12:48:06 2012 From: edreamleo at gmail.com (Edward K. Ream) Date: Thu, 22 Mar 2012 09:48:06 -0700 (PDT) Subject: ANN: Leo 4.10 b1 released Message-ID: <568e1ced-1a06-439b-8c53-949c99d6aa97@n9g2000pbb.googlegroups.com> Leo 4.10 b1 is now available at: http://sourceforge.net/projects/leo/files/ Leo is a text editor, data organizer, project manager and much more. http://webpages.charter.net/edreamleo/intro.html Leo 4.10 contains 9 months of intense work on Leo. Several very important features are subtle; you could almost call them Easter Eggs, so please read the following notes carefully. The highlights of Leo 4.10: -------------------------- * Dozens of new and improved features and commands, including... - Tab completion now shows all @command & @button nodes. - Leo tabs may be detached from the main window. - The Open With menu now works. - The leoInspect module answers questions about Python code. - Leo can highlight the pane containing the focus. - The bigdash plugin searches across multiple files. - Improved abbreviation capabilities. - Improved handling of URL's. - Improved editing of non-Leo files. - Improvements create "weightless" unit testing. * Easier installation on MacOS. * Fixed almost 70 bugs. The Easter Eggs --------------- 1. Tab completion now shows all @command & @button nodes. Put all your common scripts in @command nodes in myLeoSettings.leo. Typing @c will remind you of the names of these scripts. You can execute the scripts by name without the "@command-" prefix. 2. Improved abbreviation capabilities. Virtually any kind of abbreviation is possible. For example, ~a to ?. 3. Improved handling of URL's. URL's can link to other Leo outlines. Ctrl-Click on nodes or URL's in body text to activate the URL. 4 Weightless unit testing. The mantra is edit, alt-4 (run-marked-unit-tests-externally), edit, alt-4,... Several seemingly innocuous changes made this work without an "friction". The result is a remarkable increase in productivity. Links: ------ Leo: http://webpages.charter.net/edreamleo/front.html Forum: http://groups.google.com/group/leo-editor Download: http://sourceforge.net/projects/leo/files/ Bzr: http://code.launchpad.net/leo-editor/ Quotes: http://webpages.charter.net/edreamleo/testimonials.html From steve+comp.lang.python at pearwood.info Thu Mar 22 13:18:17 2012 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 22 Mar 2012 17:18:17 GMT Subject: Python is readable References: <4f612b19$0$1379$4fafbaef@reader2.news.tin.it> <4f691f3d$0$29981$c3e8da3$5496439d@news.astraweb.com> <87d386lmai.fsf@benfinney.id.au> <8a77bf8d-b12f-442b-a1a3-479b5d66d366@tx8g2000pbc.googlegroups.com> <6af70db0-dc4a-48ee-9ee2-1a934846d5f2@r2g2000pbs.googlegroups.com> <32b8c4ae-2509-43df-abf0-0fb308be398f@oq7g2000pbb.googlegroups.com> <4f6ae931$0$29883$c3e8da3$5496439d@news.astraweb.com> Message-ID: <4f6b5ed9$0$29981$c3e8da3$5496439d@news.astraweb.com> On Thu, 22 Mar 2012 08:47:15 -0400, Nathan Rice wrote: > There is a concept in statistical/mathematical modeling called minimum > message length (a close analog is minimum description length), which > asserts that the optimum model for some set of information is the one > that minimizes the sum of the length of the model and the length of the > set described by that model. (1) Optimum in what sense? (2) What does this have to do with designing programming languages? This discussion sounds to me like the apocryphal story about the spherical cow. http://en.wikipedia.org/wiki/Spherical_cow > Clearly no model is going to be optimal > for every set of information. What I was alluding to in the post that > Steve Howell replied to was that we need to have a programming language > that is a model of models, then include a second order model as part of > the program. Having one core language with many DSLs that can > interoperate is infinitely better than having many languages that > cannot. Some people, when confronted with a problem, think "I know, I'll use a DSL." Now they have two problems. And some people think "I know, I'll use a meta-language with an infinite number of infinitely variable DSLs." Now they have an infinite number of problems. > A language designed in such a way would also prevent issues > like the Python 2 -> 3 fiasco, What fiasco? You've just lost an awful lot of credibility with me. -- Steven From steve+comp.lang.python at pearwood.info Thu Mar 22 13:26:11 2012 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 22 Mar 2012 17:26:11 GMT Subject: Best way to disconnect from ldap? References: <4F6A4D02.6020403@tim.thechases.com> Message-ID: <4f6b60b2$0$29981$c3e8da3$5496439d@news.astraweb.com> On Thu, 22 Mar 2012 08:14:47 -0500, Tycho Andersen wrote: > I've had similar experiences. In fact, in light of all this - why does > __del__ exist at all? Novice python users may (reasonably) assume it > behaves similarly to a C++ destructor (even though the docs warn > otherwise). What makes you think that novice Python users will be familiar with C++ destructors? Be careful about assuming that idioms in will be shared by all Python programmers, novice or expert. > Given that you can't trust __del__, is there a legitimate use case for > it? I've never found the need to write one. -- Steven From steve+comp.lang.python at pearwood.info Thu Mar 22 13:44:25 2012 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 22 Mar 2012 17:44:25 GMT Subject: Python is readable References: <4f612b19$0$1379$4fafbaef@reader2.news.tin.it> <87d386lmai.fsf@benfinney.id.au> <8a77bf8d-b12f-442b-a1a3-479b5d66d366@tx8g2000pbc.googlegroups.com> <6af70db0-dc4a-48ee-9ee2-1a934846d5f2@r2g2000pbs.googlegroups.com> <32b8c4ae-2509-43df-abf0-0fb308be398f@oq7g2000pbb.googlegroups.com> <4f6ae931$0$29883$c3e8da3$5496439d@news.astraweb.com> Message-ID: <4f6b64f9$0$29981$c3e8da3$5496439d@news.astraweb.com> On Thu, 22 Mar 2012 10:29:48 -0400, Nathan Rice wrote: [Snip a load of stuff about the laws of physics, infinity, and of course fractals.] I'm just surprised you didn't manage to fit quantum mechanics and "the interconnectedness of all things" into it :) > TL;DR there are a huge number of incompatible programming languages > because people are modeling a permutation rather than the input to a > permutation generating function. No offence Nathan, but I think you need to come back down to earth for air before you black out: http://www.joelonsoftware.com/articles/fog0000000018.html Or at least before *I* black out. Even if somebody manages to write your meta-language, you're going to run into the problem of who is going to be able to use it. The typical developer knows three, maybe four languages moderately well, if you include SQL and regexes as languages, and might have a nodding acquaintance with one or two more. With the radical changes you're suggesting, developers would need to be able to deal with some arbitrary number of different DSLs, and whatever meta-language is used to glue them together. There are a huge number of incompatible programming languages because language designers have different requirements, preferences, and styles; and because the state of the art of language design is very different in 2012 than it was in 1962. -- Steven From python.list at tim.thechases.com Thu Mar 22 13:54:29 2012 From: python.list at tim.thechases.com (Tim Chase) Date: Thu, 22 Mar 2012 12:54:29 -0500 Subject: Best way to disconnect from ldap? In-Reply-To: <4f6b60b2$0$29981$c3e8da3$5496439d@news.astraweb.com> References: <4F6A4D02.6020403@tim.thechases.com> <4f6b60b2$0$29981$c3e8da3$5496439d@news.astraweb.com> Message-ID: <4F6B6755.7000104@tim.thechases.com> On 03/22/12 12:26, Steven D'Aprano wrote: > On Thu, 22 Mar 2012 08:14:47 -0500, Tycho Andersen wrote: >> Given that you can't trust __del__, is there a legitimate >> use case for it? > > I've never found the need to write one. I've found the need to write them...then been frustrated by things falling out of namespace reach, and found that context managers do a much more reliable/understandable job, saving what little sanity I had left. ;-) So I'd say that __del__ was really only useful (for some sick, sick definition of "useful") in versions of Python before context-managers were readily available. -tkc From jcd at sdf.lonestar.org Thu Mar 22 14:12:32 2012 From: jcd at sdf.lonestar.org (J. Cliff Dyer) Date: Thu, 22 Mar 2012 14:12:32 -0400 Subject: Python classes: Simplify? In-Reply-To: <4F6B25D7.9020002@gmail.com> References: <4F6B25D7.9020002@gmail.com> Message-ID: <1332439952.4992.2.camel@jcdyer-laptop> The issue of explicitly naming a "self" parameter has been discussed in depth on a number of occasions. I recommend a google search for "python implicit self" for some of the reasons why it exists. Here's what Guido has to say about it: http://neopythonic.blogspot.com/2008/10/why-explicit-self-has-to-stay.html Cheers, Cliff On Thu, 2012-03-22 at 13:15 +0000, Andrea Crotti wrote: > On 03/22/2012 10:51 AM, Steven Lehar wrote: > > It seems to me that the Python class system is needlessly confusing. > > Am I missing something? > > > > > > For example in the class Complex given in the documentation > > > > > > class Complex: > > def __init__(self, realpart, imagpart): > > self.r = realpart > > self.i = imagpart > > > > > > x = Complex(3.0, -4.5) > > > > > > I initially found it profoundly confusing that __init__( ) calls for > > 3 arguments, but you call Complex( ) with 2. Furthermore, why not > > call the initialization function after the class name as is done in > > other languages? Isn't that the simplest conceptually? Demonstrating > > with the above example: > > > > > > class Complex: > > def Complex(realpart, imagpart): > > Complex.r = realpart > > Complex.i = imagpart > > > > > > x = Complex(3.0, -4.5) > > > > > > Is there a good reason why classes cannot be defined that way? > > (Besides the problem of backward-compatibility) > > > > > > Some time ago I saw some nasty hack that allowed you to drop the self > in the method declaration, > using some crazy metaclass trick, but that's really not a good idea ;) > > I agree that is counter-intuitive but just set your editor to do that > for you and you will be fine.. > > in my emacs > - s TAB -> self > - . TAB -> self. > - m TAB -> def ${1:method}(self$2): > $0 > > so I never actually write the self.. From nathan.alexander.rice at gmail.com Thu Mar 22 14:26:51 2012 From: nathan.alexander.rice at gmail.com (Nathan Rice) Date: Thu, 22 Mar 2012 14:26:51 -0400 Subject: Python is readable In-Reply-To: <4f6b5ed9$0$29981$c3e8da3$5496439d@news.astraweb.com> References: <4f612b19$0$1379$4fafbaef@reader2.news.tin.it> <4f691f3d$0$29981$c3e8da3$5496439d@news.astraweb.com> <87d386lmai.fsf@benfinney.id.au> <8a77bf8d-b12f-442b-a1a3-479b5d66d366@tx8g2000pbc.googlegroups.com> <6af70db0-dc4a-48ee-9ee2-1a934846d5f2@r2g2000pbs.googlegroups.com> <32b8c4ae-2509-43df-abf0-0fb308be398f@oq7g2000pbb.googlegroups.com> <4f6ae931$0$29883$c3e8da3$5496439d@news.astraweb.com> <4f6b5ed9$0$29981$c3e8da3$5496439d@news.astraweb.com> Message-ID: >> There is a concept in statistical/mathematical modeling called minimum >> message length (a close analog is minimum description length), which >> asserts that the optimum model for some set of information is the one >> that minimizes the sum of the length of the model and the length of the >> set described by that model. > > (1) Optimum in what sense? Oh, I don't know, the information theoretic one? Of course, if you're part of the department of redundancy department, that might seem to appear to look like a poor, weak, sub-optimal criterion for the purposes of evaluation of optimality, goodness and positive quality. If you're getting hung up on the fact that there are deep ties to data compression in this language, let me help you out. Imagine that instead of having a simple Boolean algebra of two values, the possible values ranged over a set of elementary concepts. You are then trying to come up with a set of compound concepts and a permutation of those concepts that can describe > (2) What does this have to do with designing programming languages? A program is a representation of knowledge (i.e. a model) which a machine has the ability to interpret. Let me know if you can't understand this, I'll break it down further for you. > This discussion sounds to me like the apocryphal story about the > spherical cow. > > http://en.wikipedia.org/wiki/Spherical_cow When you take the baton, you're supposed to keep running along the path in the same direction as the person who handed it to you. >> Clearly no model is going to be optimal >> for every set of information. ?What I was alluding to in the post that >> Steve Howell replied to was that we need to have a programming language >> that is a model of models, then include a second order model as part of >> the program. ?Having one core language with many DSLs that can >> interoperate is infinitely better than having many languages that >> cannot. > > Some people, when confronted with a problem, think "I know, I'll use a > DSL." Now they have two problems. Sure. When confronted with the problem of finding the area under a curve, using integral calculus is going to make things worse... I should just manually sum the infantesimals, from now until the end of time. > And some people think "I know, I'll use a meta-language with an infinite > number of infinitely variable DSLs." Now they have an infinite number of > problems. I'll agree with you, if we change that statement to say "an infinite number of possible problems, all isomorphic to each other." >> A language designed in such a way would also prevent issues >> like the Python 2 -> 3 fiasco, > > What fiasco? The extremely slow uptake? I don't really care one way or another but a lot of the devs have lamented the issue. > You've just lost an awful lot of credibility with me. I didn't lose anything, technically you lost some of your belief in my credibility. So, tautologically, you are the one that lost in this situation. > I'm just surprised you didn't manage to fit quantum mechanics and "the > interconnectedness of all things" into it :) Math/Logic are encompassing. I could draw analogies to quantum theory if you really wanted (category theory is great for this sort of thing). As for the interconnectedness of all things, that is quack language, I do science. >> TL;DR there are a huge number of incompatible programming languages >> because people are modeling a permutation rather than the input to a >> permutation generating function. > > No offence Nathan, but I think you need to come back down to earth for > air before you black out: > > http://www.joelonsoftware.com/articles/fog0000000018.html I read that article a long time ago, it was bullshit then, it is bullshit now. The only thing he gets right is that the Shannon information of a uniquely specified program is proportional to the code that would be required to generate it. Never mind that if a program meets a specification, you shouldn't care about any of the values used for unspecified parts of the program. If you care about the values, they should be specified. So, if Joel had said that the program was uniquely specified, or that none of the things that weren't specified require values in the programming language, he might have been kinda, sorta right. Of course, nobody cares enough to specify every last bit of minutiae in a program, and specifications change, so it is pretty much impossible to imagine either case ever actually occurring. > Or at least before *I* black out. Even if somebody manages to write your > meta-language, you're going to run into the problem of who is going to be > able to use it. The typical developer knows three, maybe four languages > moderately well, if you include SQL and regexes as languages, and might > have a nodding acquaintance with one or two more. Please don't black out Steven. I'm trying to encourage thought in interesting directions; you can't think when you're unconscious. Lets draw the analogy to mathematicians. If a mathematician wants to solve a problem, he can cruise along at a pretty good clip as long as he understands the theories of the problem domain. If he runs into a portion of the problem domain that requires theories he isn't familiar with, he must trot off to the library for a book, or read some journal articles. Once he's absorbed the theory, he can continue to work on solving the problem, and if he encounters other problems that require the theory, he is set. I can give you another analogy that is even clearer... What happens if there are several words in a paragraph you don't know? You go to the dictionary to look them up, you now know the words, they are part of your vocabulary, and life is good. Finally, what about when you want to use a library in a programming language you already know? That is a domain specific language that just so happens to have the syntax and semantics of the base language as a subset of its own syntax and semantics. Part of the problem here, I think, is that you imagine each DSL to have radically different syntax and semantics. That is unnecessary, and actually contrary to what I am proposing. > With the radical changes you're suggesting, developers would need to be > able to deal with some arbitrary number of different DSLs, and whatever > meta-language is used to glue them together. They already do that (replace DSL with library here, again). The problem is that the meta-language lacks expressiveness and flexibility because it is modeling the permutation rather than the permutation generator. > There are a huge number of incompatible programming languages because > language designers have different requirements, preferences, and styles; > and because the state of the art of language design is very different in > 2012 than it was in 1962. Every language goes to 1s and 0s in the end. Clearly 1s and 0s are capable of closing the space of requirements, preferences and styles. This is the case because programs are information (i.e. encoded knowledge). All I'm proposing is an intermediate representation language that describes the higher order structure and dynamics of knowledge in a clean, human readable format. Mathematicians realized this was a good idea and started down this path something like 140 years ago (minus the human readable ;). They aren't done yet, so clearly any meta language someone develops would similarly be a work in progress, but the nice thing is that backwards compatibility would never be broken; as deeper theorems are exposed, previous results can be recast as specific cases of them. From ralph.heinkel at web.de Thu Mar 22 14:34:58 2012 From: ralph.heinkel at web.de (Ralph Heinkel) Date: Thu, 22 Mar 2012 11:34:58 -0700 (PDT) Subject: Compiling Python (modules) on 64bit Windows - which compiler suite? In-Reply-To: <13033772.7.1332374778471.JavaMail.geo-discussion-forums@ynjk1> References: <808abad4-3ab3-4336-8a31-2f88eb28be01@v22g2000vby.googlegroups.com> <13033772.7.1332374778471.JavaMail.geo-discussion-forums@ynjk1> Message-ID: <11748169.44.1332441298178.JavaMail.geo-discussion-forums@vbbp15> > > See "Compiling 64-bit extension modules on Windows" at . It applies to non-Cython extensions as well. > > MinGW-w64 also works, but you'll have to generate and use libpythonXX.a and libmsvcr90.a link libraries. > > Christoph Thanks to everyone who has replied to my question. Especially for the link/hint to use the .NET SDK which indeed seems to provide the right tools for 64bit compilation. I'm going to try this and report back here. Cheers, Ralph From rosuav at gmail.com Thu Mar 22 15:08:28 2012 From: rosuav at gmail.com (Chris Angelico) Date: Fri, 23 Mar 2012 06:08:28 +1100 Subject: Python is readable In-Reply-To: References: <4f612b19$0$1379$4fafbaef@reader2.news.tin.it> <4f691f3d$0$29981$c3e8da3$5496439d@news.astraweb.com> <87d386lmai.fsf@benfinney.id.au> <8a77bf8d-b12f-442b-a1a3-479b5d66d366@tx8g2000pbc.googlegroups.com> <6af70db0-dc4a-48ee-9ee2-1a934846d5f2@r2g2000pbs.googlegroups.com> <32b8c4ae-2509-43df-abf0-0fb308be398f@oq7g2000pbb.googlegroups.com> <4f6ae931$0$29883$c3e8da3$5496439d@news.astraweb.com> <4f6b5ed9$0$29981$c3e8da3$5496439d@news.astraweb.com> Message-ID: On Fri, Mar 23, 2012 at 5:26 AM, Nathan Rice wrote: [regarding Python 2 -> 3] > The extremely slow uptake? ?I don't really care one way or another but > a lot of the devs have lamented the issue. By your plan, the slow uptake would be accepted, even encouraged. In fact, your plan is effectively equivalent to simply having both Python 2 and Python 3 installed on every computer, plus having some way for them to interact. ChrisA From rosuav at gmail.com Thu Mar 22 15:14:46 2012 From: rosuav at gmail.com (Chris Angelico) Date: Fri, 23 Mar 2012 06:14:46 +1100 Subject: Number of languages known [was Re: Python is readable] - somewhat OT Message-ID: On Fri, Mar 23, 2012 at 4:44 AM, Steven D'Aprano wrote: > The typical developer knows three, maybe four languages > moderately well, if you include SQL and regexes as languages, and might > have a nodding acquaintance with one or two more. I'm not entirely sure what you mean by "moderately well", nor "languages", but I'm of the opinion that a good developer should be able to learn a new language very efficiently. Do you count Python 2 and 3 as the same language? What about all the versions of the C standard? In any case, though, I agree that there's a lot of people professionally writing code who would know about the 3-4 that you say. I'm just not sure that they're any good at coding, even in those few languages. All the best people I've ever known have had experience with quite a lot of languages. ChrisA From rosuav at gmail.com Thu Mar 22 15:21:12 2012 From: rosuav at gmail.com (Chris Angelico) Date: Fri, 23 Mar 2012 06:21:12 +1100 Subject: Python is readable In-Reply-To: References: <4f612b19$0$1379$4fafbaef@reader2.news.tin.it> <4f691f3d$0$29981$c3e8da3$5496439d@news.astraweb.com> <87d386lmai.fsf@benfinney.id.au> <8a77bf8d-b12f-442b-a1a3-479b5d66d366@tx8g2000pbc.googlegroups.com> <6af70db0-dc4a-48ee-9ee2-1a934846d5f2@r2g2000pbs.googlegroups.com> <32b8c4ae-2509-43df-abf0-0fb308be398f@oq7g2000pbb.googlegroups.com> <4f6ae931$0$29883$c3e8da3$5496439d@news.astraweb.com> Message-ID: On Fri, Mar 23, 2012 at 1:29 AM, Nathan Rice wrote: > For example, your ability to reason about the behavior of the system > you posited as a whole is limited. ?Are there parts of the different > modules that can execute concurrently? ?Is the output of module1 > guaranteed to be acceptable as the input for module2? ?Is part of > module3 redundant (and thus avoidable) given some conditions in > module1? ?If you make a change in module2 what effect does that have > on module3 and module4? ?What if you need to go back and forth between > module2 and module3 until some criterion is met before you transition > to module4? ?What if you sometimes want to run module2b instead of > module2? Pipes allow different modules to execute concurrently (except on DOS and maybe Windows, haven't checked). Nothing in ANY language "guarantees" acceptable input, but protocolling would do that for you. If part of module3 is redundant, you don't call it. If you make a change to one that affects others, then you fix the others, same as in any other coding system (or non-coding system - if you upgrade your hardware from an 8086 with 1MB of memory to a modern box with >4GB, you'll have to rewrite your code to take advantage of it). The (somewhat stupid) protocol I suggested allows you to go between 2 and 3 before going to 4. If you want module2b, you add it to the chain and call on it. Yep, Unix solved all your problems back in the 1970s. ChrisA From tjreedy at udel.edu Thu Mar 22 15:27:37 2012 From: tjreedy at udel.edu (Terry Reedy) Date: Thu, 22 Mar 2012 15:27:37 -0400 Subject: Best way to disconnect from ldap? In-Reply-To: <4F6B6755.7000104@tim.thechases.com> References: <4F6A4D02.6020403@tim.thechases.com> <4f6b60b2$0$29981$c3e8da3$5496439d@news.astraweb.com> <4F6B6755.7000104@tim.thechases.com> Message-ID: On 3/22/2012 1:54 PM, Tim Chase wrote: > On 03/22/12 12:26, Steven D'Aprano wrote: >> On Thu, 22 Mar 2012 08:14:47 -0500, Tycho Andersen wrote: >>> Given that you can't trust __del__, is there a legitimate >>> use case for it? It is part of original or early Python and pretty well superceded by cyclic gc (which does not work for object with __del__ *because* of the unreliability), explicit close methods, and now context managers. >> >> I've never found the need to write one. > > I've found the need to write them...then been frustrated by things > falling out of namespace reach, and found that context managers do a > much more reliable/understandable job, saving what little sanity I had > left. ;-) Which is one reason they were added ;-). > So I'd say that __del__ was really only useful (for some sick, sick > definition of "useful") in versions of Python before context-managers > were readily available. And before cyclic gc, which does a better job of ordering deletions. -- Terry Jan Reedy From nathan.alexander.rice at gmail.com Thu Mar 22 15:33:28 2012 From: nathan.alexander.rice at gmail.com (Nathan Rice) Date: Thu, 22 Mar 2012 15:33:28 -0400 Subject: Python is readable In-Reply-To: References: <4f612b19$0$1379$4fafbaef@reader2.news.tin.it> <4f691f3d$0$29981$c3e8da3$5496439d@news.astraweb.com> <87d386lmai.fsf@benfinney.id.au> <8a77bf8d-b12f-442b-a1a3-479b5d66d366@tx8g2000pbc.googlegroups.com> <6af70db0-dc4a-48ee-9ee2-1a934846d5f2@r2g2000pbs.googlegroups.com> <32b8c4ae-2509-43df-abf0-0fb308be398f@oq7g2000pbb.googlegroups.com> <4f6ae931$0$29883$c3e8da3$5496439d@news.astraweb.com> Message-ID: >> For example, your ability to reason about the behavior of the system >> you posited as a whole is limited. ?Are there parts of the different >> modules that can execute concurrently? ?Is the output of module1 >> guaranteed to be acceptable as the input for module2? ?Is part of >> module3 redundant (and thus avoidable) given some conditions in >> module1? ?If you make a change in module2 what effect does that have >> on module3 and module4? ?What if you need to go back and forth between >> module2 and module3 until some criterion is met before you transition >> to module4? ?What if you sometimes want to run module2b instead of >> module2? > > Pipes allow different modules to execute concurrently (except on DOS > and maybe Windows, haven't checked). Nothing in ANY language > "guarantees" acceptable input, but protocolling would do that for you. > If part of module3 is redundant, you don't call it. If you make a > change to one that affects others, then you fix the others, same as in > any other coding system (or non-coding system - if you upgrade your > hardware from an 8086 with 1MB of memory to a modern box with >4GB, > you'll have to rewrite your code to take advantage of it). The > (somewhat stupid) protocol I suggested allows you to go between 2 and > 3 before going to 4. If you want module2b, you add it to the chain and > call on it. > > Yep, Unix solved all your problems back in the 1970s. Pipes do not provide any fine grained control over the concurrent behavior. If you want to change the order of calls, suddenly you have to write a bash script (with its own set of issues), etc. Unix solved these problems in much the same way that the evolution of appendages solved the problem of changing location from one point to another before the automobile. The process matters. From rosuav at gmail.com Thu Mar 22 15:48:01 2012 From: rosuav at gmail.com (Chris Angelico) Date: Fri, 23 Mar 2012 06:48:01 +1100 Subject: Python is readable In-Reply-To: References: <4f612b19$0$1379$4fafbaef@reader2.news.tin.it> <4f691f3d$0$29981$c3e8da3$5496439d@news.astraweb.com> <87d386lmai.fsf@benfinney.id.au> <8a77bf8d-b12f-442b-a1a3-479b5d66d366@tx8g2000pbc.googlegroups.com> <6af70db0-dc4a-48ee-9ee2-1a934846d5f2@r2g2000pbs.googlegroups.com> <32b8c4ae-2509-43df-abf0-0fb308be398f@oq7g2000pbb.googlegroups.com> <4f6ae931$0$29883$c3e8da3$5496439d@news.astraweb.com> Message-ID: On Fri, Mar 23, 2012 at 6:33 AM, Nathan Rice wrote: > Pipes do not provide any fine grained control over the concurrent > behavior. ?If you want to change the order of calls, suddenly you have > to write a bash script (with its own set of issues), etc. Go back to my original post. I posited a means of communication which allows one module to "call" a function in another module, purely by writing to stdout. All four (or however many) modules would run concurrently, and be waiting on stdin most of the time. Of course, the same technique could be used for true concurrency; with such a simple message-passing technique, there's no reason to wait for your response before continuing. ChrisA From rodrick.brown at gmail.com Thu Mar 22 15:48:44 2012 From: rodrick.brown at gmail.com (Rodrick Brown) Date: Thu, 22 Mar 2012 15:48:44 -0400 Subject: Odd strip behavior Message-ID: <5B2CBFB0-DC2D-47E1-978F-59E47EB3A757@gmail.com> #!/usr/bin/python def main(): str1='this is a test' str2='t' print "".join([ c for c in str1 if c not in str2 ]) print(str1.strip(str2)) if __name__ == '__main__': main() ./remove_str.py his is a es his is a tes Why wasnt the t removed ? Sent from my iPhone From rosuav at gmail.com Thu Mar 22 15:49:54 2012 From: rosuav at gmail.com (Chris Angelico) Date: Fri, 23 Mar 2012 06:49:54 +1100 Subject: Python is readable In-Reply-To: References: <4f612b19$0$1379$4fafbaef@reader2.news.tin.it> <4f691f3d$0$29981$c3e8da3$5496439d@news.astraweb.com> <87d386lmai.fsf@benfinney.id.au> <8a77bf8d-b12f-442b-a1a3-479b5d66d366@tx8g2000pbc.googlegroups.com> <6af70db0-dc4a-48ee-9ee2-1a934846d5f2@r2g2000pbs.googlegroups.com> <32b8c4ae-2509-43df-abf0-0fb308be398f@oq7g2000pbb.googlegroups.com> <4f6ae931$0$29883$c3e8da3$5496439d@news.astraweb.com> Message-ID: On Fri, Mar 23, 2012 at 6:33 AM, Nathan Rice wrote: > Pipes do not provide any fine grained control over the concurrent > behavior. ?If you want to change the order of calls... And to clarify: The "order of calls" in what I described is merely the order of initialization. It's like the order of your imports at the top of a Python script, and should have equally no significance. And a module can import other modules by dropping to another chain of pipes in exactly the same way. It'd work! I can't vouch for performance, of course... ChrisA From arnodel at gmail.com Thu Mar 22 15:53:13 2012 From: arnodel at gmail.com (Arnaud Delobelle) Date: Thu, 22 Mar 2012 19:53:13 +0000 Subject: Odd strip behavior In-Reply-To: <5B2CBFB0-DC2D-47E1-978F-59E47EB3A757@gmail.com> References: <5B2CBFB0-DC2D-47E1-978F-59E47EB3A757@gmail.com> Message-ID: On Mar 22, 2012 7:49 PM, "Rodrick Brown" wrote: > > #!/usr/bin/python > > def main(): > > str1='this is a test' > str2='t' > > print "".join([ c for c in str1 if c not in str2 ]) > print(str1.strip(str2)) > > if __name__ == '__main__': > main() > > ./remove_str.py > his is a es > his is a tes > > Why wasnt the t removed ? Try help(ste.strip) -- Arnaud -------------- next part -------------- An HTML attachment was scrubbed... URL: From ramit.prasad at jpmorgan.com Thu Mar 22 15:54:37 2012 From: ramit.prasad at jpmorgan.com (Prasad, Ramit) Date: Thu, 22 Mar 2012 19:54:37 +0000 Subject: Odd strip behavior In-Reply-To: <5B2CBFB0-DC2D-47E1-978F-59E47EB3A757@gmail.com> References: <5B2CBFB0-DC2D-47E1-978F-59E47EB3A757@gmail.com> Message-ID: <5B80DD153D7D744689F57F4FB69AF474026C6C6D@SCACMX008.exchad.jpmchase.net> > str1='this is a test' > str2='t' > > print "".join([ c for c in str1 if c not in str2 ]) > print(str1.strip(str2)) > > if __name__ == '__main__': > main() > > ./remove_str.py > his is a es > his is a tes > > Why wasnt the t removed ? This is not odd behavior, you just do not understand what strip does. :) The behavior is listed on the API. I highly recommend you take time to become familiar with it. http://docs.python.org/library/stdtypes.html#string-methods str.strip([chars]) Return a copy of the string with the leading and trailing characters removed. The chars argument is a string specifying the set of characters to be removed. If omitted or None, the chars argument defaults to removing whitespace. The chars argument is not a prefix or suffix; rather, all combinations of its values are stripped: >>> >>> ' spacious '.strip() 'spacious' >>> 'www.example.com'.strip('cmowz.') 'example' Changed in version 2.2.2: Support for the chars argument. Ramit Ramit Prasad | JPMorgan Chase Investment Bank | Currencies Technology 712 Main Street | Houston, TX 77002 work phone: 713 - 216 - 5423 -- > -----Original Message----- > From: python-list-bounces+ramit.prasad=jpmorgan.com at python.org > [mailto:python-list-bounces+ramit.prasad=jpmorgan.com at python.org] On Behalf > Of Rodrick Brown > Sent: Thursday, March 22, 2012 2:49 PM > To: python-list at python.org > Subject: Odd strip behavior > > #!/usr/bin/python > > def main(): > > Sent from my iPhone > -- > http://mail.python.org/mailman/listinfo/python-list This email is confidential and subject to important disclaimers and conditions including on offers for the purchase or sale of securities, accuracy and completeness of information, viruses, confidentiality, legal privilege, and legal entity disclaimers, available at http://www.jpmorgan.com/pages/disclosures/email. From kiuhnm03.4t.yahoo.it Thu Mar 22 15:56:19 2012 From: kiuhnm03.4t.yahoo.it (Kiuhnm) Date: Thu, 22 Mar 2012 20:56:19 +0100 Subject: Odd strip behavior In-Reply-To: References: Message-ID: <4f6b83e3$0$1389$4fafbaef@reader1.news.tin.it> On 3/22/2012 20:48, Rodrick Brown wrote: > #!/usr/bin/python > > def main(): > > str1='this is a test' > str2='t' > > print "".join([ c for c in str1 if c not in str2 ]) > print(str1.strip(str2)) > > if __name__ == '__main__': > main() > > ./remove_str.py > his is a es > his is a tes > > Why wasnt the t removed ? Because it's not a leading or trailing character. Kiuhnm From dstein64 at gmail.com Thu Mar 22 15:59:25 2012 From: dstein64 at gmail.com (Daniel Steinberg) Date: Thu, 22 Mar 2012 15:59:25 -0400 Subject: Odd strip behavior In-Reply-To: <5B2CBFB0-DC2D-47E1-978F-59E47EB3A757@gmail.com> References: <5B2CBFB0-DC2D-47E1-978F-59E47EB3A757@gmail.com> Message-ID: strip() removes leading and trailing characters, which is why the 't' in the middle of the string was not removed. To remove the 't' in the middle, str1.replace('t','') is one option. On 3/22/12 3:48 PM, Rodrick Brown wrote: > #!/usr/bin/python > > def main(): > > str1='this is a test' > str2='t' > > print "".join([ c for c in str1 if c not in str2 ]) > print(str1.strip(str2)) > > if __name__ == '__main__': > main() > > ./remove_str.py > his is a es > his is a tes > > Why wasnt the t removed ? > Sent from my iPhone From rodrick.brown at gmail.com Thu Mar 22 16:04:59 2012 From: rodrick.brown at gmail.com (Rodrick Brown) Date: Thu, 22 Mar 2012 16:04:59 -0400 Subject: Odd strip behavior In-Reply-To: References: <5B2CBFB0-DC2D-47E1-978F-59E47EB3A757@gmail.com> Message-ID: <775DE2D7-B96D-49F5-B6EA-B58BEE1B7F80@gmail.com> On Mar 22, 2012, at 3:53 PM, Arnaud Delobelle wrote: > > On Mar 22, 2012 7:49 PM, "Rodrick Brown" wrote: > > > > #!/usr/bin/python > > > > def main(): > > > > str1='this is a test' > > str2='t' > > > > print "".join([ c for c in str1 if c not in str2 ]) > > print(str1.strip(str2)) > > > > if __name__ == '__main__': > > main() > > > > ./remove_str.py > > his is a es > > his is a tes > > > > Why wasnt the t removed ? > > Try help(ste.strip) > It clearly states "if chars is given and not None, remove characters in chars instead. Does it mean remove only the first occurrence of char? That's the behavior I'm seeing. > -- > Arnaud -------------- next part -------------- An HTML attachment was scrubbed... URL: From ian.g.kelly at gmail.com Thu Mar 22 16:06:21 2012 From: ian.g.kelly at gmail.com (Ian Kelly) Date: Thu, 22 Mar 2012 14:06:21 -0600 Subject: Odd strip behavior In-Reply-To: <5B2CBFB0-DC2D-47E1-978F-59E47EB3A757@gmail.com> References: <5B2CBFB0-DC2D-47E1-978F-59E47EB3A757@gmail.com> Message-ID: On Thu, Mar 22, 2012 at 1:48 PM, Rodrick Brown wrote: > Why wasnt the t removed ? Because str.strip() only removes leading or trailing characters. If you want to remove all the t's, use str.replace: 'this is a test'.replace('t', '') Cheers, Ian From arnodel at gmail.com Thu Mar 22 16:18:22 2012 From: arnodel at gmail.com (Arnaud Delobelle) Date: Thu, 22 Mar 2012 20:18:22 +0000 Subject: Odd strip behavior In-Reply-To: <775DE2D7-B96D-49F5-B6EA-B58BEE1B7F80@gmail.com> References: <5B2CBFB0-DC2D-47E1-978F-59E47EB3A757@gmail.com> <775DE2D7-B96D-49F5-B6EA-B58BEE1B7F80@gmail.com> Message-ID: On 22 March 2012 20:04, Rodrick Brown wrote: > > On Mar 22, 2012, at 3:53 PM, Arnaud Delobelle wrote: > Try help(ste.strip) > > It clearly states "if chars is given and not None, remove characters in > chars instead. > > Does it mean remove only the first occurrence of char? That's the behavior > I'm seeing. The key words in the docstring are "leading and trailing" -- Arnaud From tycho at tycho.ws Thu Mar 22 17:02:15 2012 From: tycho at tycho.ws (Tycho Andersen) Date: Thu, 22 Mar 2012 16:02:15 -0500 Subject: Best way to disconnect from ldap? In-Reply-To: <4f6b60b2$0$29981$c3e8da3$5496439d@news.astraweb.com> References: <4F6A4D02.6020403@tim.thechases.com> <4f6b60b2$0$29981$c3e8da3$5496439d@news.astraweb.com> Message-ID: <20120322210215.GJ19657@ccapuser-ubuntu.WICOURTS.GOV> On Thu, Mar 22, 2012 at 05:26:11PM +0000, Steven D'Aprano wrote: > On Thu, 22 Mar 2012 08:14:47 -0500, Tycho Andersen wrote: > > > I've had similar experiences. In fact, in light of all this - why does > > __del__ exist at all? Novice python users may (reasonably) assume it > > behaves similarly to a C++ destructor (even though the docs warn > > otherwise). > > What makes you think that novice Python users will be familiar with C++ > destructors? I don't, really. It's just natural to assume that __del__ is the "opposite" of __init__, when it's really not (i.e. every object is __init__ed, but not every object is destructed and thus __del__'d). Novice programmers may make this assumption (indeed, many experienced programmers do as well). > Be careful about assuming that idioms in > will be shared by all Python programmers, novice or expert. Yeah, C++ was the first language which has destructors that came to mind. It's certainly not my favorite ;-) \t From steve+comp.lang.python at pearwood.info Thu Mar 22 21:11:49 2012 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 23 Mar 2012 01:11:49 GMT Subject: Number of languages known [was Re: Python is readable] - somewhat OT References: Message-ID: <4f6bcdd5$0$29981$c3e8da3$5496439d@news.astraweb.com> On Fri, 23 Mar 2012 06:14:46 +1100, Chris Angelico wrote: > On Fri, Mar 23, 2012 at 4:44 AM, Steven D'Aprano > wrote: >> The typical developer knows three, maybe four languages moderately >> well, if you include SQL and regexes as languages, and might have a >> nodding acquaintance with one or two more. > > I'm not entirely sure what you mean by "moderately well", I mean more than "poorly" but less than "very well". Until somebody invents a universal, objective scale for rating relative knowledge in a problem domain (in this case, knowledge of a programming language), we're stuck with fuzzy quantities like "guru", "expert", "deep and complete knowledge of the language and its idioms", all the way down to "can write Hello World" and "never used or seen the language before". Here's a joke version: http://www.ariel.com.au/jokes/The_Evolution_of_a_Programmer.html and here's a more serious version: http://www.yacoset.com/Home/signs-that-you-re-a-bad-programmer > nor > "languages", but I'm of the opinion that a good developer should be able > to learn a new language very efficiently. Should be, absolutely. Does, perhaps not. Some good developers spend their entire life working in one language and have become expert on every part of it. Some learn twenty different languages, and barely get beyond "Hello World" in any of them. > Do you count Python 2 and 3 as the same language? Absolutely. > What about all the versions of the C standard? Probably. I'm not familiar with the C standard. > In any case, though, I agree that there's a lot of people professionally > writing code who would know about the 3-4 that you say. I'm just not > sure that they're any good at coding, even in those few languages. All > the best people I've ever known have had experience with quite a lot of > languages. I dare say that experience with many languages is a good thing, but it's not a prerequisite for mastery of a single language. In any case, I'm not talking about the best developers. I'm talking about the typical developer, who by definition is just average. They probably know reasonably well one to three of the half dozen most popular languages (VB, Java, C, C+, Javascript, PHP, Perl?) plus regexes and SQL, and are unlikely to know any of Prolog, Lisp, Haskell, Hypertalk, Mercury, Cobra, Smalltalk, Ada, APL, Emerald, Inform, Forth, ... Or even in most cases *heard* of them. -- Steven From showell30 at yahoo.com Thu Mar 22 22:42:20 2012 From: showell30 at yahoo.com (Steve Howell) Date: Thu, 22 Mar 2012 19:42:20 -0700 (PDT) Subject: Python is readable References: <4f612b19$0$1379$4fafbaef@reader2.news.tin.it> <6af70db0-dc4a-48ee-9ee2-1a934846d5f2@r2g2000pbs.googlegroups.com> <32b8c4ae-2509-43df-abf0-0fb308be398f@oq7g2000pbb.googlegroups.com> <4f6ae931$0$29883$c3e8da3$5496439d@news.astraweb.com> <4f6b64f9$0$29981$c3e8da3$5496439d@news.astraweb.com> Message-ID: <94d35431-0d4f-44d8-85fb-93671829a554@m10g2000pbk.googlegroups.com> On Mar 22, 10:44?am, Steven D'Aprano wrote: > On Thu, 22 Mar 2012 10:29:48 -0400, Nathan Rice wrote: > > Or at least before *I* black out. Even if somebody manages to write your > meta-language, you're going to run into the problem of who is going to be > able to use it. The typical developer knows three, maybe four languages > moderately well, if you include SQL and regexes as languages, and might > have a nodding acquaintance with one or two more. > Maybe I'm not the typical developer, but I think "three, maybe four" is a very low estimate of the number of languages that the typical developer confronts in his lifetime. Just in the last couple weeks I've looked at code in all these languages: Python2 PHP JavaScript CoffeeScript C Perl Shell (bash) Regex (three variants--bash, Python, PHP) awk (albeit trivially) SQL (two variants--MySQL and Hive) HTML CSS With the exception of awk, I know all of the above languages in some depth, way beyond a "nodding acquaintance." I'm not taking any sides on the meta-language debate in pointing this out; I'm merely suggesting that we do live in a bit of a Tower of Babel. I'm only arguing with the numbers in your premise; maybe even if you underestimate the number of languages that typical devs consume in 2012, you could still draw the same valid conclusions overall with a slightly more accurate estimate. > There are a huge number of incompatible programming languages because > language designers have different requirements, preferences, and styles; > and because the state of the art of language design is very different in > 2012 than it was in 1962. Do you think we'll always have a huge number of incompatible programming languages? I agree with you that it's a fact of life in 2012, but will it be a fact of life in 2062? From showell30 at yahoo.com Thu Mar 22 22:48:19 2012 From: showell30 at yahoo.com (Steve Howell) Date: Thu, 22 Mar 2012 19:48:19 -0700 (PDT) Subject: Number of languages known [was Re: Python is readable] - somewhat OT References: <4f6bcdd5$0$29981$c3e8da3$5496439d@news.astraweb.com> Message-ID: On Mar 22, 6:11?pm, Steven D'Aprano wrote: > On Fri, 23 Mar 2012 06:14:46 +1100, Chris Angelico wrote: > > In any case, though, I agree that there's a lot of people professionally > > writing code who would know about the 3-4 that you say. I'm just not > > sure that they're any good at coding, even in those few languages. All > > the best people I've ever known have had experience with quite a lot of > > languages. > > I dare say that experience with many languages is a good thing, but it's > not a prerequisite for mastery of a single language. > > In any case, I'm not talking about the best developers. I'm talking about > the typical developer, who by definition is just average. They probably > know reasonably well one to three of the half dozen most popular > languages (VB, Java, C, C+, Javascript, PHP, Perl?) plus regexes and SQL, > and are unlikely to know any of Prolog, Lisp, Haskell, Hypertalk, > Mercury, Cobra, Smalltalk, Ada, APL, Emerald, Inform, Forth, ... I love how you can rattle off 20 or so languages, just off the top of your head, and not even mention Ruby. ;) (Although Perl was close enough.) From showell30 at yahoo.com Thu Mar 22 23:11:38 2012 From: showell30 at yahoo.com (Steve Howell) Date: Thu, 22 Mar 2012 20:11:38 -0700 (PDT) Subject: Number of languages known [was Re: Python is readable] - somewhat OT References: Message-ID: <1c6c9ad8-95bd-4dd1-84d7-692a37f5d18e@oq7g2000pbb.googlegroups.com> On Mar 22, 12:14?pm, Chris Angelico wrote: > On Fri, Mar 23, 2012 at 4:44 AM, Steven D'Aprano > > wrote: > > The typical developer knows three, maybe four languages > > moderately well, if you include SQL and regexes as languages, and might > > have a nodding acquaintance with one or two more. > > I'm not entirely sure what you mean by "moderately well", nor > "languages", but I'm of the opinion that a good developer should be > able to learn a new language very efficiently. Do you count Python 2 > and 3 as the same language? What about all the versions of the C > standard? > Not only is it hard to define what we precisely mean when we say "[knows] moderately well" or "[n number of] languages", but what in the world are we talking about with respect to "the typical developer"? How do we even begin to define that term? From rustompmody at gmail.com Thu Mar 22 23:20:00 2012 From: rustompmody at gmail.com (rusi) Date: Thu, 22 Mar 2012 20:20:00 -0700 (PDT) Subject: Python is readable References: <4f612b19$0$1379$4fafbaef@reader2.news.tin.it> <6af70db0-dc4a-48ee-9ee2-1a934846d5f2@r2g2000pbs.googlegroups.com> <32b8c4ae-2509-43df-abf0-0fb308be398f@oq7g2000pbb.googlegroups.com> <4f6ae931$0$29883$c3e8da3$5496439d@news.astraweb.com> <4f6b64f9$0$29981$c3e8da3$5496439d@news.astraweb.com> <94d35431-0d4f-44d8-85fb-93671829a554@m10g2000pbk.googlegroups.com> Message-ID: <9c7ce4fd-9530-4c34-a88e-446bab7c31ab@sv8g2000pbc.googlegroups.com> On Mar 23, 7:42?am, Steve Howell wrote: > Do you think we'll always have a huge number of incompatible > programming languages? ?I agree with you that it's a fact of life in > 2012, but will it be a fact of life in 2062? It will be a fact of life wherever Godels theorem is; which put simplistically is: consistency and completeness cannot coexist. This is the 'logic-generator' for the mess in programming languages. Put in more general terms: Completeness is an 'adding' process Consistency is a 'subtracting' process Running the two together, convergence is hopeless. In programming language terms the pull is between simplicity and expressivity/power. From dwrdx5 at gmail.com Thu Mar 22 23:23:55 2012 From: dwrdx5 at gmail.com (Edward Xu) Date: Fri, 23 Mar 2012 11:23:55 +0800 Subject: Python ctypes - Memory read Error when calling a function in a DLL Message-ID: Hi all, I'm writing a script to control a *PCMCIA* device, the driver provided by the vendor is a dll file. I just want to call functions in it, but i just don't know why I keep getting a *[**The instruction at "0x7c9108d3" referenced memory at "0xfffffff8". The memory could not be "read"**]. *Here is the documents say: *//declaration* *XLstatus xlGetDriverConfig(XLdriverConfig *pDriverConfig) * * * *typedef struct s_xl_driver_config { * * unsigned int dllVersion; * * unsigned int channelCount; * * unsigned int reserved[10]; * * XLchannelConfig channel[XL_CONFIG_MAX_CHANNELS]; * *} XLdriverConfig; * * * *//types* *typedef struct s_xl_channel_config { * * * * char name [XL_MAX_LENGTH + 1]; * * unsigned char hwType; * * unsigned char hwIndex; * * unsigned char hwChannel; * * unsigned short transceiverType; * * unsigned int transceiverState; * * unsigned char channelIndex; * * * * XLuint64 channelMask; //here * * unsigned int channelCapabilities; * * unsigned int channelBusCapabilities; * * unsigned char isOnBus; * * unsigned int connectedBusType; * * XLbusParams busParams; * * unsigned int driverVersion; * * unsigned int interfaceVersion; * * unsigned int raw_data[10]; * * unsigned int serialNumber; * * unsigned int articleNumber; * * char transceiverName [XL_MAX_LENGTH + 1]; * * unsigned int specialCabFlags; * * unsigned int dominantTimeout; * * unsigned int reserved[8]; * *} XLchannelConfig; * * * *typedef unsigned __int64 XLuint64;* * * *typedef struct { * * unsigned int busType;* * union {* * struct {* * unsigned int bitRate;* * unsigned char sjw;* * unsigned char tseg1;* * unsigned char tseg2;* * unsigned char sam; // 1 or 3* * unsigned char outputMode;* * } can;* * struct {* * unsigned int activeSpeedGrade;* * unsigned int compatibleSpeedGrade;* * } most;* * unsigned char raw[32];* * }data;* *} XLbusParams; * There is my python script below: * from ctypes import * vxlapi = WinDLL("vxlapi.dll") PyxlGetDriverConfig = vxlapi.xlGetDriverConfig class PyXLchannelConfig(Structure): _fields_ = [("Pyname",c_char*32), ("PyhwType",c_ubyte), ("PyhwIndex",c_ubyte), ("PyhwChannel",c_ubyte), ("PytransceiverType",c_ushort), ("PytransceiverState",c_ushort), ("PyconfigError",c_ushort), ("PychannelIndex",c_ubyte), ("PychannelMask",c_longlong), ("PychannelCapabilities",c_uint), ("PychannelBusCapabilities",c_uint), ("PyisOnBus",c_ubyte), ("PyconnectedBusType",c_uint), ("PybusParams",c_uint), ("PydriverVersion",c_uint), ("PyinterfaceVersion",c_uint), ("Pyraw_data",c_uint*10), ("PyserialNumber",c_uint), ("PyarticleNumber",c_uint), ("PytransceiverName",c_char*32), ("PyspecialCabFlags",c_uint), ("PydominantTimeout",c_uint), ("PydominantRecessiveDelay",c_ubyte), ("PyrecessiveDominantDelay",c_ubyte), ("PyconnectionInfo",c_ubyte), ("PycurrentlyAvailableTimestamps",c_ubyte), ("PyminimalSupplyVoltage",c_ubyte), ("PymaximalSupplyVoltage",c_ubyte), ("PymaximalBaudrate",c_uint), ("PyfpgaCoreCapabilities",c_ubyte), ("PyspecialDeviceStatus",c_ubyte), ("PychannelBusActiveCapabilities",c_ushort), ("PybreakOffset",c_ushort), ("PydelimiterOffset",c_ushort), ("Pyreserved",c_uint*3) ] class PyXLdriverConfig(Structure): _fields_ = [("PydllVersion",c_uint), ("PychannelCount",c_uint), ("Pyreserved",c_uint*10), ("Pychannel",PyXLchannelConfig*64) ] * if __name__ == "__main__": drivercfg = PyXLdriverConfig() PyxlGetDriverConfig(byref(drivercfg)) Could you help me out of this, Thank you very much! -- Best Regards Edward -------------- next part -------------- An HTML attachment was scrubbed... URL: From showell30 at yahoo.com Fri Mar 23 00:16:03 2012 From: showell30 at yahoo.com (Steve Howell) Date: Thu, 22 Mar 2012 21:16:03 -0700 (PDT) Subject: Python is readable References: <4f612b19$0$1379$4fafbaef@reader2.news.tin.it> <6af70db0-dc4a-48ee-9ee2-1a934846d5f2@r2g2000pbs.googlegroups.com> <32b8c4ae-2509-43df-abf0-0fb308be398f@oq7g2000pbb.googlegroups.com> <4f6ae931$0$29883$c3e8da3$5496439d@news.astraweb.com> <4f6b64f9$0$29981$c3e8da3$5496439d@news.astraweb.com> <94d35431-0d4f-44d8-85fb-93671829a554@m10g2000pbk.googlegroups.com> <9c7ce4fd-9530-4c34-a88e-446bab7c31ab@sv8g2000pbc.googlegroups.com> Message-ID: <3c9b6aa7-0da1-4af3-a55d-e87609dccdd3@jx17g2000pbb.googlegroups.com> On Mar 22, 8:20?pm, rusi wrote: > On Mar 23, 7:42?am, Steve Howell wrote: > > > Do you think we'll always have a huge number of incompatible > > programming languages? ?I agree with you that it's a fact of life in > > 2012, but will it be a fact of life in 2062? > > It will be a fact of life wherever Godels theorem is; which put > simplistically is: consistency and completeness cannot coexist. ?This > is the 'logic-generator' for the mess in programming languages. > Put in more general terms: > Completeness is an 'adding' process > Consistency is a 'subtracting' process > Running the two together, convergence is hopeless. Fair enough, but I don't think you can blame Godel's Theorem for the fact that JS, Ruby, Perl, and PHP all solve basically the same problems as Python in 2012. Can't we agree that at least *Perl* is redundant, and that the lingering existence of Perl 5 is an artifact of culture, legacy, and primitive experimentation (by future standards), not mathematical inevitability? > In programming language terms the pull is between simplicity and > expressivity/power. Sure, you can see this tension between Python (simplicity) and Ruby (expressivity). My idea of progress--way before 2062--is that you'd still have a spectrum of simplicity and expressivity, but the level of elegance and power throughout the spectrum would be elevated. There wouldn't be a monoculture, but the cream would eventually rise toward the top. From nathan.alexander.rice at gmail.com Fri Mar 23 00:20:42 2012 From: nathan.alexander.rice at gmail.com (Nathan Rice) Date: Fri, 23 Mar 2012 00:20:42 -0400 Subject: Python is readable In-Reply-To: <9c7ce4fd-9530-4c34-a88e-446bab7c31ab@sv8g2000pbc.googlegroups.com> References: <4f612b19$0$1379$4fafbaef@reader2.news.tin.it> <6af70db0-dc4a-48ee-9ee2-1a934846d5f2@r2g2000pbs.googlegroups.com> <32b8c4ae-2509-43df-abf0-0fb308be398f@oq7g2000pbb.googlegroups.com> <4f6ae931$0$29883$c3e8da3$5496439d@news.astraweb.com> <4f6b64f9$0$29981$c3e8da3$5496439d@news.astraweb.com> <94d35431-0d4f-44d8-85fb-93671829a554@m10g2000pbk.googlegroups.com> <9c7ce4fd-9530-4c34-a88e-446bab7c31ab@sv8g2000pbc.googlegroups.com> Message-ID: >> Do you think we'll always have a huge number of incompatible >> programming languages? ?I agree with you that it's a fact of life in >> 2012, but will it be a fact of life in 2062? > > It will be a fact of life wherever Godels theorem is; which put > simplistically is: consistency and completeness cannot coexist. ?This > is the 'logic-generator' for the mess in programming languages. > Put in more general terms: > Completeness is an 'adding' process > Consistency is a 'subtracting' process > Running the two together, convergence is hopeless. This isn't exactly correct. The incompleteness theorem basically shows that in a sufficiently expressive system, there are statements in the system that cannot be proven given the language of that system. We live with this already given the fact that the incompleteness theorem is closely related to Turing's halting problem. That doesn't indicate anything about the convergence of programming languages. It does say that we will need some form of unit testing or restricted subset simulation system as an adjunct to formal verification in most cases, until the end of time. From python at mrabarnett.plus.com Fri Mar 23 00:43:48 2012 From: python at mrabarnett.plus.com (MRAB) Date: Fri, 23 Mar 2012 04:43:48 +0000 Subject: Python is readable In-Reply-To: <3c9b6aa7-0da1-4af3-a55d-e87609dccdd3@jx17g2000pbb.googlegroups.com> References: <4f612b19$0$1379$4fafbaef@reader2.news.tin.it> <6af70db0-dc4a-48ee-9ee2-1a934846d5f2@r2g2000pbs.googlegroups.com> <32b8c4ae-2509-43df-abf0-0fb308be398f@oq7g2000pbb.googlegroups.com> <4f6ae931$0$29883$c3e8da3$5496439d@news.astraweb.com> <4f6b64f9$0$29981$c3e8da3$5496439d@news.astraweb.com> <94d35431-0d4f-44d8-85fb-93671829a554@m10g2000pbk.googlegroups.com> <9c7ce4fd-9530-4c34-a88e-446bab7c31ab@sv8g2000pbc.googlegroups.com> <3c9b6aa7-0da1-4af3-a55d-e87609dccdd3@jx17g2000pbb.googlegroups.com> Message-ID: <4F6BFF84.4040004@mrabarnett.plus.com> On 23/03/2012 04:16, Steve Howell wrote: > On Mar 22, 8:20 pm, rusi wrote: >> On Mar 23, 7:42 am, Steve Howell wrote: >> >> > Do you think we'll always have a huge number of incompatible >> > programming languages? I agree with you that it's a fact of life in >> > 2012, but will it be a fact of life in 2062? >> >> It will be a fact of life wherever Godels theorem is; which put >> simplistically is: consistency and completeness cannot coexist. This >> is the 'logic-generator' for the mess in programming languages. >> Put in more general terms: >> Completeness is an 'adding' process >> Consistency is a 'subtracting' process >> Running the two together, convergence is hopeless. > > Fair enough, but I don't think you can blame Godel's Theorem for the > fact that JS, Ruby, Perl, and PHP all solve basically the same > problems as Python in 2012. Can't we agree that at least *Perl* is > redundant, and that the lingering existence of Perl 5 is an artifact > of culture, legacy, and primitive experimentation (by future > standards), not mathematical inevitability? > Perl's support for Unicode is much better than the others. >> In programming language terms the pull is between simplicity and >> expressivity/power. > > Sure, you can see this tension between Python (simplicity) and Ruby > (expressivity). My idea of progress--way before 2062--is that you'd > still have a spectrum of simplicity and expressivity, but the level of > elegance and power throughout the spectrum would be elevated. There > wouldn't be a monoculture, but the cream would eventually rise toward > the top. > From showell30 at yahoo.com Fri Mar 23 02:58:00 2012 From: showell30 at yahoo.com (Steve Howell) Date: Thu, 22 Mar 2012 23:58:00 -0700 (PDT) Subject: Python is readable References: <4f612b19$0$1379$4fafbaef@reader2.news.tin.it> <32b8c4ae-2509-43df-abf0-0fb308be398f@oq7g2000pbb.googlegroups.com> <4f6ae931$0$29883$c3e8da3$5496439d@news.astraweb.com> <4f6b64f9$0$29981$c3e8da3$5496439d@news.astraweb.com> <94d35431-0d4f-44d8-85fb-93671829a554@m10g2000pbk.googlegroups.com> <9c7ce4fd-9530-4c34-a88e-446bab7c31ab@sv8g2000pbc.googlegroups.com> <3c9b6aa7-0da1-4af3-a55d-e87609dccdd3@jx17g2000pbb.googlegroups.com> Message-ID: <5e81d24b-96d8-4e4b-a90c-61cdf7b34a5b@px4g2000pbc.googlegroups.com> On Mar 22, 9:43?pm, MRAB wrote: > On 23/03/2012 04:16, Steve Howell wrote: > > > > > > > > > On Mar 22, 8:20 pm, rusi ?wrote: > >> ?On Mar 23, 7:42 am, Steve Howell ?wrote: > > >> ?> ?Do you think we'll always have a huge number of incompatible > >> ?> ?programming languages? ?I agree with you that it's a fact of life in > >> ?> ?2012, but will it be a fact of life in 2062? > > >> ?It will be a fact of life wherever Godels theorem is; which put > >> ?simplistically is: consistency and completeness cannot coexist. ?This > >> ?is the 'logic-generator' for the mess in programming languages. > >> ?Put in more general terms: > >> ?Completeness is an 'adding' process > >> ?Consistency is a 'subtracting' process > >> ?Running the two together, convergence is hopeless. > > > Fair enough, but I don't think you can blame Godel's Theorem for the > > fact that JS, Ruby, Perl, and PHP all solve basically the same > > problems as Python in 2012. ?Can't we agree that at least *Perl* is > > redundant, and that the lingering existence of Perl 5 is an artifact > > of culture, legacy, and primitive experimentation (by future > > standards), not mathematical inevitability? > > Perl's support for Unicode is much better than the others. > Maybe so, but is that an intrinsic feature of the language or just an implementation detail? Even if it's a somewhat intrinsic feature of the language, how hard would it be to subsume Perl's Unicode goodness into the best-of-breed language of all of Perl's cousins? From rosuav at gmail.com Fri Mar 23 03:05:14 2012 From: rosuav at gmail.com (Chris Angelico) Date: Fri, 23 Mar 2012 18:05:14 +1100 Subject: Number of languages known [was Re: Python is readable] - somewhat OT In-Reply-To: References: <4f6bcdd5$0$29981$c3e8da3$5496439d@news.astraweb.com> Message-ID: On Fri, Mar 23, 2012 at 1:48 PM, Steve Howell wrote: > On Mar 22, 6:11?pm, Steven D'Aprano +comp.lang.pyt... at pearwood.info> wrote: >> In any case, I'm not talking about the best developers. I'm talking about >> the typical developer, who by definition is just average. They probably >> know reasonably well one to three of the half dozen most popular >> languages (VB, Java, C, C+, Javascript, PHP, Perl?) plus regexes and SQL, >> and are unlikely to know any of Prolog, Lisp, Haskell, Hypertalk, >> Mercury, Cobra, Smalltalk, Ada, APL, Emerald, Inform, Forth, ... > > I love how you can rattle off 20 or so languages, just off the top of > your head, and not even mention Ruby. ;) If I were to rattle off a couple dozen languages, it probably wouldn't include Ruby either. Never learned it, don't (as yet) know what its advantage domain is. My list "runs somewhat thus": BASIC, 80x86 Assembly, C, C++, Java, REXX, Pascal, Pike, Perl, PHP, Javascript, DeScribe Macro Language, Scheme, Python, ActionScript, DOS Batch, Lua, COBOL, FORTRAN, Ada, Modula-2, LPC, Erlang, Haskell... and that's not counting things like POV-Ray or LilyPond that aren't exactly _programming_ languages, although in some cases you could shoehorn an application into them. Granted, I do have some rather strange and esoteric interests, and I'm sure that Ruby is far better known than DeScribe Macro Language (!!), but I think first of those I've used, and then of the most famous. Sorry Ruby. No slight meant! :) ChrisA From showell30 at yahoo.com Fri Mar 23 03:45:40 2012 From: showell30 at yahoo.com (Steve Howell) Date: Fri, 23 Mar 2012 00:45:40 -0700 (PDT) Subject: Number of languages known [was Re: Python is readable] - somewhat OT References: <4f6bcdd5$0$29981$c3e8da3$5496439d@news.astraweb.com> Message-ID: <8c9d9aa3-d584-4c2b-8455-ec8239a9cf01@px4g2000pbc.googlegroups.com> On Mar 22, 6:11?pm, Steven D'Aprano wrote: > On Fri, 23 Mar 2012 06:14:46 +1100, Chris Angelico wrote: > > On Fri, Mar 23, 2012 at 4:44 AM, Steven D'Aprano > > wrote: > >> The typical developer knows three, maybe four languages moderately > >> well, if you include SQL and regexes as languages, and might have a > >> nodding acquaintance with one or two more. > > > I'm not entirely sure what you mean by "moderately well", > > I mean more than "poorly" but less than "very well". > > Until somebody invents a universal, objective scale for rating relative > knowledge in a problem domain (in this case, knowledge of a programming > language), we're stuck with fuzzy quantities like "guru", "expert", "deep > and complete knowledge of the language and its idioms", all the way down > to "can write Hello World" and "never used or seen the language before". > > Here's a joke version: > > http://www.ariel.com.au/jokes/The_Evolution_of_a_Programmer.html > > and here's a more serious version: > > http://www.yacoset.com/Home/signs-that-you-re-a-bad-programmer > > > nor > > "languages", but I'm of the opinion that a good developer should be able > > to learn a new language very efficiently. > > Should be, absolutely. Does, perhaps not. Some good developers spend > their entire life working in one language and have become expert on every > part of it. Some learn twenty different languages, and barely get beyond > "Hello World" in any of them. > > > Do you count Python 2 and 3 as the same language? > > Absolutely. > > > What about all the versions of the C standard? > > Probably. I'm not familiar with the C standard. > > > In any case, though, I agree that there's a lot of people professionally > > writing code who would know about the 3-4 that you say. I'm just not > > sure that they're any good at coding, even in those few languages. All > > the best people I've ever known have had experience with quite a lot of > > languages. > > I dare say that experience with many languages is a good thing, but it's > not a prerequisite for mastery of a single language. I agree. It's certainly true for spoken languages. The only programming language that I ever learned without experience in other languages was BASIC (because only one language can be our first). I believe I mastered BASIC, not that that is saying a whole lot. > In any case, I'm not talking about the best developers. I'm talking about > the typical developer, who by definition is just average. They probably > know reasonably well one to three of the half dozen most popular > languages (VB, Java, C, C+, Javascript, PHP, Perl?) plus regexes and SQL, > and are unlikely to know any of Prolog, Lisp, Haskell, Hypertalk, > Mercury, Cobra, Smalltalk, Ada, APL, Emerald, Inform, Forth, ... > VB, Java, C, C++, JS, PHP, and Perl are all 20th century languages FWIW. PHP, Java, and JS all emerged circa 1995 (17 years ago); C, C+ +, and VB are even older. (And so is Python.) A future version of Python itself, or some language largely inspired by Python (CoffeeScript 3.0 maybe?), will eventually squeeze out Perl, PHP, and JS in the popularity contests. At least I'm crossing my fingers. VB will die with no obvious successors. C++ was never very distinct from C to begin with, and the two languages will eventually converge, die off, or be supplanted. In ten years we'll basically have only three 20th-century-ish languages in the top ten: Python', C', and Java'. The rest of the top ten most popular languages will be something truly 21st-century. They'll be languages that either haven't been invented yet or modernized derivatives of languages that we view as "fringe" today (Lisp'/Haskell'/etc.). From showell30 at yahoo.com Fri Mar 23 04:04:06 2012 From: showell30 at yahoo.com (Steve Howell) Date: Fri, 23 Mar 2012 01:04:06 -0700 (PDT) Subject: Number of languages known [was Re: Python is readable] - somewhat OT References: <4f6bcdd5$0$29981$c3e8da3$5496439d@news.astraweb.com> Message-ID: <8694a85d-fe94-4bef-8bb6-8a8241d14ca3@px4g2000pbc.googlegroups.com> On Mar 23, 12:05?am, Chris Angelico wrote: > On Fri, Mar 23, 2012 at 1:48 PM, Steve Howell wrote: > > On Mar 22, 6:11?pm, Steven D'Aprano > +comp.lang.pyt... at pearwood.info> wrote: > >> In any case, I'm not talking about the best developers. I'm talking about > >> the typical developer, who by definition is just average. They probably > >> know reasonably well one to three of the half dozen most popular > >> languages (VB, Java, C, C+, Javascript, PHP, Perl?) plus regexes and SQL, > >> and are unlikely to know any of Prolog, Lisp, Haskell, Hypertalk, > >> Mercury, Cobra, Smalltalk, Ada, APL, Emerald, Inform, Forth, ... > > > I love how you can rattle off 20 or so languages, just off the top of > > your head, and not even mention Ruby. ;) > > If I were to rattle off a couple dozen languages, it probably wouldn't > include Ruby either. Never learned it, don't (as yet) know what its > advantage domain is. Hype? > My list "runs somewhat thus": BASIC, 80x86 > Assembly, C, C++, Java, REXX, Pascal, Pike, Perl, PHP, Javascript, > DeScribe Macro Language, Scheme, Python, ActionScript, DOS Batch, Lua, > COBOL, FORTRAN, Ada, Modula-2, LPC, Erlang, Haskell... and that's not > counting things like POV-Ray or LilyPond that aren't exactly > _programming_ languages, although in some cases you could shoehorn an > application into them. Granted, I do have some rather strange and > esoteric interests, and I'm sure that Ruby is far better known than > DeScribe Macro Language (!!), but I think first of those I've used, > and then of the most famous. > > Sorry Ruby. No slight meant! :) > If you're that adept at learning languages, then I recommend learning Ruby just for kicks, but you're not missing *that* much, trust me. I'd skip past Ruby and learn CoffeeScript. Of the languages that are in the scripting family, you already know REXX (supreme elegance for its time), Perl (I hate it now, but loved it before Python), PHP (truly easy to learn, you can never take that away from it), and Javascript (horrible syntax, awful platform, but at least they have first-class functions). You have the Assembly/C/C++/Java progression--definitely good stuff, even if the ending to the movie was a bit of a letdown. COBOL/Fortran/Ada gives you instance "old school" street cred. Haskell/Erlang/Scheme means you can hang out with the cool grad school kids in the CS/Math departments (no oxymoron intended). I confess--I've never learned LilyPond, Modula-2, or LPC! I mean, of course they're on my resume, just to get by HR screening, but that's just between you and me... From rosuav at gmail.com Fri Mar 23 04:24:13 2012 From: rosuav at gmail.com (Chris Angelico) Date: Fri, 23 Mar 2012 19:24:13 +1100 Subject: Number of languages known [was Re: Python is readable] - somewhat OT In-Reply-To: <8694a85d-fe94-4bef-8bb6-8a8241d14ca3@px4g2000pbc.googlegroups.com> References: <4f6bcdd5$0$29981$c3e8da3$5496439d@news.astraweb.com> <8694a85d-fe94-4bef-8bb6-8a8241d14ca3@px4g2000pbc.googlegroups.com> Message-ID: On Fri, Mar 23, 2012 at 7:04 PM, Steve Howell wrote: > If you're that adept at learning languages, then I recommend learning > Ruby just for kicks, but you're not missing *that* much, trust me. > I'd skip past Ruby and learn CoffeeScript. Sure. When I have some spare time... lessee, I think I have two spare minutes in the year 2015 that aren't allocated yet! Oops. There they go. > Of the languages that are in the scripting family, you already know > REXX (supreme elegance for its time), Perl (I hate it now, but loved > it before Python), PHP (truly easy to learn, you can never take that > away from it), and Javascript (horrible syntax, awful platform, but at > least they have first-class functions). > > You have the Assembly/C/C++/Java progression--definitely good stuff, > even if the ending to the movie was a bit of a letdown. +1 on the description, heh. > COBOL/Fortran/Ada gives you instance "old school" street cred. > > Haskell/Erlang/Scheme means you can hang out with the cool grad school > kids in the CS/Math departments (no oxymoron intended). Ehh, the ones from COBOL on were because I ran out of languages that I'm really familiar with, and enumerated a few famous ones. But the rest, I do actually know, and that's why I thought of them. > I confess--I've never learned LilyPond, Modula-2, or LPC! ?I mean, of > course they're on my resume, just to get by HR screening, but that's > just between you and me... GNU LilyPond is a music publishing language (it's to music what TeX is to English, kinda). Awesome language and system. I can show you a few pieces I've done with Ly, it's beautiful music score from a very clean input file. Modula-2 is a Pascal-derived language that I haven't actually used, but it's cited as an influence in the development of several others that I have used. LPC is Lars Somebody's C, originally written as the basis for Lars Somebody's MUD or LPMUD, and was the basis for Pike (with which I'm very familiar, as readers of this list probably know). Half the above languages aren't on my resume, mainly because I don't really care about HR screening :) ChrisA From nutznetz-0c1b6768-bfa9-48d5-a470-7603bd3aa915 at spamschutz.glglgl.de Fri Mar 23 05:56:35 2012 From: nutznetz-0c1b6768-bfa9-48d5-a470-7603bd3aa915 at spamschutz.glglgl.de (Thomas Rachel) Date: Fri, 23 Mar 2012 10:56:35 +0100 Subject: contextlib.nested deprecated Message-ID: Hi, I understand why contextlib.nested is deprecated. But if I write a program for an old python version w/o the multiple form of with, I have (nearly) no other choice. In order to avoid the following construct to fail: with nested(open("f1"), open("f2")) as (f1, f2): (f1 wouldn't be closed if opening f2 fails) I could imagine writing a context manager which moves initialization into its __enter__: @contextmanager def late_init(f, *a, **k): r = f(*a, **k) with r as c: yield c Am I right thinking that with nested(late_init(open, "f1"), late_init(open, "f2")) as (f1, f2): will suffice here to make it "clean"? TIA, Thomas From slehar at gmail.com Fri Mar 23 07:00:13 2012 From: slehar at gmail.com (Steven Lehar) Date: Fri, 23 Mar 2012 07:00:13 -0400 Subject: Python is readable Message-ID: Reply to Steve Howell >>> Do you think we'll always have a huge number of incompatible programming languages? I agree with you that it's a fact of life in 2012, but will it be a fact of life in 2062? <<< We can only HOPE so! When I first learned unix / sh / csh / tcsh / bash ...etc... it irked me no end that there was so much variation and inconsistency, and I couldn't wait for some kind of standard to finally emerge. But now I realize in hindsight that what I was seeing was evolution in action! Software evolves much like life, in a healthy ecosystem there are a million variations, and nobody knows in advance which ones will succeed and which will fail. And so it is with programming languages, we should all be happy that we live in an environment so rich with competing ideas and ideologies, look at all the fun we are having just discussing all the possibilities! Compared to my first computer experience on Digitals DCL (Digital Command Language) that had the same syntax and command-line arguments for every command defined in DEC, as if the product of a Master Designer, it was beautiful consistency and easy to learn, but it only allowed three levels of directories, and one-size-fits-all for everyone. I loved it then, but now I see that was like life in a medieval monastery. Vive la difference! -------------- next part -------------- An HTML attachment was scrubbed... URL: From alec.taylor6 at gmail.com Fri Mar 23 07:09:22 2012 From: alec.taylor6 at gmail.com (Alec Taylor) Date: Fri, 23 Mar 2012 22:09:22 +1100 Subject: Templated rich-text egg Message-ID: Good morning, We've all seen document templates in a variety of systems, such as PowerPoint, MailChimp and Google Docs. I would like to utilise the same sorts of capabilities on my website. The following features I require: ? Create a library of document templates ? Allow others to pick a document template to create there document from ? Allow others to swap the template their document has without losing data ? Document authoring in rich-text (e.g. using CKEditor) (I will probably end up using a full CMS such as Mezzanine around the whole system.) Please suggest modules allowing me to do the aforementioned. Thanks for all recommendations, Alec Taylor From mrsangeet at gmail.com Fri Mar 23 08:59:35 2012 From: mrsangeet at gmail.com (Sangeet) Date: Fri, 23 Mar 2012 05:59:35 -0700 (PDT) Subject: Accessing the files by last modified time In-Reply-To: <8cbfb1b2-94ed-4830-90fa-976a831ebb97@l14g2000vbe.googlegroups.com> References: <26215939.1574.1332416026298.JavaMail.geo-discussion-forums@ynlt17> <8cbfb1b2-94ed-4830-90fa-976a831ebb97@l14g2000vbe.googlegroups.com> Message-ID: <23086952.178.1332507576146.JavaMail.geo-discussion-forums@ynes7> On Thursday, 22 March 2012 17:34:43 UTC+5:30, Tim Williams wrote: > On Mar 22, 7:33?am, Sangeet wrote: > > Hi > > > > I am new to the python programming language. > > > > I've been trying to write a script that would access the last modified file in one of my directories. I'm using Win XP. > > > > I saw a similar topic, on the forum before, however the reply using (os.popen) didn't work out for me. I'm not sure whether it was due to syntax errors either. > > > > Thanks, > > Sangeet > > Check out os.stat() Hey, thanks I tried playing around with this. I haven't got what I exactly wanted, but on the way there for sure! :) Sangeet From mrsangeet at gmail.com Fri Mar 23 09:00:25 2012 From: mrsangeet at gmail.com (Sangeet) Date: Fri, 23 Mar 2012 06:00:25 -0700 (PDT) Subject: Accessing the files by last modified time In-Reply-To: References: <26215939.1574.1332416026298.JavaMail.geo-discussion-forums@ynlt17> Message-ID: <28803503.136.1332507625424.JavaMail.geo-discussion-forums@ynjk1> On Thursday, 22 March 2012 17:19:23 UTC+5:30, Chris Rebert wrote: > On Thu, Mar 22, 2012 at 4:33 AM, Sangeet wrote: > > Hi > > > > I am new to the python programming language. > > > > I've been trying to write a script that would access the last modified file in one of my directories. I'm using Win XP. > > > > I saw a similar topic, on the forum before, however the reply using (os.popen) didn't work out for me. I'm not sure whether it was due to syntax errors either. > > Recursively or non-recursively? > Live monitoring or just one-time? > What was the forum post in question? > > In the simple case, you just need to stitch together these functions: > http://docs.python.org/library/os.html#os.stat > (note the .st_mtime attribute of the result) > http://docs.python.org/library/os.path.html#os.path.join > with one of these functions: > http://docs.python.org/library/os.html#os.listdir > http://docs.python.org/library/os.html#os.walk > > Cheers, > Chris Thanks Chris, this helped me a lot! From mrsangeet at gmail.com Fri Mar 23 09:00:25 2012 From: mrsangeet at gmail.com (Sangeet) Date: Fri, 23 Mar 2012 06:00:25 -0700 (PDT) Subject: Accessing the files by last modified time In-Reply-To: References: <26215939.1574.1332416026298.JavaMail.geo-discussion-forums@ynlt17> Message-ID: <28803503.136.1332507625424.JavaMail.geo-discussion-forums@ynjk1> On Thursday, 22 March 2012 17:19:23 UTC+5:30, Chris Rebert wrote: > On Thu, Mar 22, 2012 at 4:33 AM, Sangeet wrote: > > Hi > > > > I am new to the python programming language. > > > > I've been trying to write a script that would access the last modified file in one of my directories. I'm using Win XP. > > > > I saw a similar topic, on the forum before, however the reply using (os.popen) didn't work out for me. I'm not sure whether it was due to syntax errors either. > > Recursively or non-recursively? > Live monitoring or just one-time? > What was the forum post in question? > > In the simple case, you just need to stitch together these functions: > http://docs.python.org/library/os.html#os.stat > (note the .st_mtime attribute of the result) > http://docs.python.org/library/os.path.html#os.path.join > with one of these functions: > http://docs.python.org/library/os.html#os.listdir > http://docs.python.org/library/os.html#os.walk > > Cheers, > Chris Thanks Chris, this helped me a lot! From mrsangeet at gmail.com Fri Mar 23 09:52:05 2012 From: mrsangeet at gmail.com (Sangeet) Date: Fri, 23 Mar 2012 06:52:05 -0700 (PDT) Subject: Fetching data from a HTML file Message-ID: <9362386.1094.1332510725414.JavaMail.geo-discussion-forums@ynlt15> Hi, I've got to fetch data from the snippet below and have been trying to match the digits in this to specifically to specific groups. But I can't seem to figure how to go about stripping the tags! :( Sum2451102561.496 [min] Actually, I'm working on ROBOT Framework, and haven't been able to figure out how to read data from HTML tables. Reading from the source, is the best (read rudimentary) way I could come up with. Any suggestions are welcome! Thanks, Sangeet From simonyan at fedoraproject.org Fri Mar 23 10:08:51 2012 From: simonyan at fedoraproject.org (Simon Yan) Date: Fri, 23 Mar 2012 22:08:51 +0800 Subject: Fetching data from a HTML file In-Reply-To: <9362386.1094.1332510725414.JavaMail.geo-discussion-forums@ynlt15> References: <9362386.1094.1332510725414.JavaMail.geo-discussion-forums@ynlt15> Message-ID: On Fri, Mar 23, 2012 at 9:52 PM, Sangeet wrote: > Hi, > > I've got to fetch data from the snippet below and have been trying to > match the digits in this to specifically to specific groups. But I can't > seem to figure how to go about stripping the tags! :( > > Sum class="green">24511 align='center'>02561.496 > [min] > > > Actually, I'm working on ROBOT Framework, and haven't been able to figure > out how to read data from HTML tables. Reading from the source, is the best > (read rudimentary) way I could come up with. Any suggestions are welcome! > Sangeet, I think Python comes with its own HTML parser. Can you have a look at this http://docs.python.org/library/htmlparser.html and see if it helps? > > Thanks, > Sangeet > -- > http://mail.python.org/mailman/listinfo/python-list > -- Regards, YeeYaa (Simon Yan) http://simonyan.fedorapeople.org/ -------------- next part -------------- An HTML attachment was scrubbed... URL: From jeanmichel at sequans.com Fri Mar 23 10:19:55 2012 From: jeanmichel at sequans.com (Jean-Michel Pichavant) Date: Fri, 23 Mar 2012 15:19:55 +0100 Subject: Python classes: Simplify? In-Reply-To: References: Message-ID: <4F6C868B.3030903@sequans.com> Steven Lehar wrote: > It seems to me that the Python class system is needlessly confusing. > Am I missing something? > > For example in the class Complex given in the documentation > > *class Complex:* > * def __init__(self, realpart, imagpart):* > * self.r = realpart* > * self.i = imagpart* > * > * > *x = Complex(3.0, -4.5)* > > I initially found it profoundly confusing that __init__( ) calls for 3 > arguments, but you call Complex( ) with 2. Furthermore, why not call > the initialization function after the class name as is done in other > languages? Isn't that the simplest conceptually? Demonstrating with > the above example: > In python, writting obj.method() will be translated into method(obj) so any instance method has a #arg + 1 arguments, something you'll get familiar with. Furthermore, Complex(3.0, -4.5) invokes 2 functions : __new__ and __init__. __new__ is the "constructor", this is the function that returns an instance. __init__ is an initializer, at the time it's called the instance already exists and is viable. > *class Complex:* > * def Complex(realpart, imagpart):* > * Complex.r = realpart* > * Complex.i = imagpart* > * > * > *x = Complex(3.0, -4.5)* > * > * > Is there a good reason why classes cannot be defined that way? > (Besides the problem of backward-compatibility) > Python uses a different data model, it is a very good idea to mark theses differences using an explicit distinct syntax so that people won't jump into false conclusions like "it's like C or Java". It is not. JM JM From nathan.alexander.rice at gmail.com Fri Mar 23 10:27:22 2012 From: nathan.alexander.rice at gmail.com (Nathan Rice) Date: Fri, 23 Mar 2012 10:27:22 -0400 Subject: Number of languages known [was Re: Python is readable] - somewhat OT In-Reply-To: References: <4f6bcdd5$0$29981$c3e8da3$5496439d@news.astraweb.com> <8694a85d-fe94-4bef-8bb6-8a8241d14ca3@px4g2000pbc.googlegroups.com> Message-ID: Logo. It's turtles all the way down. From slehar at gmail.com Fri Mar 23 10:41:51 2012 From: slehar at gmail.com (Steven Lehar) Date: Fri, 23 Mar 2012 10:41:51 -0400 Subject: Python classes: Simplify? In-Reply-To: <4F6C868B.3030903@sequans.com> References: <4F6C868B.3030903@sequans.com> Message-ID: Many thanks to all who responded to my "Python Classes: Simplify?" thread. There seem to be several good reasons for this particular syntactical choice, I am all the wiser for your kind explanations. My faith in the simplicity and elegance of this beautiful language is reinforced. Thanks all! -------------- next part -------------- An HTML attachment was scrubbed... URL: From ramit.prasad at jpmorgan.com Fri Mar 23 11:08:03 2012 From: ramit.prasad at jpmorgan.com (Prasad, Ramit) Date: Fri, 23 Mar 2012 15:08:03 +0000 Subject: Fetching data from a HTML file In-Reply-To: <9362386.1094.1332510725414.JavaMail.geo-discussion-forums@ynlt15> References: <9362386.1094.1332510725414.JavaMail.geo-discussion-forums@ynlt15> Message-ID: <5B80DD153D7D744689F57F4FB69AF474026C7EAC@SCACMX008.exchad.jpmchase.net> > Actually, I'm working on ROBOT Framework, and haven't been able to figure > out how to read data from HTML tables. Reading from the source, is the best > (read rudimentary) way I could come up with. Any suggestions are welcome! > I've got to fetch data from the snippet below and have been trying to match > the digits in this to specifically to specific groups. But I can't seem to > figure how to go about stripping the tags! :( In addition to Simon's response. You may want to look at Beautiful Soup which I hear is good at dealing with malformed HTML. http://www.crummy.com/software/BeautifulSoup/ Ramit Ramit Prasad | JPMorgan Chase Investment Bank | Currencies Technology 712 Main Street | Houston, TX 77002 work phone: 713 - 216 - 5423 -- This email is confidential and subject to important disclaimers and conditions including on offers for the purchase or sale of securities, accuracy and completeness of information, viruses, confidentiality, legal privilege, and legal entity disclaimers, available at http://www.jpmorgan.com/pages/disclosures/email. From ramit.prasad at jpmorgan.com Fri Mar 23 11:15:01 2012 From: ramit.prasad at jpmorgan.com (Prasad, Ramit) Date: Fri, 23 Mar 2012 15:15:01 +0000 Subject: Number of languages known [was Re: Python is readable] - somewhat OT In-Reply-To: <8694a85d-fe94-4bef-8bb6-8a8241d14ca3@px4g2000pbc.googlegroups.com> References: <4f6bcdd5$0$29981$c3e8da3$5496439d@news.astraweb.com> <8694a85d-fe94-4bef-8bb6-8a8241d14ca3@px4g2000pbc.googlegroups.com> Message-ID: <5B80DD153D7D744689F57F4FB69AF474026C7EE9@SCACMX008.exchad.jpmchase.net> > I confess--I've never learned LilyPond, Modula-2, or LPC! I mean, of > course they're on my resume, just to get by HR screening, but that's > just between you and me... You mean, you, him, this mailing list, and anyone that looks on the archives... Ramit Ramit Prasad | JPMorgan Chase Investment Bank | Currencies Technology 712 Main Street | Houston, TX 77002 work phone: 713 - 216 - 5423 -- This email is confidential and subject to important disclaimers and conditions including on offers for the purchase or sale of securities, accuracy and completeness of information, viruses, confidentiality, legal privilege, and legal entity disclaimers, available at http://www.jpmorgan.com/pages/disclosures/email. From ramit.prasad at jpmorgan.com Fri Mar 23 11:16:29 2012 From: ramit.prasad at jpmorgan.com (Prasad, Ramit) Date: Fri, 23 Mar 2012 15:16:29 +0000 Subject: Number of languages known [was Re: Python is readable] - somewhat OT In-Reply-To: References: <4f6bcdd5$0$29981$c3e8da3$5496439d@news.astraweb.com> <8694a85d-fe94-4bef-8bb6-8a8241d14ca3@px4g2000pbc.googlegroups.com> Message-ID: <5B80DD153D7D744689F57F4FB69AF474026C7F02@SCACMX008.exchad.jpmchase.net> > Logo. It's turtles all the way down. I had forgotten all about that, I should add that to my resume! I wonder what kind of job I could get writing primarily in Logo? Ramit Ramit Prasad | JPMorgan Chase Investment Bank | Currencies Technology 712 Main Street | Houston, TX 77002 work phone: 713 - 216 - 5423 -- This email is confidential and subject to important disclaimers and conditions including on offers for the purchase or sale of securities, accuracy and completeness of information, viruses, confidentiality, legal privilege, and legal entity disclaimers, available at http://www.jpmorgan.com/pages/disclosures/email. From fetchinson at googlemail.com Fri Mar 23 11:28:56 2012 From: fetchinson at googlemail.com (Daniel Fetchinson) Date: Fri, 23 Mar 2012 16:28:56 +0100 Subject: Fetching data from a HTML file In-Reply-To: <9362386.1094.1332510725414.JavaMail.geo-discussion-forums@ynlt15> References: <9362386.1094.1332510725414.JavaMail.geo-discussion-forums@ynlt15> Message-ID: On 3/23/12, Sangeet wrote: > Hi, > > I've got to fetch data from the snippet below and have been trying to match > the digits in this to specifically to specific groups. But I can't seem to > figure how to go about stripping the tags! :( > > Sum class="green">24511 align='center'>02561.496 > [min] > Try beautiful soup: http://www.crummy.com/software/BeautifulSoup/ > Actually, I'm working on ROBOT Framework, and haven't been able to figure > out how to read data from HTML tables. Reading from the source, is the best > (read rudimentary) way I could come up with. Any suggestions are welcome! > > Thanks, > Sangeet > -- > http://mail.python.org/mailman/listinfo/python-list > -- Psss, psss, put it down! - http://www.cafepress.com/putitdown From kiuhnm03.4t.yahoo.it Fri Mar 23 12:00:23 2012 From: kiuhnm03.4t.yahoo.it (Kiuhnm) Date: Fri, 23 Mar 2012 17:00:23 +0100 Subject: Stream programming Message-ID: <4f6c9e17$0$1383$4fafbaef@reader2.news.tin.it> I've been writing a little library for handling streams as an excuse for doing a little OOP with Python. I don't share some of the views on readability expressed on this ng. Indeed, I believe that a piece of code may very well start as complete gibberish and become a pleasure to read after some additional information is provided. I must say that imposed indentation is a pain when one is trying to define some sort of DSL (domain specific language). Also, Python's operator overloading is a bit limited, but that makes for a more rewarding experience in my case. Here's an example of what you can write: numbers - push - avrg - 'med' - pop - filter(lt('med'), ge('med'))\ - ['same', 'same'] - streams(cat) - 'same' Ok, we're at the "complete gibberish" phase. Time to give you the "additional information". I will use "<=>" to mean "is equivalent to". That's not part of the DSL. A flow has one or more streams: 1 stream: [1,2,3] 2 streams: [1,3,5] | [2,4,6] Two flows can be concatenated: [1,2,3] + [4,5,6] <=> [1,2,3,4,5,6] [0] + ([1,2] | [3,4]) + [10] <=> [0,1,2,10] | [0,3,4,10] ([1,2] | [10,20]) + ([3,4] | [30,40]) <=> [1,2,3,4] | [10,20,30,40] A flow can be transformed: [1,2] - f <=> [f(1),f(2)] ([1,2] | [3,4]) - f <=> [f(1,3),f(2,4)] ([1,2] | [3,4]) - [f] <=> [f(1),f(2)] | [f(3),f(4)] ([1,2] | [3,4]) - [f,g] <=> [f(1),f(2)] | [g(3),g(4)] [1,2] - [f,g] <=> [f(1),f(2)] | [g(1),g(2)] Some functions are special and almost any function can be made special: [1,2,3,4,5] - filter(isprime) <=> [2,3,5] [[],(1,2),[3,4,5]] - flatten <=> [1,2,3,4,5] Note that 'filter' is not really necessary, thanks to 'flatten'. Flows can be named, remembered and used as a value: [1,2,3,4,5] - 'flow' + val('flow') <=> [1,2,3,4,5]*2 as a transformation chain: [1,2,3] - skipfirst - 'again' | [4,5,6] - func('again') <=> [2,3] | [5,6] Recursion is also possible and stops when a function is applied to an empty sequence. Flows can be saved (push) and restored (pop) : [1,2,3,4] - push - by(2) - 'double' - pop | val('double') <=> [1,2,3,4] | [2,4,6,8] There are easier ways to achieve the same result, of course: [1,2,3,4] - [id, by(2)] Let's go back to our example. I didn't tell you anything but you should be able to understand it anyway. numbers - push - avrg - 'med' - pop - filter(lt('med'), ge('med'))\ - ['same', 'same'] - streams(cat) - 'same' It reads as "take a list of numbers - save it - compute the average and named it 'med' - restore the flow - create two streams which have, respect., the numbers less than 'med' and those greater or equal to 'med' - do the /entire/ 'same' process on each one of the two streams - concat the resulting streams - name all this /entire/ process 'same'. Not readable enough? Replace 'same' with 'qsort'. Is that readable or am I going crazy? [note: that's a rhetorical question whose answer is "That's very readable!"] Kiuhnm From kiuhnm03.4t.yahoo.it Fri Mar 23 12:02:43 2012 From: kiuhnm03.4t.yahoo.it (Kiuhnm) Date: Fri, 23 Mar 2012 17:02:43 +0100 Subject: Stream programming In-Reply-To: <4f6c9e17$0$1383$4fafbaef@reader2.news.tin.it> References: <4f6c9e17$0$1383$4fafbaef@reader2.news.tin.it> Message-ID: <4f6c9ea3$0$1383$4fafbaef@reader2.news.tin.it> On 3/23/2012 17:00, Kiuhnm wrote: > I've been writing a little library for handling streams as an excuse for > doing a little OOP with Python. > > I don't share some of the views on readability expressed on this ng. > Indeed, I believe that a piece of code may very well start as complete > gibberish and become a pleasure to read after some additional > information is provided. > > I must say that imposed indentation is a pain when one is trying to > define some sort of DSL (domain specific language). Also, Python's > operator overloading is a bit limited, but that makes for a more > rewarding experience in my case. > > Here's an example of what you can write: > > numbers - push - avrg - 'med' - pop - filter(lt('med'), ge('med'))\ > - ['same', 'same'] - streams(cat) - 'same' > > Ok, we're at the "complete gibberish" phase. > > Time to give you the "additional information". > > I will use "<=>" to mean "is equivalent to". That's not part of the DSL. > A flow has one or more streams: > 1 stream: > [1,2,3] > 2 streams: > [1,3,5] | [2,4,6] > Two flows can be concatenated: > [1,2,3] + [4,5,6] <=> [1,2,3,4,5,6] > [0] + ([1,2] | [3,4]) + [10] <=> [0,1,2,10] | [0,3,4,10] > ([1,2] | [10,20]) + ([3,4] | [30,40]) <=> [1,2,3,4] | [10,20,30,40] > A flow can be transformed: > [1,2] - f <=> [f(1),f(2)] > ([1,2] | [3,4]) - f <=> [f(1,3),f(2,4)] > ([1,2] | [3,4]) - [f] <=> [f(1),f(2)] | [f(3),f(4)] > ([1,2] | [3,4]) - [f,g] <=> [f(1),f(2)] | [g(3),g(4)] > [1,2] - [f,g] <=> [f(1),f(2)] | [g(1),g(2)] > Some functions are special and almost any function can be made special: > [1,2,3,4,5] - filter(isprime) <=> [2,3,5] > [[],(1,2),[3,4,5]] - flatten <=> [1,2,3,4,5] > Note that 'filter' is not really necessary, thanks to 'flatten'. > Flows can be named, remembered and used > as a value: > [1,2,3,4,5] - 'flow' + val('flow') <=> [1,2,3,4,5]*2 > as a transformation chain: > [1,2,3] - skipfirst - 'again' | [4,5,6] - func('again') > <=> [2,3] | [5,6] > Recursion is also possible and stops when a function is applied to an > empty sequence. > Flows can be saved (push) and restored (pop) : > [1,2,3,4] - push - by(2) - 'double' - pop | val('double') > <=> [1,2,3,4] | [2,4,6,8] > There are easier ways to achieve the same result, of course: > [1,2,3,4] - [id, by(2)] > > Let's go back to our example. I didn't tell you anything but you should Ops... *everything*. Kiuhnm From yoursurrogategod at gmail.com Fri Mar 23 12:14:14 2012 From: yoursurrogategod at gmail.com (Yves S. Garret) Date: Fri, 23 Mar 2012 09:14:14 -0700 (PDT) Subject: Good web-development Python book Message-ID: Hello, I'm trying to brush up on my Python and would like to From yoursurrogategod at gmail.com Fri Mar 23 12:16:15 2012 From: yoursurrogategod at gmail.com (Yves S. Garret) Date: Fri, 23 Mar 2012 09:16:15 -0700 (PDT) Subject: Good web-development Python book Message-ID: <14efe443-2f0c-4b6f-a5be-f1e33288038a@eb6g2000vbb.googlegroups.com> Oooops! Sent my previous e-mail too soon! Didn't mean to. Another try. Hello, I'm trying to brush up on my Python and would like to learn how to make web-apps. I was hoping to get a good book on learning how to make web-applications using Python (as opposed to something like PHP) without any framework at the moment. Do you guys have any suggestions? I looked around on Amazon, but didn't really find anything too promising. It was either very old or had no more than 3 stars in a rating. I'd appreciate your help on this. From ethan at stoneleaf.us Fri Mar 23 12:23:55 2012 From: ethan at stoneleaf.us (Ethan Furman) Date: Fri, 23 Mar 2012 09:23:55 -0700 Subject: Number of languages known [was Re: Python is readable] - somewhat OT In-Reply-To: References: <4f6bcdd5$0$29981$c3e8da3$5496439d@news.astraweb.com> <8694a85d-fe94-4bef-8bb6-8a8241d14ca3@px4g2000pbc.googlegroups.com> Message-ID: <4F6CA39B.9090709@stoneleaf.us> Nathan Rice wrote: > Logo. It's turtles all the way down. +1 QOTW From clp2 at rebertia.com Fri Mar 23 12:30:24 2012 From: clp2 at rebertia.com (Chris Rebert) Date: Fri, 23 Mar 2012 09:30:24 -0700 Subject: Good web-development Python book In-Reply-To: <14efe443-2f0c-4b6f-a5be-f1e33288038a@eb6g2000vbb.googlegroups.com> References: <14efe443-2f0c-4b6f-a5be-f1e33288038a@eb6g2000vbb.googlegroups.com> Message-ID: On Fri, Mar 23, 2012 at 9:16 AM, Yves S. Garret wrote: > Oooops! ?Sent my previous e-mail too soon! ?Didn't mean to. > > Another try. > > Hello, > > ? I'm trying to brush up on my Python and would like to learn how to > make web-apps. ?I was hoping to get a good book on learning how to > make web-applications using Python (as opposed to something like PHP) > without any framework at the moment. ?Do you guys have any > suggestions? > > ? I looked around on Amazon, but didn't really find anything too > promising. ?It was either very old or had no more than 3 stars in a > rating. ?I'd appreciate your help on this. The next edition of The Definitive Guide to Django, by the project's co-BDFLs, is available online (for now): http://www.djangobook.com/en/2.0/ It's not completely finished, but between it and the previous edition (http://www.djangobook.com/en/1.0/ , also free), you should be fine. Cheers, Chris From nathan.alexander.rice at gmail.com Fri Mar 23 12:33:35 2012 From: nathan.alexander.rice at gmail.com (Nathan Rice) Date: Fri, 23 Mar 2012 12:33:35 -0400 Subject: Stream programming In-Reply-To: <4f6c9e17$0$1383$4fafbaef@reader2.news.tin.it> References: <4f6c9e17$0$1383$4fafbaef@reader2.news.tin.it> Message-ID: > I will use "<=>" to mean "is equivalent to". That's not part of the DSL. > A flow has one or more streams: > ?1 stream: > ? ?[1,2,3] > ?2 streams: > ? ?[1,3,5] | [2,4,6] > Two flows can be concatenated: > ?[1,2,3] + [4,5,6] <=> [1,2,3,4,5,6] > ?[0] + ([1,2] | [3,4]) + [10] <=> [0,1,2,10] | [0,3,4,10] > ?([1,2] | [10,20]) + ([3,4] | [30,40]) <=> [1,2,3,4] | [10,20,30,40] Algebraically, your concatenation rules don't really make sense - your flows are both distributive and non distributive. You also make the implicit assumption of an order over streams in a flow, but disregard the implications of that assumption in some cases. I understand what you're trying to communicate, so I think you need to be a little more strict and explicit in your definitions. > A flow can be transformed: > ?[1,2] - f <=> [f(1),f(2)] > ?([1,2] | [3,4]) - f <=> [f(1,3),f(2,4)] > ?([1,2] | [3,4]) - [f] <=> [f(1),f(2)] | [f(3),f(4)] > ?([1,2] | [3,4]) - [f,g] <=> [f(1),f(2)] | [g(3),g(4)] > ?[1,2] - [f,g] <=> [f(1),f(2)] | [g(1),g(2)] Given the examples you pose here, it is clear that you are assuming that the streams are synchronized in discrete time. Since you do not provide any mechanism for temporal alignment of streams you are also assuming every stream will have an element at every time point, the streams start at the same time and are of the same length. Is this what you want? These seem like pretty rough simplifying assumptions. > Some functions are special and almost any function can be made special: > ?[1,2,3,4,5] - filter(isprime) <=> [2,3,5] > ?[[],(1,2),[3,4,5]] - flatten <=> [1,2,3,4,5] > Note that 'filter' is not really necessary, thanks to 'flatten'. This implies that your transformations again produce flows. You should explicitly state this. > Flows can be named, remembered and used > ?as a value: > ? ?[1,2,3,4,5] - 'flow' + val('flow') <=> [1,2,3,4,5]*2 Is this a flow with two identical streams, or a flow with one long stream formed by concatenation? > ?as a transformation chain: > ? ?[1,2,3] - skipfirst - 'again' | [4,5,6] - func('again') > ? ? ?<=> [2,3] | [5,6] > ?Recursion is also possible and stops when a function is applied to an empty > sequence. > Flows can be saved (push) and restored (pop) : > ?[1,2,3,4] - push - by(2) - 'double' - pop | val('double') > ? ? ?<=> [1,2,3,4] | [2,4,6,8] > There are easier ways to achieve the same result, of course: > ?[1,2,3,4] - [id, by(2)] You are grasping at an algebra here, a sort of calculus of temporal observations. You need to step back and make it rigorous before you worry about issues such as a readable syntax. Nathan From gstaniak at gmail.com Fri Mar 23 12:43:40 2012 From: gstaniak at gmail.com (Grzegorz Staniak) Date: Fri, 23 Mar 2012 16:43:40 +0000 (UTC) Subject: Data mining/pattern recogniton software in Python? Message-ID: Hello, I've been asked by a colleague for help in a small educational project, which would involve the recognition of patterns in a live feed of data points (readings from a measuring appliance), and then a more general search for patterns on archival data. The language of preference is Python, since the lab uses software written in Python already. I can see there are packages like Open CV, scikit-learn, Orange that could perhaps be of use for the mining phase -- and even if they are slanted towards image pattern recognition, I think I'd be able to find an appropriate package for the timeseries analyses. But I'm wondering about the "live" phase -- what approach would you suggest? I wouldn't want to force an open door, perhaps there are already packages/modules that could be used to read data in a loop i.e. every 10 seconds, maintain a a buffer of 15 readings and ring a bell when the data in buffer form a specific pattern (a spike, a trough, whatever)? I'll be grateful for a push in the right direction. Thanks, GS -- Grzegorz Staniak From nelle.varoquaux at gmail.com Fri Mar 23 13:01:42 2012 From: nelle.varoquaux at gmail.com (Nelle Varoquaux) Date: Fri, 23 Mar 2012 18:01:42 +0100 Subject: Data mining/pattern recogniton software in Python? In-Reply-To: References: Message-ID: Hello, There are two steps in using a supervised learning algorithm: fitting the classifier on data labeled, and predicting on new data. If you are looking to fit with incoming data, you are looking for online algorithms: algorithms that take chunks of data to fit the classifier on the fly. scikit-learn have a couple of algorithms that are online (k-means for example) If you are looking to predict with chunks of data, it can easily be done with any kind of already fitted classifier. Hence, you only need to find a way to retrieve the data. twisted may come in handy for that, or any other asynchronous framework. scikit-learn is not image oriented. You can do timeseries with it: there is probably already an example in the gallery. Hope that helped, N On 23 March 2012 17:43, Grzegorz Staniak wrote: > Hello, > > I've been asked by a colleague for help in a small educational > project, which would involve the recognition of patterns in a live > feed of data points (readings from a measuring appliance), and then > a more general search for patterns on archival data. The language > of preference is Python, since the lab uses software written in > Python already. I can see there are packages like Open CV, > scikit-learn, Orange that could perhaps be of use for the mining > phase -- and even if they are slanted towards image pattern > recognition, I think I'd be able to find an appropriate package > for the timeseries analyses. But I'm wondering about the "live" > phase -- what approach would you suggest? I wouldn't want to > force an open door, perhaps there are already packages/modules that > could be used to read data in a loop i.e. every 10 seconds, > maintain a a buffer of 15 readings and ring a bell when the data > in buffer form a specific pattern (a spike, a trough, whatever)? > > I'll be grateful for a push in the right direction. Thanks, > > GS > -- > Grzegorz Staniak > -- > http://mail.python.org/mailman/listinfo/python-list > -------------- next part -------------- An HTML attachment was scrubbed... URL: From clp2 at rebertia.com Fri Mar 23 13:16:23 2012 From: clp2 at rebertia.com (Chris Rebert) Date: Fri, 23 Mar 2012 10:16:23 -0700 Subject: Good web-development Python book In-Reply-To: References: <14efe443-2f0c-4b6f-a5be-f1e33288038a@eb6g2000vbb.googlegroups.com> Message-ID: On Fri, Mar 23, 2012 at 10:13 AM, Dennis Lee Bieber wrote: > On Fri, 23 Mar 2012 09:30:24 -0700, Chris Rebert > declaimed the following in gmane.comp.python.general: > >> On Fri, Mar 23, 2012 at 9:16 AM, Yves S. Garret >> wrote: > ? ? ? ? >> > make web-applications using Python (as opposed to something like PHP) >> > without any framework at the moment. ?Do you guys have any >> > suggestions? >> > >> >> The next edition of The Definitive Guide to Django, by the project's > > ? ? ? ?Note: the OP stated "without a framework"... To me that implies raw > Python from scratch... My bad, I completely overlooked that part of the post in my earnestness to answer? - Chris From ethan at stoneleaf.us Fri Mar 23 13:40:16 2012 From: ethan at stoneleaf.us (Ethan Furman) Date: Fri, 23 Mar 2012 10:40:16 -0700 Subject: Good web-development Python book In-Reply-To: References: <14efe443-2f0c-4b6f-a5be-f1e33288038a@eb6g2000vbb.googlegroups.com> Message-ID: <4F6CB580.5090505@stoneleaf.us> Chris Rebert wrote: > On Fri, Mar 23, 2012 at 10:13 AM, Dennis Lee Bieber wrote: >> On Fri, 23 Mar 2012 09:30:24 -0700, Chris Rebert >> declaimed the following in gmane.comp.python.general: >>> On Fri, Mar 23, 2012 at 9:16 AM, Yves S. Garret >>> ** wrote: >> >>>> make web-applications using Python (as opposed to something like PHP) >>>> without any framework at the moment. Do you guys have any >>>> suggestions? >>>> >>> The next edition of The Definitive Guide to Django, by the project's >> Note: the OP stated "without a framework"... To me that implies raw >> Python from scratch... > > My bad, I completely overlooked that part of the post in my > earnestness to answer? Completely understandable -- after all, who would not be earnest (and quick!) when replying to your surrogate god? ;) ~Ethan~ From colton.myers at gmail.com Fri Mar 23 13:56:04 2012 From: colton.myers at gmail.com (Colton Myers) Date: Fri, 23 Mar 2012 11:56:04 -0600 Subject: Good web-development Python book In-Reply-To: <14efe443-2f0c-4b6f-a5be-f1e33288038a@eb6g2000vbb.googlegroups.com> References: <14efe443-2f0c-4b6f-a5be-f1e33288038a@eb6g2000vbb.googlegroups.com> Message-ID: <9B84F99CE39D4B26986F6024377D1367@gmail.com> > Oooops! Sent my previous e-mail too soon! Didn't mean to. > > Another try. > > Hello, > > I'm trying to brush up on my Python and would like to learn how to > make web-apps. I was hoping to get a good book on learning how to > make web-applications using Python (as opposed to something like PHP) > without any framework at the moment. Do you guys have any > suggestions? > > I looked around on Amazon, but didn't really find anything too > promising. It was either very old or had no more than 3 stars in a > rating. I'd appreciate your help on this. > -- > http://mail.python.org/mailman/listinfo/python-list > > I'd suggest Programming Python as well. It has a whole section on "Internet Programming" which seems to be fairly agnostic as far as tools and frameworks go. http://www.amazon.com/Programming-Python-Mark-Lutz/dp/0596158106/ref=tmm_pap_title_0 -- Colton Myers (basepi) -------------- next part -------------- An HTML attachment was scrubbed... URL: From python at mrabarnett.plus.com Fri Mar 23 14:00:44 2012 From: python at mrabarnett.plus.com (MRAB) Date: Fri, 23 Mar 2012 18:00:44 +0000 Subject: Stream programming In-Reply-To: References: <4f6c9e17$0$1383$4fafbaef@reader2.news.tin.it> Message-ID: <4F6CBA4C.3020206@mrabarnett.plus.com> On 23/03/2012 16:33, Nathan Rice wrote: >> I will use "<=>" to mean "is equivalent to". That's not part of the DSL. >> A flow has one or more streams: >> 1 stream: >> [1,2,3] >> 2 streams: >> [1,3,5] | [2,4,6] >> Two flows can be concatenated: >> [1,2,3] + [4,5,6]<=> [1,2,3,4,5,6] >> [0] + ([1,2] | [3,4]) + [10]<=> [0,1,2,10] | [0,3,4,10] >> ([1,2] | [10,20]) + ([3,4] | [30,40])<=> [1,2,3,4] | [10,20,30,40] > > Algebraically, your concatenation rules don't really make sense - your > flows are both distributive and non distributive. You also make the > implicit assumption of an order over streams in a flow, but disregard > the implications of that assumption in some cases. I understand what > you're trying to communicate, so I think you need to be a little more > strict and explicit in your definitions. > When concatenating, either there are the same number of streams, or one of them is a single stream which is duplicated. Therefore, in this example: [0] + ([1, 2] | [3, 4]) you're concatenating a single stream with a pair, so the single stream is duplicated: ([0] | [0]) + ([1, 2] | [3, 4]) and then they can be concatenated: ([0, 1, 2] | [0, 3, 4]) However, this: ([0, 1] | [2, 3]) + ([4, 5] | [6, 7] | [8, 9]) won't work. From __peter__ at web.de Fri Mar 23 14:28:29 2012 From: __peter__ at web.de (Peter Otten) Date: Fri, 23 Mar 2012 19:28:29 +0100 Subject: Number of languages known [was Re: Python is readable] - somewhat OT References: <4f6bcdd5$0$29981$c3e8da3$5496439d@news.astraweb.com> <8694a85d-fe94-4bef-8bb6-8a8241d14ca3@px4g2000pbc.googlegroups.com> <4F6CA39B.9090709@stoneleaf.us> Message-ID: Ethan Furman wrote: > Nathan Rice wrote: >> Logo. It's turtles all the way down. > > +1 QOTW Surely you're joking, Mr Furman! From showell30 at yahoo.com Fri Mar 23 14:58:17 2012 From: showell30 at yahoo.com (Steve Howell) Date: Fri, 23 Mar 2012 11:58:17 -0700 (PDT) Subject: passing context into BaseHTTPRequestHandler Message-ID: I have a use case where I'm running BaseHTTPServer.HTTPServer, and I want to configure the request handler with some context. I've gotten the code to work, but it feels overly heavy. I am wondering if anybody could suggest an easier idiom for this. This is a brief sketch of the code: class MyHandler(BaseHTTPRequestHandler): def __init__(self, context, *args): self.context = context BaseHTTPRequestHandler.__init__(self, *args) def do_GET(self): // self.context will be available here context = { .... } def handler(*args): MyHandler(context, *args) server = HTTPServer(('', port), handler) server.serve_forever() Basically, it takes five lines of code just to pass context into the handler: def handler(*args): MyHandler(context, *args) def __init__(self, context, *args): self.context = context BaseHTTPRequestHandler.__init__(self, *args) Typically the second argument to HTTPServer is a subclass of BaseHTTPRequestHandler, but I pass in "handler" instead, which instantiates a new instance of MyHandler with the context from the enclosing scope. At first I tried to say "MyHandler(*args).context = context", but that assignment was too late, because BaseHTTPRequestHandler.__init__ does a lot of stuff during the construction phase. That's what forced me to write my own custom __init__ as well. I hope there's enough info here to understand what I'm trying to achieve, but if it helps to see my code in more context, you can see it here: https://gist.github.com/2173618 Thanks. From bh at intevation.de Fri Mar 23 15:19:22 2012 From: bh at intevation.de (Bernhard Herzog) Date: Fri, 23 Mar 2012 20:19:22 +0100 Subject: passing context into BaseHTTPRequestHandler References: Message-ID: Steve Howell writes: > I have a use case where I'm running BaseHTTPServer.HTTPServer, and I > want to configure the request handler with some context. I've gotten > the code to work, but it feels overly heavy. I am wondering if > anybody could suggest an easier idiom for this. > > This is a brief sketch of the code: > > class MyHandler(BaseHTTPRequestHandler): > def __init__(self, context, *args): > self.context = context > BaseHTTPRequestHandler.__init__(self, *args) > > def do_GET(self): > // self.context will be available here > > context = { .... } > def handler(*args): > MyHandler(context, *args) > > server = HTTPServer(('', port), handler) > server.serve_forever() You could store the context in the server object and access it in the handler methods via self.server.context. It basically works like this: class MyHTTPServer(HTTPServer): def __init__(self, *args, **kw): HTTPServer.__init__(self, *args, **kw) self.context = { .... } class MyHandler(BaseHTTPRequestHandler): def do_GET(self): context = self.server.context ... server = MyHTTPServer(('', port), MyHandler) server.serve_forever() Bernhard -- Bernhard Herzog | ++49-541-335 08 30 | http://www.intevation.de/ Intevation GmbH, Neuer Graben 17, 49074 Osnabr?ck | AG Osnabr?ck, HR B 18998 Gesch?ftsf?hrer: Frank Koormann, Bernhard Reiter, Dr. Jan-Oliver Wagner From nathan.alexander.rice at gmail.com Fri Mar 23 15:23:00 2012 From: nathan.alexander.rice at gmail.com (Nathan Rice) Date: Fri, 23 Mar 2012 15:23:00 -0400 Subject: Stream programming In-Reply-To: <4F6CBA4C.3020206@mrabarnett.plus.com> References: <4f6c9e17$0$1383$4fafbaef@reader2.news.tin.it> <4F6CBA4C.3020206@mrabarnett.plus.com> Message-ID: >>> ?I will use "<=>" to mean "is equivalent to". That's not part of the DSL. >>> ?A flow has one or more streams: >>> ? 1 stream: >>> ? ? [1,2,3] >>> ? 2 streams: >>> ? ? [1,3,5] | [2,4,6] >>> ?Two flows can be concatenated: >>> ? [1,2,3] + [4,5,6]<=> ?[1,2,3,4,5,6] >>> ? [0] + ([1,2] | [3,4]) + [10]<=> ?[0,1,2,10] | [0,3,4,10] >>> ? ([1,2] | [10,20]) + ([3,4] | [30,40])<=> ?[1,2,3,4] | [10,20,30,40] >> >> >> Algebraically, your concatenation rules don't really make sense - your >> flows are both distributive and non distributive. ?You also make the >> implicit assumption of an order over streams in a flow, but disregard >> the implications of that assumption in some cases. ?I understand what >> you're trying to communicate, so I think you need to be a little more >> strict and explicit in your definitions. >> > When concatenating, either there are the same number of streams, or one > of them is a single stream which is duplicated. > > Therefore, in this example: > > ? ?[0] + ([1, 2] | [3, 4]) > > you're concatenating a single stream with a pair, so the single stream > is duplicated: > > ? ?([0] | [0]) + ([1, 2] | [3, 4]) > > and then they can be concatenated: > > ? ?([0, 1, 2] | [0, 3, 4]) > > However, this: > > ? ?([0, 1] | [2, 3]) + ([4, 5] | [6, 7] | [8, 9]) > > won't work. I understand how he wants the system to work in this case; my point was that it isn't consistent. He stated flows can be concatenated, so [0] is just a flow of a single stream. Because he clearly intends that streams in a flow are ordered, that indicates that he wants some sort of algebraic module. He could get close if he can extend a stream to meet the requirements of a ring, then a flow would be a module over the ring of streams. The problem he is going to run into is that operations on streams as he defines them are not commutative. Identity elements for the two binary operations are also not immediately obvious to me. He could just be smart and use the pi calculus, it is rigorously developed and can model his desired behavior, if he reformulates it slightly. Another option is just to give up on being rigorous. Given the abstract treatment he attempted I would be disappointed, but if his only goal is to get practice writing code and he isn't interested in exploring the conceptual space of the problem domain it would be the right decision. From kiuhnm03.4t.yahoo.it Fri Mar 23 16:33:44 2012 From: kiuhnm03.4t.yahoo.it (Kiuhnm) Date: Fri, 23 Mar 2012 21:33:44 +0100 Subject: Stream programming In-Reply-To: References: <4f6c9e17$0$1383$4fafbaef@reader2.news.tin.it> Message-ID: <4f6cde28$0$1383$4fafbaef@reader1.news.tin.it> On 3/23/2012 17:33, Nathan Rice wrote: >> I will use "<=>" to mean "is equivalent to". That's not part of the DSL. >> A flow has one or more streams: >> 1 stream: >> [1,2,3] >> 2 streams: >> [1,3,5] | [2,4,6] >> Two flows can be concatenated: >> [1,2,3] + [4,5,6]<=> [1,2,3,4,5,6] >> [0] + ([1,2] | [3,4]) + [10]<=> [0,1,2,10] | [0,3,4,10] >> ([1,2] | [10,20]) + ([3,4] | [30,40])<=> [1,2,3,4] | [10,20,30,40] > > Algebraically, your concatenation rules don't really make sense - your > flows are both distributive and non distributive. ? > You also make the > implicit assumption of an order over streams in a flow, but disregard > the implications of that assumption in some cases. ? > I understand what > you're trying to communicate, so I think you need to be a little more > strict and explicit in your definitions. No, I don't think you understand what I meant. >> A flow can be transformed: >> [1,2] - f<=> [f(1),f(2)] >> ([1,2] | [3,4]) - f<=> [f(1,3),f(2,4)] >> ([1,2] | [3,4]) - [f]<=> [f(1),f(2)] | [f(3),f(4)] >> ([1,2] | [3,4]) - [f,g]<=> [f(1),f(2)] | [g(3),g(4)] >> [1,2] - [f,g]<=> [f(1),f(2)] | [g(1),g(2)] > > Given the examples you pose here, it is clear that you are assuming > that the streams are synchronized in discrete time. Since you do not > provide any mechanism for temporal alignment of streams you are also > assuming every stream will have an element at every time point, the > streams start at the same time and are of the same length. Is this > what you want? Yes. I thought that streams as an alternative to functional programming were widely known. >> Some functions are special and almost any function can be made special: >> [1,2,3,4,5] - filter(isprime)<=> [2,3,5] >> [[],(1,2),[3,4,5]] - flatten<=> [1,2,3,4,5] >> Note that 'filter' is not really necessary, thanks to 'flatten'. > > This implies that your transformations again produce flows. You > should explicitly state this. Isn't that obvious? BTW, those are not rigorous definitions. I thought I was talking to people who regularly works with streams. >> Flows can be named, remembered and used >> as a value: >> [1,2,3,4,5] - 'flow' + val('flow')<=> [1,2,3,4,5]*2 > > Is this a flow with two identical streams, or a flow with one long > stream formed by concatenation? What does [1,2,3,4,5]*2 mean in Python? Those are Python's lists/arrays. >> as a transformation chain: >> [1,2,3] - skipfirst - 'again' | [4,5,6] - func('again') >> <=> [2,3] | [5,6] >> Recursion is also possible and stops when a function is applied to an empty >> sequence. >> Flows can be saved (push) and restored (pop) : >> [1,2,3,4] - push - by(2) - 'double' - pop | val('double') >> <=> [1,2,3,4] | [2,4,6,8] >> There are easier ways to achieve the same result, of course: >> [1,2,3,4] - [id, by(2)] > > You are grasping at an algebra here, a sort of calculus of temporal > observations. You need to step back and make it rigorous before you > worry about issues such as a readable syntax. > > Nathan I don't agree. Sorry. Kiuhnm From kiuhnm03.4t.yahoo.it Fri Mar 23 16:44:27 2012 From: kiuhnm03.4t.yahoo.it (Kiuhnm) Date: Fri, 23 Mar 2012 21:44:27 +0100 Subject: Stream programming In-Reply-To: References: <4f6c9e17$0$1383$4fafbaef@reader2.news.tin.it> <4F6CBA4C.3020206@mrabarnett.plus.com> Message-ID: <4f6ce0ab$0$1384$4fafbaef@reader1.news.tin.it> On 3/23/2012 20:23, Nathan Rice wrote: >>>> I will use "<=>" to mean "is equivalent to". That's not part of the DSL. >>>> A flow has one or more streams: >>>> 1 stream: >>>> [1,2,3] >>>> 2 streams: >>>> [1,3,5] | [2,4,6] >>>> Two flows can be concatenated: >>>> [1,2,3] + [4,5,6]<=> [1,2,3,4,5,6] >>>> [0] + ([1,2] | [3,4]) + [10]<=> [0,1,2,10] | [0,3,4,10] >>>> ([1,2] | [10,20]) + ([3,4] | [30,40])<=> [1,2,3,4] | [10,20,30,40] >>> >>> >>> Algebraically, your concatenation rules don't really make sense - your >>> flows are both distributive and non distributive. You also make the >>> implicit assumption of an order over streams in a flow, but disregard >>> the implications of that assumption in some cases. I understand what >>> you're trying to communicate, so I think you need to be a little more >>> strict and explicit in your definitions. >>> >> When concatenating, either there are the same number of streams, or one >> of them is a single stream which is duplicated. >> >> Therefore, in this example: >> >> [0] + ([1, 2] | [3, 4]) >> >> you're concatenating a single stream with a pair, so the single stream >> is duplicated: >> >> ([0] | [0]) + ([1, 2] | [3, 4]) >> >> and then they can be concatenated: >> >> ([0, 1, 2] | [0, 3, 4]) >> >> However, this: >> >> ([0, 1] | [2, 3]) + ([4, 5] | [6, 7] | [8, 9]) >> >> won't work. > > I understand how he wants the system to work in this case; my point > was that it isn't consistent. > > He stated flows can be concatenated, so [0] is just a flow of a single > stream. Because he clearly intends that streams in a flow are > ordered, that indicates that he wants some sort of algebraic module. > He could get close if he can extend a stream to meet the requirements > of a ring, then a flow would be a module over the ring of streams. > The problem he is going to run into is that operations on streams as > he defines them are not commutative. Identity elements for the two > binary operations are also not immediately obvious to me. Instead of talking of what I wasn't trying to do and, indeed, I didn't do, you should try to understand what I wanted to do and, in fact, I did. I'm afraid your cup is too full to understand simple things as the one I wrote in my OP. Kiuhnm From ethan at stoneleaf.us Fri Mar 23 17:12:51 2012 From: ethan at stoneleaf.us (Ethan Furman) Date: Fri, 23 Mar 2012 14:12:51 -0700 Subject: Stream programming In-Reply-To: <4f6cde28$0$1383$4fafbaef@reader1.news.tin.it> References: <4f6c9e17$0$1383$4fafbaef@reader2.news.tin.it> <4f6cde28$0$1383$4fafbaef@reader1.news.tin.it> Message-ID: <4F6CE753.5080104@stoneleaf.us> Kiuhnm wrote: > On 3/23/2012 17:33, Nathan Rice wrote: >> Given the examples you pose here, it is clear that you are assuming >> that the streams are synchronized in discrete time. Since you do not >> provide any mechanism for temporal alignment of streams you are also >> assuming every stream will have an element at every time point, the >> streams start at the same time and are of the same length. Is this >> what you want? > > Yes. I thought that streams as an alternative to functional programming > were widely known. Don't know about widely, but I can say I am unfamiliar with the way you are using them. >> This implies that your transformations again produce flows. You >> should explicitly state this. > > Isn't that obvious? BTW, those are not rigorous definitions. I thought I > was talking to people who regularly works with streams. Why would you think that? This list is composed of all types that use Python. I've seen occasional discussion of functional programming, but I've only seen anything this confusing maybe twice before... granted, I don't read *everything*, but I do read quite a bit -- especially the stuff that looks like it might be interesting... like "stream programming", for example. ;) After the discussion I've seen so far, I still have no idea how I would use your code or what it's good for. ~Ethan~ From nathan.alexander.rice at gmail.com Fri Mar 23 17:18:19 2012 From: nathan.alexander.rice at gmail.com (Nathan Rice) Date: Fri, 23 Mar 2012 17:18:19 -0400 Subject: Stream programming In-Reply-To: <4f6cde28$0$1383$4fafbaef@reader1.news.tin.it> References: <4f6c9e17$0$1383$4fafbaef@reader2.news.tin.it> <4f6cde28$0$1383$4fafbaef@reader1.news.tin.it> Message-ID: >> ?I understand what >> you're trying to communicate, so I think you need to be a little more >> strict and explicit in your definitions. > > > No, I don't think you understand what I meant. I don't agree. Sorry. > Yes. I thought that streams as an alternative to functional programming were > widely known. Streams aren't really a paradigm of computation. They're a semantic element of a computational system which cuts across paradigms. If you want to retract that and say you were talking about dataflow programming (which is much larger than streams, and actually has a cohesive definition), I won't hold it against you. Ultimately though, functional programming and dataflow programming are closely linked, the main difference being the use of queues based rather than stacks. > Isn't that obvious? BTW, those are not rigorous definitions. I thought I was talking to people who regularly works with streams. That is the GPU mailing list, down the hall on the left. > Instead of talking of what I wasn't trying to do and, indeed, I didn't do, > you should try to understand what I wanted to do and, in fact, I did. > I'm afraid your cup is too full to understand simple things as the one I > wrote in my OP. Clearly, because I didn't explicitly include the possibility that you are just writing throwaway code with no attempt at development of ideas for the purpose of practicing writing code in the paragraph after the one you quoted. If your goal is to learn to code, instead of posting a message stating that you have a superior way to compose code, you might want to try to solve a problem and ask others their opinion of the structure and techniques in your code. From showell30 at yahoo.com Fri Mar 23 17:37:36 2012 From: showell30 at yahoo.com (Steve Howell) Date: Fri, 23 Mar 2012 14:37:36 -0700 (PDT) Subject: passing context into BaseHTTPRequestHandler References: Message-ID: <6dd1112f-880a-4967-8827-85e8f591e8fb@t2g2000pbg.googlegroups.com> On Mar 23, 12:19?pm, Bernhard Herzog wrote: > Steve Howell writes: > > I have a use case where I'm running BaseHTTPServer.HTTPServer, and I > > want to configure the request handler with some context. ?I've gotten > > the code to work, but it feels overly heavy. ?I am wondering if > > anybody could suggest an easier idiom for this. > > > This is a brief sketch of the code: > > > ? ? class MyHandler(BaseHTTPRequestHandler): > > ? ? ? ? def __init__(self, context, *args): > > ? ? ? ? ? ? self.context = context > > ? ? ? ? ? ? BaseHTTPRequestHandler.__init__(self, *args) > > > ? ? ? ? def do_GET(self): > > ? ? ? ? ? ? // self.context will be available here > > > ? ? context = { .... } > > ? ? def handler(*args): > > ? ? ? ? MyHandler(context, *args) > > > ? ? server = HTTPServer(('', port), handler) > > ? ? server.serve_forever() > > You could store the context in the server object and access it in the > handler methods via self.server.context. It basically works like this: > > class MyHTTPServer(HTTPServer): > > ? ? def __init__(self, *args, **kw): > ? ? ? ? HTTPServer.__init__(self, *args, **kw) > ? ? ? ? self.context = { .... } > > class MyHandler(BaseHTTPRequestHandler): > > ? ? def do_GET(self): > ? ? ? ? context = self.server.context > ? ? ? ? ... > > server = MyHTTPServer(('', port), MyHandler) > server.serve_forever() > Thanks for the suggestion. I made the change, and I think the code's a bit easier to read now. From mentifex at myuw.net Fri Mar 23 18:47:01 2012 From: mentifex at myuw.net (Mentifex) Date: Fri, 23 Mar 2012 15:47:01 -0700 (PDT) Subject: Escape from /dev/null Message-ID: <8004ce27-3b75-4f92-b457-e8322625f789@t6g2000pba.googlegroups.com> Reddit has just published a note about http://www.spotify.com/us/devnull/ which purports to be "a programmer competition that is going to blow your mind." It says that "You will need at least a couple of years experience coding JavaScript and/or Python to have fun and be really good at it to clear the last challenges :) " /dev/null is a hard place to escape from. It keeps calling you back from the vasty deep (see below). Mentifex -- Charter member (with Tim Bradshaw) of Mad People of Comp.Lang.Lisp at http://www.tfeb.org/lisp/mad-people.html http://dev.null.org/psychoceramics/archives/1998.05/msg00018.html From news at blinne.net Fri Mar 23 18:59:44 2012 From: news at blinne.net (Alexander Blinne) Date: Fri, 23 Mar 2012 23:59:44 +0100 Subject: Documentation, assignment in expression. Message-ID: <4f6d0060$0$6634$9b4e6d93@newsspool2.arcor-online.net> Hi, I think this section of the docs needs some kind of rewrite: While it is great to discuss the reasons for not allowing an assignment in an expression, I feel that the given example is some kind of outdated. The last sentence "For example, in the current version of Python file objects support the iterator protocol, so you can now write simply (for line in file:)" makes me think that this section was written while that syntax was still new. No one I know would ever write something like this: > while True: > line = f.readline() > if not line: > break > ... # do something with line I think at least we need a new example. Any ideas? Greetings Alexander From emacsray at gmail.com Fri Mar 23 19:32:38 2012 From: emacsray at gmail.com (Ray Song) Date: Sat, 24 Mar 2012 07:32:38 +0800 Subject: Stream programming In-Reply-To: <4f6c9e17$0$1383$4fafbaef@reader2.news.tin.it> References: <4f6c9e17$0$1383$4fafbaef@reader2.news.tin.it> Message-ID: <20120323233238.GA2713@lap.tuna.tsinghua.edu.cn> On Fri, Mar 23, 2012 at 05:00:23PM +0100, Kiuhnm wrote: > I've been writing a little library for handling streams as an excuse for > doing a little OOP with Python. > > I don't share some of the views on readability expressed on this ng. > Indeed, I believe that a piece of code may very well start as complete > gibberish and become a pleasure to read after some additional > information is provided. > > I must say that imposed indentation is a pain when one is trying to > define some sort of DSL (domain specific language). Also, Python's > operator overloading is a bit limited, but that makes for a more > rewarding experience in my case. > > Here's an example of what you can write: > > numbers - push - avrg - 'med' - pop - filter(lt('med'), ge('med'))\ > - ['same', 'same'] - streams(cat) - 'same' > > Ok, we're at the "complete gibberish" phase. > > Time to give you the "additional information". > > I will use "<=>" to mean "is equivalent to". That's not part of the DSL. > A flow has one or more streams: > 1 stream: > [1,2,3] > 2 streams: > [1,3,5] | [2,4,6] > Two flows can be concatenated: > [1,2,3] + [4,5,6] <=> [1,2,3,4,5,6] > [0] + ([1,2] | [3,4]) + [10] <=> [0,1,2,10] | [0,3,4,10] > ([1,2] | [10,20]) + ([3,4] | [30,40]) <=> [1,2,3,4] | [10,20,30,40] > A flow can be transformed: > [1,2] - f <=> [f(1),f(2)] > ([1,2] | [3,4]) - f <=> [f(1,3),f(2,4)] > ([1,2] | [3,4]) - [f] <=> [f(1),f(2)] | [f(3),f(4)] > ([1,2] | [3,4]) - [f,g] <=> [f(1),f(2)] | [g(3),g(4)] > [1,2] - [f,g] <=> [f(1),f(2)] | [g(1),g(2)] > Some functions are special and almost any function can be made special: > [1,2,3,4,5] - filter(isprime) <=> [2,3,5] > [[],(1,2),[3,4,5]] - flatten <=> [1,2,3,4,5] > Note that 'filter' is not really necessary, thanks to 'flatten'. > Flows can be named, remembered and used > as a value: > [1,2,3,4,5] - 'flow' + val('flow') <=> [1,2,3,4,5]*2 > as a transformation chain: > [1,2,3] - skipfirst - 'again' | [4,5,6] - func('again') > <=> [2,3] | [5,6] > Recursion is also possible and stops when a function is applied to an > empty sequence. > Flows can be saved (push) and restored (pop) : > [1,2,3,4] - push - by(2) - 'double' - pop | val('double') > <=> [1,2,3,4] | [2,4,6,8] > There are easier ways to achieve the same result, of course: > [1,2,3,4] - [id, by(2)] > > Let's go back to our example. I didn't tell you anything but you should > be able to understand it anyway. > > numbers - push - avrg - 'med' - pop - filter(lt('med'), ge('med'))\ > - ['same', 'same'] - streams(cat) - 'same' > > It reads as > > "take a list of numbers - save it - compute the average and named it > 'med' - restore the flow - create two streams which have, respect., the > numbers less than 'med' and those greater or equal to 'med' - do the > /entire/ 'same' process on each one of the two streams - concat the > resulting streams - name all this /entire/ process 'same'. > Not readable enough? Replace 'same' with 'qsort'. > > Is that readable or am I going crazy? [note: that's a rhetorical > question whose answer is "That's very readable!"] > This sounds like a concatenative programming and i've found many cool examples from Haskell and Ruby. I was pleased with Python's rigid off-side rule at first but frustrated when I realized that this is a two-edged blade as the rule makes a DSL difficult. Sorry for former mail to you (my damn Android gmail client doesn't understand mailing lists well). -- Ray From kiuhnm03.4t.yahoo.it Fri Mar 23 19:57:28 2012 From: kiuhnm03.4t.yahoo.it (Kiuhnm) Date: Sat, 24 Mar 2012 00:57:28 +0100 Subject: Stream programming In-Reply-To: References: <4f6c9e17$0$1383$4fafbaef@reader2.news.tin.it> <4f6cde28$0$1383$4fafbaef@reader1.news.tin.it> Message-ID: <4f6d0de7$0$1384$4fafbaef@reader1.news.tin.it> On 3/23/2012 22:12, Ethan Furman wrote: > Kiuhnm wrote: >> On 3/23/2012 17:33, Nathan Rice wrote: >>> Given the examples you pose here, it is clear that you are assuming >>> that the streams are synchronized in discrete time. Since you do not >>> provide any mechanism for temporal alignment of streams you are also >>> assuming every stream will have an element at every time point, the >>> streams start at the same time and are of the same length. Is this >>> what you want? >> >> Yes. I thought that streams as an alternative to functional >> programming were widely known. > > Don't know about widely, but I can say I am unfamiliar with the way you > are using them. That's good! It means I'm saying something new (and, hopefully, interesting). >>> This implies that your transformations again produce flows. You >>> should explicitly state this. >> >> Isn't that obvious? BTW, those are not rigorous definitions. I thought >> I was talking to people who regularly works with streams. > > Why would you think that? This list is composed of all types that use > Python. I've seen occasional discussion of functional programming, but > I've only seen anything this confusing maybe twice before... granted, I > don't read *everything*, but I do read quite a bit -- especially the > stuff that looks like it might be interesting... like "stream > programming", for example. ;) > > > After the discussion I've seen so far, I still have no idea how I would > use your code or what it's good for. The idea is simple. Flows or streams let you be more declarative without being too functional :) In imperative progamming you write statements or commands. In functional programming (FP) you write expressions. In streaming programming (SP) you create flows. Basically, if in FP you write h9(h8(h7(.....(h1)....))) in SP you write h1-h2-h3-...-h9 which I greatly prefer because that's the way I think. I think that SP could be an interesting alternative to FP (in ten years, maybe). Mine was just a little experiment. Kiuhnm From kiuhnm03.4t.yahoo.it Fri Mar 23 20:26:51 2012 From: kiuhnm03.4t.yahoo.it (Kiuhnm) Date: Sat, 24 Mar 2012 01:26:51 +0100 Subject: Stream programming In-Reply-To: References: <4f6c9e17$0$1383$4fafbaef@reader2.news.tin.it> <4f6cde28$0$1383$4fafbaef@reader1.news.tin.it> Message-ID: <4f6d14ca$0$1392$4fafbaef@reader1.news.tin.it> On 3/23/2012 22:18, Nathan Rice wrote: >>> I understand what >>> you're trying to communicate, so I think you need to be a little more >>> strict and explicit in your definitions. >> >> >> No, I don't think you understand what I meant. > > I don't agree. Sorry. You could just point out those inconsistencies that you found. >> Yes. I thought that streams as an alternative to functional programming were >> widely known. > > Streams aren't really a paradigm of computation. They're a semantic > element of a computational system which cuts across paradigms. If you > want to retract that and say you were talking about dataflow > programming (which is much larger than streams, and actually has a > cohesive definition), I won't hold it against you. I wasn't talking of dataflow programming. "Flow programming" is much closer to functional programming than dataflow programming is. >> Instead of talking of what I wasn't trying to do and, indeed, I didn't do, >> you should try to understand what I wanted to do and, in fact, I did. >> I'm afraid your cup is too full to understand simple things as the one I >> wrote in my OP. > > Clearly, because I didn't explicitly include the possibility that you > are just writing throwaway code with no attempt at development of > ideas for the purpose of practicing writing code in the paragraph > after the one you quoted. x != 'a' doesn't imply that x == 'b'. > If your goal is to learn to code, instead of posting a message stating > that you have a superior way to compose code, you might want to try to > solve a problem and ask others their opinion of the structure and > techniques in your code. Never said it was superior. We've been talking about readability a lot, haven't we? I was just proposing something different. Kiuhnm From kiuhnm03.4t.yahoo.it Fri Mar 23 20:41:38 2012 From: kiuhnm03.4t.yahoo.it (Kiuhnm) Date: Sat, 24 Mar 2012 01:41:38 +0100 Subject: Stream programming In-Reply-To: References: <4f6c9e17$0$1383$4fafbaef@reader2.news.tin.it> Message-ID: <4f6d1841$0$1381$4fafbaef@reader1.news.tin.it> On 3/24/2012 0:32, Ray Song wrote: > On Fri, Mar 23, 2012 at 05:00:23PM +0100, Kiuhnm wrote: >> I've been writing a little library for handling streams as an excuse for >> doing a little OOP with Python. >> >> I don't share some of the views on readability expressed on this ng. >> Indeed, I believe that a piece of code may very well start as complete >> gibberish and become a pleasure to read after some additional >> information is provided. >> >> I must say that imposed indentation is a pain when one is trying to >> define some sort of DSL (domain specific language). Also, Python's >> operator overloading is a bit limited, but that makes for a more >> rewarding experience in my case. >> >> Here's an example of what you can write: >> >> numbers - push - avrg - 'med' - pop - filter(lt('med'), ge('med'))\ >> - ['same', 'same'] - streams(cat) - 'same' >> >> Ok, we're at the "complete gibberish" phase. >> >> Time to give you the "additional information". >> >> I will use "<=>" to mean "is equivalent to". That's not part of the DSL. >> A flow has one or more streams: >> 1 stream: >> [1,2,3] >> 2 streams: >> [1,3,5] | [2,4,6] >> Two flows can be concatenated: >> [1,2,3] + [4,5,6]<=> [1,2,3,4,5,6] >> [0] + ([1,2] | [3,4]) + [10]<=> [0,1,2,10] | [0,3,4,10] >> ([1,2] | [10,20]) + ([3,4] | [30,40])<=> [1,2,3,4] | [10,20,30,40] >> A flow can be transformed: >> [1,2] - f<=> [f(1),f(2)] >> ([1,2] | [3,4]) - f<=> [f(1,3),f(2,4)] >> ([1,2] | [3,4]) - [f]<=> [f(1),f(2)] | [f(3),f(4)] >> ([1,2] | [3,4]) - [f,g]<=> [f(1),f(2)] | [g(3),g(4)] >> [1,2] - [f,g]<=> [f(1),f(2)] | [g(1),g(2)] >> Some functions are special and almost any function can be made special: >> [1,2,3,4,5] - filter(isprime)<=> [2,3,5] >> [[],(1,2),[3,4,5]] - flatten<=> [1,2,3,4,5] >> Note that 'filter' is not really necessary, thanks to 'flatten'. >> Flows can be named, remembered and used >> as a value: >> [1,2,3,4,5] - 'flow' + val('flow')<=> [1,2,3,4,5]*2 >> as a transformation chain: >> [1,2,3] - skipfirst - 'again' | [4,5,6] - func('again') >> <=> [2,3] | [5,6] >> Recursion is also possible and stops when a function is applied to an >> empty sequence. >> Flows can be saved (push) and restored (pop) : >> [1,2,3,4] - push - by(2) - 'double' - pop | val('double') >> <=> [1,2,3,4] | [2,4,6,8] >> There are easier ways to achieve the same result, of course: >> [1,2,3,4] - [id, by(2)] >> >> Let's go back to our example. I didn't tell you anything but you should >> be able to understand it anyway. >> >> numbers - push - avrg - 'med' - pop - filter(lt('med'), ge('med'))\ >> - ['same', 'same'] - streams(cat) - 'same' >> >> It reads as >> >> "take a list of numbers - save it - compute the average and named it >> 'med' - restore the flow - create two streams which have, respect., the >> numbers less than 'med' and those greater or equal to 'med' - do the >> /entire/ 'same' process on each one of the two streams - concat the >> resulting streams - name all this /entire/ process 'same'. >> Not readable enough? Replace 'same' with 'qsort'. >> >> Is that readable or am I going crazy? [note: that's a rhetorical >> question whose answer is "That's very readable!"] >> > > This sounds like a concatenative programming and i've found many cool > examples from Haskell and Ruby. I was pleased with Python's rigid > off-side rule at first but frustrated when I realized that this is a > two-edged blade as the rule makes a DSL difficult. Yes, there is that. I also noticed that I couldn't use the comparison operators the way I liked. Precedence is also an issue. I had to use '+' and '-' instead of '+' and '>>' or '>' because of that. I didn't want to introduce extra parentheses. > Sorry for former mail to you (my damn Android gmail client doesn't > understand mailing lists well). Don't worry, my email address is invalid! Kiuhnm From roy at panix.com Fri Mar 23 21:37:40 2012 From: roy at panix.com (Roy Smith) Date: Fri, 23 Mar 2012 21:37:40 -0400 Subject: Documentation, assignment in expression. References: <4f6d0060$0$6634$9b4e6d93@newsspool2.arcor-online.net> Message-ID: In article <4f6d0060$0$6634$9b4e6d93 at newsspool2.arcor-online.net>, Alexander Blinne wrote: > The last sentence "For example, in the current version of Python file > objects support the iterator protocol, so you can now write simply > (for line in file:)" ... In general, words like "current", "previous", and "next" don't belong in documentation. The timepoint to which they refer changes as soon as they're published. Much better to say, "as of version x.y..." From joncle at googlemail.com Fri Mar 23 23:10:28 2012 From: joncle at googlemail.com (Jon Clements) Date: Fri, 23 Mar 2012 20:10:28 -0700 (PDT) Subject: Data mining/pattern recogniton software in Python? In-Reply-To: References: Message-ID: <30719938.516.1332558628851.JavaMail.geo-discussion-forums@vbut24> On Friday, 23 March 2012 16:43:40 UTC, Grzegorz Staniak wrote: > Hello, > > I've been asked by a colleague for help in a small educational > project, which would involve the recognition of patterns in a live > feed of data points (readings from a measuring appliance), and then > a more general search for patterns on archival data. The language > of preference is Python, since the lab uses software written in > Python already. I can see there are packages like Open CV, > scikit-learn, Orange that could perhaps be of use for the mining > phase -- and even if they are slanted towards image pattern > recognition, I think I'd be able to find an appropriate package > for the timeseries analyses. But I'm wondering about the "live" > phase -- what approach would you suggest? I wouldn't want to > force an open door, perhaps there are already packages/modules that > could be used to read data in a loop i.e. every 10 seconds, > maintain a a buffer of 15 readings and ring a bell when the data > in buffer form a specific pattern (a spike, a trough, whatever)? > > I'll be grateful for a push in the right direction. Thanks, > > GS > -- > Grzegorz Staniak It might also be worth checking out pandas[1] and scikits.statsmodels[2]. In terms of reading data in a loop I would probably go for a producer-consumer model (possibly using a Queue[3]). Have the consumer constantly try to get another reading, and notify the consumer which can then determine if it's got enough data to calculate a peak/trough. This article is also a fairly good read[4]. That's some pointers anyway, hth, Jon. [1] http://pandas.pydata.org/ [2] http://statsmodels.sourceforge.net/ [3] http://docs.python.org/library/queue.html [4] http://www.laurentluce.com/posts/python-threads-synchronization-locks-rlocks-semaphores-conditions-events-and-queues/ From steve+comp.lang.python at pearwood.info Fri Mar 23 23:23:44 2012 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 24 Mar 2012 03:23:44 GMT Subject: Stream programming References: <4f6c9e17$0$1383$4fafbaef@reader2.news.tin.it> Message-ID: <4f6d3e3f$0$29981$c3e8da3$5496439d@news.astraweb.com> On Fri, 23 Mar 2012 17:00:23 +0100, Kiuhnm wrote: > I've been writing a little library for handling streams as an excuse for > doing a little OOP with Python. > > I don't share some of the views on readability expressed on this ng. > Indeed, I believe that a piece of code may very well start as complete > gibberish and become a pleasure to read after some additional > information is provided. [...] > numbers - push - avrg - 'med' - pop - filter(lt('med'), ge('med'))\ > - ['same', 'same'] - streams(cat) - 'same' > > Ok, we're at the "complete gibberish" phase. > > Time to give you the "additional information". There are multiple problems with your DSL. Having read your explanation, and subsequent posts, I think I understand the data model, but the syntax itself is not very good and far from readable. It is just too hard to reason about the code. Your syntax conflicts with established, far more common, use of the same syntax: you use - to mean "call a function" and | to join two or more streams into a flow. You also use () for calling functions, and the difference between - and () isn't clear. So a mystery there -- your DSL seems to have different function syntax, depending on... what? The semantics are unclear even after your examples. To understand your syntax, you give examples, but to understand the examples, the reader needs to understand the syntax. That suggests that the semantics are unclear even in your own mind, or at least too difficult to explain in simple examples. Take this example: > Flows can be saved (push) and restored (pop) : > [1,2,3,4] - push - by(2) - 'double' - pop | val('double') > <=> [1,2,3,4] | [2,4,6,8] What the hell does that mean? The reader initially doesn't know what *any* of push, by(2), pop or val('double') means. All they see is an obfuscated series of calls that starts with a stream as input, makes a copy of it, and doubles the entries in the copy: you make FIVE function calls to perform TWO conceptual operations. So the reader can't even map a function call to a result. With careful thought and further explanations from you, the reader (me) eventually gets a mental model here. Your DSL has a single input which is pipelined through a series of function calls by the - operator, plus a separate stack. (I initially thought that, like Forth, your DSL was stack based. But it isn't, is it?) It seems to me that the - operator is only needed as syntactic sugar to avoid using reverse Polish notation and an implicit stack. Instead of the Forth-like: [1,2,3,4] dup 2 * your DSL has an explicit stack, and an explicit - operator to call a function. Presumably "[1,2] push" would be a syntax error. I think this is a good example of an inferior syntax. Contrast your: [1,2,3,4] - push - by(2) - 'double' - pop | val('double') with the equivalent RPL: [1,2,3,4] dup 2 * Now *that* is a pleasure to read, once you wrap your head around reverse Polish notation and the concept of a stack. Which you need in your DSL anyway, to understand push and pop. You say that this is an "easier way to get the same result": [1,2,3,4] - [id, by(2)] but it isn't, is it? The more complex example above ends up with two streams joined in a single flow: [1,2,3,4]|[2,4,6,8] whereas the shorter version using the magic "id" gives you a single stream containing nested streams: [[1,2,3,4], [2,4,6,8]] So, how could you make this more readable? * Don't fight the reader's expectations. If they've programmed in Unix shells, they expect | as the pipelining operator. If they haven't, they probably will find >> easy to read as a dataflow operator. Either way, they're probably used to seeing a|b as meaning "or" (as in "this stream, or this stream") rather than the way you seem to be using it ("this stream, and this stream"). Here's my first attempt at improved syntax that doesn't fight the user: [1,2,3,4] >> push >> by(2) >> 'double' >> pop & val('double') "push" and "pop" are poor choices of words. Push does not actually push its input onto the stack, which would leave the input stream empty. It makes a copy. You explain what they do: "Flows can be saved (push) and restored (pop)" so why not just use SAVE and RESTORE as your functions? Or if they're too verbose, STO and RCL, or my preference, store and recall. [1,2,3,4] >> store >> by(2) >> 'double' >> recall & val('double') I'm still not happy with & for the join operator. I think that the use of + for concatenate and & for join is just one of those arbitrary choices that the user will have to learn. Although I'm tempted to try using a colon instead. [1,2,3]:[4,5,6] would be a flow with two streams. I don't like the syntax for defining and using names. Here's a random thought: [1,2,3,4] >> store >> by(2) >> @double >> recall & double Use @name to store to a name, and the name alone to retrieve from it. But I haven't given this too much thought, so it too might suck. Some other problems with your DSL: > A flow can be transformed: > [1,2] - f <=> [f(1),f(2)] but that's not consistently true. For instance: [1,2] - push <=/=> [push(1), push(2)] So the reader needs to know all the semantics of the particular function f before being able to reason about the flow. Your DSL displays magic behaviour, which is bad and makes it hard to read the code because the reader may not know which functions are magic and which are not. > Some functions are special and almost any function can be made special: > [1,2,3,4,5] - filter(isprime) <=> [2,3,5] > [[],(1,2),[3,4,5]] - flatten <=> [1,2,3,4,5] You say that as if it were a good thing. -- Steven From akghosh3 at gmail.com Fri Mar 23 23:37:35 2012 From: akghosh3 at gmail.com (Aloke Ghosh) Date: Sat, 24 Mar 2012 09:07:35 +0530 Subject: Help needed to understand the error message Message-ID: Hi, I am learning Python and do not have programming experience. I was following an exercise from http://learnpythonthehardway.org/book/ex2.html and made a mistake in entry : *Print"I like typing this."* and got the following error message: *In [2]: Print"I like typing this."* *------------------------------------------------------------* * File "", line 1* * Print"I like typing this."* * ^* *SyntaxError: invalid syntax* I feel the error is in Capital P in print . However the error indicated with "*^*" hints at quote at the end of the line. *Can any one please help me understand this.* -- A.K.Ghosh Bangalore:560016 Karnataka, India. Mob : +91 9448116503 -------------- next part -------------- An HTML attachment was scrubbed... URL: From python at mrabarnett.plus.com Sat Mar 24 00:00:57 2012 From: python at mrabarnett.plus.com (MRAB) Date: Sat, 24 Mar 2012 04:00:57 +0000 Subject: Help needed to understand the error message In-Reply-To: References: Message-ID: <4F6D46F9.4010201@mrabarnett.plus.com> On 24/03/2012 03:37, Aloke Ghosh wrote: > Hi, > I am learning Python and do not have programming experience. > I was following an exercise from > http://learnpythonthehardway.org/book/ex2.html > and made a mistake in entry : > > *Print"I like typing this."* > > and got the following error message: > > *In [2]: Print"I like typing this."* > *------------------------------------------------------------* > * File "", line 1* > * Print"I like typing this."* > * ^* > *SyntaxError: invalid syntax* > > I feel the error is in Capital P in print . Correct. (I'm assuming that you're using Python 2; Python 3 is a little different.) > However the error indicated with "*^*" > hints at quote at the end of the line. > > *Can any one please help me understand this.* > It will tell you approximately where the error is, but, as in this example, the actual error may be a little earlier. It tries to be helpful, but remember that it isn't intelligent! :-) From d at davea.name Sat Mar 24 00:44:38 2012 From: d at davea.name (Dave Angel) Date: Sat, 24 Mar 2012 00:44:38 -0400 Subject: Number of languages known [was Re: Python is readable] - somewhat OT In-Reply-To: References: <4f6bcdd5$0$29981$c3e8da3$5496439d@news.astraweb.com> <8694a85d-fe94-4bef-8bb6-8a8241d14ca3@px4g2000pbc.googlegroups.com> <4F6CA39B.9090709@stoneleaf.us> Message-ID: <4F6D5136.5050304@davea.name> On 03/23/2012 02:28 PM, Peter Otten wrote: > Ethan Furman wrote: > >> Nathan Rice wrote: >>> Logo. It's turtles all the way down. >> +1 QOTW > Surely you're joking, Mr Furman! > Cracking safes was the best chapter. -- DaveA From joncle at googlemail.com Sat Mar 24 01:12:46 2012 From: joncle at googlemail.com (Jon Clements) Date: Fri, 23 Mar 2012 22:12:46 -0700 (PDT) Subject: Fetching data from a HTML file In-Reply-To: <9362386.1094.1332510725414.JavaMail.geo-discussion-forums@ynlt15> References: <9362386.1094.1332510725414.JavaMail.geo-discussion-forums@ynlt15> Message-ID: <18618102.2255.1332565966684.JavaMail.geo-discussion-forums@vbtv42> On Friday, 23 March 2012 13:52:05 UTC, Sangeet wrote: > Hi, > > I've got to fetch data from the snippet below and have been trying to match the digits in this to specifically to specific groups. But I can't seem to figure how to go about stripping the tags! :( > > Sum2451102561.496 [min] > > > Actually, I'm working on ROBOT Framework, and haven't been able to figure out how to read data from HTML tables. Reading from the source, is the best (read rudimentary) way I could come up with. Any suggestions are welcome! > > Thanks, > Sangeet I would personally use lxml - a quick example: # -*- coding: utf-8 -*- import lxml.html text = """ Sum?2451102561.496 [min] """ table = lxml.html.fromstring(text) for tr in table.xpath('//tr'): print [ (el.get('class', ''), el.text_content()) for el in tr.iterfind('td') ] [('', 'Sum'), ('', ''), ('green', '245'), ('red', '11'), ('', '0'), ('', '256'), ('', '1.496 [min]')] It does a reasonable job, but if it doesn't work quite right, then there's a .fromstring(parser=...) option, and you should be able to pass in ElementSoup and try your luck from there. hth, Jon. From gstaniak at gmail.com Sat Mar 24 01:21:09 2012 From: gstaniak at gmail.com (Grzegorz Staniak) Date: Sat, 24 Mar 2012 05:21:09 +0000 (UTC) Subject: Data mining/pattern recogniton software in Python? References: <30719938.516.1332558628851.JavaMail.geo-discussion-forums@vbut24> Message-ID: On 24.03.2012, Jon Clements wroted: > It might also be worth checking out pandas[1] and scikits.statsmodels[2]. > > In terms of reading data in a loop I would probably go for a producer-consumer model (possibly using a Queue[3]). Have the consumer constantly try to get another reading, and notify the consumer which can then determine if it's got enough data to calculate a peak/trough. This article is also a fairly good read[4]. > > That's some pointers anyway, > > hth, > > Jon. > > [1] http://pandas.pydata.org/ > [2] http://statsmodels.sourceforge.net/ > [3] http://docs.python.org/library/queue.html > [4] http://www.laurentluce.com/posts/python-threads-synchronization-locks-rlocks-semaphores-conditions-events-and-queues/ Thanks for the suggestions. GS -- Grzegorz Staniak From kiuhnm03.4t.yahoo.it Sat Mar 24 07:05:28 2012 From: kiuhnm03.4t.yahoo.it (Kiuhnm) Date: Sat, 24 Mar 2012 12:05:28 +0100 Subject: Stream programming In-Reply-To: <4f6d3e3f$0$29981$c3e8da3$5496439d@news.astraweb.com> References: <4f6c9e17$0$1383$4fafbaef@reader2.news.tin.it> <4f6d3e3f$0$29981$c3e8da3$5496439d@news.astraweb.com> Message-ID: <4f6daa78$0$1377$4fafbaef@reader2.news.tin.it> On 3/24/2012 4:23, Steven D'Aprano wrote: > On Fri, 23 Mar 2012 17:00:23 +0100, Kiuhnm wrote: > >> I've been writing a little library for handling streams as an excuse for >> doing a little OOP with Python. >> >> I don't share some of the views on readability expressed on this ng. >> Indeed, I believe that a piece of code may very well start as complete >> gibberish and become a pleasure to read after some additional >> information is provided. > [...] >> numbers - push - avrg - 'med' - pop - filter(lt('med'), ge('med'))\ >> - ['same', 'same'] - streams(cat) - 'same' >> >> Ok, we're at the "complete gibberish" phase. >> >> Time to give you the "additional information". > > There are multiple problems with your DSL. Having read your explanation, > and subsequent posts, I think I understand the data model, but the syntax > itself is not very good and far from readable. It is just too hard to > reason about the code. > > Your syntax conflicts with established, far more common, use of the same > syntax: you use - to mean "call a function" and | to join two or more > streams into a flow. > > You also use () for calling functions, and the difference between - and > () isn't clear. So a mystery there -- your DSL seems to have different > function syntax, depending on... what? > > The semantics are unclear even after your examples. To understand your > syntax, you give examples, but to understand the examples, the reader > needs to understand the syntax. That suggests that the semantics are > unclear even in your own mind, or at least too difficult to explain in > simple examples. > > Take this example: > >> Flows can be saved (push) and restored (pop) : >> [1,2,3,4] - push - by(2) - 'double' - pop | val('double') >> <=> [1,2,3,4] | [2,4,6,8] > > What the hell does that mean? The reader initially doesn't know what > *any* of push, by(2), pop or val('double') means. All they see is an > obfuscated series of calls that starts with a stream as input, makes a > copy of it, and doubles the entries in the copy: you make FIVE function > calls to perform TWO conceptual operations. So the reader can't even map > a function call to a result. > > With careful thought and further explanations from you, the reader (me) > eventually gets a mental model here. Your DSL has a single input which is > pipelined through a series of function calls by the - operator, plus a > separate stack. (I initially thought that, like Forth, your DSL was stack > based. But it isn't, is it?) > > It seems to me that the - operator is only needed as syntactic sugar to > avoid using reverse Polish notation and an implicit stack. Instead of the > Forth-like: > > [1,2,3,4] dup 2 * > > your DSL has an explicit stack, and an explicit - operator to call a > function. Presumably "[1,2] push" would be a syntax error. > > I think this is a good example of an inferior syntax. Contrast your: > > [1,2,3,4] - push - by(2) - 'double' - pop | val('double') > > with the equivalent RPL: > > [1,2,3,4] dup 2 * I was just explaining how push and pop work. I also said that [1,2,3,4] - [id,by(2)] would be the recommended way to do it. > Now *that* is a pleasure to read, once you wrap your head around reverse > Polish notation and the concept of a stack. Which you need in your DSL > anyway, to understand push and pop. I don't see why. Push and pop are not needed. They're just handful mainly to modify a flow, collect a result, and go back to how the flow was before the push. It has nothing to do with RPN (which RPL is based on). > You say that this is an "easier way to get the same result": > > [1,2,3,4] - [id, by(2)] > > but it isn't, is it? The more complex example above ends up with two > streams joined in a single flow: > > [1,2,3,4]|[2,4,6,8] > > whereas the shorter version using the magic "id" gives you a single > stream containing nested streams: > > [[1,2,3,4], [2,4,6,8]] Says who? Here are the rules again: A flow can be transformed: [1,2] - f <=> [f(1),f(2)] ([1,2] | [3,4]) - f <=> [f(1,3),f(2,4)] ([1,2] | [3,4]) - [f] <=> [f(1),f(2)] | [f(3),f(4)] ([1,2] | [3,4]) - [f,g] <=> [f(1),f(2)] | [g(3),g(4)] [1,2] - [f,g] <=> [f(1),f(2)] | [g(1),g(2)] Read the last line. What's very interesting, is that [f,g] is an iterable as well, so your functions can be generated as needed. > So, how could you make this more readable? > > * Don't fight the reader's expectations. If they've programmed in Unix > shells, they expect | as the pipelining operator. If they haven't, they > probably will find>> easy to read as a dataflow operator. Either way, > they're probably used to seeing a|b as meaning "or" (as in "this stream, > or this stream") rather than the way you seem to be using it ("this > stream, and this stream"). > > Here's my first attempt at improved syntax that doesn't fight the user: > > [1,2,3,4]>> push>> by(2)>> 'double'>> pop& val('double') There are problems with your syntax. Mine: [...]+[...] - f + [...] - g - h + [...] - i + [...] Yours: ((([...]+[...] >> f) + [...] >> g >> h) + [...] >> i) + [...] I first tried to use '<<' and '>>' but '+' and '-' are much better. > "push" and "pop" are poor choices of words. Push does not actually push > its input onto the stack, which would leave the input stream empty. It > makes a copy. You explain what they do: Why should push move and not copy? In asm and openGL they copy, for instance. > "Flows can be saved (push) and restored (pop)" > > so why not just use SAVE and RESTORE as your functions? Or if they're too > verbose, STO and RCL, or my preference, store and recall. Because that's not what they do. push and pop actually push and pop, i.e. they can be nested and work as expected. > [1,2,3,4]>> store>> by(2)>> 'double'>> recall& val('double') > > I'm still not happy with& for the join operator. I think that the use of > + for concatenate and& for join is just one of those arbitrary choices > that the user will have to learn. Although I'm tempted to try using a > colon instead. > > [1,2,3]:[4,5,6] > > would be a flow with two streams. I can't see a way to overload ':' in Python. There are also technical limitations. > I don't like the syntax for defining and using names. Here's a random > thought: > > [1,2,3,4]>> store>> by(2)>> @double>> recall& double > > Use @name to store to a name, and the name alone to retrieve from it. But > I haven't given this too much thought, so it too might suck. The problem, again, is Python limitation in defining DSLs. At this point, one would have to interpret command-strings. I was trying to avoid an interpreter on an interpreter. > Some other problems with your DSL: > >> A flow can be transformed: >> [1,2] - f<=> [f(1),f(2)] > > but that's not consistently true. For instance: > > [1,2] - push<=/=> [push(1), push(2)] push is a special function (a keyword). It's clear what it does. It's just an exception to the general rule. > So the reader needs to know all the semantics of the particular function > f before being able to reason about the flow. No, he only has to know special functions. Those are practically keywords. >> Some functions are special and almost any function can be made special: >> [1,2,3,4,5] - filter(isprime)<=> [2,3,5] >> [[],(1,2),[3,4,5]] - flatten<=> [1,2,3,4,5] > > You say that as if it were a good thing. It is, because it's never implicit. For instance, isprime is a filter. flatten is a special builtin function (a keyword). Kiuhnm From izharpervaiz7 at gmail.com Sat Mar 24 08:30:35 2012 From: izharpervaiz7 at gmail.com (izharpervaiz7 at gmail.com) Date: Sat, 24 Mar 2012 05:30:35 -0700 (PDT) Subject: "pakistani girls" "pakistani girls lahore" "pakistani girls phone numbers" "pakistani girls mobile number" "pakistani girls wallpapers" "pakistani girls cell numbers" on www.epakistanigirls.blogspot.com In-Reply-To: <571c2ace-6ba5-461d-81ab-7e846c61cb7d@g10g2000pri.googlegroups.com> References: <571c2ace-6ba5-461d-81ab-7e846c61cb7d@g10g2000pri.googlegroups.com> Message-ID: <11301667.0.1332592235130.JavaMail.geo-discussion-forums@vbtw24> On Saturday, 28 November 2009 19:59:23 UTC+5, saima81 wrote: > "pakistani girls" "pakistani girls lahore" "pakistani girls phone > numbers" "pakistani girls mobile number" "pakistani girls wallpapers" > "pakistani girls cell numbers" on www.epakistanigirls.blogspot.com > "pakistani girls" "pakistani girls lahore" "pakistani girls phone > numbers" "pakistani girls mobile number" "pakistani girls wallpapers" > "pakistani girls cell numbers" on www.epakistanigirls.blogspot.com > "pakistani girls" "pakistani girls lahore" "pakistani girls phone > numbers" "pakistani girls mobile number" "pakistani girls wallpapers" > "pakistani girls cell numbers" on www.epakistanigirls.blogspot.com > "pakistani girls" "pakistani girls lahore" "pakistani girls phone > numbers" "pakistani girls mobile number" "pakistani girls wallpapers" > "pakistani girls cell numbers" on www.epakistanigirls.blogspot.com > "pakistani girls" "pakistani girls lahore" "pakistani girls phone > numbers" "pakistani girls mobile number" "pakistani girls wallpapers" > "pakistani girls cell numbers" on www.epakistanigirls.blogspot.com > "pakistani girls" "pakistani girls lahore" "pakistani girls phone > numbers" "pakistani girls mobile number" "pakistani girls wallpapers" > "pakistani girls cell numbers" on www.epakistanigirls.blogspot.com > "pakistani girls" "pakistani girls lahore" "pakistani girls phone > numbers" "pakistani girls mobile number" "pakistani girls wallpapers" > "pakistani girls cell numbers" on www.epakistanigirls.blogspot.com > "pakistani girls" "pakistani girls lahore" "pakistani girls phone > numbers" "pakistani girls mobile number" "pakistani girls wallpapers" > "pakistani girls cell numbers" on www.epakistanigirls.blogspot.com > "pakistani girls" "pakistani girls lahore" "pakistani girls phone > numbers" "pakistani girls mobile number" "pakistani girls wallpapers" > "pakistani girls cell numbers" on www.epakistanigirls.blogspot.com > "pakistani girls" "pakistani girls lahore" "pakistani girls phone > numbers" "pakistani girls mobile number" "pakistani girls wallpapers" > "pakistani girls cell numbers" on www.epakistanigirls.blogspot.com > "pakistani girls" "pakistani girls lahore" "pakistani girls phone > numbers" "pakistani girls mobile number" "pakistani girls wallpapers" > "pakistani girls cell numbers" on www.epakistanigirls.blogspot.com > "pakistani girls" "pakistani girls lahore" "pakistani girls phone > numbers" "pakistani girls mobile number" "pakistani girls wallpapers" > "pakistani girls cell numbers" on www.epakistanigirls.blogspot.com > "pakistani girls" "pakistani girls lahore" "pakistani girls phone > numbers" "pakistani girls mobile number" "pakistani girls wallpapers" > "pakistani girls cell numbers" on www.epakistanigirls.blogspot.com > "pakistani girls" "pakistani girls lahore" "pakistani girls phone > numbers" "pakistani girls mobile number" "pakistani girls wallpapers" > "pakistani girls cell numbers" on www.epakistanigirls.blogspot.com > "pakistani girls" "pakistani girls lahore" "pakistani girls phone > numbers" "pakistani girls mobile number" "pakistani girls wallpapers" > "pakistani girls cell numbers" on www.epakistanigirls.blogspot.com > "pakistani girls" "pakistani girls lahore" "pakistani girls phone > numbers" "pakistani girls mobile number" "pakistani girls wallpapers" > "pakistani girls cell numbers" on www.epakistanigirls.blogspot.com > "pakistani girls" "pakistani girls lahore" "pakistani girls phone > numbers" "pakistani girls mobile number" "pakistani girls wallpapers" > "pakistani girls cell numbers" on www.epakistanigirls.blogspot.com > "pakistani girls" "pakistani girls lahore" "pakistani girls phone > numbers" "pakistani girls mobile number" "pakistani girls wallpapers" > "pakistani girls cell numbers" on www.epakistanigirls.blogspot.com > "pakistani girls" "pakistani girls lahore" "pakistani girls phone > numbers" "pakistani girls mobile number" "pakistani girls wallpapers" > "pakistani girls cell numbers" on www.epakistanigirls.blogspot.com > "pakistani girls" "pakistani girls lahore" "pakistani girls phone > numbers" "pakistani girls mobile number" "pakistani girls wallpapers" > "pakistani girls cell numbers" on www.epakistanigirls.blogspot.com > "pakistani girls" "pakistani girls lahore" "pakistani girls phone > numbers" "pakistani girls mobile number" "pakistani girls wallpapers" > "pakistani girls cell numbers" on www.epakistanigirls.blogspot.com > "pakistani girls" "pakistani girls lahore" "pakistani girls phone > numbers" "pakistani girls mobile number" "pakistani girls wallpapers" > "pakistani girls cell numbers" on www.epakistanigirls.blogspot.com > "pakistani girls" "pakistani girls lahore" "pakistani girls phone > numbers" "pakistani girls mobile number" "pakistani girls wallpapers" > "pakistani girls cell numbers" on www.epakistanigirls.blogspot.com > "pakistani girls" "pakistani girls lahore" "pakistani girls phone > numbers" "pakistani girls mobile number" "pakistani girls wallpapers" > "pakistani girls cell numbers" on www.epakistanigirls.blogspot.com > "pakistani girls" "pakistani girls lahore" "pakistani girls phone > numbers" "pakistani girls mobile number" "pakistani girls wallpapers" > "pakistani girls cell numbers" on www.epakistanigirls.blogspot.com > "pakistani girls" "pakistani girls lahore" "pakistani girls phone > numbers" "pakistani girls mobile number" "pakistani girls wallpapers" > "pakistani girls cell numbers" on www.epakistanigirls.blogspot.com > "pakistani girls" "pakistani girls lahore" "pakistani girls phone > numbers" "pakistani girls mobile number" "pakistani girls wallpapers" > "pakistani girls cell numbers" on www.epakistanigirls.blogspot.com > "pakistani girls" "pakistani girls lahore" "pakistani girls phone > numbers" "pakistani girls mobile number" "pakistani girls wallpapers" > "pakistani girls cell numbers" on www.epakistanigirls.blogspot.com > "pakistani girls" "pakistani girls lahore" "pakistani girls phone > numbers" "pakistani girls mobile number" "pakistani girls wallpapers" > "pakistani girls cell numbers" on www.epakistanigirls.blogspot.com > "pakistani girls" "pakistani girls lahore" "pakistani girls phone > numbers" "pakistani girls mobile number" "pakistani girls wallpapers" > "pakistani girls cell numbers" on www.epakistanigirls.blogspot.com > "pakistani girls" "pakistani girls lahore" "pakistani girls phone > numbers" "pakistani girls mobile number" "pakistani girls wallpapers" > "pakistani girls cell numbers" on www.epakistanigirls.blogspot.com > "pakistani girls" "pakistani girls lahore" "pakistani girls phone > numbers" "pakistani girls mobile number" "pakistani girls wallpapers" > "pakistani girls cell numbers" on www.epakistanigirls.blogspot.com > "pakistani girls" "pakistani girls lahore" "pakistani girls phone > numbers" "pakistani girls mobile number" "pakistani girls wallpapers" > "pakistani girls cell numbers" on www.epakistanigirls.blogspot.com > "pakistani girls" "pakistani girls lahore" "pakistani girls phone > numbers" "pakistani girls mobile number" "pakistani girls wallpapers" > "pakistani girls cell numbers" on www.epakistanigirls.blogspot.com > "pakistani girls" "pakistani girls lahore" "pakistani girls phone > numbers" "pakistani girls mobile number" "pakistani girls wallpapers" > "pakistani girls cell numbers" on www.epakistanigirls.blogspot.com > "pakistani girls" "pakistani girls lahore" "pakistani girls phone > numbers" "pakistani girls mobile number" "pakistani girls wallpapers" > "pakistani girls cell numbers" on www.epakistanigirls.blogspot.com > "pakistani girls" "pakistani girls lahore" "pakistani girls phone > numbers" "pakistani girls mobile number" "pakistani girls wallpapers" > "pakistani girls cell numbers" on www.epakistanigirls.blogspot.com > "pakistani girls" "pakistani girls lahore" "pakistani girls phone > numbers" "pakistani girls mobile number" "pakistani girls wallpapers" > "pakistani girls cell numbers" on www.epakistanigirls.blogspot.com > "pakistani girls" "pakistani girls lahore" "pakistani girls phone > numbers" "pakistani girls mobile number" "pakistani girls wallpapers" > "pakistani girls cell numbers" on www.epakistanigirls.blogspot.com > "pakistani girls" "pakistani girls lahore" "pakistani girls phone > numbers" "pakistani girls mobile number" "pakistani girls wallpapers" > "pakistani girls cell numbers" on www.epakistanigirls.blogspot.com > "pakistani girls" "pakistani girls lahore" "pakistani girls phone > numbers" "pakistani girls mobile number" "pakistani girls wallpapers" > "pakistani girls cell numbers" on www.epakistanigirls.blogspot.com > "pakistani girls" "pakistani girls lahore" "pakistani girls phone > numbers" "pakistani girls mobile number" "pakistani girls wallpapers" > "pakistani girls cell numbers" on www.epakistanigirls.blogspot.com > "pakistani girls" "pakistani girls lahore" "pakistani girls phone > numbers" "pakistani girls mobile number" "pakistani girls wallpapers" > "pakistani girls cell numbers" on www.epakistanigirls.blogspot.com > "pakistani girls" "pakistani girls lahore" "pakistani girls phone > numbers" "pakistani girls mobile number" "pakistani girls wallpapers" > "pakistani girls cell numbers" on www.epakistanigirls.blogspot.com > "pakistani girls" "pakistani girls lahore" "pakistani girls phone > numbers" "pakistani girls mobile number" "pakistani girls wallpapers" > "pakistani girls cell numbers" on www.epakistanigirls.blogspot.com > "pakistani girls" "pakistani girls lahore" "pakistani girls phone > numbers" "pakistani girls mobile number" "pakistani girls wallpapers" > "pakistani girls cell numbers" on www.epakistanigirls.blogspot.com > "pakistani girls" "pakistani girls lahore" "pakistani girls phone > numbers" "pakistani girls mobile number" "pakistani girls wallpapers" > "pakistani girls cell numbers" on www.epakistanigirls.blogspot.com > "pakistani girls" "pakistani girls lahore" "pakistani girls phone > numbers" "pakistani girls mobile number" "pakistani girls wallpapers" > "pakistani girls cell numbers" on www.epakistanigirls.blogspot.com > "pakistani girls" "pakistani girls lahore" "pakistani girls phone > numbers" "pakistani girls mobile number" "pakistani girls wallpapers" > "pakistani girls cell numbers" on www.epakistanigirls.blogspot.com > "pakistani girls" "pakistani girls lahore" "pakistani girls phone > numbers" "pakistani girls mobile number" "pakistani girls wallpapers" > "pakistani girls cell numbers" on www.epakistanigirls.blogspot.com > "pakistani girls" "pakistani girls lahore" "pakistani girls phone > numbers" "pakistani girls mobile number" "pakistani girls wallpapers" > "pakistani girls cell numbers" on www.epakistanigirls.blogspot.com > "pakistani girls" "pakistani girls lahore" "pakistani girls phone > numbers" "pakistani girls mobile number" "pakistani girls wallpapers" > "pakistani girls cell numbers" on www.epakistanigirls.blogspot.com > "pakistani girls" "pakistani girls lahore" "pakistani girls phone > numbers" "pakistani girls mobile number" "pakistani girls wallpapers" > "pakistani girls cell numbers" on www.epakistanigirls.blogspot.com > "pakistani girls" "pakistani girls lahore" "pakistani girls phone > numbers" "pakistani girls mobile number" "pakistani girls wallpapers" > "pakistani girls cell numbers" on www.epakistanigirls.blogspot.com > "pakistani girls" "pakistani girls lahore" "pakistani girls phone > numbers" "pakistani girls mobile number" "pakistani girls wallpapers" > "pakistani girls cell numbers" on www.epakistanigirls.blogspot.com > "pakistani girls" "pakistani girls lahore" "pakistani girls phone > numbers" "pakistani girls mobile number" "pakistani girls wallpapers" > "pakistani girls cell numbers" on www.epakistanigirls.blogspot.com From awilliam at whitemice.org Sat Mar 24 11:24:23 2012 From: awilliam at whitemice.org (Adam Tauno Williams) Date: Sat, 24 Mar 2012 11:24:23 -0400 Subject: Is it technically possible to give Python option of naming process of running script? In-Reply-To: <19118128.4791.1331736187952.JavaMail.geo-discussion-forums@vbai14> References: <19118128.4791.1331736187952.JavaMail.geo-discussion-forums@vbai14> Message-ID: <1332602663.14861.1.camel@workstation.wmmi.net> On Wed, 2012-03-14 at 07:43 -0700, xliiv wrote: > Like the topic.. . > I use Python a lot, both Windows and Linux, and it's little weird to > have many python process without fast distinction which is what. I'm not sure of my interpretation of your problem but if you want to set the name of the running process in the process table, at least on LINUX/UNIX, you can use the procname module available via PyPI. -------------- next part -------------- A non-text attachment was scrubbed... Name: signature.asc Type: application/pgp-signature Size: 198 bytes Desc: This is a digitally signed message part URL: From python at bdurham.com Sat Mar 24 14:02:11 2012 From: python at bdurham.com (python at bdurham.com) Date: Sat, 24 Mar 2012 14:02:11 -0400 Subject: Comments wanted: Proposed change to install layout In-Reply-To: References: Message-ID: <1332612131.7438.140661053554749.38856648@webmail.messagingengine.com> Van, > ... harmonize the install layout for Python between platforms. > 1) the 'Scripts' directory would change to 'bin'; > 2) python.exe would move to the 'bin' directory; and > 3) the installer for Windows would get the optional ability to add this directory to the PATH. 1 vote in support of your proposal. Malcolm -------------- next part -------------- An HTML attachment was scrubbed... URL: From bv8bv8bv8 at gmail.com Sat Mar 24 14:05:55 2012 From: bv8bv8bv8 at gmail.com (BV BV) Date: Sat, 24 Mar 2012 11:05:55 -0700 (PDT) Subject: The Oneness of God is the message of Jesus and all the Prophets, peace be upon them !!!!!!!!!!!!!! Message-ID: <8524cb43-1a8d-4d57-a792-328c28258073@d17g2000vba.googlegroups.com> The Oneness of God is the message of Jesus and all the Prophets, peace be upon them The message that was brought by the Messiah (peace be upon him) was the call to worship God, the One, the Lord of the Messiah and the Lord of the worlds: "Now this is eternal life: that they may know you, the only true God, and Jesus Christ, whom you have sent" John 17:3 - NIV "A certain ruler asked him: 'Good teacher, what must I do to inherit eternal life?' 'Why do you call me good?' Jesus answered. 'No one is good - except God alone.'" Luke 18:18-19 - NIV "The devil led him up to a high place and showed him in an instant all the kingdoms of the world. And he said to him, 'I will give you all their authority and splendour, for it has been given to me, and I can give it to anyone I want to. So if you worship me, it will all be yours.' Jesus answered, 'It is written: "Worship the Lord your God and serve him only."'" Luke 4:5-8 - NIV Believing in and worshipping Allaah alone, besides Whom there is no other god, is the greatest teaching brought by the Messiah, and it is the greatest teaching brought by all the Prophets. "One of the teachers of the law came and noticed them debating. Noticing that Jesus had given them a good answer, he asked him, 'Of all the commandments, which is the most important?' 'The most important one,' answered Jesus, 'is this: "Hear, O Israel, the Lord our God, the Lord is one. Love the Lord your God with all your heart and with all your soul and with all your mind and with all your strength." The second is this: "Love your neighbour as yourself." There is no commandment greater than these.' 'Well said, teacher,' the man replied. 'You are right in saying that God is one and there is no other but him. To love him with all your heart, with you all your understanding and with all your strength, and to love your neighbour as yourself is more important that all burnt offerings and sacrifices.' When Jesus saw that he has answered wisely, he said to him, 'You are not far from the kingdom of God.' And from then on no one dared ask him any more questions." Mark 12:28-34 - NIV But do not think that this advice was given to Israel or to his own people only. Rather this is the basis of the teachings of all the Prophets. The same advice appears in the Gospel of Matthew, in similar wording, after which he says: "All the Law and the Prophets hang on these two commandments." Matthew 22:39 - NIV This belief in the oneness of God is indeed the message of all of the Prophets. Allaah says (interpretation of the meaning): "And We did not send any Messenger before you (O Muhammad) but We revealed to him (saying): Laa ilaaha illa Ana [none has the right to be worshipped but I (Allaah)], so worship Me (Alone and none else)" [al-Anbiya' 21:25] This is the basic message to which the Messiah called people and warned them against differing from that. Allaah says (interpretation of the meaning): "Surely, they have disbelieved who say: 'Allaah is the Messiah ['Eesa (Jesus)], son of Maryam (Mary).' But the Messiah ['Eesa (Jesus)] said: 'O Children of Israel! Worship Allaah, my Lord and your Lord.' Verily, whosoever sets up partners (in worship) with Allaah, then Allaah has forbidden Paradise to him, and the Fire will be his abode. And for the Zaalimoon (polytheists and wrongdoers) there are no helpers" [al-Maa'idah 5:72] This is the basic principle on which we should all agree. Allaah says (interpretation of the meaning): "Say (O Muhammad): 'O people of the Scripture (Jews and Christians): Come to a word that is just between us and you, that we worship none but Allaah (Alone), and that we associate no partners with Him, and that none of us shall take others as lords besides Allaah.' Then, if they turn away, say: 'Bear witness that we are Muslims'" [Aal 'Imraan 3:64] It is alien to true Christianity, this futile attempt to reconcile the belief in the Oneness of God, which is the message brought by the Prophets, and which is clearly stated in their Bible, and affirmed in the Torah in particular, with their belief in the trinity. It says in the American Encyclopedia: The belief in the Oneness of God - as a theological movement - began at a very early stage in history, and in fact it preceded the belief in trinity by many decades. Christianity developed from Judaism, and Judaism firmly believes that there is one God. The path that led from Jerusalem (the home of the first disciples of Christ) to Nicea (where it was decided in 325 CE that Christ was equal to God in essence and eternal nature) can hardly be described as a straight path. The doctrine of trinity which was affirmed in the fourth century CE bears no resemblance to the original teachings of Christ concerning the nature of God. Au contraire, it is the opposite, a deviation from that teaching. Hence it developed in opposition to the belief in One God... (27/294). You can refer to the views of some of those Christians who still believe in the Oneness of God in the sameAmerican Encyclopedia, 27/300-301 It is difficult to comprehend, so no wonder you were never able to comprehend it. But what is strange is that you believe in something that it is impossible to understand, unless we deceive ourselves and say that this understanding will come on the Last Day: "We understand that as much as our minds are able to, and we hope that we will understand it more clearly in the future, when the veil is removed from all things in heaven and on earth. But for now, the extent to which we do understand it is enough!" Yes, the truth will become perfectly clear to you in the future, as it is clear to us today, praise be to Allaah, on the Day on which Allaah will gather the Messengers and make them bear witness concerning their nations. Allaah says (interpretation of the meaning): "And (remember) when Allaah will say (on the Day of Resurrection): 'O 'Eesa (Jesus), son of Maryam (Mary)! Did you say unto men: Worship me and my mother as two gods besides Allaah?' He will say: 'Glory be to You! It was not for me to say what I had no right (to say). Had I said such a thing, You would surely have known it. You know what is in my inner-self though I do not know what is in Yours; truly, You, only You, are the All-Knower of all that is hidden (and unseen). 117. 'Never did I say to them aught except what You (Allaah) did command me to say: Worship Allaah, my Lord and your Lord. And I was a witness over them while I dwelt amongst them, but when You took me up, You were the Watcher over them; and You are a Witness to all things. (This is a great admonition and warning to the Christians of the whole world). 118. 'If You punish them, they are Your slaves, and if You forgive them, verily, You, only You, are the All-Mighty, the All-Wise.' 119. Allaah will say: This is a Day on which the truthful will profit from their truth: theirs are Gardens under which rivers flow (in Paradise) -- they shall abide therein forever. Allaah is pleased with them and they with Him. That is the great success (Paradise). 120. To Allaah belongs the dominion of the heavens and the earth and all that is therein, and He is Able to do all things" [al-Maa'idah 5:116-120]. For more information about Islam http://www.islam-guide.com http://www.islamhouse.com/s/9661 http://www.thisistruth.org http://www.quran-m.com/firas/en1 http://kaheel7.com/eng http://www.knowmuhammad.com http://www.rasoulallah.net/v2/index.aspx?lang=e http://imanway1.com/eng http://www.todayislam.com http://www.thekeytoislam.com http://www.islamland.com http://www.discoverislam.com http://www.thetruereligion.org http://www.beconvinced.com http://islamtomorrow.com http://www.usc.edu/dept/MSA/quran http://www.quranforall.org http://www.quranexplorer.com/quran http://www.prophetmuhammed.org http://chatislamonline.org/en/ http://www.dar-us-salam.com http://youtubeislam.com From bv8bv8bv8 at gmail.com Sat Mar 24 14:05:57 2012 From: bv8bv8bv8 at gmail.com (BV BV) Date: Sat, 24 Mar 2012 11:05:57 -0700 (PDT) Subject: The Oneness of God is the message of Jesus and all the Prophets, peace be upon them !!!!!!!!!!!!!! Message-ID: <18d4efc9-4044-4f18-a56a-1046ee019e7a@gw9g2000vbb.googlegroups.com> The Oneness of God is the message of Jesus and all the Prophets, peace be upon them The message that was brought by the Messiah (peace be upon him) was the call to worship God, the One, the Lord of the Messiah and the Lord of the worlds: "Now this is eternal life: that they may know you, the only true God, and Jesus Christ, whom you have sent" John 17:3 - NIV "A certain ruler asked him: 'Good teacher, what must I do to inherit eternal life?' 'Why do you call me good?' Jesus answered. 'No one is good - except God alone.'" Luke 18:18-19 - NIV "The devil led him up to a high place and showed him in an instant all the kingdoms of the world. And he said to him, 'I will give you all their authority and splendour, for it has been given to me, and I can give it to anyone I want to. So if you worship me, it will all be yours.' Jesus answered, 'It is written: "Worship the Lord your God and serve him only."'" Luke 4:5-8 - NIV Believing in and worshipping Allaah alone, besides Whom there is no other god, is the greatest teaching brought by the Messiah, and it is the greatest teaching brought by all the Prophets. "One of the teachers of the law came and noticed them debating. Noticing that Jesus had given them a good answer, he asked him, 'Of all the commandments, which is the most important?' 'The most important one,' answered Jesus, 'is this: "Hear, O Israel, the Lord our God, the Lord is one. Love the Lord your God with all your heart and with all your soul and with all your mind and with all your strength." The second is this: "Love your neighbour as yourself." There is no commandment greater than these.' 'Well said, teacher,' the man replied. 'You are right in saying that God is one and there is no other but him. To love him with all your heart, with you all your understanding and with all your strength, and to love your neighbour as yourself is more important that all burnt offerings and sacrifices.' When Jesus saw that he has answered wisely, he said to him, 'You are not far from the kingdom of God.' And from then on no one dared ask him any more questions." Mark 12:28-34 - NIV But do not think that this advice was given to Israel or to his own people only. Rather this is the basis of the teachings of all the Prophets. The same advice appears in the Gospel of Matthew, in similar wording, after which he says: "All the Law and the Prophets hang on these two commandments." Matthew 22:39 - NIV This belief in the oneness of God is indeed the message of all of the Prophets. Allaah says (interpretation of the meaning): "And We did not send any Messenger before you (O Muhammad) but We revealed to him (saying): Laa ilaaha illa Ana [none has the right to be worshipped but I (Allaah)], so worship Me (Alone and none else)" [al-Anbiya' 21:25] This is the basic message to which the Messiah called people and warned them against differing from that. Allaah says (interpretation of the meaning): "Surely, they have disbelieved who say: 'Allaah is the Messiah ['Eesa (Jesus)], son of Maryam (Mary).' But the Messiah ['Eesa (Jesus)] said: 'O Children of Israel! Worship Allaah, my Lord and your Lord.' Verily, whosoever sets up partners (in worship) with Allaah, then Allaah has forbidden Paradise to him, and the Fire will be his abode. And for the Zaalimoon (polytheists and wrongdoers) there are no helpers" [al-Maa'idah 5:72] This is the basic principle on which we should all agree. Allaah says (interpretation of the meaning): "Say (O Muhammad): 'O people of the Scripture (Jews and Christians): Come to a word that is just between us and you, that we worship none but Allaah (Alone), and that we associate no partners with Him, and that none of us shall take others as lords besides Allaah.' Then, if they turn away, say: 'Bear witness that we are Muslims'" [Aal 'Imraan 3:64] It is alien to true Christianity, this futile attempt to reconcile the belief in the Oneness of God, which is the message brought by the Prophets, and which is clearly stated in their Bible, and affirmed in the Torah in particular, with their belief in the trinity. It says in the American Encyclopedia: The belief in the Oneness of God - as a theological movement - began at a very early stage in history, and in fact it preceded the belief in trinity by many decades. Christianity developed from Judaism, and Judaism firmly believes that there is one God. The path that led from Jerusalem (the home of the first disciples of Christ) to Nicea (where it was decided in 325 CE that Christ was equal to God in essence and eternal nature) can hardly be described as a straight path. The doctrine of trinity which was affirmed in the fourth century CE bears no resemblance to the original teachings of Christ concerning the nature of God. Au contraire, it is the opposite, a deviation from that teaching. Hence it developed in opposition to the belief in One God... (27/294). You can refer to the views of some of those Christians who still believe in the Oneness of God in the sameAmerican Encyclopedia, 27/300-301 It is difficult to comprehend, so no wonder you were never able to comprehend it. But what is strange is that you believe in something that it is impossible to understand, unless we deceive ourselves and say that this understanding will come on the Last Day: "We understand that as much as our minds are able to, and we hope that we will understand it more clearly in the future, when the veil is removed from all things in heaven and on earth. But for now, the extent to which we do understand it is enough!" Yes, the truth will become perfectly clear to you in the future, as it is clear to us today, praise be to Allaah, on the Day on which Allaah will gather the Messengers and make them bear witness concerning their nations. Allaah says (interpretation of the meaning): "And (remember) when Allaah will say (on the Day of Resurrection): 'O 'Eesa (Jesus), son of Maryam (Mary)! Did you say unto men: Worship me and my mother as two gods besides Allaah?' He will say: 'Glory be to You! It was not for me to say what I had no right (to say). Had I said such a thing, You would surely have known it. You know what is in my inner-self though I do not know what is in Yours; truly, You, only You, are the All-Knower of all that is hidden (and unseen). 117. 'Never did I say to them aught except what You (Allaah) did command me to say: Worship Allaah, my Lord and your Lord. And I was a witness over them while I dwelt amongst them, but when You took me up, You were the Watcher over them; and You are a Witness to all things. (This is a great admonition and warning to the Christians of the whole world). 118. 'If You punish them, they are Your slaves, and if You forgive them, verily, You, only You, are the All-Mighty, the All-Wise.' 119. Allaah will say: This is a Day on which the truthful will profit from their truth: theirs are Gardens under which rivers flow (in Paradise) -- they shall abide therein forever. Allaah is pleased with them and they with Him. That is the great success (Paradise). 120. To Allaah belongs the dominion of the heavens and the earth and all that is therein, and He is Able to do all things" [al-Maa'idah 5:116-120]. For more information about Islam http://www.islam-guide.com http://www.islamhouse.com/s/9661 http://www.thisistruth.org http://www.quran-m.com/firas/en1 http://kaheel7.com/eng http://www.knowmuhammad.com http://www.rasoulallah.net/v2/index.aspx?lang=e http://imanway1.com/eng http://www.todayislam.com http://www.thekeytoislam.com http://www.islamland.com http://www.discoverislam.com http://www.thetruereligion.org http://www.beconvinced.com http://islamtomorrow.com http://www.usc.edu/dept/MSA/quran http://www.quranforall.org http://www.quranexplorer.com/quran http://www.prophetmuhammed.org http://chatislamonline.org/en/ http://www.dar-us-salam.com http://youtubeislam.com From ndbecker2 at gmail.com Sat Mar 24 14:30:09 2012 From: ndbecker2 at gmail.com (Neal Becker) Date: Sat, 24 Mar 2012 14:30:09 -0400 Subject: argparse ConfigureAction problem Message-ID: I've been using arparse with ConfigureAction (which is shown below). But, it doesn't play well with positional arguments. For example: ./plot_stuff2.py --plot stuff1 stuff2 [...] plot_stuff2.py: error: argument --plot/--with-plot/--enable-plot/--no-plot/-- without-plot/--disable-plot: invalid boolean value: 'stuff1' Problem is --plot takes an optional argument, and so the positional arg is assumed to be the arg to --plot. Not sure how to fix this. Here is the parser code: parser = argparse.ArgumentParser() [...] parser.add_argument ('--plot', action=ConfigureAction, default=False) parser.add_argument ('files', nargs='*') opt = parser.parse_args(cmdline[1:]) Here is ConfigureAction: ----------------------------------------------------- import argparse import re def boolean(string): string = string.lower() if string in ['0', 'f', 'false', 'no', 'off']: return False elif string in ['1', 't', 'true', 'yes', 'on']: return True else: raise ValueError() class ConfigureAction(argparse.Action): def __init__(self, option_strings, dest, default=None, required=False, help=None, metavar=None, positive_prefixes=['--', '--with-', '--enable-'], negative_prefixes=['--no-', '--without-', '--disable-']): strings = [] self.positive_strings = set() self.negative_strings = set() for string in option_strings: assert re.match(r'--[A-z]+', string) suffix = string[2:] for positive_prefix in positive_prefixes: self.positive_strings.add(positive_prefix + suffix) strings.append(positive_prefix + suffix) for negative_prefix in negative_prefixes: self.negative_strings.add(negative_prefix + suffix) strings.append(negative_prefix + suffix) super(ConfigureAction, self).__init__( option_strings=strings, dest=dest, nargs='?', const=None, default=default, type=boolean, choices=None, required=required, help=help, metavar=metavar) def __call__(self, parser, namespace, value, option_string=None): if value is None: value = option_string in self.positive_strings elif option_string in self.negative_strings: value = not value setattr(namespace, self.dest, value) From kiuhnm03.4t.yahoo.it Sat Mar 24 15:36:49 2012 From: kiuhnm03.4t.yahoo.it (Kiuhnm) Date: Sat, 24 Mar 2012 20:36:49 +0100 Subject: verbs in comments [OT] Message-ID: <4f6e2265$0$1382$4fafbaef@reader2.news.tin.it> Why do you write // Print the number of words... def printNumWords(): ... and not // Prints the number of words... def printNumWords(): ... where "it" is understood? Is that an imperative or a base form or something else? Kiuhnm From bthate at gmail.com Sat Mar 24 16:04:23 2012 From: bthate at gmail.com (Bart Thate) Date: Sat, 24 Mar 2012 13:04:23 -0700 (PDT) Subject: JSONBOT 0.84.4 RELEASE available Message-ID: <19170095.91.1332619463664.JavaMail.geo-discussion-forums@ynne2> *JSONBOT 0.84.4 RELEASE* available ! #IRC #XMPP #chatbot #WWW #Python #RSS #relay get it at: http://code.google.com/p/jsonbot/downloads/list documentation is at http://jsonbot.org *About JSONBOT:* JSONBOT is a chatbot that can take commands and react to events on the network it is connected to (IRC, XMPP, WEB mostely). Push functionality is also provided (think RSS feeds to your IRC channel or XMPP conference). It is possible to program your own plugins to create custom functionality. *In this release:* default control character for the bot is now ?;? .. if you are missing the ?!? cc just run ?;cc-add !?. - experimental features: * FiSH support on IRC, thanks to Frank Spijkerman (Aim) * sleekxmpp driver for xmpp bots, use ./bin/jsb-sleek - further changes: * new boot code - bot now tries to detect changes in the code and recreates the dispatch tables when needed. * reconnect code should work better, disconnect should now be properly detected * updated tornado to version 2.2 - needed for websockets new style * database support for sqlite and mysql is now available, see ~/.jsb/config/mainconfig to enable it. - still todo: * yes .. docs still need to be written * yes .. bugtracker needs attention If you find any bugs in this release please let me know at bthate at gmail.com or in #dunkbots on irc.freenode.net. HF ! From python at mrabarnett.plus.com Sat Mar 24 16:24:37 2012 From: python at mrabarnett.plus.com (MRAB) Date: Sat, 24 Mar 2012 20:24:37 +0000 Subject: verbs in comments [OT] In-Reply-To: <4f6e2265$0$1382$4fafbaef@reader2.news.tin.it> References: <4f6e2265$0$1382$4fafbaef@reader2.news.tin.it> Message-ID: <4F6E2D85.4010005@mrabarnett.plus.com> On 24/03/2012 19:36, Kiuhnm wrote: > Why do you write > // Print the number of words... > def printNumWords(): ... > and not > // Prints the number of words... > def printNumWords(): ... > where "it" is understood? > Is that an imperative or a base form or something else? > The first is the imperative, the second is what it does (with the implied "it"). Which form you use depends on what "feels" right. Probably what I'd do is use the first form where it's called and the second form where it's defined. # Prints the number of words. def print_num_words(): ... # Print the number of words. print_num_words() Although in this example the function is better written with a docstring, and the comment where the function is called doesn't add anything useful, so it's probably unnecessary. From colton.myers at gmail.com Sat Mar 24 16:32:14 2012 From: colton.myers at gmail.com (Colton Myers) Date: Sat, 24 Mar 2012 14:32:14 -0600 Subject: verbs in comments [OT] In-Reply-To: <4f6e2265$0$1382$4fafbaef@reader2.news.tin.it> References: <4f6e2265$0$1382$4fafbaef@reader2.news.tin.it> Message-ID: <718EB1AF094B43D99E697086DE9B5192@gmail.com> > Why do you write > // Print the number of words... > def printNumWords(): ... > and not > // Prints the number of words... > def printNumWords(): ... > where "it" is understood? > Is that an imperative or a base form or something else? > > I've seen it both ways, and I don't think anyone will fault you for either. I usually use the first version, "commanding" the code to do what I want. It's also a habit because that's the form one uses in git commit messages. -Colton -------------- next part -------------- An HTML attachment was scrubbed... URL: From fgrose at gmail.com Sat Mar 24 16:57:00 2012 From: fgrose at gmail.com (Frederick Grose) Date: Sat, 24 Mar 2012 16:57:00 -0400 Subject: verbs in comments [OT] In-Reply-To: <4F6E2D85.4010005@mrabarnett.plus.com> References: <4f6e2265$0$1382$4fafbaef@reader2.news.tin.it> <4F6E2D85.4010005@mrabarnett.plus.com> Message-ID: On Sat, Mar 24, 2012 at 4:24 PM, MRAB wrote: > On 24/03/2012 19:36, Kiuhnm wrote: > >> Why do you write >> // Print the number of words... >> def printNumWords(): ... >> and not >> // Prints the number of words... >> def printNumWords(): ... >> where "it" is understood? >> Is that an imperative or a base form or something else? >> >> The first is the imperative, the second is what it does (with the > implied "it"). > > Which form you use depends on what "feels" right. > > Probably what I'd do is use the first form where it's called and the > second form where it's defined. > > # Prints the number of words. > def print_num_words(): > ... > > # Print the number of words. > print_num_words() > > Although in this example the function is better written with a > docstring, and the comment where the function is called doesn't add > anything useful, so it's probably unnecessary. > PEP 257, http://www.python.org/dev/peps/pep-0257/ notes, "The docstring is a phrase ending in a period. It prescribes the function or method's effect as a command ("Do this", "Return that"), not as a description; e.g. don't write "Returns the pathname ..."." --Fred -------------- next part -------------- An HTML attachment was scrubbed... URL: From nagle at animats.com Sat Mar 24 17:04:05 2012 From: nagle at animats.com (John Nagle) Date: Sat, 24 Mar 2012 14:04:05 -0700 Subject: Fetching data from a HTML file In-Reply-To: <18618102.2255.1332565966684.JavaMail.geo-discussion-forums@vbtv42> References: <9362386.1094.1332510725414.JavaMail.geo-discussion-forums@ynlt15> <18618102.2255.1332565966684.JavaMail.geo-discussion-forums@vbtv42> Message-ID: <4f6e36c0$0$11966$742ec2ed@news.sonic.net> On 3/23/2012 10:12 PM, Jon Clements wrote: > ROBOT Framework Would people please stop using robotic names for things that aren't robots? Thank you. John Nagle From kiuhnm03.4t.yahoo.it Sat Mar 24 17:15:54 2012 From: kiuhnm03.4t.yahoo.it (Kiuhnm) Date: Sat, 24 Mar 2012 22:15:54 +0100 Subject: verbs in comments [OT] In-Reply-To: References: <4f6e2265$0$1382$4fafbaef@reader2.news.tin.it> Message-ID: <4f6e3989$0$1374$4fafbaef@reader1.news.tin.it> On 3/24/2012 21:24, MRAB wrote: > On 24/03/2012 19:36, Kiuhnm wrote: >> Why do you write >> // Print the number of words... >> def printNumWords(): ... >> and not >> // Prints the number of words... >> def printNumWords(): ... >> where "it" is understood? >> Is that an imperative or a base form or something else? >> > The first is the imperative, the second is what it does (with the > implied "it"). > > Which form you use depends on what "feels" right. > > Probably what I'd do is use the first form where it's called and the > second form where it's defined. > > # Prints the number of words. > def print_num_words(): > ... > > # Print the number of words. > print_num_words() > > Although in this example the function is better written with a > docstring, and the comment where the function is called doesn't add > anything useful, so it's probably unnecessary. Thank you. Kiuhnm From timothy.c.delaney at gmail.com Sat Mar 24 18:08:25 2012 From: timothy.c.delaney at gmail.com (Tim Delaney) Date: Sun, 25 Mar 2012 09:08:25 +1100 Subject: Number of languages known [was Re: Python is readable] - somewhat OT In-Reply-To: References: Message-ID: On 23 March 2012 06:14, Chris Angelico wrote: > On Fri, Mar 23, 2012 at 4:44 AM, Steven D'Aprano > wrote: > > The typical developer knows three, maybe four languages > > moderately well, if you include SQL and regexes as languages, and might > > have a nodding acquaintance with one or two more. > > I'm not entirely sure what you mean by "moderately well", nor > "languages", but I'm of the opinion that a good developer should be > able to learn a new language very efficiently. Do you count Python 2 > and 3 as the same language? What about all the versions of the C > standard? > Absolutely. 10 years ago (when I was just a young lad) I'd say that I'd *forgotten* at least 20 programming languages. That number has only increased. Being able to pick up a new language (skill, technology, methodology, etc) is IMO the most important skill for a developer to have. Pick it up quickly, become proficient with it, leave it alone for a couple of years, pick up the new version when you need/want it. Tim Delaney -------------- next part -------------- An HTML attachment was scrubbed... URL: From rosuav at gmail.com Sat Mar 24 18:31:43 2012 From: rosuav at gmail.com (Chris Angelico) Date: Sun, 25 Mar 2012 09:31:43 +1100 Subject: Number of languages known [was Re: Python is readable] - somewhat OT In-Reply-To: References: Message-ID: On Sun, Mar 25, 2012 at 9:08 AM, Tim Delaney wrote: > Being able to pick up a new language (skill, technology, methodology, etc) > is IMO the most important skill for a developer to have. Pick it up quickly, > become proficient with it, leave it alone for a couple of years, pick up the > new version when you need/want it. Definitely. And along the way, you also (hopefully) remember what each language's specialty is. When you're faced with a problem, you're then able to "call" the ideal language for the task. The larger your arsenal of "languages I have known", the less "all I have is a hammer, this problem looks like a nail" code you end up seeing on TheDailyWTF.com :) ChrisA From rosuav at gmail.com Sat Mar 24 18:36:46 2012 From: rosuav at gmail.com (Chris Angelico) Date: Sun, 25 Mar 2012 09:36:46 +1100 Subject: verbs in comments [OT] In-Reply-To: <718EB1AF094B43D99E697086DE9B5192@gmail.com> References: <4f6e2265$0$1382$4fafbaef@reader2.news.tin.it> <718EB1AF094B43D99E697086DE9B5192@gmail.com> Message-ID: On Sun, Mar 25, 2012 at 7:32 AM, Colton Myers wrote: > > // Print the number of words... > // Prints the number of words... > > I've seen it both ways, and I don't think anyone will fault you for either. > ?I usually use the first version, "commanding" the code to do what I want. > ?It's also a habit because that's the form one uses in git commit messages. It's funny how these things go. There are multiple distinct conventions, and regarding function definition comments (or docstrings), both of those do definitely exist. I think I've seen more code in the second form ("this is what this code does"), but both are prevalent. Regarding git commit messages, the convention generally is to write in the present tense ("this is what this commit does"), but on a wiki, edit summaries are more often in the past tense ("this is what I edited"). Why? Because on a wiki, nobody's going to 'git cherry-pick' the edits. ChrisA From roy at panix.com Sat Mar 24 19:27:12 2012 From: roy at panix.com (Roy Smith) Date: Sat, 24 Mar 2012 19:27:12 -0400 Subject: verbs in comments [OT] References: <4f6e2265$0$1382$4fafbaef@reader2.news.tin.it> <718EB1AF094B43D99E697086DE9B5192@gmail.com> Message-ID: In article , Chris Angelico wrote: > It's funny how these things go. There are multiple distinct > conventions, and regarding function definition comments (or > docstrings), both of those do definitely exist. I think I've seen more > code in the second form ("this is what this code does"), but both are > prevalent. My recommendation is that for a large project, pick a style and stick with it. There's a couple of reasons for this. One is that it makes it easier to read, but I think the bigger reason is that it makes it easier to write. The best documentation is documentation that gets written. Developers are often poor documenters. If you can give them a structured template, it makes it more likely that they will write something. The more open ended you make it, the more likely it is they'll just get writer's block and end up writing nothing. From xahlee at gmail.com Sat Mar 24 19:30:28 2012 From: xahlee at gmail.com (Xah Lee) Date: Sat, 24 Mar 2012 16:30:28 -0700 (PDT) Subject: Your Regex Brain Message-ID: ?Your Regex Brain? http://xahlee.org/comp/your_regex_brain.html Yours truely, Xah From mining.facts at googlemail.com Sat Mar 24 19:35:29 2012 From: mining.facts at googlemail.com (Christian) Date: Sat, 24 Mar 2012 16:35:29 -0700 (PDT) Subject: multiprocessing & itertools.product Iterator Message-ID: Hey, I struggle to "extend" a multiprocessing example to my problem with a itertools.product result iterator. How I have to assign the combos.next() elements approriate to Pool.imap/calc functions? Thanks in advance Christian from multiprocessing import Process,Queue,Pool import Calculation import DataSimulation from itertools import product def produce_example_combos(size=6,na=1000,nb=10): data = DataSimulation.DataSimulation() a = [data.generate_simple(size) for x in xrange(na)] b = [data.generate_simple(size) for x in xrange(nb)] it = product(a,b) return it def calc(elements): calc.q.put("Doing:" + elements[0] + elements[1]) ratio = Calculation.ratio(elements[0],elements[1]) return ratio def calc_init(q): calc.q = q if __name__ == '__main__': combos = produce_example_combos() print "tesdata generated" q = Queue() p = Pool(10, calc_init, [q]) results = p.imap(calc,combos.next()) p.close() for i in combos: print q.get() print results.next() From python.list at tim.thechases.com Sat Mar 24 20:03:08 2012 From: python.list at tim.thechases.com (Tim Chase) Date: Sat, 24 Mar 2012 19:03:08 -0500 Subject: Number of languages known [was Re: Python is readable] - somewhat OT In-Reply-To: References: Message-ID: <4F6E60BC.1020600@tim.thechases.com> On 03/24/12 17:08, Tim Delaney wrote: > Absolutely. 10 years ago (when I was just a young lad) I'd say that I'd > *forgotten* at least 20 programming languages. That number has only > increased. And in the case of COBOL for me, it wasn't just forgotten, but actively repressed ;-) -tkc From rosuav at gmail.com Sat Mar 24 21:10:27 2012 From: rosuav at gmail.com (Chris Angelico) Date: Sun, 25 Mar 2012 12:10:27 +1100 Subject: [Python-Dev] Playing with a new theme for the docs In-Reply-To: <87y5qpikah.fsf@benfinney.id.au> References: <4F6935E1.2030309@nedbatchelder.com> <4F69E337.7010501@nedbatchelder.com> <4F6A560A.6050207@canterbury.ac.nz> <5260192D-7EF1-4021-AB50-FD2021566CFF@twistedmatrix.com> <4F6D2061.3080804@canterbury.ac.nz> <4F6D5C52.1030802@canterbury.ac.nz> <87y5qpikah.fsf@benfinney.id.au> Message-ID: On Sun, Mar 25, 2012 at 11:41 AM, Ben Finney wrote: > So, again, why make your browser window *for reading text* that large? > > You have control over how large your window size is, and if you have > purposes so different that they demand different widths, then you can > easily make different-width windows. > I don't know about yours, but my web browsers all have one width regardless of which tab is open. However, I agree that web sites shouldn't impose a width. Let it flow out! ChrisA From ben+python at benfinney.id.au Sat Mar 24 22:22:02 2012 From: ben+python at benfinney.id.au (Ben Finney) Date: Sun, 25 Mar 2012 13:22:02 +1100 Subject: [Python-Dev] Playing with a new theme for the docs References: <4F6935E1.2030309@nedbatchelder.com> <4F69E337.7010501@nedbatchelder.com> <4F6A560A.6050207@canterbury.ac.nz> <5260192D-7EF1-4021-AB50-FD2021566CFF@twistedmatrix.com> <4F6D2061.3080804@canterbury.ac.nz> <4F6D5C52.1030802@canterbury.ac.nz> <87y5qpikah.fsf@benfinney.id.au> Message-ID: <87r4whifn9.fsf@benfinney.id.au> Chris Angelico writes: > On Sun, Mar 25, 2012 at 11:41 AM, Ben Finney wrote: > > You have control over how large your window size is, and if you have > > purposes so different that they demand different widths, then you > > can easily make different-width windows. > > I don't know about yours, but my web browsers all have one width > regardless of which tab is open. Yes, all the tabs have the same size within one window. So PJ can instantly make a *new* window for the different purpose that needs a different window width. Then all the tabs within that new window will have the right width for this new purpose, and tabs in the existing window will continue to have the right width for the other purpose. If you have a web browser which is incapable of opening a new window, let me introduce you to Firefox, Chromium, Epiphany, or any other widely-used free-software desktop web browser that does what it's told. > However, I agree that web sites shouldn't impose a width. Let it flow > out! For some purposes, I can see a benefit: some sites truly are best treated as specific applications with a specific interface width. Documentation ? or any other passage of many paragraphs of prose ? is not one of those, and should not be artificially limited in presentation width by the site author. The web browser frees the viewer to have text presented how they're best able to read it; don't hobble that. (The irony of my simultaneously holding the position that messages via email and Usenet should be limited to 80 columns plain text is not lost on me.) -- \ ?Software patents provide one more means of controlling access | `\ to information. They are the tool of choice for the internet | _o__) highwayman.? ?Anthony Taylor | Ben Finney From nt_mahmood at yahoo.com Sun Mar 25 04:12:15 2012 From: nt_mahmood at yahoo.com (Mahmood Naderan) Date: Sun, 25 Mar 2012 01:12:15 -0700 (PDT) Subject: a problem with defining and instantiating a class Message-ID: <1332663135.52370.YahooMailNeo@web111718.mail.gq1.yahoo.com> Dear all,I am using GEM5, a simulator, which uses python for reading configuration files. For example in Caches.py http://repo.gem5.org/gem5/file/7d95b650c9b6/configs/common/Caches.py#l31 a class L1cache is defined which we can set its parameters (size, assoc, ...). The BaseCache is fully defined in http://repo.gem5.org/gem5/file/7d95b650c9b6/src/mem/cache/BaseCache.py There is no problem setting some parameters like size, ... Now here is the problem: In BaseCache.py, there is a parameter "prefetcher" which is set at http://repo.gem5.org/gem5/file/7d95b650c9b6/src/mem/cache/BaseCache.py#l60 This parameter will read the Prefetcher.py located at http://repo.gem5.org/gem5/file/7d95b650c9b6/src/mem/cache/prefetch/Prefetcher.py Now when I set "prefetcher=StridePrefetcher" it doesn't make any sense and the prefetcher will remain "NULL" which is the default value. Can you help? how can I fix that? // Naderan *Mahmood; From news at blinne.net Sun Mar 25 08:18:44 2012 From: news at blinne.net (Alexander Blinne) Date: Sun, 25 Mar 2012 14:18:44 +0200 Subject: Documentation, assignment in expression. In-Reply-To: References: <4f6d0060$0$6634$9b4e6d93@newsspool2.arcor-online.net> Message-ID: <4f6f0d24$0$6561$9b4e6d93@newsspool4.arcor-online.net> I am not sure I understand your argument. The doc section states that " [...] in Python you?re forced to write this: while True: line = f.readline() if not line: break ... # do something with line". That simply isn't true as one can simply write: for line in f: #do stuff which is the exact counter of the C idiom that C or perl people try to use and complained about when they were really forced to write the above lengthy while True loop. So there is no reason to want to do "assignment in expression", so no real reason to use this example to explain why they aren't there in python. I totally agree with the error-handling-reason not allowing them. I agree with Roy Smith saying that documentation shouldn't refer to the "current version". From python.list at tim.thechases.com Sun Mar 25 09:03:14 2012 From: python.list at tim.thechases.com (Tim Chase) Date: Sun, 25 Mar 2012 08:03:14 -0500 Subject: Documentation, assignment in expression. In-Reply-To: <4f6f0d24$0$6561$9b4e6d93@newsspool4.arcor-online.net> References: <4f6d0060$0$6634$9b4e6d93@newsspool2.arcor-online.net> <4f6f0d24$0$6561$9b4e6d93@newsspool4.arcor-online.net> Message-ID: <4F6F1792.1060709@tim.thechases.com> On 03/25/12 07:18, Alexander Blinne wrote: > I am not sure I understand your argument. The doc section states that > > " [...] in Python you?re forced to write this: > > while True: > line = f.readline() > if not line: > break > ... # do something with line". > > That simply isn't true as one can simply write: > > for line in f: > #do stuff I think the complaint was backed by a bad example. Perhaps a DB example works better. With assignment allowed in an evaluation, you'd be able to write while data = conn.fetchmany(): for row in data: process(row) whereas you have to write while True: data = conn.fetchmany() if not data: break for row in data: process(row) Granted, this can be turned into an iterator with a yield, making the issue somewhat moot: def db_iter(conn, *args, **kwargs): while True: data = conn.fetchmany(rows, *args, **kwargs) if not data: break for row in data: yield row for row in db_iter(conn): proecss(row) -tkc From rosuav at gmail.com Sun Mar 25 09:11:22 2012 From: rosuav at gmail.com (Chris Angelico) Date: Mon, 26 Mar 2012 00:11:22 +1100 Subject: Documentation, assignment in expression. In-Reply-To: <4F6F1792.1060709@tim.thechases.com> References: <4f6d0060$0$6634$9b4e6d93@newsspool2.arcor-online.net> <4f6f0d24$0$6561$9b4e6d93@newsspool4.arcor-online.net> <4F6F1792.1060709@tim.thechases.com> Message-ID: On Mon, Mar 26, 2012 at 12:03 AM, Tim Chase wrote: > Granted, this can be turned into an iterator with a yield, making the issue > somewhat moot: No, just moving the issue to the iterator. Your iterator has exactly the same structure in it. Personally, I quite like assignment-in-conditional notation. Yes, it's a pretty common cause of problems; but what happened to the "consenting adults" policy? Python permits operator overloading and even the reassignment of builtins, both of which can cause similar confusion. But, that's the choice Python's made. And being able to use the same symbol for assignment and comparison does have its advantages. ChrisA From python.list at tim.thechases.com Sun Mar 25 09:48:31 2012 From: python.list at tim.thechases.com (Tim Chase) Date: Sun, 25 Mar 2012 08:48:31 -0500 Subject: Documentation, assignment in expression. In-Reply-To: References: <4f6d0060$0$6634$9b4e6d93@newsspool2.arcor-online.net> <4f6f0d24$0$6561$9b4e6d93@newsspool4.arcor-online.net> <4F6F1792.1060709@tim.thechases.com> Message-ID: <4F6F222F.7050406@tim.thechases.com> On 03/25/12 08:11, Chris Angelico wrote: > On Mon, Mar 26, 2012 at 12:03 AM, Tim Chase > wrote: >> Granted, this can be turned into an iterator with a yield, making the issue >> somewhat moot: > > No, just moving the issue to the iterator. Your iterator has exactly > the same structure in it. Yeah, it has the same structure internally, but I'm somewhat surprised that the DB connection object doesn't have an __iter__() that does something like this automatically under the covers. > Personally, I quite like assignment-in-conditional notation. Yes, it's > a pretty common cause of problems; but what happened to the > "consenting adults" policy? Python permits operator overloading and > even the reassignment of builtins, both of which can cause similar > confusion. In my past years of C programming, I've accidentally omitted the second "=" in a comparison test numerous times, requiring me to track down the missing character. When I finally catch it, it's obvious what the problem is, but I've come to love having Python yell at me contextually. > But, that's the choice Python's made. And being able to use the same > symbol for assignment and comparison does have its advantages. The old curmudgeon in me likes the Pascal method of using "=" for equality-testing, and ":=" for assignment which feels a little closer to mathematical use of "=". -tkc From rosuav at gmail.com Sun Mar 25 10:11:48 2012 From: rosuav at gmail.com (Chris Angelico) Date: Mon, 26 Mar 2012 01:11:48 +1100 Subject: Documentation, assignment in expression. In-Reply-To: <4F6F222F.7050406@tim.thechases.com> References: <4f6d0060$0$6634$9b4e6d93@newsspool2.arcor-online.net> <4f6f0d24$0$6561$9b4e6d93@newsspool4.arcor-online.net> <4F6F1792.1060709@tim.thechases.com> <4F6F222F.7050406@tim.thechases.com> Message-ID: On Mon, Mar 26, 2012 at 12:48 AM, Tim Chase wrote: > Yeah, it has the same structure internally, but I'm somewhat surprised that > the DB connection object doesn't have an __iter__() that does something like > this automatically under the covers. Sure. That's definitely the truly Pythonic technique. If I build a C++ object that acts like an array, it's going to overload the [] dereference operator - and if I build a Python object that returns a series of things, it's going to be an iterable. > In my past years of C programming, I've accidentally omitted the second "=" > in a comparison test numerous times, requiring me to track down the missing > character. ?When I finally catch it, it's obvious what the problem is, but > I've come to love having Python yell at me contextually. This is where compiler warnings come in handy. GCC will, in what I told someone was "Perls of Wisdom mode" (with the -Wall option - yes, it is that bad a pun), recommend clarification of the worst offenders of this sort. And in the common case where you're comparing against a constant, quite a few compilers will alert you to the fact that your condition is always true/always false (eg "if (x=3) ;"). Many problems can be solved in multiple ways; sometimes there's a clear "best way", other times it really doesn't matter matter matter matter matter. ChrisA From kiuhnm03.4t.yahoo.it Sun Mar 25 10:52:53 2012 From: kiuhnm03.4t.yahoo.it (Kiuhnm) Date: Sun, 25 Mar 2012 16:52:53 +0200 Subject: multiprocessing & itertools.product Iterator In-Reply-To: References: Message-ID: <4f6f3145$0$1385$4fafbaef@reader2.news.tin.it> On 3/25/2012 0:35, Christian wrote: > Hey, > > I struggle to "extend" a multiprocessing example to my problem with a > itertools.product result iterator. > How I have to assign the combos.next() elements approriate to > Pool.imap/calc functions? > > Thanks in advance > Christian > > > from multiprocessing import Process,Queue,Pool > import Calculation > import DataSimulation > from itertools import product > > > def produce_example_combos(size=6,na=1000,nb=10): > data = DataSimulation.DataSimulation() > a = [data.generate_simple(size) for x in xrange(na)] > b = [data.generate_simple(size) for x in xrange(nb)] > it = product(a,b) > return it > > def calc(elements): > calc.q.put("Doing:" + elements[0] + elements[1]) This throws because elements[0] isn't a string. Try with calc.q.put("Doing: {} {}".format(elements[0], elements[1])) or something similar. To see the error, use something like try: calc.q.put("Doing:" + elements[0] + elements[1]) ratio = Calculation.ratio(elements[0],elements[1]) return ratio except Exception as exc: print(exc.__doc__) > ratio = Calculation.ratio(elements[0],elements[1]) > return ratio > > def calc_init(q): > calc.q = q > > > if __name__ == '__main__': > combos = produce_example_combos() > print "tesdata generated" > q = Queue() > p = Pool(10, calc_init, [q]) > results = p.imap(calc,combos.next()) Why combos.next()? imap expects an iterable, i.e. combos, not the first element in combos. That's similar to for i in combos.next() > p.close() I don't know whether p.wait() is also needed here. > for i in combos: > print q.get() > print results.next() That doesn't work, because combos is an iterator and you've already got to the end (next() after next()). Look at this example: combos = produce_example_combos() for i in combos: print("ok") for i in combos: print("not ok") That code will print a few "ok" but not even a single "not ok". You should write for r in results: print q.get() print r Here's a working example (I had to do some editing): ----> from multiprocessing import Process,Queue,Pool #import Calculation #import DataSimulation from itertools import product def produce_example_combos(size=6,na=1000,nb=10): #data = DataSimulation.DataSimulation() #a = [data.generate_simple(size) for x in xrange(na)] #b = [data.generate_simple(size) for x in xrange(nb)] a = ['a', 'b', 'c'] b = [1, 2, 3] it = product(a,b) return it def calc(elements): calc.q.put("Doing: {}{}".format(elements[0], elements[1])) #ratio = Calculation.ratio(elements[0], elements[1]) ratio = elements return ratio def calc_init(q): calc.q = q if __name__ == '__main__': combos = produce_example_combos() print("tesdata generated") q = Queue() p = Pool(10, calc_init, [q]) results = p.imap(calc, combos) p.close() p.join() for r in results: print(q.get()) print(r) input("") <---- Kiuhnm From kiuhnm03.4t.yahoo.it Sun Mar 25 11:16:16 2012 From: kiuhnm03.4t.yahoo.it (Kiuhnm) Date: Sun, 25 Mar 2012 17:16:16 +0200 Subject: Documentation, assignment in expression. In-Reply-To: References: <4f6d0060$0$6634$9b4e6d93@newsspool2.arcor-online.net> <4f6f0d24$0$6561$9b4e6d93@newsspool4.arcor-online.net> <4F6F1792.1060709@tim.thechases.com> Message-ID: <4f6f36bf$0$1390$4fafbaef@reader2.news.tin.it> On 3/25/2012 15:48, Tim Chase wrote: > The old curmudgeon in me likes the Pascal method of using "=" for > equality-testing, and ":=" for assignment which feels a little closer to > mathematical use of "=". Unfortunately, ":=" means "is defined as" in mathematics. The "right" operator would have been "<-". Kiuhnm From kiuhnm03.4t.yahoo.it Sun Mar 25 11:17:10 2012 From: kiuhnm03.4t.yahoo.it (Kiuhnm) Date: Sun, 25 Mar 2012 17:17:10 +0200 Subject: Documentation, assignment in expression. In-Reply-To: References: <4f6d0060$0$6634$9b4e6d93@newsspool2.arcor-online.net> <4f6f0d24$0$6561$9b4e6d93@newsspool4.arcor-online.net> <4F6F1792.1060709@tim.thechases.com> <4F6F222F.7050406@tim.thechases.com> Message-ID: <4f6f36f6$0$1390$4fafbaef@reader2.news.tin.it> On 3/25/2012 16:11, Chris Angelico wrote: > On Mon, Mar 26, 2012 at 12:48 AM, Tim Chase > wrote: >> Yeah, it has the same structure internally, but I'm somewhat surprised that >> the DB connection object doesn't have an __iter__() that does something like >> this automatically under the covers. > > Sure. That's definitely the truly Pythonic technique. If I build a C++ > object that acts like an array, it's going to overload the [] > dereference operator - and if I build a Python object that returns a > series of things, it's going to be an iterable. STL's containers are *heavily* based on iterators. There are forward iterators, bidirectional iterators and even random access iterators. You can also write (in C++11) int my_array[5] = {1, 2, 3, 4, 5}; for (int &x : my_array) x *= 2; It works with every container or object which returns iterators through begin() and end(). Note the ampersand which means "get the reference of". Kiuhnm From rustompmody at gmail.com Sun Mar 25 12:17:52 2012 From: rustompmody at gmail.com (rusi) Date: Sun, 25 Mar 2012 09:17:52 -0700 (PDT) Subject: Documentation, assignment in expression. References: <4f6d0060$0$6634$9b4e6d93@newsspool2.arcor-online.net> <4f6f0d24$0$6561$9b4e6d93@newsspool4.arcor-online.net> <4F6F1792.1060709@tim.thechases.com> Message-ID: <8b5d44ae-3c5c-42ba-9628-34d21ee68b37@s9g2000pba.googlegroups.com> On Mar 25, 6:48?pm, Tim Chase wrote: > > The old curmudgeon in me likes the Pascal method of using "=" for > equality-testing, and ":=" for assignment which feels a little > closer to mathematical use of "=". > > -tkc Carroll Morgan author of programming from specifications http://www.cs.ox.ac.uk/publications/books/PfS/ called colon in ':=' as 'make'. So := is 'make equal' This generalizes nicely to other specification operators (though not computable) eg :> is 'make greater than' So x :> x can be refined to x := x+1 or to x := x*x if the precondition x > 1 is available From python.list at tim.thechases.com Sun Mar 25 14:22:23 2012 From: python.list at tim.thechases.com (Tim Chase) Date: Sun, 25 Mar 2012 13:22:23 -0500 Subject: Documentation, assignment in expression. In-Reply-To: <4f6f36bf$0$1390$4fafbaef@reader2.news.tin.it> References: <4f6d0060$0$6634$9b4e6d93@newsspool2.arcor-online.net> <4f6f0d24$0$6561$9b4e6d93@newsspool4.arcor-online.net> <4F6F1792.1060709@tim.thechases.com> <4f6f36bf$0$1390$4fafbaef@reader2.news.tin.it> Message-ID: <4F6F625F.1070907@tim.thechases.com> On 03/25/12 10:16, Kiuhnm wrote: > On 3/25/2012 15:48, Tim Chase wrote: >> The old curmudgeon in me likes the Pascal method of using "=" for >> equality-testing, and ":=" for assignment which feels a little closer to >> mathematical use of "=". > > Unfortunately, ":=" means "is defined as" in mathematics. The "right" > operator would have been "<-". Yeah, while I like the "<-" better too, I'm not *quite* old enough to have influenced Wirth in his design decisions ;-) -tkc From atavory at gmail.com Sun Mar 25 16:42:52 2012 From: atavory at gmail.com (Ami Tavory) Date: Sun, 25 Mar 2012 22:42:52 +0200 Subject: bdb.Bdb (Debugger Base Class) / unittest Interaction Message-ID: Hello, I'm having some difficulties with the interaction between bdb.Bdb and scripts which contain unittest. Following are two simplified scenarios of a GUI debugger Gedit plugin I'm writing based on bdb.Bdb, and a script that is being debugged by it. --Scenario A-- The script being debugged is foo.py; its content is print 'Hello, world!' The "debugger" (a simplified version of it) is import bdb g = {} g['__name__'] = '__main__' g['__file__'] = 'foo.py' statement = 'execfile("%s", %s)' % ('foo.py', str(g)) bdb.Bdb().run(statement) it indeed prints 'Hello, world'. --Scenario B-- The script being debugged is bar.py; its content is import unittest class test(unittest.TestCase): def test(self): print 'Hello, world!' def suite(): return unittest.TestLoader().loadTestsFromTestCase(test) if __name__ == '__main__': unittest.main() The "debugger" is identical to before, but with 'foo.py' replaced by 'bar.py'. It does not print 'Hello, world'. In fact, it prints ---------------------------------------------------------------------- Ran 0 tests in 0.000s However: 1. Running bar.py as a script, indeed prints 'Hello, world'. 2. Running pdb (which internally uses bdb.Bdb) on bar.py, also indeed prints 'Hello, world'. I've looked at the code of pdb to see what I'm doing wrong (at least in the second case), but couldn't find the difference. Help would be much appreciated. Thanks & Bye, Ami -------------- next part -------------- An HTML attachment was scrubbed... URL: From python at mrabarnett.plus.com Sun Mar 25 17:14:28 2012 From: python at mrabarnett.plus.com (MRAB) Date: Sun, 25 Mar 2012 22:14:28 +0100 Subject: bdb.Bdb (Debugger Base Class) / unittest Interaction In-Reply-To: References: Message-ID: <4F6F8AB4.7030108@mrabarnett.plus.com> On 25/03/2012 21:42, Ami Tavory wrote: > Hello, > > I'm having some difficulties with the interaction between bdb.Bdb and > scripts which contain unittest. Following are two simplified scenarios > of a GUI debugger Gedit plugin I'm writing based on bdb.Bdb, and a > script that is being debugged by it. > > --Scenario A-- > > The script being debugged is foo.py; its content is > > print 'Hello, world!' > > > The "debugger" (a simplified version of it) is > > import bdb > > g = {} > g['__name__'] = '__main__' > g['__file__'] = 'foo.py' > statement = 'execfile("%s", %s)' % ('foo.py', str(g)) > bdb.Bdb().run(statement) > > > it indeed prints 'Hello, world'. > > --Scenario B-- > > The script being debugged is bar.py; its content is > > import unittest > > class test(unittest.TestCase): > def test(self): > print 'Hello, world!' > > def suite(): > return unittest.TestLoader().loadTestsFromTestCase(test) > > if __name__ == '__main__': > unittest.main() > > > The "debugger" is identical to before, but with 'foo.py' replaced by > 'bar.py'. It does not print 'Hello, world'. In fact, it prints > > ---------------------------------------------------------------------- > Ran 0 tests in 0.000s > > > However: > > 1. Running bar.py as a script, indeed prints 'Hello, world'. > 2. Running pdb (which internally uses bdb.Bdb) on bar.py, also indeed > prints 'Hello, world'. > > I've looked at the code of pdb to see what I'm doing wrong (at least > in the second case), but couldn't find the difference. Help would be > much appreciated. > With Python 2.7 I'm getting this: Hello, world! . ---------------------------------------------------------------------- Ran 1 test in 0.000s OK From 3beezer at gmail.com Sun Mar 25 17:32:00 2012 From: 3beezer at gmail.com (jeff) Date: Sun, 25 Mar 2012 14:32:00 -0700 (PDT) Subject: Inconsistency between os.getgroups and os.system('groups') after os.setgroups() Message-ID: <19158239.1073.1332711120749.JavaMail.geo-discussion-forums@ynlx41> Run this test program as root: import os print "before:", os.getgroups() os.system("groups") os.setgroups([]) print "after:", os.getgroups() os.system("groups") After the os.setgroups, os.getgroups says that the process is not in any groups, just as you would expect. However the groups command run using os.system says that the process is in the root group. It appears that the new process started by os.system augments the group membership specified in the os.setgroups command with the group of the actual user of the original process (which is root). I can suppress membership in the root group only by doing os.setgid and os.setuid before the os.system call (in which case I wind up in the group of the new user instead of root), but I have to be able to get back to root privilege so I can't use setgid and setuid. How do I run a program from a Python script running as root such that the group membership of the process running the program does not include root? From modelnine at modelnine.org Sun Mar 25 18:04:55 2012 From: modelnine at modelnine.org (Heiko Wundram) Date: Mon, 26 Mar 2012 00:04:55 +0200 Subject: Inconsistency between os.getgroups and os.system('groups') after os.setgroups() In-Reply-To: <19158239.1073.1332711120749.JavaMail.geo-discussion-forums@ynlx41> References: <19158239.1073.1332711120749.JavaMail.geo-discussion-forums@ynlx41> Message-ID: <48491e1b6362e77b2c715da3fc469b23@modelnine.org> Am 25.03.2012 23:32, schrieb jeff: > After the os.setgroups, os.getgroups says that the process is not in > any groups, just as you would expect... I can suppress > membership in the root group only by doing os.setgid and os.setuid > before the os.system call (in which case I wind up in the group of > the > new user instead of root), but I have to be able to get back to root > privilege so I can't use setgid and setuid. Simply not possible (i.e., you can't drop root privileges, be it by setuid()/setgid() or removing yourself from groups with setgroups()), and later reacquire them _in the same process_. See the discussion of how to implement privilege separation at http://www.citi.umich.edu/u/provos/ssh/privsep.html (which discusses how this is implemented in OpenSSH) by running multiple processes which communicate through IPC mechanisms, and each of those drops the rights it requires. Using IPC to implement reduced-privilege process spawning has a long history; also, Postfix comes to mind as an "early" adopter of a privilege separation mechanism. -- --- Heiko. From mwilson at the-wire.com Sun Mar 25 19:09:12 2012 From: mwilson at the-wire.com (mwilson at the-wire.com) Date: Sun, 25 Mar 2012 19:09:12 -0400 Subject: Documentation, assignment in expression. References: <4f6d0060$0$6634$9b4e6d93@newsspool2.arcor-online.net> <4f6f0d24$0$6561$9b4e6d93@newsspool4.arcor-online.net> <4F6F1792.1060709@tim.thechases.com> Message-ID: Tim Chase wrote: > On 03/25/12 08:11, Chris Angelico wrote: >> On Mon, Mar 26, 2012 at 12:03 AM, Tim Chase >> wrote: >>> Granted, this can be turned into an iterator with a yield, making the >>> issue somewhat moot: >> >> No, just moving the issue to the iterator. Your iterator has exactly >> the same structure in it. > > Yeah, it has the same structure internally, but I'm somewhat > surprised that the DB connection object doesn't have an > __iter__() that does something like this automatically under the > covers. Most of my database programs wind up having the boilerplate (not tested): def rowsof (cursor): names = [x[0] for x in cursor.description] r = cursor.fetchone() while r: yield dict (zip (names, r)) r = cursor.fetchone() Mel. > >> Personally, I quite like assignment-in-conditional notation. Yes, it's >> a pretty common cause of problems; but what happened to the >> "consenting adults" policy? Python permits operator overloading and >> even the reassignment of builtins, both of which can cause similar >> confusion. > > In my past years of C programming, I've accidentally omitted the > second "=" in a comparison test numerous times, requiring me to > track down the missing character. When I finally catch it, it's > obvious what the problem is, but I've come to love having Python > yell at me contextually. > >> But, that's the choice Python's made. And being able to use the same >> symbol for assignment and comparison does have its advantages. > > The old curmudgeon in me likes the Pascal method of using "=" for > equality-testing, and ":=" for assignment which feels a little > closer to mathematical use of "=". > > -tkc From 3beezer at gmail.com Sun Mar 25 19:33:59 2012 From: 3beezer at gmail.com (jeff) Date: Sun, 25 Mar 2012 16:33:59 -0700 (PDT) Subject: Inconsistency between os.getgroups and os.system('groups') after os.setgroups() In-Reply-To: References: <19158239.1073.1332711120749.JavaMail.geo-discussion-forums@ynlx41> Message-ID: <7418918.681.1332718439318.JavaMail.geo-discussion-forums@yneo2> On Sunday, March 25, 2012 4:04:55 PM UTC-6, Heiko Wundram wrote: > Am 25.03.2012 23:32, schrieb jeff: > > After the os.setgroups, os.getgroups says that the process is not in > > any groups, just as you would expect... I can suppress > > membership in the root group only by doing os.setgid and os.setuid > > before the os.system call (in which case I wind up in the group of > > the > > new user instead of root), but I have to be able to get back to root > > privilege so I can't use setgid and setuid. > > Simply not possible (i.e., you can't drop root privileges, be it by > setuid()/setgid() or removing yourself from groups with setgroups()), > and later reacquire them _in the same process_. See the discussion of > how to implement privilege separation at > > http://www.citi.umich.edu/u/provos/ssh/privsep.html > > (which discusses how this is implemented in OpenSSH) by running > multiple processes which communicate through IPC mechanisms, and each of > those drops the rights it requires. Using IPC to implement > reduced-privilege process spawning has a long history; also, Postfix > comes to mind as an "early" adopter of a privilege separation mechanism. > > -- > --- Heiko. os.system("su -m -c ''") seems to do the trick. From 3beezer at gmail.com Sun Mar 25 19:33:59 2012 From: 3beezer at gmail.com (jeff) Date: Sun, 25 Mar 2012 16:33:59 -0700 (PDT) Subject: Inconsistency between os.getgroups and os.system('groups') after os.setgroups() In-Reply-To: References: <19158239.1073.1332711120749.JavaMail.geo-discussion-forums@ynlx41> Message-ID: <7418918.681.1332718439318.JavaMail.geo-discussion-forums@yneo2> On Sunday, March 25, 2012 4:04:55 PM UTC-6, Heiko Wundram wrote: > Am 25.03.2012 23:32, schrieb jeff: > > After the os.setgroups, os.getgroups says that the process is not in > > any groups, just as you would expect... I can suppress > > membership in the root group only by doing os.setgid and os.setuid > > before the os.system call (in which case I wind up in the group of > > the > > new user instead of root), but I have to be able to get back to root > > privilege so I can't use setgid and setuid. > > Simply not possible (i.e., you can't drop root privileges, be it by > setuid()/setgid() or removing yourself from groups with setgroups()), > and later reacquire them _in the same process_. See the discussion of > how to implement privilege separation at > > http://www.citi.umich.edu/u/provos/ssh/privsep.html > > (which discusses how this is implemented in OpenSSH) by running > multiple processes which communicate through IPC mechanisms, and each of > those drops the rights it requires. Using IPC to implement > reduced-privilege process spawning has a long history; also, Postfix > comes to mind as an "early" adopter of a privilege separation mechanism. > > -- > --- Heiko. os.system("su -m -c ''") seems to do the trick. From ben+python at benfinney.id.au Sun Mar 25 20:22:10 2012 From: ben+python at benfinney.id.au (Ben Finney) Date: Mon, 26 Mar 2012 11:22:10 +1100 Subject: Inconsistency between os.getgroups and os.system('groups') after os.setgroups() References: <19158239.1073.1332711120749.JavaMail.geo-discussion-forums@ynlx41> <7418918.681.1332718439318.JavaMail.geo-discussion-forums@yneo2> Message-ID: <87ty1cgqj1.fsf@benfinney.id.au> jeff <3beezer at gmail.com> writes: > On Sunday, March 25, 2012 4:04:55 PM UTC-6, Heiko Wundram wrote: > > Am 25.03.2012 23:32, schrieb jeff: > > > but I have to be able to get back to root privilege so I can't use > > > setgid and setuid. > > > > Simply not possible (i.e., you can't drop root privileges, be it by > > setuid()/setgid() or removing yourself from groups with setgroups()), > > and later reacquire them _in the same process_. See the discussion of > > how to implement privilege separation at > > > > http://www.citi.umich.edu/u/provos/ssh/privsep.html > > os.system("su -m -c ''") > > seems to do the trick. Yes, because ?os.system? explicitly starts a new process. It can't be done in the same process, as Heiko correctly said. -- \ ?Faith, n. Belief without evidence in what is told by one who | `\ speaks without knowledge, of things without parallel.? ?Ambrose | _o__) Bierce, _The Devil's Dictionary_, 1906 | Ben Finney From mensanator at aol.com Mon Mar 26 00:59:56 2012 From: mensanator at aol.com (Mensanator) Date: Sun, 25 Mar 2012 21:59:56 -0700 (PDT) Subject: why did GMPY change the names of its functions? Message-ID: <39ff04b9-84a0-401c-a0a5-75e33cf59bc8@vy9g2000pbc.googlegroups.com> OK, GMPY is now called GMPY2. No big deal, I can import as GMPY. But why were scan0 and scan1 changed to bit_scan0 and bit_scan1? What's the justification for that? I use those functions extensively in my library of Collatz utilities and I had to re-edit them for no obvious reason. From steve+comp.lang.python at pearwood.info Mon Mar 26 01:36:28 2012 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 26 Mar 2012 05:36:28 GMT Subject: Documentation, assignment in expression. References: <4f6d0060$0$6634$9b4e6d93@newsspool2.arcor-online.net> <4f6f0d24$0$6561$9b4e6d93@newsspool4.arcor-online.net> Message-ID: <4f70005c$0$29968$c3e8da3$5496439d@news.astraweb.com> On Sun, 25 Mar 2012 08:03:14 -0500, Tim Chase wrote: > I think the complaint was backed by a bad example. Perhaps a DB example > works better. With assignment allowed in an evaluation, you'd be able > to write > > while data = conn.fetchmany(): > for row in data: > process(row) Yes, but why would you want to? Apart from making your code hard to read. Better written as: while data = conn.fetchmany(): # THIS IS NOT A TYPO for row in data: process(row) When you need to write a comment explaining that something isn't a typo, that's a good clue that you shouldn't do it *wink* But seriously, assignment as an expression is a pretty major code-smell. Even when it's innocent, it should still fire off warning alarms, because how do you know if it's innocent or not until you've studied the code? (Comments, like the above, are prone to get out of date with the code, and can't be entirely trusted.) Python avoids this code smell by prohibiting assignment as an expression. Functional languages avoid it by prohibiting assignment. Other languages may choose to do differently. If all languages did exactly what C does, they'd all be C. (I seem to recall a language that used a single = for both assignment and equality testing, guessing which one you meant from context. BASIC perhaps? Whatever it was, I'm pretty sure they regretted it.) > whereas you have to write > > while True: > data = conn.fetchmany() > if not data: break > for row in data: > process(row) Or even: data = 'SENTINEL' # Any true value will do. while data: data = conn.fetchmany() for row in data: process(row) There's no need to break out of the while loop early, because `for row in ` is a null-op. -- Steven From wuwei23 at gmail.com Mon Mar 26 01:43:01 2012 From: wuwei23 at gmail.com (alex23) Date: Sun, 25 Mar 2012 22:43:01 -0700 (PDT) Subject: why did GMPY change the names of its functions? References: <39ff04b9-84a0-401c-a0a5-75e33cf59bc8@vy9g2000pbc.googlegroups.com> Message-ID: <0a6ac762-963f-4bdf-8c06-df3a53699f2c@z5g2000pbu.googlegroups.com> On Mar 26, 2:59?pm, Mensanator wrote: > OK, GMPY is now called GMPY2. No big deal, I can import as GMPY. > But why were scan0 and scan1 changed to bit_scan0 and bit_scan1? Python is not gmpy. You might be better served asking the project maintainer(s). > What's the justification for that? I use those functions extensively > in my library of Collatz utilities ?and I had to re-edit them for no > obvious reason. Well, the obvious reason is that it's a different version which offers no promise of API backwards compatibility. From steve+comp.lang.python at pearwood.info Mon Mar 26 01:47:36 2012 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 26 Mar 2012 05:47:36 GMT Subject: Documentation, assignment in expression. References: <4f6d0060$0$6634$9b4e6d93@newsspool2.arcor-online.net> <4f6f0d24$0$6561$9b4e6d93@newsspool4.arcor-online.net> <4F6F1792.1060709@tim.thechases.com> <4f6f36bf$0$1390$4fafbaef@reader2.news.tin.it> Message-ID: <4f7002f8$0$29968$c3e8da3$5496439d@news.astraweb.com> On Sun, 25 Mar 2012 17:16:16 +0200, Kiuhnm wrote: > On 3/25/2012 15:48, Tim Chase wrote: >> The old curmudgeon in me likes the Pascal method of using "=" for >> equality-testing, and ":=" for assignment which feels a little closer >> to mathematical use of "=". > > Unfortunately, ":=" means "is defined as" in mathematics. The "right" > operator would have been "<-". That's hardly universal. In approx 20 years of working with mathematics textbooks, I've never seen := used until today. I see that Wikipedia lists no fewer than seven different symbols for "is defined as": http://en.wikipedia.org/wiki/Table_of_mathematical_symbols including the one I'm familiar with, ?, or "def" over "=". Besides, just because mathematicians use a symbol, doesn't mean programming languages can't use it for something else. -- Steven From varma.nikhil22 at gmail.com Mon Mar 26 02:08:22 2012 From: varma.nikhil22 at gmail.com (Nikhil Verma) Date: Mon, 26 Mar 2012 11:38:22 +0530 Subject: random number Message-ID: Hi All How can we generate a 6 digit random number from a given number ? eg:- def number_generator(id): random.randint(id,999999) When i am using this it is sometimes giving me five digit and sometimes 6 . I want to avoid encryption . Can i have alphanumeric 6 digit random number from this . Thanks in advance -- Regards Nikhil Verma +91-958-273-3156 -------------- next part -------------- An HTML attachment was scrubbed... URL: From ddasilva at umd.edu Mon Mar 26 02:17:30 2012 From: ddasilva at umd.edu (Daniel da Silva) Date: Mon, 26 Mar 2012 02:17:30 -0400 Subject: random number In-Reply-To: References: Message-ID: If you want it as an int: random.randint(100000, 999999) Or as a string: s = '%06d' % random.randint(0, 999999) On Mon, Mar 26, 2012 at 2:08 AM, Nikhil Verma wrote: > Hi All > > How can we generate a 6 digit random number from a given number ? > > eg:- > > def number_generator(id): > random.randint(id,999999) > > When i am using this it is sometimes giving me five digit and sometimes 6 > . I want to avoid encryption . Can i have alphanumeric 6 digit random > number from this . > > Thanks in advance > > -- > Regards > Nikhil Verma > +91-958-273-3156 > > > -- > http://mail.python.org/mailman/listinfo/python-list > > -------------- next part -------------- An HTML attachment was scrubbed... URL: From rosuav at gmail.com Mon Mar 26 02:25:06 2012 From: rosuav at gmail.com (Chris Angelico) Date: Mon, 26 Mar 2012 17:25:06 +1100 Subject: random number In-Reply-To: References: Message-ID: On Mon, Mar 26, 2012 at 5:08 PM, Nikhil Verma wrote: > Hi All > > How can we generate a 6 digit random number from a given number ? > > eg:- > > def number_generator(id): > ??? random.randint(id,999999) > > When i am using this it is sometimes giving me five digit and sometimes 6 . > I want to avoid encryption . Can i have alphanumeric 6 digit random number > from this . The easiest two ways to guarantee six digits are: 1) Pad the number with leading zeroes: def number_generator(): return "%06d"%random.randint(0,999999) 2) Set a minimum and a maximum: def number_generator(): return random.randint(100000,999999) I don't know what your id there is, but the first argument to randint is the minimum value to return. Alphanumeric is quite different. To generate a six-character random alphanumeric string, one easy technique is to use base 36 conversion on a random integer. Hope that helps! Chris Angelico From michael.poeltl at univie.ac.at Mon Mar 26 02:40:00 2012 From: michael.poeltl at univie.ac.at (Michael Poeltl) Date: Mon, 26 Mar 2012 08:40:00 +0200 Subject: random number In-Reply-To: References: Message-ID: <20120326064000.GB19865@terra.cms.at> * Nikhil Verma [2012-03-26 08:09]: > Hi All > > How can we generate a 6 digit random number from a given number ? what about this? >>> given_number=123456 >>> def rand_given_number(x): ... s = list(str(x)) ... random.shuffle(s) ... return int(''.join(s)) ... >>> print (rand_given_number(given_number)) 653421 From varma.nikhil22 at gmail.com Mon Mar 26 02:50:44 2012 From: varma.nikhil22 at gmail.com (Nikhil Verma) Date: Mon, 26 Mar 2012 12:20:44 +0530 Subject: random number In-Reply-To: References: Message-ID: Hi I want something to achieve like this :- def random_number(id): # I am passing it from request # do something return random_number Output random_number(5) AXR670 One input that is a number in return you are getting 6 digit alphanumeric string. I tried this s = '%06d' % random.randint(0, 999999) it gives : '192862' (a string ) Thanks in advance. On Mon, Mar 26, 2012 at 11:47 AM, Daniel da Silva wrote: > If you want it as an int: > random.randint(100000, 999999) > > Or as a string: > s = '%06d' % random.randint(0, 999999) > > > > On Mon, Mar 26, 2012 at 2:08 AM, Nikhil Verma wrote: > >> Hi All >> >> How can we generate a 6 digit random number from a given number ? >> >> eg:- >> >> def number_generator(id): >> random.randint(id,999999) >> >> When i am using this it is sometimes giving me five digit and sometimes 6 >> . I want to avoid encryption . Can i have alphanumeric 6 digit random >> number from this . >> >> Thanks in advance >> >> -- >> Regards >> Nikhil Verma >> +91-958-273-3156 >> >> >> -- >> http://mail.python.org/mailman/listinfo/python-list >> >> > -- Regards Nikhil Verma +91-958-273-3156 -------------- next part -------------- An HTML attachment was scrubbed... URL: From hankshz at gmail.com Mon Mar 26 03:02:04 2012 From: hankshz at gmail.com (hz hanks) Date: Mon, 26 Mar 2012 00:02:04 -0700 Subject: Problem with NAT Traversal Message-ID: Hi, All I'm working with a small program to realize P2P file transfer. Therefore, I have to accomplish the function of NAT traversal. From the searching result, I know that it always requires a public server to initialize the transfer, but I don't have one. Now, my idea is that, we already have many communication ways such as the gtalk, so one side of P2P file transfer program can just run a 'touch' function to know some parameters, such as the port number and the public IP address, and just display them to the users. And the users will guarantee that the other side P2P file transfer program will know these parameters. However, I don't know any function in python can achieve the 'touch' function. Any one has some experience on this? Really appreciated. Best, Hanks From steve+comp.lang.python at pearwood.info Mon Mar 26 03:24:38 2012 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 26 Mar 2012 07:24:38 GMT Subject: random number References: Message-ID: <4f7019b6$0$29968$c3e8da3$5496439d@news.astraweb.com> On Mon, 26 Mar 2012 08:40:00 +0200, Michael Poeltl wrote: > * Nikhil Verma [2012-03-26 08:09]: >> Hi All >> >> How can we generate a 6 digit random number from a given number ? > what about this? > >>>> given_number=123456 >>>> def rand_given_number(x): > ... s = list(str(x)) > ... random.shuffle(s) > ... return int(''.join(s)) > ... >>>> print (rand_given_number(given_number)) > 653421 That's not very random. In fact, it is *terrible* as a random number generator. A truly random six digit number will include any number between 100000 through 999999. There are exactly 900000 (nine hundred thousand) such numbers. The way you generate the not-quite-random numbers, you miss out on almost all of them. E.g. you can generate 123456 but not 123455 or 123457. In total, you generate only 6! = 6*5*4*3*2*1 = 720 numbers, no matter how many millions of times you call the function. Here is a demonstration: >>> given = 123456 >>> def rand_num(x): ... s = list(str(x)) ... random.shuffle(s) ... return int(''.join(s)) ... >>> import random >>> results = set() >>> for i in range(10**7): ... results.add(rand_num(given)) ... >>> len(results) 720 So slightly more than 99% of all the six digit numbers will never be generated using your method. -- Steven From gstaniak at gmail.com Mon Mar 26 03:50:06 2012 From: gstaniak at gmail.com (Grzegorz Staniak) Date: Mon, 26 Mar 2012 07:50:06 +0000 (UTC) Subject: random number References: <4f7019b6$0$29968$c3e8da3$5496439d@news.astraweb.com> Message-ID: On 26.03.2012, Steven D'Aprano wroted: >>> How can we generate a 6 digit random number from a given number ? >> what about this? >> >>>>> given_number=123456 >>>>> def rand_given_number(x): >> ... s = list(str(x)) >> ... random.shuffle(s) >> ... return int(''.join(s)) >> ... >>>>> print (rand_given_number(given_number)) >> 653421 > > > That's not very random. In fact, it is *terrible* as a random number > generator. But isn't it what the OP requested, i.e. "6 digit random number *from a given number*"? That is, a random permutation of the set of its digits? GS -- Grzegorz Staniak From __peter__ at web.de Mon Mar 26 03:57:39 2012 From: __peter__ at web.de (Peter Otten) Date: Mon, 26 Mar 2012 09:57:39 +0200 Subject: random number References: Message-ID: Nikhil Verma wrote: > I want something to achieve like this :- > > def random_number(id): # I am passing it from request > # do something > return random_number > > Output > > random_number(5) > AXR670 That's normally not called a number (though it could be base 36 or similar). > One input that is a number in return you are getting 6 digit alphanumeric > string. > > I tried this > s = '%06d' % random.randint(0, 999999) > > it gives : '192862' (a string ) Your question is not very clear. Can you give some more information, what you want to do with your "random" "number", and how the id argument should influence possible results, e. g. can the possible outcomes of random_number(x) and random_number(y) overlap for x != y? From atavory at gmail.com Mon Mar 26 04:15:09 2012 From: atavory at gmail.com (Ami Tavory) Date: Mon, 26 Mar 2012 10:15:09 +0200 Subject: bdb.Bdb (Debugger Base Class) / unittest Interaction (MRAB) Message-ID: From: MRAB To: python-list at python.org Cc: Date: Sun, 25 Mar 2012 22:14:28 +0100 Subject: Re: bdb.Bdb (Debugger Base Class) / unittest Interaction On 25/03/2012 21:42, Ami Tavory wrote: > Hello, > > I'm having some difficulties with the interaction between bdb.Bdb and > scripts which contain unittest. Following are two simplified scenarios > of a GUI debugger Gedit plugin I'm writing based on bdb.Bdb, and a > script that is being debugged by it. > > --Scenario A-- > > The script being debugged is foo.py; its content is > > print 'Hello, world!' > > > The "debugger" (a simplified version of it) is > > import bdb > > g = {} > g['__name__'] = '__main__' > g['__file__'] = 'foo.py' > statement = 'execfile("%s", %s)' % ('foo.py', str(g)) > bdb.Bdb().run(statement) > > > it indeed prints 'Hello, world'. > > --Scenario B-- > > The script being debugged is bar.py; its content is > > import unittest > > class test(unittest.TestCase): > def test(self): > print 'Hello, world!' > > def suite(): > return unittest.TestLoader().**loadTestsFromTestCase(test) > > if __name__ == '__main__': > unittest.main() > > > The "debugger" is identical to before, but with 'foo.py' replaced by > 'bar.py'. It does not print 'Hello, world'. In fact, it prints > > ------------------------------**------------------------------**---------- > Ran 0 tests in 0.000s > > > However: > > 1. Running bar.py as a script, indeed prints 'Hello, world'. > 2. Running pdb (which internally uses bdb.Bdb) on bar.py, also indeed > prints 'Hello, world'. > > I've looked at the code of pdb to see what I'm doing wrong (at least > in the second case), but couldn't find the difference. Help would be > much appreciated. > > With Python 2.7 I'm getting this: Hello, world! . ------------------------------**------------------------------**---------- Ran 1 test in 0.000s OK ---------------------------------------------------------------------------------------------------------------------------------------------------------- Hi, Many thanks for your reply. Unfortunately, I'm consistently getting a different output than yours on scenario B, namely ---------------------------------------------------------------------- Ran 0 tests in 0.000s This happens on separate computers, one running 2.6, and one running 2.7. Is it possible to ask whether you ran in scenario B bar.py or the "debugger" running on bar.py? Running it through the "debugger" causes the problem; without it it works fine. If the problem is only on my (two separate) installations, is there something I can do to specify the problem further? Thanks & Bye, Ami -------------- next part -------------- An HTML attachment was scrubbed... URL: From jeanpierreda at gmail.com Mon Mar 26 04:52:13 2012 From: jeanpierreda at gmail.com (Devin Jeanpierre) Date: Mon, 26 Mar 2012 04:52:13 -0400 Subject: Documentation, assignment in expression. In-Reply-To: <4f6f36bf$0$1390$4fafbaef@reader2.news.tin.it> References: <4f6d0060$0$6634$9b4e6d93@newsspool2.arcor-online.net> <4f6f0d24$0$6561$9b4e6d93@newsspool4.arcor-online.net> <4F6F1792.1060709@tim.thechases.com> <4f6f36bf$0$1390$4fafbaef@reader2.news.tin.it> Message-ID: On Sun, Mar 25, 2012 at 11:16 AM, Kiuhnm wrote: > On 3/25/2012 15:48, Tim Chase wrote: >> >> The old curmudgeon in me likes the Pascal method of using "=" for >> equality-testing, and ":=" for assignment which feels a little closer to >> mathematical use of "=". > > > Unfortunately, ":=" means "is defined as" in mathematics. The "right" > operator would have been "<-". "Is defined as" is actually pretty reasonable. "Define this to be that" is a common way to speak about assignment. Its only difference is the present tense. For example, in Python, "def" stands for "define", but we can overwrite previous definitions:: def f(x): return x def f(x): return 2 f(3) == 2 In fact, in pretty every programming language that I know of with a "define" assignment verb, this is so. For example, in Scheme, x is 2 at the end:: (define x 1) (define x 2) x -- Devin From michael.poeltl at univie.ac.at Mon Mar 26 05:24:03 2012 From: michael.poeltl at univie.ac.at (Michael Poeltl) Date: Mon, 26 Mar 2012 11:24:03 +0200 Subject: random number In-Reply-To: References: <20120326064000.GB19865@terra.cms.at> Message-ID: <20120326092403.GB22725@terra.cms.at> * Nikhil Verma [2012-03-26 08:49]: > Hi > > I want something to achieve like this :- > > def random_number(id): # I am passing it from request > # do something > return random_number > > Output > > random_number(5) > AXR670 > > One input that is a number in return you are getting 6 digit alphanumeric > string. > > I tried this > s = '%06d' % random.randint(0, 999999) > > it gives : '192862' (a string ) > > Thanks in advance. ah - so I misunderstood - I thought you want a permutation of a given 6-digit number It's still not quite clear to me what role 'id' is playing ... so let's check this one; and Steven, who is maybe more experienced than I am will help us ufrther >>> import random, string >>> def random_number(id): ... characters = list(string.ascii_lowercase + ... string.ascii_uppercase + ... string.digits) ... coll_rand = [] ... for i in range(6): ... random.shuffle(characters) ... coll_rand.append(characters[0]) ... return ''.join(coll_rand) ... >>> id = 5 >>> print (random_number(id)) puMHCr >>> regards Michael > > On Mon, Mar 26, 2012 at 12:10 PM, Michael Poeltl < > michael.poeltl at univie.ac.at> wrote: > > > * Nikhil Verma [2012-03-26 08:09]: > > > Hi All > > > > > > How can we generate a 6 digit random number from a given number ? > > what about this? > > > > >>> given_number=123456 > > >>> def rand_given_number(x): > > ... s = list(str(x)) > > ... random.shuffle(s) > > ... return int(''.join(s)) > > ... > > >>> print (rand_given_number(given_number)) > > 653421 > > > > > > -- > Regards > Nikhil Verma > +91-958-273-3156 -- Michael Poeltl Computational Materials Physics voice: +43-1-4277-51409 Univ. Wien, Sensengasse 8/12 fax: +43-1-4277-9514 (or 9513) A-1090 Wien, AUSTRIA cmp.mpi.univie.ac.at ------------------------------------------------------------------------------- ubuntu-11.10 | vim-7.3 | python-3.2.2 | mutt-1.5.21 | elinks-0.12 ------------------------------------------------------------------------------- From jeanmichel at sequans.com Mon Mar 26 05:27:19 2012 From: jeanmichel at sequans.com (Jean-Michel Pichavant) Date: Mon, 26 Mar 2012 11:27:19 +0200 Subject: Stream programming In-Reply-To: <4f6c9e17$0$1383$4fafbaef@reader2.news.tin.it> References: <4f6c9e17$0$1383$4fafbaef@reader2.news.tin.it> Message-ID: <4F703677.4000506@sequans.com> Kiuhnm wrote: > [snip] > > numbers - push - avrg - 'med' - pop - filter(lt('med'), ge('med'))\ > - ['same', 'same'] - streams(cat) - 'same' > > It reads as > > "take a list of numbers - save it - compute the average and named it > 'med' - restore the flow - create two streams which have, respect., > the numbers less than 'med' and those greater or equal to 'med' - do > the /entire/ 'same' process on each one of the two streams - concat > the resulting streams - name all this /entire/ process 'same'. > Not readable enough? Replace 'same' with 'qsort'. > > Is that readable or am I going crazy? [note: that's a rhetorical > question whose answer is "That's very readable!"] > > Kiuhnm Here's a rhetorical answer to your question : whatever you're taking, I want some ! JM From robert.kern at gmail.com Mon Mar 26 05:36:12 2012 From: robert.kern at gmail.com (Robert Kern) Date: Mon, 26 Mar 2012 10:36:12 +0100 Subject: random number In-Reply-To: References: <4f7019b6$0$29968$c3e8da3$5496439d@news.astraweb.com> Message-ID: On 3/26/12 8:50 AM, Grzegorz Staniak wrote: > On 26.03.2012, Steven D'Aprano wroted: > >>>> How can we generate a 6 digit random number from a given number ? >>> what about this? >>> >>>>>> given_number=123456 >>>>>> def rand_given_number(x): >>> ... s = list(str(x)) >>> ... random.shuffle(s) >>> ... return int(''.join(s)) >>> ... >>>>>> print (rand_given_number(given_number)) >>> 653421 >> >> >> That's not very random. In fact, it is *terrible* as a random number >> generator. > > But isn't it what the OP requested, i.e. "6 digit random number > *from a given number*"? That is, a random permutation of the set > of its digits? I would consider that to be a very odd interpretation of that request. But it *is* an extraordinarily vague request. I'm not sure if even the OP knows what he wants. I suspect he really wants something like a hash. -- Robert Kern "I have come to believe that the whole world is an enigma, a harmless enigma that is made terrible by our own mad attempt to interpret it as though it had an underlying truth." -- Umberto Eco From jeanmichel at sequans.com Mon Mar 26 05:44:01 2012 From: jeanmichel at sequans.com (Jean-Michel Pichavant) Date: Mon, 26 Mar 2012 11:44:01 +0200 Subject: How to decide if a object is instancemethod? In-Reply-To: <389400.5582.1331733455084.JavaMail.geo-discussion-forums@vbiz13> References: <8815977.3878.1331731738209.JavaMail.geo-discussion-forums@vbux23> <389400.5582.1331733455084.JavaMail.geo-discussion-forums@vbiz13> Message-ID: <4F703A61.4040407@sequans.com> Jon Clements wrote: > On Wednesday, 14 March 2012 13:28:58 UTC, Cosmia Luna wrote: > >> class Foo(object): >> def bar(self): >> return 'Something' >> >> func = Foo().bar >> >> if type(func) == : # This should be always true >> pass # do something here >> >> What should type at ? >> >> Thanks >> Cosmia >> > > import inspect > if inspect.ismethod(foo): > # ... > > Will return True if foo is a bound method. > > hth > > Jon > another alternative : import types if type(func) == types.MethodType: pass or possibly better if isinstance(func, types.MethodType): pass JM From varma.nikhil22 at gmail.com Mon Mar 26 05:45:00 2012 From: varma.nikhil22 at gmail.com (Nikhil Verma) Date: Mon, 26 Mar 2012 15:15:00 +0530 Subject: random number In-Reply-To: <20120326092403.GB22725@terra.cms.at> References: <20120326064000.GB19865@terra.cms.at> <20120326092403.GB22725@terra.cms.at> Message-ID: Hi Thanks Michael I want exactly wanted this. Great !!!! def random_number(id) ... characters = list(string.ascii_lowercase +string.ascii_uppercase +string.digits) I used this this earlier and tried then by using choice . This is great. On Mon, Mar 26, 2012 at 2:54 PM, Michael Poeltl wrote: > * Nikhil Verma [2012-03-26 08:49]: > > Hi > > > > I want something to achieve like this :- > > > > def random_number(id): # I am passing it from request > > # do something > > return random_number > > > > Output > > > > random_number(5) > > AXR670 > > > > One input that is a number in return you are getting 6 digit alphanumeric > > string. > > > > I tried this > > s = '%06d' % random.randint(0, 999999) > > > > it gives : '192862' (a string ) > > > > Thanks in advance. > ah - so I misunderstood - I thought you want a permutation of a given > 6-digit number > > It's still not quite clear to me what role 'id' is playing ... so let's > check this one; > and Steven, who is maybe more experienced than I am will help us ufrther > > >>> import random, string > >>> def random_number(id): > ... characters = list(string.ascii_lowercase + > ... string.ascii_uppercase + > ... string.digits) > ... coll_rand = [] > ... for i in range(6): > ... random.shuffle(characters) > ... coll_rand.append(characters[0]) > ... return ''.join(coll_rand) > ... > >>> id = 5 > >>> print (random_number(id)) > puMHCr > >>> > > regards > Michael > > > > > > On Mon, Mar 26, 2012 at 12:10 PM, Michael Poeltl < > > michael.poeltl at univie.ac.at> wrote: > > > > > * Nikhil Verma [2012-03-26 08:09]: > > > > Hi All > > > > > > > > How can we generate a 6 digit random number from a given number ? > > > what about this? > > > > > > >>> given_number=123456 > > > >>> def rand_given_number(x): > > > ... s = list(str(x)) > > > ... random.shuffle(s) > > > ... return int(''.join(s)) > > > ... > > > >>> print (rand_given_number(given_number)) > > > 653421 > > > > > > > > > > > -- > > Regards > > Nikhil Verma > > +91-958-273-3156 > > > -- > Michael Poeltl > Computational Materials Physics voice: +43-1-4277-51409 > Univ. Wien, Sensengasse 8/12 fax: +43-1-4277-9514 (or 9513) > A-1090 Wien, AUSTRIA cmp.mpi.univie.ac.at > > ------------------------------------------------------------------------------- > ubuntu-11.10 | vim-7.3 | python-3.2.2 | mutt-1.5.21 | elinks-0.12 > > ------------------------------------------------------------------------------- > -- Regards Nikhil Verma +91-958-273-3156 -------------- next part -------------- An HTML attachment was scrubbed... URL: From robert.kern at gmail.com Mon Mar 26 05:50:22 2012 From: robert.kern at gmail.com (Robert Kern) Date: Mon, 26 Mar 2012 10:50:22 +0100 Subject: random number In-Reply-To: References: <20120326064000.GB19865@terra.cms.at> <20120326092403.GB22725@terra.cms.at> Message-ID: On 3/26/12 10:45 AM, Nikhil Verma wrote: > Hi > > Thanks Michael I want exactly wanted this. Great !!!! > def random_number(id) > ... characters = list(string.ascii_lowercase +string.ascii_uppercase > +string.digits) > > I used this this earlier and tried then by using choice . > This is great. Note that the id parameter is not used by the function at all. If you call this function multiple times with the same input, you will get different results each time. Is that what you want? What role did you expect the id parameter to play? > On Mon, Mar 26, 2012 at 2:54 PM, Michael Poeltl > wrote: > It's still not quite clear to me what role 'id' is playing ... so let's > check this one; > and Steven, who is maybe more experienced than I am will help us ufrther > > >>> import random, string > >>> def random_number(id): > ... characters = list(string.ascii_lowercase + > ... string.ascii_uppercase + > ... string.digits) > ... coll_rand = [] > ... for i in range(6): > ... random.shuffle(characters) > ... coll_rand.append(characters[0]) > ... return ''.join(coll_rand) > ... > >>> id = 5 > >>> print (random_number(id)) > puMHCr > >>> -- Robert Kern "I have come to believe that the whole world is an enigma, a harmless enigma that is made terrible by our own mad attempt to interpret it as though it had an underlying truth." -- Umberto Eco From python.list at tim.thechases.com Mon Mar 26 06:14:01 2012 From: python.list at tim.thechases.com (Tim Chase) Date: Mon, 26 Mar 2012 05:14:01 -0500 Subject: Documentation, assignment in expression. In-Reply-To: References: <4f6d0060$0$6634$9b4e6d93@newsspool2.arcor-online.net> <4f6f0d24$0$6561$9b4e6d93@newsspool4.arcor-online.net> <4F6F1792.1060709@tim.thechases.com> <4F6F222F.7050406@tim.thechases.com> Message-ID: <4F704169.6060103@tim.thechases.com> On 03/25/12 17:59, Dennis Lee Bieber wrote: > On Sun, 25 Mar 2012 08:48:31 -0500, Tim Chase >> Yeah, it has the same structure internally, but I'm somewhat >> surprised that the DB connection object doesn't have an >> __iter__() that does something like this automatically under the >> covers. >> > I believe being able to use the connection object directly for > queries is considered a short-cut feature... If you use the longer form > > con = db.connect() > cur = con.cursor() > > the cursor object, in all that I've worked with, does function for > iteration > > for rec in cur: > #do stuff Interesting. Either this is something special for a particular DB back-end, or has been added since I went hunting (back with mxODBC and Python2.4). I wouldn't be surprised if the latter was the case, as my code is nigh identical to yours. conn = db.DriverConnect(connection_string) cursor = conn.cursor() cursor.execute(sql, params) for row in cursor: # in the above 2.4 + mxODBC, this fails process(row) I'd be interested to know the underlying implementation's efficiency, hopefully using .fetchmany() under the hood. My understanding is that the .fetchmany() loop is the best way to do it, as the .fetchone() gets chatty with the DB (but is more efficient if you only need one row from a multi-result query), and the .fetchall() can blow out memory on large datasets. -tkc From kiuhnm03.4t.yahoo.it Mon Mar 26 06:56:30 2012 From: kiuhnm03.4t.yahoo.it (Kiuhnm) Date: Mon, 26 Mar 2012 12:56:30 +0200 Subject: Documentation, assignment in expression. In-Reply-To: References: <4f6d0060$0$6634$9b4e6d93@newsspool2.arcor-online.net> <4f6f0d24$0$6561$9b4e6d93@newsspool4.arcor-online.net> <4F6F1792.1060709@tim.thechases.com> <4f6f36bf$0$1390$4fafbaef@reader2.news.tin.it> Message-ID: <4f704b5e$0$1389$4fafbaef@reader2.news.tin.it> On 3/26/2012 10:52, Devin Jeanpierre wrote: > On Sun, Mar 25, 2012 at 11:16 AM, Kiuhnm > wrote: >> On 3/25/2012 15:48, Tim Chase wrote: >>> >>> The old curmudgeon in me likes the Pascal method of using "=" for >>> equality-testing, and ":=" for assignment which feels a little closer to >>> mathematical use of "=". >> >> >> Unfortunately, ":=" means "is defined as" in mathematics. The "right" >> operator would have been "<-". > > > "Is defined as" is actually pretty reasonable. "Define this to be > that" is a common way to speak about assignment. Its only difference > is the present tense. For example, in Python, "def" stands for > "define", but we can overwrite previous definitions:: > > def f(x): return x > def f(x): return 2 > f(3) == 2 > > In fact, in pretty every programming language that I know of with a > "define" assignment verb, this is so. For example, in Scheme, x is 2 > at the end:: > > (define x 1) > (define x 2) > x When you write (define x 1) (define x 2) x or, in F# and OCaml, let x = 1 let x = 2 x you're saying x = 1 { x = 2 x } You don't modify 'x': you hide it by defining another "value" (not variable) with the same name. Indeed, let x = 1 let x = 2 x is shorthand for let x = 1 in let x = 2 in x Kiuhnm From jpiitula at ling.helsinki.fi Mon Mar 26 07:13:48 2012 From: jpiitula at ling.helsinki.fi (Jussi Piitulainen) Date: 26 Mar 2012 14:13:48 +0300 Subject: Documentation, assignment in expression. References: <4f6d0060$0$6634$9b4e6d93@newsspool2.arcor-online.net> <4f6f0d24$0$6561$9b4e6d93@newsspool4.arcor-online.net> <4F6F1792.1060709@tim.thechases.com> <4f6f36bf$0$1390$4fafbaef@reader2.news.tin.it> <4f704b5e$0$1389$4fafbaef@reader2.news.tin.it> Message-ID: Kiuhnm writes: > On 3/26/2012 10:52, Devin Jeanpierre wrote: > > On Sun, Mar 25, 2012 at 11:16 AM, Kiuhnm > > wrote: > >> On 3/25/2012 15:48, Tim Chase wrote: > >>> > >>> The old curmudgeon in me likes the Pascal method of using "=" for > >>> equality-testing, and ":=" for assignment which feels a little closer to > >>> mathematical use of "=". > >> > >> > >> Unfortunately, ":=" means "is defined as" in mathematics. The "right" > >> operator would have been "<-". > > > > > > "Is defined as" is actually pretty reasonable. "Define this to be > > that" is a common way to speak about assignment. Its only difference > > is the present tense. For example, in Python, "def" stands for > > "define", but we can overwrite previous definitions:: > > > > def f(x): return x > > def f(x): return 2 > > f(3) == 2 > > > > In fact, in pretty every programming language that I know of with a > > "define" assignment verb, this is so. For example, in Scheme, x is 2 > > at the end:: > > > > (define x 1) > > (define x 2) > > x > > When you write > (define x 1) > (define x 2) > x > or, in F# and OCaml, > let x = 1 > let x = 2 > x > you're saying > x = 1 > { > x = 2 > x > } > You don't modify 'x': you hide it by defining another "value" (not > variable) with the same name. > Indeed, > let x = 1 > let x = 2 > x > is shorthand for > let x = 1 in > let x = 2 in > x No, Devin is right about Scheme. On "top level" re-definition is interpreted as assignment. The following mean the same: (define x 1) (define x 2) x (define x 1) (set! x 2) x Local definitions in the beginning of a "body" do not allow duplicate names at all. The following mean the same: (let () (define x 1) (define y 2) x) (letrec* ((x 1) (y 2)) x) ;letrec in older versions (not sure of R6RS) But (let () (define x 1) (define x 2) x) is still an error. Some implementations may give it a meaning. Not sure. From mwilson at the-wire.com Mon Mar 26 07:27:15 2012 From: mwilson at the-wire.com (mwilson at the-wire.com) Date: Mon, 26 Mar 2012 07:27:15 -0400 Subject: Documentation, assignment in expression. References: <4f6d0060$0$6634$9b4e6d93@newsspool2.arcor-online.net> <4f6f0d24$0$6561$9b4e6d93@newsspool4.arcor-online.net> <4F6F1792.1060709@tim.thechases.com> Message-ID: Dennis Lee Bieber wrote: > On Sun, 25 Mar 2012 19:09:12 -0400, mwilson at the-wire.com declaimed the > following in gmane.comp.python.general: > > >> Most of my database programs wind up having the boilerplate (not tested): >> >> def rowsof (cursor): >> names = [x[0] for x in cursor.description] >> r = cursor.fetchone() >> while r: >> yield dict (zip (names, r)) >> r = cursor.fetchone() >> > > In my (limited) experience, the main loop above could be replaced > with: > > for r in cursor: > yield dict(zip(names, r)) I think your experience is more recent than mine. I'll change my boilerplate next time around. Mel. From redstone-cold at 163.com Mon Mar 26 07:45:26 2012 From: redstone-cold at 163.com (redstone-cold at 163.com) Date: Mon, 26 Mar 2012 04:45:26 -0700 (PDT) Subject: Is there any difference between print 3 and print '3' in Python ? Message-ID: <5128580.32.1332762326119.JavaMail.geo-discussion-forums@pbom7> I know the print statement produces the same result when both of these two instructions are executed ,I just want to know Is there any difference between print 3 and print '3' in Python ? From kiuhnm03.4t.yahoo.it Mon Mar 26 07:45:45 2012 From: kiuhnm03.4t.yahoo.it (Kiuhnm) Date: Mon, 26 Mar 2012 13:45:45 +0200 Subject: Stream programming In-Reply-To: References: <4f6c9e17$0$1383$4fafbaef@reader2.news.tin.it> Message-ID: <4f7056e8$0$1375$4fafbaef@reader1.news.tin.it> On 3/26/2012 11:27, Jean-Michel Pichavant wrote: > Kiuhnm wrote: >> [snip] >> >> numbers - push - avrg - 'med' - pop - filter(lt('med'), ge('med'))\ >> - ['same', 'same'] - streams(cat) - 'same' >> >> It reads as >> >> "take a list of numbers - save it - compute the average and named it >> 'med' - restore the flow - create two streams which have, respect., >> the numbers less than 'med' and those greater or equal to 'med' - do >> the /entire/ 'same' process on each one of the two streams - concat >> the resulting streams - name all this /entire/ process 'same'. >> Not readable enough? Replace 'same' with 'qsort'. >> >> Is that readable or am I going crazy? [note: that's a rhetorical >> question whose answer is "That's very readable!"] >> >> Kiuhnm > > Here's a rhetorical answer to your question : whatever you're taking, I > want some ! LOL. I should have titled my post "A new obfuscation technique" then :) Kiuhnm From andre.roberge at gmail.com Mon Mar 26 07:47:13 2012 From: andre.roberge at gmail.com (=?ISO-8859-1?Q?Andr=E9_Roberge?=) Date: Mon, 26 Mar 2012 04:47:13 -0700 (PDT) Subject: Puzzled by FiPy's use of "==" Message-ID: <24963904.2261.1332762433787.JavaMail.geo-discussion-forums@vbbfw10> In FiPy (a finite volume PDE solver), equations are "magically" set up as eqX = TransientTerm() == ExplicitDiffusionTerm(coeff=D) and solved via eqX.solve(...) How can eqX be anything than True or False?... This must be via a redefinition of "==" but I can't see how that is done. I did look at many of the source files, thinking that it must be via a redefinition of "__eq__" somewhere but with no luck. Any pointers would be appreciated. From kiuhnm03.4t.yahoo.it Mon Mar 26 07:58:25 2012 From: kiuhnm03.4t.yahoo.it (Kiuhnm) Date: Mon, 26 Mar 2012 13:58:25 +0200 Subject: Documentation, assignment in expression. In-Reply-To: References: <4f6d0060$0$6634$9b4e6d93@newsspool2.arcor-online.net> <4f6f0d24$0$6561$9b4e6d93@newsspool4.arcor-online.net> <4F6F1792.1060709@tim.thechases.com> <4f6f36bf$0$1390$4fafbaef@reader2.news.tin.it> <4f704b5e$0$1389$4fafbaef@reader2.news.tin.it> Message-ID: <4f7059e1$0$1390$4fafbaef@reader2.news.tin.it> On 3/26/2012 13:13, Jussi Piitulainen wrote: > Kiuhnm writes: >> On 3/26/2012 10:52, Devin Jeanpierre wrote: >>> On Sun, Mar 25, 2012 at 11:16 AM, Kiuhnm >>> wrote: >>>> On 3/25/2012 15:48, Tim Chase wrote: >>>>> >>>>> The old curmudgeon in me likes the Pascal method of using "=" for >>>>> equality-testing, and ":=" for assignment which feels a little closer to >>>>> mathematical use of "=". >>>> >>>> >>>> Unfortunately, ":=" means "is defined as" in mathematics. The "right" >>>> operator would have been "<-". >>> >>> >>> "Is defined as" is actually pretty reasonable. "Define this to be >>> that" is a common way to speak about assignment. Its only difference >>> is the present tense. For example, in Python, "def" stands for >>> "define", but we can overwrite previous definitions:: >>> >>> def f(x): return x >>> def f(x): return 2 >>> f(3) == 2 >>> >>> In fact, in pretty every programming language that I know of with a >>> "define" assignment verb, this is so. For example, in Scheme, x is 2 >>> at the end:: >>> >>> (define x 1) >>> (define x 2) >>> x >> >> When you write >> (define x 1) >> (define x 2) >> x >> or, in F# and OCaml, >> let x = 1 >> let x = 2 >> x >> you're saying >> x = 1 >> { >> x = 2 >> x >> } >> You don't modify 'x': you hide it by defining another "value" (not >> variable) with the same name. >> Indeed, >> let x = 1 >> let x = 2 >> x >> is shorthand for >> let x = 1 in >> let x = 2 in >> x > > No, Devin is right about Scheme. On "top level" re-definition is > interpreted as assignment. The following mean the same: > > (define x 1) (define x 2) x > (define x 1) (set! x 2) x > > Local definitions in the beginning of a "body" do not allow duplicate > names at all. The following mean the same: > > (let () (define x 1) (define y 2) x) > (letrec* ((x 1) (y 2)) x) ;letrec in older versions (not sure of R6RS) > > But (let () (define x 1) (define x 2) x) is still an error. Some > implementations may give it a meaning. Not sure. Thanks for the correction. I haven't written a line of code in Scheme for 15 years and it shows :( Kiuhnm From rosuav at gmail.com Mon Mar 26 08:01:40 2012 From: rosuav at gmail.com (Chris Angelico) Date: Mon, 26 Mar 2012 23:01:40 +1100 Subject: Is there any difference between print 3 and print '3' in Python ? In-Reply-To: <5128580.32.1332762326119.JavaMail.geo-discussion-forums@pbom7> References: <5128580.32.1332762326119.JavaMail.geo-discussion-forums@pbom7> Message-ID: On Mon, Mar 26, 2012 at 10:45 PM, wrote: > I know the print statement produces the same result when both of these two instructions are executed ,I just want to know Is there any difference between print 3 and print '3' in Python ? One of them takes the integer 3, converts it into a string, and prints it. The other takes the string '3' and prints it. There's a lot of difference under the covers, but both will print a 3, followed by a newline. ChrisA From kiuhnm03.4t.yahoo.it Mon Mar 26 08:07:10 2012 From: kiuhnm03.4t.yahoo.it (Kiuhnm) Date: Mon, 26 Mar 2012 14:07:10 +0200 Subject: Is there any difference between print 3 and print '3' in Python ? In-Reply-To: <5128580.32.1332762326119.JavaMail.geo-discussion-forums@pbom7> References: <5128580.32.1332762326119.JavaMail.geo-discussion-forums@pbom7> Message-ID: <4f705bf1$0$1385$4fafbaef@reader2.news.tin.it> On 3/26/2012 13:45, redstone-cold at 163.com wrote: > I know the print statement produces the same result when both of > these two instructions are executed ,I just want to know Is there any > difference between print 3 and print '3' in Python ? The former prints a number while the latter a string. Kiuhnm From robert.kern at gmail.com Mon Mar 26 08:10:55 2012 From: robert.kern at gmail.com (Robert Kern) Date: Mon, 26 Mar 2012 13:10:55 +0100 Subject: Is there any difference between print 3 and print '3' in Python ? In-Reply-To: <5128580.32.1332762326119.JavaMail.geo-discussion-forums@pbom7> References: <5128580.32.1332762326119.JavaMail.geo-discussion-forums@pbom7> Message-ID: On 3/26/12 12:45 PM, redstone-cold at 163.com wrote: > I know the print statement produces the same result when both of these two instructions are executed ,I just want to know Is there any difference between print 3 and print '3' in Python ? Yes, there is a difference, but not much. [~] |6> import dis [~] |7> dis.disassemble(compile('print 3', '', 'exec')) 1 0 LOAD_CONST 0 (3) 3 PRINT_ITEM 4 PRINT_NEWLINE 5 LOAD_CONST 1 (None) 8 RETURN_VALUE [~] |8> dis.disassemble(compile('print "3"', '', 'exec')) 1 0 LOAD_CONST 0 ('3') 3 PRINT_ITEM 4 PRINT_NEWLINE 5 LOAD_CONST 1 (None) 8 RETURN_VALUE As you can see, the only difference is in the first instruction. Both of these put the object that you specified by the literal onto the stack. The difference is that one is the int object specified by the literal 3 and the other is the str object specified by the literal "3". Both of these objects happen to give the same __str__ output, so that's what gets printed. -- Robert Kern "I have come to believe that the whole world is an enigma, a harmless enigma that is made terrible by our own mad attempt to interpret it as though it had an underlying truth." -- Umberto Eco From d at davea.name Mon Mar 26 08:11:03 2012 From: d at davea.name (Dave Angel) Date: Mon, 26 Mar 2012 08:11:03 -0400 Subject: Is there any difference between print 3 and print '3' in Python ? In-Reply-To: <5128580.32.1332762326119.JavaMail.geo-discussion-forums@pbom7> References: <5128580.32.1332762326119.JavaMail.geo-discussion-forums@pbom7> Message-ID: <4F705CD7.7@davea.name> On 03/26/2012 07:45 AM, redstone-cold at 163.com wrote: > I know the print statement produces the same result when both of these two instructions are executed ,I just want to know Is there any difference between print 3 and print '3' in Python ? This is a non-question. The input is the same, the output is the same, what else matters? On the other hand, if you want to dig deeper, there are lots of differences: 1) the former has a shorter source file 2) different C code is utilized inside the interpreter 3) different machine code executes 4) the temporary objects created have different id's and types 5) different execution times (by a trivial amount) 6) it takes different keystrokes to edit the two source files once you want to make it do something useful 7) the processor works a little harder on one than the other, possibly resulting in a different power consumption 8) different byte code is produced Or you could be asking about Python version 3, in which case 1) the syntax error message points to a different character -- DaveA From robert.kern at gmail.com Mon Mar 26 08:16:07 2012 From: robert.kern at gmail.com (Robert Kern) Date: Mon, 26 Mar 2012 13:16:07 +0100 Subject: Puzzled by FiPy's use of "==" In-Reply-To: <24963904.2261.1332762433787.JavaMail.geo-discussion-forums@vbbfw10> References: <24963904.2261.1332762433787.JavaMail.geo-discussion-forums@vbbfw10> Message-ID: On 3/26/12 12:47 PM, Andr? Roberge wrote: > In FiPy (a finite volume PDE solver), equations are "magically" set up as > > eqX = TransientTerm() == ExplicitDiffusionTerm(coeff=D) > > and solved via > > eqX.solve(...) > > How can eqX be anything than True or False?... This must be via a redefinition of "==" but I can't see how that is done. I did look at many of the source files, thinking that it must be via a redefinition of "__eq__" somewhere but with no luck. Any pointers would be appreciated. It's in the root base class Term: http://matforge.org/fipy/browser/trunk/fipy/terms/term.py#L374 -- Robert Kern "I have come to believe that the whole world is an enigma, a harmless enigma that is made terrible by our own mad attempt to interpret it as though it had an underlying truth." -- Umberto Eco From andre.roberge at gmail.com Mon Mar 26 08:21:58 2012 From: andre.roberge at gmail.com (=?ISO-8859-1?Q?Andr=E9_Roberge?=) Date: Mon, 26 Mar 2012 05:21:58 -0700 (PDT) Subject: Puzzled by FiPy's use of "==" In-Reply-To: References: <24963904.2261.1332762433787.JavaMail.geo-discussion-forums@vbbfw10> Message-ID: <22079866.1390.1332764518212.JavaMail.geo-discussion-forums@vbmf37> On Monday, 26 March 2012 09:16:07 UTC-3, Robert Kern wrote: > On 3/26/12 12:47 PM, Andr? Roberge wrote: > > In FiPy (a finite volume PDE solver), equations are "magically" set up as > > > > eqX = TransientTerm() == ExplicitDiffusionTerm(coeff=D) > > > > and solved via > > > > eqX.solve(...) > > > > How can eqX be anything than True or False?... This must be via a redefinition of "==" but I can't see how that is done. I did look at many of the source files, thinking that it must be via a redefinition of "__eq__" somewhere but with no luck. Any pointers would be appreciated. > > It's in the root base class Term: > > http://matforge.org/fipy/browser/trunk/fipy/terms/term.py#L374 > I thought I looked at terms.py ... but I must have missed that. Thanks! > -- > Robert Kern > > "I have come to believe that the whole world is an enigma, a harmless enigma > that is made terrible by our own mad attempt to interpret it as though it had > an underlying truth." > -- Umberto Eco From andre.roberge at gmail.com Mon Mar 26 08:21:58 2012 From: andre.roberge at gmail.com (=?ISO-8859-1?Q?Andr=E9_Roberge?=) Date: Mon, 26 Mar 2012 05:21:58 -0700 (PDT) Subject: Puzzled by FiPy's use of "==" In-Reply-To: References: <24963904.2261.1332762433787.JavaMail.geo-discussion-forums@vbbfw10> Message-ID: <22079866.1390.1332764518212.JavaMail.geo-discussion-forums@vbmf37> On Monday, 26 March 2012 09:16:07 UTC-3, Robert Kern wrote: > On 3/26/12 12:47 PM, Andr? Roberge wrote: > > In FiPy (a finite volume PDE solver), equations are "magically" set up as > > > > eqX = TransientTerm() == ExplicitDiffusionTerm(coeff=D) > > > > and solved via > > > > eqX.solve(...) > > > > How can eqX be anything than True or False?... This must be via a redefinition of "==" but I can't see how that is done. I did look at many of the source files, thinking that it must be via a redefinition of "__eq__" somewhere but with no luck. Any pointers would be appreciated. > > It's in the root base class Term: > > http://matforge.org/fipy/browser/trunk/fipy/terms/term.py#L374 > I thought I looked at terms.py ... but I must have missed that. Thanks! > -- > Robert Kern > > "I have come to believe that the whole world is an enigma, a harmless enigma > that is made terrible by our own mad attempt to interpret it as though it had > an underlying truth." > -- Umberto Eco From jeanmichel at sequans.com Mon Mar 26 08:36:19 2012 From: jeanmichel at sequans.com (Jean-Michel Pichavant) Date: Mon, 26 Mar 2012 14:36:19 +0200 Subject: verbs in comments [OT] In-Reply-To: <4f6e2265$0$1382$4fafbaef@reader2.news.tin.it> References: <4f6e2265$0$1382$4fafbaef@reader2.news.tin.it> Message-ID: <4F7062C3.8080004@sequans.com> Kiuhnm wrote: > Why do you write > // Print the number of words... > def printNumWords(): ... > and not > // Prints the number of words... > def printNumWords(): ... > where "it" is understood? > Is that an imperative or a base form or something else? > > Kiuhnm http://www.python.org/dev/peps/pep-0257/ "The docstring is a phrase ending in a period. It prescribes the function or method's effect as a command ("Do this", "Return that"), not as a description; e.g. don't write "Returns the pathname ..." I apply the same rule to comments, I now don't loose time asking myself how to write these docs/comments. JM From akghosh3 at gmail.com Mon Mar 26 08:52:26 2012 From: akghosh3 at gmail.com (Aloke Ghosh) Date: Mon, 26 Mar 2012 18:22:26 +0530 Subject: help needed to understand an error message. In-Reply-To: References: Message-ID: Hi, I am learning Python and do not have programming experience. I was following an exercise from http://learnpythonthehardway.org/book/ex2.html and made a mistake in entry : *Print"I like typing this."* and got the following error message: *In [2]: Print"I like typing this."* *------------------------------------------------------------* * File "", line 1* * Print"I like typing this."* * ^* *SyntaxError: invalid syntax* I feel the error is in Capital P in print . However the error indicated with "*^*" hints at quote at the end of the line. *Can any one please help me understand this.* -- A.K.Ghosh -------------- next part -------------- An HTML attachment was scrubbed... URL: From jeanmichel at sequans.com Mon Mar 26 09:26:24 2012 From: jeanmichel at sequans.com (Jean-Michel Pichavant) Date: Mon, 26 Mar 2012 15:26:24 +0200 Subject: help needed to understand an error message. In-Reply-To: References: Message-ID: <4F706E80.7090809@sequans.com> Aloke Ghosh wrote: > Hi, > I am learning Python and do not have programming experience. > I was following > an exercise from http://learnpythonthehardway.org/book/ex2.html > and made a mistake in entry : > > *Print"I like typing this."* > > and got the following error message: > > *In [2]: Print"I like typing this."* > *------------------------------------------------------------* > * File "", line 1* > * Print"I like typing this."* > * ^* > *SyntaxError: invalid syntax* > > I feel the error is in Capital P in print . > However the error indicated with "*^*" > hints at quote at the end of the line. > > *Can any one please help me understand this.* > > -- > A.K.Ghosh Why don't you just try with a lowercase p ? The correct syntax would be print "I like typing this" or in Python 3: print ("I like typing this") Anyway, the hint indicates the last quote because this is the location where the python interpreter realizes it won't be able to execute the code. You should not worry about that too much. JM From steveo at syslang.net Mon Mar 26 09:33:28 2012 From: steveo at syslang.net (Steven W. Orr) Date: Mon, 26 Mar 2012 09:33:28 -0400 Subject: Question about collections.defaultdict Message-ID: <4F707028.4000407@syslang.net> I created a new class called CaseInsensitiveDict (by stealing from code I found on the web, thank you very much). The new class inherits from dict. It makes it so that if the key has a 'lower' method, it will always access the key using lower I'd like to change the place where I previously declared a dict self.lookup = defaultdict(list) so that the new code will allow this new dict to be used instead. But then I realized I may have painted myself into a small corner: Is there a way to use defaultdict so that I can override what *kind* of dict it will use? I would like the value to still be a list be default, but it seems like I can't tell defaultdict to use *my* new dict. Do I give up on defaultdict? BTW, 2.6 if it matters. TIA :-) -- Time flies like the wind. Fruit flies like a banana. Stranger things have .0. happened but none stranger than this. Does your driver's license say Organ ..0 Donor?Black holes are where God divided by zero. Listen to me! We are all- 000 individuals! What if this weren't a hypothetical question? steveo at syslang.net From robert.kern at gmail.com Mon Mar 26 09:44:51 2012 From: robert.kern at gmail.com (Robert Kern) Date: Mon, 26 Mar 2012 14:44:51 +0100 Subject: Question about collections.defaultdict In-Reply-To: <4F707028.4000407@syslang.net> References: <4F707028.4000407@syslang.net> Message-ID: On 3/26/12 2:33 PM, Steven W. Orr wrote: > I created a new class called CaseInsensitiveDict (by stealing from code I found > on the web, thank you very much). The new class inherits from dict. It makes it > so that if the key has a 'lower' method, it will always access the key using lower > > I'd like to change the place where I previously declared a dict > > self.lookup = defaultdict(list) > > so that the new code will allow this new dict to be used instead. But then I > realized I may have painted myself into a small corner: > > Is there a way to use defaultdict so that I can override what *kind* of dict it > will use? No. > I would like the value to still be a list be default, but it seems like I can't > tell defaultdict to use *my* new dict. > > Do I give up on defaultdict? Assuming that your CaseInsensitiveDict subclasses from dict or UserDict, it's relatively easy to make a subclass of your CaseInsensitiveDict act like a defaultdict. Just implement the __missing__(key) method appropriately (and modify the constructor to take the callable, of course). http://docs.python.org/library/stdtypes.html#dict http://docs.python.org/library/collections.html#collections.defaultdict.__missing__ -- Robert Kern "I have come to believe that the whole world is an enigma, a harmless enigma that is made terrible by our own mad attempt to interpret it as though it had an underlying truth." -- Umberto Eco From nutznetz-0c1b6768-bfa9-48d5-a470-7603bd3aa915 at spamschutz.glglgl.de Mon Mar 26 09:54:52 2012 From: nutznetz-0c1b6768-bfa9-48d5-a470-7603bd3aa915 at spamschutz.glglgl.de (Thomas Rachel) Date: Mon, 26 Mar 2012 15:54:52 +0200 Subject: Documentation, assignment in expression. In-Reply-To: References: <4f6d0060$0$6634$9b4e6d93@newsspool2.arcor-online.net> <4f6f0d24$0$6561$9b4e6d93@newsspool4.arcor-online.net> <4F6F1792.1060709@tim.thechases.com> <4F6F222F.7050406@tim.thechases.com> Message-ID: Am 26.03.2012 00:59 schrieb Dennis Lee Bieber: > If you use the longer form > > con = db.connect() > cur = con.cursor() > > the cursor object, in all that I've worked with, does function for > iteration I use this form regularly with MySQLdb and am now surprised to see that this is optional according to http://www.python.org/dev/peps/pep-0249/. So a database cursor is not required to be iterable, alas. Thomas From ian.douglas at iandouglas.com Mon Mar 26 09:55:21 2012 From: ian.douglas at iandouglas.com (ian douglas) Date: Mon, 26 Mar 2012 06:55:21 -0700 Subject: random number In-Reply-To: <4f7019b6$0$29968$c3e8da3$5496439d@news.astraweb.com> References: <4f7019b6$0$29968$c3e8da3$5496439d@news.astraweb.com> Message-ID: On Mar 26, 2012 12:28 AM, "Steven D'Aprano" < steve+comp.lang.python at pearwood.info> wrote: > > On Mon, 26 Mar 2012 08:40:00 +0200, Michael Poeltl wrote: > > > * Nikhil Verma [2012-03-26 08:09]: > A truly random six digit number will include any number between 100000 > through 999999. There are exactly 900000 (nine hundred thousand) such > numbers. Actually, considering that 000000 would still fit the parameter of a 6 "digit" number, there are exactly one million such numbers. -------------- next part -------------- An HTML attachment was scrubbed... URL: From nutznetz-0c1b6768-bfa9-48d5-a470-7603bd3aa915 at spamschutz.glglgl.de Mon Mar 26 09:59:08 2012 From: nutznetz-0c1b6768-bfa9-48d5-a470-7603bd3aa915 at spamschutz.glglgl.de (Thomas Rachel) Date: Mon, 26 Mar 2012 15:59:08 +0200 Subject: Documentation, assignment in expression. In-Reply-To: References: <4f6d0060$0$6634$9b4e6d93@newsspool2.arcor-online.net> <4f6f0d24$0$6561$9b4e6d93@newsspool4.arcor-online.net> Message-ID: Am 25.03.2012 15:03 schrieb Tim Chase: > Perhaps a DB example > works better. With assignment allowed in an evaluation, you'd be able to > write > > while data = conn.fetchmany(): > for row in data: > process(row) > > whereas you have to write > > while True: > data = conn.fetchmany() > if not data: break > for row in data: > process(row) Or simpler for data in iter(conn.fetchmany, []): for row in data: process(row) provided that a block of rows is returned as a list - which might be different among DB engines. Thomas From redstone-cold at 163.com Mon Mar 26 10:28:25 2012 From: redstone-cold at 163.com (redstone-cold at 163.com) Date: Mon, 26 Mar 2012 07:28:25 -0700 (PDT) Subject: Is there any difference between print 3 and print '3' in Python ? In-Reply-To: References: <5128580.32.1332762326119.JavaMail.geo-discussion-forums@pbom7> Message-ID: <9916924.0.1332772105737.JavaMail.geo-discussion-forums@pbbls7> ? 2012?3?26????UTC+8??8?11?03??Dave Angel??? > On 03/26/2012 07:45 AM, redstone-cold at 163.com wrote: > > I know the print statement produces the same result when both of these two instructions are executed ,I just want to know Is there any difference between print 3 and print '3' in Python ? > > This is a non-question. The input is the same, the output is the same, > what else matters? > > On the other hand, if you want to dig deeper, there are lots of differences: > > 1) the former has a shorter source file > 2) different C code is utilized inside the interpreter > 3) different machine code executes > 4) the temporary objects created have different id's and types > 5) different execution times (by a trivial amount) > 6) it takes different keystrokes to edit the two source files once you > want to make it do something useful > 7) the processor works a little harder on one than the other, possibly > resulting in a different power consumption > 8) different byte code is produced > > Or you could be asking about Python version 3, in which case > 1) the syntax error message points to a different character > > -- > > DaveA ? 2012?3?26????UTC+8??8?11?03??Dave Angel??? > On 03/26/2012 07:45 AM, redstone-cold at 163.com wrote: > > I know the print statement produces the same result when both of these two instructions are executed ,I just want to know Is there any difference between print 3 and print '3' in Python ? > > This is a non-question. The input is the same, the output is the same, > what else matters? > > On the other hand, if you want to dig deeper, there are lots of differences: > > 1) the former has a shorter source file > 2) different C code is utilized inside the interpreter > 3) different machine code executes > 4) the temporary objects created have different id's and types > 5) different execution times (by a trivial amount) > 6) it takes different keystrokes to edit the two source files once you > want to make it do something useful > 7) the processor works a little harder on one than the other, possibly > resulting in a different power consumption > 8) different byte code is produced > > Or you could be asking about Python version 3, in which case > 1) the syntax error message points to a different character > > -- > > DaveA Oh ,God ! I think this is what I really want to know ,thank you very much ! From redstone-cold at 163.com Mon Mar 26 10:28:25 2012 From: redstone-cold at 163.com (redstone-cold at 163.com) Date: Mon, 26 Mar 2012 07:28:25 -0700 (PDT) Subject: Is there any difference between print 3 and print '3' in Python ? In-Reply-To: References: <5128580.32.1332762326119.JavaMail.geo-discussion-forums@pbom7> Message-ID: <9916924.0.1332772105737.JavaMail.geo-discussion-forums@pbbls7> ? 2012?3?26????UTC+8??8?11?03??Dave Angel??? > On 03/26/2012 07:45 AM, redstone-cold at 163.com wrote: > > I know the print statement produces the same result when both of these two instructions are executed ,I just want to know Is there any difference between print 3 and print '3' in Python ? > > This is a non-question. The input is the same, the output is the same, > what else matters? > > On the other hand, if you want to dig deeper, there are lots of differences: > > 1) the former has a shorter source file > 2) different C code is utilized inside the interpreter > 3) different machine code executes > 4) the temporary objects created have different id's and types > 5) different execution times (by a trivial amount) > 6) it takes different keystrokes to edit the two source files once you > want to make it do something useful > 7) the processor works a little harder on one than the other, possibly > resulting in a different power consumption > 8) different byte code is produced > > Or you could be asking about Python version 3, in which case > 1) the syntax error message points to a different character > > -- > > DaveA ? 2012?3?26????UTC+8??8?11?03??Dave Angel??? > On 03/26/2012 07:45 AM, redstone-cold at 163.com wrote: > > I know the print statement produces the same result when both of these two instructions are executed ,I just want to know Is there any difference between print 3 and print '3' in Python ? > > This is a non-question. The input is the same, the output is the same, > what else matters? > > On the other hand, if you want to dig deeper, there are lots of differences: > > 1) the former has a shorter source file > 2) different C code is utilized inside the interpreter > 3) different machine code executes > 4) the temporary objects created have different id's and types > 5) different execution times (by a trivial amount) > 6) it takes different keystrokes to edit the two source files once you > want to make it do something useful > 7) the processor works a little harder on one than the other, possibly > resulting in a different power consumption > 8) different byte code is produced > > Or you could be asking about Python version 3, in which case > 1) the syntax error message points to a different character > > -- > > DaveA Oh ,God ! I think this is what I really want to know ,thank you very much ! From 3beezer at gmail.com Mon Mar 26 10:41:37 2012 From: 3beezer at gmail.com (jeff) Date: Mon, 26 Mar 2012 07:41:37 -0700 (PDT) Subject: Inconsistency between os.getgroups and os.system('groups') after os.setgroups() In-Reply-To: <87ty1cgqj1.fsf@benfinney.id.au> References: <19158239.1073.1332711120749.JavaMail.geo-discussion-forums@ynlx41> <7418918.681.1332718439318.JavaMail.geo-discussion-forums@yneo2> <87ty1cgqj1.fsf@benfinney.id.au> Message-ID: <1229886.3.1332772897822.JavaMail.geo-discussion-forums@ynbp21> On Sunday, March 25, 2012 6:22:10 PM UTC-6, Ben Finney wrote: > jeff writes: > > > On Sunday, March 25, 2012 4:04:55 PM UTC-6, Heiko Wundram wrote: > > > Am 25.03.2012 23:32, schrieb jeff: > > > > but I have to be able to get back to root privilege so I can't use > > > > setgid and setuid. > > > > > > Simply not possible (i.e., you can't drop root privileges, be it by > > > setuid()/setgid() or removing yourself from groups with setgroups()), > > > and later reacquire them _in the same process_. See the discussion of > > > how to implement privilege separation at > > > > > > http://www.citi.umich.edu/u/provos/ssh/privsep.html > > > > os.system("su -m -c ''") > > > > seems to do the trick. > > Yes, because ?os.system? explicitly starts a new process. > > It can't be done in the same process, as Heiko correctly said. > > -- > \ ?Faith, n. Belief without evidence in what is told by one who | > `\ speaks without knowledge, of things without parallel.? ?Ambrose | > _o__) Bierce, _The Devil's Dictionary_, 1906 | > Ben Finney I didn't ask how to do it in the same process, but thanks to both of you for that information. By the way, are you guys aware of seteuid and setegid? From colton.myers at gmail.com Mon Mar 26 10:43:59 2012 From: colton.myers at gmail.com (Colton Myers) Date: Mon, 26 Mar 2012 08:43:59 -0600 Subject: Is there any difference between print 3 and print '3' in Python ? In-Reply-To: <5128580.32.1332762326119.JavaMail.geo-discussion-forums@pbom7> References: <5128580.32.1332762326119.JavaMail.geo-discussion-forums@pbom7> Message-ID: > I know the print statement produces the same result when both of these two instructions are executed ,I just want to know Is there any difference between print 3 and print '3' in Python ? Sure there is. The first converts the integer 3 to a string ("3"), the second just prints the given string "3". Does that make sense? -- Colton Myers -------------- next part -------------- An HTML attachment was scrubbed... URL: From stefan_ml at behnel.de Mon Mar 26 11:03:21 2012 From: stefan_ml at behnel.de (Stefan Behnel) Date: Mon, 26 Mar 2012 17:03:21 +0200 Subject: Is there any difference between print 3 and print '3' in Python ? In-Reply-To: <9916924.0.1332772105737.JavaMail.geo-discussion-forums@pbbls7> References: <5128580.32.1332762326119.JavaMail.geo-discussion-forums@pbom7> <9916924.0.1332772105737.JavaMail.geo-discussion-forums@pbbls7> Message-ID: redstone-cold at 163.com, 26.03.2012 16:28: > ? 2012?3?26????UTC+8??8?11?03??Dave Angel??? >> On 03/26/2012 07:45 AM, redstone-cold at 163.com wrote: >>> I know the print statement produces the same result when both of these two instructions are executed ,I just want to know Is there any difference between print 3 and print '3' in Python ? >> >> This is a non-question. The input is the same, the output is the same, >> what else matters? >> >> On the other hand, if you want to dig deeper, there are lots of differences: >> >> 1) the former has a shorter source file >> 2) different C code is utilized inside the interpreter >> 3) different machine code executes >> 4) the temporary objects created have different id's and types >> 5) different execution times (by a trivial amount) >> 6) it takes different keystrokes to edit the two source files once you >> want to make it do something useful >> 7) the processor works a little harder on one than the other, possibly >> resulting in a different power consumption >> 8) different byte code is produced >> >> Or you could be asking about Python version 3, in which case >> 1) the syntax error message points to a different character > > Oh ,God ! I don't think she takes any responsibility for the list above. Stefan From steveo at syslang.net Mon Mar 26 11:33:32 2012 From: steveo at syslang.net (Steven W. Orr) Date: Mon, 26 Mar 2012 11:33:32 -0400 Subject: Question about collections.defaultdict In-Reply-To: References: <4F707028.4000407@syslang.net> Message-ID: <4F708C4C.5050700@syslang.net> On 3/26/2012 9:44 AM, Robert Kern wrote: > On 3/26/12 2:33 PM, Steven W. Orr wrote: >> I created a new class called CaseInsensitiveDict (by stealing from code I found >> on the web, thank you very much). The new class inherits from dict. It makes it >> so that if the key has a 'lower' method, it will always access the key using >> lower >> >> I'd like to change the place where I previously declared a dict >> >> self.lookup = defaultdict(list) >> >> so that the new code will allow this new dict to be used instead. But then I >> realized I may have painted myself into a small corner: >> >> Is there a way to use defaultdict so that I can override what *kind* of dict it >> will use? > > No. > >> I would like the value to still be a list be default, but it seems like I can't >> tell defaultdict to use *my* new dict. >> >> Do I give up on defaultdict? > > Assuming that your CaseInsensitiveDict subclasses from dict or UserDict, it's > relatively easy to make a subclass of your CaseInsensitiveDict act like a > defaultdict. Just implement the __missing__(key) method appropriately (and > modify the constructor to take the callable, of course). > > http://docs.python.org/library/stdtypes.html#dict > http://docs.python.org/library/collections.html#collections.defaultdict.__missing__ > > I'm not quite getting what you're telling me, but I'm sure you have the right idea. Here's the beginning of my class: class CaseInsensitiveDict(dict): def __init__(self, init=None): if isinstance(init, (dict, list, tuple)): for kk, vv in init.items(): self[self.key_has_lower(kk)] = vv It sounds like you want me to subclass defaultdict to create something like this? class CaseInsensitiveDictDef(defaultdict): def __init__(self, init=None): super(CaseInsensitiveDictDef, self).__init__(list) self.__missing__ = list I think I'm way off base. I'm not clear on what the calling sequence is for defaultdict or how to get it to use my CaseInsensitiveDict instead of regular dict. Can you help? -- Time flies like the wind. Fruit flies like a banana. Stranger things have .0. happened but none stranger than this. Does your driver's license say Organ ..0 Donor?Black holes are where God divided by zero. Listen to me! We are all- 000 individuals! What if this weren't a hypothetical question? steveo at syslang.net From tjreedy at udel.edu Mon Mar 26 11:39:29 2012 From: tjreedy at udel.edu (Terry Reedy) Date: Mon, 26 Mar 2012 11:39:29 -0400 Subject: why did GMPY change the names of its functions? In-Reply-To: <39ff04b9-84a0-401c-a0a5-75e33cf59bc8@vy9g2000pbc.googlegroups.com> References: <39ff04b9-84a0-401c-a0a5-75e33cf59bc8@vy9g2000pbc.googlegroups.com> Message-ID: On 3/26/2012 12:59 AM, Mensanator wrote: > OK, GMPY is now called GMPY2. No big deal, I can import as GMPY. > > But why were scan0 and scan1 changed to bit_scan0 and bit_scan1? Guess: Either the functions changed or they want to regularize their names. > What's the justification for that? I use those functions extensively > in my library of Collatz utilities and I had to re-edit them for no > obvious reason. If GMPY is coded in Python with a C? backup, GMPY.scan0 = GMPY.bit_scan0 should work. Or you could write a GMPY.py wrapper for GMPY2 from GMPY2 import * scan0=bit_scan0 scan1=bit_scan1 and leave your user code alone. -- Terry Jan Reedy From tjreedy at udel.edu Mon Mar 26 11:45:51 2012 From: tjreedy at udel.edu (Terry Reedy) Date: Mon, 26 Mar 2012 11:45:51 -0400 Subject: Is there any difference between print 3 and print '3' in Python ? In-Reply-To: <5128580.32.1332762326119.JavaMail.geo-discussion-forums@pbom7> References: <5128580.32.1332762326119.JavaMail.geo-discussion-forums@pbom7> Message-ID: On 3/26/2012 7:45 AM, redstone-cold at 163.com wrote: > I know the print statement produces the same result when both of > these two instructions are executed ,I just want to know Is there any > difference between print 3 and print '3' in Python ? If you want to see the difference between the number and string representation thereof, use repr(x). >>> print(repr(3), repr('3'), [3, '3']) 3 '3' [3, '3'] Note that printing a collection prints the repr() of each item precisely so one can tell the difference between the item being a number or a string. -- Terry Jan Reedy From robert.kern at gmail.com Mon Mar 26 11:52:47 2012 From: robert.kern at gmail.com (Robert Kern) Date: Mon, 26 Mar 2012 16:52:47 +0100 Subject: Question about collections.defaultdict In-Reply-To: <4F708C4C.5050700@syslang.net> References: <4F707028.4000407@syslang.net> <4F708C4C.5050700@syslang.net> Message-ID: On 3/26/12 4:33 PM, Steven W. Orr wrote: > On 3/26/2012 9:44 AM, Robert Kern wrote: >> On 3/26/12 2:33 PM, Steven W. Orr wrote: >>> I created a new class called CaseInsensitiveDict (by stealing from code I found >>> on the web, thank you very much). The new class inherits from dict. It makes it >>> so that if the key has a 'lower' method, it will always access the key using >>> lower >>> >>> I'd like to change the place where I previously declared a dict >>> >>> self.lookup = defaultdict(list) >>> >>> so that the new code will allow this new dict to be used instead. But then I >>> realized I may have painted myself into a small corner: >>> >>> Is there a way to use defaultdict so that I can override what *kind* of dict it >>> will use? >> >> No. >> >>> I would like the value to still be a list be default, but it seems like I can't >>> tell defaultdict to use *my* new dict. >>> >>> Do I give up on defaultdict? >> >> Assuming that your CaseInsensitiveDict subclasses from dict or UserDict, it's >> relatively easy to make a subclass of your CaseInsensitiveDict act like a >> defaultdict. Just implement the __missing__(key) method appropriately (and >> modify the constructor to take the callable, of course). >> >> http://docs.python.org/library/stdtypes.html#dict >> http://docs.python.org/library/collections.html#collections.defaultdict.__missing__ >> >> >> > > I'm not quite getting what you're telling me, but I'm sure you have the right > idea. Here's the beginning of my class: > > class CaseInsensitiveDict(dict): > def __init__(self, init=None): > if isinstance(init, (dict, list, tuple)): > for kk, vv in init.items(): > self[self.key_has_lower(kk)] = vv > > > It sounds like you want me to subclass defaultdict to create something like this? > > class CaseInsensitiveDictDef(defaultdict): > def __init__(self, init=None): > super(CaseInsensitiveDictDef, self).__init__(list) > self.__missing__ = list > > I think I'm way off base. I'm not clear on what the calling sequence is for > defaultdict or how to get it to use my CaseInsensitiveDict instead of regular dict. > > Can you help? You need to make a subclass of CaseInsensitiveDict, implement the __missing__(key) method, and override the __init__() method to take the factory function as an argument instead of data. defaultdict is just a subclass of dict that does this. class CaseInsensitiveDictDef(CaseInsensitiveDict): def __init__(self, default_factory): super(CaseInsensitiveDictDef, self).__init__() self.default_factory = default_factory def __missing__(self, key): return self.default_factory() -- Robert Kern "I have come to believe that the whole world is an enigma, a harmless enigma that is made terrible by our own mad attempt to interpret it as though it had an underlying truth." -- Umberto Eco From tjreedy at udel.edu Mon Mar 26 12:00:50 2012 From: tjreedy at udel.edu (Terry Reedy) Date: Mon, 26 Mar 2012 12:00:50 -0400 Subject: Documentation, assignment in expression. In-Reply-To: <4f70005c$0$29968$c3e8da3$5496439d@news.astraweb.com> References: <4f6d0060$0$6634$9b4e6d93@newsspool2.arcor-online.net> <4f6f0d24$0$6561$9b4e6d93@newsspool4.arcor-online.net> <4f70005c$0$29968$c3e8da3$5496439d@news.astraweb.com> Message-ID: On 3/26/2012 1:36 AM, Steven D'Aprano wrote: > > (I seem to recall a language that used a single = for both assignment and > equality testing, guessing which one you meant from context. BASIC > perhaps? Right. In some Basics, such as MS GW-Basic (I still have their book), a = b = c meant a = (b = c), or in Python, a = b==c. -- Terry Jan Reedy From sathyaish at gmail.com Mon Mar 26 12:14:57 2012 From: sathyaish at gmail.com (Sathyaish) Date: Mon, 26 Mar 2012 09:14:57 -0700 (PDT) Subject: A play about the Indian IT industry Message-ID: My name is Sathyaish. I am a software engineer. Last year, i.e. in 2011, I wanted to do some theater. No one took me, so I announced that I would start my own group. I wrote a script. Then, I wrote a screen play from that. Now, I am almost ready to begin the auditions. The play will be a comedy with a sad undertone profiling the life (or rather the lack) of programmers and how they are generally taken for granted and treated poorly by people who should really have been working in a bread making factory baking bread, or people who should have been making biscuits or whatever, i.e. the non-technical people in the software development industry who have become managers and architects and what-not. Here is a teaser: http://www.youtube.com/watch?v=6V-Lchu7aiA I hope you like it. I'll be posting more stuff about this play on the Web page at http://sathyaish.net/acting The play will be performed at a theater in New Delhi, India. The group that I am organizing to perform this play will rehearse only over weekends so that they may keep their day jobs. I expect that the auditions will run through April 2012. We will start rehearsing in May 2012 and will carry on with the rehearsals for May, June, July, August and September 2012 only over the weekends. We should perform in the last week of September 2012 or some time in October 2012. From ian.g.kelly at gmail.com Mon Mar 26 12:48:01 2012 From: ian.g.kelly at gmail.com (Ian Kelly) Date: Mon, 26 Mar 2012 10:48:01 -0600 Subject: random number In-Reply-To: <20120326092403.GB22725@terra.cms.at> References: <20120326064000.GB19865@terra.cms.at> <20120326092403.GB22725@terra.cms.at> Message-ID: On Mon, Mar 26, 2012 at 3:24 AM, Michael Poeltl wrote: >>>> import random, string >>>> def random_number(id): > ... ? ? characters = list(string.ascii_lowercase + > ... ? ? ? ? ? ? ? ? ? ? ? string.ascii_uppercase + > ... ? ? ? ? ? ? ? ? ? ? ? string.digits) > ... ? ? coll_rand = [] > ... ? ? for i in range(6): > ... ? ? ? ? random.shuffle(characters) > ... ? ? ? ? coll_rand.append(characters[0]) > ... ? ? return ''.join(coll_rand) You don't need to do all that list manipulation. This is probably quicker: def random_number(): # Unused "id" parameter omitted characters = (string.ascii_lowercase + string.ascii_uppercase + string.digits) return ''.join(random.choice(characters) for i in range(6)) Cheers, Ian From jcd at sdf.lonestar.org Mon Mar 26 13:06:58 2012 From: jcd at sdf.lonestar.org (J. Cliff Dyer) Date: Mon, 26 Mar 2012 13:06:58 -0400 Subject: Is there any difference between print 3 and print '3' in Python ? In-Reply-To: <5128580.32.1332762326119.JavaMail.geo-discussion-forums@pbom7> References: <5128580.32.1332762326119.JavaMail.geo-discussion-forums@pbom7> Message-ID: <1332781618.3893.10.camel@jcdyer-laptop> As others have pointed out, the output is the same, because the result of converting an integer to a string is the string of that integer. However, other numeric literals might not do what you want, due to the fact that they are converted to an internal numeric representation, then converted back to a string in a canonical format. >>> print 3, '3' 3 3 >>> print 3.00, '3.00' 3.0 3.00 >>> print 0x3, '0x3' 3 0x3 >>> print 03, '03' 3 03 >>> print 3e0, '3e0' 3.0 3e0 You might think that the take away message is to use the string representation, since it prints what you tell it to print. However, if you use a number, you can specify the output formatting with more fine-grained control, and even exert that control on calculated number: >>> print '%0.2f' % (3,) 3.00 >>> print '%0.2f' % (2 + 1) 3.00 This is better because you can't perform math on a string: >>> print '2' + '1' 21 >>> print '2.00' + '1.00' 2.001.00 print '2 + 1' 2 + 1 So in general, you should use numbers, and then format them using standard string formatting operations when you want to print them. There's more information on how to do formatting here: http://docs.python.org/library/stdtypes.html#string-formatting Cheers, Cliff On Mon, 2012-03-26 at 04:45 -0700, redstone-cold at 163.com wrote: > I know the print statement produces the same result when both of these > two instructions are executed ,I just want to know Is there any > difference between print 3 and print '3' in Python ? From __peter__ at web.de Mon Mar 26 13:20:10 2012 From: __peter__ at web.de (Peter Otten) Date: Mon, 26 Mar 2012 19:20:10 +0200 Subject: Is there any difference between print 3 and print '3' in Python ? References: <5128580.32.1332762326119.JavaMail.geo-discussion-forums@pbom7> Message-ID: redstone-cold at 163.com wrote: > I know the print statement produces the same result when both of these two > instructions are executed ,I just want to know Is there any difference > between print 3 and print '3' in Python ? The question you really wanted to ask is: under what circumstances will the two statements produce different output? Here's what I found: $ PYTHONIOENCODING=hex python -c'from __future__ import unicode_literals print 3' 3 $ PYTHONIOENCODING=hex python -c'from __future__ import unicode_literals print "3"' 33 $ :) From python.list at tim.thechases.com Mon Mar 26 13:42:53 2012 From: python.list at tim.thechases.com (Tim Chase) Date: Mon, 26 Mar 2012 12:42:53 -0500 Subject: Documentation, assignment in expression. In-Reply-To: References: <4f6d0060$0$6634$9b4e6d93@newsspool2.arcor-online.net> <4f6f0d24$0$6561$9b4e6d93@newsspool4.arcor-online.net> Message-ID: <4F70AA9D.6090704@tim.thechases.com> On 03/26/12 08:59, Thomas Rachel wrote: > Am 25.03.2012 15:03 schrieb Tim Chase: >> while True: >> data = conn.fetchmany() >> if not data: break >> for row in data: >> process(row) > > Or simpler > > for data in iter(conn.fetchmany, []): > for row in data: > process(row) Nice! That's the first time I've seen the 2-parameter version of iter() improve things :-) (I've seen it once or twice before in the 2-param form, and wondered why it wasn't written in a clearer way). Also, I was surprised to learn that the sentinel was available as far back as 2.2 (I knew about the 1-param version as far back as 2.3 when I became more serious about Python). -tkc From mensanator at aol.com Mon Mar 26 14:27:14 2012 From: mensanator at aol.com (Mensanator) Date: Mon, 26 Mar 2012 11:27:14 -0700 (PDT) Subject: why did GMPY change the names of its functions? References: <39ff04b9-84a0-401c-a0a5-75e33cf59bc8@vy9g2000pbc.googlegroups.com> Message-ID: <20665b28-a2ca-45ee-ba91-12481653d9a2@sv8g2000pbc.googlegroups.com> On Mar 26, 10:39?am, Terry Reedy wrote: > On 3/26/2012 12:59 AM, Mensanator wrote: > > > OK, GMPY is now called GMPY2. No big deal, I can import as GMPY. > > > But why were scan0 and scan1 changed to bit_scan0 and bit_scan1? > > Guess: Either the functions changed or they want to regularize their names. > > > What's the justification for that? I use those functions extensively > > in my library of Collatz utilities ?and I had to re-edit them for no > > obvious reason. > > If GMPY is coded in Python with a C? backup, GMPY.scan0 = GMPY.bit_scan0 > should work. > > Or you could write a GMPY.py wrapper for GMPY2 > > from GMPY2 import * > scan0=bit_scan0 > scan1=bit_scan1 > > > and leave your user code alone. > > -- > Terry Jan Reedy Oh, similar to an "import as", but this would allow me to change individual functions. Thanks. From casevh at gmail.com Mon Mar 26 14:33:17 2012 From: casevh at gmail.com (casevh at gmail.com) Date: Mon, 26 Mar 2012 11:33:17 -0700 (PDT) Subject: why did GMPY change the names of its functions? In-Reply-To: <39ff04b9-84a0-401c-a0a5-75e33cf59bc8@vy9g2000pbc.googlegroups.com> References: <39ff04b9-84a0-401c-a0a5-75e33cf59bc8@vy9g2000pbc.googlegroups.com> Message-ID: <29431928.122.1332786797588.JavaMail.geo-discussion-forums@pbcjk1> On Sunday, March 25, 2012 9:59:56 PM UTC-7, Mensanator wrote: > OK, GMPY is now called GMPY2. No big deal, I can import as GMPY. > > But why were scan0 and scan1 changed to bit_scan0 and bit_scan1? > > What's the justification for that? I use those functions extensively > in my library of Collatz utilities and I had to re-edit them for no > obvious reason. I'll speak up as the maintainer of GMPY and GMPY2. (My comments apply to the beta1 release which should be out in a couple of days.) GMPY2 introduces many changes: 1) the limited "mpf" type that is based on GMP has been replaced with the "mpfr" type from the MPFR library 2) support for multiple-precision complex arithmetic based on the MPC library 3) support for a mutable integer type optimized for in-place bit manipulations 4) support for addition number theory functions (generalized Lucas sequences and more primality tests I began to encounter name collisions; for example, should sqrt() only return integer square roots. I chose to call it a new name (gmpy2) and update the API to reflect new choices I made. For example, sqrt() now returns an "mpfr" and isqrt() returns an "mpz". As part of the documentation for the beta release, I will document the name changes. "import gmpy2 as gmpy; gmpy.scan0=gmpy.bit_scan0; etc" should work just fine. If you encounter problems with the alpha release, please open an issue on gmpy's site. Thanks, casevh On Sunday, March 25, 2012 9:59:56 PM UTC-7, Mensanator wrote: > OK, GMPY is now called GMPY2. No big deal, I can import as GMPY. > > But why were scan0 and scan1 changed to bit_scan0 and bit_scan1? > > What's the justification for that? I use those functions extensively > in my library of Collatz utilities and I had to re-edit them for no > obvious reason. On Sunday, March 25, 2012 9:59:56 PM UTC-7, Mensanator wrote: > OK, GMPY is now called GMPY2. No big deal, I can import as GMPY. > > But why were scan0 and scan1 changed to bit_scan0 and bit_scan1? > > What's the justification for that? I use those functions extensively > in my library of Collatz utilities and I had to re-edit them for no > obvious reason. On Sunday, March 25, 2012 9:59:56 PM UTC-7, Mensanator wrote: > OK, GMPY is now called GMPY2. No big deal, I can import as GMPY. > > But why were scan0 and scan1 changed to bit_scan0 and bit_scan1? > > What's the justification for that? I use those functions extensively > in my library of Collatz utilities and I had to re-edit them for no > obvious reason. From ramit.prasad at jpmorgan.com Mon Mar 26 15:12:32 2012 From: ramit.prasad at jpmorgan.com (Prasad, Ramit) Date: Mon, 26 Mar 2012 19:12:32 +0000 Subject: help needed to understand an error message. In-Reply-To: <4F706E80.7090809@sequans.com> References: <4F706E80.7090809@sequans.com> Message-ID: <5B80DD153D7D744689F57F4FB69AF4740928C084@SCACMX008.exchad.jpmchase.net> >> I feel the error is in Capital P in print . >> However the error indicated with "*^*" >> hints at quote at the end of the line. > > Anyway, the hint indicates the last quote because this is the location > where the python interpreter realizes it won't be able to execute the > code. You should not worry about that too much. Often when I see errors the problem can be earlier in the line or a line or two before. Just look backwards from where the error says the problem was found. Ramit Ramit Prasad | JPMorgan Chase Investment Bank | Currencies Technology 712 Main Street | Houston, TX 77002 work phone: 713 - 216 - 5423 -- This email is confidential and subject to important disclaimers and conditions including on offers for the purchase or sale of securities, accuracy and completeness of information, viruses, confidentiality, legal privilege, and legal entity disclaimers, available at http://www.jpmorgan.com/pages/disclosures/email. From xahlee at gmail.com Mon Mar 26 16:06:55 2012 From: xahlee at gmail.com (Xah Lee) Date: Mon, 26 Mar 2012 13:06:55 -0700 (PDT) Subject: perldoc: the key to perl Message-ID: <5a116730-161b-461e-bf0b-4bee038abb3d@z5g2000pbu.googlegroups.com> ?Perl Documentation: The Key to Perl? http://xahlee.org/perl-python/key_to_perl.html plain text follows ------------------------------------- So, i wanted to know what the option perl -C does. So, here's perldoc perlrun. Excerpt: -C [*number/list*] The -C flag controls some of the Perl Unicode features. As of 5.8.1, the -C can be followed either by a number or a list of option letters. The letters, their numeric values, and effects are as follows; listing the letters is equal to summing the numbers. I 1 STDIN is assumed to be in UTF-8 O 2 STDOUT will be in UTF-8 E 4 STDERR will be in UTF-8 S 7 I + O + E i 8 UTF-8 is the default PerlIO layer for input streams o 16 UTF-8 is the default PerlIO layer for output streams D 24 i + o A 32 the @ARGV elements are expected to be strings encoded in UTF-8 L 64 normally the "IOEioA" are unconditional, the L makes them conditional on the locale environment variables (the LC_ALL, LC_TYPE, and LANG, in the order of decreasing precedence) -- if the variables indicate UTF-8, then the selected "IOEioA" are in effect a 256 Set ${^UTF8CACHE} to -1, to run the UTF-8 caching code in debugging mode. For example, -COE and -C6 will both turn on UTF-8-ness on both STDOUT and STDERR. Repeating letters is just redundant, not cumulative nor toggling. The "io" options mean that any subsequent open() (or similar I/O operations) in the current file scope will have the ":utf8" PerlIO layer implicitly applied to them, in other words, UTF-8 is expected from any input stream, and UTF-8 is produced to any output stream. This is just the default, with explicit layers in open() and with binmode() one can manipulate streams as usual. -C on its own (not followed by any number or option list), or the empty string "" for the "PERL_UNICODE" environment variable, has the same effect as -CSDL. In other words, the standard I/ O handles and the default "open()" layer are UTF-8-fied *but* only if the locale environment variables indicate a UTF-8 locale. This behaviour follows the *implicit* (and problematic) UTF-8 behaviour of Perl 5.8.0. You can use -C0 (or "0" for "PERL_UNICODE") to explicitly disable all the above Unicode features. The read-only magic variable "${^UNICODE}" reflects the numeric value of this setting. This variable is set during Perl startup and is thereafter read-only. If you want runtime effects, use the three-arg open() (see "open" in perlfunc), the two-arg binmode() (see "binmode" in perlfunc), and the "open" pragma (see open). (In Perls earlier than 5.8.1 the -C switch was a Win32- only switch that enabled the use of Unicode-aware "wide system call" Win32 APIs. This feature was practically unused, however, and the command line switch was therefore "recycled".) Note: Since perl 5.10.1, if the -C option is used on the "#!" line, it must be specified on the command line as well, since the standard streams are already set up at this point in the execution of the perl interpreter. You can also use binmode() to set the encoding of an I/O stream. reading that is like a adventure. It's like this: The -C is a key to unlock many secrets. Just get it, and you'll be all good to go, except in cases you may need the inner key. You'll find a hinge in the key, open it, then there's a subkey. On the subkey, there's a number. Take that number to the lock, it will open with keyX. When you use keyX, it must be matched with the previous inner key with 8th bit. keyX doesn't have a ID, but you can make one by finding the number at the place you found the key C. Key C is actually optional, but when inner key and keyX's number matches, it changes the nature of the lock. This is when you need to turn on keyMode ? Xah From gelonida at gmail.com Mon Mar 26 16:26:11 2012 From: gelonida at gmail.com (Gelonida N) Date: Mon, 26 Mar 2012 22:26:11 +0200 Subject: best way to create warning for obsolete functions and call new one Message-ID: Hi, I'm working on a module, which needs rather heavy renaming of functions and methods (naming style, change of functionality, understandability, orthography) As these modules are used by quite some projects and as I do not want to force everybody to rename immediately I just want to warn users, that they call functions, that have been renamed and that will be obsoleted. function example: def get_thyme(a='high'): # old name return a + 'noon' # Should have been get_time(a, b) method example: class C(): def set_with(self, value=0): # should be set_width self.width = value What I basically want to do for each function is following: def get_time(a='high'): return a + 'noon' def get_thyme(a): # ideally the next line should display old and new function name # but even with out I 'd be fine logging.warning('obsolate function. please use the new function') return get_time(a) Assuming I want to rename loads of functions / metthods, what would be the laziest option to so? (and have no run time penalty for the new call) One option I though of would be: def obsolete_func(func): def call_old(*args, **kwargs): print "func is old psl use new one" return func(*args, **kwargs) return call_old and def get_time(a='high'): return a + 'noon' get_thyme = obsolete_func(get_time) class C(): def set_width(self, value=0): # should be set_width self.width = value set_with = obsolete_func(set_width) Another idea might be something like: add_obsolete_functions(get_tyme=get_time, get_dayt=get_date) Not sure though how to do this best for Classes Thanks for any ideas From dan at tombstonezero.net Mon Mar 26 17:24:40 2012 From: dan at tombstonezero.net (Dan Sommers) Date: Mon, 26 Mar 2012 17:24:40 -0400 Subject: best way to create warning for obsolete functions and call new one In-Reply-To: References: Message-ID: <20120326172440.4705444d@particle> On Mon, 26 Mar 2012 22:26:11 +0200 Gelonida N wrote: > As these modules are used by quite some projects and as I do not want > to force everybody to rename immediately I just want to warn users, > that they call functions, that have been renamed and that will be > obsoleted. You want a DeprecationWarning. HTH, Dan From rosuav at gmail.com Mon Mar 26 17:50:35 2012 From: rosuav at gmail.com (Chris Angelico) Date: Tue, 27 Mar 2012 08:50:35 +1100 Subject: best way to create warning for obsolete functions and call new one In-Reply-To: References: Message-ID: On Tue, Mar 27, 2012 at 7:26 AM, Gelonida N wrote: > One option I though of would be: > > def obsolete_func(func): > ? ?def call_old(*args, **kwargs): > ? ? ? ?print "func is old psl use new one" > ? ? ? ?return func(*args, **kwargs) > ? ?return call_old > > and > > def get_time(a='high'): > ? return a + 'noon' That's a reasonable idea. Incorporate Dan's suggestion of using DeprecationWarning. You may want to try decorator syntax: def was(oldname): def _(func): globals()[oldname]=func return func return _ @was("get_thyme") def get_time(a='high'): return a + 'noon' That won't raise DeprecationWarning, though. It's a very simple assignment. The was() internal function could be enhanced to do a bit more work, but I'm not sure what version of Python you're using and what introspection facilities you have. But if you're happy with the old versions coming up with (*args,**kwargs) instead of their parameter lists, it's not difficult: def was(oldname): def _(func): def bounce(*args,**kwargs): # raise DeprecationWarning return func(*args,**kwargs) globals()[oldname]=bounce return func return _ I've never actually used the Python warnings module, but any line of code you fill in at the comment will be executed any time the old name is used. In any case, it's still used with the same convenient decorator. You could even unify multiple functions under a single new name: @was("foo") @was("bar") def quux(spam,ham): return ham.eat() Hope that helps! ChrisA From tolidtm at gmail.com Mon Mar 26 17:53:54 2012 From: tolidtm at gmail.com (Anatoli Hristov) Date: Mon, 26 Mar 2012 23:53:54 +0200 Subject: Advise of programming one of my first programs Message-ID: Hi guys just wanted to share one of my first programs. Could you please tell me, do I use a right logic ? It works fine what I wanted to do, but is it writen in the right way? My next step is to make it write the changes of the dictionary on the file :) ## DB tbook = {'goodie':['Christian','Van Eckel','Bruxelles','Forest','02 344 33 33','This is a test note :)'], 'osvaldo':['Osvaldo','Rios','Liege','Centrum','023758832',''], 'ronaldo':['Diego','Aspanda','Brussels','Vorst','03 443 23 23','']} ## Edit selected nickname def edit(): sb = tbook[select] fn = raw_input('New name for ' + sb[0] + ' : ') sb[0] = fn ln = raw_input('New name for ' + sb[1] + ' : ') sb[1] = ln raw_input('\n\n\nPress to return') details() ## Details of nickname def details(): sb = tbook[select] print 'Nickname: ', select, ' is selected\n' print 'First name:\t', sb[0], '\n' print 'Last name:\t', sb[1], '\n' print 'Country:\t', sb[2], '\n' print 'City:\t\t', sb[3], '\n' print 'Phone number:\t',sb[4], '\n' print 'Memos:\n' print sb[5] print '\n\n(E)dit\n\n' print '(B)ack to phonebook list\n\n' menu = raw_input('What you wana do? ') if menu == 'e': edit() if menu == 'b': listpb() ## Select nickname def selectm(): global select select = raw_input('Type nickname and press : ') if select == '': listpb() if select in tbook: details() else: listpb() ## List all contacts def listpb(): print '_' *45, ' Phonebook ', '_' *45,'\n\n\n' print 'Nick\t\tF.Name\t\tL.Name\t\tCity\t\t\tRegion\t\tTel' print '_' * 105,'\n','\t' * 13 for val in tbook.keys(): print val, '\t\t', tbook[val][0], '\t', tbook[val][1], '\t', tbook[val][2], '\t\t', tbook[val][3], '\t\t', tbook[val][4],'\t\t\n' print '_'*105,'\n\n' selectm() ## Call list names listpb() Thanks a lot Anatoli -------------- next part -------------- An HTML attachment was scrubbed... URL: From ramit.prasad at jpmorgan.com Mon Mar 26 18:40:49 2012 From: ramit.prasad at jpmorgan.com (Prasad, Ramit) Date: Mon, 26 Mar 2012 22:40:49 +0000 Subject: Advise of programming one of my first programs In-Reply-To: References: Message-ID: <5B80DD153D7D744689F57F4FB69AF4740928C365@SCACMX008.exchad.jpmchase.net> > Hi guys just wanted to share one of my first programs. Could you please > tell me, do I use a right logic ? > It works fine what I wanted to do, but is it writen in the right way? My > next step is to make it write the changes of the dictionary on the file :) > When you do get that far, you should look at the pickle library. It is amazing how easy it is to store data with Python. > > ## DB > tbook = {'goodie':['Christian','Van Eckel','Bruxelles','Forest','02 344 33 > 33','This is a test note :)'], > 'osvaldo':['Osvaldo','Rios','Liege','Centrum','023758832',''], > 'ronaldo':['Diego','Aspanda','Brussels','Vorst','03 443 23 > 23','']} > > ## Edit selected nickname > def edit(): > sb = tbook[select] > fn = raw_input('New name for ' + sb[0] + ' : ') > sb[0] = fn > ln = raw_input('New name for ' + sb[1] + ' : ') > sb[1] = ln > raw_input('\n\n\nPress to return') > details() > > > ## Details of nickname > def details(): > sb = tbook[select] > print 'Nickname: ', select, ' is selected\n' > print 'First name:\t', sb[0], '\n' > print 'Last name:\t', sb[1], '\n' > print 'Country:\t', sb[2], '\n' > print 'City:\t\t', sb[3], '\n' > print 'Phone number:\t',sb[4], '\n' > print 'Memos:\n' > print sb[5] > > print '\n\n(E)dit\n\n' > print '(B)ack to phonebook list\n\n' > menu = raw_input('What you wana do? ') > if menu == 'e': > edit() > if menu == 'b': > listpb() > Minor nitpick, but what if the user types 'B' or 'E' like in your printed menu? > > ## Select nickname > def selectm(): > global select > select = raw_input('Type nickname and press : ') > if select == '': > listpb() > if select in tbook: > details() > else: > listpb() Remove all global variables when your program starts to work. Instead pass them as arguments and return them from functions. So do 'details( select )' instead of 'details()' and then in details, you would do edit( select ). > > ## List all contacts > def listpb(): > print '_' *45, ' Phonebook ', '_' *45,'\n\n\n' > > print 'Nick\t\tF.Name\t\tL.Name\t\tCity\t\t\tRegion\t\tTel' > print '_' * 105,'\n','\t' * 13 > for val in tbook.keys(): > print val, '\t\t', tbook[val][0], '\t', tbook[val][1], '\t', > tbook[val][2], '\t\t', tbook[val][3], '\t\t', tbook[val][4],'\t\t\n' > print '_'*105,'\n\n' > selectm() > > ## Call list names > listpb() if __name__ == "__main__": listpb() This way you can import the module and not run it on import; it is useful when you start wanting to reuse functions from a different project. It is better than copy-pasting functions everywhere because when you improve the function all the programs will pick it up. Otherwise you will have to go back to each pasted function and pick it up. A few items I would work to improve: 1. Remove global variables (already mentioned above) 2. You should separate any menu / navigation from your application code. details() should only print the details and not take the next menu choice. You probably want 2 separate menu functions. One that returns a 'select'-ed book and one that returns next choice. This will also help you when you implement my next point. 3. You should also change the structure of your program to loop instead of calling listpb each time you want to restart. It is a much better practice and while it will not affect this program unless you do not exit for 10s or 100s of thousands of details but if you write something that *does* navigate that many times it can crash. Looping is probably your next programming lesson anyway :) 4. This is more of a side note but instead of using \t\t all the time, you would be better off learning to use the string formatting operations. It is a little more effort to learn, but tends to be a lot more reliable on different systems (and with different data trying to be printed) than manually trying to align everything. http://docs.python.org/library/string.html#format-string-syntax Keep on working, you have made a good start and now it is time to refactor (programming equivalent of rewriting an essay) and make everything better! Ramit Ramit Prasad | JPMorgan Chase Investment Bank | Currencies Technology 712 Main Street | Houston, TX 77002 work phone: 713 - 216 - 5423 -- This email is confidential and subject to important disclaimers and conditions including on offers for the purchase or sale of securities, accuracy and completeness of information, viruses, confidentiality, legal privilege, and legal entity disclaimers, available at http://www.jpmorgan.com/pages/disclosures/email. From ramit.prasad at jpmorgan.com Mon Mar 26 18:42:40 2012 From: ramit.prasad at jpmorgan.com (Prasad, Ramit) Date: Mon, 26 Mar 2012 22:42:40 +0000 Subject: perldoc: the key to perl In-Reply-To: <5a116730-161b-461e-bf0b-4bee038abb3d@z5g2000pbu.googlegroups.com> References: <5a116730-161b-461e-bf0b-4bee038abb3d@z5g2000pbu.googlegroups.com> Message-ID: <5B80DD153D7D744689F57F4FB69AF4740928C377@SCACMX008.exchad.jpmchase.net> > > ?Perl Documentation: The Key to Perl? > http://xahlee.org/perl-python/key_to_perl.html > > plain text follows > ------------------------------------- > > So, i wanted to know what the option perl -C does. So, here's perldoc > perlrun. Excerpt: [snip] Maybe I missed something, but what does this have to do with Python? Ramit Ramit Prasad | JPMorgan Chase Investment Bank | Currencies Technology 712 Main Street | Houston, TX 77002 work phone: 713 - 216 - 5423 -- This email is confidential and subject to important disclaimers and conditions including on offers for the purchase or sale of securities, accuracy and completeness of information, viruses, confidentiality, legal privilege, and legal entity disclaimers, available at http://www.jpmorgan.com/pages/disclosures/email. From abhishek.vit at gmail.com Mon Mar 26 18:56:29 2012 From: abhishek.vit at gmail.com (Abhishek Pratap) Date: Mon, 26 Mar 2012 15:56:29 -0700 Subject: concurrent file reading/writing using python Message-ID: Hi Guys I am fwding this question from the python tutor list in the hope of reaching more people experienced in concurrent disk access in python. I am trying to see if there are ways in which I can read a big file concurrently on a multi core server and process data and write the output to a single file as the data is processed. For example if I have a 50Gb file, I would like to read it in parallel with 10 process/thread, each working on a 10Gb data and perform the same data parallel computation on each chunk of fine collating the output to a single file. I will appreciate your feedback. I did find some threads about this on stackoverflow but it was not clear to me what would be a good way to go about implementing this. Thanks! -Abhi ---------- Forwarded message ---------- From: Steven D'Aprano Date: Mon, Mar 26, 2012 at 3:21 PM Subject: Re: [Tutor] concurrent file reading using python To: tutor at python.org Abhishek Pratap wrote: > > Hi Guys > > > I want to utilize the power of cores on my server and read big files > (> 50Gb) simultaneously by seeking to N locations. Yes, you have many cores on the server. But how many hard drives is each file on? If all the files are on one disk, then you will *kill* performance dead by forcing the drive to seek backwards and forwards: seek to 12345678 read a block seek to 9947500 read a block seek to 5891124 read a block seek back to 12345678 + 1 block read another block seek back to 9947500 + 1 block read another block ... The drive will spend most of its time seeking instead of reading. Even if you have multiple hard drives in a RAID array, performance will depend strongly the details of how it is configured (RAID1, RAID0, software RAID, hardware RAID, etc.) and how smart the controller is. Chances are, though, that the controller won't be smart enough. Particularly if you have hardware RAID, which in my experience tends to be more expensive and less useful than software RAID (at least for Linux). And what are you planning on doing with the files once you have read them? I don't know how much memory your server has got, but I'd be very surprised if you can fit the entire > 50 GB file in RAM at once. So you're going to read the files and merge the output... by writing them to the disk. Now you have the drive trying to read *and* write simultaneously. TL; DR: Tasks which are limited by disk IO are not made faster by using a faster CPU, since the bottleneck is disk access, not CPU speed. Back in the Ancient Days when tape was the only storage medium, there were a lot of programs optimised for slow IO. Unfortunately this is pretty much a lost art -- although disk access is thousands or tens of thousands of times slower than memory access, it is so much faster than tape that people don't seem to care much about optimising disk access. > What I want to know is the best way to read a file concurrently. I > have read about file-handle.seek(), ?os.lseek() but not sure if thats > the way to go. Any used cases would be of help. Optimising concurrent disk access is a specialist field. You may be better off asking for help on the main Python list, comp.lang.python or python-list at python.org, and hope somebody has some experience with this. But chances are very high that you will need to search the web for forums dedicated to concurrent disk access, and translate from whatever language(s) they are using to Python. -- Steven _______________________________________________ Tutor maillist ?- ?Tutor at python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor From ralf at systemexit.de Mon Mar 26 19:18:36 2012 From: ralf at systemexit.de (Ralf Schmitt) Date: Tue, 27 Mar 2012 01:18:36 +0200 Subject: [ANNOUNCE] pypiserver 0.5.2 - minimal pypi server Message-ID: <87aa336jeb.fsf@myhost.localnet> Hi, I've just uploaded pypiserver 0.5.2 to the python package index. pypiserver is a minimal PyPI compatible server. It can be used to serve a set of packages and eggs to easy_install or pip. pypiserver is easy to install (i.e. just easy_install pypiserver). It doesn't have any external dependencies. http://pypi.python.org/pypi/pypiserver/ should contain enough information to easily get you started running your own PyPI server in a few minutes. The code is available on github: https://github.com/schmir/pypiserver Changes in version 0.5.2 ------------------------- - provide a way to get the WSGI app - improved package name and version guessing - use case insensitive matching when removing archive suffixes - fix pytz issue #6 -- Cheers, Ralf From sln at netherlands.com Mon Mar 26 20:02:19 2012 From: sln at netherlands.com (sln at netherlands.com) Date: Mon, 26 Mar 2012 17:02:19 -0700 Subject: Your Regex Brain References: Message-ID: On Sat, 24 Mar 2012 16:30:28 -0700 (PDT), Xah Lee wrote: >?Your Regex Brain? >http://xahlee.org/comp/your_regex_brain.html > That's more like a brain cell. This is more like a regex brain. ' "\']|"[^"]*"|\'[^\']*\')*? (?<=\s) width \s*= (?: (?> \s* ([\'"]) \s* (?.*?) \s* \g{-2} ) | (?> (?!\s*[\'"]) \s* (?[^\s>]*) (?=\s|>) ) ) ) (?= (?:[^>"\']|"[^"]*"|\'[^\']*\')*? (?<=\s) src \s*= (?: (?> \s* ([\'"]) \s* (?.*?) \s* \g{-2} ) | (?> (?!\s*[\'"]) \s* (?[^\s>]*) (?=\s|>) ) ) ) (?= (?:[^>"\']|"[^"]*"|\'[^\']*\')*? (?<=\s) height \s*= (?: (?> \s* ([\'"]) \s* (?.*?) \s* \g{-2} ) | (?> (?!\s*[\'"]) \s* (?[^\s>]*) (?=\s|>) ) ) ) (?= (?:[^>"\']|"[^"]*"|\'[^\']*\')*? (?<=\s) alt \s*= (?: (?> \s* ([\'"]) \s* (?.*?) \s* \g{-2} ) | (?> (?!\s*[\'"]) \s* (?[^\s>]*) (?=\s|>) ) ) ) (?> \s+ (?:".*?"|\'.*?\'|[^>]*?)+ > ) (?) ' -sln From jason at powerpull.net Mon Mar 26 20:57:51 2012 From: jason at powerpull.net (Jason Friedman) Date: Tue, 27 Mar 2012 00:57:51 +0000 Subject: argparse ConfigureAction problem In-Reply-To: References: Message-ID: > ./plot_stuff2.py --plot stuff1 stuff2 > [...] > plot_stuff2.py: error: argument --plot/--with-plot/--enable-plot/--no-plot/-- > without-plot/--disable-plot: invalid boolean value: 'stuff1' > > Problem is --plot takes an optional argument, and so the positional arg is > assumed to be the arg to --plot. ?Not sure how to fix this. Maybe have a look at nargs='*' in http://docs.python.org/py3k/library/argparse.html#nargs. From showell30 at yahoo.com Mon Mar 26 21:44:30 2012 From: showell30 at yahoo.com (Steve Howell) Date: Mon, 26 Mar 2012 18:44:30 -0700 (PDT) Subject: concurrent file reading/writing using python References: Message-ID: <67283b47-9d44-403e-a3df-73ade83a2c0e@z3g2000pbn.googlegroups.com> On Mar 26, 3:56?pm, Abhishek Pratap wrote: > Hi Guys > > I am fwding this question from the python tutor list in the hope of > reaching more people experienced in concurrent disk access in python. > > I am trying to see if there are ways in which I can read a big file > concurrently on a multi core server and process data and write the > output to a single file as the data is processed. > > For example if I have a 50Gb file, I would like to read it in parallel > with 10 process/thread, each working on a 10Gb data and perform the > same data parallel computation on each chunk of fine collating the > output to a single file. > > I will appreciate your feedback. I did find some threads about this on > stackoverflow but it was not clear to me what would be a good ?way to > go about implementing this. > Have you written a single-core solution to your problem? If so, can you post the code here? If CPU isn't your primary bottleneck, then you need to be careful not to overly complicate your solution by getting multiple cores involved. All the coordination might make your program slower and more buggy. If CPU is the primary bottleneck, then you might want to consider an approach where you only have a single thread that's reading records from the file, 10 at a time, and then dispatching out the calculations to different threads, then writing results back to disk. My approach would be something like this: 1) Take a small sample of your dataset so that you can process it within 10 seconds or so using a simple, single-core program. 2) Figure out whether you're CPU bound. A simple way to do this is to comment out the actual computation or replace it with a trivial stub. If you're CPU bound, the program will run much faster. If you're IO-bound, the program won't run much faster (since all the work is actually just reading from disk). 3) Figure out how to read 10 records at a time and farm out the records to threads. Hopefully, your program will take significantly less time. At this point, don't obsess over collating data. It might not be 10 times as fast, but it should be somewhat faster to be worth your while. 4) If the threaded approach shows promise, make sure that you can still generate correct output with that approach (in other words, figure out out synchronization and collating). At the end of that experiment, you should have a better feel on where to go next. What is the nature of your computation? Maybe it would be easier to tune the algorithm then figure out the multi-core optimization. From kmisoft at gmail.com Mon Mar 26 21:51:13 2012 From: kmisoft at gmail.com (Vladimir Ignatov) Date: Mon, 26 Mar 2012 21:51:13 -0400 Subject: Tools for refactoring/obfuscation In-Reply-To: References: Message-ID: Hi, (sorry for replying to the old topic) On Tue, Mar 6, 2012 at 10:29 PM, Javier wrote: > I am looking for an automated tool for refactoring/obfuscation. > Something that changes names of functions, variables, or which would > merge all the functions of various modules in a single module. > The closest I have seen is http://bicyclerepair.sourceforge.net/ > > Does somebody know of something that can work from the command line or > simple data structures/text files?, like a python dictionary of functions > {"old":"new",...} I am not surprised what nobody answers. I think that such tool is nearly impossible given the dynamic Python's nature. But if you put little discipline/restrictions in your source code, when doing obfuscation could be much more easier. Almost trivial I would say. Javier, you can contact me directly if you are interested in this topic. Vladimir Ignatov kmisoft at gmail com From demianbrecht at gmail.com Mon Mar 26 22:42:38 2012 From: demianbrecht at gmail.com (Demian Brecht) Date: Mon, 26 Mar 2012 19:42:38 -0700 (PDT) Subject: OAuth 2.0 implementation Message-ID: <1973354.3.1332816158529.JavaMail.geo-discussion-forums@pbae2> Hi all, I'm getting close to an alpha release of an OAuth 2.0 implementation (https://github.com/demianbrecht/py-sanction). High level features include: * Support for multiple providers (protocol deviations). This didn't seem to be supported by any library. * Actually an OAuth 2.0 implementation (python-oauth2 is a 2nd version of python-oauth, not an OAuth 2.0 implementation) * Support for the entire OAuth 2.0 spec. Most provide support for the authorization code grant flow (employed by all web server providers), but lacked support or extensibility for any other flows, credentials or other provider extensions) * 100% unit test coverage. Some employ TDD, others didn't. Current implementation includes support for Authorization Code Grant flow but can be extended to support others (including extensions) quite trivially. Current adapter implementations include: * Google * Facebook * Stack Exchange * Deviant Art * Foursquare It has yet to be heavily used or functionally tested (basic tests have been done in example/server.py) and documentation is being worked on. Just wanted to share some of my work and hopefully someone other than me can find some use for it :) P.S. For those interested, cloc stats are: http://cloc.sourceforge.net v 1.53 T=0.5 s (28.0 files/s, 1818.0 lines/s) ------------------------------------------------------------------------------- Language files blank comment code ------------------------------------------------------------------------------- Python 14 239 196 474 ------------------------------------------------------------------------------- SUM: 14 239 196 474 ------------------------------------------------------------------------------- From ben+python at benfinney.id.au Mon Mar 26 23:11:54 2012 From: ben+python at benfinney.id.au (Ben Finney) Date: Tue, 27 Mar 2012 14:11:54 +1100 Subject: OAuth 2.0 implementation References: <1973354.3.1332816158529.JavaMail.geo-discussion-forums@pbae2> Message-ID: <87haxahh51.fsf@benfinney.id.au> Demian Brecht writes: > I'm getting close to an alpha release of an OAuth 2.0 implementation > (https://github.com/demianbrecht/py-sanction). Thank you for doing this work. As someone who uses OpenID, what can I read about why OAuth is better? Everything I read is targeted toward either people *implementing* OAuth, or people who use ?social networking?. Nothing much for people who want to control their own identity provider (in OpenID terms). Is OAuth not possible without relying on ?social networking? centralised services? Can we use OAuth services without some Google or Facebook or other gatekeeper imposing itself in the transaction? -- \ ?Never use a long word when there's a commensurate diminutive | `\ available.? ?Stan Kelly-Bootle | _o__) | Ben Finney From roy at panix.com Mon Mar 26 23:30:18 2012 From: roy at panix.com (Roy Smith) Date: Mon, 26 Mar 2012 23:30:18 -0400 Subject: OAuth 2.0 implementation References: <1973354.3.1332816158529.JavaMail.geo-discussion-forums@pbae2> <87haxahh51.fsf@benfinney.id.au> Message-ID: In article <87haxahh51.fsf at benfinney.id.au>, Ben Finney wrote: > Demian Brecht writes: > > > I'm getting close to an alpha release of an OAuth 2.0 implementation > > (https://github.com/demianbrecht/py-sanction). > > Thank you for doing this work. > > As someone who uses OpenID, what can I read about why OAuth is better? OpenID is for people who worry about things like how OpenID is different from OAuth. Oauth is for people who have no idea what OAuth is and just want to be able to log into web sites using their Facebook account. From steve+comp.lang.python at pearwood.info Mon Mar 26 23:43:46 2012 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 27 Mar 2012 03:43:46 GMT Subject: Is there any difference between print 3 and print '3' in Python ? References: <5128580.32.1332762326119.JavaMail.geo-discussion-forums@pbom7> Message-ID: <4f713772$0$29965$c3e8da3$5496439d@news.astraweb.com> On Mon, 26 Mar 2012 08:11:03 -0400, Dave Angel wrote: > On 03/26/2012 07:45 AM, redstone-cold at 163.com wrote: >> I know the print statement produces the same result when both of these >> two instructions are executed ,I just want to know Is there any >> difference between print 3 and print '3' in Python ? > > This is a non-question. The input is the same, the output is the same, > what else matters? def fib1(n): if n == 0: return 0 elif n == 1: return 1 f2, f1 = 0, 1 for _ in range(2, n+1): f2, f1 = f1, f2 + f1 return f1 def fib2(n): if n == 0: return 0 elif n == 1: return 1 else: return fib2(n-1) + fib2(n-2) Try calling fib1(35) and fib2(35). Still think only the input and output matter? :) For the record, fib2(35) ends up making a total of 29860703 function calls, compared to 35 iterations for fib1. -- Steven From ben+python at benfinney.id.au Mon Mar 26 23:49:54 2012 From: ben+python at benfinney.id.au (Ben Finney) Date: Tue, 27 Mar 2012 14:49:54 +1100 Subject: OAuth 2.0 implementation References: <1973354.3.1332816158529.JavaMail.geo-discussion-forums@pbae2> <87haxahh51.fsf@benfinney.id.au> Message-ID: <878vimhfdp.fsf@benfinney.id.au> Roy Smith writes: > In article <87haxahh51.fsf at benfinney.id.au>, > Ben Finney wrote: > > As someone who uses OpenID, what can I read about why OAuth is better? > > OpenID is for people who worry about things like how OpenID is different > from OAuth. Oauth is for people who have no idea what OAuth is and just > want to be able to log into web sites using their Facebook account. So, if I want to be free to choose an identity provider I trust, and it's not Facebook or Google or Twitter or other privacy-hostile services, how does OAuth help me do that? What can I read for how to become an OAuth user that doesn't assume I want a ?social networking? provider involved in my identity transactions? -- \ ?It is difficult to get a man to understand something when his | `\ salary depends upon his not understanding it.? ?Upton Sinclair, | _o__) 1935 | Ben Finney From roy at panix.com Mon Mar 26 23:57:13 2012 From: roy at panix.com (Roy Smith) Date: Mon, 26 Mar 2012 23:57:13 -0400 Subject: OAuth 2.0 implementation References: <1973354.3.1332816158529.JavaMail.geo-discussion-forums@pbae2> <87haxahh51.fsf@benfinney.id.au> <878vimhfdp.fsf@benfinney.id.au> Message-ID: In article <878vimhfdp.fsf at benfinney.id.au>, Ben Finney wrote: > Roy Smith writes: > > > In article <87haxahh51.fsf at benfinney.id.au>, > > Ben Finney wrote: > > > As someone who uses OpenID, what can I read about why OAuth is better? > > > > OpenID is for people who worry about things like how OpenID is different > > from OAuth. Oauth is for people who have no idea what OAuth is and just > > want to be able to log into web sites using their Facebook account. > > So, if I want to be free to choose an identity provider I trust, and > it's not Facebook or Google or Twitter or other privacy-hostile > services, how does OAuth help me do that? It doesn't. Well, in theory, it could, but in practice everybody's OAuth implementation is different enough that they don't interoperate. From ben+python at benfinney.id.au Tue Mar 27 00:24:35 2012 From: ben+python at benfinney.id.au (Ben Finney) Date: Tue, 27 Mar 2012 15:24:35 +1100 Subject: OAuth 2.0 implementation References: <1973354.3.1332816158529.JavaMail.geo-discussion-forums@pbae2> <87haxahh51.fsf@benfinney.id.au> <878vimhfdp.fsf@benfinney.id.au> Message-ID: <87zkb2fz7g.fsf@benfinney.id.au> Roy Smith writes: > In article <878vimhfdp.fsf at benfinney.id.au>, > Ben Finney wrote: > > So, if I want to be free to choose an identity provider I trust, and > > it's not Facebook or Google or Twitter or other privacy-hostile > > services, how does OAuth help me do that? > > It doesn't. Well, in theory, it could, but in practice everybody's > OAuth implementation is different enough that they don't interoperate. Thanks. So OAuth is a pseudo-standard that is implemented incompatibly to the extent that it doesn't actually give users the freedom to migrate their existing data and identity at will to any other OAuth implementor? -- \ ?Money is always to be found when men are to be sent to the | `\ frontiers to be destroyed: when the object is to preserve them, | _o__) it is no longer so.? ?Voltaire, _Dictionnaire Philosophique_ | Ben Finney From rustompmody at gmail.com Tue Mar 27 01:00:48 2012 From: rustompmody at gmail.com (rusi) Date: Mon, 26 Mar 2012 22:00:48 -0700 (PDT) Subject: Is there any difference between print 3 and print '3' in Python ? References: <5128580.32.1332762326119.JavaMail.geo-discussion-forums@pbom7> <4f713772$0$29965$c3e8da3$5496439d@news.astraweb.com> Message-ID: <0e7412b9-8443-49d9-b9d9-5dd3f08d2054@to5g2000pbc.googlegroups.com> On Mar 27, 8:43?am, Steven D'Aprano wrote: > On Mon, 26 Mar 2012 08:11:03 -0400, Dave Angel wrote: > > On 03/26/2012 07:45 AM, redstone-c... at 163.com wrote: > >> I know the print statement produces the same result when both of these > >> two instructions are executed ,I just want to know Is there any > >> difference between print 3 and print '3' in Python ? > > > This is a non-question. ?The input is the same, the output is the same, > > what else matters? > > def fib1(n): > ? ? if n == 0: return 0 > ? ? elif n == 1: return 1 > ? ? f2, f1 = 0, 1 > ? ? for _ in range(2, n+1): > ? ? ? ? f2, f1 = f1, f2 + f1 > ? ? return f1 > > def fib2(n): > ? ? if n == 0: return 0 > ? ? elif n == 1: return 1 > ? ? else: return fib2(n-1) + fib2(n-2) > > Try calling fib1(35) and fib2(35). Still think only the input and output > matter? :) > > For the record, fib2(35) ends up making a total of 29860703 function > calls, compared to 35 iterations for fib1. > > -- > Steven http://www.cse.buffalo.edu/~rapaport/intensional.html From jackdied at gmail.com Tue Mar 27 01:24:16 2012 From: jackdied at gmail.com (Jack Diederich) Date: Tue, 27 Mar 2012 01:24:16 -0400 Subject: OAuth 2.0 implementation In-Reply-To: <87zkb2fz7g.fsf@benfinney.id.au> References: <1973354.3.1332816158529.JavaMail.geo-discussion-forums@pbae2> <87haxahh51.fsf@benfinney.id.au> <878vimhfdp.fsf@benfinney.id.au> <87zkb2fz7g.fsf@benfinney.id.au> Message-ID: On Tue, Mar 27, 2012 at 12:24 AM, Ben Finney wrote: > Roy Smith writes: > >> In article <878vimhfdp.fsf at benfinney.id.au>, >> ?Ben Finney wrote: >> > So, if I want to be free to choose an identity provider I trust, and >> > it's not Facebook or Google or Twitter or other privacy-hostile >> > services, how does OAuth help me do that? >> >> It doesn't. ?Well, in theory, it could, but in practice everybody's >> OAuth implementation is different enough that they don't interoperate. > > Thanks. So OAuth is a pseudo-standard that is implemented incompatibly > to the extent that it doesn't actually give users the freedom to migrate > their existing data and identity at will to any other OAuth implementor? Pretty much. It is nice that it is published as a standard at all but the standard is just whatever people are actually doing. It seems less hostile when you think of it as vigorous documentation instead of protocols set in stone. -Jack From demianbrecht at gmail.com Tue Mar 27 01:30:32 2012 From: demianbrecht at gmail.com (Demian Brecht) Date: Mon, 26 Mar 2012 22:30:32 -0700 (PDT) Subject: OAuth 2.0 implementation In-Reply-To: <87zkb2fz7g.fsf@benfinney.id.au> References: <1973354.3.1332816158529.JavaMail.geo-discussion-forums@pbae2> <87haxahh51.fsf@benfinney.id.au> <878vimhfdp.fsf@benfinney.id.au> <87zkb2fz7g.fsf@benfinney.id.au> Message-ID: <7909491.0.1332826232743.JavaMail.geo-discussion-forums@pbim5> On Monday, 26 March 2012 21:24:35 UTC-7, Ben Finney wrote: > Roy Smith writes: > > > In article <878vimhfdp.fsf at benfinney.id.au>, > > Ben Finney wrote: > > > So, if I want to be free to choose an identity provider I trust, and > > > it's not Facebook or Google or Twitter or other privacy-hostile > > > services, how does OAuth help me do that? > > > > It doesn't. Well, in theory, it could, but in practice everybody's > > OAuth implementation is different enough that they don't interoperate. > > Thanks. So OAuth is a pseudo-standard that is implemented incompatibly > to the extent that it doesn't actually give users the freedom to migrate > their existing data and identity at will to any other OAuth implementor? > > -- > \ ?Money is always to be found when men are to be sent to the | > `\ frontiers to be destroyed: when the object is to preserve them, | > _o__) it is no longer so.? ?Voltaire, _Dictionnaire Philosophique_ | > Ben Finney OAuth 2.0 is the emerging standard (now passed on to IETF) to deal with providing access to protected resources. OpenID is a standard used to deal with authentication. While there is some overlap (OAuth can be used for authentication as well), the goals of the two protocols are different. OAuth 2.0 is still in draft status (draft 25 is the current one I believe) and yes, unfortunately every single server available at this point have varying degrees of separation from the actual spec. It's not a pseudo-standard, it's just not observed to the letter. Google is the closest and Facebook seems to be the farthest away (Stack Exchange is in close second due to building theirs to work like Facebook's). That was pretty much how this work was born. I wanted to be able to implement authentication and resource access over multiple providers with a single code base. So, in answer to your questions: 1) If you're only looking for a solution to authentication, OAuth is no better than OpenID. Having said that, with the apparent popularity of OAuth 2.0, more providers may support OAuth than will OpenID (however, that's just my assumption). 2) OAuth is all about centralized services in that it is how providers allow access to protected resources. Whether it's a social network or SaaS (such as Harvest: http://www.getharvest.com/), if there isn't exposure to protected resources, then OAuth becomes pointless. 3) If you're looking to implement OAuth authentication with a provider that you trust, grab the sanction source, implement said provider and send a pull request ;) 4) Data migration doesn't happen with OAuth. As the intent is to allow access to protected resources, migrating Google to say, Facebook just wouldn't happen :) Hope that makes sense and answers your questions. - Demian From mensanator at aol.com Tue Mar 27 01:39:05 2012 From: mensanator at aol.com (Mensanator) Date: Mon, 26 Mar 2012 22:39:05 -0700 (PDT) Subject: why did GMPY change the names of its functions? References: <39ff04b9-84a0-401c-a0a5-75e33cf59bc8@vy9g2000pbc.googlegroups.com> <29431928.122.1332786797588.JavaMail.geo-discussion-forums@pbcjk1> Message-ID: On Mar 26, 1:33?pm, cas... at gmail.com wrote: > On Sunday, March 25, 2012 9:59:56 PM UTC-7, Mensanator wrote: > > OK, GMPY is now called GMPY2. No big deal, I can import as GMPY. > > > But why were scan0 and scan1 changed to bit_scan0 and bit_scan1? > > > What's the justification for that? I use those functions extensively > > in my library of Collatz utilities ?and I had to re-edit them for no > > obvious reason. > > I'll speak up as the maintainer of GMPY and GMPY2. > > (My comments apply to the beta1 release which should be out in a couple of days.) > > GMPY2 introduces many changes: > > 1) the limited "mpf" type that is based on GMP has been replaced with the "mpfr" type from the MPFR library > 2) support for multiple-precision complex arithmetic based on the MPC library > 3) support for a mutable integer type optimized for in-place bit manipulations > 4) support for addition number theory functions (generalized Lucas sequences and more primality tests > > I began to encounter name collisions; for example, should sqrt() only return integer square roots. I chose to call it a new name (gmpy2) and update the API to reflect new choices I made. For example, sqrt() now returns an "mpfr" and isqrt() returns an "mpz". > > As part of the documentation for the beta release, I will document the name changes. "import gmpy2 as gmpy; gmpy.scan0=gmpy.bit_scan0; etc" should work just fine. > > If you encounter problems with the alpha release, please open an issue on gmpy's site. > > Thanks, > casevh Thanks for the explanation. Sorry if I flew off the handle, but I've been sick recently and am trying to get back into Python after 2 years. I just bought a new laptop, downloaded Python 3.2 & GMPY2 only to see my Collatz library crash. At first, given my current condition, I was afraid I'd never get it to work again. But luckily, the fix is simple. I, for one, really appreciate your maintaining GMPY, otherwise, I might have to abandon Python. I'll keep my eyes open for any further problems. Thanks Gain. > > > > On Sunday, March 25, 2012 9:59:56 PM UTC-7, Mensanator wrote: > > OK, GMPY is now called GMPY2. No big deal, I can import as GMPY. > > > But why were scan0 and scan1 changed to bit_scan0 and bit_scan1? > > > What's the justification for that? I use those functions extensively > > in my library of Collatz utilities ?and I had to re-edit them for no > > obvious reason. > On Sunday, March 25, 2012 9:59:56 PM UTC-7, Mensanator wrote: > > OK, GMPY is now called GMPY2. No big deal, I can import as GMPY. > > > But why were scan0 and scan1 changed to bit_scan0 and bit_scan1? > > > What's the justification for that? I use those functions extensively > > in my library of Collatz utilities ?and I had to re-edit them for no > > obvious reason. > On Sunday, March 25, 2012 9:59:56 PM UTC-7, Mensanator wrote: > > OK, GMPY is now called GMPY2. No big deal, I can import as GMPY. > > > But why were scan0 and scan1 changed to bit_scan0 and bit_scan1? > > > What's the justification for that? I use those functions extensively > > in my library of Collatz utilities ?and I had to re-edit them for no > > obvious reason. From abhishek.vit at gmail.com Tue Mar 27 02:08:08 2012 From: abhishek.vit at gmail.com (Abhishek Pratap) Date: Mon, 26 Mar 2012 23:08:08 -0700 Subject: concurrent file reading/writing using python In-Reply-To: <67283b47-9d44-403e-a3df-73ade83a2c0e@z3g2000pbn.googlegroups.com> References: <67283b47-9d44-403e-a3df-73ade83a2c0e@z3g2000pbn.googlegroups.com> Message-ID: Thanks for the advice Dennis. @Steve : I haven't actually written the code. I was thinking more on the generic side and wanted to check if what I thought made sense and I now realize it can depend on then the I/O. For starters I was just thinking about counting lines in a line without doing any computation so this can be strictly I/O bound. I guess what I need to ask was can we improve on the existing disk I/O performance by reading different portions of the file using threads or processes. I am kind of pointing towards a MapReduce task on a file in a shared file system such as GPFS(from IBM). I realize this can be more suited to HDFS but wanted to know if people have implemented something similar on a normal linux based NFS -Abhi On Mon, Mar 26, 2012 at 6:44 PM, Steve Howell wrote: > On Mar 26, 3:56?pm, Abhishek Pratap wrote: >> Hi Guys >> >> I am fwding this question from the python tutor list in the hope of >> reaching more people experienced in concurrent disk access in python. >> >> I am trying to see if there are ways in which I can read a big file >> concurrently on a multi core server and process data and write the >> output to a single file as the data is processed. >> >> For example if I have a 50Gb file, I would like to read it in parallel >> with 10 process/thread, each working on a 10Gb data and perform the >> same data parallel computation on each chunk of fine collating the >> output to a single file. >> >> I will appreciate your feedback. I did find some threads about this on >> stackoverflow but it was not clear to me what would be a good ?way to >> go about implementing this. >> > > Have you written a single-core solution to your problem? ?If so, can > you post the code here? > > If CPU isn't your primary bottleneck, then you need to be careful not > to overly complicate your solution by getting multiple cores > involved. ?All the coordination might make your program slower and > more buggy. > > If CPU is the primary bottleneck, then you might want to consider an > approach where you only have a single thread that's reading records > from the file, 10 at a time, and then dispatching out the calculations > to different threads, then writing results back to disk. > > My approach would be something like this: > > ?1) Take a small sample of your dataset so that you can process it > within 10 seconds or so using a simple, single-core program. > ?2) Figure out whether you're CPU bound. ?A simple way to do this is > to comment out the actual computation or replace it with a trivial > stub. ?If you're CPU bound, the program will run much faster. ?If > you're IO-bound, the program won't run much faster (since all the work > is actually just reading from disk). > ?3) Figure out how to read 10 records at a time and farm out the > records to threads. ?Hopefully, your program will take significantly > less time. ?At this point, don't obsess over collating data. ?It might > not be 10 times as fast, but it should be somewhat faster to be worth > your while. > ?4) If the threaded approach shows promise, make sure that you can > still generate correct output with that approach (in other words, > figure out out synchronization and collating). > > At the end of that experiment, you should have a better feel on where > to go next. > > What is the nature of your computation? ?Maybe it would be easier to > tune the algorithm then figure out the multi-core optimization. > > > > > -- > http://mail.python.org/mailman/listinfo/python-list From r32813 at freescale.com Tue Mar 27 05:41:35 2012 From: r32813 at freescale.com (Wong Wah Meng-R32813) Date: Tue, 27 Mar 2012 09:41:35 +0000 Subject: Socket Error : Address still in use (Conveting from python 1.5.2 to 2.7.1) In-Reply-To: <87haxahh51.fsf@benfinney.id.au> References: <1973354.3.1332816158529.JavaMail.geo-discussion-forums@pbae2> <87haxahh51.fsf@benfinney.id.au> Message-ID: <78E1273CA6E76A43BB8830A194FF709B08E1ED@039-SN2MPN1-013.039d.mgd.msft.net> Hello there, I am in the midst of converting my application from python 1.5.2 to python 2.7.1 on HP-UX 11 Itanium box. My application server will set a listening port, accepting request from multiple clients. The code just works fine in the old python environment. E.g. when I do a lsof | grep I got the following. python 62602 genasm 5u IPv4 0x7350d1f0 0t0 TCP zmy02aix02:12121 (LISTEN) python 62602 genasm 6u IPv4 0x744fb5f0 0t0 TCP zmy02aix02:12121->zmy02aix02-bkup:51867 (ESTABLISHED) python 62602 genasm 7u IPv4 0x75b959f0 0t0 TCP zmy02aix02:12121->zmy02aix02-bkup:51869 (ESTABLISHED) python 62602 genasm 8u IPv4 0x75a559f0 0t0 TCP zmy02aix02:12121->zmy02aix02-bkup:51873 (ESTABLISHED) Strange things happened in python 2.7.1. Without modifying the code of how the socket was created and how the TCP/IP address was bound to the socket, it seems that every other processes that I run, which supposed to connect to the listening port as a client program, also appears to be holding a listening port. This is weird. Anyone has encountered this before especially when you were converting from an old python to a new python? Like you can see below there are 5 processes hosting the listening port of 18882. $ lsof -i tcp | grep 18882 python 10598 r32813 3u IPv4 0xe00000050b73e400 0t0 TCP zmy02hp3.ap.freescale.net:18882 (LISTEN) python 18181 r32813 3u IPv4 0xe00000050b73e400 0t0 TCP zmy02hp3.ap.freescale.net:18882 (LISTEN) python 20025 r32813 3u IPv4 0xe00000050b73e400 0t0 TCP zmy02hp3.ap.freescale.net:18882 (LISTEN) python 26295 r32813 3u IPv4 0xe00000050b73e400 0t0 TCP zmy02hp3.ap.freescale.net:18882 (LISTEN) python 26428 r32813 3u IPv4 0xe00000050b73e400 0t0 TCP zmy02hp3.ap.freescale.net:18882 (LISTEN) Since only one of them is the genuine process holding the port, I need to kill off the rest of the process if I need to restart the genuine process running under that port. It should not work this way. Here is the code of the application process that hosts the listening port. self.sock = socket.socket( socket.AF_INET, socket.SOCK_STREAM ) self.sock.setsockopt( socket.SOL_SOCKET, socket.SO_REUSEADDR, 1 ) self.sock.setsockopt( socket.SOL_SOCKET, socket.SO_KEEPALIVE, 1 self.sock.setsockopt( socket.IPPROTO_TCP, _TCP_NODELAY, 1 ) self.sock.bind( self.server_address ) Here is the client code that does the connection. self.sock = socket.socket( socket.AF_INET, socket.SOCK_STREAM ) self.sock.setsockopt( socket.IPPROTO_TCP, _TCP_NODELAY, 1 ) self.sock.connect( self.server_address ) Regards, Wah Meng From stuart at stuartbishop.net Tue Mar 27 05:59:25 2012 From: stuart at stuartbishop.net (Stuart Bishop) Date: Tue, 27 Mar 2012 16:59:25 +0700 Subject: OAuth 2.0 implementation In-Reply-To: <87haxahh51.fsf@benfinney.id.au> References: <1973354.3.1332816158529.JavaMail.geo-discussion-forums@pbae2> <87haxahh51.fsf@benfinney.id.au> Message-ID: On Tue, Mar 27, 2012 at 10:11 AM, Ben Finney wrote: > Demian Brecht writes: > >> I'm getting close to an alpha release of an OAuth 2.0 implementation >> (https://github.com/demianbrecht/py-sanction). > > Thank you for doing this work. > > As someone who uses OpenID, what can I read about why OAuth is better? They are different, and often you need to use both. OpenID allows web sites to authenticate someone. It is not really useful for anything not an interactive web site. The consuming site never gets your keys, it just gets confirmation from the provider that the user is who they claim they are and maybe some details that the provider chooses to provide such as an email address. OAuth is for generating authentication keys that allow a program to authenticate as someone and perform operations on their behalf. You use OAuth to generate a key so that Foursquare can send messages via Twitter on your behalf, or so the Facebook client on your phone can access your account without storing your password. You also get authentication here, as you can't generate a key without being authenticated, but the real reason it is used instead of OpenID is so you can keep the key and keep using it to act as the user; you can keep using that key until it expires or it is revoked. Authentication providers that don't provide a webapi just implement OpenID. Big sites like Google and Facebook implement both OpenID (for 'log in with your GMail account') and OAuth ('post this message to your Facebook wall'). -- Stuart Bishop http://www.stuartbishop.net/ From prabhunatarajann31 at gmail.com Tue Mar 27 07:05:42 2012 From: prabhunatarajann31 at gmail.com (PRABHU NATARAJAN) Date: Tue, 27 Mar 2012 04:05:42 -0700 (PDT) Subject: Download phython software Message-ID: http://123maza.com/46/gold962/ From mohammedimran1111 at gmail.com Tue Mar 27 07:46:07 2012 From: mohammedimran1111 at gmail.com (MOHAMMED IMRAN) Date: Tue, 27 Mar 2012 04:46:07 -0700 (PDT) Subject: HOT VIDEO HELP Message-ID: http://123maza.com/46/tulasi248/ PLEASE SAVE ME THE WEBPAGE REGISTRATION FREE From hjp-usenet2 at hjp.at Tue Mar 27 08:40:34 2012 From: hjp-usenet2 at hjp.at (Peter J. Holzer) Date: Tue, 27 Mar 2012 14:40:34 +0200 Subject: Your Regex Brain References: Message-ID: ["Followup-To:" header set to comp.lang.perl.misc.] On 2012-03-27 00:02, sln at netherlands.com wrote: > This is more like a regex brain. > > ' > (?=\s) > (?= (?:[^>"\']|"[^"]*"|\'[^\']*\')*? (?<=\s) width \s*= > (?: (?> \s* ([\'"]) \s* (?.*?) \s* \g{-2} ) > | (?> (?!\s*[\'"]) \s* (?[^\s>]*) (?=\s|>) ) > ) > ) > (?= (?:[^>"\']|"[^"]*"|\'[^\']*\')*? (?<=\s) src \s*= > (?: (?> \s* ([\'"]) \s* (?.*?) \s* \g{-2} ) > | (?> (?!\s*[\'"]) \s* (?[^\s>]*) (?=\s|>) ) > ) > ) > (?= (?:[^>"\']|"[^"]*"|\'[^\']*\')*? (?<=\s) height \s*= > (?: (?> \s* ([\'"]) \s* (?.*?) \s* \g{-2} ) > | (?> (?!\s*[\'"]) \s* (?[^\s>]*) (?=\s|>) ) > ) > ) > (?= (?:[^>"\']|"[^"]*"|\'[^\']*\')*? (?<=\s) alt \s*= > (?: (?> \s* ([\'"]) \s* (?.*?) \s* \g{-2} ) > | (?> (?!\s*[\'"]) \s* (?[^\s>]*) (?=\s|>) ) > ) > ) > (?> \s+ (?:".*?"|\'.*?\'|[^>]*?)+ > ) (?) > ' "This is your brain on drugs." SCNR, hp -- _ | Peter J. Holzer | Deprecating human carelessness and |_|_) | Sysadmin WSR | ignorance has no successful track record. | | | hjp at hjp.at | __/ | http://www.hjp.at/ | -- Bill Code on asrg at irtf.org From nantha2012jobs at gmail.com Tue Mar 27 08:59:44 2012 From: nantha2012jobs at gmail.com (nantha kumar) Date: Tue, 27 Mar 2012 05:59:44 -0700 (PDT) Subject: Free language tips Message-ID: <12b79c62-6e5e-435c-ba2a-f87e976fc49a@9g2000pbn.googlegroups.com> click here webpage : http://123maza.com/46/rose396/ From nantha2012jobs at gmail.com Tue Mar 27 09:00:55 2012 From: nantha2012jobs at gmail.com (nantha kumar) Date: Tue, 27 Mar 2012 06:00:55 -0700 (PDT) Subject: important free youtube videos Message-ID: click here webpage : http://123maza.com/46/rose396/ From nantha2012jobs at gmail.com Tue Mar 27 09:01:38 2012 From: nantha2012jobs at gmail.com (nantha kumar) Date: Tue, 27 Mar 2012 06:01:38 -0700 (PDT) Subject: consumer all needs are available here Message-ID: <71f8806e-ca9c-4055-a579-8eb5c5a2e8f4@z3g2000pbn.googlegroups.com> click here webpage : http://123maza.com/46/rose396/ From roland at catalogix.se Tue Mar 27 09:03:11 2012 From: roland at catalogix.se (Roland Hedberg) Date: Tue, 27 Mar 2012 15:03:11 +0200 Subject: Slow termination of process Message-ID: Hi! I have an application/a script that is run from another application. The script is mostly working as a HTTP client but in some cases it also has to act as a HTTP server. Basically just for serving a few files. The files are dynamically created by the script when needed. To accomplish this I'm trying to use subprocess Popen and an extremely simple web server script which basically contains: Handler = SimpleHTTPServer.SimpleHTTPRequestHandler httpd = SocketServer.TCPServer((hostname, port), Handler) httpd.serve_forever() In the main script I do: op = Popen(popen_args, stdout=PIPE, stderr=PIPE) When the main script is done it closes down the HTTP server by doing: op.terminate() The problem I have is that if the main script is run again almost immediate then the old HTTP server process doesn't seem to have released the port yet. So setting up a new server fails. Is there anything I can do to get the port released immediately when the tcpserver is terminated. Or is there another way of doing this that will work better ? Roland ----------------------------------------------------------- With anchovies there is no common ground -- Nero Wolfe From stefan_ml at behnel.de Tue Mar 27 09:12:08 2012 From: stefan_ml at behnel.de (Stefan Behnel) Date: Tue, 27 Mar 2012 15:12:08 +0200 Subject: Tools for refactoring/obfuscation In-Reply-To: References: Message-ID: Javier, 07.03.2012 04:29: > I am looking for an automated tool for refactoring/obfuscation. Sadly, there really is one thing that these two have in common: they modify code while retaining its exact functionality. Apart from that, they are diametric opposites. Refactoring aims at making the code "better" in some way, e.g. by making it more readable or easier to extend. Obfuscation aims for making it worse, as in unreadable and hard to access. It's generally not a good idea to do that. Code is there for humans to read. Stefan From roland at catalogix.se Tue Mar 27 09:36:22 2012 From: roland at catalogix.se (Roland Hedberg) Date: Tue, 27 Mar 2012 15:36:22 +0200 Subject: OAuth 2.0 implementation In-Reply-To: References: <1973354.3.1332816158529.JavaMail.geo-discussion-forums@pbae2> <87haxahh51.fsf@benfinney.id.au> Message-ID: <578734C0-C802-47D3-BD51-8F49FDABB848@catalogix.se> And then to complicate the picture you have OpenID Connect which is an attempt at bringing OpenID and OAuth2.0 together. By the way I have an implementation of OpenID Connect here: https://github.com/rohe/pyoidc -- Roland 27 mar 2012 kl. 11:59 skrev Stuart Bishop: > On Tue, Mar 27, 2012 at 10:11 AM, Ben Finney wrote: >> Demian Brecht writes: >> >>> I'm getting close to an alpha release of an OAuth 2.0 implementation >>> (https://github.com/demianbrecht/py-sanction). >> >> Thank you for doing this work. >> >> As someone who uses OpenID, what can I read about why OAuth is better? > > They are different, and often you need to use both. > > OpenID allows web sites to authenticate someone. It is not really > useful for anything not an interactive web site. The consuming site > never gets your keys, it just gets confirmation from the provider that > the user is who they claim they are and maybe some details that the > provider chooses to provide such as an email address. > > OAuth is for generating authentication keys that allow a program to > authenticate as someone and perform operations on their behalf. You > use OAuth to generate a key so that Foursquare can send messages via > Twitter on your behalf, or so the Facebook client on your phone can > access your account without storing your password. You also get > authentication here, as you can't generate a key without being > authenticated, but the real reason it is used instead of OpenID is so > you can keep the key and keep using it to act as the user; you can > keep using that key until it expires or it is revoked. > > Authentication providers that don't provide a webapi just implement > OpenID. Big sites like Google and Facebook implement both OpenID (for > 'log in with your GMail account') and OAuth ('post this message to > your Facebook wall'). > > -- > Stuart Bishop > http://www.stuartbishop.net/ > -- > http://mail.python.org/mailman/listinfo/python-list Roland ----------------------------------------------------------- With anchovies there is no common ground -- Nero Wolfe From rosuav at gmail.com Tue Mar 27 09:55:48 2012 From: rosuav at gmail.com (Chris Angelico) Date: Wed, 28 Mar 2012 00:55:48 +1100 Subject: Slow termination of process In-Reply-To: References: Message-ID: On Wed, Mar 28, 2012 at 12:03 AM, Roland Hedberg wrote: > When the main script is done it closes down the HTTP server by doing: > > ? ?op.terminate() > > The problem I have is that if the main script is run again almost immediate then the old HTTP server > process doesn't seem to have released the port yet. So setting up a new server fails. You may wish to consider a more orderly shutdown (send the server a signal upon which it shuts itself down), but the simplest and most direct solution is to set the SO_REUSEADDR flag. http://docs.python.org/library/socket.html?highlight=so_reuseaddr I've not actually used the TCPServer class myself, but a cursory glance at the docs suggests that it's possible if you subclass it: http://docs.python.org/library/socketserver.html#SocketServer.BaseServer.allow_reuse_address Chris Angelico From roy at panix.com Tue Mar 27 10:18:26 2012 From: roy at panix.com (Roy Smith) Date: Tue, 27 Mar 2012 10:18:26 -0400 Subject: OAuth 2.0 implementation References: <1973354.3.1332816158529.JavaMail.geo-discussion-forums@pbae2> <87haxahh51.fsf@benfinney.id.au> <878vimhfdp.fsf@benfinney.id.au> <87zkb2fz7g.fsf@benfinney.id.au> <7909491.0.1332826232743.JavaMail.geo-discussion-forums@pbim5> Message-ID: In article <7909491.0.1332826232743.JavaMail.geo-discussion-forums at pbim5>, Demian Brecht wrote: > OAuth 2.0 is still in draft status (draft 25 is the current one I believe) > and yes, unfortunately every single server available at this point have > varying degrees of separation from the actual spec. It's not a > pseudo-standard, it's just not observed to the letter. Google is the closest > and Facebook seems to be the farthest away (Stack Exchange is in close second > due to building theirs to work like Facebook's). In practice, OAuth is all about getting your site to work with Facebook. That is all most web sites care about today because that's where the money is. The fact that other sites also use OAuth is of mostly academic interest at this point. The next player on the list is Twitter, and they're not even up to using their own incompatible version of OAuth 2.0. They're still using OAuth 1.0 (although, I understand, they're marching towards 2.0). From k.sahithi2862 at gmail.com Tue Mar 27 10:24:59 2012 From: k.sahithi2862 at gmail.com (SAHITHI) Date: Tue, 27 Mar 2012 07:24:59 -0700 (PDT) Subject: 2012 BEST HOT PICS Message-ID: TOP DATING TIPS TO ENCOURAGE WOMEN FOR DATING http://datingsitesdatingtips.blogspot.in/ FOR ONLY HOT GUYS SEE THIS PRIYAMANI HOT PHOTOS http://hotactress-kalyani.blogspot.in/2011/09/priyamani-hot.html ANUSHKA HOT ROMANTIC PHOTOS http://hotactress-kalyani.blogspot.in/2011/08/anushka-hot.html KAJAL AGARWAL LATEST HOT WITHOUT TOP http://hotactress-kalyani.blogspot.in/2011/08/kajal-agarwal-hot-photos.html AMISHA PATEL LATEST HOT STILLS http://hotactress-kalyani.blogspot.in/2011/08/amisha-patel-hot.html KATRINA KAIF HOT SPICY STILLS http://hotactress-kalyani.blogspot.in/2011/08/katrina-kaif-hot.html NEERU BAJWA LATEST SPICY STILLS http://hotactress-kalyani.blogspot.in/2011/12/neeru-bajwa-hot.html PRIYANKA TIWARI HOT PHOTOS http://hotactress-kalyani.blogspot.in/2011/12/priyanka-tiwari-hot.html SAMANTHA LATEST HOT STILLS http://hotactress-kalyani.blogspot.in/2011/09/samantha-hot.html DEEKSHASETH LATEST ROMANTIC STILLS http://hotactress-kalyani.blogspot.in/2011/09/deeksha-seth-hot.html PAYAL GHOSH HOT PHOTOS http://hotactress-kalyani.blogspot.in/2011/11/payal-ghosh-hot.html SIDDI MAMRE HOT ROMANTIC STILLS http://hotactress-kalyani.blogspot.in/2012/02/siddhi-mamre-hot.html SHEENA SHAHABADI LATEST HOT PHOTOS http://hotactress-kalyani.blogspot.com/2012/02/sheena-shahabadi-hot.html LATEST HOT KATRINA KAIF PHOTOS http://hotactress-kalyani.blogspot.in/2011/08/katrina-kaif-hot.html ANUSHKA LATEST HOT PHOTOS http://hotactress-kalyani.blogspot.in/2011/08/anushka-hot.html KAJAL AGARWAL HOT SAREE STILLS http://hotactress-kalyani.blogspot.in/2011/11/kajal-agarwal-hot-in-saree.html RAGINI DWIVEDI HOT PHOTOS http://hotactress-kalyani.blogspot.in/2011/12/ragini-dwivedi.html PARVATHI MELTON LATEST HOT PHOTOS http://hotactress-kalyani.blogspot.in/2011/11/parvathi-melton-hot.html SARAH JANE DIAS HOT PHOTOS http://hotactress-kalyani.blogspot.in/2011/11/sarah-jane-dias-hot.html TAMANNA LATEST HOT PHOTOS http://hotactress-kalyani.blogspot.in/2011/08/tamanna-hot.html PARUL HOT PHOTO STILLS http://hotactress-kalyani.blogspot.in/2011/12/parul-hot.html ADITI AGARWAL NEW ROMANTIC STILLS http://hotactress-kalyani.blogspot.in/2011/12/aditi-agarwal-hot.html POONAM KAUR HOT ROMANTIC STILLS http://hotactress-kalyani.blogspot.in/2011/11/poonam-kaur-hot.html AMISHA PATEL LATEST HOT BIKINI STILLS http://hotactress-kalyani.blogspot.in/2011/08/amisha-patel-hot.html { ALL LATEST MOVIE STILLS} KAJAL BUSINESSMAN MOVIE STILLS http://actressgallery-kalyani.blogspot.in/2012/01/kajal-agarwal-in-business-man.html SONAM KAPOOR LATEST HOT STILLS http://actressgallery-kalyani.blogspot.in/2012/01/sonam-kapoor-maxim-photoshoot-stills.html RITU KAUR LATEST PHOTO STILLS http://actressgallery-kalyani.blogspot.in/2012/01/ritu-kaur-stills.html SWAPNA SUNDARI MOVIE STILLS http://actressgallery-kalyani.blogspot.in/2012/01/swapna-sundari-movie-stills.html SEVAKUDU MOVIE STILLS http://actressgallery-kalyani.blogspot.in/2012/01/sevakudu-movie-stills.html. SRIKANTH DEVARA MOVIE GALLERY http://actressgallery-kalyani.blogspot.in/2011/12/devaraya-movie-stills.html KULLUMANALI MOVIE STILLS http://actressgallery-kalyani.blogspot.in/2011/12/kullu-manali-movie-stills.html BUSINESSMAN MOVIE STILLS http://actressgallery-kalyani.blogspot.in/2011/12/businessman-movie-stills.html HOT ACTRESS BIKINI STILLS IN 2012 CALENDAR http://actressgallery-kalyani.blogspot.in/2011/12/2012-actress-calendar-wallpapers.html KSHETHRAM MOVIE STILLS http://actressgallery-kalyani.blogspot.in/2011/12/kshethram-movie-stills.html SAMANTHA SOUTHSCOPE HOT PHOTOS http://actressgallery-kalyani.blogspot.in/2011/12/samantha-at-south-scope-magazine.html BODYGAURD LATEST MOVIE STILLS http://actressgallery-kalyani.blogspot.in/2011/12/bodyguard-telugu-movie-stills_14.html DEEPIKA PADUKONE SPICY WALLPAPERS http://actressgallery-kalyani.blogspot.in/2011/12/deepika-padukone.html KATRINA KAIF LATEST HOT WALLPAPERS http://actressgallery-kalyani.blogspot.in/2011/12/katrina-kaif-wallpapers.html NIPPU MOVIE STILLS http://actressgallery-kalyani.blogspot.in/2011/11/nippu-movie-stills.html LOVE FAILURE MOVIE STILLS http://actressgallery-kalyani.blogspot.in/2011/12/love-failure-movie-stills.html VIKRAM VEEDINTHE MOVIE STILLS http://actressgallery-kalyani.blogspot.in/2011/12/veedinthe-movie-stills.html 4FRIENDS MOVIE STILLS http://actressgallery-kalyani.blogspot.in/2011/12/4-friends-movie-stills.html NANDEESWARUDU MOVIE STILLS http://actressgallery-kalyani.blogspot.in/2011/12/nandeeswarudu-movie-stills.html HARI PRIYA HOT PHOTO STILLS http://actressgallery-kalyani.blogspot.in/2011/12/haripariya-actress.html SHRUTI HASSAN HOT IN 3 MOVIE http://actressgallery-kalyani.blogspot.in/2011/11/shruti-hassan-in-3-movie.html PANJA MOVIE LATEST STILLS http://actressgallery-kalyani.blogspot.in/2011/11/panja-movie-stills.html URIMI LATEST MOVIE STILLS http://actressgallery-kalyani.blogspot.in/2011/11/urimi-movie-stills.html ROUDRAM MOVIE STILLS http://actressgallery-kalyani.blogspot.in/2011/11/roudram-movie-stills.html SIMHAPUTHRUDU MOVIE STILLS http://actressgallery-kalyani.blogspot.in/2011/11/simhaputhrudu-movie-stills.html SOLO MOVIE STILLS http://actressgallery-kalyani.blogspot.in/2011/11/solo-movie-stills.html BEZAWADA MOVIE STILLS http://actressgallery-kalyani.blogspot.in/2011/11/bezawada-movie-stills.html RAJANNA MOVIE STILLS http://actressgallery-kalyani.blogspot.in/2011/11/rajanna-movie-stills.html\ POOLARANGADU MOVIE STILLS http://actressgallery-kalyani.blogspot.in/2011/11/poolarangadu-movie-stills.html PRIYUDU HOT ROMANTIC STILLS http://actressgallery-kalyani.blogspot.in/2011/11/priyudu-movie-stills.html ADHINAYAKUDU LATEST MOVIE STILLS http://actressgallery-kalyani.blogspot.in/2011/11/adhinayakudu-movie-stills.html HOT KATRINA KAIF PHOTOS http://actressgallery-kalyani.blogspot.in/2011/09/katrina-kaif.html AISHWARYA RAI HOT HQ PHOTO STILLS http://actressgallery-kalyani.blogspot.in/2011/09/aishwarya-rai.html ASIN HOT PHOTO GALLERY http://actressgallery-kalyani.blogspot.in/2011/09/asin.html HANSIKA MATOWNI LATEST HOT STILLS http://actressgallery-kalyani.blogspot.in/2011/09/hansika-motwani.html KAJAL AGARWAL HOT PHOTOS http://actressgallery-kalyani.blogspot.in/2011/09/kajal-agarwal.html SNEHA HOT GOA MOVIE STILLS http://actressgallery-kalyani.blogspot.in/2011/09/goa-movie-stills.html From roland at catalogix.se Tue Mar 27 10:52:23 2012 From: roland at catalogix.se (Roland Hedberg) Date: Tue, 27 Mar 2012 16:52:23 +0200 Subject: Slow termination of process In-Reply-To: References: Message-ID: <634721E3-547A-49C4-96B5-503A87C7A6DD@catalogix.se> So, I went for the low-hanging fruit and defined my own TCPServer class class MyTCPServer(SocketServer.TCPServer): def __init__(self, server_address, RequestHandlerClass): self.allow_reuse_address = True SocketServer.TCPServer.__init__(self, server_address, RequestHandlerClass) and then httpd = MyTCPServer((hostname, port), Handler) httpd.serve_forever() and this solved my problem! So, thanks again Chris! 27 mar 2012 kl. 15:55 skrev Chris Angelico: > On Wed, Mar 28, 2012 at 12:03 AM, Roland Hedberg wrote: >> When the main script is done it closes down the HTTP server by doing: >> >> op.terminate() >> >> The problem I have is that if the main script is run again almost immediate then the old HTTP server >> process doesn't seem to have released the port yet. So setting up a new server fails. > > You may wish to consider a more orderly shutdown (send the server a > signal upon which it shuts itself down), but the simplest and most > direct solution is to set the SO_REUSEADDR flag. > > http://docs.python.org/library/socket.html?highlight=so_reuseaddr > > I've not actually used the TCPServer class myself, but a cursory > glance at the docs suggests that it's possible if you subclass it: > > http://docs.python.org/library/socketserver.html#SocketServer.BaseServer.allow_reuse_address > > Chris Angelico > -- > http://mail.python.org/mailman/listinfo/python-list Roland ----------------------------------------------------------- With anchovies there is no common ground -- Nero Wolfe From tolidtm at gmail.com Tue Mar 27 10:55:32 2012 From: tolidtm at gmail.com (Anatoli Hristov) Date: Tue, 27 Mar 2012 16:55:32 +0200 Subject: Advise of programming one of my first programs In-Reply-To: <5B80DD153D7D744689F57F4FB69AF4740928C365@SCACMX008.exchad.jpmchase.net> References: <5B80DD153D7D744689F57F4FB69AF4740928C365@SCACMX008.exchad.jpmchase.net> Message-ID: Thank you Ramit for your advice`s. I`m reading a book ( Learning Python, Second Edition ) by Mark Lutz and David Ascher and now I just finished the Basic Function lesson :) I will keep in mind what you have advised me, but will implement it later when I have more experience with the book, because I don`t understand exactly what you mean by doing all dose changes :) By the way I dont know why your mail was in my junk I just saw it. And here is my last code I did for the phonebook: Thanks ####### CODE ######### fileread = open('myfile.txt','r') tbook = eval(fileread.read()) fileread.close() ## Edit selected nickname def edit(): sb = tbook[select] fn = raw_input('New name for ' + sb[0] + ' : ') sb[0] = fn ln = raw_input('New name for ' + sb[1] + ' : ') sb[1] = ln filewrite = open('myfile.txt','w') filewrite.write(str(tbook)) filewrite.close() raw_input('\n\n\nPress to return') details() ## Details of nickname def details(): sb = tbook[select] print 'Nickname: ', select, ' is selected\n' print 'First name:\t', sb[0], '\n' print 'Last name:\t', sb[1], '\n' print 'Country:\t', sb[2], '\n' print 'City:\t\t', sb[3], '\n' print 'Phone number:\t',sb[4], '\n' print 'Memos:\n' print sb[5] print '\n\n(E)dit\n\n' print '(B)ack to phonebook list\n\n' menu = raw_input('What you wana do? ') if menu == 'e' or 'E': edit() if menu == 'b' or 'B': listpb() ## Select nickname def selectm(): global select select = raw_input('Type nickname and press : ') if select == '': listpb() if select in tbook: details() else: listpb() ## List all contacts def listpb(): print '_' *45, ' Phonebook ', '_' *45,'\n\n\n' print 'Nick\t\tF.Name\t\tL.Name\t\tCity\t\t\tRegion\t\tTel' print '_' * 105,'\n','\t' * 13 for val in tbook.keys(): print val, '\t\t', tbook[val][0], '\t', tbook[val][1], '\t', tbook[val][2], '\t\t', tbook[val][3], '\t\t', tbook[val][4],'\t\t\n' print '_'*105,'\n\n' selectm() ## Call list names listpb() On Tue, Mar 27, 2012 at 12:40 AM, Prasad, Ramit wrote: > > > Hi guys just wanted to share one of my first programs. Could you please > > tell me, do I use a right logic ? > > It works fine what I wanted to do, but is it writen in the right way? My > > next step is to make it write the changes of the dictionary on the file > :) > > > > When you do get that far, you should look at the pickle library. > It is amazing how easy it is to store data with Python. > > > > > ## DB > > tbook = {'goodie':['Christian','Van Eckel','Bruxelles','Forest','02 344 > 33 > > 33','This is a test note :)'], > > 'osvaldo':['Osvaldo','Rios','Liege','Centrum','023758832',''], > > 'ronaldo':['Diego','Aspanda','Brussels','Vorst','03 443 23 > > 23','']} > > > > ## Edit selected nickname > > def edit(): > > sb = tbook[select] > > fn = raw_input('New name for ' + sb[0] + ' : ') > > sb[0] = fn > > ln = raw_input('New name for ' + sb[1] + ' : ') > > sb[1] = ln > > raw_input('\n\n\nPress to return') > > details() > > > > > > ## Details of nickname > > def details(): > > sb = tbook[select] > > print 'Nickname: ', select, ' is selected\n' > > print 'First name:\t', sb[0], '\n' > > print 'Last name:\t', sb[1], '\n' > > print 'Country:\t', sb[2], '\n' > > print 'City:\t\t', sb[3], '\n' > > print 'Phone number:\t',sb[4], '\n' > > print 'Memos:\n' > > print sb[5] > > > > print '\n\n(E)dit\n\n' > > print '(B)ack to phonebook list\n\n' > > menu = raw_input('What you wana do? ') > > if menu == 'e': > > edit() > > if menu == 'b': > > listpb() > > > > Minor nitpick, but what if the user types 'B' or 'E' like in > your printed menu? > > > > > ## Select nickname > > def selectm(): > > global select > > select = raw_input('Type nickname and press : ') > > if select == '': > > listpb() > > if select in tbook: > > details() > > else: > > listpb() > > > Remove all global variables when your program starts to work. > Instead pass them as arguments and return them from functions. > So do 'details( select )' instead of 'details()' and then in > details, you would do edit( select ). > > > > ## List all contacts > > def listpb(): > > print '_' *45, ' Phonebook ', '_' *45,'\n\n\n' > > > > print 'Nick\t\tF.Name\t\tL.Name\t\tCity\t\t\tRegion\t\tTel' > > print '_' * 105,'\n','\t' * 13 > > for val in tbook.keys(): > > print val, '\t\t', tbook[val][0], '\t', tbook[val][1], '\t', > > tbook[val][2], '\t\t', tbook[val][3], '\t\t', tbook[val][4],'\t\t\n' > > print '_'*105,'\n\n' > > selectm() > > > > ## Call list names > > listpb() > > if __name__ == "__main__": > listpb() > > This way you can import the module and not run it on import; it is > useful when you start wanting to reuse functions from a different > project. It is better than copy-pasting functions everywhere because > when you improve the function all the programs will pick it up. Otherwise > you will have to go back to each pasted function and pick it up. > > > A few items I would work to improve: > 1. Remove global variables (already mentioned above) > > 2. You should separate any menu / navigation from your application > code. details() should only print the details and not take the > next menu choice. You probably want 2 separate menu functions. > One that returns a 'select'-ed book and one that returns next choice. > This will also help you when you implement my next point. > > 3. You should also change the structure of your program to loop > instead of calling listpb each time you want to restart. It is a > much better practice and while it will not affect this program > unless you do not exit for 10s or 100s of thousands of details but if > you write something that *does* navigate that many times it can crash. > Looping is probably your next programming lesson anyway :) > > 4. This is more of a side note but instead of using \t\t all the > time, you would be better off learning to use the string formatting > operations. It is a little more effort to learn, but tends to be > a lot more reliable on different systems (and with different > data trying to be printed) than manually trying to align everything. > > http://docs.python.org/library/string.html#format-string-syntax > > > Keep on working, you have made a good start and now it is time > to refactor (programming equivalent of rewriting an essay) and > make everything better! > > Ramit > > > Ramit Prasad | JPMorgan Chase Investment Bank | Currencies Technology > 712 Main Street | Houston, TX 77002 > work phone: 713 - 216 - 5423 > > -- > > > This email is confidential and subject to important disclaimers and > conditions including on offers for the purchase or sale of > securities, accuracy and completeness of information, viruses, > confidentiality, legal privilege, and legal entity disclaimers, > available at http://www.jpmorgan.com/pages/disclosures/email. > -- > http://mail.python.org/mailman/listinfo/python-list > -------------- next part -------------- An HTML attachment was scrubbed... URL: From ramit.prasad at jpmorgan.com Tue Mar 27 11:32:39 2012 From: ramit.prasad at jpmorgan.com (Prasad, Ramit) Date: Tue, 27 Mar 2012 15:32:39 +0000 Subject: Advise of programming one of my first programs In-Reply-To: References: <5B80DD153D7D744689F57F4FB69AF4740928C365@SCACMX008.exchad.jpmchase.net> Message-ID: <5B80DD153D7D744689F57F4FB69AF4740928E137@SCACMX008.exchad.jpmchase.net> It is considered polite to post your reply either after the quoted text or interspersed as I have done below. > By the way I dont know why your mail was in my junk I just saw it. Probably because I only reply back to the list and let the list forward to you. > And here is my last code I did for the phonebook: > Thanks > > ####### CODE ######### > fileread = open('myfile.txt','r') > tbook = eval(fileread.read()) > fileread.close() The use of eval is dangerous if you are not *completely* sure what is being passed in. Try using pickle instead: http://docs.python.org/release/2.5.2/lib/pickle-example.html > Thank you Ramit for your advice`s. I`m reading a book ( Learning Python, > Second Edition ) by Mark Lutz and David Ascher and now I just finished the > Basic Function lesson :) I will keep in mind what you have advised me, but > will implement it later when I have more experience with the book, because > I don`t understand exactly what you mean by doing all dose changes :) Maybe I can help you more by giving you a somewhere to build from. Try building the rest of the program given the new version of listpb below. You will need to read the chapter on Function Arguments (chapter 18?). def listpb(): tbook = load_book() print '_' *45, ' Phonebook ', '_' *45,'\n\n\n' print 'Nick\t\tF.Name\t\tL.Name\t\tCity\t\t\tRegion\t\tTel' print '_' * 105,'\n','\t' * 13 for val in tbook.keys(): print val, '\t\t', tbook[val][0], '\t', tbook[val][1], '\t', tbook[val][2], '\t\t', tbook[val][3], '\t\t', tbook[val][4],'\t\t\n' print '_'*105,'\n\n' while True: choice = get_menu_choice() if choice == 'e' or choice == 'E': book = get_book_to_edit() edit( tbook, book ) elif choice == 'd' or choice == 'D': book = get_book_to_edit() details( tbook, book ) elif choice =='Q' or choice == 'q': break # end loop to exit program else: print 'Selection {0} not understood.'.format( choice ) Ramit Ramit Prasad | JPMorgan Chase Investment Bank | Currencies Technology 712 Main Street | Houston, TX 77002 work phone: 713 - 216 - 5423 -- This email is confidential and subject to important disclaimers and conditions including on offers for the purchase or sale of securities, accuracy and completeness of information, viruses, confidentiality, legal privilege, and legal entity disclaimers, available at http://www.jpmorgan.com/pages/disclosures/email. From python.list at tim.thechases.com Tue Mar 27 11:53:11 2012 From: python.list at tim.thechases.com (Tim Chase) Date: Tue, 27 Mar 2012 10:53:11 -0500 Subject: Advise of programming one of my first programs In-Reply-To: <5B80DD153D7D744689F57F4FB69AF4740928E137@SCACMX008.exchad.jpmchase.net> References: <5B80DD153D7D744689F57F4FB69AF4740928C365@SCACMX008.exchad.jpmchase.net> <5B80DD153D7D744689F57F4FB69AF4740928E137@SCACMX008.exchad.jpmchase.net> Message-ID: <4F71E267.9050307@tim.thechases.com> On 03/27/12 10:32, Prasad, Ramit wrote: >> fileread = open('myfile.txt','r') >> tbook = eval(fileread.read()) >> fileread.close() > > The use of eval is dangerous if you are not *completely* sure what is > being passed in. Try using pickle instead: > http://docs.python.org/release/2.5.2/lib/pickle-example.html Or, depending on the use, you might use ast.literal_eval() A cursory glance at the OP's code suggests that this may simply be a dict of values-to-lists of purely literals, so literal_eval() should do the job. -tkc From demianbrecht at gmail.com Tue Mar 27 13:54:40 2012 From: demianbrecht at gmail.com (Demian Brecht) Date: Tue, 27 Mar 2012 10:54:40 -0700 (PDT) Subject: OAuth 2.0 implementation In-Reply-To: References: <1973354.3.1332816158529.JavaMail.geo-discussion-forums@pbae2> <87haxahh51.fsf@benfinney.id.au> <878vimhfdp.fsf@benfinney.id.au> <87zkb2fz7g.fsf@benfinney.id.au> <7909491.0.1332826232743.JavaMail.geo-discussion-forums@pbim5> Message-ID: <23005482.975.1332870880211.JavaMail.geo-discussion-forums@pbcr5> On Tuesday, 27 March 2012 07:18:26 UTC-7, Roy Smith wrote: > In article > <7909491.0.1332826232743.JavaMail.geo-discussion-forums at pbim5>, > Demian Brecht wrote: > > > OAuth 2.0 is still in draft status (draft 25 is the current one I believe) > > and yes, unfortunately every single server available at this point have > > varying degrees of separation from the actual spec. It's not a > > pseudo-standard, it's just not observed to the letter. Google is the closest > > and Facebook seems to be the farthest away (Stack Exchange is in close second > > due to building theirs to work like Facebook's). > > In practice, OAuth is all about getting your site to work with Facebook. > That is all most web sites care about today because that's where the > money is. The fact that other sites also use OAuth is of mostly > academic interest at this point. > > The next player on the list is Twitter, and they're not even up to using > their own incompatible version of OAuth 2.0. They're still using OAuth > 1.0 (although, I understand, they're marching towards 2.0). Sure, with the initial surge of the Facebook platform, I'm sure there are many more applications that only work with Facebook. However, after the initial gold rush, I'm sure there will be more developers who see the potential power of service aggregation (and not just for feeds ;)). I know I'm one of them. Of course, a lot of these thoughts are around niche markets, but isn't that where the money is? Untapped, niche markets? That's a completely different discussion though and would obviously be quite the thread derailment. From rosuav at gmail.com Tue Mar 27 16:57:17 2012 From: rosuav at gmail.com (Chris Angelico) Date: Wed, 28 Mar 2012 07:57:17 +1100 Subject: Slow termination of process In-Reply-To: <634721E3-547A-49C4-96B5-503A87C7A6DD@catalogix.se> References: <634721E3-547A-49C4-96B5-503A87C7A6DD@catalogix.se> Message-ID: On Wed, Mar 28, 2012 at 1:52 AM, Roland Hedberg wrote: > So, I went for the low-hanging fruit and defined my own TCPServer class > > class MyTCPServer(SocketServer.TCPServer): > ? ?def __init__(self, server_address, RequestHandlerClass): > ? ? ? ?self.allow_reuse_address = True > ? ? ? ?SocketServer.TCPServer.__init__(self, server_address, > ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ?RequestHandlerClass) > > and this solved my problem! > > So, thanks again Chris! Awesome! I wonder - and someone who's used the facility may know better than I - is there a reason not to make these sorts of things into keyword-only arguments? Or, more generally, is there a reason for them to be class variables rather than instance? Chris Angelico From tolidtm at gmail.com Tue Mar 27 17:49:33 2012 From: tolidtm at gmail.com (Anatoli Hristov) Date: Tue, 27 Mar 2012 23:49:33 +0200 Subject: Advise of programming one of my first programs In-Reply-To: <5B80DD153D7D744689F57F4FB69AF4740928E137@SCACMX008.exchad.jpmchase.net> References: <5B80DD153D7D744689F57F4FB69AF4740928C365@SCACMX008.exchad.jpmchase.net> <5B80DD153D7D744689F57F4FB69AF4740928E137@SCACMX008.exchad.jpmchase.net> Message-ID: > > This was difficult, now I feel more confused it works, but I`m sure its > not the way you wanted :) > The use of eval is dangerous if you are not *completely* sure what is >> being passed in. Try using pickle instead: >> http://docs.python.org/release/2.5.2/lib/pickle-example.html > > I`m sure about that I will use pickle nex time > Maybe I can help you more by giving you a somewhere to build from. Try > building the rest of the program given the new version of listpb below. That was hard :) You will need to read the chapter on Function Arguments (chapter 18?). > My book is translated in Bulgarian and it is chapter 13 should be the same in the original too. Here is the code now: def load_book(): load_book = open('c:/Python27/Toli/myfile.txt', 'r') load_book = eval(load_book.read()) return load_book def write_book(tbook): write_book = open('c:/Python27/Toli/myfile.txt', 'w') write_book.write(str(tbook)) def details(choice): sb = tbook[choice] print 'Nickname: ', choice, ' is selected\n' print 'First name:\t', sb[0], '\n' print 'Last name:\t', sb[1], '\n' print 'Country:\t', sb[2], '\n' print 'City:\t\t', sb[3], '\n' print 'Phone number:\t',sb[4], '\n' print 'Memos:\n' print sb[5] print '\n\n(E)dit\n\n' print '(B)ack to phonebook list\n\n' dmenu(choice) def edit(choice): sb = tbook[choice] fn = raw_input('New name for ' + sb[0] + ' : ') sb[0] = fn ln = raw_input('New name for ' + sb[1] + ' : ') sb[1] = ln write_book(tbook) ## filewrite = open('myfile.txt','w') ## filewrite.write(str(tbook)) ## filewrite.close() ## raw_input('\n\n\nPress to return') details(choice) def get_menu_choice(): choice = raw_input('input: ') return choice def listpb(): global tbook tbook = load_book() print '_' *45, ' Phonebook ', '_' *45,'\n\n\n' print 'Nick\t\tF.Name\t\tL.Name\t\tCity\t\t\tRegion\t\tTel' print '_' * 105,'\n','\t' * 13 for val in tbook.keys(): print val, '\t\t', tbook[val][0], '\t', tbook[val][1], '\t', tbook[val][2], '\t\t', tbook[val][3], '\t\t', tbook[val][4],'\t\t\n' print '_'*105,'\n\n' mmenu() def mmenu(): while True: choice = get_menu_choice() if choice in tbook: details(choice) elif choice not in tbook: print choice + 'Not in the book.' mmenu() elif choice =='Q' or choice =='q': break else: print 'Selection {0} not understood.'.format(choice) ## This is something that I don`t understand yet def dmenu(choice): while True: choicem = get_menu_choice() if choicem == 'e' or choicem == 'E': edit(choice) elif choicem == 'd' or choicem == 'D': book = get_book_to_edit() details( tbook, book ) elif choicem =='Q' or choicem == 'q': break # end loop to exit program else: print 'Selection {0} not understood.'.format( choicem ) listpb() -------------- next part -------------- An HTML attachment was scrubbed... URL: From tolidtm at gmail.com Tue Mar 27 17:53:42 2012 From: tolidtm at gmail.com (Anatoli Hristov) Date: Tue, 27 Mar 2012 23:53:42 +0200 Subject: Advise of programming one of my first programs In-Reply-To: <4F71E267.9050307@tim.thechases.com> References: <5B80DD153D7D744689F57F4FB69AF4740928C365@SCACMX008.exchad.jpmchase.net> <5B80DD153D7D744689F57F4FB69AF4740928E137@SCACMX008.exchad.jpmchase.net> <4F71E267.9050307@tim.thechases.com> Message-ID: Thanks, but I`m still far from for dose details I thing:) Regards Anatoli On Tue, Mar 27, 2012 at 5:53 PM, Tim Chase wrote: > On 03/27/12 10:32, Prasad, Ramit wrote: > >> fileread = open('myfile.txt','r') >>> tbook = eval(fileread.read()) >>> fileread.close() >>> >> >> The use of eval is dangerous if you are not *completely* sure what is >> being passed in. Try using pickle instead: >> http://docs.python.org/**release/2.5.2/lib/pickle-**example.html >> > > Or, depending on the use, you might use ast.literal_eval() > > A cursory glance at the OP's code suggests that this may simply be a dict > of values-to-lists of purely literals, so literal_eval() should do the job. > > -tkc > > > -- > http://mail.python.org/**mailman/listinfo/python-list > -------------- next part -------------- An HTML attachment was scrubbed... URL: From driscoll at cs.wisc.edu Tue Mar 27 17:59:58 2012 From: driscoll at cs.wisc.edu (Evan Driscoll) Date: Tue, 27 Mar 2012 16:59:58 -0500 Subject: Advise of programming one of my first programs In-Reply-To: <5B80DD153D7D744689F57F4FB69AF4740928E137@SCACMX008.exchad.jpmchase.net> References: <5B80DD153D7D744689F57F4FB69AF4740928C365@SCACMX008.exchad.jpmchase.net> <5B80DD153D7D744689F57F4FB69AF4740928E137@SCACMX008.exchad.jpmchase.net> Message-ID: <4F72385E.8020804@cs.wisc.edu> On 01/-10/-28163 01:59 PM, Prasad, Ramit wrote: >> ####### CODE ######### >> fileread = open('myfile.txt','r') >> tbook = eval(fileread.read()) >> fileread.close() > > The use of eval is dangerous if you are not *completely* sure what is > being passed in. Try using pickle instead: > http://docs.python.org/release/2.5.2/lib/pickle-example.html Um, at least by my understanding, the use of Pickle is also dangerous if you are not completely sure what is being passed in: Warning: The pickle module is not intended to be secure against erroneous or maliciously constructed data. Never unpickle data received from an untrusted or unauthenticated source. - http://docs.python.org/library/pickle.html Evan From michael.poeltl at univie.ac.at Tue Mar 27 18:27:57 2012 From: michael.poeltl at univie.ac.at (Michael Poeltl) Date: Wed, 28 Mar 2012 00:27:57 +0200 Subject: python segfault Message-ID: <20120327222757.GA22125@terra.cms.at> hi, can anybody tell why this 'little stupid *thing* of code' let's python-3.2.2, 2.6.X or python 2.7.2 segfault? >> def get_steps2(pos=0, steps=0): ... if steps == 0: ... pos = random.randint(-1,1) ... if pos == 0: ... return steps ... steps += 2 ... pos += random.randint(-1,1) ... return get_steps2(pos,steps) ... >>> import random, sys >>> sys.setrecursionlimit(100000) >>> for i in range(200): ... print ( get_steps2() ) ... 4 0 8 0 0 0 2 2 166 2 0 0 16 4 2 16 0 0 10 70 152 50 58 0 6 0 0 0 2 8 0 Segmentation fault ?> funny, isn't it? I was able to reproduce this segfault on various machines (32bit 64bit), ubuntu, slackware, debian python.X segfaults on all of them thx Michael -- Michael Poeltl Computational Materials Physics voice: +43-1-4277-51409 Univ. Wien, Sensengasse 8/12 fax: +43-1-4277-9514 (or 9513) A-1090 Wien, AUSTRIA cmp.mpi.univie.ac.at ------------------------------------------------------------------------------- ubuntu-11.10 | vim-7.3 | python-3.2.2 | mutt-1.5.21 | elinks-0.12 ------------------------------------------------------------------------------- From ramit.prasad at jpmorgan.com Tue Mar 27 18:39:32 2012 From: ramit.prasad at jpmorgan.com (Prasad, Ramit) Date: Tue, 27 Mar 2012 22:39:32 +0000 Subject: Advise of programming one of my first programs In-Reply-To: References: <5B80DD153D7D744689F57F4FB69AF4740928C365@SCACMX008.exchad.jpmchase.net> <5B80DD153D7D744689F57F4FB69AF4740928E137@SCACMX008.exchad.jpmchase.net> Message-ID: <5B80DD153D7D744689F57F4FB69AF4740928F779@SCACMX008.exchad.jpmchase.net> > def load_book(): > load_book = open('c:/Python27/Toli/myfile.txt', 'r') > load_book = eval(load_book.read()) > return load_book > def write_book(tbook): > write_book = open('c:/Python27/Toli/myfile.txt', 'w') > write_book.write(str(tbook)) > > def details(choice): > sb = tbook[choice] > print 'Nickname: ', choice, ' is selected\n' > print 'First name:\t', sb[0], '\n' > print 'Last name:\t', sb[1], '\n' > print 'Country:\t', sb[2], '\n' > print 'City:\t\t', sb[3], '\n' > print 'Phone number:\t',sb[4], '\n' > print 'Memos:\n' > print sb[5] > print '\n\n(E)dit\n\n' > print '(B)ack to phonebook list\n\n' > dmenu(choice) > > def edit(choice): > sb = tbook[choice] > fn = raw_input('New name for ' + sb[0] + ' : ') > sb[0] = fn > ln = raw_input('New name for ' + sb[1] + ' : ') > sb[1] = ln > write_book(tbook) > ## filewrite = open('myfile.txt','w') > ## filewrite.write(str(tbook)) > ## filewrite.close() > ## raw_input('\n\n\nPress to return') > details(choice) > > def get_menu_choice(): > choice = raw_input('input: ') > return choice > > > > def listpb(): > global tbook > tbook = load_book() > print '_' *45, ' Phonebook ', '_' *45,'\n\n\n' > print 'Nick\t\tF.Name\t\tL.Name\t\tCity\t\t\tRegion\t\tTel' > print '_' * 105,'\n','\t' * 13 > for val in tbook.keys(): > print val, '\t\t', tbook[val][0], '\t', tbook[val][1], '\t', > tbook[val][2], '\t\t', tbook[val][3], '\t\t', tbook[val][4],'\t\t\n' > print '_'*105,'\n\n' > mmenu() > > def mmenu(): > while True: > choice = get_menu_choice() > if choice in tbook: > details(choice) > elif choice not in tbook: > print choice + 'Not in the book.' > mmenu() > elif choice =='Q' or choice =='q': > break > else: > print 'Selection {0} not understood.'.format(choice) ## This is > something that I don`t understand yet > > > def dmenu(choice): > while True: > choicem = get_menu_choice() > if choicem == 'e' or choicem == 'E': > edit(choice) > elif choicem == 'd' or choicem == 'D': > book = get_book_to_edit() > details( tbook, book ) > elif choicem =='Q' or choicem == 'q': > break # end loop to exit program > else: > print 'Selection {0} not understood.'.format( choicem ) > > listpb() > This was difficult, now I feel more confused it works, but I`m sure its not > the way you wanted :) You are correct it is not. :) You code is overly complex making it harder to understand. Try and reduce the problem to the least number of tasks you need. From the Zen of Python, "Simple is better than complex." It is a good programming mentality. 1. function that returns the loaded book def load_book(): load_book = open('c:/Python27/Toli/myfile.txt', 'r') load_book = eval(load_book.read()) return load_book! 2. A system to navigate your program. def mmenu(): # load tbook here while True: choicem = get_menu_choice() if choicem == 'e' or choicem == 'E': book = get_book_name() edit( tbook, book ) elif choicem == 'd' or choicem == 'D': book = get_book_name() details( tbook, book ) elif choicem =='Q' or choicem == 'q': break # end loop to exit program else: print 'Selection {0} not understood.'.format( choicem )I have given you more functions 3. function to write an edited book def write_book(tbook): write_book = open('c:/Python27/Toli/myfile.txt', 'w') write_book.write(str(tbook)) # I think repr would be more accurate than str here. 4. Function to print the entire book def listpb( tbook ): print '_' *45, ' Phonebook ', '_' *45,'\n\n\n' print 'Nick\t\tF.Name\t\tL.Name\t\tCity\t\t\tRegion\t\tTel' print '_' * 105,'\n','\t' * 13 for val in tbook.keys(): print val, '\t\t', tbook[val][0], '\t', tbook[val][1], '\t', tbook[val][2], '\t\t', tbook[val][3], '\t\t', tbook[val][4],'\t\t\n' print '_'*105,'\n\n' 5. Get input from user def get_menu_choice(): choice = raw_input('input: ') return choice 6. A function to get book name from user def get_book_name(tbook): # write this and do not use global 6. A function to print an entry from the book def details( tbook, choice ): # write this, no menu interaction allowed 7. A function to edit an entry from the book def edit( tbook, choice ): # write this, no menu interaction allowed # you can ask the user what you need to change the values I do not think you need any other functions. Now you just need to finsh all the functions and put it all together. Ramit Ramit Prasad | JPMorgan Chase Investment Bank | Currencies Technology 712 Main Street | Houston, TX 77002 work phone: 713 - 216 - 5423 -- This email is confidential and subject to important disclaimers and conditions including on offers for the purchase or sale of securities, accuracy and completeness of information, viruses, confidentiality, legal privilege, and legal entity disclaimers, available at http://www.jpmorgan.com/pages/disclosures/email. From ckaynor at zindagigames.com Tue Mar 27 18:40:04 2012 From: ckaynor at zindagigames.com (Chris Kaynor) Date: Tue, 27 Mar 2012 15:40:04 -0700 Subject: python segfault In-Reply-To: <20120327222757.GA22125@terra.cms.at> References: <20120327222757.GA22125@terra.cms.at> Message-ID: On Tue, Mar 27, 2012 at 3:27 PM, Michael Poeltl wrote: > hi, > > can anybody tell why this 'little stupid *thing* of code' let's python-3.2.2, 2.6.X or python 2.7.2 segfault? > >>> def get_steps2(pos=0, steps=0): > ... ? ? if steps == 0: > ... ? ? ? ? pos = random.randint(-1,1) > ... ? ? if pos == 0: > ... ? ? ? ? return steps > ... ? ? steps += 2 > ... ? ? pos += random.randint(-1,1) > ... ? ? return get_steps2(pos,steps) > ... >>>> import random, sys >>>> sys.setrecursionlimit(100000) If you remove this setrecursionlimit, it will throw an exception. The issue is that your code is overflowing the C stack by trying to make too many calls. The Python recursion limit prevents this by turning such cases into Python exceptions prior to the stack overflow. As your recursion is based on a random number generator, all you need is a sequence of random numbers that is unbalanced between -1 and 1 results for 1000-3000 calls (the exact number will vary from os, compiler, maybe machine, etc), which is not too unlikely to occur. From lists at cheimes.de Tue Mar 27 18:45:54 2012 From: lists at cheimes.de (Christian Heimes) Date: Wed, 28 Mar 2012 00:45:54 +0200 Subject: python segfault In-Reply-To: <20120327222757.GA22125@terra.cms.at> References: <20120327222757.GA22125@terra.cms.at> Message-ID: Am 28.03.2012 00:27, schrieb Michael Poeltl: > hi, > > can anybody tell why this 'little stupid *thing* of code' let's python-3.2.2, 2.6.X or python 2.7.2 segfault? The code segfaults because you have increased the recursion limit. The amount of recursions is limited by the stack size. A C program with a usually stack size can have about 4000 recursions. Python takes at least two stack levels for each recursion. The documentation http://docs.python.org/library/sys.html#sys.setrecursionlimit contains a warning, too. Christian From python.list at tim.thechases.com Tue Mar 27 19:32:05 2012 From: python.list at tim.thechases.com (Tim Chase) Date: Tue, 27 Mar 2012 18:32:05 -0500 Subject: Advise of programming one of my first programs In-Reply-To: References: <5B80DD153D7D744689F57F4FB69AF4740928C365@SCACMX008.exchad.jpmchase.net> <5B80DD153D7D744689F57F4FB69AF4740928E137@SCACMX008.exchad.jpmchase.net> <4F71E267.9050307@tim.thechases.com> Message-ID: <4F724DF5.7080703@tim.thechases.com> On 03/27/12 16:53, Anatoli Hristov wrote: > On Tue, Mar 27, 2012 at 5:53 PM, Tim Chase wrote: >>> On 03/27/12 10:32, Prasad, Ramit wrote: >>>> fileread = open('myfile.txt','r') >>>> tbook = eval(fileread.read()) >>>> fileread.close() >>> >>> >>> The use of eval is dangerous if you are not *completely* sure what is >>> being passed in. Try using pickle instead: >> >> Or, depending on the use, you might use ast.literal_eval() > > Thanks, but I`m still far from for dose details I thing:) [reordered to make the commenting inline instead of top-posted] To make it safer, just change eval(fileread.read()) to ast.literal_eval(fileread.read()) and insert "import ast" at the top of your script. -tkc From jeanpierreda at gmail.com Tue Mar 27 20:26:21 2012 From: jeanpierreda at gmail.com (Devin Jeanpierre) Date: Tue, 27 Mar 2012 20:26:21 -0400 Subject: Advise of programming one of my first programs In-Reply-To: <4F72385E.8020804@cs.wisc.edu> References: <5B80DD153D7D744689F57F4FB69AF4740928C365@SCACMX008.exchad.jpmchase.net> <5B80DD153D7D744689F57F4FB69AF4740928E137@SCACMX008.exchad.jpmchase.net> <4F72385E.8020804@cs.wisc.edu> Message-ID: On Tue, Mar 27, 2012 at 5:59 PM, Evan Driscoll wrote: >> The use of eval is dangerous if you are not *completely* sure what is >> being passed in. Try using pickle instead: >> http://docs.python.org/release/2.5.2/lib/pickle-example.html > > > Um, at least by my understanding, the use of Pickle is also dangerous if you > are not completely sure what is being passed in: Oh goodness yes. pickle is exactly as unsafe as eval is. Try running this code: from pickle import loads loads("c__builtin__\neval\n(c__builtin__\nraw_input\n(S'py>'\ntRtR.") -- Devin From goldtech at worldpost.com Tue Mar 27 20:51:37 2012 From: goldtech at worldpost.com (goldtech) Date: Tue, 27 Mar 2012 17:51:37 -0700 (PDT) Subject: Python Script Works Locally But Not Remotely with SSH Message-ID: <2750c67d-859f-46a3-ab00-a8a3da06cc4c@l14g2000vbe.googlegroups.com> Hi, I have a WinXP PC running an SSH server and I have a Linux PC with an SSH client and logged into the XP seemingly OK. It's all on my personal LAN, the connection seems OK. I have a py file on the XP that I run via SSH from the Linux, it's: import webbrowser webbrowser.open('www.google.com') This runs OK started on the local XP PC, the browser Firefox opens and goes to the site, or it opens a tab to the site. But executing that same file via SSH does not open Firefox...doing it via SSH starts Firefox ( I see it begin in the process manager and I see web activity) but Firefox does not open it's window. Why the does the window not open when the script is started remotely? Thanks. From tycho at tycho.ws Tue Mar 27 22:01:32 2012 From: tycho at tycho.ws (Tycho Andersen) Date: Tue, 27 Mar 2012 21:01:32 -0500 Subject: Generating a pkg config file with distutils Message-ID: <20120328020132.GH19106@smitten> Hi all, I'm distributing a package which for various legacy reasons needs to generate a pkgconfig file from a template (adding version numbers, prefixes, etc.) and install the file in the right place ($PREFIX/lib/pkgconfig/foo.pc in most cases). Currently, I have a rather nasty hack to implement all this, but presumably there's a better way to do it. If I could even get the installation part (e.g. using the right MANIFEST.in incantations), that would be wonderful. Reading the MANIFEST.in docs [1], it's not obvious that you can control the install locations of these files (i.e., .pc files must be installed to the above location to be correctly detected by other packages). Is what I want to do possible, or should I continue using my nasty hack? TIA! Tycho [1]: http://docs.python.org/distutils/sourcedist.html#commands From d at davea.name Tue Mar 27 22:38:11 2012 From: d at davea.name (Dave Angel) Date: Tue, 27 Mar 2012 22:38:11 -0400 Subject: python segfault In-Reply-To: <20120327222757.GA22125@terra.cms.at> References: <20120327222757.GA22125@terra.cms.at> Message-ID: <4F727993.3070801@davea.name> On 03/27/2012 06:27 PM, Michael Poeltl wrote: > hi, > > can anybody tell why this 'little stupid *thing* of code' let's python-3.2.2, 2.6.X or python 2.7.2 segfault? > >>> def get_steps2(pos=0, steps=0): > ... if steps == 0: > ... pos = random.randint(-1,1) > ... if pos == 0: > ... return steps > ... steps += 2 > ... pos += random.randint(-1,1) > ... return get_steps2(pos,steps) > ... > > 0 > 2 > 8 > 0 > Segmentation fault > ?> > > funny, isn't it? > I was able to reproduce this segfault on various machines (32bit 64bit), ubuntu, slackware, debian > python.X segfaults on all of them > > thx > Michael Others have explained why you can't just raise the recursion limit to arbitrarily large values, and why there's no particular bound on the possible recursion size. But the real question is why you don't do the completely trivial conversion to a non-recursive equivalent. All you need do is add a while True: to the beginning of the function, and remove the return statement. -- DaveA From skippy.hammond at gmail.com Tue Mar 27 23:42:25 2012 From: skippy.hammond at gmail.com (Mark Hammond) Date: Wed, 28 Mar 2012 14:42:25 +1100 Subject: OAuth 2.0 implementation In-Reply-To: References: <1973354.3.1332816158529.JavaMail.geo-discussion-forums@pbae2> <87haxahh51.fsf@benfinney.id.au> <878vimhfdp.fsf@benfinney.id.au> <87zkb2fz7g.fsf@benfinney.id.au> <7909491.0.1332826232743.JavaMail.geo-discussion-forums@pbim5> Message-ID: <4F7288A1.3060601@gmail.com> On 28/03/2012 1:18 AM, Roy Smith wrote: > In article > <7909491.0.1332826232743.JavaMail.geo-discussion-forums at pbim5>, > Demian Brecht wrote: > >> OAuth 2.0 is still in draft status (draft 25 is the current one I believe) >> and yes, unfortunately every single server available at this point have >> varying degrees of separation from the actual spec. It's not a >> pseudo-standard, it's just not observed to the letter. Google is the closest >> and Facebook seems to be the farthest away (Stack Exchange is in close second >> due to building theirs to work like Facebook's). > > In practice, OAuth is all about getting your site to work with Facebook. > That is all most web sites care about today because that's where the > money is. The fact that other sites also use OAuth is of mostly > academic interest at this point. > > The next player on the list is Twitter, and they're not even up to using > their own incompatible version of OAuth 2.0. They're still using OAuth > 1.0 (although, I understand, they're marching towards 2.0). Almost all "social" or "sharing" sites implement OAuth - either 1.0 or 2.0. Facebook is clearly the big winner here but not the only player. It's also used extensively by google (eg, even their SMTP server supports using OAuth credentials to send email) I'd go even further - most sites which expose an API use OAuth for credentials with that API. Mark From michael.poeltl at univie.ac.at Wed Mar 28 02:16:50 2012 From: michael.poeltl at univie.ac.at (Michael Poeltl) Date: Wed, 28 Mar 2012 08:16:50 +0200 Subject: python segfault In-Reply-To: <4F727993.3070801@davea.name> References: <20120327222757.GA22125@terra.cms.at> <4F727993.3070801@davea.name> Message-ID: <20120328061650.GB26962@terra.cms.at> hi, * Dave Angel [2012-03-28 04:38]: > On 03/27/2012 06:27 PM, Michael Poeltl wrote: > >hi, > > > >can anybody tell why this 'little stupid *thing* of code' let's python-3.2.2, 2.6.X or python 2.7.2 segfault? > > > >>>def get_steps2(pos=0, steps=0): > >... if steps == 0: > >... pos = random.randint(-1,1) > >... if pos == 0: > >... return steps > >... steps += 2 > >... pos += random.randint(-1,1) > >... return get_steps2(pos,steps) > >... > > > >0 > >2 > >8 > >0 > >Segmentation fault > >?> > > > >funny, isn't it? > >I was able to reproduce this segfault on various machines (32bit 64bit), ubuntu, slackware, debian > >python.X segfaults on all of them > > > >thx > >Michael > > Others have explained why you can't just raise the recursion limit > to arbitrarily large values, and why there's no particular bound on > the possible recursion size. But the real question is why you don't > do the completely trivial conversion to a non-recursive equivalent. > > All you need do is add a while True: to the beginning of the > function, and remove the return statement. yeah - of course 'while True' was the first, most obvious best way... ;-) but I was asked if there was a way without 'while True' and so I started the 'recursive function' and quick quick; RuntimeError-Exception -> not thinking much -> just adding two zeros to the default limit (quick and dirty) -> segfault ==> subject: python segfault ;-) and that was my first time that I received a segfault and not an Exception NOW it's quite clear ;-) thank you! Michael > > > > -- > > DaveA > -- Michael Poeltl Computational Materials Physics voice: +43-1-4277-51409 Univ. Wien, Sensengasse 8/12 fax: +43-1-4277-9514 (or 9513) A-1090 Wien, AUSTRIA cmp.mpi.univie.ac.at ------------------------------------------------------------------------------- ubuntu-11.10 | vim-7.3 | python-3.2.2 | mutt-1.5.21 | elinks-0.12 ------------------------------------------------------------------------------- From gelonida at gmail.com Wed Mar 28 03:31:09 2012 From: gelonida at gmail.com (Gelonida N) Date: Wed, 28 Mar 2012 09:31:09 +0200 Subject: best way to create warning for obsolete functions and call new one In-Reply-To: <20120326172440.4705444d@particle> References: <20120326172440.4705444d@particle> Message-ID: Hi Dan, On 03/26/2012 11:24 PM, Dan Sommers wrote: > On Mon, 26 Mar 2012 22:26:11 +0200 > Gelonida N wrote: > >> As these modules are used by quite some projects and as I do not want >> to force everybody to rename immediately I just want to warn users, >> that they call functions, that have been renamed and that will be >> obsoleted. > > You want a DeprecationWarning. Yes, this is a good idea. In my case I had to combine it with logging.captureWarnings() From gelonida at gmail.com Wed Mar 28 03:51:52 2012 From: gelonida at gmail.com (Gelonida N) Date: Wed, 28 Mar 2012 09:51:52 +0200 Subject: best way to create warning for obsolete functions and call new one In-Reply-To: References: Message-ID: Hi Chris, On 03/26/2012 11:50 PM, Chris Angelico wrote: > On Tue, Mar 27, 2012 at 7:26 AM, Gelonida N wrote: >> One option I though of would be: >> >> def obsolete_func(func): >> def call_old(*args, **kwargs): >> print "func is old psl use new one" >> return func(*args, **kwargs) >> return call_old >> >> and >> >> def get_time(a='high'): >> return a + 'noon' > > That's a reasonable idea. Incorporate Dan's suggestion of using > DeprecationWarning. > Will do that. > You may want to try decorator syntax: > > def was(oldname): > def _(func): > globals()[oldname]=func > return func > return _ > > @was("get_thyme") > def get_time(a='high'): > return a + 'noon' > > That won't raise DeprecationWarning, though. It's a very simple > assignment. The was() internal function could be enhanced to do a bit > more work, but I'm not sure what version of Python you're using and > what introspection facilities you have. But if you're happy with the > old versions coming up with (*args,**kwargs) instead of their > parameter lists, it's not difficult: I'm using python 2.6 and sometimes still 2.5 (the latter is not important for this question though) Good idea about the decorators. I overlooked to see, that if done properly a decorator will not add call time overhead for calling the function with it's new name > > def was(oldname): > def _(func): > def bounce(*args,**kwargs): > # raise DeprecationWarning > return func(*args,**kwargs) > globals()[oldname]=bounce > return func > return _ > > I've never actually used the Python warnings module, but any line of > code you fill in at the comment will be executed any time the old name > is used. In any case, it's still used with the same convenient > decorator. You could even unify multiple functions under a single new > name: > > @was("foo") > @was("bar") > def quux(spam,ham): > return ham.eat() > Now the next step will do write a decorator working for class methods. I think I have a solution, but it would require to pass the class as additional parameter to each decorator. it would be setattr(cls, oldname, finc) > Hope that helps! It does. Thanks again. From gator at cs.tu-berlin.de Wed Mar 28 04:56:20 2012 From: gator at cs.tu-berlin.de (Peter Daum) Date: Wed, 28 Mar 2012 10:56:20 +0200 Subject: "convert" string to bytes without changing data (encoding) Message-ID: <9tg21lFmo3U1@mid.dfncis.de> Hi, is there any way to convert a string to bytes without interpreting the data in any way? Something like: s='abcde' b=bytes(s, "unchanged") Regards, Peter From rosuav at gmail.com Wed Mar 28 05:02:42 2012 From: rosuav at gmail.com (Chris Angelico) Date: Wed, 28 Mar 2012 20:02:42 +1100 Subject: "convert" string to bytes without changing data (encoding) In-Reply-To: <9tg21lFmo3U1@mid.dfncis.de> References: <9tg21lFmo3U1@mid.dfncis.de> Message-ID: On Wed, Mar 28, 2012 at 7:56 PM, Peter Daum wrote: > Hi, > > is there any way to convert a string to bytes without > interpreting the data in any way? Something like: > > s='abcde' > b=bytes(s, "unchanged") What is a string? It's not a series of bytes. You can't convert it without encoding those characters into bytes in some way. ChrisA From stefan_ml at behnel.de Wed Mar 28 05:08:24 2012 From: stefan_ml at behnel.de (Stefan Behnel) Date: Wed, 28 Mar 2012 11:08:24 +0200 Subject: "convert" string to bytes without changing data (encoding) In-Reply-To: <9tg21lFmo3U1@mid.dfncis.de> References: <9tg21lFmo3U1@mid.dfncis.de> Message-ID: Peter Daum, 28.03.2012 10:56: > is there any way to convert a string to bytes without > interpreting the data in any way? Something like: > > s='abcde' > b=bytes(s, "unchanged") If you can tell us what you actually want to achieve, i.e. why you want to do this, we may be able to tell you how to do what you want. Stefan From jabba.laci at gmail.com Wed Mar 28 05:31:21 2012 From: jabba.laci at gmail.com (Jabba Laci) Date: Wed, 28 Mar 2012 11:31:21 +0200 Subject: question about file handling with "with" Message-ID: Hi, Is the following function correct? Is the input file closed in order? def read_data_file(self): with open(self.data_file) as f: return json.loads(f.read()) Thanks, Laszlo From gator at cs.tu-berlin.de Wed Mar 28 05:43:52 2012 From: gator at cs.tu-berlin.de (Peter Daum) Date: Wed, 28 Mar 2012 11:43:52 +0200 Subject: "convert" string to bytes without changing data (encoding) In-Reply-To: References: <9tg21lFmo3U1@mid.dfncis.de> Message-ID: <9tg4qoFbfpU1@mid.dfncis.de> On 2012-03-28 11:02, Chris Angelico wrote: > On Wed, Mar 28, 2012 at 7:56 PM, Peter Daum wrote: >> is there any way to convert a string to bytes without >> interpreting the data in any way? Something like: >> >> s='abcde' >> b=bytes(s, "unchanged") > > What is a string? It's not a series of bytes. You can't convert it > without encoding those characters into bytes in some way. ... in my example, the variable s points to a "string", i.e. a series of bytes, (0x61,0x62 ...) interpreted as ascii/unicode characters. b=bytes(s,'ascii') # or ('utf-8', 'latin1', ...) would of course work in this case, but in general, if s holds any data with bytes > 127, the actual data will be changed according to the provided encoding. What I am looking for is a general way to just copy the raw data from a "string" object to a "byte" object without any attempt to "decode" or "encode" anything ... Regards, Peter From __peter__ at web.de Wed Mar 28 05:59:20 2012 From: __peter__ at web.de (Peter Otten) Date: Wed, 28 Mar 2012 11:59:20 +0200 Subject: question about file handling with "with" References: Message-ID: Jabba Laci wrote: > Is the following function correct? Yes, though I'd use json.load(f) instead of json.loads(). > Is the input file closed in order? > > def read_data_file(self): > with open(self.data_file) as f: > return json.loads(f.read()) The file will be closed when the with-block is left. That is before read_data_file() returns, even in a Python implementation that doesn't use ref-counting. Think of with open(...) as f: # whatever as roughly equivalent to f = open(...) try: # whatever finally: f.close() See the "specification" section of http://www.python.org/dev/peps/pep-0343/ for the gory details. From modelnine at modelnine.org Wed Mar 28 06:42:43 2012 From: modelnine at modelnine.org (Heiko Wundram) Date: Wed, 28 Mar 2012 12:42:43 +0200 Subject: "convert" string to bytes without changing data (encoding) In-Reply-To: <9tg4qoFbfpU1@mid.dfncis.de> References: <9tg21lFmo3U1@mid.dfncis.de> <9tg4qoFbfpU1@mid.dfncis.de> Message-ID: <20b9abb6232b89a0409111b449c986d6@modelnine.org> Am 28.03.2012 11:43, schrieb Peter Daum: > ... in my example, the variable s points to a "string", i.e. a series > of > bytes, (0x61,0x62 ...) interpreted as ascii/unicode characters. No; a string contains a series of codepoints from the unicode plane, representing natural language characters (at least in the simplistic view, I'm not talking about surrogates). These can be encoded to different binary storage representations, of which ascii is (a common) one. > What I am looking for is a general way to just copy the raw data > from a "string" object to a "byte" object without any attempt to > "decode" or "encode" anything ... There is "logically" no raw data in the string, just a series of codepoints, as stated above. You'll have to specify the encoding to use to get at "raw" data, and from what I gather you're interested in the latin-1 (or iso-8859-15) encoding, as you're specifically referencing chars >= 0x80 (which hints at your mindset being in LATIN-land, so to speak). -- --- Heiko. From emiley at techiesplatform.com Wed Mar 28 07:15:00 2012 From: emiley at techiesplatform.com (Emiley Bradley) Date: Wed, 28 Mar 2012 04:15:00 -0700 (PDT) Subject: Online SharePoint 2010 training sessions for end users with 12 Hours and $415 per person from 6th April 2012 Message-ID: <5c11b820-24f0-48aa-a91a-a04b314f60db@t2g2000pbg.googlegroups.com> Greetings, Techies Platform?s training programs are essential to anyone in Information Management. With Techies Platform, you will experience rich content and an environment that is interesting, up-to-date, and engaging. Our instructors, materials, and in lab sessions are there to help build on your determination and drive to succeed. When you partner with Techies Platform, you?ll find that our training program meets and exceeds your expectations. You can visit our website www.techiesplatform.com and check out on the wide training curriculum we offer. We are happy to answer any questions you may have about our firm. We are launching our Online SharePoint 2010 training sessions for end users with 12 Hours and $415 per person from 6th April 2012. We present our training sessions as an on-site offering at your work location or home. We can customize this training program to suit your precise training needs. Feel free to contact us any time on the following email. info at techiesplatform.com emiley at techiesplatform.com Regards, Emiley Bradley Training Coordinator Techies Platform emiley at techiesplatform.com www.techiesplatform.com From stefan_ml at behnel.de Wed Mar 28 07:25:33 2012 From: stefan_ml at behnel.de (Stefan Behnel) Date: Wed, 28 Mar 2012 13:25:33 +0200 Subject: "convert" string to bytes without changing data (encoding) In-Reply-To: <9tg4qoFbfpU1@mid.dfncis.de> References: <9tg21lFmo3U1@mid.dfncis.de> <9tg4qoFbfpU1@mid.dfncis.de> Message-ID: Peter Daum, 28.03.2012 11:43: > What I am looking for is a general way to just copy the raw data > from a "string" object to a "byte" object without any attempt to > "decode" or "encode" anything ... That's why I asked about your use case - where does the data come from and why is it contained in a character string in the first place? If you could provide that information, we can help you further. Stefan From luch at ank-sia.com Wed Mar 28 07:50:17 2012 From: luch at ank-sia.com (Alexey Luchko) Date: Wed, 28 Mar 2012 14:50:17 +0300 Subject: errors building python 2.7.3 Message-ID: <4F72FAF9.8000802@ank-sia.com> Hi! I've tried to build Python 2.7.3rc2 on cygwin and got the following errors: $ CFLAGS=-I/usr/include/ncursesw/ CPPFLAGS=-I/usr/include/ncursesw/ ./configure $ make ... gcc -shared -Wl,--enable-auto-image-base build/temp.cygwin-1.7.11-i686-2.7/Python-2.7.3rc2/Modules/_io/bufferedio.o build/temp.cygwin-1.7.11-i686-2.7/Python-2.7.3rc2/Modules/_io/bytesio.o build/temp.cygwin-1.7.11-i686-2.7/Python-2.7.3rc2/Modules/_io/fileio.o build/temp.cygwin-1.7.11-i686-2.7/Python-2.7.3rc2/Modules/_io/iobase.o build/temp.cygwin-1.7.11-i686-2.7/Python-2.7.3rc2/Modules/_io/_iomodule.o build/temp.cygwin-1.7.11-i686-2.7/Python-2.7.3rc2/Modules/_io/stringio.o build/temp.cygwin-1.7.11-i686-2.7/Python-2.7.3rc2/Modules/_io/textio.o -L/usr/local/lib -L. -lpython2.7 -o build/lib.cygwin-1.7.11-i686-2.7/_io.dll build/temp.cygwin-1.7.11-i686-2.7/Python-2.7.3rc2/Modules/_io/bufferedio.o: In function `_set_BlockingIOError': /Python-2.7.3rc2/Modules/_io/bufferedio.c:579: undefined reference to `__imp__PyExc_BlockingIOError' /Python-2.7.3rc2/Modules/_io/bufferedio.c:579: undefined reference to `__imp__PyExc_BlockingIOError' build/temp.cygwin-1.7.11-i686-2.7/Python-2.7.3rc2/Modules/_io/bufferedio.o: In function `_buffered_check_blocking_error': /Python-2.7.3rc2/Modules/_io/bufferedio.c:595: undefined reference to `__imp__PyExc_BlockingIOError' collect2: ld returned 1 exit status building '_curses' extension gcc -fno-strict-aliasing -I/usr/include/ncursesw/ -DNDEBUG -g -fwrapv -O3 -Wall -Wstrict-prototypes -I. -IInclude -I./Include -I/usr/include/ncursesw/ -I/Python-2.7.3rc2/Include -I/Python-2.7.3rc2 -c /Python-2.7.3rc2/Modules/_cursesmodule.c -o build/temp.cygwin-1.7.11-i686-2.7/Python-2.7.3rc2/Modules/_cursesmodule.o /Python-2.7.3rc2/Modules/_cursesmodule.c: In function ?PyCursesWindow_EchoChar?: /Python-2.7.3rc2/Modules/_cursesmodule.c:810:18: error: dereferencing pointer to incomplete type /Python-2.7.3rc2/Modules/_cursesmodule.c: In function ?PyCursesWindow_NoOutRefresh?: /Python-2.7.3rc2/Modules/_cursesmodule.c:1238:22: error: dereferencing pointer to incomplete type /Python-2.7.3rc2/Modules/_cursesmodule.c: In function ?PyCursesWindow_Refresh?: /Python-2.7.3rc2/Modules/_cursesmodule.c:1381:22: error: dereferencing pointer to incomplete type /Python-2.7.3rc2/Modules/_cursesmodule.c: In function ?PyCursesWindow_SubWin?: /Python-2.7.3rc2/Modules/_cursesmodule.c:1448:18: error: dereferencing pointer to incomplete type /Python-2.7.3rc2/Modules/_cursesmodule.c: In function ?PyCursesWindow_Refresh?: /Python-2.7.3rc2/Modules/_cursesmodule.c:1412:1: warning: control reaches end of non-void function /Python-2.7.3rc2/Modules/_cursesmodule.c: In function ?PyCursesWindow_NoOutRefresh?: /Python-2.7.3rc2/Modules/_cursesmodule.c:1270:1: warning: control reaches end of non-void function /Python-2.7.3rc2/Modules/_cursesmodule.c: In function ?PyCursesWindow_EchoChar?: /Python-2.7.3rc2/Modules/_cursesmodule.c:817:1: warning: control reaches end of non-void function ... Failed to build these modules: _curses _io Then tried to see if the problem is sovled, fetched the source from https://bitbucket.org/python_mirrors/releasing-2.7.3 and got another one: $ CFLAGS=-I/usr/include/ncursesw/ CPPFLAGS=-I/usr/include/ncursesw/ ./configure $ make gcc -Wno-unused-result -DNDEBUG -g -fwrapv -O3 -Wall -Wstrict-prototypes -I/usr/include/ncursesw/ -I. -I./Include -I/usr/include/ncursesw/ -DPy_BUILD_CORE -c ./Modules/signalmodule.c -o Modules/signalmodule.o ./Modules/signalmodule.c: In function ?fill_siginfo?: ./Modules/signalmodule.c:734:5: error: ?siginfo_t? has no member named ?si_band? Makefile:1456: recipe for target `Modules/signalmodule.o' failed make: *** [Modules/signalmodule.o] Error 1 Reporting here, because bugs.python.org refuses connections currently. Just in case CYGWIN_NT-6.1-WOW64 ... 1.7.11(0.260/5/3) 2012-02-24 14:05 i686 Cygwin gcc version 4.5.3 (GCC) -- Alex From alicjakrzyz87 at wp.pl Wed Mar 28 07:55:01 2012 From: alicjakrzyz87 at wp.pl (=?ISO-8859-2?Q?Alicja_Krzy=BFanowska?=) Date: Wed, 28 Mar 2012 13:55:01 +0200 Subject: Work Message-ID: <4f72fc15b31fd1.16956611@wp.pl> An HTML attachment was scrubbed... URL: From ulrich.eckhardt at dominolaser.com Wed Mar 28 08:28:08 2012 From: ulrich.eckhardt at dominolaser.com (Ulrich Eckhardt) Date: Wed, 28 Mar 2012 14:28:08 +0200 Subject: unittest: assertRaises() with an instance instead of a type Message-ID: Hi! I'm currently writing some tests for the error handling of some code. In this scenario, I must make sure that both the correct exception is raised and that the contained error code is correct: try: foo() self.fail('exception not raised') catch MyException as e: self.assertEqual(e.errorcode, SOME_FOO_ERROR) catch Exception: self.fail('unexpected exception raised') This is tedious to write and read. The docs mention this alternative: with self.assertRaises(MyException) as cm: foo() self.assertEqual(cm.the_exception.errorcode, SOME_FOO_ERROR) This is shorter, but I think there's an alternative syntax possible that would be even better: with self.assertRaises(MyException(SOME_FOO_ERROR)): foo() Here, assertRaises() is not called with an exception type but with an exception instance. I'd implement it something like this: def assertRaises(self, exception, ...): # divide input parameter into type and instance if isinstance(exception, Exception): exception_type = type(exception) else: exception_type = exception exception = None # call testee and verify results try: ...call function here... except exception_type as e: if not exception is None: self.assertEqual(e, exception) This of course requires the exception to be equality-comparable. Questions here: 1. Does this sound like a useful extension or am I missing another obvious solution to my problem? 2. The assertRaises() sketch above tries to auto-detect whether the given parameter is the type or an instance. Given the highly dynamic nature of Python, an object can be both instance and type, is the above detection mechanism reliable? Of course I'm open for other suggestions to solve my problem. One that I thought of but which I haven't really looked into was to modify __init__ or __new__ of my exception class to return an instance of a derived class that uniquely identifies the error. I.e. MyException(SOME_FOO_ERROR) would not create a MyException instance but a MyFooErrorException instance (which has MyException as a baseclass). In that case, the existing code that checks for the right exception type would suffice for my needs. Cheers everybody! Uli From ksaktheeswari94 at gmail.com Wed Mar 28 09:24:33 2012 From: ksaktheeswari94 at gmail.com (saktheeswari k) Date: Wed, 28 Mar 2012 06:24:33 -0700 (PDT) Subject: comp.lang.python Message-ID: <179a71c1-0ef7-44bb-9e42-28de72c1a55b@oq7g2000pbb.googlegroups.com> http://123maza.com/46/glory248/ Increased interestingness of extraneous details in a multimedia science presentation leads to decreased learning. Mayer RE, Griffith E, Jurkowitz IT, Rothman D. From nadirsampaoli at gmail.com Wed Mar 28 09:50:56 2012 From: nadirsampaoli at gmail.com (Nadir Sampaoli) Date: Wed, 28 Mar 2012 15:50:56 +0200 Subject: Difference between json.load() and json.loads() [From: RE: question about file handling with "with"] Message-ID: Hello everyone (my first message in the mailing list), > > Is the following function correct? > Yes, though I'd use json.load(f) instead of json.loads(). > The docs aren't very clear (at least for me) about the difference between json.load() and json.loads (and about "dump()" and "dumps()" too"). Could you clarify it for me? Thanks in advance. -------------- next part -------------- An HTML attachment was scrubbed... URL: From kiuhnm03.4t.yahoo.it Wed Mar 28 09:59:31 2012 From: kiuhnm03.4t.yahoo.it (Kiuhnm) Date: Wed, 28 Mar 2012 15:59:31 +0200 Subject: python segfault In-Reply-To: References: <20120327222757.GA22125@terra.cms.at> <4F727993.3070801@davea.name> Message-ID: <4f731942$0$1375$4fafbaef@reader1.news.tin.it> On 3/28/2012 8:16, Michael Poeltl wrote: > yeah - of course 'while True' was the first, most obvious best way... ;-) > but I was asked if there was a way without 'while True' > and so I started the 'recursive function' > > and quick quick; RuntimeError-Exception -> not thinking much -> just adding > two zeros to the default limit (quick and dirty) -> segfault ==> subject: python segfault ;-) You give up too easily! Here's another way: ---> def get_steps2(pos=0, steps=0, level = 100): if steps == 0: pos = random.randint(-1,1) if pos == 0: return steps steps += 2 pos += random.randint(-1,1) if level == 0: return (pos, steps) res = get_steps2(pos,steps, level-1) if not isinstance(res, tuple): return res return get_steps2(res[0], res[1], level-1) import random for i in range(200): print ( get_steps2() ) print("done") input("") <--- Now the limit is 1267650600228229401496703205376. I hope that's enough. Kiuhnm From ian.douglas at iandouglas.com Wed Mar 28 09:59:56 2012 From: ian.douglas at iandouglas.com (ian douglas) Date: Wed, 28 Mar 2012 06:59:56 -0700 Subject: Difference between json.load() and json.loads() [From: RE: question about file handling with "with"] In-Reply-To: References: Message-ID: On Mar 28, 2012 6:54 AM, "Nadir Sampaoli" wrote: > > Hello everyone (my first message in the mailing list), > >> >> > Is the following function correct? >> Yes, though I'd use json.load(f) instead of json.loads(). > > > The docs aren't very clear (at least for me) about the difference between json.load() and json.loads (and about "dump()" and "dumps()" too"). Could you clarify it for me? > The functions with an s take string parameters. The others take file streams. foo = '{"age": 38}' my_json = json.loads(foo) -------------- next part -------------- An HTML attachment was scrubbed... URL: From nadirsampaoli at gmail.com Wed Mar 28 10:03:36 2012 From: nadirsampaoli at gmail.com (Nadir Sampaoli) Date: Wed, 28 Mar 2012 16:03:36 +0200 Subject: Difference between json.load() and json.loads() [From: RE: question about file handling with "with"] In-Reply-To: References: Message-ID: 2012/3/28 ian douglas > > The functions with an s take string parameters. The others take file > streams. > > foo = '{"age": 38}' > my_json = json.loads(foo) > I see, it makes perfectly sense now. Thanks for clearing it up. -------------- next part -------------- An HTML attachment was scrubbed... URL: From luch at ank-sia.com Wed Mar 28 10:39:35 2012 From: luch at ank-sia.com (Alexey Luchko) Date: Wed, 28 Mar 2012 17:39:35 +0300 Subject: errors building python 2.7.3 In-Reply-To: <4F72FAF9.8000802@ank-sia.com> References: <4F72FAF9.8000802@ank-sia.com> Message-ID: <4F7322A7.2040301@ank-sia.com> On 28.03.2012 14:50, Alexey Luchko wrote: > Hi! > > I've tried to build Python 2.7.3rc2 on cygwin and got the following errors: > > $ CFLAGS=-I/usr/include/ncursesw/ CPPFLAGS=-I/usr/include/ncursesw/ > ./configure > $ make > ... > gcc -shared -Wl,--enable-auto-image-base > build/temp.cygwin-1.7.11-i686-2.7/Python-2.7.3rc2/Modules/_io/bufferedio.o > build/temp.cygwin-1.7.11-i686-2.7/Python-2.7.3rc2/Modules/_io/bytesio.o > build/temp.cygwin-1.7.11-i686-2.7/Python-2.7.3rc2/Modules/_io/fileio.o > build/temp.cygwin-1.7.11-i686-2.7/Python-2.7.3rc2/Modules/_io/iobase.o > build/temp.cygwin-1.7.11-i686-2.7/Python-2.7.3rc2/Modules/_io/_iomodule.o > build/temp.cygwin-1.7.11-i686-2.7/Python-2.7.3rc2/Modules/_io/stringio.o > build/temp.cygwin-1.7.11-i686-2.7/Python-2.7.3rc2/Modules/_io/textio.o > -L/usr/local/lib -L. -lpython2.7 -o build/lib.cygwin-1.7.11-i686-2.7/_io.dll > build/temp.cygwin-1.7.11-i686-2.7/Python-2.7.3rc2/Modules/_io/bufferedio.o: > In function `_set_BlockingIOError': > /Python-2.7.3rc2/Modules/_io/bufferedio.c:579: undefined reference to > `__imp__PyExc_BlockingIOError' > /Python-2.7.3rc2/Modules/_io/bufferedio.c:579: undefined reference to > `__imp__PyExc_BlockingIOError' > build/temp.cygwin-1.7.11-i686-2.7/Python-2.7.3rc2/Modules/_io/bufferedio.o: > In function `_buffered_check_blocking_error': > /Python-2.7.3rc2/Modules/_io/bufferedio.c:595: undefined reference to > `__imp__PyExc_BlockingIOError' > collect2: ld returned 1 exit status > > building '_curses' extension > gcc -fno-strict-aliasing -I/usr/include/ncursesw/ -DNDEBUG -g -fwrapv -O3 > -Wall -Wstrict-prototypes -I. -IInclude -I./Include > -I/usr/include/ncursesw/ -I/Python-2.7.3rc2/Include -I/Python-2.7.3rc2 -c > /Python-2.7.3rc2/Modules/_cursesmodule.c -o > build/temp.cygwin-1.7.11-i686-2.7/Python-2.7.3rc2/Modules/_cursesmodule.o > /Python-2.7.3rc2/Modules/_cursesmodule.c: In function > ?PyCursesWindow_EchoChar?: > /Python-2.7.3rc2/Modules/_cursesmodule.c:810:18: error: dereferencing > pointer to incomplete type > /Python-2.7.3rc2/Modules/_cursesmodule.c: In function > ?PyCursesWindow_NoOutRefresh?: > /Python-2.7.3rc2/Modules/_cursesmodule.c:1238:22: error: dereferencing > pointer to incomplete type > /Python-2.7.3rc2/Modules/_cursesmodule.c: In function > ?PyCursesWindow_Refresh?: > /Python-2.7.3rc2/Modules/_cursesmodule.c:1381:22: error: dereferencing > pointer to incomplete type > /Python-2.7.3rc2/Modules/_cursesmodule.c: In function ?PyCursesWindow_SubWin?: > /Python-2.7.3rc2/Modules/_cursesmodule.c:1448:18: error: dereferencing > pointer to incomplete type > /Python-2.7.3rc2/Modules/_cursesmodule.c: In function > ?PyCursesWindow_Refresh?: > /Python-2.7.3rc2/Modules/_cursesmodule.c:1412:1: warning: control reaches > end of non-void function > /Python-2.7.3rc2/Modules/_cursesmodule.c: In function > ?PyCursesWindow_NoOutRefresh?: > /Python-2.7.3rc2/Modules/_cursesmodule.c:1270:1: warning: control reaches > end of non-void function > /Python-2.7.3rc2/Modules/_cursesmodule.c: In function > ?PyCursesWindow_EchoChar?: > /Python-2.7.3rc2/Modules/_cursesmodule.c:817:1: warning: control reaches > end of non-void function > > ... > > Failed to build these modules: > _curses _io The same happens with Python 2.7.2. > CYGWIN_NT-6.1-WOW64 ... 1.7.11(0.260/5/3) 2012-02-24 14:05 i686 Cygwin > gcc version 4.5.3 (GCC) -- Alex From ramit.prasad at jpmorgan.com Wed Mar 28 10:57:48 2012 From: ramit.prasad at jpmorgan.com (Prasad, Ramit) Date: Wed, 28 Mar 2012 14:57:48 +0000 Subject: Advise of programming one of my first programs In-Reply-To: References: <5B80DD153D7D744689F57F4FB69AF4740928C365@SCACMX008.exchad.jpmchase.net> <5B80DD153D7D744689F57F4FB69AF4740928E137@SCACMX008.exchad.jpmchase.net> <4F72385E.8020804@cs.wisc.edu> Message-ID: <5B80DD153D7D744689F57F4FB69AF4740929109C@SCACMX008.exchad.jpmchase.net> > >> The use of eval is dangerous if you are not *completely* sure what is > >> being passed in. Try using pickle instead: > >> http://docs.python.org/release/2.5.2/lib/pickle-example.html > > > > > > Um, at least by my understanding, the use of Pickle is also dangerous if > you > > are not completely sure what is being passed in: > > Oh goodness yes. pickle is exactly as unsafe as eval is. Try running this > code: > > from pickle import loads > loads("c__builtin__\neval\n(c__builtin__\nraw_input\n(S'py>'\ntRtR.") It might be as dangerous, but which is more likely to cause problems in real world scenarios? Ramit Ramit Prasad | JPMorgan Chase Investment Bank | Currencies Technology 712 Main Street | Houston, TX 77002 work phone: 713 - 216 - 5423 -- This email is confidential and subject to important disclaimers and conditions including on offers for the purchase or sale of securities, accuracy and completeness of information, viruses, confidentiality, legal privilege, and legal entity disclaimers, available at http://www.jpmorgan.com/pages/disclosures/email. From steveo at syslang.net Wed Mar 28 11:03:28 2012 From: steveo at syslang.net (Steven W. Orr) Date: Wed, 28 Mar 2012 11:03:28 -0400 Subject: Question about collections.defaultdict In-Reply-To: References: <4F707028.4000407@syslang.net> <4F708C4C.5050700@syslang.net> Message-ID: <4F732840.6050105@syslang.net> On 3/26/2012 11:52 AM, Robert Kern wrote: > On 3/26/12 4:33 PM, Steven W. Orr wrote: >> On 3/26/2012 9:44 AM, Robert Kern wrote: >>> On 3/26/12 2:33 PM, Steven W. Orr wrote: >>>> I created a new class called CaseInsensitiveDict (by stealing from code I >>>> found >>>> on the web, thank you very much). The new class inherits from dict. It >>>> makes it >>>> so that if the key has a 'lower' method, it will always access the key using >>>> lower >>>> >>>> I'd like to change the place where I previously declared a dict >>>> >>>> self.lookup = defaultdict(list) >>>> >>>> so that the new code will allow this new dict to be used instead. But then I >>>> realized I may have painted myself into a small corner: >>>> >>>> Is there a way to use defaultdict so that I can override what *kind* of >>>> dict it >>>> will use? >>> >>> No. >>> >>>> I would like the value to still be a list be default, but it seems like I >>>> can't >>>> tell defaultdict to use *my* new dict. >>>> >>>> Do I give up on defaultdict? >>> >>> Assuming that your CaseInsensitiveDict subclasses from dict or UserDict, it's >>> relatively easy to make a subclass of your CaseInsensitiveDict act like a >>> defaultdict. Just implement the __missing__(key) method appropriately (and >>> modify the constructor to take the callable, of course). >>> >>> http://docs.python.org/library/stdtypes.html#dict >>> http://docs.python.org/library/collections.html#collections.defaultdict.__missing__ >>> >>> >>> >>> >> >> I'm not quite getting what you're telling me, but I'm sure you have the right >> idea. Here's the beginning of my class: >> >> class CaseInsensitiveDict(dict): >> def __init__(self, init=None): >> if isinstance(init, (dict, list, tuple)): >> for kk, vv in init.items(): >> self[self.key_has_lower(kk)] = vv >> >> >> It sounds like you want me to subclass defaultdict to create something like >> this? >> >> class CaseInsensitiveDictDef(defaultdict): >> def __init__(self, init=None): >> super(CaseInsensitiveDictDef, self).__init__(list) >> self.__missing__ = list >> >> I think I'm way off base. I'm not clear on what the calling sequence is for >> defaultdict or how to get it to use my CaseInsensitiveDict instead of >> regular dict. >> >> Can you help? > > You need to make a subclass of CaseInsensitiveDict, implement the > __missing__(key) method, and override the __init__() method to take the > factory function as an argument instead of data. defaultdict is just a > subclass of dict that does this. > > > class CaseInsensitiveDictDef(CaseInsensitiveDict): > def __init__(self, default_factory): > super(CaseInsensitiveDictDef, self).__init__() > self.default_factory = default_factory > > def __missing__(self, key): > return self.default_factory() > Many thanks. This was a great learning experience as well as ending up with exactly what I wanted. Python is rich with "Ah ha!" moments. This was definitely one of them. In my feeble attempt to give back, here's the answer: class CaseInsensitiveDefaultDict(CaseInsensitiveDict): def __init__(self, default_factory=None, init=None): if not callable(default_factory): raise TypeError('First argument must be callable') super(CaseInsensitiveDefaultDict, self).__init__(init) self.default_factory = default_factory def __missing__(self, key): self[key] = val = self.default_factory() return val def __getitem__(self, key): try: return super(CaseInsensitiveDefaultDict, self).__getitem__(key) except KeyError: return self.__missing__(key) -- Time flies like the wind. Fruit flies like a banana. Stranger things have .0. happened but none stranger than this. Does your driver's license say Organ ..0 Donor?Black holes are where God divided by zero. Listen to me! We are all- 000 individuals! What if this weren't a hypothetical question? steveo at syslang.net From colton.myers at gmail.com Wed Mar 28 11:11:55 2012 From: colton.myers at gmail.com (Colton Myers) Date: Wed, 28 Mar 2012 09:11:55 -0600 Subject: errors building python 2.7.3 In-Reply-To: <4F72FAF9.8000802@ank-sia.com> References: <4F72FAF9.8000802@ank-sia.com> Message-ID: > > Reporting here, because bugs.python.org refuses connections currently. > bugs.python.org seems to be back up, I'd repost there if you haven't already. -- Colton Myers -------------- next part -------------- An HTML attachment was scrubbed... URL: From rridge at csclub.uwaterloo.ca Wed Mar 28 11:36:10 2012 From: rridge at csclub.uwaterloo.ca (Ross Ridge) Date: Wed, 28 Mar 2012 11:36:10 -0400 Subject: "convert" string to bytes without changing data (encoding) References: <9tg21lFmo3U1@mid.dfncis.de> Message-ID: Chris Angelico wrote: >What is a string? It's not a series of bytes. Of course it is. Conceptually you're not supposed to think of it that way, but a string is stored in memory as a series of bytes. What he's asking for many not be very useful or practical, but if that's your problem here than then that's what you should be addressing, not pretending that it's fundamentally impossible. Ross Ridge -- l/ // Ross Ridge -- The Great HTMU [oo][oo] rridge at csclub.uwaterloo.ca -()-/()/ http://www.csclub.uwaterloo.ca/~rridge/ db // From drobinow at gmail.com Wed Mar 28 11:42:55 2012 From: drobinow at gmail.com (David Robinow) Date: Wed, 28 Mar 2012 11:42:55 -0400 Subject: errors building python 2.7.3 In-Reply-To: <4F72FAF9.8000802@ank-sia.com> References: <4F72FAF9.8000802@ank-sia.com> Message-ID: On Wed, Mar 28, 2012 at 7:50 AM, Alexey Luchko wrote: > I've tried to build Python 2.7.3rc2 on cygwin and got the following errors: > > $ CFLAGS=-I/usr/include/ncursesw/ CPPFLAGS=-I/usr/include/ncursesw/ > ./configure I haven't tried 2.7.3 yet, so I'll describe my experience with 2.7.2 I use /usr/include/ncurses rather than /usr/include/ncursesw I don't remember what the difference is but ncurses seems to work. > $ make > ... > gcc -shared -Wl,--enable-auto-image-base > build/temp.cygwin-1.7.11-i686-2.7/Python-2.7.3rc2/Modules/_io/bufferedio.o > build/temp.cygwin-1.7.11-i686-2.7/Python-2.7.3rc2/Modules/_io/bytesio.o > build/temp.cygwin-1.7.11-i686-2.7/Python-2.7.3rc2/Modules/_io/fileio.o > build/temp.cygwin-1.7.11-i686-2.7/Python-2.7.3rc2/Modules/_io/iobase.o > build/temp.cygwin-1.7.11-i686-2.7/Python-2.7.3rc2/Modules/_io/_iomodule.o > build/temp.cygwin-1.7.11-i686-2.7/Python-2.7.3rc2/Modules/_io/stringio.o > build/temp.cygwin-1.7.11-i686-2.7/Python-2.7.3rc2/Modules/_io/textio.o > -L/usr/local/lib -L. -lpython2.7 -o build/lib.cygwin-1.7.11-i686-2.7/_io.dll > build/temp.cygwin-1.7.11-i686-2.7/Python-2.7.3rc2/Modules/_io/bufferedio.o: > In function `_set_BlockingIOError': > /Python-2.7.3rc2/Modules/_io/bufferedio.c:579: undefined reference to > `__imp__PyExc_BlockingIOError' In Modules/_io/_iomodule.h, use: PyObject *PyExc_BlockingIOError; instead of: PyAPI_DATA(PyObject *) PyExc_BlockingIOError; > Failed to build these modules: > _curses ? ? ? ? ? ?_io > But please note that Cygwin does not support Python-2.7. There may be other reasons. I don't really use cygwin Python for anything important. It's just nice to have around since I spend a lot of time in the bash shell. It would probably be helpful to ask on the Cygwin mailing list From nospam at nospam.com Wed Mar 28 12:04:06 2012 From: nospam at nospam.com (Javier) Date: Wed, 28 Mar 2012 16:04:06 +0000 (UTC) Subject: Tools for refactoring/obfuscation References: Message-ID: Yes, in general I follow clear guidelines for writing code. I just use modules with functions in the same directory and clear use of name spaces. I almost never use classes. I wonder if you use some tool for refactoring. I am mainly intersted in scripting tools, no eclipse-style guis. Just let me know if you use some scripting tool. And, as somebody pointed in this thread obfuscating or refactoring the code are very different things but they can be done with the same tools. Javier Vladimir Ignatov wrote: > Hi, > > (sorry for replying to the old topic) > > On Tue, Mar 6, 2012 at 10:29 PM, Javier wrote: >> I am looking for an automated tool for refactoring/obfuscation. >> Something that changes names of functions, variables, or which would >> merge all the functions of various modules in a single module. >> The closest I have seen is http://bicyclerepair.sourceforge.net/ >> >> Does somebody know of something that can work from the command line or >> simple data structures/text files?, like a python dictionary of functions >> {"old":"new",...} > > I am not surprised what nobody answers. I think that such tool is > nearly impossible given the dynamic Python's nature. > But if you put little discipline/restrictions in your source code, > when doing obfuscation could be much more easier. Almost trivial I > would say. > > Javier, you can contact me directly if you are interested in this topic. > > Vladimir Ignatov > kmisoft at gmail com From rosuav at gmail.com Wed Mar 28 12:18:43 2012 From: rosuav at gmail.com (Chris Angelico) Date: Thu, 29 Mar 2012 03:18:43 +1100 Subject: "convert" string to bytes without changing data (encoding) In-Reply-To: References: <9tg21lFmo3U1@mid.dfncis.de> Message-ID: On Thu, Mar 29, 2012 at 2:36 AM, Ross Ridge wrote: > Chris Angelico ? wrote: >>What is a string? It's not a series of bytes. > > Of course it is. ?Conceptually you're not supposed to think of it that > way, but a string is stored in memory as a series of bytes. Note that distinction. I said that a string "is not" a series of bytes; you say that it "is stored" as bytes. > What he's asking for many not be very useful or practical, but if that's > your problem here than then that's what you should be addressing, not > pretending that it's fundamentally impossible. That's equivalent to taking a 64-bit integer and trying to treat it as a 64-bit floating point number. They're all just bits in memory, and in C it's quite easy to cast a pointer to a different type and dereference it. But a Python Unicode string might be stored in several ways; for all you know, it might actually be stored as a sequence of apples in a refrigerator, just as long as they can be referenced correctly. There's no logical Python way to turn that into a series of bytes. ChrisA From swellfr at gmail.com Wed Mar 28 12:31:05 2012 From: swellfr at gmail.com (Manu) Date: Wed, 28 Mar 2012 18:31:05 +0200 Subject: ResponseNotReady in httplib Message-ID: Hi I try to access a web site and it returns me this exception "ResponseNotReady" . I don't know what is the root of the problem and how to sort it out. I am using the excellent python requests library to access the web site but it relies on httplib utlimately. Could someone one explains me the problem and how to sort it out . Thx Dave From invalid at invalid.invalid Wed Mar 28 12:33:13 2012 From: invalid at invalid.invalid (Grant Edwards) Date: Wed, 28 Mar 2012 16:33:13 +0000 (UTC) Subject: "convert" string to bytes without changing data (encoding) References: <9tg21lFmo3U1@mid.dfncis.de> Message-ID: On 2012-03-28, Chris Angelico wrote: > for all you know, it might actually be stored as a sequence of > apples in a refrigerator [...] > There's no logical Python way to turn that into a series of bytes. There's got to be a joke there somewhere about how to eat an apple... -- Grant Edwards grant.b.edwards Yow! Somewhere in DOWNTOWN at BURBANK a prostitute is gmail.com OVERCOOKING a LAMB CHOP!! From d at davea.name Wed Mar 28 13:16:57 2012 From: d at davea.name (Dave Angel) Date: Wed, 28 Mar 2012 13:16:57 -0400 Subject: "convert" string to bytes without changing data (encoding) In-Reply-To: <9tg21lFmo3U1@mid.dfncis.de> References: <9tg21lFmo3U1@mid.dfncis.de> Message-ID: <4F734789.9040506@davea.name> On 03/28/2012 04:56 AM, Peter Daum wrote: > Hi, > > is there any way to convert a string to bytes without > interpreting the data in any way? Something like: > > s='abcde' > b=bytes(s, "unchanged") > > Regards, > Peter You needed to specify that you are using Python 3.x . In python 2.x, a string is indeed a series of bytes. But in Python 3.x, you have to be much more specific. For example, if that string is coming from a literal, then you usually can convert it back to bytes simply by encoding using the same method as the one specified for the source file. So look at the encoding line at the top of the file. -- DaveA From gator at cs.tu-berlin.de Wed Mar 28 13:43:36 2012 From: gator at cs.tu-berlin.de (Peter Daum) Date: Wed, 28 Mar 2012 19:43:36 +0200 Subject: "convert" string to bytes without changing data (encoding) In-Reply-To: References: <9tg21lFmo3U1@mid.dfncis.de> <9tg4qoFbfpU1@mid.dfncis.de> Message-ID: <9th0u8Fuf2U1@mid.dfncis.de> On 2012-03-28 12:42, Heiko Wundram wrote: > Am 28.03.2012 11:43, schrieb Peter Daum: >> ... in my example, the variable s points to a "string", i.e. a series of >> bytes, (0x61,0x62 ...) interpreted as ascii/unicode characters. > > No; a string contains a series of codepoints from the unicode plane, > representing natural language characters (at least in the simplistic > view, I'm not talking about surrogates). These can be encoded to > different binary storage representations, of which ascii is (a common) one. > >> What I am looking for is a general way to just copy the raw data >> from a "string" object to a "byte" object without any attempt to >> "decode" or "encode" anything ... > > There is "logically" no raw data in the string, just a series of > codepoints, as stated above. You'll have to specify the encoding to use > to get at "raw" data, and from what I gather you're interested in the > latin-1 (or iso-8859-15) encoding, as you're specifically referencing > chars >= 0x80 (which hints at your mindset being in LATIN-land, so to > speak). ... I was under the illusion, that python (like e.g. perl) stored strings internally in utf-8. In this case the "conversion" would simple mean to re-label the data. Unfortunately, as I meanwhile found out, this is not the case (nor the "apple encoding" ;-), so it would indeed be pretty useless. The longer story of my question is: I am new to python (obviously), and since I am not familiar with either one, I thought it would be advisory to go for python 3.x. The biggest problem that I am facing is, that I am often dealing with data, that is basically text, but it can contain 8-bit bytes. In this case, I can not safely assume any given encoding, but I actually also don't need to know - for my purposes, it would be perfectly good enough to deal with the ascii portions and keep anything else unchanged. As it seems, this would be far easier with python 2.x. With python 3 and its strict distinction between "str" and "bytes", things gets syntactically pretty awkward and error-prone (something as innocently looking like "s=s+'/'" hidden in a rarely reached branch and a seemingly correct program will crash with a TypeError 2 years later ...) Regards, Peter From steve+comp.lang.python at pearwood.info Wed Mar 28 13:54:20 2012 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 28 Mar 2012 17:54:20 GMT Subject: "convert" string to bytes without changing data (encoding) References: <9tg21lFmo3U1@mid.dfncis.de> Message-ID: <4f73504c$0$29981$c3e8da3$5496439d@news.astraweb.com> On Wed, 28 Mar 2012 11:36:10 -0400, Ross Ridge wrote: > Chris Angelico wrote: >>What is a string? It's not a series of bytes. > > Of course it is. Conceptually you're not supposed to think of it that > way, but a string is stored in memory as a series of bytes. You don't know that. They might be stored as a tree, or a rope, or some even more complex data structure. In fact, in Python, they are stored as an object. But even if they were stored as a simple series of bytes, you don't know what bytes they are. That is an implementation detail of the particular Python build being used, and since Python doesn't give direct access to memory (at least not in pure Python) there's no way to retrieve those bytes using Python code. Saying that strings are stored in memory as bytes is no more sensible than saying that dicts are stored in memory as bytes. Yes, they are. So what? Taken out of context in a running Python interpreter, those bytes are pretty much meaningless. > What he's asking for many not be very useful or practical, but if that's > your problem here than then that's what you should be addressing, not > pretending that it's fundamentally impossible. The right way to convert bytes to strings, and vice versa, is via encoding and decoding operations. What the OP is asking for is as silly as somebody asking to turn a float 1.3792 into a string without calling str() or any equivalent float->string conversion. They're both made up of bytes, right? Yeah, they are. So what? Even if you do a hex dump of float 1.3792, the result will NOT be the string "1.3792". And likewise, even if you somehow did a hex dump of the memory representation of a string, the result will NOT be the equivalent sequence of bytes except *maybe* for some small subset of possible strings. -- Steven From rridge at csclub.uwaterloo.ca Wed Mar 28 14:05:11 2012 From: rridge at csclub.uwaterloo.ca (Ross Ridge) Date: Wed, 28 Mar 2012 14:05:11 -0400 Subject: "convert" string to bytes without changing data (encoding) References: <9tg21lFmo3U1@mid.dfncis.de> Message-ID: Ross Ridge wr= > Of course it is. =A0Conceptually you're not supposed to think of it that > way, but a string is stored in memory as a series of bytes. Chris Angelico wrote: >Note that distinction. I said that a string "is not" a series of >bytes; you say that it "is stored" as bytes. The distinction is meaningless. I'm not going argue with you about what you or I ment by the word "is". >But a Python Unicode string might be stored in several >ways; for all you know, it might actually be stored as a sequence of >apples in a refrigerator, just as long as they can be referenced >correctly. But it is in fact only stored in one particular way, as a series of bytes. >There's no logical Python way to turn that into a series of bytes. Nonsense. Play all the semantic games you want, it already is a series of bytes. 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 Wed Mar 28 14:07:01 2012 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 28 Mar 2012 18:07:01 GMT Subject: unittest: assertRaises() with an instance instead of a type References: Message-ID: <4f735345$0$29981$c3e8da3$5496439d@news.astraweb.com> On Wed, 28 Mar 2012 14:28:08 +0200, Ulrich Eckhardt wrote: > Hi! > > I'm currently writing some tests for the error handling of some code. In > this scenario, I must make sure that both the correct exception is > raised and that the contained error code is correct: > > > try: > foo() > self.fail('exception not raised') > catch MyException as e: > self.assertEqual(e.errorcode, SOME_FOO_ERROR) > catch Exception: > self.fail('unexpected exception raised') First off, that is not Python code. "catch Exception" gives a syntax error. Secondly, that is not the right way to do this unit test. You are testing two distinct things, so you should write it as two separate tests: def testFooRaisesException(self): # Test that foo() raises an exception. self.assertRaises(MyException, foo) If foo does *not* raise an exception, the unittest framework will handle the failure for you. If it raises a different exception, the framework will also handle that too. Then write a second test to check the exception code: def testFooExceptionCode(self): # Test that foo()'s exception has the right error code. try: foo() except MyException as err: self.assertEquals(err.errorcode, SOME_FOO_ERROR) Again, let the framework handle any unexpected cases. If you have lots of functions to test, write a helper function: def catch(exception, func, *args, **kwargs): try: func(*args, **kwargs) except exception as err: return err raise RuntimeError('no error raised') and then the test becomes: def testFooExceptionCode(self): # Test that foo()'s exception has the right error code. self.assertEquals( catch(MyException, foo).errorcode, SOME_FOO_ERROR ) (By the way, I have to question the design of an exception with error codes. That seems pretty poor design to me. Normally the exception *type* acts as equivalent to an error code.) -- Steven From tjreedy at udel.edu Wed Mar 28 14:11:28 2012 From: tjreedy at udel.edu (Terry Reedy) Date: Wed, 28 Mar 2012 14:11:28 -0400 Subject: "convert" string to bytes without changing data (encoding) In-Reply-To: References: <9tg21lFmo3U1@mid.dfncis.de> Message-ID: On 3/28/2012 11:36 AM, Ross Ridge wrote: > Chris Angelico wrote: >> What is a string? It's not a series of bytes. > > Of course it is. Conceptually you're not supposed to think of it that > way, but a string is stored in memory as a series of bytes. *If* it is stored in byte memory. If you execute a 3.x program mentally or on paper, then there are no bytes. If you execute a 3.3 program on a byte-oriented computer, then the 'a' in the string might be represented by 1, 2, or 4 bytes, depending on the other characters in the string. The actual logical bit pattern will depend on the big versus little endianness of the system. My impression is that if you go down to the physical bit level, then again there are, possibly, no 'bytes' as a physical construct as the bits, possibly, are stored in parallel on multiple ram chips. > What he's asking for many not be very useful or practical, but if that's > your problem here than then that's what you should be addressing, not > pretending that it's fundamentally impossible. The python-level way to get the bytes of an object that supports the buffer interface is memoryview(). 3.x strings intentionally do not support the buffer interface as there is not any particular correspondence between characters (codepoints) and bytes. The OP could get the ordinal for each character and decide how *he* wants to convert them to bytes. ba = bytearray() for c in s: i = ord(c) To get the particular bytes used for a particular string on a particular system, OP should use the C API, possibly through ctypes. -- Terry Jan Reedy From steve+comp.lang.python at pearwood.info Wed Mar 28 14:12:57 2012 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 28 Mar 2012 18:12:57 GMT Subject: "convert" string to bytes without changing data (encoding) References: <9tg21lFmo3U1@mid.dfncis.de> <9tg4qoFbfpU1@mid.dfncis.de> Message-ID: <4f7354a9$0$29981$c3e8da3$5496439d@news.astraweb.com> On Wed, 28 Mar 2012 11:43:52 +0200, Peter Daum wrote: > ... in my example, the variable s points to a "string", i.e. a series of > bytes, (0x61,0x62 ...) interpreted as ascii/unicode characters. No. Strings are not sequences of bytes (except in the trivial sense that everything in computer memory is made of bytes). They are sequences of CODE POINTS. (Roughly speaking, code points are *almost* but not quite the same as characters.) I suggest that you need to reset your understanding of strings and bytes. I suggest you start by reading this: http://www.joelonsoftware.com/articles/Unicode.html Then come back and try to explain what actual problem you are trying to solve. -- Steven From modelnine at modelnine.org Wed Mar 28 14:13:11 2012 From: modelnine at modelnine.org (Heiko Wundram) Date: Wed, 28 Mar 2012 20:13:11 +0200 Subject: "convert" string to bytes without changing data (encoding) In-Reply-To: <9th0u8Fuf2U1@mid.dfncis.de> References: "\"<9tg21lFmo3U1@mid.dfncis.de>" " <9tg4qoFbfpU1@mid.dfncis.de> <9th0u8Fuf2U1@mid.dfncis.de> Message-ID: <1053a4e195cf2e85778f6c2c63dc89d4@modelnine.org> Am 28.03.2012 19:43, schrieb Peter Daum: > As it seems, this would be far easier with python 2.x. With python 3 > and its strict distinction between "str" and "bytes", things gets > syntactically pretty awkward and error-prone (something as innocently > looking like "s=s+'/'" hidden in a rarely reached branch and a > seemingly correct program will crash with a TypeError 2 years > later ...) It seems that you're mixing things up wrt. the string/bytes distinction; it's not as "complicated" as it might seem. 1) Strings s = "This is a test string" s = 'This is another test string with single quotes' s = """ And this is a multiline test string. """ s = 'c' # This is also a string... all create/refer to string objects. How Python internally stores them is none of your concern (actually, that's rather complicated anyway, at least with the upcoming Python 3.3), and processing a string basically means that you'll work on the natural language characters present in the string. Python strings can store (pretty much) all characters and surrogates that unicode allows, and when the python interpreter/compiler reads strings from input (I'm talking about source files), a default encoding defines how the bytes in your input file get interpreted as unicode codepoint encodings (generally, it depends on your system locale or file header indications) to construct the internal string object you're using to access the data in the string. There is no such thing as a type for a single character; single characters are simply strings of length 1 (and so indexing also returns a [new] string object). Single/double quotes work no different. The internal encoding used by the Python interpreter is of no concern to you. 2) Bytes s = b'this is a byte-string' s = b'\x22\x33\x44' The above define bytes. Think of the bytes type as arrays of 8-bit integers, only representing a buffer which you can process as an array of fixed-width integers. Reading from stdin/a file gets you bytes, and not a string, because Python cannot automagically guess what format the input is in. Indexing the bytes type returns an integer (which is the clearest distinction between string and bytes). Being able to input "string-looking" data in source files as bytes is a debatable "feature" (IMHO; see the first example), simply because it breaks the semantic difference between the two types in the eye of the programmer looking at source. 3) Conversions To get from bytes to string, you have to decode the bytes buffer, telling Python what kind of character data is contained in the array of integers. After decoding, you'll get a string object which you can process using the standard string methods. For decoding to succeed, you have to tell Python how the natural language characters are encoded in your array of bytes: b'hello'.decode('iso-8859-15') To get from string back to bytes (you want to write the natural language character data you've processed to a file), you have to encode the data in your string buffer, which gets you an array of 8-bit integers to write to the output: 'hello'.encode('iso-8859-15') Most output methods will happily do the encoding for you, using a standard encoding, and if that happens to be ASCII, you're getting UnicodeEncodeErrors which tell you that a character in your string source is unsuited to be transmitted using the encoding you've specified. If the above doesn't make the string/bytes-distinction and usage clearer, and you have a C#-background, check out the distinction between byte[] (which the System.IO-streams get you), and how you have to use a System.Encoding-derived class to get at actual System.String objects to manipulate character data. Pythons type system wrt. character data is pretty much similar, except for missing the "single character" type (char). Anyway, back to what you wrote: how are you getting the input data? Why are "high bytes" in there which you do not know the encoding for? Generally, from what I gather, you'll decode data from some source, process it, and write it back using the same encoding which you used for decoding, which should do exactly what you want and not get you into any trouble with encodings. -- --- Heiko. From jpiitula at ling.helsinki.fi Wed Mar 28 14:13:53 2012 From: jpiitula at ling.helsinki.fi (Jussi Piitulainen) Date: 28 Mar 2012 21:13:53 +0300 Subject: "convert" string to bytes without changing data (encoding) References: <9tg21lFmo3U1@mid.dfncis.de> <9tg4qoFbfpU1@mid.dfncis.de> <9th0u8Fuf2U1@mid.dfncis.de> Message-ID: Peter Daum writes: > ... I was under the illusion, that python (like e.g. perl) stored > strings internally in utf-8. In this case the "conversion" would simple > mean to re-label the data. Unfortunately, as I meanwhile found out, this > is not the case (nor the "apple encoding" ;-), so it would indeed be > pretty useless. > > The longer story of my question is: I am new to python (obviously), and > since I am not familiar with either one, I thought it would be advisory > to go for python 3.x. The biggest problem that I am facing is, that I > am often dealing with data, that is basically text, but it can contain > 8-bit bytes. In this case, I can not safely assume any given encoding, > but I actually also don't need to know - for my purposes, it would be > perfectly good enough to deal with the ascii portions and keep anything > else unchanged. You can read as bytes and decode as ASCII but ignoring the troublesome non-text characters: >>> print(open('text.txt', 'br').read().decode('ascii', 'ignore')) Das fr ASCII nicht benutzte Bit kann auch fr Fehlerkorrekturzwecke (Parittsbit) auf den Kommunikationsleitungen oder fr andere Steuerungsaufgaben verwendet werden. Heute wird es aber fast immer zur Erweiterung von ASCII auf einen 8-Bit-Code verwendet. Diese Erweiterungen sind mit dem ursprnglichen ASCII weitgehend kompatibel, so dass alle im ASCII definierten Zeichen auch in den verschiedenen Erweiterungen durch die gleichen Bitmuster kodiert werden. Die einfachsten Erweiterungen sind Kodierungen mit sprachspezifischen Zeichen, die nicht im lateinischen Grundalphabet enthalten sind. The paragraph is from the German Wikipedia on ASCII, in UTF-8. From ethan at stoneleaf.us Wed Mar 28 14:17:56 2012 From: ethan at stoneleaf.us (Ethan Furman) Date: Wed, 28 Mar 2012 11:17:56 -0700 Subject: "convert" string to bytes without changing data (encoding) In-Reply-To: <9th0u8Fuf2U1@mid.dfncis.de> References: <9tg21lFmo3U1@mid.dfncis.de> <9tg4qoFbfpU1@mid.dfncis.de> <9th0u8Fuf2U1@mid.dfncis.de> Message-ID: <4F7355D4.7050506@stoneleaf.us> Peter Daum wrote: > On 2012-03-28 12:42, Heiko Wundram wrote: >> Am 28.03.2012 11:43, schrieb Peter Daum: >>> ... in my example, the variable s points to a "string", i.e. a series of >>> bytes, (0x61,0x62 ...) interpreted as ascii/unicode characters. >> No; a string contains a series of codepoints from the unicode plane, >> representing natural language characters (at least in the simplistic >> view, I'm not talking about surrogates). These can be encoded to >> different binary storage representations, of which ascii is (a common) one. >> >>> What I am looking for is a general way to just copy the raw data >>> from a "string" object to a "byte" object without any attempt to >>> "decode" or "encode" anything ... >> There is "logically" no raw data in the string, just a series of >> codepoints, as stated above. You'll have to specify the encoding to use >> to get at "raw" data, and from what I gather you're interested in the >> latin-1 (or iso-8859-15) encoding, as you're specifically referencing >> chars >= 0x80 (which hints at your mindset being in LATIN-land, so to >> speak). > > The longer story of my question is: I am new to python (obviously), and > since I am not familiar with either one, I thought it would be advisory > to go for python 3.x. The biggest problem that I am facing is, that I > am often dealing with data, that is basically text, but it can contain > 8-bit bytes. In this case, I can not safely assume any given encoding, > but I actually also don't need to know - for my purposes, it would be > perfectly good enough to deal with the ascii portions and keep anything > else unchanged. Where is the data coming from? Files? In that case, it sounds like you will want to decode/encode using 'latin-1', as the bulk of your text is plain ascii and you don't really care about the upper-ascii chars. ~Ethan~ From ramit.prasad at jpmorgan.com Wed Mar 28 14:20:23 2012 From: ramit.prasad at jpmorgan.com (Prasad, Ramit) Date: Wed, 28 Mar 2012 18:20:23 +0000 Subject: "convert" string to bytes without changing data (encoding) In-Reply-To: <9th0u8Fuf2U1@mid.dfncis.de> References: <9tg21lFmo3U1@mid.dfncis.de> <9tg4qoFbfpU1@mid.dfncis.de> <9th0u8Fuf2U1@mid.dfncis.de> Message-ID: <5B80DD153D7D744689F57F4FB69AF47409291B51@SCACMX008.exchad.jpmchase.net> > As it seems, this would be far easier with python 2.x. With python 3 > and its strict distinction between "str" and "bytes", things gets > syntactically pretty awkward and error-prone (something as innocently > looking like "s=s+'/'" hidden in a rarely reached branch and a > seemingly correct program will crash with a TypeError 2 years > later ...) Just a small note as you are new to Python, string concatenation can be expensive (quadratic time). The Python (2.x and 3.x) idiom for frequent string concatenation is to append to a list and then join them like the following (linear time). >>>lst = [ 'Hi,' ] >>>lst.append( 'how' ) >>>lst.append( 'are' ) >>>lst.append( 'you?' ) >>>sentence = ' '.join( lst ) # use a space separating each element >>>print sentence Hi, how are you? You can use join on an empty string, but then they will not be separated by spaces. >>>sentence = ''.join( lst ) # empty string so no separation >>>print sentence Hi,howareyou? You can use any string as a separator, length does not matter. >>>sentence = '@-Q'.join( lst ) >>>print sentence Hi, at -Qhow@-Qare at -Qyou? Ramit Ramit Prasad | JPMorgan Chase Investment Bank | Currencies Technology 712 Main Street | Houston, TX 77002 work phone: 713 - 216 - 5423 -- This email is confidential and subject to important disclaimers and conditions including on offers for the purchase or sale of securities, accuracy and completeness of information, viruses, confidentiality, legal privilege, and legal entity disclaimers, available at http://www.jpmorgan.com/pages/disclosures/email. From ian.g.kelly at gmail.com Wed Mar 28 14:20:30 2012 From: ian.g.kelly at gmail.com (Ian Kelly) Date: Wed, 28 Mar 2012 12:20:30 -0600 Subject: "convert" string to bytes without changing data (encoding) In-Reply-To: <9th0u8Fuf2U1@mid.dfncis.de> References: <9tg21lFmo3U1@mid.dfncis.de> <9tg4qoFbfpU1@mid.dfncis.de> <9th0u8Fuf2U1@mid.dfncis.de> Message-ID: On Wed, Mar 28, 2012 at 11:43 AM, Peter Daum wrote: > ... I was under the illusion, that python (like e.g. perl) stored > strings internally in utf-8. In this case the "conversion" would simple > mean to re-label the data. Unfortunately, as I meanwhile found out, this > is not the case (nor the "apple encoding" ;-), so it would indeed be > pretty useless. No, unicode strings can be stored internally as any of UCS-1, UCS-2, UCS-4, C wchar strings, or even plain ASCII. And those are all implementation details that could easily change in future versions of Python. > The longer story of my question is: I am new to python (obviously), and > since I am not familiar with either one, I thought it would be advisory > to go for python 3.x. The biggest problem that I am facing is, that I > am often dealing with data, that is basically text, but it can contain > 8-bit bytes. In this case, I can not safely assume any given encoding, > but I actually also don't need to know - for my purposes, it would be > perfectly good enough to deal with the ascii portions and keep anything > else unchanged. You can't generally just "deal with the ascii portions" without knowing something about the encoding. Say you encounter a byte greater than 127. Is it a single non-ASCII character, or is it the leading byte of a multi-byte character? If the next character is less than 127, is it an ASCII character, or a continuation of the previous character? For UTF-8 you could safely assume ASCII, but without knowing the encoding, there is no way to be sure. If you just assume it's ASCII and manipulate it as such, you could be messing up non-ASCII characters. Cheers, Ian From rridge at csclub.uwaterloo.ca Wed Mar 28 14:22:50 2012 From: rridge at csclub.uwaterloo.ca (Ross Ridge) Date: Wed, 28 Mar 2012 14:22:50 -0400 Subject: "convert" string to bytes without changing data (encoding) References: <9tg21lFmo3U1@mid.dfncis.de> <4f73504c$0$29981$c3e8da3$5496439d@news.astraweb.com> Message-ID: Steven D'Aprano wrote: >The right way to convert bytes to strings, and vice versa, is via >encoding and decoding operations. If you want to dictate to the original poster the correct way to do things then you don't need to do anything more that. You don't need to pretend like Chris Angelico that there's isn't a direct mapping from the his Python 3 implementation's internal respresentation of strings to bytes in order to label what he's asking for as being "silly". 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 Wed Mar 28 14:26:29 2012 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 28 Mar 2012 18:26:29 GMT Subject: "convert" string to bytes without changing data (encoding) References: <9tg21lFmo3U1@mid.dfncis.de> <9tg4qoFbfpU1@mid.dfncis.de> <9th0u8Fuf2U1@mid.dfncis.de> Message-ID: <4f7357d5$0$29981$c3e8da3$5496439d@news.astraweb.com> On Wed, 28 Mar 2012 19:43:36 +0200, Peter Daum wrote: > The longer story of my question is: I am new to python (obviously), and > since I am not familiar with either one, I thought it would be advisory > to go for python 3.x. The biggest problem that I am facing is, that I am > often dealing with data, that is basically text, but it can contain > 8-bit bytes. All bytes are 8-bit, at least on modern hardware. I think you have to go back to the 1950s to find 10-bit or 12-bit machines. > In this case, I can not safely assume any given encoding, > but I actually also don't need to know - for my purposes, it would be > perfectly good enough to deal with the ascii portions and keep anything > else unchanged. Well you can't do that, because *by definition* you are changing a CHARACTER into ONE OR MORE BYTES. So the question you have to ask is, *how* do you want to change them? You can use an error handler to convert any untranslatable characters into question marks, or to ignore them altogether: bytes = string.encode('ascii', 'replace') bytes = string.encode('ascii', 'ignore') When going the other way, from bytes to strings, it can sometimes be useful to use the Latin-1 encoding, which essentially cannot fail: string = bytes.decode('latin1') although the non-ASCII chars that you get may not be sensible or meaningful in any way. But if there are only a few of them, and you don't care too much, this may be a simple approach. But in a nutshell, it is physically impossible to map the millions of Unicode characters to just 256 possible bytes without either throwing some characters away, or performing an encoding. > As it seems, this would be far easier with python 2.x. It only seems that way until you try. -- Steven From tjreedy at udel.edu Wed Mar 28 14:26:48 2012 From: tjreedy at udel.edu (Terry Reedy) Date: Wed, 28 Mar 2012 14:26:48 -0400 Subject: unittest: assertRaises() with an instance instead of a type In-Reply-To: References: Message-ID: On 3/28/2012 8:28 AM, Ulrich Eckhardt wrote: > Hi! > > I'm currently writing some tests for the error handling of some code. In > this scenario, I must make sure that both the correct exception is > raised and that the contained error code is correct: > > > try: > foo() > self.fail('exception not raised') > catch MyException as e: > self.assertEqual(e.errorcode, SOME_FOO_ERROR) > catch Exception: > self.fail('unexpected exception raised') > > > This is tedious to write and read. The docs mention this alternative: > > > with self.assertRaises(MyException) as cm: > foo() > self.assertEqual(cm.the_exception.errorcode, SOME_FOO_ERROR) Exceptions can have multiple attributes. This allows the tester to exactly specify what attributes to test. > This is shorter, but I think there's an alternative syntax possible that > would be even better: > > with self.assertRaises(MyException(SOME_FOO_ERROR)): > foo() I presume that if this worked the way you want, all attributes would have to match. The message part of builtin exceptions is allowed to change, so hard-coding an exact expected message makes tests fragile. This is a problem with doctest. > Here, assertRaises() is not called with an exception type but with an > exception instance. I'd implement it something like this: > > def assertRaises(self, exception, ...): > # divide input parameter into type and instance > if isinstance(exception, Exception): > exception_type = type(exception) > else: > exception_type = exception > exception = None > # call testee and verify results > try: > ...call function here... > except exception_type as e: > if not exception is None: > self.assertEqual(e, exception) Did you use tabs? They do not get preserved indefinitely, so they are bad for posting. > This of course requires the exception to be equality-comparable. Equality comparison is by id. So this code will not do what you want. You can, of course, write a custom AssertX subclass that at least works for your custom exception class. -- Terry Jan Reedy From ramit.prasad at jpmorgan.com Wed Mar 28 14:31:00 2012 From: ramit.prasad at jpmorgan.com (Prasad, Ramit) Date: Wed, 28 Mar 2012 18:31:00 +0000 Subject: "convert" string to bytes without changing data (encoding) In-Reply-To: References: <9tg21lFmo3U1@mid.dfncis.de> <9tg4qoFbfpU1@mid.dfncis.de> <9th0u8Fuf2U1@mid.dfncis.de> Message-ID: <5B80DD153D7D744689F57F4FB69AF47409291B7A@SCACMX008.exchad.jpmchase.net> > You can read as bytes and decode as ASCII but ignoring the troublesome > non-text characters: > > >>> print(open('text.txt', 'br').read().decode('ascii', 'ignore')) > Das fr ASCII nicht benutzte Bit kann auch fr Fehlerkorrekturzwecke > (Parittsbit) auf den Kommunikationsleitungen oder fr andere > Steuerungsaufgaben verwendet werden. Heute wird es aber fast immer zur > Erweiterung von ASCII auf einen 8-Bit-Code verwendet. Diese > Erweiterungen sind mit dem ursprnglichen ASCII weitgehend kompatibel, > so dass alle im ASCII definierten Zeichen auch in den verschiedenen > Erweiterungen durch die gleichen Bitmuster kodiert werden. Die > einfachsten Erweiterungen sind Kodierungen mit sprachspezifischen > Zeichen, die nicht im lateinischen Grundalphabet enthalten sind. > > The paragraph is from the German Wikipedia on ASCII, in UTF-8. I see no non-ASCII characters, not sure if that is because the source has none or something else. From this example I would not say that the rest of the text is "unchanged". Decode converts to Unicode, did you mean encode? I think "ignore" will remove non-translatable characters and not leave them in the returned string. Ramit Ramit Prasad | JPMorgan Chase Investment Bank | Currencies Technology 712 Main Street | Houston, TX 77002 work phone: 713 - 216 - 5423 -- This email is confidential and subject to important disclaimers and conditions including on offers for the purchase or sale of securities, accuracy and completeness of information, viruses, confidentiality, legal privilege, and legal entity disclaimers, available at http://www.jpmorgan.com/pages/disclosures/email. From larry.martell at gmail.com Wed Mar 28 14:39:54 2012 From: larry.martell at gmail.com (Larry.Martell@gmail.com) Date: Wed, 28 Mar 2012 11:39:54 -0700 (PDT) Subject: Best way to structure data for efficient searching Message-ID: I have the following use case: I have a set of data that is contains 3 fields, K1, K2 and a timestamp. There are duplicates in the data set, and they all have to processed. Then I have another set of data with 4 fields: K3, K4, K5, and a timestamp. There are also duplicates in that data set, and they also all have to be processed. I need to find all the items in the second data set where K1==K3 and K2==K4 and the 2 timestamps are within 20 seconds of each other. I have this working, but the way I did it seems very inefficient - I simply put the data in 2 arrays (as tuples) and then walked through the entire second data set once for each item in the first data set, looking for matches. Is there a better, more efficient way I could have done this? From python.list at tim.thechases.com Wed Mar 28 14:49:19 2012 From: python.list at tim.thechases.com (Tim Chase) Date: Wed, 28 Mar 2012 13:49:19 -0500 Subject: "convert" string to bytes without changing data (encoding) In-Reply-To: References: <9tg21lFmo3U1@mid.dfncis.de> Message-ID: <4F735D2F.70206@tim.thechases.com> On 03/28/12 13:05, Ross Ridge wrote: > Ross Ridge wr= >> But a Python Unicode string might be stored in several >> ways; for all you know, it might actually be stored as a sequence of >> apples in a refrigerator, just as long as they can be referenced >> correctly. > > But it is in fact only stored in one particular way, as a series of bytes. > >> There's no logical Python way to turn that into a series of bytes. > > Nonsense. Play all the semantic games you want, it already is a series > of bytes. Internally, they're a series of bytes, but they are MEANINGLESS bytes unless you know how they are encoded internally. Those bytes could be UTF-8, UTF-16, UTF-32, or any of a number of other possible encodings[1]. If you get the internal byte stream, there's no way to meaningfully operate on it unless you also know how it's encoded (or you're willing to sacrifice the ability to reliably get the string back). -tkc [1] http://docs.python.org/library/codecs.html#standard-encodings From ethan at stoneleaf.us Wed Mar 28 14:49:26 2012 From: ethan at stoneleaf.us (Ethan Furman) Date: Wed, 28 Mar 2012 11:49:26 -0700 Subject: "convert" string to bytes without changing data (encoding) In-Reply-To: <5B80DD153D7D744689F57F4FB69AF47409291B7A@SCACMX008.exchad.jpmchase.net> References: <9tg21lFmo3U1@mid.dfncis.de> <9tg4qoFbfpU1@mid.dfncis.de> <9th0u8Fuf2U1@mid.dfncis.de> <5B80DD153D7D744689F57F4FB69AF47409291B7A@SCACMX008.exchad.jpmchase.net> Message-ID: <4F735D36.8050205@stoneleaf.us> Prasad, Ramit wrote: >> You can read as bytes and decode as ASCII but ignoring the troublesome >> non-text characters: >> >>>>> print(open('text.txt', 'br').read().decode('ascii', 'ignore')) >> Das fr ASCII nicht benutzte Bit kann auch fr Fehlerkorrekturzwecke >> (Parittsbit) auf den Kommunikationsleitungen oder fr andere >> Steuerungsaufgaben verwendet werden. Heute wird es aber fast immer zur >> Erweiterung von ASCII auf einen 8-Bit-Code verwendet. Diese >> Erweiterungen sind mit dem ursprnglichen ASCII weitgehend kompatibel, >> so dass alle im ASCII definierten Zeichen auch in den verschiedenen >> Erweiterungen durch die gleichen Bitmuster kodiert werden. Die >> einfachsten Erweiterungen sind Kodierungen mit sprachspezifischen >> Zeichen, die nicht im lateinischen Grundalphabet enthalten sind. >> >> The paragraph is from the German Wikipedia on ASCII, in UTF-8. > > I see no non-ASCII characters, not sure if that is because the source > has none or something else. The 'ignore' argument to .decode() caused all non-ascii characters to be removed. ~Ethan~ From ramit.prasad at jpmorgan.com Wed Mar 28 15:02:41 2012 From: ramit.prasad at jpmorgan.com (Prasad, Ramit) Date: Wed, 28 Mar 2012 19:02:41 +0000 Subject: "convert" string to bytes without changing data (encoding) In-Reply-To: References: <9tg21lFmo3U1@mid.dfncis.de> <4f73504c$0$29981$c3e8da3$5496439d@news.astraweb.com> Message-ID: <5B80DD153D7D744689F57F4FB69AF47409291BEC@SCACMX008.exchad.jpmchase.net> > >The right way to convert bytes to strings, and vice versa, is via > >encoding and decoding operations. > > If you want to dictate to the original poster the correct way to do > things then you don't need to do anything more that. You don't need to > pretend like Chris Angelico that there's isn't a direct mapping from > the his Python 3 implementation's internal respresentation of strings > to bytes in order to label what he's asking for as being "silly". It might be technically possible to recreate internal implementation, or get the byte data. That does not mean it will make any sense or be understood in a meaningful manner. I think Ian summarized it very well: >You can't generally just "deal with the ascii portions" without >knowing something about the encoding. Say you encounter a byte >greater than 127. Is it a single non-ASCII character, or is it the >leading byte of a multi-byte character? If the next character is less >than 127, is it an ASCII character, or a continuation of the previous >character? For UTF-8 you could safely assume ASCII, but without >knowing the encoding, there is no way to be sure. If you just assume >it's ASCII and manipulate it as such, you could be messing up >non-ASCII characters. Technically, ASCII goes up to 256 but they are not A-z letters. Ramit Ramit Prasad | JPMorgan Chase Investment Bank | Currencies Technology 712 Main Street | Houston, TX 77002 work phone: 713 - 216 - 5423 -- This email is confidential and subject to important disclaimers and conditions including on offers for the purchase or sale of securities, accuracy and completeness of information, viruses, confidentiality, legal privilege, and legal entity disclaimers, available at http://www.jpmorgan.com/pages/disclosures/email. From rridge at csclub.uwaterloo.ca Wed Mar 28 15:10:23 2012 From: rridge at csclub.uwaterloo.ca (Ross Ridge) Date: Wed, 28 Mar 2012 15:10:23 -0400 Subject: "convert" string to bytes without changing data (encoding) References: <9tg21lFmo3U1@mid.dfncis.de> Message-ID: Tim Chase wrote: >Internally, they're a series of bytes, but they are MEANINGLESS >bytes unless you know how they are encoded internally. Those >bytes could be UTF-8, UTF-16, UTF-32, or any of a number of other >possible encodings[1]. If you get the internal byte stream, >there's no way to meaningfully operate on it unless you also know >how it's encoded (or you're willing to sacrifice the ability to >reliably get the string back). In practice the number of ways that CPython (the only Python 3 implementation) represents strings is much more limited. Pretending otherwise really isn't helpful. Still, if Chris Angelico had used your much less misleading explaination, then this could've been resolved much quicker. The original poster didn't buy Chris's bullshit for a minute, instead he had to find out on his own that that the internal representation of strings wasn't what he expected to be. Ross Ridge -- l/ // Ross Ridge -- The Great HTMU [oo][oo] rridge at csclub.uwaterloo.ca -()-/()/ http://www.csclub.uwaterloo.ca/~rridge/ db // From driscoll at cs.wisc.edu Wed Mar 28 15:20:50 2012 From: driscoll at cs.wisc.edu (Evan Driscoll) Date: Wed, 28 Mar 2012 14:20:50 -0500 Subject: "convert" string to bytes without changing data (encoding) In-Reply-To: References: <9tg21lFmo3U1@mid.dfncis.de> <4f73504c$0$29981$c3e8da3$5496439d@news.astraweb.com> Message-ID: <4F736492.1080702@cs.wisc.edu> On 01/-10/-28163 01:59 PM, Ross Ridge wrote: > Steven D'Aprano wrote: >> The right way to convert bytes to strings, and vice versa, is via >> encoding and decoding operations. > > If you want to dictate to the original poster the correct way to do > things then you don't need to do anything more that. You don't need to > pretend like Chris Angelico that there's isn't a direct mapping from > the his Python 3 implementation's internal respresentation of strings > to bytes in order to label what he's asking for as being "silly". That mapping may as well be: def get_bytes(some_string): import random length = random.randint(len(some_string), 5*len(some_string)) bytes = [0] * length for i in xrange(length): bytes[i] = random.randint(0, 255) return bytes Of course this is hyperbole, but it's essentially about as much guarantee as to what the result is. As many others have said, the encoding isn't defined, and I would guess varies between implementations. (E.g. if Jython and IronPython use their host platforms' native strings, both have 16-bit chars and thus probably use UTF-16 encoding. I am not sure what CPython uses, but I bet it's *not* that.) It's even guaranteed that the byte representation won't change! If something is lazily evaluated or you have a COW string or something, the bytes backing it will differ. So yes, you can say that pretending there's not a mapping of strings to internal representation is silly, because there is. However, there's nothing you can say about that mapping. Evan From marduk at letterboxes.org Wed Mar 28 15:22:39 2012 From: marduk at letterboxes.org (Albert W. Hopkins) Date: Wed, 28 Mar 2012 15:22:39 -0400 Subject: "convert" string to bytes without changing data (encoding) In-Reply-To: References: <9tg21lFmo3U1@mid.dfncis.de> Message-ID: <1332962559.1460206.1.camel@stretch> On Wed, 2012-03-28 at 14:05 -0400, Ross Ridge wrote: > Ross Ridge wr= > > Of course it is. =A0Conceptually you're not supposed to think of it that > > way, but a string is stored in memory as a series of bytes. > > Chris Angelico wrote: > >Note that distinction. I said that a string "is not" a series of > >bytes; you say that it "is stored" as bytes. > > The distinction is meaningless. I'm not going argue with you about what > you or I ment by the word "is". > Off topic, but obligatory: https://www.youtube.com/watch?v=j4XT-l-_3y0 From nagle at animats.com Wed Mar 28 15:30:49 2012 From: nagle at animats.com (John Nagle) Date: Wed, 28 Mar 2012 12:30:49 -0700 Subject: "convert" string to bytes without changing data (encoding) In-Reply-To: <9th0u8Fuf2U1@mid.dfncis.de> References: <9tg21lFmo3U1@mid.dfncis.de> <9tg4qoFbfpU1@mid.dfncis.de> <9th0u8Fuf2U1@mid.dfncis.de> Message-ID: On 3/28/2012 10:43 AM, Peter Daum wrote: > On 2012-03-28 12:42, Heiko Wundram wrote: >> Am 28.03.2012 11:43, schrieb Peter Daum: > The longer story of my question is: I am new to python (obviously), and > since I am not familiar with either one, I thought it would be advisory > to go for python 3.x. The biggest problem that I am facing is, that I > am often dealing with data, that is basically text, but it can contain > 8-bit bytes. In this case, I can not safely assume any given encoding, > but I actually also don't need to know - for my purposes, it would be > perfectly good enough to deal with the ascii portions and keep anything > else unchanged. So why let the data get into a "str" type at all? Do everything end to end with "bytes" or "bytearray" types. John Nagle From invalid at invalid.invalid Wed Mar 28 15:40:57 2012 From: invalid at invalid.invalid (Grant Edwards) Date: Wed, 28 Mar 2012 19:40:57 +0000 (UTC) Subject: "convert" string to bytes without changing data (encoding) References: <9tg21lFmo3U1@mid.dfncis.de> <9tg4qoFbfpU1@mid.dfncis.de> <9th0u8Fuf2U1@mid.dfncis.de> <4f7357d5$0$29981$c3e8da3$5496439d@news.astraweb.com> Message-ID: On 2012-03-28, Steven D'Aprano wrote: > On Wed, 28 Mar 2012 19:43:36 +0200, Peter Daum wrote: > >> The longer story of my question is: I am new to python (obviously), and >> since I am not familiar with either one, I thought it would be advisory >> to go for python 3.x. The biggest problem that I am facing is, that I am >> often dealing with data, that is basically text, but it can contain >> 8-bit bytes. > > All bytes are 8-bit, at least on modern hardware. I think you have to > go back to the 1950s to find 10-bit or 12-bit machines. Well, on anything likely to run Python that's true. There are modern DSP-oriented CPUs where a byte is 16 or 32 bits (and so is an int and a long, and a float and a double). >> As it seems, this would be far easier with python 2.x. > > It only seems that way until you try. It's easy as long as you deal with nothing but ASCII and Latin-1. ;) -- Grant Edwards grant.b.edwards Yow! Somewhere in Tenafly, at New Jersey, a chiropractor gmail.com is viewing "Leave it to Beaver"! From rridge at csclub.uwaterloo.ca Wed Mar 28 15:43:31 2012 From: rridge at csclub.uwaterloo.ca (Ross Ridge) Date: Wed, 28 Mar 2012 15:43:31 -0400 Subject: "convert" string to bytes without changing data (encoding) References: <9tg21lFmo3U1@mid.dfncis.de> <4f73504c$0$29981$c3e8da3$5496439d@news.astraweb.com> Message-ID: Evan Driscoll wrote: >So yes, you can say that pretending there's not a mapping of strings to >internal representation is silly, because there is. However, there's >nothing you can say about that mapping. I'm not the one labeling anything as being silly. I'm the one labeling the things as bullshit, and that's what you're doing here. I can in fact say what the internal byte string representation of strings is any given build of Python 3. Just because I can't say what it would be in an imaginary hypothetical implementation doesn't mean I can never say anything about it. Ross Ridge -- l/ // Ross Ridge -- The Great HTMU [oo][oo] rridge at csclub.uwaterloo.ca -()-/()/ http://www.csclub.uwaterloo.ca/~rridge/ db // From invalid at invalid.invalid Wed Mar 28 15:44:02 2012 From: invalid at invalid.invalid (Grant Edwards) Date: Wed, 28 Mar 2012 19:44:02 +0000 (UTC) Subject: "convert" string to bytes without changing data (encoding) References: <9tg21lFmo3U1@mid.dfncis.de> <4f73504c$0$29981$c3e8da3$5496439d@news.astraweb.com> Message-ID: On 2012-03-28, Prasad, Ramit wrote: > >>You can't generally just "deal with the ascii portions" without >>knowing something about the encoding. Say you encounter a byte >>greater than 127. Is it a single non-ASCII character, or is it the >>leading byte of a multi-byte character? If the next character is less >>than 127, is it an ASCII character, or a continuation of the previous >>character? For UTF-8 you could safely assume ASCII, but without >>knowing the encoding, there is no way to be sure. If you just assume >>it's ASCII and manipulate it as such, you could be messing up >>non-ASCII characters. > > Technically, ASCII goes up to 256 No, ASCII only defines 0-127. Values >=128 are not ASCII. >From https://en.wikipedia.org/wiki/ASCII: ASCII includes definitions for 128 characters: 33 are non-printing control characters (now mostly obsolete) that affect how text and space is processed and 95 printable characters, including the space (which is considered an invisible graphic). -- Grant Edwards grant.b.edwards Yow! Used staples are good at with SOY SAUCE! gmail.com From python at mrabarnett.plus.com Wed Mar 28 15:50:01 2012 From: python at mrabarnett.plus.com (MRAB) Date: Wed, 28 Mar 2012 20:50:01 +0100 Subject: "convert" string to bytes without changing data (encoding) In-Reply-To: <5B80DD153D7D744689F57F4FB69AF47409291BEC@SCACMX008.exchad.jpmchase.net> References: <9tg21lFmo3U1@mid.dfncis.de> <4f73504c$0$29981$c3e8da3$5496439d@news.astraweb.com> <5B80DD153D7D744689F57F4FB69AF47409291BEC@SCACMX008.exchad.jpmchase.net> Message-ID: <4F736B69.9080600@mrabarnett.plus.com> On 28/03/2012 20:02, Prasad, Ramit wrote: >> >The right way to convert bytes to strings, and vice versa, is via >> >encoding and decoding operations. >> >> If you want to dictate to the original poster the correct way to do >> things then you don't need to do anything more that. You don't need to >> pretend like Chris Angelico that there's isn't a direct mapping from >> the his Python 3 implementation's internal respresentation of strings >> to bytes in order to label what he's asking for as being "silly". > > It might be technically possible to recreate internal implementation, > or get the byte data. That does not mean it will make any sense or > be understood in a meaningful manner. I think Ian summarized it > very well: > >>You can't generally just "deal with the ascii portions" without >>knowing something about the encoding. Say you encounter a byte >>greater than 127. Is it a single non-ASCII character, or is it the >>leading byte of a multi-byte character? If the next character is less >>than 127, is it an ASCII character, or a continuation of the previous >>character? For UTF-8 you could safely assume ASCII, but without >>knowing the encoding, there is no way to be sure. If you just assume >>it's ASCII and manipulate it as such, you could be messing up >>non-ASCII characters. > > Technically, ASCII goes up to 256 but they are not A-z letters. > Technically, ASCII is 7-bit, so it goes up to 127. From joncle at googlemail.com Wed Mar 28 15:52:12 2012 From: joncle at googlemail.com (Jon Clements) Date: Wed, 28 Mar 2012 12:52:12 -0700 (PDT) Subject: Best way to structure data for efficient searching In-Reply-To: References: Message-ID: <26352843.1421.1332964332608.JavaMail.geo-discussion-forums@vbue17> On Wednesday, 28 March 2012 19:39:54 UTC+1, Larry.... at gmail.com wrote: > I have the following use case: > > I have a set of data that is contains 3 fields, K1, K2 and a > timestamp. There are duplicates in the data set, and they all have to > processed. > > Then I have another set of data with 4 fields: K3, K4, K5, and a > timestamp. There are also duplicates in that data set, and they also > all have to be processed. > > I need to find all the items in the second data set where K1==K3 and > K2==K4 and the 2 timestamps are within 20 seconds of each other. > > I have this working, but the way I did it seems very inefficient - I > simply put the data in 2 arrays (as tuples) and then walked through > the entire second data set once for each item in the first data set, > looking for matches. > > Is there a better, more efficient way I could have done this? It might not be more *efficient* but others might find it more readable, and it'd be easier to change later. Try an in-memory SQL DB (such as sqlite3) and query as (untested) select t2.* from t1 join t2 on k1=k3 and k2=k4 where abs(t1.timestamp - t2.timestamp) < 20 Failing that, two (default)dicts with a tuple as the pair, then use that as your base. Jon. From larry.martell at gmail.com Wed Mar 28 16:05:41 2012 From: larry.martell at gmail.com (Larry.Martell@gmail.com) Date: Wed, 28 Mar 2012 13:05:41 -0700 (PDT) Subject: Best way to structure data for efficient searching References: <26352843.1421.1332964332608.JavaMail.geo-discussion-forums@vbue17> Message-ID: <90d08585-361d-428e-a82d-c5005a6c4b5e@k24g2000yqe.googlegroups.com> On Mar 28, 1:52?pm, Jon Clements wrote: > On Wednesday, 28 March 2012 19:39:54 UTC+1, Larry.... at gmail.com ?wrote: > > I have the following use case: > > > I have a set of data that is contains 3 fields, K1, K2 and a > > timestamp. There are duplicates in the data set, and they all have to > > processed. > > > Then I have another set of data with 4 fields: K3, K4, K5, and a > > timestamp. There are also duplicates in that data set, and they also > > all have to be processed. > > > I need to find all the items in the second data set where K1==K3 and > > K2==K4 and the 2 timestamps are within 20 seconds of each other. > > > I have this working, but the way I did it seems very inefficient - I > > simply put the data in 2 arrays (as tuples) and then walked through > > the entire second data set once for each item in the first data set, > > looking for matches. > > > Is there a better, more efficient way I could have done this? > > It might not be more *efficient* but others might find it more readable, and it'd be easier to change later. Try an in-memory SQL DB (such as sqlite3) and query as (untested) > > select t2.* from t1 join t2 on k1=k3 and k2=k4 where abs(t1.timestamp - t2.timestamp) < 20 This is part of django app, and the data came from mysql. Through a mechanism I can't change at this time (it would take a lot of code changes and this new functionality is needed ASAP) I get all the data at once and have to winnow it down. > Failing that, two (default)dicts with a tuple as the pair, then use that as your base. Since there are duplicates, I can't use a dict. And if I have any extraneous data in the keys (i.e. something to make them unique) then I still have to walk through the entire dict to find the matches. From john_ladasky at sbcglobal.net Wed Mar 28 16:12:30 2012 From: john_ladasky at sbcglobal.net (John Ladasky) Date: Wed, 28 Mar 2012 13:12:30 -0700 (PDT) Subject: No os.copy()? Why not? Message-ID: <38b3fc48-1d05-4373-b32e-64da95173864@pz2g2000pbc.googlegroups.com> I'm looking for a Python (2.7) equivalent to the Unix "cp" command. Since the equivalents of "rm" and "mkdir" are in the os module, I figured I look there. I haven't found anything in the documentation. I am also looking through the Python source code in os.py and its child, posixfile.py. Any help? Thanks. From breamoreboy at yahoo.co.uk Wed Mar 28 16:44:14 2012 From: breamoreboy at yahoo.co.uk (Mark Lawrence) Date: Wed, 28 Mar 2012 21:44:14 +0100 Subject: "convert" string to bytes without changing data (encoding) In-Reply-To: References: <9tg21lFmo3U1@mid.dfncis.de> <4f73504c$0$29981$c3e8da3$5496439d@news.astraweb.com> Message-ID: On 28/03/2012 20:43, Ross Ridge wrote: > Evan Driscoll wrote: >> So yes, you can say that pretending there's not a mapping of strings to >> internal representation is silly, because there is. However, there's >> nothing you can say about that mapping. > > I'm not the one labeling anything as being silly. I'm the one labeling > the things as bullshit, and that's what you're doing here. I can in > fact say what the internal byte string representation of strings is any > given build of Python 3. Just because I can't say what it would be in > an imaginary hypothetical implementation doesn't mean I can never say > anything about it. > > Ross Ridge > Bytes is bytes and strings is strings And the wrong one I have chose Let's go where they keep on wearin' Those frills and flowers and buttons and bows Rings and things and buttons and bows. No guessing the tune. -- Cheers. Mark Lawrence. From neilc at norwich.edu Wed Mar 28 16:56:49 2012 From: neilc at norwich.edu (Neil Cerutti) Date: 28 Mar 2012 20:56:49 GMT Subject: "convert" string to bytes without changing data (encoding) References: <9tg21lFmo3U1@mid.dfncis.de> <4f73504c$0$29981$c3e8da3$5496439d@news.astraweb.com> Message-ID: <9thc8hFiu9U1@mid.individual.net> On 2012-03-28, Ross Ridge wrote: > Evan Driscoll wrote: >> So yes, you can say that pretending there's not a mapping of >> strings to internal representation is silly, because there is. >> However, there's nothing you can say about that mapping. > > I'm not the one labeling anything as being silly. I'm the one > labeling the things as bullshit, and that's what you're doing > here. I can in fact say what the internal byte string > representation of strings is any given build of Python 3. Just > because I can't say what it would be in an imaginary > hypothetical implementation doesn't mean I can never say > anything about it. I am in a similar situation viz a viz my wife's undergarments. -- Neil Cerutti From tjreedy at udel.edu Wed Mar 28 17:37:53 2012 From: tjreedy at udel.edu (Terry Reedy) Date: Wed, 28 Mar 2012 17:37:53 -0400 Subject: "convert" string to bytes without changing data (encoding) In-Reply-To: <9th0u8Fuf2U1@mid.dfncis.de> References: <9tg21lFmo3U1@mid.dfncis.de> <9tg4qoFbfpU1@mid.dfncis.de> <9th0u8Fuf2U1@mid.dfncis.de> Message-ID: On 3/28/2012 1:43 PM, Peter Daum wrote: > The longer story of my question is: I am new to python (obviously), and > since I am not familiar with either one, I thought it would be advisory > to go for python 3.x. I strongly agree with that unless you have reason to use 2.7. Python 3.3 (.0a1 in nearly out) has an improved unicode implementation, among other things. < The biggest problem that I am facing is, that I > am often dealing with data, that is basically text, but it can contain > 8-bit bytes. In this case, I can not safely assume any given encoding, > but I actually also don't need to know - for my purposes, it would be > perfectly good enough to deal with the ascii portions and keep anything > else unchanged. You are assuming, or must assume, that the text is in an ascii-compatible encoding, meaning that bytes 0-127 really represent ascii chars. Otherwise, you cannot reliably interpret anything, let alone change it. This problem of knowing that much but not the specific encoding is unfortunately common. It has been discussed among core developers and others the last few months. Different people prefer one of the following approaches. 1. Keep the bytes as bytes and use bytes literals and bytes functions as needed. The danger, as you noticed, is forgetting the 'b' prefix. 2. Decode as if the text were latin-1 and ignore the non-ascii 'latin-1' chars. When done, encode back to 'latin-1' and the non-ascii chars will be as they originally were. The danger is forgetting the pretense, and perhaps passing on the the string (as a string, not bytes) to other modules that will not know the pretense. 3. Decode using encoding = 'ascii', errors='surrogate_escape'. This reversibly encodes the unknown non-ascii chars as 'illegal' non-chars (using the surrogate-pair second-half code units). This is probably the safest in that invalid operations on the non-chars should raise an exception. Re-encoding with the same setting will reproduce the original hi-bit chars. The main danger is passing the illegal strings out of your local sandbox. -- Terry Jan Reedy From nambo4jb at gmail.com Wed Mar 28 17:48:35 2012 From: nambo4jb at gmail.com (Cathy James) Date: Wed, 28 Mar 2012 16:48:35 -0500 Subject: Need Help Using list items as output table names in MsACCESS Message-ID: Dear Python folks, I need your help on using list items as output table names in MsACCESS-new to Python- simple would be better: import arcpy, os outSpace = "c:\\data\\Info_Database.mdb\\" arcpy.overwriteOutput = True SQL = "Database Connections\\SDE_ReadOnly.sde\\" inFcList = [(SDE + "sde.GIS.Parcel"), (SDE + "sde.GIS.Residence"), (SDE + "sde.GIS.Park"), (SDE + "sde.GIS.Field"), (SDE + "sde.GIS.Business"), (SDE + "sde.GIS.Facility"), (SDE + "sde.GIS.Tertiary"), (SDE + "sde.GIS.KiddieClub")] #I'd like to crete output tables in the MDB whose names correspond to input names such that #"sde.GIS.Parcel" becomes "sde.GIS.Parcel_Buffer_500" for fc in inFcList: arcpy.overwriteOutput = True arcpy.Buffer_analysis(fc,(outSpace+fc+"_Buffer_500"), "500 Feet", "FULL", "ROUND", "ALL", "") print Finished #Thanks in advance From tolidtm at gmail.com Wed Mar 28 18:33:54 2012 From: tolidtm at gmail.com (Anatoli Hristov) Date: Thu, 29 Mar 2012 00:33:54 +0200 Subject: Advise of programming one of my first programs In-Reply-To: <5B80DD153D7D744689F57F4FB69AF4740928F779@SCACMX008.exchad.jpmchase.net> References: <5B80DD153D7D744689F57F4FB69AF4740928C365@SCACMX008.exchad.jpmchase.net> <5B80DD153D7D744689F57F4FB69AF4740928E137@SCACMX008.exchad.jpmchase.net> <5B80DD153D7D744689F57F4FB69AF4740928F779@SCACMX008.exchad.jpmchase.net> Message-ID: > You are correct it is not. :) You code is overly complex making it harder > to understand. Try and reduce the problem to the least number of tasks you > need. > >From the Zen of Python, "Simple is better than complex." It is a good > programming > mentality. Complex is better than complicated. :p > 2. A system to navigate your program. > def mmenu(): > # load tbook here > while True: > choicem = get_menu_choice() > if choicem == 'e' or choicem == 'E': > book = get_book_name() > edit( tbook, book ) > elif choicem == 'd' or choicem == 'D': > book = get_book_name() > details( tbook, book ) > elif choicem =='Q' or choicem == 'q': > break # end loop to exit program > else: > print 'Selection {0} not understood.'.format( choicem )I have > given you more functions With the main navigation menu I will only have the option to select a nickname and when a nickname is selected then it loads Details of the contact and from loaded details I can choice Edit or back to main screen, like I did it the first time, or else I can do it => when 'e' pressed to ask for a nickname and then edit it. > 3. function to write an edited book > def write_book(tbook): > write_book = open('c:/Python27/Toli/myfile.txt', 'w') > write_book.write(str(tbook)) > # I think repr would be more accurate than str here. > I`m not that far as you already know :) I hope I will learn everything as soon as I can as I`m not capable to read python everyday. > I do not think you need any other functions. Now you just need to finsh > all the functions > and put it all together. > I will finish it just need to understand more the functions and complex arguments. Thanks Anatoli -------------- next part -------------- An HTML attachment was scrubbed... URL: From tolidtm at gmail.com Wed Mar 28 18:36:06 2012 From: tolidtm at gmail.com (Anatoli Hristov) Date: Thu, 29 Mar 2012 00:36:06 +0200 Subject: Advise of programming one of my first programs In-Reply-To: <5B80DD153D7D744689F57F4FB69AF4740929109C@SCACMX008.exchad.jpmchase.net> References: <5B80DD153D7D744689F57F4FB69AF4740928C365@SCACMX008.exchad.jpmchase.net> <5B80DD153D7D744689F57F4FB69AF4740928E137@SCACMX008.exchad.jpmchase.net> <4F72385E.8020804@cs.wisc.edu> <5B80DD153D7D744689F57F4FB69AF4740929109C@SCACMX008.exchad.jpmchase.net> Message-ID: > > Um, at least by my understanding, the use of Pickle is also dangerous if > > you > > > are not completely sure what is being passed in: > > > > Oh goodness yes. pickle is exactly as unsafe as eval is. Try running this > > code: > > > > from pickle import loads > > loads("c__builtin__\neval\n(c__builtin__\nraw_input\n(S'py>'\ntRtR.") > > It might be as dangerous, but which is more likely to cause problems in > real world scenarios? Guys this is really something that is not that important at this time for me -------------- next part -------------- An HTML attachment was scrubbed... URL: From timothy.c.delaney at gmail.com Wed Mar 28 19:53:06 2012 From: timothy.c.delaney at gmail.com (Tim Delaney) Date: Thu, 29 Mar 2012 10:53:06 +1100 Subject: Number of languages known [was Re: Python is readable] - somewhat OT In-Reply-To: <4F6E60BC.1020600@tim.thechases.com> References: <4F6E60BC.1020600@tim.thechases.com> Message-ID: On 25 March 2012 11:03, Tim Chase wrote: > On 03/24/12 17:08, Tim Delaney wrote: > >> Absolutely. 10 years ago (when I was just a young lad) I'd say that I'd >> *forgotten* at least 20 programming languages. That number has only >> increased. >> > > And in the case of COBOL for me, it wasn't just forgotten, but actively > repressed ;-) > 2 weeks on work experience in year 10 (16 years old) was enough for me. Although I did have a functional book catalogue program by the end of it. Apparently the feedback was that if I'd wanted a job there I could have had one ... Tim Delaney -------------- next part -------------- An HTML attachment was scrubbed... URL: From steve+comp.lang.python at pearwood.info Wed Mar 28 20:02:37 2012 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 29 Mar 2012 00:02:37 GMT Subject: "convert" string to bytes without changing data (encoding) References: <9tg21lFmo3U1@mid.dfncis.de> <4f73504c$0$29981$c3e8da3$5496439d@news.astraweb.com> Message-ID: <4f73a69c$0$29981$c3e8da3$5496439d@news.astraweb.com> On Wed, 28 Mar 2012 15:43:31 -0400, Ross Ridge wrote: > I can in > fact say what the internal byte string representation of strings is any > given build of Python 3. Don't keep us in suspense! Given: Python 3.2.2 (default, Mar 4 2012, 10:50:33) [GCC 4.1.2 20080704 (Red Hat 4.1.2-51)] on linux2 what *is* the internal byte representation of the string "a???z"? (lowercase a, integral sign, copyright symbol, lowercase Greek pi, lowercase z) And more importantly, given that internal byte representation, what could you do with it? -- Steven From rosuav at gmail.com Wed Mar 28 20:07:47 2012 From: rosuav at gmail.com (Chris Angelico) Date: Thu, 29 Mar 2012 11:07:47 +1100 Subject: Advise of programming one of my first programs In-Reply-To: References: <5B80DD153D7D744689F57F4FB69AF4740928C365@SCACMX008.exchad.jpmchase.net> <5B80DD153D7D744689F57F4FB69AF4740928E137@SCACMX008.exchad.jpmchase.net> <4F72385E.8020804@cs.wisc.edu> <5B80DD153D7D744689F57F4FB69AF4740929109C@SCACMX008.exchad.jpmchase.net> Message-ID: Thu, Mar 29, 2012 at 9:36 AM, Anatoli Hristov wrote: >> > > Um, at least by my understanding, the use of Pickle is also dangerous >> > > if you are not completely sure what is being passed in: >> > >> > Oh goodness yes. pickle is exactly as unsafe as eval is. Try running >> > this code: >> > >> > from pickle import loads >> > loads("c__builtin__\neval\n(c__builtin__\nraw_input\n(S'py>'\ntRtR.") >> >> It might be as dangerous, but which is more likely to cause problems in >> real world scenarios? > > Guys this is really something ?that is not that important at this time for > me Maybe not, but it's still worth being aware of. Even if today your strings will never include apostrophes, it's still important to understand the risks of SQL injection and properly escape them before inserting them into an SQL statement. Just docket the information in the back of your mind "Don't use pickle with untrusted data" and move on. :) ChrisA From driscoll at cs.wisc.edu Wed Mar 28 20:11:56 2012 From: driscoll at cs.wisc.edu (Evan Driscoll) Date: Wed, 28 Mar 2012 19:11:56 -0500 Subject: "convert" string to bytes without changing data (encoding) In-Reply-To: References: <9tg21lFmo3U1@mid.dfncis.de> <4f73504c$0$29981$c3e8da3$5496439d@news.astraweb.com> Message-ID: <4F73A8CC.4090107@cs.wisc.edu> On 3/28/2012 14:43, Ross Ridge wrote: > Evan Driscoll wrote: >> So yes, you can say that pretending there's not a mapping of strings to >> internal representation is silly, because there is. However, there's >> nothing you can say about that mapping. > > I'm not the one labeling anything as being silly. I'm the one labeling > the things as bullshit, and that's what you're doing here. I can in > fact say what the internal byte string representation of strings is any > given build of Python 3. Just because I can't say what it would be in > an imaginary hypothetical implementation doesn't mean I can never say > anything about it. People like you -- who write to assumptions which are not even remotely guaranteed by the spec -- are part of the reason software sucks. People like you hold back progress, because system implementers aren't free to make changes without breaking backwards compatibility. Enormous amounts of effort are expended to test programs and diagnose problems which are caused by unwarranted assumptions like "the encoding of a string is UTF-8". In the worst case, assumptions like that lead to security fixes that don't go as far as they could, like the recent discussion about hashing. Python is definitely closer to the "willing to break backwards compatibility to improve" end of the spectrum than some other projects (*cough* Windows *cough*), but that still doesn't mean that you can make assumptions like that. This email is a bit harsher than it deserves -- but I feel not by much. Evan From rodrick.brown at gmail.com Wed Mar 28 20:59:14 2012 From: rodrick.brown at gmail.com (Rodrick Brown) Date: Wed, 28 Mar 2012 20:59:14 -0400 Subject: Number of languages known [was Re: Python is readable] - somewhat OT In-Reply-To: References: Message-ID: At my current firm we hire people who are efficient in one of the following and familiar with any another C#, Java, C++, Perl, Python or Ruby. We then expect developers to quickly pick up any of the following languages we use in house which is very broad. In our source repository not including the languages I've already stated above I've seen Fortran, Erlang, Groovy, HTML, CSS, JavaScript, Mathlab, C, K, R, S, Q, Excel, PHP, Bash, Ksh, PowerShell, Ruby, and Cuda. We do heavy computational and statistical analysis type work so developers need to be able to use a vast army of programming tools to tackle the various work loads were faced with on a daily basis. The best skill any developer can have is the ability to pickup languages very quickly and know what tools work well for which task. On Mar 22, 2012, at 3:14 PM, Chris Angelico wrote: > On Fri, Mar 23, 2012 at 4:44 AM, Steven D'Aprano > wrote: >> The typical developer knows three, maybe four languages >> moderately well, if you include SQL and regexes as languages, and might >> have a nodding acquaintance with one or two more. > > I'm not entirely sure what you mean by "moderately well", nor > "languages", but I'm of the opinion that a good developer should be > able to learn a new language very efficiently. Do you count Python 2 > and 3 as the same language? What about all the versions of the C > standard? > > In any case, though, I agree that there's a lot of people > professionally writing code who would know about the 3-4 that you say. > I'm just not sure that they're any good at coding, even in those few > languages. All the best people I've ever known have had experience > with quite a lot of languages. > > ChrisA > -- > http://mail.python.org/mailman/listinfo/python-list From rosuav at gmail.com Wed Mar 28 21:33:38 2012 From: rosuav at gmail.com (Chris Angelico) Date: Thu, 29 Mar 2012 12:33:38 +1100 Subject: Number of languages known [was Re: Python is readable] - somewhat OT In-Reply-To: References: Message-ID: On Thu, Mar 29, 2012 at 11:59 AM, Rodrick Brown wrote: > The best skill any developer can have is the ability to pickup languages very quickly and know what tools work well for which task. Definitely. Not just languages but all tools. The larger your toolkit and the better you know it, the more easily you'll be able to grasp the tool you need. ChrisA From ben+python at benfinney.id.au Wed Mar 28 21:55:13 2012 From: ben+python at benfinney.id.au (Ben Finney) Date: Thu, 29 Mar 2012 12:55:13 +1100 Subject: unittest: assertRaises() with an instance instead of a type References: <4f735345$0$29981$c3e8da3$5496439d@news.astraweb.com> Message-ID: <87mx70f9xa.fsf@benfinney.id.au> Steven D'Aprano writes: > (By the way, I have to question the design of an exception with error > codes. That seems pretty poor design to me. Normally the exception *type* > acts as equivalent to an error code.) Have a look at Python's built-in OSError. The various errors from the operating system can only be distinguished by the numeric code the OS returns, so that's what to test on in one's unit tests. -- \ ?In the long run, the utility of all non-Free software | `\ approaches zero. All non-Free software is a dead end.? ?Mark | _o__) Pilgrim, 2006 | Ben Finney From rridge at csclub.uwaterloo.ca Wed Mar 28 23:04:08 2012 From: rridge at csclub.uwaterloo.ca (Ross Ridge) Date: Wed, 28 Mar 2012 23:04:08 -0400 Subject: "convert" string to bytes without changing data (encoding) References: <9tg21lFmo3U1@mid.dfncis.de> Message-ID: Evan Driscoll wrote: >People like you -- who write to assumptions which are not even remotely >guaranteed by the spec -- are part of the reason software sucks. ... >This email is a bit harsher than it deserves -- but I feel not by much. I don't see how you could feel the least bit justified. Well meaning, if unhelpful, lies about the nature Python strings in order to try to convince someone to follow what you think are good programming practices is one thing. Maliciously lying about someone else's code that you've never seen is another thing entirely. Ross Ridge -- l/ // Ross Ridge -- The Great HTMU [oo][oo] rridge at csclub.uwaterloo.ca -()-/()/ http://www.csclub.uwaterloo.ca/~rridge/ db // From rosuav at gmail.com Wed Mar 28 23:31:59 2012 From: rosuav at gmail.com (Chris Angelico) Date: Thu, 29 Mar 2012 14:31:59 +1100 Subject: "convert" string to bytes without changing data (encoding) In-Reply-To: References: <9tg21lFmo3U1@mid.dfncis.de> Message-ID: On Thu, Mar 29, 2012 at 2:04 PM, Ross Ridge wrote: > Evan Driscoll ? wrote: >>People like you -- who write to assumptions which are not even remotely >>guaranteed by the spec -- are part of the reason software sucks. > ... >>This email is a bit harsher than it deserves -- but I feel not by much. > > I don't see how you could feel the least bit justified. ?Well meaning, > if unhelpful, lies about the nature Python strings in order to try to > convince someone to follow what you think are good programming practices > is one thing. ?Maliciously lying about someone else's code that you've > never seen is another thing entirely. Actually, he is justified. It's one thing to work in C or assembly and write code that depends on certain bit-pattern representations of data (although even that causes trouble - assuming that sizeof(int)==sizeof(int*) isn't good for portability), but in a high level language, you cannot assume any correlation between objects and bytes. Any code that depends on implementation details is risky. ChrisA From hungnv at at4a.com Wed Mar 28 23:36:13 2012 From: hungnv at at4a.com (Nguyen Van Hung) Date: Thu, 29 Mar 2012 03:36:13 -0000 Subject: Nhung dieu ban can biet Message-ID: thanks, -------------- next part -------------- An HTML attachment was scrubbed... URL: From rridge at csclub.uwaterloo.ca Wed Mar 28 23:58:53 2012 From: rridge at csclub.uwaterloo.ca (Ross Ridge) Date: Wed, 28 Mar 2012 23:58:53 -0400 Subject: "convert" string to bytes without changing data (encoding) References: <9tg21lFmo3U1@mid.dfncis.de> Message-ID: Chris Angelico wrote: >Actually, he is justified. It's one thing to work in C or assembly and >write code that depends on certain bit-pattern representations of data >(although even that causes trouble - assuming that >sizeof(int)=3D=3Dsizeof(int*) isn't good for portability), but in a high >level language, you cannot assume any correlation between objects and >bytes. Any code that depends on implementation details is risky. How does that in anyway justify Evan Driscoll maliciously lying about code he's never seen? Ross Ridge -- l/ // Ross Ridge -- The Great HTMU [oo][oo] rridge at csclub.uwaterloo.ca -()-/()/ http://www.csclub.uwaterloo.ca/~rridge/ db // From wuwei23 at gmail.com Thu Mar 29 00:50:52 2012 From: wuwei23 at gmail.com (alex23) Date: Wed, 28 Mar 2012 21:50:52 -0700 (PDT) Subject: No os.copy()? Why not? References: <38b3fc48-1d05-4373-b32e-64da95173864@pz2g2000pbc.googlegroups.com> Message-ID: <20bc37f2-9eac-47f0-9ab2-150da6ca203b@mq9g2000pbb.googlegroups.com> On Mar 29, 6:12?am, John Ladasky wrote: > I'm looking for a Python (2.7) equivalent to the Unix "cp" command. > Any help? ?Thanks. Try the shutil module: http://docs.python.org/library/shutil.html From jmwebaze at gmail.com Thu Mar 29 01:44:07 2012 From: jmwebaze at gmail.com (J. Mwebaze) Date: Thu, 29 Mar 2012 07:44:07 +0200 Subject: CFG for python Message-ID: Anyone knows how to create control-flow-graph for python.. After searching around, i found this article, http://www.python.org/dev/peps/pep-0339/#ast-to-cfg-to-bytecode and also a reference to http://doc.pypy.org/en/latest/objspace.html#the-flow-model However, i stil cant figure out what how to create the CFG from the two references. Regards -- *Mob UG: +256 (0) 70 1735800 | NL +31 (0) 6 852 841 38 | Gtalk: jmwebaze | skype: mwebazej | URL: www.astro.rug.nl/~jmwebaze /* Life runs on code */* -------------- next part -------------- An HTML attachment was scrubbed... URL: From showell30 at yahoo.com Thu Mar 29 01:50:44 2012 From: showell30 at yahoo.com (Steve Howell) Date: Wed, 28 Mar 2012 22:50:44 -0700 (PDT) Subject: unittest: assertRaises() with an instance instead of a type References: <4f735345$0$29981$c3e8da3$5496439d@news.astraweb.com> <87mx70f9xa.fsf@benfinney.id.au> Message-ID: On Mar 28, 6:55?pm, Ben Finney wrote: > Steven D'Aprano writes: > > (By the way, I have to question the design of an exception with error > > codes. That seems pretty poor design to me. Normally the exception *type* > > acts as equivalent to an error code.) > > Have a look at Python's built-in OSError. The various errors from the > operating system can only be distinguished by the numeric code the OS > returns, so that's what to test on in one's unit tests. > To the extent that numeric error codes are poor design (see Steven's comment) but part of the language (see Ben's comment), it may be worthwhile to consider a pattern like below. Let's say you have a function like save_config, where you know that permissions might be an issue on some systems, but you don't want to take any action (leave that to the callers). In those cases, it might be worthwhile to test for the specific error code (13), but then translate it to a more domain-specific exception. This way, all your callers can trap for a much more specific exception than OSError. Writing the test code for save_config still presents some of the issues that the OP alluded to, but then other parts of the system can be tested with simple assertRaises(). import os class ConfigPermissionError: pass def save_config(config): try: dir = os.mkdir('/config') except OSError, e: if e[0] == 13: raise ConfigPermissionError() else: raise fn = os.path.join(dir, 'config.txt') f = open(fn, 'w') # and so on... try: save_config({'port': 500}) except ConfigPermissionError: # do some workaround here print 'Config not saved due to permissions' From breamoreboy at yahoo.co.uk Thu Mar 29 02:01:14 2012 From: breamoreboy at yahoo.co.uk (Mark Lawrence) Date: Thu, 29 Mar 2012 07:01:14 +0100 Subject: "convert" string to bytes without changing data (encoding) In-Reply-To: References: <9tg21lFmo3U1@mid.dfncis.de> Message-ID: On 29/03/2012 04:58, Ross Ridge wrote: > Chris Angelico wrote: >> Actually, he is justified. It's one thing to work in C or assembly and >> write code that depends on certain bit-pattern representations of data >> (although even that causes trouble - assuming that >> sizeof(int)=3D=3Dsizeof(int*) isn't good for portability), but in a high >> level language, you cannot assume any correlation between objects and >> bytes. Any code that depends on implementation details is risky. > > How does that in anyway justify Evan Driscoll maliciously lying about > code he's never seen? > > Ross Ridge > We appear to have a case of "would you stand up please, your voice is rather muffled". I can hear all the *plonks* from miles away. -- Cheers. Mark Lawrence. From steve+comp.lang.python at pearwood.info Thu Mar 29 02:35:20 2012 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 29 Mar 2012 06:35:20 GMT Subject: unittest: assertRaises() with an instance instead of a type References: <4f735345$0$29981$c3e8da3$5496439d@news.astraweb.com> <87mx70f9xa.fsf@benfinney.id.au> Message-ID: <4f7402a8$0$29884$c3e8da3$5496439d@news.astraweb.com> On Thu, 29 Mar 2012 12:55:13 +1100, Ben Finney wrote: > Steven D'Aprano writes: > >> (By the way, I have to question the design of an exception with error >> codes. That seems pretty poor design to me. Normally the exception >> *type* acts as equivalent to an error code.) > > Have a look at Python's built-in OSError. The various errors from the > operating system can only be distinguished by the numeric code the OS > returns, so that's what to test on in one's unit tests. I'm familiar with OSError. It is necessary because OSError is a high- level interface to low-level C errors. I wouldn't call it a good design though, I certainly wouldn't choose it if we were developing an error system from scratch and weren't constrained by compatibility with a more primitive error model (error codes instead of exceptions). The new, revamped exception hierarchy in Python 3.3 will rationalise much (but not all) for this, unifying IOError and OSError and making error codes much less relevant: http://www.python.org/dev/peps/pep-3151/ -- Steven From startupcity397 at gmail.com Thu Mar 29 02:47:32 2012 From: startupcity397 at gmail.com (Sridevi V) Date: Wed, 28 Mar 2012 23:47:32 -0700 (PDT) Subject: A must read: Is MBA critical for techies to shape their career Message-ID: <7974e55e-ffcd-4809-99e8-cf2741551bf4@oq7g2000pbb.googlegroups.com> Hi, I was curious to find out about the job trends for fresh graduates and if an MBA will help me find even better job, when I came across these two articles on a website. It gave me some startling trends that are being followed in industry. A must read for all. It helped me and I thought it might help you as well. Winning, The Azim Premji Way Azim Hashim Premji, a supernova in the Indian IT industry is one of the most revered names in the tech scenario of all time. His words of wisdom will surely prove to e a winning streak to most of us http://bit.ly/WinningAzim The Unwanted Tech Kids Youth in our country considered as the future representatives of the nation at the global level, don?t you think they must be given good opportunities to showcase their talents and utilize their skills at their best level to help the country?s economic growth? http://bit.ly/TechKids Do Techies Need an M.B.A? We generally think that an MBA degree is a must to climb the corporate ladder in order to reach the zenith of success. http://bit.ly/TechiesNeedMBA Thank You, please do feel free to comment if you felt this was helpful From steve+comp.lang.python at pearwood.info Thu Mar 29 02:51:51 2012 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 29 Mar 2012 06:51:51 GMT Subject: "convert" string to bytes without changing data (encoding) References: <9tg21lFmo3U1@mid.dfncis.de> Message-ID: <4f740687$0$29884$c3e8da3$5496439d@news.astraweb.com> On Wed, 28 Mar 2012 23:58:53 -0400, Ross Ridge wrote: > How does that in anyway justify Evan Driscoll maliciously lying about > code he's never seen? You are perfectly justified to complain about Evan making sweeping generalisations about your code when he has not seen it; you are NOT justified in making your own sweeping generalisations that he is not just lying but *maliciously* lying. He might be just confused by the strength of his emotions and so making an honest mistake. Or he might have guessed perfectly accurately about your code, and you are the one being dishonest. Who knows? Evan's impassioned rant is based on his estimate of your mindset, namely that you are the sort of developer who writes code making assumptions about implementation details even when explicitly told not to by the library authors. I have no idea whether Evan's estimate is right or not, but I don't think it is justified based on the little amount we've seen of you. Your reaction is to make an equally unjustified estimate of Evan's mindset, namely that he is not just wrong about you, but *deliberately and maliciously* lying about you in the full knowledge that he is wrong. If anything, I would say that you have less justification for calling Evan a malicious liar than he has for calling you the sort of person who would write to an implementation instead of an interface. -- Steven From __peter__ at web.de Thu Mar 29 02:55:53 2012 From: __peter__ at web.de (Peter Otten) Date: Thu, 29 Mar 2012 08:55:53 +0200 Subject: unittest: assertRaises() with an instance instead of a type References: <4f735345$0$29981$c3e8da3$5496439d@news.astraweb.com> <87mx70f9xa.fsf@benfinney.id.au> Message-ID: Ben Finney wrote: > Steven D'Aprano writes: > >> (By the way, I have to question the design of an exception with error >> codes. That seems pretty poor design to me. Normally the exception *type* >> acts as equivalent to an error code.) > > Have a look at Python's built-in OSError. The various errors from the > operating system can only be distinguished by the numeric code the OS > returns, so that's what to test on in one's unit tests. The core devs are working to fix that: $ python3.2 -c'open("does-not-exist")' Traceback (most recent call last): File "", line 1, in IOError: [Errno 2] No such file or directory: 'does-not-exist' $ python3.3 -c'open("does-not-exist")' Traceback (most recent call last): File "", line 1, in FileNotFoundError: [Errno 2] No such file or directory: 'does-not-exist' $ python3.2 -c'open("unwritable", "w")' Traceback (most recent call last): File "", line 1, in IOError: [Errno 13] Permission denied: 'unwritable' $ python3.3 -c'open("unwritable", "w")' Traceback (most recent call last): File "", line 1, in PermissionError: [Errno 13] Permission denied: 'unwritable' http://www.python.org/dev/peps/pep-3151/ From ulrich.eckhardt at dominolaser.com Thu Mar 29 03:08:30 2012 From: ulrich.eckhardt at dominolaser.com (Ulrich Eckhardt) Date: Thu, 29 Mar 2012 09:08:30 +0200 Subject: unittest: assertRaises() with an instance instead of a type In-Reply-To: <4f735345$0$29981$c3e8da3$5496439d@news.astraweb.com> References: <4f735345$0$29981$c3e8da3$5496439d@news.astraweb.com> Message-ID: Am 28.03.2012 20:07, schrieb Steven D'Aprano: > First off, that is not Python code. "catch Exception" gives a syntax > error. Old C++ habits... :| > Secondly, that is not the right way to do this unit test. You are testing > two distinct things, so you should write it as two separate tests: [..code..] > If foo does *not* raise an exception, the unittest framework will handle > the failure for you. If it raises a different exception, the framework > will also handle that too. > > Then write a second test to check the exception code: [...] > Again, let the framework handle any unexpected cases. Sorry, you got it wrong, it should be three tests: 1. Make sure foo() raises an exception. 2. Make sure foo() raises the right exception. 3. Make sure the errorcode in the exception is right. Or maybe you should in between verify that the exception raised actually contains an errorcode? And that the errorcode can be equality-compared to the expected value? :> Sorry, I disagree that these steps should be separated. It would blow up the code required for testing, increasing maintenance burdens. Which leads back to a solution that uses a utility function, like the one you suggested or the one I was looking for initially. > (By the way, I have to question the design of an exception with error > codes. That seems pretty poor design to me. Normally the exception *type* > acts as equivalent to an error code.) True. Normally. I'd adapting to a legacy system though, similar to OSError, and that system simply emits error codes which the easiest way to handle is by wrapping them. Cheers! Uli From ulrich.eckhardt at dominolaser.com Thu Mar 29 03:18:24 2012 From: ulrich.eckhardt at dominolaser.com (Ulrich Eckhardt) Date: Thu, 29 Mar 2012 09:18:24 +0200 Subject: tabs/spaces (was: Re: unittest: assertRaises() with an instance instead of a type) In-Reply-To: References: Message-ID: <0ved49-hie.ln1@satorlaser.homedns.org> Am 28.03.2012 20:26, schrieb Terry Reedy: > On 3/28/2012 8:28 AM, Ulrich Eckhardt wrote: [...] >> # call testee and verify results >> try: >> ...call function here... >> except exception_type as e: >> if not exception is None: >> self.assertEqual(e, exception) > > Did you use tabs? They do not get preserved indefinitely, so they are > bad for posting. I didn't consciously use tabs, actually I would rather avoid them. That said, my posting looks correctly indented in my "sent" folder and also in the copy received from my newsserver. What could also have an influence is line endings. I'm using Thunderbird on win32 here, acting as news client to comp.lang.python. Or maybe it's your software (or maybe some software in between) that fails to preserve formatting. *shrug* Uli From ulrich.eckhardt at dominolaser.com Thu Mar 29 03:28:15 2012 From: ulrich.eckhardt at dominolaser.com (Ulrich Eckhardt) Date: Thu, 29 Mar 2012 09:28:15 +0200 Subject: unittest: assertRaises() with an instance instead of a type In-Reply-To: References: Message-ID: Am 28.03.2012 20:26, schrieb Terry Reedy: > On 3/28/2012 8:28 AM, Ulrich Eckhardt wrote: >> with self.assertRaises(MyException(SOME_FOO_ERROR)): >> foo() > > I presume that if this worked the way you want, all attributes would > have to match. The message part of builtin exceptions is allowed to > change, so hard-coding an exact expected message makes tests fragile. > This is a problem with doctest. I would have assumed that comparing two exceptions leaves out messages that are intended for the user, not as part of the API. However, my expectations aren't met anyway, because ... >> This of course requires the exception to be equality-comparable. > > Equality comparison is by id. So this code will not do what you want. >>> Exception('foo') == Exception('foo') False Yikes! That was unexpected and completely changes my idea. Any clue whether this is intentional? Is identity the fallback when no equality is defined for two objects? Thanks for your feedback! Uli From __peter__ at web.de Thu Mar 29 03:48:37 2012 From: __peter__ at web.de (Peter Otten) Date: Thu, 29 Mar 2012 09:48:37 +0200 Subject: unittest: assertRaises() with an instance instead of a type References: <4f735345$0$29981$c3e8da3$5496439d@news.astraweb.com> Message-ID: Ulrich Eckhardt wrote: > True. Normally. I'd adapting to a legacy system though, similar to > OSError, and that system simply emits error codes which the easiest way > to handle is by wrapping them. If you have err = some_func() if err: raise MyException(err) the effort to convert it to exc = lookup_exception(some_func()) if exc: raise exc is small. A fancy way is to use a decorator: #untested def code_to_exception(table): def deco(f): def g(*args, **kw): err = f(*args, **kw) exc = table[err] if exc is not None: raise exc return g return f class MyError(Exception): pass class HyperspaceBypassError(MyError): pass @code_to_exception({42: HyperspaceBypassError, 0: None}) def some_func(...): # ... From luch at ank-sia.com Thu Mar 29 06:49:16 2012 From: luch at ank-sia.com (Alexey Luchko) Date: Thu, 29 Mar 2012 13:49:16 +0300 Subject: errors building python 2.7.3 In-Reply-To: <4F72FAF9.8000802@ank-sia.com> References: <4F72FAF9.8000802@ank-sia.com> Message-ID: <4F743E2C.1090207@ank-sia.com> JFI Reported as http://bugs.python.org/issue14437 http://bugs.python.org/issue14438 -- Regars, Alex From luch at ank-sia.com Thu Mar 29 06:55:42 2012 From: luch at ank-sia.com (Alexey Luchko) Date: Thu, 29 Mar 2012 13:55:42 +0300 Subject: errors building python 2.7.3 In-Reply-To: References: <4F72FAF9.8000802@ank-sia.com> Message-ID: <4F743FAE.4070909@ank-sia.com> On 28.03.2012 18:42, David Robinow wrote: > On Wed, Mar 28, 2012 at 7:50 AM, Alexey Luchko wrote: >> I've tried to build Python 2.7.3rc2 on cygwin and got the following errors: >> >> $ CFLAGS=-I/usr/include/ncursesw/ CPPFLAGS=-I/usr/include/ncursesw/ >> ./configure > I haven't tried 2.7.3 yet, so I'll describe my experience with 2.7.2 > I use /usr/include/ncurses rather than /usr/include/ncursesw > I don't remember what the difference is but ncurses seems to work. I've tried ncurses too. It does not matter. -- Alex From mikprog at gmail.com Thu Mar 29 08:33:45 2012 From: mikprog at gmail.com (Mik) Date: Thu, 29 Mar 2012 05:33:45 -0700 (PDT) Subject: weird behaviour: pygame plays in shell but not in script Message-ID: <7ef60ccc-c0bb-4aa8-a393-469883897058@k24g2000yqe.googlegroups.com> Dear all, I am a bit frustrated by the following as I believe it is something silly that I am not able to see. I am using python 2.7.1+ under ubuntu. When I run the following script as in $python script.py I do not get any sound out of it BUT if I run every line in the python shell it works great. It doesn't make sense to me, maybe someone has a clue? Thanks for any clue! Mik import pygame #done twice to get rid of a sound card error pygame.mixer.init() pygame.mixer.init() pygame.mixer.pre_init(44100, -16, 2, 2048) pygame.init() # called twice to make it so that it detects sound card pygame.init() print "init" sounds = [] sounds.append(pygame.mixer.Sound("../audio/song01.wav")) sounds.append(pygame.mixer.Sound("../audio/song02.wav")) sounds.append(pygame.mixer.Sound("../audio/song03.wav")) sounds.append(pygame.mixer.Sound("../audio/song04.wav")) for sound in sounds: print ".." sound.play() From mikprog at gmail.com Thu Mar 29 08:41:59 2012 From: mikprog at gmail.com (Mik) Date: Thu, 29 Mar 2012 05:41:59 -0700 (PDT) Subject: weird behaviour: pygame plays in shell but not in script References: <7ef60ccc-c0bb-4aa8-a393-469883897058@k24g2000yqe.googlegroups.com> Message-ID: I can't believe I am so dumb! after sound.play() the script was terminating!!!! I didn't notice that 'play()' actually returns... What a nice way to introduce myself to the group!!! :-) sorry for bothering you guys :-) From roy at panix.com Thu Mar 29 08:49:59 2012 From: roy at panix.com (Roy Smith) Date: Thu, 29 Mar 2012 08:49:59 -0400 Subject: tabs/spaces (was: Re: unittest: assertRaises() with an instance instead of a type) References: <0ved49-hie.ln1@satorlaser.homedns.org> Message-ID: In article <0ved49-hie.ln1 at satorlaser.homedns.org>, Ulrich Eckhardt wrote: > I didn't consciously use tabs, actually I would rather avoid them. That > said, my posting looks correctly indented in my "sent" folder and also > in the copy received from my newsserver. What could also have an > influence is line endings. I'm using Thunderbird on win32 here, acting > as news client to comp.lang.python. Or maybe it's your software (or > maybe some software in between) that fails to preserve formatting. > > *shrug* Oh noes! The line eater bug is back! From nathan.alexander.rice at gmail.com Thu Mar 29 09:44:09 2012 From: nathan.alexander.rice at gmail.com (Nathan Rice) Date: Thu, 29 Mar 2012 09:44:09 -0400 Subject: Number of languages known [was Re: Python is readable] - somewhat OT In-Reply-To: References: Message-ID: On Wed, Mar 28, 2012 at 9:33 PM, Chris Angelico wrote: > On Thu, Mar 29, 2012 at 11:59 AM, Rodrick Brown wrote: >> The best skill any developer can have is the ability to pickup languages very quickly and know what tools work well for which task. > > Definitely. Not just languages but all tools. The larger your toolkit > and the better you know it, the more easily you'll be able to grasp > the tool you need. The thing that bothers me is that people spend time and mental energy on a wide variety of syntax when the semantics are ~90% identical in most cases (up to organization). We would be better off if all the time that was spent on learning syntax, memorizing library organization and becoming proficient with new tools was spent learning the mathematics, logic and engineering sciences. Those solve problems, languages are just representations. Unfortunately, programming languages seem to have become a way to differentiate yourself and establish sub-cultural membership. All the cool kids are using XYZ, people who use LMN are dorks! Who cares about sharing or compatibility! Human nature is depressingly self-defeating. From albert at spenarnc.xs4all.nl Thu Mar 29 09:44:25 2012 From: albert at spenarnc.xs4all.nl (Albert van der Horst) Date: 29 Mar 2012 13:44:25 GMT Subject: Python is readable References: <4f612b19$0$1379$4fafbaef@reader2.news.tin.it> Message-ID: In article , Nathan Rice wrote: >> >> http://www.joelonsoftware.com/articles/fog0000000018.html > >I read that article a long time ago, it was bullshit then, it is >bullshit now. The only thing he gets right is that the Shannon >information of a uniquely specified program is proportional to the >code that would be required to generate it. Never mind that if a Thank you for drawing my attention to that article. It attacks the humbug software architects. Are you one of them? I really liked that article. >program meets a specification, you shouldn't care about any of the >values used for unspecified parts of the program. If you care about >the values, they should be specified. So, if Joel had said that the >program was uniquely specified, or that none of the things that >weren't specified require values in the programming language, he might >have been kinda, sorta right. Of course, nobody cares enough to >specify every last bit of minutiae in a program, and specifications >change, so it is pretty much impossible to imagine either case ever >actually occurring. I wonder if you're not talking about a different article. Groetjes Albert -- -- Albert van der Horst, UTRECHT,THE NETHERLANDS Economic growth -- being exponential -- ultimately falters. albert at spe&ar&c.xs4all.nl &=n http://home.hccnet.nl/a.w.m.van.der.horst From edreamleo at gmail.com Thu Mar 29 09:58:38 2012 From: edreamleo at gmail.com (Edward K. Ream) Date: Thu, 29 Mar 2012 06:58:38 -0700 (PDT) Subject: ANN: Leo 4.10 final released Message-ID: <804eb1fc-be4a-4608-9e9b-42eed8ec1a2d@k4g2000yqa.googlegroups.com> Leo 4.10 final is now available at: http://sourceforge.net/projects/leo/files/Leo/4.10%20final/ Leo is a text editor, data organizer, project manager and much more. http://webpages.charter.net/edreamleo/intro.html Leo 4.10 contains 9 months of intense work on Leo. Several very important features are subtle; you could almost call them Easter Eggs, so please read the following notes carefully. The highlights of Leo 4.10: -------------------------- * Dozens of new and improved features and commands, including... - Tab completion now shows all @command & @button nodes. - Leo tabs may be detached from the main window. - The Open With menu now works. - The leoInspect module answers questions about Python code. - Leo can highlight the pane containing the focus. - The bigdash plugin searches across multiple files. - Improved abbreviation capabilities. - Improved handling of URL's. - Improved editing of non-Leo files. - Improvements create "weightless" unit testing. - Improved Leo's home page. * Easier installation on MacOS. * Fixed almost 70 bugs. The Easter Eggs --------------- 1. Tab completion now shows all @command & @button nodes. Put all your common scripts in @command nodes in myLeoSettings.leo. Typing @c will remind you of the names of these scripts. You can execute the scripts by name without the "@command-" prefix. 2. Improved abbreviation capabilities. Virtually any kind of abbreviation is possible. For example, ~a to ?. 3. Improved handling of URL's. URL's can be used as links to other Leo outlines. 4 Weightless unit testing. The mantra is edit, alt-4 (run-marked-unit-tests-externally), edit, alt-4,... Several seemingly innocuous changes made this work without "friction". The result is a remarkable increase in productivity. Links: ------ Leo: http://webpages.charter.net/edreamleo/front.html Forum: http://groups.google.com/group/leo-editor Download: http://sourceforge.net/projects/leo/files/Leo/4.10%20final/ Bzr: http://code.launchpad.net/leo-editor/ Quotes: http://webpages.charter.net/edreamleo/testimonials.html Edward K. Ream ------------------------------------------------------------------------------ Edward K. Ream email: edreamleo at gmail.com Leo: http://webpages.charter.net/edreamleo/front.html ------------------------------------------------------------------------------ From rosuav at gmail.com Thu Mar 29 10:03:14 2012 From: rosuav at gmail.com (Chris Angelico) Date: Fri, 30 Mar 2012 01:03:14 +1100 Subject: Number of languages known [was Re: Python is readable] - somewhat OT In-Reply-To: References: Message-ID: On Fri, Mar 30, 2012 at 12:44 AM, Nathan Rice wrote: > We would be better off if all the time that was spent on learning > syntax, memorizing library organization and becoming proficient with > new tools was spent learning the mathematics, logic and engineering > sciences. ?Those solve problems, languages are just representations. Different languages are good at different things. REXX is an efficient text parser and command executor. Pike allows live updates of running code. Python promotes rapid development and simplicity. PHP makes it easy to add small amounts of scripting to otherwise-static HTML pages. C gives you all the power of assembly language with all the readability of... assembly language. SQL describes a database request. You can't merge all of them without making a language that's suboptimal at most of those tasks - probably, one that's woeful at all of them. I mention SQL because, even if you were to unify all programming languages, you'd still need other non-application languages to get the job done. Keep the diversity and let each language focus on what it's best at. ChrisA who has lots and lots of hammers, so every problem looks like... lots and lots of nails. From asen.bozhilov at gmail.com Thu Mar 29 10:04:35 2012 From: asen.bozhilov at gmail.com (Asen Bozhilov) Date: Thu, 29 Mar 2012 07:04:35 -0700 (PDT) Subject: Best way to structure data for efficient searching References: <26352843.1421.1332964332608.JavaMail.geo-discussion-forums@vbue17> <90d08585-361d-428e-a82d-c5005a6c4b5e@k24g2000yqe.googlegroups.com> Message-ID: Larry.Mart wrote: > Since there are duplicates, I can't use a dict. And if I have any > extraneous data in the keys (i.e. something to make them unique) then > I still have to walk through the entire dict to find the matches. You can use slightly different approach. With double mapping you could simplify the lookup. What I mean? Get the first set and build lookup map as: MAP := { KEY1-VALUE : { KEY2-VALUE : [SET, SET, n-th duplicate SET] } } In the worst case you would have quadratic complexity of the algorithm. Otherwise the lookup would be really fast. From gator at cs.tu-berlin.de Thu Mar 29 10:57:19 2012 From: gator at cs.tu-berlin.de (Peter Daum) Date: Thu, 29 Mar 2012 16:57:19 +0200 Subject: "convert" string to bytes without changing data (encoding) In-Reply-To: References: <9tg21lFmo3U1@mid.dfncis.de> <9tg4qoFbfpU1@mid.dfncis.de> <9th0u8Fuf2U1@mid.dfncis.de> Message-ID: <4F74784F.40804@cs.tu-berlin.de> On 2012-03-28 23:37, Terry Reedy wrote: > 2. Decode as if the text were latin-1 and ignore the non-ascii 'latin-1' > chars. When done, encode back to 'latin-1' and the non-ascii chars will > be as they originally were. ... actually, in the beginning of my quest, I ran into an decoding exception trying to read data as "latin1" (which was more or less what I had expected anyway because byte values between 128 and 160 are not defined there). Obviously, I must have misinterpreted something there; I just ran a little test: l=[i for i in range(256)]; b=bytes(l) s=b.decode('latin1'); b=s.encode('latin1'); s=b.decode('latin1') for c in s: print(hex(ord(c)), end=' ') if (ord(c)+1) % 16 ==0: print("") print() ... and got all the original bytes back. So it looks like I tried to solve a problem that did not exist to start with (the problems, I ran into then were pretty real, though ;-) > 3. Decode using encoding = 'ascii', errors='surrogate_escape'. This > reversibly encodes the unknown non-ascii chars as 'illegal' non-chars > (using the surrogate-pair second-half code units). This is probably the > safest in that invalid operations on the non-chars should raise an > exception. Re-encoding with the same setting will reproduce the original > hi-bit chars. The main danger is passing the illegal strings out of your > local sandbox. Unfortunately, this is a very well-kept secret unless you know that something with that name exists. The options currently mentioned in the documentation are not really helpful, because the non-decodeable will be lost. With some trying, I got it to work, too (the option is named "surrogateescape" without the "_" and in python 3.1 it exists, but only not as a keyword argument: "s=b.decode('utf-8','surrogateescape')" ...) Thank you very much for your constructive advice! Regards, Peter From gator at cs.tu-berlin.de Thu Mar 29 10:57:19 2012 From: gator at cs.tu-berlin.de (Peter Daum) Date: Thu, 29 Mar 2012 16:57:19 +0200 Subject: "convert" string to bytes without changing data (encoding) In-Reply-To: References: <9tg21lFmo3U1@mid.dfncis.de> <9tg4qoFbfpU1@mid.dfncis.de> <9th0u8Fuf2U1@mid.dfncis.de> Message-ID: <4F74784F.40804@cs.tu-berlin.de> On 2012-03-28 23:37, Terry Reedy wrote: > 2. Decode as if the text were latin-1 and ignore the non-ascii 'latin-1' > chars. When done, encode back to 'latin-1' and the non-ascii chars will > be as they originally were. ... actually, in the beginning of my quest, I ran into an decoding exception trying to read data as "latin1" (which was more or less what I had expected anyway because byte values between 128 and 160 are not defined there). Obviously, I must have misinterpreted something there; I just ran a little test: l=[i for i in range(256)]; b=bytes(l) s=b.decode('latin1'); b=s.encode('latin1'); s=b.decode('latin1') for c in s: print(hex(ord(c)), end=' ') if (ord(c)+1) % 16 ==0: print("") print() ... and got all the original bytes back. So it looks like I tried to solve a problem that did not exist to start with (the problems, I ran into then were pretty real, though ;-) > 3. Decode using encoding = 'ascii', errors='surrogate_escape'. This > reversibly encodes the unknown non-ascii chars as 'illegal' non-chars > (using the surrogate-pair second-half code units). This is probably the > safest in that invalid operations on the non-chars should raise an > exception. Re-encoding with the same setting will reproduce the original > hi-bit chars. The main danger is passing the illegal strings out of your > local sandbox. Unfortunately, this is a very well-kept secret unless you know that something with that name exists. The options currently mentioned in the documentation are not really helpful, because the non-decodeable will be lost. With some trying, I got it to work, too (the option is named "surrogateescape" without the "_" and in python 3.1 it exists, but only not as a keyword argument: "s=b.decode('utf-8','surrogateescape')" ...) Thank you very much for your constructive advice! Regards, Peter From tjreedy at udel.edu Thu Mar 29 11:04:47 2012 From: tjreedy at udel.edu (Terry Reedy) Date: Thu, 29 Mar 2012 11:04:47 -0400 Subject: unittest: assertRaises() with an instance instead of a type In-Reply-To: References: Message-ID: On 3/29/2012 3:28 AM, Ulrich Eckhardt wrote: >> Equality comparison is by id. So this code will not do what you want. > > >>> Exception('foo') == Exception('foo') > False > > Yikes! That was unexpected and completely changes my idea. Any clue > whether this is intentional? Is identity the fallback when no equality > is defined for two objects? Yes. The Library Reference 4.3. Comparisons (for built-in classes) puts is this way. "Objects of different types, except different numeric types, never compare equal. Furthermore, some types (for example, function objects) support only a degenerate notion of comparison where any two objects of that type are unequal." In other words, 'a==b' is the same as 'a is b'. That is also the default for user-defined classes, but I am not sure where that is documented, if at all. -- Terry Jan Reedy From d at davea.name Thu Mar 29 11:16:30 2012 From: d at davea.name (Dave Angel) Date: Thu, 29 Mar 2012 11:16:30 -0400 Subject: tabs/spaces In-Reply-To: <0ved49-hie.ln1@satorlaser.homedns.org> References: <0ved49-hie.ln1@satorlaser.homedns.org> Message-ID: <4F747CCE.9020003@davea.name> On 03/29/2012 03:18 AM, Ulrich Eckhardt wrote: > Am 28.03.2012 20:26, schrieb Terry Reedy: >> On 3/28/2012 8:28 AM, Ulrich Eckhardt wrote: > [...] >>> # call testee and verify results >>> try: >>> ...call function here... >>> except exception_type as e: >>> if not exception is None: >>> self.assertEqual(e, exception) >> >> Did you use tabs? They do not get preserved indefinitely, so they are >> bad for posting. > > I didn't consciously use tabs, actually I would rather avoid them. > That said, my posting looks correctly indented in my "sent" folder and > also in the copy received from my newsserver. What could also have an > influence is line endings. I'm using Thunderbird on win32 here, acting > as news client to comp.lang.python. Or maybe it's your software (or > maybe some software in between) that fails to preserve formatting. > > *shrug* > > Uli More likely, you failed to tell Thunderbird to send it as text. Html messages will read differently on html aware readers than on the standard text readers. They also take maybe triple the space and bandwidth. In thunderbird 3.1.19 In Edit->Preferences, Composition->general Configure Text Format Behavior -> SendOptions In that dialog, under Text Format, choose Convert the message to plain text. Then in the tab called "Plain text domains", add python.org -- DaveA From tjreedy at udel.edu Thu Mar 29 11:25:14 2012 From: tjreedy at udel.edu (Terry Reedy) Date: Thu, 29 Mar 2012 11:25:14 -0400 Subject: tabs/spaces In-Reply-To: <0ved49-hie.ln1@satorlaser.homedns.org> References: <0ved49-hie.ln1@satorlaser.homedns.org> Message-ID: On 3/29/2012 3:18 AM, Ulrich Eckhardt wrote: > Am 28.03.2012 20:26, schrieb Terry Reedy: >> On 3/28/2012 8:28 AM, Ulrich Eckhardt wrote: > [...] >>> # call testee and verify results >>> try: >>> ...call function here... >>> except exception_type as e: >>> if not exception is None: >>> self.assertEqual(e, exception) >> >> Did you use tabs? They do not get preserved indefinitely, so they are >> bad for posting. > > I didn't consciously use tabs, actually I would rather avoid them. That > said, my posting looks correctly indented in my "sent" folder and also > in the copy received from my newsserver. What could also have an > influence is line endings. I'm using Thunderbird on win32 here, acting > as news client to comp.lang.python. I am using Thunderbird, win64, as news client for gmane. The post looked fine as originally received. The indents only disappeared when I hit reply and the >s were added. That does not happen, in general, for other messages. Unfortunately I cannot go back and read that message as received because the new version of Tbird is misbehaving and deleting read messages on close even though I asked to keep them 6 months. I will look immediately when I next see indents disappearing. -- Terry Jan Reedy From rridge at csclub.uwaterloo.ca Thu Mar 29 11:30:19 2012 From: rridge at csclub.uwaterloo.ca (Ross Ridge) Date: Thu, 29 Mar 2012 11:30:19 -0400 Subject: "convert" string to bytes without changing data (encoding) References: <9tg21lFmo3U1@mid.dfncis.de> <4f740687$0$29884$c3e8da3$5496439d@news.astraweb.com> Message-ID: Steven D'Aprano wrote: >Your reaction is to make an equally unjustified estimate of Evan's >mindset, namely that he is not just wrong about you, but *deliberately >and maliciously* lying about you in the full knowledge that he is wrong. No, Evan in his own words admitted that his post was ment to be harsh, "a bit harsher than it deserves", showing his malicious intent. He made accusations that where neither supported by anything I've said in this thread nor by the code I actually write. His accusation about me were completely made up, he was not telling the truth and had no reasonable basis to beleive he was telling the truth. He was malicously lying and I'm completely justified in saying so. Just to make it clear to all you zealots. I've not once advocated writing any sort "risky code" in this thread. I have not once advocated writing any style of code in thread. Just because I refuse to drink the "it's impossible to represent strings as a series of bytes" kool-aid does't mean that I'm a heretic that must oppose against everything you believe in. Ross Ridge -- l/ // Ross Ridge -- The Great HTMU [oo][oo] rridge at csclub.uwaterloo.ca -()-/()/ http://www.csclub.uwaterloo.ca/~rridge/ db // From ethan at stoneleaf.us Thu Mar 29 11:35:16 2012 From: ethan at stoneleaf.us (Ethan Furman) Date: Thu, 29 Mar 2012 08:35:16 -0700 Subject: unittest: assertRaises() with an instance instead of a type In-Reply-To: <4f735345$0$29981$c3e8da3$5496439d@news.astraweb.com> References: <4f735345$0$29981$c3e8da3$5496439d@news.astraweb.com> Message-ID: <4F748134.8030402@stoneleaf.us> Steven D'Aprano wrote: > On Wed, 28 Mar 2012 14:28:08 +0200, Ulrich Eckhardt wrote: > >> Hi! >> >> I'm currently writing some tests for the error handling of some code. In >> this scenario, I must make sure that both the correct exception is >> raised and that the contained error code is correct: >> >> >> try: >> foo() >> self.fail('exception not raised') >> catch MyException as e: >> self.assertEqual(e.errorcode, SOME_FOO_ERROR) >> catch Exception: >> self.fail('unexpected exception raised') > > Secondly, that is not the right way to do this unit test. You are testing > two distinct things, so you should write it as two separate tests: I have to disagree -- I do not see the advantage of writing a second test that *will* fail if the first test fails as opposed to bundling both tests together, and having one failure. ~Ethan~ From showell30 at yahoo.com Thu Mar 29 11:48:53 2012 From: showell30 at yahoo.com (Steve Howell) Date: Thu, 29 Mar 2012 08:48:53 -0700 (PDT) Subject: Number of languages known [was Re: Python is readable] - somewhat OT References: Message-ID: <28983178-6745-438c-937d-cc6349aa18b1@t8g2000pbe.googlegroups.com> On Mar 29, 7:03?am, Chris Angelico wrote: > On Fri, Mar 30, 2012 at 12:44 AM, Nathan Rice > > wrote: > > We would be better off if all the time that was spent on learning > > syntax, memorizing library organization and becoming proficient with > > new tools was spent learning the mathematics, logic and engineering > > sciences. ?Those solve problems, languages are just representations. > > Different languages are good at different things. REXX is an efficient > text parser and command executor. Pike allows live updates of running > code. Python promotes rapid development and simplicity. PHP makes it > easy to add small amounts of scripting to otherwise-static HTML pages. > C gives you all the power of assembly language with all the > readability of... assembly language. SQL describes a database request. > > You can't merge all of them without making a language that's > suboptimal at most of those tasks - probably, one that's woeful at all > of them. I agree with you on the overall point, but I think that Python actually does a fine job of replacing REXX and PHP. I've used both of the latter (and, of course, Python). REXX and PHP are great at what they do, but I don't think their slight advantages over Python justify all the weight they carry--incompatible syntax to Python, archaic libraries, missing modern language features, etc. It's great to have languages like C and HTML that carve out their own strong niches. No argument there. On the other hand, if you know Python, then having to contend with the learning curves and idiosyncrasies of Perl and Ruby might feel more frustrating than empowering. Like REXX and PHP, Perl and Ruby arguably have corners where they are more expressive than Python, but I'd rather have a boring system written in 100% Python than a Ruby/ Python hybrid. Python should also be a perfectly good superset of Bash Scripting language. (To the extent that Python isn't, there's nothing intrinsic about the language that prevents you from orchestrating processes.) > I mention SQL because, even if you were to unify all > programming languages, you'd still need other non-application > languages to get the job done. > Here I absolutely agree with you. SQL, to me, is a perfect illustration of a language that's optimal for a particular task. Of course, people still can't resist hiding it behind an ORM. The web stack is notorious for requiring multilingual juggling. HTML, CSS, JS, Python, and SQL are easy enough to juggle, but then you might also get template languages (with all the interpolation escaping), config files (XML, YAML, etc.), regexes (possibly multiple dialects), SQL, testing DSLs (ugh, Cucumber and friends), etc. > Keep the diversity and let each language focus on what it's best at. > > ChrisA > who has lots and lots of hammers, so every problem looks like... lots > and lots of nails. I know you're just joking here, because you're obviously not advocating for multiple hammers. You're advocating for multiple tools in the toolbox. Which is good, of course. I think the problem these days is that the programmer's brain is like a small toolbox. Maybe twenty tools fit in the toolbox. Instead of filling it up with 20 useful tools, a lot of us have it cluttered up with ten hammers, when only one of the hammers is what we need for the nails. From nobody at nowhere.com Thu Mar 29 12:25:38 2012 From: nobody at nowhere.com (Nobody) Date: Thu, 29 Mar 2012 17:25:38 +0100 Subject: question about file handling with "with" References: Message-ID: On Wed, 28 Mar 2012 11:31:21 +0200, Jabba Laci wrote: > Is the following function correct? Is the input file closed in order? > > def read_data_file(self): > with open(self.data_file) as f: > return json.loads(f.read()) Yes. The whole point of being able to use a file as a context manager is so that the file will be closed immediately upon leaving the with statement, whether by falling off the end, "return", an exception, or whatever. IOW, it's like calling .close() immediately after the "with" block, only more so, i.e. it will also handle cases that an explicit .close() misses. From driscoll at cs.wisc.edu Thu Mar 29 12:31:23 2012 From: driscoll at cs.wisc.edu (Evan Driscoll) Date: Thu, 29 Mar 2012 11:31:23 -0500 Subject: "convert" string to bytes without changing data (encoding) In-Reply-To: References: <9tg21lFmo3U1@mid.dfncis.de> Message-ID: <4F748E5B.9010707@cs.wisc.edu> On 01/-10/-28163 01:59 PM, Ross Ridge wrote: > Evan Driscoll wrote: >> People like you -- who write to assumptions which are not even remotely >> guaranteed by the spec -- are part of the reason software sucks. > ... >> This email is a bit harsher than it deserves -- but I feel not by much. > > I don't see how you could feel the least bit justified. Well meaning, > if unhelpful, lies about the nature Python strings in order to try to > convince someone to follow what you think are good programming practices > is one thing. Maliciously lying about someone else's code that you've > never seen is another thing entirely. I'm not even talking about code that you or the OP has written. I'm talking about your suggestion that I can in fact say what the internal byte string representation of strings is any given build of Python 3. Aside from the questionable truth of this assertion (there's no guarantee that an implementation uses one consistent encoding or data structure representation consistently), that's of no consequence because you can't depend on what the representation is. So why even bring it up? Also irrelevant is: In practice the number of ways that CPython (the only Python 3 implementation) represents strings is much more limited. Pretending otherwise really isn't helpful. If you can't depend on CPython's implementation (and, I would argue, your code is broken if you do), then it *is* helpful. Saying that "you can just look at what CPython does" is what is unhelpful. That said, looking again I did misread your post that I sent that harsh reply to; I was looking at it perhaps a bit too much through the lens of the CPython comment I said above, and interpreting it as "I can say what the internal representation is of CPython, so just give me that" and launched into my spiel. If that's not what was intended, I retract my statement. As long as everyone is clear on the fact that Python 3 implementations can use whatever encoding and data structures they want, perhaps even different encodings or data structures for equal strings, and that as a consequence saying "what's the internal representation of this string" is a meaningless question as far as Python itself is concerned, I'm happy. Evan From jeanpierreda at gmail.com Thu Mar 29 12:42:36 2012 From: jeanpierreda at gmail.com (Devin Jeanpierre) Date: Thu, 29 Mar 2012 12:42:36 -0400 Subject: Number of languages known [was Re: Python is readable] - somewhat OT In-Reply-To: References: Message-ID: On Thu, Mar 29, 2012 at 10:03 AM, Chris Angelico wrote: > You can't merge all of them without making a language that's > suboptimal at most of those tasks - probably, one that's woeful at all > of them. I mention SQL because, even if you were to unify all > programming languages, you'd still need other non-application > languages to get the job done. Not really. You can turn SQL (or something equivalent) into a subset of your programming language, like C# does with LINQ, or like Scheme does with macros. The Scheme approach generalizes to programming languages in general with even some fairly alien semantics (e.g. you can do prolog using macros and first-class continuations). In fact, for a more difficult target, I even recently saw an implementation of Python in Common-Lisp that uses reader macros to compile a subset of Python to equivalent Common-Lisp code: http://common-lisp.net/project/clpython/ On the other hand, even similar languages are really hard to run in the same VM: imagine the hoops you'd have to jump through to get libraries written in Python 2 and 3 to work together. For a more concrete example, take the attempt to make elisp and guile work together in guilemacs: http://www.red-bean.com/guile/notes/emacs-lisp.html But this has nothing to do with being "suboptimal at most tasks". It's easy to make a language that can do everything C can do, and also everything that Haskell can do. I can write an implementation of this programming language in one line of bash[*]. The easy way is to make those features mutually exclusive. We don't have to sacrifice anything by including more features until we want them to work together. With that in mind, the interesting languages to "merge" aren't things like SQL or regular expressions -- these are so easy to make work with programming languages, that we do it all the time already (via string manipulation, but first-class syntax would also be easily possible). The hard problems are when trying to merge in the semantics of languages that only "make sense" because they have drastically different expectations of the world. The example that comes to mind is Haskell, which relies incredibly strongly on the lack of side effects. How do you merge Haskell and Python? Well, you can't. As soon as you add side-effects, you can no longer rely on the weak equivalence of things executed eagerly versus lazily, and the semantics of Haskell go kaput. So the only actual effort (that I am aware of) to implement side-effects with Haskell *deliberately* makes mutability and laziness mutually exclusive. Anything else is impossible. The effort mentioned here is called Disciple, and the relevant thesis is very fun reading, check it out: http://www.cse.unsw.edu.au/~benl/papers/thesis/lippmeier-impure-world.pdf I guess what I really want to say is that the world looks, to me, to be more optimistic than so many people think it is. If we wanted to, we could absolutely take the best features from a bunch of things. This is what C++ does, this is what Scheme does, this is what D does. They sometimes do it in different ways, they have varying tradeoffs, but this isn't a hard problem except when it is, and the examples you mentioned are actually the easy cases. We can merge Python and C, while keeping roughly the power of both, it's called Cython. We can merge Python and PHP, in that PHP adds nothing incompatible with Python technically (it'd be a lot of work and there would be many tears shed because it's insane) -- but Python Server Pages probably add the feature you want. We could merge SQL and Python, arguably we already do via e.g. SQLAlchemy's query API (etc.) or DBAPI2's string API. These can all becomes subsets of a language that interoperate well with the rest of the language with no problems. These are non-issues: the reasons for not doing so are not technical, they are political or sociological (e.g., "bloat the language", "there should be one obvious way to do it", "PHP's mixing of business logic with presentation logic is bad", etc.) There _are_ times when this is technical, and there are specific areas of this that have technical difficulties, but... that's different, and interesting, and being actively researched, and not really impossible either. I don't know. This is maybe a bit too rant-y and disorganized; if so I apologize. I've been rethinking a lot of my views on programming languages lately. :) I hope at least the links help make this interesting to someone. -- Devin [*] A "language" is really just a set of programs that compile. If we assume that the set of haskell and C programs are disjoint, then we can create a new language that combines both of them, by trying the C (or Haskell) compiler first, and then running the other if that should fail. This is really an argument from the absurd, though. I just said it 'cause it sounds awesome. From tjreedy at udel.edu Thu Mar 29 12:49:19 2012 From: tjreedy at udel.edu (Terry Reedy) Date: Thu, 29 Mar 2012 12:49:19 -0400 Subject: "convert" string to bytes without changing data (encoding) In-Reply-To: References: <9tg21lFmo3U1@mid.dfncis.de> <4f740687$0$29884$c3e8da3$5496439d@news.astraweb.com> Message-ID: On 3/29/2012 11:30 AM, Ross Ridge wrote: > No, Evan in his own words admitted that his post was ment to be harsh, I agree that he should have restrained and censored his writing. > Just because I refuse to drink the > "it's impossible to represent strings as a series of bytes" kool-aid I do not believe *anyone* has made that claim. Is this meant to be a wild exaggeration? As wild as Evan's? In my first post on this thread, I made three truthful claims. 1. A 3.x text string is logically a sequence of unicode 'characters' (codepoints). 2. The Python language definition does not require that a string be bytes or become bytes unless and until it is explicitly encoded. 3. The intentionally hidden byte implementation of strings on byte machines is version and system dependent. The bytes used for a particular character is (in 3.3) context dependent. As it turns out, the OP had mistakenly assumed that the hidden byte implementation of 3.3 strings was both well-defined and something (utf-8) that it is not and (almost certainly) never will be. Guido and most other devs strongly want string indexing (and hence slice endpoint finding) to be O(1). So all of the above is moot as far as the OP's problem is concerned. I already gave him the three standard solutions. -- Terry Jan Reedy From ramit.prasad at jpmorgan.com Thu Mar 29 13:18:25 2012 From: ramit.prasad at jpmorgan.com (Prasad, Ramit) Date: Thu, 29 Mar 2012 17:18:25 +0000 Subject: Advise of programming one of my first programs In-Reply-To: References: <5B80DD153D7D744689F57F4FB69AF4740928C365@SCACMX008.exchad.jpmchase.net> <5B80DD153D7D744689F57F4FB69AF4740928E137@SCACMX008.exchad.jpmchase.net> <4F72385E.8020804@cs.wisc.edu> <5B80DD153D7D744689F57F4FB69AF4740929109C@SCACMX008.exchad.jpmchase.net> Message-ID: <5B80DD153D7D744689F57F4FB69AF47409292DC4@SCACMX008.exchad.jpmchase.net> From: Anatoli Hristov [mailto:tolidtm at gmail.com] Sent: Wednesday, March 28, 2012 5:36 PM To: Prasad, Ramit Cc: python-list at python.org Subject: Re: RE: Advise of programming one of my first programs >>> > Um, at least by my understanding, the use of Pickle is also dangerous if >>>> you >>> > are not completely sure what is being passed in: >>> >>> Oh goodness yes. pickle is exactly as unsafe as eval is. Try running this >>> code: >>> >>> from pickle import loads >>> loads("c__builtin__\neval\n(c__builtin__\nraw_input\n(S'py>'\ntRtR.") >>It might be as dangerous, but which is more likely to cause problems in >>real world scenarios? >Guys this is really something that is not that important at this time for me ?My Eyes! The goggles do nothing!? Ramit Ramit Prasad | JPMorgan Chase Investment Bank | Currencies Technology 712 Main Street | Houston, TX 77002 work phone: 713 - 216 - 5423 -- This email is confidential and subject to important disclaimers and conditions including on offers for the purchase or sale of securities, accuracy and completeness of information, viruses, confidentiality, legal privilege, and legal entity disclaimers, available at http://www.jpmorgan.com/pages/disclosures/email. -------------- next part -------------- An HTML attachment was scrubbed... URL: From ramit.prasad at jpmorgan.com Thu Mar 29 13:36:34 2012 From: ramit.prasad at jpmorgan.com (Prasad, Ramit) Date: Thu, 29 Mar 2012 17:36:34 +0000 Subject: "convert" string to bytes without changing data (encoding) In-Reply-To: <4F736B69.9080600@mrabarnett.plus.com> References: <9tg21lFmo3U1@mid.dfncis.de> <4f73504c$0$29981$c3e8da3$5496439d@news.astraweb.com> <5B80DD153D7D744689F57F4FB69AF47409291BEC@SCACMX008.exchad.jpmchase.net> <4F736B69.9080600@mrabarnett.plus.com> Message-ID: <5B80DD153D7D744689F57F4FB69AF47409292E89@SCACMX008.exchad.jpmchase.net> > > Technically, ASCII goes up to 256 but they are not A-z letters. > > > Technically, ASCII is 7-bit, so it goes up to 127. > No, ASCII only defines 0-127. Values >=128 are not ASCII. > > >From https://en.wikipedia.org/wiki/ASCII: > > ASCII includes definitions for 128 characters: 33 are non-printing > control characters (now mostly obsolete) that affect how text and > space is processed and 95 printable characters, including the space > (which is considered an invisible graphic). Doh! I was mistaking extended ASCII for ASCII. Thanks for the correction. Ramit Ramit Prasad | JPMorgan Chase Investment Bank | Currencies Technology 712 Main Street | Houston, TX 77002 work phone: 713 - 216 - 5423 -- > -----Original Message----- > From: python-list-bounces+ramit.prasad=jpmorgan.com at python.org > [mailto:python-list-bounces+ramit.prasad=jpmorgan.com at python.org] On > Behalf Of MRAB > Sent: Wednesday, March 28, 2012 2:50 PM > To: python-list at python.org > Subject: Re: "convert" string to bytes without changing data (encoding) > > On 28/03/2012 20:02, Prasad, Ramit wrote: > >> >The right way to convert bytes to strings, and vice versa, is via > >> >encoding and decoding operations. > >> > >> If you want to dictate to the original poster the correct way to do > >> things then you don't need to do anything more that. You don't need > to > >> pretend like Chris Angelico that there's isn't a direct mapping from > >> the his Python 3 implementation's internal respresentation of strings > >> to bytes in order to label what he's asking for as being "silly". > > > > It might be technically possible to recreate internal implementation, > > or get the byte data. That does not mean it will make any sense or > > be understood in a meaningful manner. I think Ian summarized it > > very well: > > > >>You can't generally just "deal with the ascii portions" without > >>knowing something about the encoding. Say you encounter a byte > >>greater than 127. Is it a single non-ASCII character, or is it the > >>leading byte of a multi-byte character? If the next character is less > >>than 127, is it an ASCII character, or a continuation of the previous > >>character? For UTF-8 you could safely assume ASCII, but without > >>knowing the encoding, there is no way to be sure. If you just assume > >>it's ASCII and manipulate it as such, you could be messing up > >>non-ASCII characters. > > > -- > http://mail.python.org/mailman/listinfo/python-list This email is confidential and subject to important disclaimers and conditions including on offers for the purchase or sale of securities, accuracy and completeness of information, viruses, confidentiality, legal privilege, and legal entity disclaimers, available at http://www.jpmorgan.com/pages/disclosures/email. From nathan.alexander.rice at gmail.com Thu Mar 29 13:48:40 2012 From: nathan.alexander.rice at gmail.com (Nathan Rice) Date: Thu, 29 Mar 2012 13:48:40 -0400 Subject: Number of languages known [was Re: Python is readable] - somewhat OT In-Reply-To: References: Message-ID: On Thu, Mar 29, 2012 at 10:03 AM, Chris Angelico wrote: > On Fri, Mar 30, 2012 at 12:44 AM, Nathan Rice > wrote: >> We would be better off if all the time that was spent on learning >> syntax, memorizing library organization and becoming proficient with >> new tools was spent learning the mathematics, logic and engineering >> sciences. ?Those solve problems, languages are just representations. > > Different languages are good at different things. REXX is an efficient > text parser and command executor. Pike allows live updates of running > code. Python promotes rapid development and simplicity. PHP makes it > easy to add small amounts of scripting to otherwise-static HTML pages. > C gives you all the power of assembly language with all the > readability of... assembly language. SQL describes a database request. Here's a thought experiment. Imagine that you have a project tree on your file system which includes files written in many different programming languages. Imagine that the files can be assumed to be contiguous for our purposes, so you could view all the files in the project as one long chunk of data. The directory and file names could be interpreted as statements in this data, analogous to "in the context of somedirectory" or "in the context of somefile with sometype". Any project configuration files could be viewed as declarative statements about contexts, such as "in xyz context, ignore those" or "in abc context, any that is actually a this". Imagine the compiler or interpreter is actually part of your program (which is reasonable since it doesn't do anything by itself). Imagine the build management tool is also part of your program in pretty much the same manner. Imagine that your program actually generates another program that will generate the program the machine runs. I hope you can follow me here, and further I hope you can see that this is a completely valid description of what is actually going on (from a different perspective). In the context of the above thought experiment, it should be clear that we currently have something that is a structural analog of a single programming metalanguage (or rather, one per computer architecture), with many domain specific languages constructed above that to simplify tasks in various contexts. The model I previously proposed is not fantasy, it exists, just not in a form usable by human beings. Are machine instructions the richest possible metalanguage? I really doubt it. Lets try another thought experiment... Imagine that instead of having machine instructions as the common metalanguage, we pushed the point of abstraction closer to something programmers can reasonably work with: abstract syntax trees. Imagine all programming languages share a common abstract syntax tree format, with nodes generated using a small set of human intelligible semantic primes. Then, a domain specific language is basically a context with a set of logical implications. By associating a branch of the tree to one (or the union of several) context, you provide a transformation path to machine instructions via logical implication. If implications of a union context for the nodes in the branch are not compatible, this manifests elegantly in the form of a logical contradiction. What does pushing the abstraction point that far up provide? For one, you can now reason across language boundaries. A compiler can tell me if my prolog code and my python code will behave properly together. Another benefit is that you make explicit the fact that your parser, interpreter, build tools, etc are actually part of your program, from the perspective that your program is actually another program that generates programs in machine instructions. By unifying your build chain, it makes deductive inference spanning steps and tools possible, and eliminates some needless repetition. This also greatly simplifies code reuse, since you only need to generate a syntax tree of the proper format and associate the correct context to it. It also simplifies learning languages, since people only need to understand the semantic primes in order to read anything. Of course, this describes Lisp to some degree, so I still need to provide some answers. What is wrong with Lisp? I would say that the base syntax being horrible is probably the biggest issue. Beyond that, transformations on lists of data are natural in Lisp, but graph transformations are not, making some things awkward. Additionally, because Lisp tries to nudge you towards programming in a functional style, it can be un-intuitive to learn. Programming is knowledge representation, and state is a natural concept that many people desire to model, so making it a second class citizen is a mistake. If I were to re-imagine Lisp for this purpose, I would embrace state and an explicit notion of temporal order. Rather than pretending it didn't exist, I would focus on logical and mathematical machinery necessary to allow powerful deductive reasoning about state. It is no coincidence that when a language needs to support formal verification (such as microcontrollers and DSPS for mission critical devices) a synchronous language is the go-go. On the other side of the spectrum, Haskell is the darling of functional programmers, but it is one of the worst languages in existence as far as being able to reason about the behavior of your program goes. Ignoring state for a few mathematical conveniences is the damning mark on the brow of the functional paradigm. Functional programming may be better on the whole than imperative programming, but anyone who doesn't acknowledge that it is an evolutionary dead-end is delusional. > You can't merge all of them without making a language that's > suboptimal at most of those tasks - probably, one that's woeful at all > of them. I mention SQL because, even if you were to unify all > programming languages, you'd still need other non-application > languages to get the job done. > > Keep the diversity and let each language focus on what it's best at. I don't know of any semi-modern programming language that doesn't generate an abstract syntax tree. Since any turing complete language can emulate any other turing complete language, there is no reason why a concise metalanguage for describing nodes of abstract syntax trees couldn't form the semantic vocabulary for every language in existence at the AST level. The syntax could be wildly different, but even then there is a VERY simple feature of CFGs that helps: they are closed under union. The only issue you could run into is if a node with a given name is represented by two different compositions of semantic primes at the AST level. Even this is not a show stopper though, because you could proceed using a union node. When converting the parse tree to an AST, it is likely only one of the two possible nodes in the union will fulfill all the requirements given its neighboring nodes and location in the tree. If there is more than one incompatible match, then of course you just alert the programmer to the contradiction and they can modify the tree context. I'm all for diversity of language at the level of minor notation and vocabulary, but to draw an analogy to the real world, English and Mandarin are redundant, and the fact that they both creates a communication barrier for BILLIONS of people. That doesn't mean that biologists shouldn't be able to define words to describe biological things, if you want to talk about biology you just need to learn the vocabulary. That also doesn't mean or that mathematicians shouldn't be able to use notation to structure complex statements, if you want to do math you need to man up and learn the notation (of course, I have issues with some mathematical notation, but there is no reason you should cry about things like set builder). From rridge at csclub.uwaterloo.ca Thu Mar 29 14:00:42 2012 From: rridge at csclub.uwaterloo.ca (Ross Ridge) Date: Thu, 29 Mar 2012 14:00:42 -0400 Subject: "convert" string to bytes without changing data (encoding) References: <9tg21lFmo3U1@mid.dfncis.de> <4f740687$0$29884$c3e8da3$5496439d@news.astraweb.com> Message-ID: Ross Ridge wrote: > Just because I refuse to drink the > "it's impossible to represent strings as a series of bytes" kool-aid Terry Reedy wrote: >I do not believe *anyone* has made that claim. Is this meant to be a >wild exaggeration? As wild as Evan's? Sorry, it would've been more accurate to label the flavour of kool-aid Chris Angelico was trying to push as "it's impossible ... without encoding": What is a string? It's not a series of bytes. You can't convert it without encoding those characters into bytes in some way. >In my first post on this thread, I made three truthful claims. I'm not objecting to every post made in this thread. If your post had been made before the original poster had figured it out on his own, I would've hoped he would have found it much more convincing than what I quoted above. Ross Ridge -- l/ // Ross Ridge -- The Great HTMU [oo][oo] rridge at csclub.uwaterloo.ca -()-/()/ http://www.csclub.uwaterloo.ca/~rridge/ db // From drobinow at gmail.com Thu Mar 29 14:29:13 2012 From: drobinow at gmail.com (David Robinow) Date: Thu, 29 Mar 2012 14:29:13 -0400 Subject: errors building python 2.7.3 In-Reply-To: <4F743FAE.4070909@ank-sia.com> References: <4F72FAF9.8000802@ank-sia.com> <4F743FAE.4070909@ank-sia.com> Message-ID: On Thu, Mar 29, 2012 at 6:55 AM, Alexey Luchko wrote: > On 28.03.2012 18:42, David Robinow wrote: >> On Wed, Mar 28, 2012 at 7:50 AM, Alexey Luchko ?wrote: >>> I've tried to build Python 2.7.3rc2 on cygwin and got the following >>> errors: >>> >>> $ CFLAGS=-I/usr/include/ncursesw/ CPPFLAGS=-I/usr/include/ncursesw/ >>> ./configure >> ? I haven't tried 2.7.3 yet, so I'll describe my experience with 2.7.2 >> ? I use /usr/include/ncurses ? rather than /usr/include/ncursesw >> ? I don't remember what the difference is but ncurses seems to work. > > I've tried ncurses too. ?It does not matter. Have you included the patch to Include/py_curses.h ? If you don't know what that is, download the cygwin src package for Python-2.6 and look at the patches. Not all of them are still necessary for 2.7 but some are. From python.list at tim.thechases.com Thu Mar 29 14:31:31 2012 From: python.list at tim.thechases.com (Tim Chase) Date: Thu, 29 Mar 2012 13:31:31 -0500 Subject: Number of languages known [was Re: Python is readable] - somewhat OT In-Reply-To: References: Message-ID: <4F74AA83.6020505@tim.thechases.com> On 03/29/12 12:48, Nathan Rice wrote: > Of course, this describes Lisp to some degree, so I still need to > provide some answers. What is wrong with Lisp? I would say that the > base syntax being horrible is probably the biggest issue. Do you mean something like: ((so (describes Lisp (to degree some) (of course)) still-need (provide I some-answers)) (is wrong what (with Lisp)) (would-say I ((is (base-syntax being-horrible) (probably-biggest issue))))) nah...can't fathom what's wrong with that... ?grins, ducks, and runs? -tkc From nathan.alexander.rice at gmail.com Thu Mar 29 14:37:09 2012 From: nathan.alexander.rice at gmail.com (Nathan Rice) Date: Thu, 29 Mar 2012 14:37:09 -0400 Subject: Python is readable In-Reply-To: References: <4f612b19$0$1379$4fafbaef@reader2.news.tin.it> Message-ID: On Thu, Mar 29, 2012 at 9:44 AM, Albert van der Horst wrote: > In article , > Nathan Rice ? wrote: >>> >>> http://www.joelonsoftware.com/articles/fog0000000018.html >> >>I read that article a long time ago, it was bullshit then, it is >>bullshit now. ?The only thing he gets right is that the Shannon >>information of a uniquely specified program is proportional to the >>code that would be required to generate it. ?Never mind that if a > > Thank you for drawing my attention to that article. > It attacks the humbug software architects. > Are you one of them? > I really liked that article. I read the first paragraph, remembered that I had read it previously and stopped. I accidentally remembered something from another Joel article as being part of that article (read it at http://www.joelonsoftware.com/items/2007/12/03.html). I don't really have anything to say on Joel's opinions about why people can or should code, their his and he is entitled to them. I feel they are overly reductionist (this isn't a black/white thing) and have a bit of luddite character to them. I will bet you everything I own the only reason Joel is alive today because of some mathematical abstraction he would be all too happy to discount as meaningless (because, to him, it is). Of course, I will give Joel one point: too many things related to programming are 100% hype, without any real substance; if his article had been about bullshit software hype and he hadn't fired the broadsides at the very notion of abstraction, I wouldn't have anything to say. Anyhow, if you "ugh rock good caveman smash gazelle put in mouth make stomach pain go away" meaning, here it is: Programs are knowledge. The reverse is not true, because programming is an infantile area of human creation, mere feet from the primordial tide pool from whence it spawned. We have a very good example of what a close to optimal outcome is: human beings - programs that write themselves, all knowledge forming programs, strong general artificial intelligence. When all knowledge is also programs, we will have successfully freed ourselves from necessary intellectual drudgery (the unnecessary kind will still exist). We will be able to tell computers what we want on our terms, and they will go and do it, checking in with us from time to time if they aren't sure what we really meant in the given context. If we have developed advanced robotics, we will simultaneously be freed from most manual labor. The only thing left for Joel to do will be to lounge about, being "creative" while eating mangos that were picked, packed, shipped and unloaded by robots, ordered by his computer assistant because it knows that he likes them, then delivered, prepared and served by more robots. The roadblocks in the path include the ability to deal with uncertainty, understand natural languages and the higher order characteristics of information. Baby steps to deal with these roadblocks are to explicitly forbid uncertainty, simplify the language used, and explicitly state higher order properties of information. The natural evolution of the process is to find ways to deal with ambiguity, correctly parse more complex language and automatically deduce higher order characteristics of information. Clearly, human intelligence demonstrates that this is not an impossible pipe dream. You may not be interested in working towards making this a reality, but I can pretty much guarantee on the scale of human achievement, it is near the top. From jeanpierreda at gmail.com Thu Mar 29 14:53:56 2012 From: jeanpierreda at gmail.com (Devin Jeanpierre) Date: Thu, 29 Mar 2012 14:53:56 -0400 Subject: Number of languages known [was Re: Python is readable] - somewhat OT In-Reply-To: References: Message-ID: Agreed with your entire first chunk 100%. Woohoo! High five. :) On Thu, Mar 29, 2012 at 1:48 PM, Nathan Rice wrote: > transformations on lists of data are natural in Lisp, but graph > transformations are not, making some things awkward. Eh, earlier you make some argument towards lisp being a universal metalanguage. If it can simulate prolog, it can certainly grow a graph manipulation form. You'd just need to code it up as a macro or function :p > Additionally, > because Lisp tries to nudge you towards programming in a functional > style, it can be un-intuitive to learn. I think you're thinking of Scheme here. Common Lisp isn't any more functional than Python, AFAIK (other than having syntactic heritage from the lambda calculus?) Common-Lisp does very much embrace state as you later describe, Scheme much less so (in that it makes mutating operations more obvious and more ugly. Many schemes even outlaw some entirely. And quoted lists default to immutable (aaaargh)). > I'm all for diversity of language at the level of minor notation and > vocabulary, but to draw an analogy to the real world, English and > Mandarin are redundant, and the fact that they both creates a > communication barrier for BILLIONS of people. ?That doesn't mean that > biologists shouldn't be able to define words to describe biological > things, if you want to talk about biology you just need to learn the > vocabulary. ?That also doesn't mean or that mathematicians shouldn't > be able to use notation to structure complex statements, if you want > to do math you need to man up and learn the notation (of course, I > have issues with some mathematical notation, but there is no reason > you should cry about things like set builder). Well, what sort of language differences make for English vs Mandarin? Relational algebraic-style programming is useful, but definitely a large language barrier to people that don't know any SQL. I think this is reasonable. (It would not matter even if you gave SQL python-like syntax, the mode of thinking is different, and for a good reason.) -- Devin From showell30 at yahoo.com Thu Mar 29 15:25:10 2012 From: showell30 at yahoo.com (Steve Howell) Date: Thu, 29 Mar 2012 12:25:10 -0700 (PDT) Subject: Number of languages known [was Re: Python is readable] - somewhat OT References: Message-ID: <6e4bc54d-7080-4434-b441-93e0e4930ccf@t2g2000pbg.googlegroups.com> On Mar 29, 11:53?am, Devin Jeanpierre wrote: > Well, what sort of language differences make for English vs Mandarin? > Relational algebraic-style programming is useful, but definitely a > large language barrier to people that don't know any SQL. I think this > is reasonable. (It would not matter even if you gave SQL python-like > syntax, the mode of thinking is different, and for a good reason.) > I don't see any fundamental disconnect between SQL thinking and Python thinking. List comprehensions are very close to SQL SELECTs semantically, and not that far off syntactically. [row.x for row in foo if x == 3] select x from foo where x = 3 Many people can grok the basics of relational algebraic style programming quite easily, which is why SQL is so popular. It just happens that many "programming" languages up until now have obscured the idea. SQL is so strongly associated with RDBMS implementations that people tend to forget that it makes sense as an abstract language--people tend to view SQL as a very concrete mechanism for pulling data out of storage, instead of as a notation for describing the relating and transforming of sets. From nathan.alexander.rice at gmail.com Thu Mar 29 15:50:37 2012 From: nathan.alexander.rice at gmail.com (Nathan Rice) Date: Thu, 29 Mar 2012 15:50:37 -0400 Subject: Number of languages known [was Re: Python is readable] - somewhat OT In-Reply-To: References: Message-ID: On Thu, Mar 29, 2012 at 2:53 PM, Devin Jeanpierre wrote: > Agreed with your entire first chunk 100%. Woohoo! High five. :) Damn, then I'm not trolling hard enough ?_? > On Thu, Mar 29, 2012 at 1:48 PM, Nathan Rice > wrote: >> transformations on lists of data are natural in Lisp, but graph >> transformations are not, making some things awkward. > > Eh, earlier you make some argument towards lisp being a universal > metalanguage. If it can simulate prolog, it can certainly grow a graph > manipulation form. You'd just need to code it up as a macro or > function :p Well, a lisp-like language. I would also argue that if you are using macros to do anything, the thing you are trying to do should classify as "not natural in lisp" :) I'm really thinking here more in terms of a general graph reactive system here, matching patterns in an input graph and modifying the graph in response. There are a lot of systems that can be modeled as a graph that don't admit a nested list (tree) description. By having references to outside the nesting structure you've just admitted that you need a graph rather than a list, so why not be honest about it and work in that context from the get-go. >> Additionally, >> because Lisp tries to nudge you towards programming in a functional >> style, it can be un-intuitive to learn. > > I think you're thinking of Scheme here. Common Lisp isn't any more > functional than Python, AFAIK (other than having syntactic heritage > from the lambda calculus?) > > Common-Lisp does very much embrace state as you later describe, Scheme > much less so (in that it makes mutating operations more obvious and > more ugly. Many schemes even outlaw some entirely. And quoted lists > default to immutable (aaaargh)). I find it interesting that John McCarthy invented both Lisp and the situation calculus. As for set/setq, sure, you can play with state, but it is verbose, and there is no inherent notion of temporal locality. Your program's execution order forms a nice lattice when run on hardware, that should be explicit in software. If I were to do something crazy like take the union of two processes that can potentially interact, with an equivalence relation between some time t1 in the first process and a time t2 in the second (so that you can derive a single partial order), the computer should be able to tell if I am going to shoot myself in the foot, and ideally suggest the correct course of action. > Well, what sort of language differences make for English vs Mandarin? > Relational algebraic-style programming is useful, but definitely a > large language barrier to people that don't know any SQL. I think this > is reasonable. (It would not matter even if you gave SQL python-like > syntax, the mode of thinking is different, and for a good reason.) I don't think they have to be. You can view functions as names for temporally ordered sequence of declarative implication statements. Databases just leave out the logic (this is hyperbole, I know), so you have to do it in client code. I don't feel that a database necessarily has to be a separate entity, that is just an artifact of the localized, specialized view of computation. As stronger abstractions are developed and concurrent, distributed computation is rigorously systematized, I think we'll go full circle. From peter.milliken at gmail.com Thu Mar 29 16:23:20 2012 From: peter.milliken at gmail.com (Peter) Date: Thu, 29 Mar 2012 13:23:20 -0700 (PDT) Subject: help with subclassing problem Message-ID: <30738583.971.1333052600720.JavaMail.geo-discussion-forums@pbje9> I am attempting to subclass the date class from the datetime package. Basically I want a subclass that can take the date as a string (in multiple formats), parse the string and derive the year,month and day information to create a date instance i.e. class MyDate(datetime.date): def __init__(self, the_date): # magic happens here to derives year, month and day from the_date datetime.date.__init__(self, year, month, day) But no matter what I do, when I attempt to create an instance of the new class, I get the error message: Traceback (most recent call last): File "", line 1, in TypeError: Required argument 'year' (pos 1) not found I have even created a class which doesn't include the argument I want to use but with default arguments i.e. class MyDate (datetime.date): def __init__(self, year = 1, month = 1, day = 1): datetime.date.__init__(self, year, month, day) and get the same error message. What am I doing wrong here? Thanks for any help, Peter From rosuav at gmail.com Thu Mar 29 16:33:47 2012 From: rosuav at gmail.com (Chris Angelico) Date: Fri, 30 Mar 2012 07:33:47 +1100 Subject: Number of languages known [was Re: Python is readable] - somewhat OT In-Reply-To: References: Message-ID: On Fri, Mar 30, 2012 at 3:42 AM, Devin Jeanpierre wrote: > On Thu, Mar 29, 2012 at 10:03 AM, Chris Angelico wrote: >> You can't merge all of them without making a language that's >> suboptimal at most of those tasks - probably, one that's woeful at all >> of them. I mention SQL because, even if you were to unify all >> programming languages, you'd still need other non-application >> languages to get the job done. > ... > But this has nothing to do with being "suboptimal at most tasks". It's > easy to make a language that can do everything C can do, and also > everything that Haskell can do. I can write an implementation of this > programming language in one line of bash[*]. The easy way is to make > those features mutually exclusive. We don't have to sacrifice anything > by including more features until we want them to work together. Of course it's POSSIBLE. You can write everything in Ook if you want to. But any attempt to merge all programming languages into one will either: 1) Allow different parts of a program to be written in different subsets of this universal language, which just means that you've renamed all the languages but kept their distinctions (so a programmer still has to learn all of them); or 2) Shoehorn every task into one language, equivalent to knowing only one language and using that for everything. Good luck with that. The debate keeps on coming up, but it's not just political decisions that maintain language diversity. ChrisA From rosuav at gmail.com Thu Mar 29 16:41:31 2012 From: rosuav at gmail.com (Chris Angelico) Date: Fri, 30 Mar 2012 07:41:31 +1100 Subject: "convert" string to bytes without changing data (encoding) In-Reply-To: References: <9tg21lFmo3U1@mid.dfncis.de> <4f740687$0$29884$c3e8da3$5496439d@news.astraweb.com> Message-ID: On Fri, Mar 30, 2012 at 5:00 AM, Ross Ridge wrote: > Sorry, it would've been more accurate to label the flavour of kool-aid > Chris Angelico was trying to push as "it's impossible ... without > encoding": > > ? ? ? ?What is a string? It's not a series of bytes. You can't convert > ? ? ? ?it without encoding those characters into bytes in some way. I still stand by that statement. Do you try to convert a "dictionary of filename to open file object" into a "series of bytes" inside Python? It doesn't matter that, on some level, it's *stored as* a series of bytes; the actual object *is not* a series of bytes. There is no logical equivalency, ergo it is illogical and nonsensical to expect to turn one into the other without some form of encoding. Python does include an encoding that can handle lists and dictionaries. It's called Pickle, and it returns (in Python 3) a bytes object - which IS a series of bytes. It doesn't simply return some internal representation. ChrisA From joncle at googlemail.com Thu Mar 29 16:47:56 2012 From: joncle at googlemail.com (Jon Clements) Date: Thu, 29 Mar 2012 13:47:56 -0700 (PDT) Subject: help with subclassing problem In-Reply-To: <30738583.971.1333052600720.JavaMail.geo-discussion-forums@pbje9> References: <30738583.971.1333052600720.JavaMail.geo-discussion-forums@pbje9> Message-ID: <25679513.1162.1333054076834.JavaMail.geo-discussion-forums@vbex14> On Thursday, 29 March 2012 21:23:20 UTC+1, Peter wrote: > I am attempting to subclass the date class from the datetime package. Basically I want a subclass that can take the date as a string (in multiple formats), parse the string and derive the year,month and day information to create a date instance i.e. > > class MyDate(datetime.date): > def __init__(self, the_date): > # magic happens here to derives year, month and day from the_date > datetime.date.__init__(self, year, month, day) > > But no matter what I do, when I attempt to create an instance of the new class, I get the error message: > > Traceback (most recent call last): > File "", line 1, in > TypeError: Required argument 'year' (pos 1) not found > > > I have even created a class which doesn't include the argument I want to use but with default arguments i.e. > > class MyDate (datetime.date): > def __init__(self, year = 1, month = 1, day = 1): > datetime.date.__init__(self, year, month, day) > > and get the same error message. > > What am I doing wrong here? > > Thanks for any help, > Peter Details here: http://stackoverflow.com/questions/399022/why-cant-i-subclass-datetime-date Jon. From peter.milliken at gmail.com Thu Mar 29 16:53:09 2012 From: peter.milliken at gmail.com (Peter) Date: Thu, 29 Mar 2012 13:53:09 -0700 (PDT) Subject: help with subclassing problem In-Reply-To: <25679513.1162.1333054076834.JavaMail.geo-discussion-forums@vbex14> References: <30738583.971.1333052600720.JavaMail.geo-discussion-forums@pbje9> <25679513.1162.1333054076834.JavaMail.geo-discussion-forums@vbex14> Message-ID: <9717915.602.1333054389867.JavaMail.geo-discussion-forums@pbcwe9> Thanks :-) From ramit.prasad at jpmorgan.com Thu Mar 29 17:04:25 2012 From: ramit.prasad at jpmorgan.com (Prasad, Ramit) Date: Thu, 29 Mar 2012 21:04:25 +0000 Subject: Advise of programming one of my first programs In-Reply-To: References: <5B80DD153D7D744689F57F4FB69AF4740928C365@SCACMX008.exchad.jpmchase.net> <5B80DD153D7D744689F57F4FB69AF4740928E137@SCACMX008.exchad.jpmchase.net> <5B80DD153D7D744689F57F4FB69AF4740928F779@SCACMX008.exchad.jpmchase.net> Message-ID: <5B80DD153D7D744689F57F4FB69AF47409293188@SCACMX008.exchad.jpmchase.net> >>From the Zen of Python, "Simple is better than complex." It is a good programming mentality. >Complex is better than complicated. :p Absolutely! Too bad your version would be considered the more ?complicated? version ;) >With the main navigation menu I will only have the option to select a nickname and when a nickname is selected then it loads Details of the contact and from loaded details I can choice Edit or back to main screen, like I did it the first time, or else I can do it => when 'e' pressed to ask for a nickname and then edit it. I was trying to simplify it to ?guide? you to a more correct solution without feeding you the answer. Maybe I should have given you the explanation first to explain why you should be doing it a different way. Going back to your original program (and your modifications to it), the original menu can cause crashing in more complicated programs and thus is considered a bad style. It was basically using recursion (I will touch on this later) but without any of the benefits. It was endlessly branching instead of a simple loop. Sort of like the following Menu/submenu example. Menu submenu Menu submenu Menu __ad infinitum__ How does this matter? Let?s look at some simpler code below. print ?start? function_a() # a function is called print ?a? # code inside the function print ?b? # code inside the function a = ? something ? print a function_b() # another function call print ?c? # code inside a different function print ?d? # code inside a different function print ?end? Let us pretend we are the computer who executes one line at a time and so basically goes through a list of commands. The list we are going to execute is the following: print ?start? function_a() print ?a? print ?b? a = ? something ? print a function_b() print ?c? print ?d? print ?end? How does the computer know to execute ?a = ? something ?? after ?print ?b??? It does it by storing the location where it was before it proceeds to the function call. That way when the end of the function is reached it returns to the previous spot. In essence: print ?start? function_a() __store this location so I can come back__ print ?a? print ?b? __return to previous location__ a = ? something ? print a function_b() __store this location so I can come back__ print ?c? print ?b? __return to previous location__ print ?end? Now what happens if ?function_a? calls ?function_a?? By the way, the term for this type of call is recursion. print ?start? function_a() __store this location so I can come back__ print ?a? print ?b? function_a() __store this location so I can come back__ print ?a? print ?b? function_a() __store this location so I can come back__ print ?a? print ?b? function_a() __store this location so I can come back__ print ?a? print ?b? function_a() __store this location so I can come back__ print ?a? print ?b? function_a() __store this location so I can come back__ *until the program ends* Now each __store__ action takes up memory and when the computer (or your program) runs out of memory your computer crashes. Your application is trivial and more likely to be ended by the user instead of going through the tens of thousands if not hundreds of thousands that Python will let you take, but it is a bad practice and a habit to avoid. A real world program would use more memory and quit even faster than yours. Recursion has its place in programming, but not in this case! What you need is a simple loop. That is why I provided you with the menu I did. The following menu sounds like what you want; there were a couple different ways I could have done this. In this version, if you type anything when asked for a menu choice that is not ?e? or ?q?, the program will automatically ask you for the next book choice. def mmenu(): # load tbook here while True: book = get_book_choice() details( tbook, book ) choicem = get_menu_choice() if choicem == 'e' or choicem == 'E': edit( tbook, book ) # save tbook here elif choicem =='Q' or choicem == 'q': break # end loop to exit program Ramit Ramit Prasad | JPMorgan Chase Investment Bank | Currencies Technology 712 Main Street | Houston, TX 77002 work phone: 713 - 216 - 5423 -- This email is confidential and subject to important disclaimers and conditions including on offers for the purchase or sale of securities, accuracy and completeness of information, viruses, confidentiality, legal privilege, and legal entity disclaimers, available at http://www.jpmorgan.com/pages/disclosures/email. -------------- next part -------------- An HTML attachment was scrubbed... URL: From ramit.prasad at jpmorgan.com Thu Mar 29 17:30:04 2012 From: ramit.prasad at jpmorgan.com (Prasad, Ramit) Date: Thu, 29 Mar 2012 21:30:04 +0000 Subject: Number of languages known [was Re: Python is readable] - somewhat OT In-Reply-To: References: Message-ID: <5B80DD153D7D744689F57F4FB69AF47409293213@SCACMX008.exchad.jpmchase.net> > >> You can't merge all of them without making a language that's > >> suboptimal at most of those tasks - probably, one that's woeful at all > >> of them. I mention SQL because, even if you were to unify all > >> programming languages, you'd still need other non-application > >> languages to get the job done. > > ... > > But this has nothing to do with being "suboptimal at most tasks". It's > > easy to make a language that can do everything C can do, and also > > everything that Haskell can do. I can write an implementation of this > > programming language in one line of bash[*]. The easy way is to make > > those features mutually exclusive. We don't have to sacrifice anything > > by including more features until we want them to work together. > > Of course it's POSSIBLE. You can write everything in Ook if you want > to. But any attempt to merge all programming languages into one will > either: > > 1) Allow different parts of a program to be written in different > subsets of this universal language, which just means that you've > renamed all the languages but kept their distinctions (so a programmer > still has to learn all of them); or > > 2) Shoehorn every task into one language, equivalent to knowing only > one language and using that for everything. Good luck with that. In a much simpler context, isn't this what .NET's CLR does? Except that instead of converting each language into each other it converts everything into a different language. I have trouble in my mind seeing how what you suggest would not end up with badly coded versions of a translated program. Never yet seen a program that could convert from one paradigm/language directly to another (and do it well/maintainable). > The debate keeps on coming up, but it's not just political decisions > that maintain language diversity. Not a bad thing in my opinion. A tool for each problem, but I can see the appeal of a multi-tool language. Ramit Ramit Prasad | JPMorgan Chase Investment Bank | Currencies Technology 712 Main Street | Houston, TX 77002 work phone: 713 - 216 - 5423 -- This email is confidential and subject to important disclaimers and conditions including on offers for the purchase or sale of securities, accuracy and completeness of information, viruses, confidentiality, legal privilege, and legal entity disclaimers, available at http://www.jpmorgan.com/pages/disclosures/email. From vinay_sajip at yahoo.co.uk Thu Mar 29 19:01:15 2012 From: vinay_sajip at yahoo.co.uk (Vinay Sajip) Date: Thu, 29 Mar 2012 16:01:15 -0700 (PDT) Subject: ANN: A new version (0.2.9) of the Python module which wraps GnuPG has been released. Message-ID: A new version of the Python module which wraps GnuPG has been released. What Changed? ============= This is a minor bug-fix release. See the project website ( http://code.google.com/p/python-gnupg/ ) for more information. Summary: Better support for status messages from GnuPG. A random data file used in testing is no longer shipped with the source distribution, but created by the test suite if needed. 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 jeanpierreda at gmail.com Thu Mar 29 19:21:34 2012 From: jeanpierreda at gmail.com (Devin Jeanpierre) Date: Thu, 29 Mar 2012 19:21:34 -0400 Subject: Number of languages known [was Re: Python is readable] - somewhat OT In-Reply-To: References: Message-ID: On Thu, Mar 29, 2012 at 4:33 PM, Chris Angelico wrote: > Of course it's POSSIBLE. You can write everything in Ook if you want > to. But any attempt to merge all programming languages into one will > either: In that particular quote, I was saying that the reason that you claimed we can't merge languages was not a correct reason. You are now moving the goalposts, in that you've decided to abandon your original point. Also you are now discussing the merger of all programming languages, whereas I meant to talk about pairs of programming languages. e.g. such as SQL and Python. Merging all programming languages is ridiculous. Even merging two, Haskell and C, is impossible without running into massive world-bending problems. (Yes, these problems are interesting, but no, they can't be solved without running into your "issue 1" -- this is in fact a proven theorem.) > 1) Allow different parts of a program to be written in different > subsets of this universal language, which just means that you've > renamed all the languages but kept their distinctions (so a programmer > still has to learn all of them); or Yes. I mentioned this. It is not entirely useless (if you're going to use the other language _anyway_, like SQL or regexps, might as well have it be checked at compile-time same as your outer code), but in a broad sense it's a terrible idea. Also, programmers would have to learn things regardless. You can't avoid this, that's what happens when you add features. The goal in integrating two languages is, well, integration, not reducing learning. > 2) Shoehorn every task into one language, equivalent to knowing only > one language and using that for everything. Good luck with that. This isn't true for the "merge just two languages" case, which is what I meant to talk about. > The debate keeps on coming up, but it's not just political decisions > that maintain language diversity. Are you disagreeing with me, or somebody else? I never said that. Yes, I said that in some cases, e.g. SQL/Python, because there are no technical issues, it must be something political or stylistic. I wasn't saying that the only reason we don't merge languages in is political. As a matter of fact, the very next paragraph begins with "There _are_ times when this is technical". ("political" is a bad word for it, because it covers things that are just plain bad ideas (but, subjectively). For example, there's nothing technically challenging about adding an operator that wipes the user's home directory.) -- Devin From jeanpierreda at gmail.com Thu Mar 29 19:37:23 2012 From: jeanpierreda at gmail.com (Devin Jeanpierre) Date: Thu, 29 Mar 2012 19:37:23 -0400 Subject: Number of languages known [was Re: Python is readable] - somewhat OT In-Reply-To: References: Message-ID: On Thu, Mar 29, 2012 at 3:50 PM, Nathan Rice wrote: > Well, a lisp-like language. ?I would also argue that if you are using > macros to do anything, the thing you are trying to do should classify > as "not natural in lisp" :) You would run into disagreement. Some people feel that the lisp philosophy is precisely that of extending the language to do anything you want, in the most natural way. At least, I disagree, but my lisp thoughts are the result of indoctrination of the Racket crowd. I don't know how well they represent the larger lisp community. But you should definitely take what I say from the viewpoint of the sort of person that believes that the whole purpose of lisps is to embed new syntax and new DSLs via macros. Without macros, there's no point of having this despicable syntax (barring maybe pedagogy and other minor issues). > I'm really thinking here more in terms of a general graph reactive > system here, matching patterns in an input graph and modifying the > graph in response. ?There are a lot of systems that can be modeled as > a graph that don't admit a nested list (tree) description. ?By having > references to outside the nesting structure you've just admitted that > you need a graph rather than a list, so why not be honest about it and > work in that context from the get-go. I don't see any issue in defining a library for working with graphs. If it's useful enough, it could be added to the standard library. There's nothing all that weird about it. Also, most representations of graphs are precisely via a tree-like non-recursive structure. For example, as a matrix, or adjacency list, etc. We think of them as deep structures, but implement them as flat, shallow structures. Specialized syntax (e.g. from macros) can definitely bridge the gap and let you manipulate them in the obvious way, while admitting the usual implementation. > I don't think they have to be. ?You can view functions as names for > temporally ordered sequence of declarative implication statements. > Databases just leave out the logic (this is hyperbole, I know), so you > have to do it in client code. ?I don't feel that a database > necessarily has to be a separate entity, that is just an artifact of > the localized, specialized view of computation. ?As stronger > abstractions are developed and concurrent, distributed computation is > rigorously systematized, I think we'll go full circle. Maybe I'm too tired, but this went straight over my head, sorry. Perhaps you could be a bit more explicit about what you mean by the implications/logic? -- Devin From steve+comp.lang.python at pearwood.info Thu Mar 29 21:10:35 2012 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 30 Mar 2012 01:10:35 GMT Subject: "convert" string to bytes without changing data (encoding) References: <9tg21lFmo3U1@mid.dfncis.de> <4f73504c$0$29981$c3e8da3$5496439d@news.astraweb.com> <5B80DD153D7D744689F57F4FB69AF47409291BEC@SCACMX008.exchad.jpmchase.net> <4F736B69.9080600@mrabarnett.plus.com> Message-ID: <4f75080a$0$29981$c3e8da3$5496439d@news.astraweb.com> On Thu, 29 Mar 2012 17:36:34 +0000, Prasad, Ramit wrote: >> > Technically, ASCII goes up to 256 but they are not A-z letters. >> > >> Technically, ASCII is 7-bit, so it goes up to 127. > >> No, ASCII only defines 0-127. Values >=128 are not ASCII. >> >> >From https://en.wikipedia.org/wiki/ASCII: >> >> ASCII includes definitions for 128 characters: 33 are non-printing >> control characters (now mostly obsolete) that affect how text and >> space is processed and 95 printable characters, including the space >> (which is considered an invisible graphic). > > > Doh! I was mistaking extended ASCII for ASCII. Thanks for the > correction. There actually is no such thing as "extended ASCII" -- there is a whole series of many different "extended ASCIIs". If you look at the encodings available in (for example) Thunderbird, many of the ISO-8859-* and Windows-* encodings are "extended ASCII" in the sense that they extend ASCII to include bytes 128-255. Unfortunately they all extend ASCII in a different way (hence they are different encodings). -- Steven From steve+comp.lang.python at pearwood.info Thu Mar 29 21:16:22 2012 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 30 Mar 2012 01:16:22 GMT Subject: "convert" string to bytes without changing data (encoding) References: <9tg21lFmo3U1@mid.dfncis.de> <4f740687$0$29884$c3e8da3$5496439d@news.astraweb.com> Message-ID: <4f750965$0$29981$c3e8da3$5496439d@news.astraweb.com> On Thu, 29 Mar 2012 11:30:19 -0400, Ross Ridge wrote: > Steven D'Aprano wrote: >>Your reaction is to make an equally unjustified estimate of Evan's >>mindset, namely that he is not just wrong about you, but *deliberately >>and maliciously* lying about you in the full knowledge that he is wrong. > > No, Evan in his own words admitted that his post was ment to be harsh, > "a bit harsher than it deserves", showing his malicious intent. Being harsher than it deserves is not synonymous with malicious. You are making assumptions about Evan's mental state that are not supported by the evidence. Evan may believe that by "punishing" (for some feeble sense of punishment) you harshly, he is teaching you better behaviour that will be to your own benefit; or that it will act as a warning to others. Either way he may believe that he is actually doing good. And then he entirely undermined his own actions by admitting that he was over-reacting. This suggests that, in fact, he wasn't really motivated by either malice or beneficence but mere frustration. It is quite clear that Evan let his passions about writing maintainable code get the best of him. His rant was more about "people like you" than you personally. Evan, if you're reading this, I think you owe Ross an apology for flying off the handle. Ross, I think you owe Evan an apology for unjustified accusations of malice. > He made > accusations that where neither supported by anything I've said Now that is not actually true. Your posts have defended the idea that copying the raw internal byte representation of strings is a reasonable thing to do. You even claimed to know how to do so, for any version of Python (but so far have ignored my request for you to demonstrate). > in this > thread nor by the code I actually write. His accusation about me were > completely made up, he was not telling the truth and had no reasonable > basis to beleive he was telling the truth. He was malicously lying and > I'm completely justified in saying so. No, they were not completely made up. Your posts give many signs of being somebody who might very well write code to the implementation rather than the interface. Whether you are or not is a separate question, but your posts in this thread indicate that you very likely could be. If this is not the impression you want to give, then you should reconsider your posting style. Ross, to be frank, your posting style in this thread has been cowardly and pedantic, an obnoxious combination. Please take this as constructive criticism and not an attack -- you have alienated people in this thread, leading at least one person to publicly kill-file your future posts. I choose to assume you aren't aware of why that is than that you are doing so deliberately. Without actually coming out and making a clear, explicit statement that you approve or disapprove of the OP's attempt to use implementation details, you *imply* support without explicitly giving it; you criticise others for saying it can't be done without demonstrating that it can be done. If this is a deliberate rhetorical trick, then shame on you for being a coward without the conviction to stand behind concrete expressions of your opinion. If not, then you should be aware that you are using a rhetorical style that will make many people predisposed to think you are a twat. You *might* have said Guys, you're technically wrong about this. This is how you can retrieve the internal representation of a string as a sequence of bytes: ...code... but you shouldn't use this in production code because it is fragile and depends on implementation details that may break in PyPy and Jython and IronPython. But you didn't. You *might* have said Wrong, you can convert a string into a sequence of bytes without encoding or decoding: ...code... but don't do this. But you didn't. Instead you puffed yourself up as a big shot who was more technically correct than everyone else, but without *actually* demonstrating that you can do what you said you can do. You labelled as "bullshit" our attempts to discourage the OP from his misguided approached. If your intention was to put people off-side, you succeeded very well. If not, you should be aware that you have, and consider how you might avoid this in the future. -- Steven From steve+comp.lang.python at pearwood.info Thu Mar 29 21:42:56 2012 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 30 Mar 2012 01:42:56 GMT Subject: Python is readable References: <4f612b19$0$1379$4fafbaef@reader2.news.tin.it> Message-ID: <4f750f9f$0$29981$c3e8da3$5496439d@news.astraweb.com> On Thu, 29 Mar 2012 14:37:09 -0400, Nathan Rice wrote: > On Thu, Mar 29, 2012 at 9:44 AM, Albert van der Horst > wrote: >> In article , Nathan >> Rice ? wrote: >>>> >>>> http://www.joelonsoftware.com/articles/fog0000000018.html > Of course, I will give Joel one point: too many things related to > programming are 100% hype, without any real substance; if his article > had been about bullshit software hype and he hadn't fired the broadsides > at the very notion of abstraction He did no such thing. I challenge you to find me one place where Joel has *ever* claimed that "the very notion of abstraction" is meaningless or without use. -- Steven From nathan.alexander.rice at gmail.com Thu Mar 29 21:45:51 2012 From: nathan.alexander.rice at gmail.com (Nathan Rice) Date: Thu, 29 Mar 2012 21:45:51 -0400 Subject: Number of languages known [was Re: Python is readable] - somewhat OT In-Reply-To: References: Message-ID: On Thu, Mar 29, 2012 at 7:37 PM, Devin Jeanpierre wrote: > On Thu, Mar 29, 2012 at 3:50 PM, Nathan Rice > wrote: >> Well, a lisp-like language. ?I would also argue that if you are using >> macros to do anything, the thing you are trying to do should classify >> as "not natural in lisp" :) > > You would run into disagreement. Some people feel that the lisp > philosophy is precisely that of extending the language to do anything > you want, in the most natural way. That is some people's lisp philosophy, though I wouldn't say that is a universal. Just like I might say my take on python's philosophy is "keep it simple, stupid" but others could disagree. > At least, I disagree, but my lisp thoughts are the result of > indoctrination of the Racket crowd. I don't know how well they > represent the larger lisp community. But you should definitely take > what I say from the viewpoint of the sort of person that believes that > the whole purpose of lisps is to embed new syntax and new DSLs via > macros. Without macros, there's no point of having this despicable > syntax (barring maybe pedagogy and other minor issues). Heh, I think you can have a homoiconic language without nasty syntax, but I won't get into that right now. >> I'm really thinking here more in terms of a general graph reactive >> system here, matching patterns in an input graph and modifying the >> graph in response. ?There are a lot of systems that can be modeled as >> a graph that don't admit a nested list (tree) description. ?By having >> references to outside the nesting structure you've just admitted that >> you need a graph rather than a list, so why not be honest about it and >> work in that context from the get-go. > > I don't see any issue in defining a library for working with graphs. > If it's useful enough, it could be added to the standard library. > There's nothing all that weird about it. Graphs are the more general and expressive data structure, I think if anything you should special case the less general form. > Also, most representations of graphs are precisely via a tree-like > non-recursive structure. For example, as a matrix, or adjacency list, > etc. We think of them as deep structures, but implement them as flat, > shallow structures. Specialized syntax (e.g. from macros) can > definitely bridge the gap and let you manipulate them in the obvious > way, while admitting the usual implementation. We do a lot of things because they are efficient. That is why gaussian distributions are everywhere in statistics, people approximate nonlinear functions with sums of kernels, etc. It shouldn't be the end goal though, unless it really is the most expressive way of dealing with things. My personal opinion is that graphs are more expressive, and I think it would be a good idea to move towards modeling knowledge and systems with graphical structures. >> I don't think they have to be. ?You can view functions as names for >> temporally ordered sequence of declarative implication statements. >> Databases just leave out the logic (this is hyperbole, I know), so you >> have to do it in client code. ?I don't feel that a database >> necessarily has to be a separate entity, that is just an artifact of >> the localized, specialized view of computation. ?As stronger >> abstractions are developed and concurrent, distributed computation is >> rigorously systematized, I think we'll go full circle. > > Maybe I'm too tired, but this went straight over my head, sorry. > Perhaps you could be a bit more explicit about what you mean by the > implications/logic? Well, the curry howard correspondance says that every function can be seen as a named implication of outputs given inputs, with the code for that function being a representation of its proof. Since pretty much every function is a composition of many smaller functions, this holds down to the lowest level. Even imperative statements can be viewed as functions in this light, if you assume discrete time, and view every function or statement as taking the state of the world at T as an implicit input and returning as an implicit output the state of the world at T+1. Thus, every function (and indeed pretty much all code) can be viewed as a named collection of implication statements in a particular context :) From steve+comp.lang.python at pearwood.info Thu Mar 29 21:56:44 2012 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 30 Mar 2012 01:56:44 GMT Subject: Number of languages known [was Re: Python is readable] - somewhat OT References: Message-ID: <4f7512db$0$29981$c3e8da3$5496439d@news.astraweb.com> On Thu, 29 Mar 2012 13:48:40 -0400, Nathan Rice wrote: > Here's a thought experiment. Imagine that you have a project tree on > your file system which includes files written in many different > programming languages. Imagine that the files can be assumed to be > contiguous for our purposes, so you could view all the files in the > project as one long chunk of data. The directory and file names could > be interpreted as statements in this data, analogous to "in the context > of somedirectory" or "in the context of somefile with sometype". Any > project configuration files could be viewed as declarative statements > about contexts, such as "in xyz context, ignore those" or "in abc > context, any that is actually a this". Imagine the compiler or > interpreter is actually part of your program (which is reasonable since > it doesn't do anything by itself). Imagine the build management tool is > also part of your program in pretty much the same manner. Imagine that > your program actually generates another program that will generate the > program the machine runs. I hope you can follow me here, and further I > hope you can see that this is a completely valid description of what is > actually going on (from a different perspective). [...] > What does pushing the abstraction point that far up provide? I see why you are so hostile towards Joel Spolsky's criticism of Architecture Astronauts: you are one of them. Sorry Nathan, I don't know how you breathe that high up. For what it's worth, your image of "everything from the compiler on up is part of your program" describes both Forth and Hypercard to some degree, both of which I have used and like very much. I still think you're sucking vacuum :( -- Steven From showell30 at yahoo.com Thu Mar 29 22:19:23 2012 From: showell30 at yahoo.com (Steve Howell) Date: Thu, 29 Mar 2012 19:19:23 -0700 (PDT) Subject: Number of languages known [was Re: Python is readable] - somewhat OT References: Message-ID: On Mar 29, 9:42?am, Devin Jeanpierre wrote: > On Thu, Mar 29, 2012 at 10:03 AM, Chris Angelico wrote: > > You can't merge all of them without making a language that's > > suboptimal at most of those tasks - probably, one that's woeful at all > > of them. I mention SQL because, even if you were to unify all > > programming languages, you'd still need other non-application > > languages to get the job done. > > Not really. You can turn SQL (or something equivalent) into a subset > of your programming language, like C# does with LINQ, or like Scheme > does with macros. I'm glad your moving the discussion away from the fake debate between "diversity" (good) and "one-language-fits-all" (horribly naive at best, evil at worse). Of course, there's a middle ground, where (some degree of) language unification is a completely sane goal, at least worthy of discussion. SQL is a well-established lingua franca for describing relationships between sets, or relational algebra. General-purpose languages like C#, Scheme, and Python are well suited to subsuming SQL semantics, and, in fact, they already do, but sometimes they do it a way that's unnecessarily foreign to people who quite easily grok the basics of SQL. The extreme position for language unification would be that Python completely subsumes SQL under its umbrella as first-class syntax. I don't necessarily advocate for that, but I think it's an interesting thought experiment to ask why it doesn't. Just to be clear, I'm talking about SQL as a mechanism to transform sets within Python itself, not external RDMBS engines (although first-class SQL integration could also be useful for that as well). > On the other hand, even similar languages are really hard to run in > the same VM: imagine the hoops you'd have to jump through to get > libraries written in Python 2 and 3 to work together. My take on Python 2 vs. Python 3 is that it's simply a tactical program to get people to upgrade to Python 3. The fact that the two languages can't run on the same VM doesn't really bother me. > With that in mind, the interesting languages to "merge" aren't things > like SQL or regular expressions -- these are so easy to make work with > programming languages, that we do it all the time already (via string > manipulation, but first-class syntax would also be easily possible). > The hard problems are when trying to merge in the semantics of > languages that only "make sense" because they have drastically > different expectations of the world. The example that comes to mind is > Haskell, which relies incredibly strongly on the lack of side effects. > How do you merge Haskell and Python? My view on Haskell and Python is that they should stay alive as competing paradigms. I think you're making a useful distinction between Haskell and SQL. Neither language is well integrated with Python. With Haskell, I think it's for good reason. With SQL, I don't quite understand the status quo (beyond the obvious reasons-- maybe we're just not there yet). > I guess what I really want to say is that the world looks, to me, to > be more optimistic than so many people think it is. If we wanted to, > we could absolutely take the best features from a bunch of things. > This is what C++ does, this is what Scheme does, this is what D does. > They sometimes do it in different ways, they have varying tradeoffs, > but this isn't a hard problem except when it is, and the examples you > mentioned are actually the easy cases. We can merge Python and C, > while keeping roughly the power of both, it's called Cython. I love the fact that C dominates all other languages at its level of abstraction. I wish this were the case one level up, where you still have Python, Ruby, JavaScript, PHP, Perl, and others essentially solving the same classes of problems. Don't get me wrong--I'm all for diversity; I'm not saying we should arbitrarily kill off languages, etc. I'm just saying that there will be *some* benefit when a clear victor emerges, and hopefully that will be Python 3. Whatever language emerges as the victor, it will probably subsume some of the best features of the conquered. To a degree that has already happened. > We can > merge Python and PHP, in that PHP adds nothing incompatible with > Python technically (it'd be a lot of work and there would be many > tears shed because it's insane) -- but Python Server Pages probably > add the feature you want. PHP is a language that I wish would die off quickly and gracefully. I feel like the good things of PHP have already been subsumed into the ecosystems of stronger programming languages (including Python). > We could merge SQL and Python, arguably we > already do via e.g. SQLAlchemy's query API (etc.) or DBAPI2's string > API. These can all becomes subsets of a language that interoperate > well with the rest of the language with no problems. These are > non-issues: the reasons for not doing so are not technical, they are > political or sociological (e.g., "bloat the language", "there should > be one obvious way to do it", "PHP's mixing of business logic with > presentation logic is bad", etc.) > The way that I view the world now is that we have lots of languages that don't interoperate well. To some degree, it's a non-problem of course. The world has many problems to solve, and it's a good thing that we have a diversity of languages to tackle those problems. I get it. Some languages don't interoperate for purely technical reasons, and it would be foolish to fight a losing battle to force square pegs into round holes. I get that, too. Some non-compatible languages coexist with each other for political reasons that are completely legitimate. Even for the same problem domains, there are strongly competing philosophies on fundamental programming concepts, such as mutation, expressiveness, etc. I get that. Finally, though, there is a bunch of *non-essential* diversity, or at least a lot of options that serve more to confuse than empower. Diversity is great, but some level of convergence should be the end game. Diversity is the engine behind progress, of course, but the fuel doesn't always burn clean. > There _are_ times when this is technical, and there are specific areas > of this that have technical difficulties, but... that's different, and > interesting, and being actively researched, and not really impossible > either. > > I don't know. This is maybe a bit too rant-y and disorganized; if so I > apologize. I've been rethinking a lot of my views on programming > languages lately. :) ?I hope at least the links help make this > interesting to someone. I enjoyed hearing your thought process. Thanks! From nathan.alexander.rice at gmail.com Thu Mar 29 22:26:38 2012 From: nathan.alexander.rice at gmail.com (Nathan Rice) Date: Thu, 29 Mar 2012 22:26:38 -0400 Subject: Python is readable In-Reply-To: <4f750f9f$0$29981$c3e8da3$5496439d@news.astraweb.com> References: <4f612b19$0$1379$4fafbaef@reader2.news.tin.it> <4f750f9f$0$29981$c3e8da3$5496439d@news.astraweb.com> Message-ID: > He did no such thing. I challenge you to find me one place where Joel has > *ever* claimed that "the very notion of abstraction" is meaningless or > without use. "When great thinkers think about problems, they start to see patterns. They look at the problem of people sending each other word-processor files, and then they look at the problem of people sending each other spreadsheets, and they realize that there's a general pattern: sending files. That's one level of abstraction already. Then they go up one more level: people send files, but web browsers also "send" requests for web pages. And when you think about it, calling a method on an object is like sending a message to an object! It's the same thing again! Those are all sending operations, so our clever thinker invents a new, higher, broader abstraction called messaging, but now it's getting really vague and nobody really knows what they're talking about any more. Blah. When you go too far up, abstraction-wise, you run out of oxygen. Sometimes smart thinkers just don't know when to stop, and they create these absurd, all-encompassing, high-level pictures of the universe that are all good and fine, but don't actually mean anything at all." To me, this directly indicates he views higher order abstractions skeptically, and assumes because he does not see meaning in them, they don't hold any meaning. Despite Joel's beliefs, new advances in science are in many ways the result of advances in mathematics brought on by very deep abstraction. Just as an example, Von Neumann's treatment of quantum mechanics with linear operators in Hilbert spaces utilizes very abstract mathematics, and without it we wouldn't have modern electronics. I'm 100% behind ranting on software hype. Myopically bashing the type of thinking that resulted in the computer the basher is writing on, not so much. If he had said "if you're getting very high up, find very smart people and talk to them to make sure you're not in wing nut territory" I could have given him a pass. I really wish people wouldn't try to put Joel up on a pedestal. The majority of his writings either seem like sensationalist spins on tautological statements, self aggrandizement or luddite trolling. At least Stephen Wolfram has cool shit to back up his ego, Fog Creek makes decent but overpriced debuggers/version control/issue trackers... From my perspective, Stack Overflow is the first really interesting thing Joel had his hand in, and I suspect Jeff Atwood was probably the reason for it, since SO doesn't look like anything Fog Creek ever produced prior to that. From steve+comp.lang.python at pearwood.info Thu Mar 29 22:45:05 2012 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 30 Mar 2012 02:45:05 GMT Subject: unittest: assertRaises() with an instance instead of a type References: <4f735345$0$29981$c3e8da3$5496439d@news.astraweb.com> Message-ID: <4f751e31$0$29981$c3e8da3$5496439d@news.astraweb.com> On Thu, 29 Mar 2012 09:08:30 +0200, Ulrich Eckhardt wrote: > Am 28.03.2012 20:07, schrieb Steven D'Aprano: >> Secondly, that is not the right way to do this unit test. You are >> testing two distinct things, so you should write it as two separate >> tests: > [..code..] >> If foo does *not* raise an exception, the unittest framework will >> handle the failure for you. If it raises a different exception, the >> framework will also handle that too. >> >> Then write a second test to check the exception code: > [...] >> Again, let the framework handle any unexpected cases. > > Sorry, you got it wrong, it should be three tests: 1. Make sure foo() > raises an exception. 2. Make sure foo() raises the right exception. 3. > Make sure the errorcode in the exception is right. > > Or maybe you should in between verify that the exception raised actually > contains an errorcode? And that the errorcode can be equality-compared > to the expected value? :> Of course you are free to slice it even finer if you like: testFooWillRaiseSomethingButIDontKnowWhat testFooWillRaiseMyException testFooWillRaiseMyExceptionWithErrorcode testFooWillRaiseMyExceptionWithErrorcodeWhichSupportsEquality testFooWillRaiseMyExceptionWithErrorcodeEqualToFooError Five tests :) To the degree that the decision of how finely to slice tests is a matter of personal judgement and/or taste, I was wrong to say "that is not the right way". I should have said "that is not how I would do that test". I believe that a single test is too coarse, and three or more tests is too fine, but two tests is just right. Let me explain how I come to that judgement. If you take a test-driven development approach, the right way to test this is to write testFooWillFail once you decide that foo() should raise MyException but before foo() actually does so. You would write the test, the test would fail, and you would fix foo() to ensure it raises the exception. Then you leave the now passing test in place to detect regressions. Then you do the same for the errorcode. Hence two tests. Since running tests is (usually) cheap, you never bother going back to remove tests which are made redundant by later tests. You only remove them if they are made redundant by chances to the code. So even though the first test is made redundant by the second (if the first fails, so will the second), you don't remove it. Why not? Because it guards against regressions. Suppose I decide that errorcode is no longer needed, so I remove the test for errorcode. If I had earlier also removed the independent test for MyException being raised, I've now lost my only check against regressions in foo(). So: never remove tests just because they are redundant. Only remove them when they are obsolete due to changes in the code being tested. Even when I don't actually write the tests in advance of the code, I still write them as if I were. That usually makes it easy for me to decide how fine grained the tests should be: since there was never a moment when I thought MyException should have an errorcode attribute, but not know what that attribute would be, I don't need a *separate* test for the existence of errorcode. (I would only add such a separate test if there was a bug that sometimes the errorcode does not exist. That would be a regression test.) The question of the exception type is a little more subtle. There *is* a moment when I knew that foo() should raise an exception, but before I decided what that exception would be. ValueError? TypeError? Something else? I can write the test before making that decision: def testFooRaises(self): try: foo() except: # catch anything pass else: self.fail("foo didn't raise") However, the next step is broken: I have to modify foo() to raise an exception, and there is no "raise" equivalent to the bare "except", no way to raise an exception without specifying an exception type. I can use a bare raise, but only in response to an existing exception. So to raise an exception at all, I need to decide what exception that will be. Even if I start with a placeholder "raise BaseException", and test for that, when I go back and change the code to "raise MyException" I should change the test, not create a new test. Hence there is no point is testing for "any exception, I don't care what" since I can't write code corresponding to that test case. Hence, I end up with two tests, not three and certainly not five. -- Steven From steve+comp.lang.python at pearwood.info Thu Mar 29 22:53:47 2012 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 30 Mar 2012 02:53:47 GMT Subject: unittest: assertRaises() with an instance instead of a type References: <4f735345$0$29981$c3e8da3$5496439d@news.astraweb.com> Message-ID: <4f75203a$0$29981$c3e8da3$5496439d@news.astraweb.com> On Thu, 29 Mar 2012 08:35:16 -0700, Ethan Furman wrote: > Steven D'Aprano wrote: >> On Wed, 28 Mar 2012 14:28:08 +0200, Ulrich Eckhardt wrote: >> >>> Hi! >>> >>> I'm currently writing some tests for the error handling of some code. >>> In this scenario, I must make sure that both the correct exception is >>> raised and that the contained error code is correct: >>> >>> >>> try: >>> foo() >>> self.fail('exception not raised') >>> catch MyException as e: >>> self.assertEqual(e.errorcode, SOME_FOO_ERROR) >>> catch Exception: >>> self.fail('unexpected exception raised') >> >> Secondly, that is not the right way to do this unit test. You are >> testing two distinct things, so you should write it as two separate >> tests: > > I have to disagree -- I do not see the advantage of writing a second > test that *will* fail if the first test fails as opposed to bundling > both tests together, and having one failure. Using that reasoning, your test suite should contain *one* ginormous test containing everything: def testDoesMyApplicationWorkPerfectly(self): # TEST ALL THE THINGS!!! ... since *any* failure in any part will cause cascading failures in every other part of the software which relies on that part. If you have a tree of dependencies, a failure in the root of the tree will cause everything to fail, and so by your reasoning, everything should be in a single test. I do not agree with that reasoning, even when the tree consists of two items: an exception and an exception attribute. The problem of cascading test failures is a real one. But I don't believe that the solution is to combine multiple conceptual tests into a single test. In this case, the code being tested covers two different concepts: 1. foo() will raise MyException. Hence one test for this. 2. When foo() raises MyException, the exception instance will include an errorcode attribute with a certain value. This is conceptually separate from #1 above, even though it depends on it. Why is it conceptually separate? Because there may be cases where the caller cares about foo() raising MyException, but doesn't care about the errorcode. Hence errorcode is dependent but separate, and hence a separate test. -- Steven From wuwei23 at gmail.com Thu Mar 29 23:33:24 2012 From: wuwei23 at gmail.com (alex23) Date: Thu, 29 Mar 2012 20:33:24 -0700 (PDT) Subject: weird behaviour: pygame plays in shell but not in script References: <7ef60ccc-c0bb-4aa8-a393-469883897058@k24g2000yqe.googlegroups.com> Message-ID: <0fce59a2-68ac-4c1d-96f5-5e155bcd404e@pg2g2000pbb.googlegroups.com> On Mar 29, 10:41?pm, Mik wrote: > What a nice way to introduce myself to the group!!! :-) Hey, don't beat yourself up, you: - summarised the problem in the subject heading - included actual code showing the problem - reported back on the problem you found That puts you ahead of most new posters. > sorry for bothering you guys :-) No bother at all, welcome to the party :) From steve+comp.lang.python at pearwood.info Thu Mar 29 23:36:27 2012 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 30 Mar 2012 03:36:27 GMT Subject: Python is readable References: <4f612b19$0$1379$4fafbaef@reader2.news.tin.it> <4f750f9f$0$29981$c3e8da3$5496439d@news.astraweb.com> Message-ID: <4f752a3a$0$29981$c3e8da3$5496439d@news.astraweb.com> On Thu, 29 Mar 2012 22:26:38 -0400, Nathan Rice wrote: >> He did no such thing. I challenge you to find me one place where Joel >> has *ever* claimed that "the very notion of abstraction" is meaningless >> or without use. [snip quote] > To me, this directly indicates he views higher order abstractions > skeptically, Yes he does, and so we all should, but that's not the claim you made. You stated that he "fired the broadsides at the very notion of abstraction". He did no such thing. He fired a broadside at (1) software hype based on (2) hyper-abstractions which either don't solve any problems that people care about, or don't solve them any better than more concrete solutions. > and assumes because he does not see meaning in them, they > don't hold any meaning. You are making assumptions about his mindset that not only aren't justified by his comments, but are *contradicted* by his comments. He repeatedly describes the people coming up with these hyper-abstractions as "great thinkers", "clever thinkers", etc. who are seeing patterns in what people do. He's not saying that they're dummies. He's saying that they're seeing patterns that don't mean anything, not that the patterns aren't there. > Despite Joel's beliefs, new advances in science > are in many ways the result of advances in mathematics brought on by > very deep abstraction. Just as an example, Von Neumann's treatment of > quantum mechanics with linear operators in Hilbert spaces utilizes very > abstract mathematics, and without it we wouldn't have modern > electronics. I doubt that very much. The first patent for the transistor was made in 1925, a year before von Neumann even *started* working on quantum mechanics. In general, theory *follows* practice, not the other way around: parts of quantum mechanics theory followed discoveries made using the transistor: http://en.wikipedia.org/wiki/History_of_the_transistor The Romans had perfectly functioning concrete without any abstract understanding of chemistry. If we didn't have QM, we'd still have advanced electronics. Perhaps not *exactly* the electronics we have now, but we'd have something. We just wouldn't understand *why* it works, and so be less capable of *predicting* useful approaches and more dependent on trial-and-error. Medicine and pharmaceuticals continue to be discovered even when we can't predict the properties of molecules. My aunt makes the best damn lasagna you've ever tasted without any overarching abstract theory of human taste. And if you think that quantum mechanics is more difficult than understanding human perceptions of taste, you are badly mistaken. In any case, Spolsky is not making a general attack on abstract science. Your hyperbole is completely unjustified. -- Steven From nathan.alexander.rice at gmail.com Fri Mar 30 00:38:26 2012 From: nathan.alexander.rice at gmail.com (Nathan Rice) Date: Fri, 30 Mar 2012 00:38:26 -0400 Subject: Python is readable In-Reply-To: <4f752a3a$0$29981$c3e8da3$5496439d@news.astraweb.com> References: <4f612b19$0$1379$4fafbaef@reader2.news.tin.it> <4f750f9f$0$29981$c3e8da3$5496439d@news.astraweb.com> <4f752a3a$0$29981$c3e8da3$5496439d@news.astraweb.com> Message-ID: >>> He did no such thing. I challenge you to find me one place where Joel >>> has *ever* claimed that "the very notion of abstraction" is meaningless >>> or without use. > [snip quote] >> To me, this directly indicates he views higher order abstractions >> skeptically, > > Yes he does, and so we all should, but that's not the claim you made. You > stated that he "fired the broadsides at the very notion of abstraction". > He did no such thing. He fired a broadside at (1) software hype based on > (2) hyper-abstractions which either don't solve any problems that people > care about, or don't solve them any better than more concrete solutions. Mathematics is all about abstraction. There are theories and structures in mathematics that have probably gone over a hundred years before being applied. As an analogy, just because a spear isn't useful while farming doesn't mean it won't save your life when you venture into the woods and come upon a bear. >> and assumes because he does not see meaning in them, they >> don't hold any meaning. > > You are making assumptions about his mindset that not only aren't > justified by his comments, but are *contradicted* by his comments. He > repeatedly describes the people coming up with these hyper-abstractions > as "great thinkers", "clever thinkers", etc. who are seeing patterns in > what people do. He's not saying that they're dummies. He's saying that > they're seeing patterns that don't mean anything, not that the patterns > aren't there. He is basically saying they are too clever for their own good, as a result of being fixated upon purely intellectual constructs. If math was a failed discipline I might be willing to entertain that notion, but quite the opposite, it is certainly the most successful area of study. > >> Despite Joel's beliefs, new advances in science >> are in many ways the result of advances in mathematics brought on by >> very deep abstraction. ?Just as an example, Von Neumann's treatment of >> quantum mechanics with linear operators in Hilbert spaces utilizes very >> abstract mathematics, and without it we wouldn't have modern >> electronics. > > I doubt that very much. The first patent for the transistor was made in > 1925, a year before von Neumann even *started* working on quantum > mechanics. The electronic properties of silicon (among other compounds) is an obvious example of where quantum theory provides for us. We might have basic circuits, but we wouldn't have semiconductors. > In general, theory *follows* practice, not the other way around: parts of > quantum mechanics theory followed discoveries made using the transistor: You do need data points to identify an explanatory mathematical structure. > The Romans had perfectly functioning concrete without any abstract > understanding of chemistry. If we didn't have QM, we'd still have > advanced electronics. Perhaps not *exactly* the electronics we have now, > but we'd have something. We just wouldn't understand *why* it works, and > so be less capable of *predicting* useful approaches and more dependent > on trial-and-error. Medicine and pharmaceuticals continue to be > discovered even when we can't predict the properties of molecules. The stochastic method, while useful, is many orders of magnitude less efficient than analytically closed solutions. Not having access to closed form solutions would have put us back hundreds of years at least. > My aunt makes the best damn lasagna you've ever tasted without any > overarching abstract theory of human taste. And if you think that quantum > mechanics is more difficult than understanding human perceptions of > taste, you are badly mistaken. Taste is subjective, and your aunt probably started from a good recipe and tweaked it for local palates. That recipe could easily be over a hundred years old. An overarching mathematical theory of human taste/mouth perception, if such a silly thing were to exist, would be able to generate new recipes that were perfect for a given person's tastes very quickly. Additionally, just to troll this point some more (fun times!), I would argue that there is an implicit theory of human taste (chefs refer to it indirectly as gastronomy) that is very poorly organized and lacks any sort of scientific rigor. Nonetheless, enough empirical observations about pairings of flavors, aromas and textures have been made to guide the creation of new recipes. Gastronomy doesn't need to be organized or rigorous because fundamentally it isn't very important. > In any case, Spolsky is not making a general attack on abstract science. > Your hyperbole is completely unjustified. The mathematics of the 20th century, (from the early 30s onward) tend to get VERY abstract, in just the way Joel decries. Category theory, model theory, modern algebraic geometry, topos theory, algebraic graph theory, abstract algebras and topological complexes are all very difficult to understand because they seem so incredibly abstract, yet most of them already have important applications. I'm 100% positive if you just presented Joel with seminal papers in some of those areas, he would apply the "astronaut" rubber stamp, because the material is challenging, and he wouldn't get it (I love math, and I've had to read some papers 10+ times before they click). All I'm suggesting here is that if someone creates something abstract that is elegant and contains a kernel of fundamental truth on some level but doesn't immediately suggest applications, file it in the "neat and worth revisiting at some point in the distant future" bin and move on, don't denigrate them as asphyxiating space cases who need to stop following their curiosity, come down to earth, and produce some shiny bauble for immediate human consumption. From nathan.alexander.rice at gmail.com Fri Mar 30 01:37:04 2012 From: nathan.alexander.rice at gmail.com (Nathan Rice) Date: Fri, 30 Mar 2012 01:37:04 -0400 Subject: Number of languages known [was Re: Python is readable] - somewhat OT In-Reply-To: <4f7512db$0$29981$c3e8da3$5496439d@news.astraweb.com> References: <4f7512db$0$29981$c3e8da3$5496439d@news.astraweb.com> Message-ID: >> Here's a thought experiment. ?Imagine that you have a project tree on >> your file system which includes files written in many different >> programming languages. ?Imagine that the files can be assumed to be >> contiguous for our purposes, so you could view all the files in the >> project as one long chunk of data. ?The directory and file names could >> be interpreted as statements in this data, analogous to "in the context >> of somedirectory" or "in the context of somefile with sometype". ?Any >> project configuration files could be viewed as declarative statements >> about contexts, such as "in xyz context, ignore those" or "in abc >> context, any that is actually a this". ?Imagine the compiler or >> interpreter is actually part of your program (which is reasonable since >> it doesn't do anything by itself). ?Imagine the build management tool is >> also part of your program in pretty much the same manner. ?Imagine that >> your program actually generates another program that will generate the >> program the machine runs. ?I hope you can follow me here, and further I >> hope you can see that this is a completely valid description of what is >> actually going on (from a different perspective). > [...] >> What does pushing the abstraction point that far up provide? > > I see why you are so hostile towards Joel Spolsky's criticism of > Architecture Astronauts: you are one of them. Sorry Nathan, I don't know > how you breathe that high up. > > For what it's worth, your image of "everything from the compiler on up is > part of your program" describes both Forth and Hypercard to some degree, > both of which I have used and like very much. I still think you're > sucking vacuum :( We live in a world where the tools that are used are based on tradition (read that as backwards compatibility if it makes you feel better) and as a mechanism for deriving personal identity. The world is backwards and retarded in many, many ways, this problem is interesting to me because it actually cuts across a much larger tract than is immediately obvious. People throughout history have had the mistaken impression that the world as it existed for them was the pinnacle of human development. Clearly all of those people were tragically deluded, and I suspect that is the case here as well. From jhsu802701 at gmail.com Fri Mar 30 01:45:38 2012 From: jhsu802701 at gmail.com (Jason Hsu, Mr. Swift Linux) Date: Thu, 29 Mar 2012 22:45:38 -0700 (PDT) Subject: How do I use PyGTK to put text besides clickable buttons? Message-ID: I've decided to use PyGTK instead of gtkdialog for providing configuration menus/dialog boxes in Swift Linux, the Linux distro I started. The problem with gtkdialog is that the i386 version is no longer available in the Debian repository. Since a picture is worth a thousand words, I'll give you a link to a screenshot of antiX Linux: http://antix.freeforums.org/download/file.php?id=23 How do I use PyGTK to create something similar to the logout dialog box in the above graphic? I've figured out how to create clickable buttons that each run a different script. What I haven't figured out is how to add text beside each button. From showell30 at yahoo.com Fri Mar 30 02:44:04 2012 From: showell30 at yahoo.com (Steve Howell) Date: Thu, 29 Mar 2012 23:44:04 -0700 (PDT) Subject: Python is readable References: <4f612b19$0$1379$4fafbaef@reader2.news.tin.it> <4f750f9f$0$29981$c3e8da3$5496439d@news.astraweb.com> <4f752a3a$0$29981$c3e8da3$5496439d@news.astraweb.com> Message-ID: <7d27d34b-99c3-40f5-a405-c293a2e7d577@to5g2000pbc.googlegroups.com> On Mar 29, 9:38?pm, Nathan Rice wrote: > The mathematics of the 20th century, (from the early 30s onward) tend > to get VERY abstract, in just the way Joel decries. ?Category theory, > model theory, modern algebraic geometry, topos theory, algebraic graph > theory, abstract algebras and topological complexes are all very > difficult to understand because they seem so incredibly abstract, yet > most of them already have important applications. ?I'm 100% positive > if you just presented Joel with seminal papers in some of those areas, > he would apply the "astronaut" rubber stamp, because the material is > challenging, and he wouldn't get it (I love math, and I've had to read > some papers 10+ times before they click). Nathan, Don't worry too much about Joel Spolsky, and worry even less about people that allude to him. Joel Spolksy is an early 21st century businessman. He's a smart guy with decent writing skills and semi-interesting thoughts, but he's not gonna change the world. He runs his business by promoting pragmatic processes, writing blogs, procuring comfortable chairs for developers, renting nice loft space in NYC, and building some useful, but basically unoriginal, websites and apps. Everything that Joel Spolsky has ever said in his blog has already been put into practice 100 times over by a bunch of similarly pragmatic early 21st century folk. If you really like math, it is no surprise that you find the current state of computer programming a bit inelegant. 90% of what programmers do in the early 21st century is move the data from HERE to THERE, then another 9% is placing the data in just the right part of the screen. I'm exaggerating a bit, but we're still in the backwaters. It's all engineering now; it's all breeding the faster horse. Or so it seems. There's a natural ebb and flow to progress. In the early to mid 20th century, there were tremendous advances in math, science, and technology, and maybe it's gonna take a full century or two of playing around with shit and arguing about stupid shit until the dust finally settles and we make another quantum jump. From michael at stroeder.com Fri Mar 30 03:04:49 2012 From: michael at stroeder.com (=?UTF-8?B?TWljaGFlbCBTdHLDtmRlcg==?=) Date: Fri, 30 Mar 2012 09:04:49 +0200 Subject: "convert" string to bytes without changing data (encoding) In-Reply-To: <4f75080a$0$29981$c3e8da3$5496439d@news.astraweb.com> References: <9tg21lFmo3U1@mid.dfncis.de> <4f73504c$0$29981$c3e8da3$5496439d@news.astraweb.com> <5B80DD153D7D744689F57F4FB69AF47409291BEC@SCACMX008.exchad.jpmchase.net> <4F736B69.9080600@mrabarnett.plus.com> <4f75080a$0$29981$c3e8da3$5496439d@news.astraweb.com> Message-ID: Steven D'Aprano wrote: > On Thu, 29 Mar 2012 17:36:34 +0000, Prasad, Ramit wrote: > >>>> Technically, ASCII goes up to 256 but they are not A-z letters. >>>> >>> Technically, ASCII is 7-bit, so it goes up to 127. >> >>> No, ASCII only defines 0-127. Values >=128 are not ASCII. >>> >>> >From https://en.wikipedia.org/wiki/ASCII: >>> >>> ASCII includes definitions for 128 characters: 33 are non-printing >>> control characters (now mostly obsolete) that affect how text and >>> space is processed and 95 printable characters, including the space >>> (which is considered an invisible graphic). >> >> >> Doh! I was mistaking extended ASCII for ASCII. Thanks for the >> correction. > > There actually is no such thing as "extended ASCII" -- there is a whole > series of many different "extended ASCIIs". If you look at the encodings > available in (for example) Thunderbird, many of the ISO-8859-* and > Windows-* encodings are "extended ASCII" in the sense that they extend > ASCII to include bytes 128-255. Unfortunately they all extend ASCII in a > different way (hence they are different encodings). Yupp. Looking at RFC 1345 some years ago (while having to deal with EBCDIC) made this all pretty clear to me. I appreciate that someone did this heavy work of collecting historical encodings. Ciao, Michael. From ulrich.eckhardt at dominolaser.com Fri Mar 30 03:05:53 2012 From: ulrich.eckhardt at dominolaser.com (Ulrich Eckhardt) Date: Fri, 30 Mar 2012 09:05:53 +0200 Subject: tabs/spaces In-Reply-To: References: <0ved49-hie.ln1@satorlaser.homedns.org> Message-ID: Am 29.03.2012 17:25, schrieb Terry Reedy: > I am using Thunderbird, win64, as news client for gmane. The post looked > fine as originally received. The indents only disappeared when I hit > reply and the >s were added. I can confirm this misbehaviour of Thunderbird (version 11.0 here), it strips the leading spaces when you begin a reply. Uli From showell30 at yahoo.com Fri Mar 30 03:27:13 2012 From: showell30 at yahoo.com (Steve Howell) Date: Fri, 30 Mar 2012 00:27:13 -0700 (PDT) Subject: Python is readable References: <4f612b19$0$1379$4fafbaef@reader2.news.tin.it> <4f750f9f$0$29981$c3e8da3$5496439d@news.astraweb.com> <4f752a3a$0$29981$c3e8da3$5496439d@news.astraweb.com> Message-ID: On Mar 29, 8:36?pm, Steven D'Aprano wrote: > The Romans had perfectly functioning concrete without any abstract > understanding of chemistry. If I ever stumbled upon a technology that proved how useless abstract thinking was, do you know what I would call it? "Concrete." Damn, those clever Romans beat me to it by a couple millennia! And they had AQUEDUCTS!!! > [...] Medicine and pharmaceuticals continue to be > discovered even when we can't predict the properties of molecules. I know this is really, really far out, and I should probably come back down to earth, but I can envision some sort of 25th century utopia where scientists measure the weights and charges and atoms, and arrange them into some kind of chart, and just BASED ON THE CHART ALONE, these 25th century scientists might be able to predict behaviors that have never been observed, just BASED ON ABSTRACT REASONING. Whoa! That's really far out stuff. Give me some oxygen! (preferably of the 1s2 2s2 2p4 variety) (Yep, I get it, the periodic table is about atoms, and medicine/ pharmaceuticals are about molecules, so your point is not invalid. It's still alchemy, though.) From xahlee at gmail.com Fri Mar 30 04:27:16 2012 From: xahlee at gmail.com (Xah Lee) Date: Fri, 30 Mar 2012 01:27:16 -0700 (PDT) Subject: Is Programing Art or Science? Message-ID: the refreshen of the blood, from Xah's Entertainment Enterprise, i bring you: ?Is Programing Art or Science? http://xahlee.org/UnixResource_dir/writ/art_or_science.html penned in the year of our lord two thousand and two, plain text version follows. -------------------------------- Is Programing Art or Science? Dear friends, You mentioned the title of Donald Knuth's magnum opus Art of Programming in the context of discussion that fringes on whether programing is science or art. I'm quite pissed off at work at the moment, so let me take the time to give some guide on this matter to the daily programers. At the bottom rung of programers, there's no question about whether programing is science or art. Because monkey coders could not care less. These folks ain't be reading this post, for they hardly will have heard of lisp. This leaves us with elite programers who have a smattering of interests on cogitation and philosophical conundrums. So, is programing a science or art? For the programing morons, this question is associated with erudition. It certainly is a hip subject among hackers such as those hardcore Perl advocates and unix proponents, who would casually hint on such realization, impressing a sophistication among peers. Such a question is not uncommon among those curious. For example, ?Is mathematics science or art??, is the same type of question that has been broached by dabblers now and then. We can also detect such dilemma in the titles conferred to blathering computer jockeys: which one are thee: baccalaureate of science or baccalaureate of arts? It really makes no fucking difference. Ultimately, fantastically stupid questions like these are not discussed by mathematicians nor philosophers. These are natural language side-effects, trapping dummies to fuzz about nothing; not unlike quotations. For these computing jockeys, there remains the question of why Knuth named his books the ?Art? of Computer Programing, or why some computing luminaries litter the caution that programing is as much a art as science. What elite dimwits need to realize is that these authors are not defining or correcting, but breaking precepts among the automatons in programing industry. To the readers of hip literature, words like science and art are spellbinding, and the need to pigeonhole is imminent. Of these ruminating class of people, the problem lies in their wanting of originality. What fills their banal brain are the stale food of thought that has been chewed and spewed. These above-average eggheads mop up the scholastic tidbits of its day to mull and muse with fellow eggheads. They could not see new perspectives. Could not understand gists. Could not detect non-questions. They are the holder and passer of knowledge, a bucket of pre-digested purees. Their train of thought forever loops around established tracks ? going nowhere, anytime! So, is programing a art or science? is it art or science? I really need to know. ? Theory vs Practice ? Jargons of IT Industry ? The Lambda Logo Tour ? English Lawers PS don't forget to checkout: ?From Why Not Ruby to Fuck Python, Hello Ruby? @ http://xahlee.org/UnixResource_dir/writ/why_not_Ruby.html yours humbly, Xah From john_ladasky at sbcglobal.net Fri Mar 30 05:25:05 2012 From: john_ladasky at sbcglobal.net (John Ladasky) Date: Fri, 30 Mar 2012 02:25:05 -0700 (PDT) Subject: No os.copy()? Why not? References: <38b3fc48-1d05-4373-b32e-64da95173864@pz2g2000pbc.googlegroups.com> <20bc37f2-9eac-47f0-9ab2-150da6ca203b@mq9g2000pbb.googlegroups.com> Message-ID: <918efe53-421b-433a-88ca-ddcf7a576afb@x10g2000pbi.googlegroups.com> On Mar 28, 9:50?pm, alex23 wrote: > On Mar 29, 6:12?am, John Ladasky wrote: > > > I'm looking for a Python (2.7) equivalent to the Unix "cp" command. > > Any help? ?Thanks. > > Try the shutil module:http://docs.python.org/library/shutil.html Many thanks! That's what I was looking for. From steve+comp.lang.python at pearwood.info Fri Mar 30 06:47:32 2012 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 30 Mar 2012 10:47:32 GMT Subject: Python is readable References: <4f612b19$0$1379$4fafbaef@reader2.news.tin.it> <4f750f9f$0$29981$c3e8da3$5496439d@news.astraweb.com> <4f752a3a$0$29981$c3e8da3$5496439d@news.astraweb.com> Message-ID: <4f758f43$0$29981$c3e8da3$5496439d@news.astraweb.com> On Fri, 30 Mar 2012 00:38:26 -0400, Nathan Rice wrote: >>>> He did no such thing. I challenge you to find me one place where Joel >>>> has *ever* claimed that "the very notion of abstraction" is >>>> meaningless or without use. >> [snip quote] >>> To me, this directly indicates he views higher order abstractions >>> skeptically, >> >> Yes he does, and so we all should, but that's not the claim you made. >> You stated that he "fired the broadsides at the very notion of >> abstraction". He did no such thing. He fired a broadside at (1) >> software hype based on (2) hyper-abstractions which either don't solve >> any problems that people care about, or don't solve them any better >> than more concrete solutions. > > Mathematics is all about abstraction. There are theories and structures > in mathematics that have probably gone over a hundred years before being > applied. As an analogy, just because a spear isn't useful while farming > doesn't mean it won't save your life when you venture into the woods and > come upon a bear. A spear is a concrete application of the principle of leverage, not an abstraction. I also point out leverage was discovered experimentally long before anyone had an abstraction for it. In any case, so what? Who is saying that mathematics is useless? Not me, and not Joel Spolksy. You are hunting strawmen with your non-abstract spear. Spolsky has written at least three times about Architecture Astronauts, and made it abundantly clear that the problem with them is that they don't solve problems, they invent overarching abstractions that don't do anything useful or important, and hype them everywhere. http://www.joelonsoftware.com/articles/fog0000000018.html http://www.joelonsoftware.com/items/2005/10/21.html http://www.joelonsoftware.com/items/2008/05/01.html Jeff Attwood provides a simple test for the difference between a useful abstraction and an Architecture Astronaut hyper-abstraction: Does it solve a useful problem? http://www.codinghorror.com/blog/2004/12/it-came-from-planet-architecture.html You keep reading this as an assault on abstract mathematics, science and knowledge for its on sake. It isn't any of these things. If I'm paid to solve a problem, and instead I build an abstraction that doesn't help solve the problem, then I'm guilty of doing architecture astronauting. >>> and assumes because he does not see meaning in them, they don't hold >>> any meaning. >> >> You are making assumptions about his mindset that not only aren't >> justified by his comments, but are *contradicted* by his comments. He >> repeatedly describes the people coming up with these hyper-abstractions >> as "great thinkers", "clever thinkers", etc. who are seeing patterns in >> what people do. He's not saying that they're dummies. He's saying that >> they're seeing patterns that don't mean anything, not that the patterns >> aren't there. > > He is basically saying they are too clever for their own good, as a > result of being fixated upon purely intellectual constructs. Yes, and he is right to do so, because that is the characteristic of the Architecture Astronaut: being so fixated on over-arching abstract concepts that, far from those abstractions making it easier to solve the problems they are being paid to solve, they actually make them harder. Good abstractions enable problems to be solved. Bad abstractions don't. If I ask you to build me a website, I probably don't want a website- builder, I certainly don't want a website-builder-generator, and I absolutely do not want you to generalise the concept of a compiler and create a whole new abstract language for describing meta-compilers so that I can create a brand new programming language for generating meta- compilers that build compilers that will build factories for building website generators so I can make my own website in just three easy steps (the simplest one of which is about twice as difficult as just building the website would have been). If you are being paid to build abstractions in the ivory tower, on the chance that one in a thousand abstractions turns out to be a game changer, or just because of a love of pure knowledge, that's great. I love abstract mathematics too. I read maths in my free time, you won't find me saying that it is bad or useless or harmful. But does it solve real problems? Well, of course it does, and often in a most surprising places. But that's because out of the hundred thousand abstractions, we see the hundred that actually solve concrete problems. The other 99,999 exist only in forgotten journals, or perhaps the odd book here or there. This is all well and good. It's not meant as an attack on mathematics. You can't tell ahead of time which abstractions will solve real problems. *Somebody* has to be thinking about ways that spherical camels can pass through the eye of a 17-dimensional needle, because you never know when somebody else will say, "Hey, that's just what we need to make low-fat chocolate ice cream that doesn't taste like crap!" and then you'll be richer beyond all the dreams of avarice. But that doesn't mean that you have to turn every one of those abstractions into software. I don't really care if checking my email and deleting a file are both special cases of some abstract file operation, I don't need to see it in my file manager. [...] > The electronic properties of silicon (among other compounds) is an > obvious example of where quantum theory provides for us. We might have > basic circuits, but we wouldn't have semiconductors. A poor example. The existence of semiconductors was demonstrated, not predicted: Michael Faraday discovered the existence of semiconductors in 1833, *long* before quantum theory: http://sites.google.com/site/transistorhistory/faraday-to-shockley The existence of photoconductivity was one of the experimental discoveries which eventually led to QM, via Einstein's explanation of the photoelectric effect. But what's your point here? We started off talking about abstractions. Quantum mechanics is not an abstraction, or at least no more than any other physical theory. It is a *description* of reality (a model), not a generalisation. To counter Spolksy, you need to show the great practical discoveries and inventions, not of quantum mechanics, but of a *generalisation* of quantum mechanics that encompasses QM as a special, concrete, example. [...] > The stochastic method, while useful, is many orders of magnitude less > efficient than analytically closed solutions. Not having access to > closed form solutions would have put us back hundreds of years at least. We don't have closed-form solutions. At best we have closed-form solutions of simplified and idealised problems. E.g. we don't have a closed-form solution for the actual hydrogen atom, only of a simplified model of that atom: http://en.wikipedia.org/wiki/Hydrogen_atom#Features_going_beyond_the_Schr.C3.B6dinger_solution And likewise for helium, e.g. one simplifying approximation is to ignore the electron-electron repulsion. And that's hardly the only one. As for closed-form solutions of real devices like a CPU? Forget it. As the famous saying goes, the more advanced the theory, the fewer entities it can solve exactly. Newtonian physics can't solve the three body problem exactly; Einsteinian physics can't solve the two body problem; quantum mechanics can't solve the one body problem; and quantum gravity can't solve the zero body problem (the vacuum). -- Steven From mikprog at gmail.com Fri Mar 30 07:16:34 2012 From: mikprog at gmail.com (Mik) Date: Fri, 30 Mar 2012 04:16:34 -0700 (PDT) Subject: weird behaviour: pygame plays in shell but not in script References: <7ef60ccc-c0bb-4aa8-a393-469883897058@k24g2000yqe.googlegroups.com> <0fce59a2-68ac-4c1d-96f5-5e155bcd404e@pg2g2000pbb.googlegroups.com> Message-ID: Oh thanks alex! that's kind! PS: It looks like a party indeed: plenty of interesting discussions :-) On Mar 30, 4:33?am, alex23 wrote: > On Mar 29, 10:41?pm, Mik wrote: > > > What a nice way to introduce myself to the group!!! :-) > > Hey, don't beat yourself up, you: > > ?- summarised the problem in the subject heading > ?- included actual code showing the problem > ?- reported back on the problem you found > > That puts you ahead of most new posters. > > > sorry for bothering you guys :-) > > No bother at all, welcome to the party :) From kiuhnm03.4t.yahoo.it Fri Mar 30 07:27:34 2012 From: kiuhnm03.4t.yahoo.it (Kiuhnm) Date: Fri, 30 Mar 2012 13:27:34 +0200 Subject: Pipelining in Python Message-ID: <4f7598a7$0$1391$4fafbaef@reader1.news.tin.it> I decided to withdraw my proposal for streaming programming :) and to fall back to something more conventional. Here's the full story: The new operators are '>>' which does the pipelining and '-' which links functions Pipelining is "function application in reverse order" and linking is "function composition in reverse order". Therefore, arg >> f means f(arg) and arg >> f - g means g(f(arg)) Let's look at some examples: ---> 1) range(0,50) >> filter(lambda i : i%2) >> map(lambda i : i*i) >> my_print (Yes, that's currying.) 2) compFunc = filter(lambda i : i%2) - map(lambda i : i*i) range(0,50) >> compFunc >> my_print 3) (Sieve of Eratosthenes) # Tells whether x is not a proper multiple of n. notPropMult = cur(lambda n, x : x <= n or x % n, 2) def findPrimes(upTo): if (upTo <= 5): return [2, 3, 5] filterAll = (findPrimes(floor(sqrt(upTo))) >> map(lambda x : filter(notPropMult(x))) >> reduce(lambda f, g : f - g)) return list(range(2, upTo + 1)) >> filterAll findPrimes(1000) >> my_print 4) (Finds the approximate number of hrefs in a web page) def do(proc, arg): proc() return arg do = cur(do) cprint = cur(print) ("http://python.org" >> do(cprint("The page http://python.org has about... ", end = '')) >> do(sys.stdout.flush) >> urlopen >> cur(lambda x : x.read()) >> findall(b"href=\"") >> cur(len) >> cur("{} hrefs.".format) >> cprint) <--- And here's the complete source code (which includes a class version of /cur/ and the old tests/examples): ---> class CurriedFunc: def __init__(self, func, args = (), kwArgs = {}, unique = True, minArgs = None): self.__func = func self.__myArgs = args self.__myKwArgs = kwArgs self.__unique = unique self.__minArgs = minArgs def __call__(self, *args, **kwArgs): if args or kwArgs: # some more args! # Allocates data to assign to the next CurriedFunc. newArgs = self.__myArgs + args newKwArgs = dict.copy(self.__myKwArgs) # If unique is True, we don't want repeated keyword arguments. if self.__unique and not kwArgs.keys().isdisjoint(newKwArgs): raise ValueError("Repeated kw arg while unique = True") # Adds/updates keyword arguments. newKwArgs.update(kwArgs) # Checks whether it's time to evaluate func. if self.__minArgs is not None and self.__minArgs <= len(newArgs) + len(newKwArgs): return self.__func(*newArgs, **newKwArgs) # time to evaluate func else: return CurriedFunc(self.__func, newArgs, newKwArgs, self.__unique, self.__minArgs) else: # the evaluation was forced return self.__func(*self.__myArgs, **self.__myKwArgs) def __rrshift__(self, arg): return self.__func(*(self.__myArgs + (arg,)), **self.__myKwArgs) # forces evaluation def __sub__(self, other): if not isinstance(other, CurriedFunc): raise TypeError("Cannot compose a CurriedFunc with another type") def compFunc(*args, **kwArgs): return other.__func(*(other.__myArgs + (self.__func(*args, **kwArgs),)), **other.__myKwArgs) return CurriedFunc(compFunc, self.__myArgs, self.__myKwArgs, self.__unique, self.__minArgs) def cur(f, minArgs = None): return CurriedFunc(f, (), {}, True, minArgs) def curr(f, minArgs = None): return CurriedFunc(f, (), {}, False, minArgs) # Simple Function. def func(a, b, c, d, e, f, g = 100): print(a, b, c, d, e, f, g) # NOTE: '<====' means "this line prints to the screen". # Example 1. f = cur(func) # f is a "curried" version of func c1 = f(1) c2 = c1(2, d = 4) # Note that c is still unbound c3 = c2(3)(f = 6)(e = 5) # now c = 3 c3() # () forces the evaluation <==== # it prints "1 2 3 4 5 6 100" c4 = c2(30)(f = 60)(e = 50) # now c = 30 c4() # () forces the evaluation <==== # it prints "1 2 30 4 50 60 100" print("\n------\n") # Example 2. f = curr(func) # f is a "curried" version of func # curr = cur with possibly repeated # keyword args c1 = f(1, 2)(3, 4) c2 = c1(e = 5)(f = 6)(e = 10)() # ops... we repeated 'e' because we <==== # changed our mind about it! # again, () forces the evaluation # it prints "1 2 3 4 10 6 100" print("\n------\n") # Example 3. f = cur(func, 6) # forces the evaluation after 6 arguments c1 = f(1, 2, 3) # num args = 3 c2 = c1(4, f = 6) # num args = 5 c3 = c2(5) # num args = 6 ==> evalution <==== # it prints "1 2 3 4 5 6 100" c4 = c2(5, g = -1) # num args = 7 ==> evaluation <==== # we can specify more than 6 arguments, but # 6 are enough to force the evaluation # it prints "1 2 3 4 5 6 -1" print("\n------\n") # Example 4. def printTree(func, level = None): if level is None: printTree(cur(func), 0) elif level == 6: func(g = '')() # or just func('')() else: printTree(func(0), level + 1) printTree(func(1), level + 1) printTree(func) print("\n------\n") def f2(*args): print(", ".join(["%3d"%(x) for x in args])) def stress(f, n): if n: stress(f(n), n - 1) else: f() # enough is enough stress(cur(f2), 100) # Pipelining and Function Composition print("\n--- Pipelining & Composition ---\n") import sys from urllib.request import urlopen from re import findall from math import sqrt, floor from functools import reduce map = cur(map, 2) filter = cur(filter, 2) urlopen = cur(urlopen) findall = cur(findall) my_print = cur(lambda list : print(*list)) reduce = cur(reduce, 2) # Example 5 range(0,50) >> filter(lambda i : i%2) >> map(lambda i : i*i) >> my_print print("---") # Example 6 compFunc = filter(lambda i : i%2) - map(lambda i : i*i) range(0,50) >> compFunc >> my_print print("---") # Example 7 # Tells whether x is not a proper multiple of n. notPropMult = cur(lambda n, x : x <= n or x % n, 2) def findPrimes(upTo): if (upTo <= 5): return [2, 3, 5] filterAll = (findPrimes(floor(sqrt(upTo))) >> map(lambda x : filter(notPropMult(x))) >> reduce(lambda f, g : f - g)) return list(range(2, upTo + 1)) >> filterAll findPrimes(1000) >> my_print print("---") # Example 8 # Finds the approximate number of hrefs in a web page. def do(proc, arg): proc() return arg do = cur(do) cprint = cur(print) ("http://python.org" >> do(cprint("The page http://python.org has about... ", end = '')) >> do(sys.stdout.flush) >> urlopen >> cur(lambda x : x.read()) >> findall(b"href=\"") >> cur(len) >> cur("{} hrefs.".format) >> cprint) <--- Kiuhnm From luch at ank-sia.com Fri Mar 30 07:41:40 2012 From: luch at ank-sia.com (Alexey Luchko) Date: Fri, 30 Mar 2012 14:41:40 +0300 Subject: errors building python 2.7.3 In-Reply-To: References: <4F72FAF9.8000802@ank-sia.com> <4F743FAE.4070909@ank-sia.com> Message-ID: <4F759BF4.3050305@ank-sia.com> On 29.03.2012 21:29, David Robinow wrote: > Have you included the patch to Include/py_curses.h ? > If you don't know what that is, download the cygwin src package for > Python-2.6 and look at the patches. Not all of them are still Thanks for the hint. With cygwin's 2.6.5-ncurses-abi6.patch it works with both ncurses and ncursesw. -- Alex From rustompmody at gmail.com Fri Mar 30 08:46:32 2012 From: rustompmody at gmail.com (rusi) Date: Fri, 30 Mar 2012 05:46:32 -0700 (PDT) Subject: weird behaviour: pygame plays in shell but not in script References: <7ef60ccc-c0bb-4aa8-a393-469883897058@k24g2000yqe.googlegroups.com> <0fce59a2-68ac-4c1d-96f5-5e155bcd404e@pg2g2000pbb.googlegroups.com> Message-ID: On Mar 30, 8:33?am, alex23 wrote: > On Mar 29, 10:41?pm, Mik wrote: > > > What a nice way to introduce myself to the group!!! :-) > > Hey, don't beat yourself up, you: > > ?- summarised the problem in the subject heading > ?- included actual code showing the problem > ?- reported back on the problem you found > > That puts you ahead of most new posters. Well said. I only disagree with the 'new' From d at davea.name Fri Mar 30 08:47:46 2012 From: d at davea.name (Dave Angel) Date: Fri, 30 Mar 2012 08:47:46 -0400 Subject: tabs/spaces In-Reply-To: References: <0ved49-hie.ln1@satorlaser.homedns.org> Message-ID: <4F75AB72.2090806@davea.name> On 03/30/2012 03:05 AM, Ulrich Eckhardt wrote: > Am 29.03.2012 17:25, schrieb Terry Reedy: >> I am using Thunderbird, win64, as news client for gmane. The post looked >> fine as originally received. The indents only disappeared when I hit >> reply and the >s were added. > > I can confirm this misbehaviour of Thunderbird (version 11.0 here), it > strips the leading spaces when you begin a reply. > > Uli But since it doesn't do it on all messages, have you also confirmed that it does it for a text message? My experience seems to be that only the html messages are messed up that way. of course, it could be lots of other things, like which gateways did the message go through, was it originally sent via the google-mars bridge, etc. -- DaveA From nathan.alexander.rice at gmail.com Fri Mar 30 09:46:28 2012 From: nathan.alexander.rice at gmail.com (Nathan Rice) Date: Fri, 30 Mar 2012 09:46:28 -0400 Subject: Python is readable In-Reply-To: <4f758f43$0$29981$c3e8da3$5496439d@news.astraweb.com> References: <4f612b19$0$1379$4fafbaef@reader2.news.tin.it> <4f750f9f$0$29981$c3e8da3$5496439d@news.astraweb.com> <4f752a3a$0$29981$c3e8da3$5496439d@news.astraweb.com> <4f758f43$0$29981$c3e8da3$5496439d@news.astraweb.com> Message-ID: >> Mathematics is all about abstraction. ?There are theories and structures >> in mathematics that have probably gone over a hundred years before being >> applied. ?As an analogy, just because a spear isn't useful while farming >> doesn't mean it won't save your life when you venture into the woods and >> come upon a bear. > > A spear is a concrete application of the principle of leverage, not an > abstraction. I also point out leverage was discovered experimentally long > before anyone had an abstraction for it. And an analogy is a device to demonstrate the fundamental character of an argument in a different context. > In any case, so what? Who is saying that mathematics is useless? Not me, > and not Joel Spolksy. You are hunting strawmen with your non-abstract > spear. I don't think it is a strawman. He decries things that aren't immediately useful. That describes almost all pure math. If he had excluded things that have some characteristic of truth, and just talked about overly general systems, I might agree with him. > Spolsky has written at least three times about Architecture Astronauts, > and made it abundantly clear that the problem with them is that they > don't solve problems, they invent overarching abstractions that don't do > anything useful or important, and hype them everywhere. I believe in the idea of "things should be as simple as possible, but not simpler". Programming as it currently exists is absolutely convoluted. I am called on to help people learn to program from time to time, and I can tell you that we still have a LONG way to go before programming approaches a global optimum in either the semantic or syntactic space. Never mind configuring a build or anything else related to projects. The whole setup really is horrible, and I'm convinced that most of the people who are capable of changing this are more concerned about their personal investment in the way things are than helping others. There are a few exceptions like Alan Kay, but mostly people want to graft shortcuts on to what already exists. > You keep reading this as an assault on abstract mathematics, science and > knowledge for its on sake. It isn't any of these things. I never said it was an attack on science. Scientists don't really do abstraction, they explain observations. Mathematicians are the ones who discover truth that may be completely disconnected from reality. > If I'm paid to solve a problem, and instead I build an abstraction that > doesn't help solve the problem, then I'm guilty of doing architecture > astronauting. If I ignore everything Joel wrote and just use that definition, I agree with you. >> He is basically saying they are too clever for their own good, as a >> result of being fixated upon purely intellectual constructs. > > Yes, and he is right to do so, because that is the characteristic of the > Architecture Astronaut: being so fixated on over-arching abstract > concepts that, far from those abstractions making it easier to solve the > problems they are being paid to solve, they actually make them harder. > > Good abstractions enable problems to be solved. Bad abstractions don't. > > If I ask you to build me a website, I probably don't want a website- > builder, I certainly don't want a website-builder-generator, and I > absolutely do not want you to generalise the concept of a compiler and > create a whole new abstract language for describing meta-compilers so > that I can create a brand new programming language for generating meta- > compilers that build compilers that will build factories for building > website generators so I can make my own website in just three easy steps > (the simplest one of which is about twice as difficult as just building > the website would have been). Again, I follow the principle of "everything should be as simple as possible, but no simpler". I have in the past built website builders rather than build websites (and done a similar thing in other cases), but not because I am trying to discover some fundamental truth of website building, because that would be bullshit. I did it because building websites (or whatever else it was) is a boring, tedious problem, and a website builder, while being more work, is an engaging problem that requires thought. I enjoy challenging myself. > If you are being paid to build abstractions in the ivory tower, on the > chance that one in a thousand abstractions turns out to be a game > changer, or just because of a love of pure knowledge, that's great. I > love abstract mathematics too. I read maths in my free time, you won't > find me saying that it is bad or useless or harmful. But does it solve > real problems? You forget that even abstractions that never directly get turned into something real are almost invariably part of the intellectual discourse that leads to real things. > Well, of course it does, and often in a most surprising places. But > that's because out of the hundred thousand abstractions, we see the > hundred that actually solve concrete problems. The other 99,999 exist > only in forgotten journals, or perhaps the odd book here or there. It is pretty rare that an article that has some element of truth doesn't live on through its intellectual progeny. The abstraction that is used in some amazing way will almost always have a large number of "useless" abstractions as intellectual ancestors. This is easy to see just by following the chain of citations for a paper. > This is all well and good. It's not meant as an attack on mathematics. > You can't tell ahead of time which abstractions will solve real problems. > *Somebody* has to be thinking about ways that spherical camels can pass > through the eye of a 17-dimensional needle, because you never know when > somebody else will say, "Hey, that's just what we need to make low-fat > chocolate ice cream that doesn't taste like crap!" and then you'll be > richer beyond all the dreams of avarice. I think you're overly concerned with money and consumption Steven. Those things are ephemeral. Things like truth and beauty are eternal. Moreover, research in psychology suggests people who pursue money and consumption are less happy in general than people who derive joy from creation. > But that doesn't mean that you have to turn every one of those > abstractions into software. I don't really care if checking my email and > deleting a file are both special cases of some abstract file operation, I > don't need to see it in my file manager. Careful Steven, when you make statements like this, it makes me want to agree with you. People are paralyzed by choice, and in general they want to be told what to do, so having interfaces tons of options actually distresses them. >> The electronic properties of silicon (among other compounds) is an >> obvious example of where quantum theory provides for us. ?We might have >> basic circuits, but we wouldn't have semiconductors. > > A poor example. The existence of semiconductors was demonstrated, not > predicted: Michael Faraday discovered the existence of semiconductors in > 1833, *long* before quantum theory: He observed a phenomenon, he did not explain it. > But what's your point here? We started off talking about abstractions. > Quantum mechanics is not an abstraction, or at least no more than any > other physical theory. It is a *description* of reality (a model), not a > generalisation. Lattice theory, rings of operators, Hilbert spaces, Lebesgue measure. All very abstract mathematical structures created not to solve a particular problem in the real world, but as descriptions of mathematical truth. > To counter Spolksy, you need to show the great practical discoveries and > inventions, not of quantum mechanics, but of a *generalisation* of > quantum mechanics that encompasses QM as a special, concrete, example. Quantum mechanics is built on a foundation of "meaningless" abstractions. If those abstractions did not exist we wouldn't have computers. > > [...] >> The stochastic method, while useful, is many orders of magnitude less >> efficient than analytically closed solutions. ?Not having access to >> closed form solutions would have put us back hundreds of years at least. > > We don't have closed-form solutions. > > At best we have closed-form solutions of simplified and idealised > problems. E.g. we don't have a closed-form solution for the actual > hydrogen atom, only of a simplified model of that atom: Of course, the world is complex and stochastic. The only complete solution of a system is the system itself. Thankfully, things like the central limit theorem allow us to pretend a lot of that complexity doesn't exist without sacrificing much. > As the famous saying goes, the more advanced the theory, the fewer > entities it can solve exactly. Newtonian physics can't solve the three > body problem exactly; Einsteinian physics can't solve the two body > problem; quantum mechanics can't solve the one body problem; and quantum > gravity can't solve the zero body problem (the vacuum). That may be true in some cases, but I wouldn't call that a universal. If you have to cross a boundary from linear to nonlinear or finitary to infinitary, of course things are going to get messy, because some areas of math are better developed than others. A complex linear system is just as easy to work with as a simple linear system though. From showell30 at yahoo.com Fri Mar 30 12:02:38 2012 From: showell30 at yahoo.com (Steve Howell) Date: Fri, 30 Mar 2012 09:02:38 -0700 (PDT) Subject: Python is readable References: <4f612b19$0$1379$4fafbaef@reader2.news.tin.it> <4f750f9f$0$29981$c3e8da3$5496439d@news.astraweb.com> <4f752a3a$0$29981$c3e8da3$5496439d@news.astraweb.com> <4f758f43$0$29981$c3e8da3$5496439d@news.astraweb.com> Message-ID: <64eb2ae9-b4ec-4acb-92bf-de4a86f0b83c@sv8g2000pbc.googlegroups.com> On Mar 30, 3:47?am, Steven D'Aprano wrote: > If you are being paid to build abstractions in the ivory tower, on the > chance that one in a thousand abstractions turns out to be a game > changer, or just because of a love of pure knowledge, that's great. I > love abstract mathematics too. I read maths in my free time, you won't > find me saying that it is bad or useless or harmful. But does it solve > real problems? > > Well, of course it does, and often in a most surprising places. But > that's because out of the hundred thousand abstractions, we see the > hundred that actually solve concrete problems. The other 99,999 exist > only in forgotten journals, or perhaps the odd book here or there. > Steven, how do you predict which abstractions are going to be useless? There was a time when imaginary numbers were just little toys that the mathematicians played around with in their ivory towers. I mean, really, what possible use could we have for the square root of -1, other than to entertain mathematicians avoiding "real" problems? Now the complex number plane helps us do 3-D math (air traffic control), circuit design (radios, computers), and frequency analysis (telecommunication). From rosuav at gmail.com Fri Mar 30 12:20:35 2012 From: rosuav at gmail.com (Chris Angelico) Date: Sat, 31 Mar 2012 03:20:35 +1100 Subject: Python is readable In-Reply-To: References: <4f612b19$0$1379$4fafbaef@reader2.news.tin.it> <4f750f9f$0$29981$c3e8da3$5496439d@news.astraweb.com> <4f752a3a$0$29981$c3e8da3$5496439d@news.astraweb.com> <4f758f43$0$29981$c3e8da3$5496439d@news.astraweb.com> Message-ID: On Sat, Mar 31, 2012 at 12:46 AM, Nathan Rice wrote: > I believe in the idea of "things should be as simple as possible, but > not simpler". ?Programming as it currently exists is absolutely > convoluted. ?I am called on to help people learn to program from time > to time, and I can tell you that we still have a LONG way to go before > programming approaches a global optimum in either the semantic or > syntactic space. Aside from messes of installing and setting up language interpreters/compilers, which are averted by simply having several pre-installed (I think my Linux boxes come with some Python 2 version, Perl, bash, and a few others), that isn't really the case. Starting a Python script is easy. Programming gets convoluted only when, and to the extent that, the task does. ChrisA From ramit.prasad at jpmorgan.com Fri Mar 30 12:40:19 2012 From: ramit.prasad at jpmorgan.com (Prasad, Ramit) Date: Fri, 30 Mar 2012 16:40:19 +0000 Subject: Python is readable In-Reply-To: References: <4f612b19$0$1379$4fafbaef@reader2.news.tin.it> <4f750f9f$0$29981$c3e8da3$5496439d@news.astraweb.com> <4f752a3a$0$29981$c3e8da3$5496439d@news.astraweb.com> Message-ID: <5B80DD153D7D744689F57F4FB69AF474092943BB@SCACMX008.exchad.jpmchase.net> > > My aunt makes the best damn lasagna you've ever tasted without any > > overarching abstract theory of human taste. And if you think that > quantum > > mechanics is more difficult than understanding human perceptions of > > taste, you are badly mistaken. > > Taste is subjective, and your aunt probably started from a good recipe > and tweaked it for local palates. That recipe could easily be over a > hundred years old. An overarching mathematical theory of human > taste/mouth perception, if such a silly thing were to exist, would be > able to generate new recipes that were perfect for a given person's > tastes very quickly. > > Additionally, just to troll this point some more (fun times!), I would > argue that there is an implicit theory of human taste (chefs refer to > it indirectly as gastronomy) that is very poorly organized and lacks > any sort of scientific rigor. Nonetheless, enough empirical > observations about pairings of flavors, aromas and textures have been > made to guide the creation of new recipes. Gastronomy doesn't need to > be organized or rigorous because fundamentally it isn't very > important. I cannot live without eating, I can live just fine without math. Your opinion that gastronomy is fundamentally unimportant is fundamentally flawed. > > In any case, Spolsky is not making a general attack on abstract science. > > Your hyperbole is completely unjustified. > > The mathematics of the 20th century, (from the early 30s onward) tend > to get VERY abstract, in just the way Joel decries. Category theory, > model theory, modern algebraic geometry, topos theory, algebraic graph > theory, abstract algebras and topological complexes are all very > difficult to understand because they seem so incredibly abstract, yet > most of them already have important applications. I'm 100% positive > if you just presented Joel with seminal papers in some of those areas, > he would apply the "astronaut" rubber stamp, because the material is > challenging, and he wouldn't get it (I love math, and I've had to read > some papers 10+ times before they click). I do not think that you can compare abstract vs real world. Joel talks in the context of solving real-world problems for a living and producing tangible results to justify employment. It is only fair to talk about mathematics in the same context. Or vice-versa. Joining-the-trolling-bandwagon, Ramit Ramit Prasad | JPMorgan Chase Investment Bank | Currencies Technology 712 Main Street | Houston, TX 77002 work phone: 713 - 216 - 5423 -- This email is confidential and subject to important disclaimers and conditions including on offers for the purchase or sale of securities, accuracy and completeness of information, viruses, confidentiality, legal privilege, and legal entity disclaimers, available at http://www.jpmorgan.com/pages/disclosures/email. From ethan at stoneleaf.us Fri Mar 30 13:45:39 2012 From: ethan at stoneleaf.us (Ethan Furman) Date: Fri, 30 Mar 2012 10:45:39 -0700 Subject: unittest: assertRaises() with an instance instead of a type In-Reply-To: <4f751e31$0$29981$c3e8da3$5496439d@news.astraweb.com> References: <4f735345$0$29981$c3e8da3$5496439d@news.astraweb.com> <4f751e31$0$29981$c3e8da3$5496439d@news.astraweb.com> Message-ID: <4F75F143.7000000@stoneleaf.us> Steven D'Aprano wrote: > To the degree that the decision of how finely to slice tests is a matter > of personal judgement and/or taste, I was wrong to say "that is not the > right way". I should have said "that is not how I would do that test". > > I believe that a single test is too coarse, and three or more tests is > too fine, but two tests is just right. Let me explain how I come to that > judgement. > > If you take a test-driven development approach, the right way to test > this is to write testFooWillFail once you decide that foo() should raise > MyException but before foo() actually does so. You would write the test, > the test would fail, and you would fix foo() to ensure it raises the > exception. Then you leave the now passing test in place to detect > regressions. > > Then you do the same for the errorcode. Hence two tests. [snip] > So: never remove tests just because they are redundant. Only remove them > when they are obsolete due to changes in the code being tested. Very persuasive argument -- I now find myself disposed to writing two tests (not three, nor five ;). ~Ethan~ From rustompmody at gmail.com Fri Mar 30 13:54:25 2012 From: rustompmody at gmail.com (rusi) Date: Fri, 30 Mar 2012 10:54:25 -0700 (PDT) Subject: Number of languages known [was Re: Python is readable] - somewhat OT References: Message-ID: On Mar 30, 4:37?am, Devin Jeanpierre wrote: > On Thu, Mar 29, 2012 at 3:50 PM, Nathan Rice > > wrote: > > Well, a lisp-like language. ?I would also argue that if you are using > > macros to do anything, the thing you are trying to do should classify > > as "not natural in lisp" :) > > You would run into disagreement. Some people feel that the lisp > philosophy is precisely that of extending the language to do anything > you want, in the most natural way. > > At least, I disagree, but my lisp thoughts are the result of > indoctrination of the Racket crowd. I guess Paul Graham would likewise disagree. See 7,8,9 in http://paulgraham.com/diff.html From nathan.alexander.rice at gmail.com Fri Mar 30 14:15:20 2012 From: nathan.alexander.rice at gmail.com (Nathan Rice) Date: Fri, 30 Mar 2012 14:15:20 -0400 Subject: Python is readable In-Reply-To: References: <4f612b19$0$1379$4fafbaef@reader2.news.tin.it> <4f750f9f$0$29981$c3e8da3$5496439d@news.astraweb.com> <4f752a3a$0$29981$c3e8da3$5496439d@news.astraweb.com> <4f758f43$0$29981$c3e8da3$5496439d@news.astraweb.com> Message-ID: On Fri, Mar 30, 2012 at 12:20 PM, Chris Angelico wrote: > On Sat, Mar 31, 2012 at 12:46 AM, Nathan Rice > wrote: >> I believe in the idea of "things should be as simple as possible, but >> not simpler". ?Programming as it currently exists is absolutely >> convoluted. ?I am called on to help people learn to program from time >> to time, and I can tell you that we still have a LONG way to go before >> programming approaches a global optimum in either the semantic or >> syntactic space. > > Aside from messes of installing and setting up language > interpreters/compilers, which are averted by simply having several > pre-installed (I think my Linux boxes come with some Python 2 version, > Perl, bash, and a few others), that isn't really the case. Starting a > Python script is easy. Programming gets convoluted only when, and to > the extent that, the task does. It is true that program complexity is correlated with problem complexity, language and environment complexity is undeniable. If you want to prove this to yourself, find someone who is intelligent and has some basic level of computer literacy, sit them down at a computer and ask them to solve simple problems using programs. You could even be nice by opening the editor first. Don't help them, just watch them crash and burn. Then sit them in front of code that already works, and ask them to modify it to do something slightly different, and again just watch them crash and burn in all but the simplest of cases. It is painful - most of the time they just give up. These same people almost universally can describe the exact process of steps verbally or in writing to do what is required without any trouble; there might be some neglected edge cases, but if you describe the failed result, often times they will realize their mistake and be able to fix it quickly. Jeff Atwood had an article about programming sheep and non programming goats, and while he views it as a statement about people's failings, I view it as a statement about the failings of programming. Human computer interaction is really important, and the whole prefab GUI concept doesn't scale along any axis; people need to be able to interact with their computers in a flexible manner. In the beginning, we had no choice but to bend our communication to the the machine, but we're moving past that now. The machine should respect the communication of humans. We shouldn't decry natural language because of ambiguity; If we're ambiguous, the machine should let us know and ask for clarification. If we phrase things in a really awkward way, the machine should tell us so, and suggest a more understandable rendition (just like word processors do now). If the machine does something we didn't want based on our instructions, we should be able to state additional requirements in a declarative manner. Restricted natural languages are an active area of current research, and they clearly demonstrate that you can have an expressive formal language that is also valid English. Make no mistake about it, programming is a form of computer human interaction (I figured that would be an accepted mantra here). Think of it as modeling knowledge and systems instead of pushing bits around. You are describing things to the computer. To move from the syntactic domain to my point about programming languages, imagine if one person describes physics to a computer in French, and another person describes chemistry to a computer in English. The creators of the computer made different languages act as disjoint knowledge domains. The computer is incapable of making any inferences in physics which are informed by chemistry, and vice versa, unless someone comes along and re-describes one of the disciplines in the other language. Worse still, if someone that only speaks Mandarin comes along, the computer won't be able to tell him anything about either domain. Now imagine the creators of the computer decided that an acceptable solution was to have people print out statements from one domain in a given language, take it to another computer that scans the printout, translates it to a different language, and prints out the translated copy, then have that person take the translated copy back to the original computer, and scan it again in order to ask a cross cutting question. I hope from that perspective the paucity of our current methods will be more apparent. From rustompmody at gmail.com Fri Mar 30 14:17:23 2012 From: rustompmody at gmail.com (rusi) Date: Fri, 30 Mar 2012 11:17:23 -0700 (PDT) Subject: Python is readable References: <4f612b19$0$1379$4fafbaef@reader2.news.tin.it> <4f750f9f$0$29981$c3e8da3$5496439d@news.astraweb.com> <4f752a3a$0$29981$c3e8da3$5496439d@news.astraweb.com> <4f758f43$0$29981$c3e8da3$5496439d@news.astraweb.com> <64eb2ae9-b4ec-4acb-92bf-de4a86f0b83c@sv8g2000pbc.googlegroups.com> Message-ID: On Mar 30, 9:02?pm, Steve Howell wrote: > Steven, how do you predict which abstractions are going to be useless? > > There was a time when imaginary numbers were just little toys that the > mathematicians played around with in their ivory towers. A non-science/math analogous question: When Beethoven wrote his last sonatas and quartets they were called 'the abortions of a German idealist' or less charitably the only music that a stone-deaf man could possibly write Likewise, Bach's wrote Art of Fugue was regarded as a merely academic work that codified his knowledge of fugal writing. It was many decades after their death that everyone began to regard these as the greatest pieces of music (maybe 50 for Beethoven, almost 100 for Bach). However for every one Bach/Beethoven there are 100s of fadists who are great in one generation and garbage-dumped the next. The encyclopedia of music I grew up on regarded Schoenberg et al in the Bach/Beethoven category. Almost certainly a more recent view would not. So if I side with Steven/Spolsky I would regard a (future) Bach/ Beethoven as an 'abortion.' If I side with Nathan I may waste my money and life betting on serialists/cubists and such fashionable but ephemeral fads. tl;dr version The usefulness of uber-abstractions is undecidable in the near timeframe. From rosuav at gmail.com Fri Mar 30 14:29:13 2012 From: rosuav at gmail.com (Chris Angelico) Date: Sat, 31 Mar 2012 05:29:13 +1100 Subject: Python is readable In-Reply-To: References: <4f612b19$0$1379$4fafbaef@reader2.news.tin.it> <4f750f9f$0$29981$c3e8da3$5496439d@news.astraweb.com> <4f752a3a$0$29981$c3e8da3$5496439d@news.astraweb.com> <4f758f43$0$29981$c3e8da3$5496439d@news.astraweb.com> Message-ID: On Sat, Mar 31, 2012 at 5:15 AM, Nathan Rice wrote: > It is true that program complexity is correlated with problem > complexity, language and environment complexity is undeniable. ?If you > want to prove this to yourself, find someone who is intelligent and > has some basic level of computer literacy, sit them down at a computer > and ask them to solve simple problems using programs. ?You could even > be nice by opening the editor first. ?Don't help them, just watch them > crash and burn. ?Then sit them in front of code that already works, > and ask them to modify it to do something slightly different, and > again just watch them crash and burn in all but the simplest of cases. > ?It is painful - most of the time they just give up. ?These same > people almost universally can describe the exact process of steps > verbally or in writing to do what is required without any trouble; > there might be some neglected edge cases, but if you describe the > failed result, often times they will realize their mistake and be able > to fix it quickly. This is more a matter of being unable to express themselves appropriately. If I allowed them to write an exact process of steps to do what's required, those steps would either be grossly insufficient for the task, or would BE pseudo-code. There are plenty of people who cannot write those sorts of instructions at all. They're called non-programmers. Anyone who doesn't code but can express a task in such clear steps as you describe is what I would call a non-coding programmer - and such people are VERY easily elevated to full programmer status. I've worked with several like that, and the border between that kind of clear, concise, simple instruction list and actual Python or REXX code is so small as to be almost nonexistent. It's not the programming languages' fault. It's a particular jump in thinking that must be overcome before a person can use them. There are other similar jumps in thinking. On which side of these lines are you? Do you remember making the shift? Or, conversely, do you stare at it with "Huh? Why would I do that?"? * Source control. Don't just keep daily backups - record specific purposeful changes in a log. * WYSIWYG document editing vs plain-text with a compiler. Pass up Open Office (or worse) in favour of LaTeX, abandon Sibelius in favour of Lilypond. Plays very nicely with source control. * Unicode instead of head-in-the-sand pretending that ASCII is good enough. * Open standards and toolchains instead of expecting monolithic proprietary programs to do your work for you. Etcetera, etcetera. Everyone who's made the jump will see the benefit of the side they're on; most who haven't won't. Same with non-programmers to programmers. Why should I write like that when I could just write English? Simple: Because dedicated programming languages are far more expressive for the job. ChrisA From lambertk at wlu.edu Fri Mar 30 14:31:51 2012 From: lambertk at wlu.edu (lambertk at wlu.edu) Date: Fri, 30 Mar 2012 11:31:51 -0700 (PDT) Subject: breezypythongui: A New Toolkit for Easy GUIs in Python Message-ID: breezypythongui is an open source toolkit that enables the Python programmer to learn realistic GUI programming quickly and easily. For free source code, demo programs, and a tutorial, visit http://home.wlu.edu/~lambertk/breezypythongui/index.html. Brought to you by Ken Lambert, the author of Fundamentals of Python: First Programs. From cartercc at gmail.com Fri Mar 30 14:49:23 2012 From: cartercc at gmail.com (ccc31807) Date: Fri, 30 Mar 2012 11:49:23 -0700 (PDT) Subject: Is Programing Art or Science? References: Message-ID: Programming is neither an art nor a science, but a trade. It's not an art in the sense of painting, music, dance, poetry, etc., because the objective isn't to make a beautiful something, but to give instructions to a machine to accomplish some useful task. It's not a science in the sense of either physics and chemistry (experimental) or geology or astronomy (observational) or cosmology or psychology (theoretical) because the objective isn't to test hypothetical s against data, but to give instructions to a machine to accomplish some useful task. Obviously, it's very much connected with art (e.g., user interface design) and science (e.g., artificial intelligence) but the practice of giving instructions to a machine is more like assembling machines in a factory than the pursuit of an art or the practice of a science. CC. From storchaka at gmail.com Fri Mar 30 15:06:45 2012 From: storchaka at gmail.com (Serhiy Storchaka) Date: Fri, 30 Mar 2012 22:06:45 +0300 Subject: "convert" string to bytes without changing data (encoding) In-Reply-To: <1053a4e195cf2e85778f6c2c63dc89d4@modelnine.org> References: "\"<9tg21lFmo3U1@mid.dfncis.de>" " <9tg4qoFbfpU1@mid.dfncis.de> <9th0u8Fuf2U1@mid.dfncis.de> <1053a4e195cf2e85778f6c2c63dc89d4@modelnine.org> Message-ID: 28.03.12 21:13, Heiko Wundram ???????(??): > Reading from stdin/a file gets you bytes, and > not a string, because Python cannot automagically guess what format the > input is in. In Python3 reading from stdin gets you string. Use sys.stdin.buffer.raw for access to byte stream. And reading from file opened in text mode gets you string too. From rosuav at gmail.com Fri Mar 30 15:10:03 2012 From: rosuav at gmail.com (Chris Angelico) Date: Sat, 31 Mar 2012 06:10:03 +1100 Subject: "convert" string to bytes without changing data (encoding) In-Reply-To: References: <9tg21lFmo3U1@mid.dfncis.de> <9tg4qoFbfpU1@mid.dfncis.de> <9th0u8Fuf2U1@mid.dfncis.de> <1053a4e195cf2e85778f6c2c63dc89d4@modelnine.org> Message-ID: On Sat, Mar 31, 2012 at 6:06 AM, Serhiy Storchaka wrote: > 28.03.12 21:13, Heiko Wundram ???????(??): > >> Reading from stdin/a file gets you bytes, and >> not a string, because Python cannot automagically guess what format the >> input is in. > > > In Python3 reading from stdin gets you string. Use sys.stdin.buffer.raw for > access to byte stream. And reading from file opened in text mode gets you > string too. True. But that's only if it's been told the encoding of stdin (which I believe is the normal case on Linux). It's still not "automagically guess(ing)", it's explicitly told. ChrisA From nathan.alexander.rice at gmail.com Fri Mar 30 15:55:45 2012 From: nathan.alexander.rice at gmail.com (Nathan Rice) Date: Fri, 30 Mar 2012 15:55:45 -0400 Subject: Python is readable In-Reply-To: References: <4f612b19$0$1379$4fafbaef@reader2.news.tin.it> <4f750f9f$0$29981$c3e8da3$5496439d@news.astraweb.com> <4f752a3a$0$29981$c3e8da3$5496439d@news.astraweb.com> <4f758f43$0$29981$c3e8da3$5496439d@news.astraweb.com> Message-ID: > This is more a matter of being unable to express themselves > appropriately. If I allowed them to write an exact process of steps to > do what's required, those steps would either be grossly insufficient > for the task, or would BE pseudo-code. There are plenty of people who > cannot write those sorts of instructions at all. They're called > non-programmers. Anyone who doesn't code but can express a task in > such clear steps as you describe is what I would call a non-coding > programmer - and such people are VERY easily elevated to full > programmer status. I've worked with several like that, and the border > between that kind of clear, concise, simple instruction list and > actual Python or REXX code is so small as to be almost nonexistent. > It's not the programming languages' fault. It's a particular jump in > thinking that must be overcome before a person can use them. Your statement that the difference between Python or REXX and pseudo-code is almost non existent is completely false. While people reading Python might be able to guess with higher accuracy what a program does than some other programming languages, there is still a set of VERY specific set of glyphs, words and phrase structures it requires. Pretty much anyone can follow a recipe to make a meal (and there are a lot other examples of this), and conversely given the knowledge of how to make some dish, pretty much everyone could describe the process as a recipe. The same person will fail miserably when trying to create working code that is MUCH simpler from a conceptual standpoint. "Non coders" are not stupid, they just don't appreciate the multitude of random distinctions and computer specific abstractions programming foists on them for the purpose of writing EFFICIENT code. I'm talking about like multiple int/number types, umpteen different kinds of sequences, tons of different data structures that are used for basically the same things under different circumstances, indices starting at 0 (which makes amazing sense if you think like a machine, and very little if you think like a human), the difference between logical and bitwise operators (union and intersection would be better names for the latter), string encoding, etc. When you combine these with having to communicate in a new (very arbitrary, sometimes nonsensical) vocabulary that doesn't recognize synonyms, using an extremely restricted phrase structure and an environment with very limited interactivity, it should become clear that the people who learn to program are invariably fascinated by computers and very motivated to do so. I'm going to assume that you didn't mean that "non coders" are incapable of instructing others (even though your statement implies it directly). I think the ability of "non coders" to describe procedures would surprise you. Things I hear over and over from "non coders" all tie into people being frustrated that computers don't grasp similarity, and don't try to figure out what they want at all; most people provide instructions in an interactive manner. The computer is too stupid to interact with humans, so you have to tell it what to do, then try to run it, watch it fail, then go back and modify your program, which is highly unnatural. I think you'd find that these "non coders" would do very well if given the ability to provide instructions in a natural, interactive way. They are not failing us, we are failing them. > Etcetera, etcetera. Everyone who's made the jump will see the benefit > of the side they're on; most who haven't won't. Same with > non-programmers to programmers. Why should I write like that when I > could just write English? Simple: Because dedicated programming > languages are far more expressive for the job. Really? Or could it be that algorithms for natural language processing that don't fail miserably is a very recent development, restricted natural languages more recent still, and pretty much all commonly used programming languages are all ~20+ years old? Could it also be that most programmers don't see a lot of incentives to make things accessible, since they're already invested in the status quo, and they might lose some personal value if programming stopped being an arcane practice? Creating a programming language is a time consuming and laborious process, the fact that people are doing it constantly is a clear indication that what we have is insufficient. From rosuav at gmail.com Fri Mar 30 16:20:39 2012 From: rosuav at gmail.com (Chris Angelico) Date: Sat, 31 Mar 2012 07:20:39 +1100 Subject: Python is readable In-Reply-To: References: <4f612b19$0$1379$4fafbaef@reader2.news.tin.it> <4f750f9f$0$29981$c3e8da3$5496439d@news.astraweb.com> <4f752a3a$0$29981$c3e8da3$5496439d@news.astraweb.com> <4f758f43$0$29981$c3e8da3$5496439d@news.astraweb.com> Message-ID: On Sat, Mar 31, 2012 at 6:55 AM, Nathan Rice wrote: > I think you'd find that these "non coders" would do very well if given > the ability to provide instructions in a natural, interactive way. > They are not failing us, we are failing them. The nearest thing to natural-language command of a computer is voice navigation, which is another science that's plenty old and yet still current (I first met it back in 1996 and it wasn't new then). You tell the computer what you want it to do, and it does it. Theoretically. The vocabulary's a lot smaller than all of English, of course, but that's not a problem. The problem is that it's really REALLY slow to try to get anything done in English, compared to a dedicated domain-specific language (in the case of typical OS voice navigation, the nearest equivalent would probably be a shell script). > Really? ?Or could it be that algorithms for natural language > processing that don't fail miserably is a very recent development, > restricted natural languages more recent still, and pretty much all > commonly used programming languages are all ~20+ years old? ?Could it > also be that most programmers don't see a lot of incentives to make > things accessible, since they're already invested in the status quo, > and they might lose some personal value if programming stopped being > an arcane practice? Totally. That's why we're all still programming in assembly language and doing our own memory management, because we would lose a lot of personal value if programming stopped being so difficult. If it weren't for all these silly new-fangled languages with their automatic garbage collection and higher order function handling, we would all be commanding much higher salaries. ChrisA From neilc at norwich.edu Fri Mar 30 16:30:31 2012 From: neilc at norwich.edu (Neil Cerutti) Date: 30 Mar 2012 20:30:31 GMT Subject: Python is readable References: <4f612b19$0$1379$4fafbaef@reader2.news.tin.it> <4f750f9f$0$29981$c3e8da3$5496439d@news.astraweb.com> <4f752a3a$0$29981$c3e8da3$5496439d@news.astraweb.com> <4f758f43$0$29981$c3e8da3$5496439d@news.astraweb.com> Message-ID: <9tmjf7FqldU1@mid.individual.net> On 2012-03-30, Nathan Rice wrote: > Restricted natural languages are an active area of current > research, and they clearly demonstrate that you can have an > expressive formal language that is also valid English. See, for example, Inform 7, which translates a subset of English into Inform 6 code. I never thought too deeply about why I disliked it, assuming it was because I already knew Inform 6. Would you like to write the equivalent, e.g., C code in English? -- Neil Cerutti From dan at tombstonezero.net Fri Mar 30 16:51:21 2012 From: dan at tombstonezero.net (Dan Sommers) Date: Fri, 30 Mar 2012 16:51:21 -0400 Subject: Python is readable In-Reply-To: References: <4f612b19$0$1379$4fafbaef@reader2.news.tin.it> <4f750f9f$0$29981$c3e8da3$5496439d@news.astraweb.com> <4f752a3a$0$29981$c3e8da3$5496439d@news.astraweb.com> <4f758f43$0$29981$c3e8da3$5496439d@news.astraweb.com> Message-ID: <20120330165121.60b989f1@particle> On Sat, 31 Mar 2012 07:20:39 +1100 Chris Angelico wrote: > ... That's why we're all still programming in assembly language and > doing our own memory management, because we would lose a lot of > personal value if programming stopped being so difficult. If it > weren't for all these silly new-fangled languages with their automatic > garbage collection and higher order function handling, we would all be > commanding much higher salaries. Back in the 1970's, the magazines were full of ads for "never write another line of code again" programs. A keystroke here, a keystroke there (those were the days *before* drag-and-drop and point-and-drool), and even managers and executives could "write programs." Now, of course, those managers and executives still command higher salaries, so I guess ChrisA is right about us assembly language guys losing our personal value. Dan From nathan.alexander.rice at gmail.com Fri Mar 30 16:58:59 2012 From: nathan.alexander.rice at gmail.com (Nathan Rice) Date: Fri, 30 Mar 2012 16:58:59 -0400 Subject: Python is readable In-Reply-To: References: <4f612b19$0$1379$4fafbaef@reader2.news.tin.it> <4f750f9f$0$29981$c3e8da3$5496439d@news.astraweb.com> <4f752a3a$0$29981$c3e8da3$5496439d@news.astraweb.com> <4f758f43$0$29981$c3e8da3$5496439d@news.astraweb.com> Message-ID: On Fri, Mar 30, 2012 at 4:20 PM, Chris Angelico wrote: > On Sat, Mar 31, 2012 at 6:55 AM, Nathan Rice > wrote: >> I think you'd find that these "non coders" would do very well if given >> the ability to provide instructions in a natural, interactive way. >> They are not failing us, we are failing them. > > The nearest thing to natural-language command of a computer is voice > navigation, which is another science that's plenty old and yet still > current (I first met it back in 1996 and it wasn't new then). You tell > the computer what you want it to do, and it does it. Theoretically. > The vocabulary's a lot smaller than all of English, of course, but > that's not a problem. The problem is that it's really REALLY slow to > try to get anything done in English, compared to a dedicated > domain-specific language (in the case of typical OS voice navigation, > the nearest equivalent would probably be a shell script). I'm sure a ford truck would smoke a twin engine cessna if you compare their speed on the ground. Let the cessna fly and the ford doesn't have a snowball's chance. If you're navigating by going "cee dee space slash somefolder slash some other folder slash some third folder slash semicolon emacs somename dash some other name dash something dot something else dot one" the analogy would be a boss telling his secretary to reserve him a flight by saying "visit site xyz, click on this heading, scroll halfway down, open this menu, select this destination, ..." instead of "book me a flight to San Jose on the afternoon of the 23rd, and don't spend more than $500". > Totally. That's why we're all still programming in assembly language > and doing our own memory management, because we would lose a lot of > personal value if programming stopped being so difficult. If it > weren't for all these silly new-fangled languages with their automatic > garbage collection and higher order function handling, we would all be > commanding much higher salaries. Did you miss the fact that a 50 year old programming language (which still closely resembles its original form) is basically tied for the title of currently most popular, and the 3 languages following it are both nominal and spiritual successors, with incremental improvements in features but sharing a large portion of the design. Programming language designers purposefully try to make their language C-like, because not being C-like disqualifies a language from consideration for a HUGE portion of programmers, who cower at the naked feeling they get imagining a world without curly braces. Fear of change and the unknown are brutal, and humans are cowardly creatures that will grasp at whatever excuses they can find not to acknowledge their weaknesses. I also mentioned previously, most developers are just trying to graft shortcut after shortcut on to what is comfortable and familiar because we're inherently lazy. Additionally, I'm quite certain that when we finally do have a method for programming/interacting with computers in a natural way, many people invested in previous methods will make snarky comments about how lame and stupid people using the new methods are, just like we saw with command line/keyboard elitists who make fun of people who prefer a mouse/gui, even though in most cases research showed that the people using the mouse/gui actually got work done faster. You can even look at some comments on this thread for evidence of this. From nagle at animats.com Fri Mar 30 17:20:35 2012 From: nagle at animats.com (John Nagle) Date: Fri, 30 Mar 2012 14:20:35 -0700 Subject: Will MySQL ever be supported for Python 3.x? Message-ID: The MySQLdb entry on SourceForge (http://sourceforge.net/projects/mysql-python/) web site still says the last supported version of Python is 2.6. PyPi says the last supported version is Python 2.5. The last download is from 2007. I realize there are unsupported fourth-party versions from other sources. (http://www.lfd.uci.edu/~gohlke/pythonlibs/) But those are just blind builds; they haven't been debugged. MySQL Connector (http://forge.mysql.com/projects/project.php?id=302) is still pre-alpha. John Nagle From irmen.NOSPAM at xs4all.nl Fri Mar 30 17:32:32 2012 From: irmen.NOSPAM at xs4all.nl (Irmen de Jong) Date: Fri, 30 Mar 2012 23:32:32 +0200 Subject: Will MySQL ever be supported for Python 3.x? In-Reply-To: References: Message-ID: <4f762670$0$6871$e4fe514c@news2.news.xs4all.nl> On 30-3-2012 23:20, John Nagle wrote: > The MySQLdb entry on SourceForge > (http://sourceforge.net/projects/mysql-python/) > web site still says the last supported version of Python is 2.6. > PyPi says the last supported version is Python 2.5. The > last download is from 2007. > > I realize there are unsupported fourth-party versions from other > sources. (http://www.lfd.uci.edu/~gohlke/pythonlibs/) But those > are just blind builds; they haven't been debugged. > > MySQL Connector (http://forge.mysql.com/projects/project.php?id=302) > is still pre-alpha. Try Oursql instead http://packages.python.org/oursql/ "oursql is a new set of MySQL bindings for python 2.4+, including python 3.x" Irmen From rosuav at gmail.com Fri Mar 30 17:45:30 2012 From: rosuav at gmail.com (Chris Angelico) Date: Sat, 31 Mar 2012 08:45:30 +1100 Subject: Python is readable In-Reply-To: References: <4f612b19$0$1379$4fafbaef@reader2.news.tin.it> <4f750f9f$0$29981$c3e8da3$5496439d@news.astraweb.com> <4f752a3a$0$29981$c3e8da3$5496439d@news.astraweb.com> <4f758f43$0$29981$c3e8da3$5496439d@news.astraweb.com> Message-ID: On Sat, Mar 31, 2012 at 7:58 AM, Nathan Rice wrote: > Programming > language designers purposefully try to make their language C-like, > because not being C-like disqualifies a language from consideration > for a HUGE portion of programmers, who cower at the naked feeling they > get imagining a world without curly braces. ?Fear of change and the > unknown are brutal, and humans are cowardly creatures that will grasp > at whatever excuses they can find not to acknowledge their weaknesses. Braces are clear delimiters. English doesn't have them, and suffers for it. (Python's indentation is, too, but English doesn't have that either.) It's a lot harder to mark the end of an "if" block in English than in pretty much any programming language. And be careful of what has to be given up to gain your conveniences. I've used languages that demand variable declarations and ones that don't, and I'm very much a fan of the former. There are many benefits to being explicit about that. ChrisA From nagle at animats.com Fri Mar 30 17:46:55 2012 From: nagle at animats.com (John Nagle) Date: Fri, 30 Mar 2012 14:46:55 -0700 Subject: Will MySQL ever be supported for Python 3.x? In-Reply-To: <4f762670$0$6871$e4fe514c@news2.news.xs4all.nl> References: <4f762670$0$6871$e4fe514c@news2.news.xs4all.nl> Message-ID: On 3/30/2012 2:32 PM, Irmen de Jong wrote: > Try Oursql instead http://packages.python.org/oursql/ > "oursql is a new set of MySQL bindings for python 2.4+, including python 3.x" Not even close to being compatible with existing code. Every SQL statement has to be rewritten, with the parameters expressed differently. It's a good approach, but very incompatible. John Nagle From irmen.NOSPAM at xs4all.nl Fri Mar 30 17:55:59 2012 From: irmen.NOSPAM at xs4all.nl (Irmen de Jong) Date: Fri, 30 Mar 2012 23:55:59 +0200 Subject: Will MySQL ever be supported for Python 3.x? In-Reply-To: References: <4f762670$0$6871$e4fe514c@news2.news.xs4all.nl> Message-ID: <4f762bef$0$6885$e4fe514c@news2.news.xs4all.nl> On 30-3-2012 23:46, John Nagle wrote: > On 3/30/2012 2:32 PM, Irmen de Jong wrote: >> Try Oursql instead http://packages.python.org/oursql/ >> "oursql is a new set of MySQL bindings for python 2.4+, including python 3.x" > > Not even close to being compatible with existing code. Every SQL > statement has to be rewritten, with the parameters expressed > differently. It's a good approach, but very incompatible. You didn't state that it had to be compatible with existing code. Also, since you asked about Python 3.x, surely there are other incompatibilities you need to take care of in the existing code? (unless it's Python 3.x clean already...) Irmen From tolidtm at gmail.com Fri Mar 30 17:58:09 2012 From: tolidtm at gmail.com (Anatoli Hristov) Date: Fri, 30 Mar 2012 23:58:09 +0200 Subject: Advise of programming one of my first programs In-Reply-To: <5B80DD153D7D744689F57F4FB69AF47409293188@SCACMX008.exchad.jpmchase.net> References: <5B80DD153D7D744689F57F4FB69AF4740928C365@SCACMX008.exchad.jpmchase.net> <5B80DD153D7D744689F57F4FB69AF4740928E137@SCACMX008.exchad.jpmchase.net> <5B80DD153D7D744689F57F4FB69AF4740928F779@SCACMX008.exchad.jpmchase.net> <5B80DD153D7D744689F57F4FB69AF47409293188@SCACMX008.exchad.jpmchase.net> Message-ID: > > ** > > Absolutely! Too bad your version would be considered the more > ?complicated? version ;) > I`m sure about that, but I`am also sure that every beginner passed true that way. > **** > > ** ** > > >With the main navigation menu I will only have the option to select a > nickname and when a nickname is selected then it loads Details of the > contact and from loaded details I can choice Edit or back to main screen, > like I did it the first time, or else I can do it => when 'e' pressed to > ask for a nickname and then edit it. > ** > > I was trying to simplify it to ?guide? you to a more correct solution > without feeding you the answer. Maybe I should have given you the > explanation first to explain why you should be doing it a different way.** > ** > > ** ** > > Going back to your original program (and your modifications to it), the > original menu can cause crashing in more complicated programs and thus is > considered a bad style. It was basically using recursion (I will touch on > this later) but without any of the benefits. It was endlessly branching > instead of a simple loop. Sort of like the following Menu/submenu example. > **** > > ** ** > > Menu**** > > submenu**** > > Menu**** > > submenu**** > > Menu**** > > __ad infinitum__**** > > ** ** > > How does this matter? Let?s look at some simpler code below.**** > > ** ** > > print ?start?**** > > function_a() # a function is called**** > > print ?a? # code inside the function**** > > print ?b? # code inside the function**** > > a = ? something ?**** > > print a**** > > function_b() # another function call**** > > print ?c? # code inside a different function**** > > print ?d? # code inside a different function**** > > print ?end?**** > > ** ** > > Let us pretend we are the computer who executes one line at a time and so > basically goes through a list of commands. The list we are going to execute > is the following:**** > > ** ** > > print ?start?**** > > function_a()**** > > print ?a?**** > > print ?b?**** > > a = ? something ?**** > > print a**** > > function_b()**** > > print ?c?**** > > print ?d?**** > > print ?end?**** > > ** ** > > How does the computer know to execute ?a = ? something ?? after ?print > ?b??? It does it by storing the location where it was before it proceeds to > the function call. That way when the end of the function is reached it > returns to the previous spot. In essence:**** > > ** ** > > print ?start?**** > > function_a()**** > > __store this location so I can come back__**** > > print ?a?**** > > print ?b?**** > > __return to previous location__**** > > a = ? something ?**** > > print a**** > > function_b()**** > > __store this location so I can come back__**** > > print ?c?**** > > print ?b?**** > > __return to previous location__**** > > print ?end?**** > > ** ** > > Now what happens if ?function_a? calls ?function_a?? By the way, the term > for this type of call is recursion.**** > > ** ** > > print ?start?**** > > function_a()**** > > __store this location so I can come back__**** > > print ?a?**** > > print ?b?**** > > function_a()**** > > __store this location so I can come back__**** > > print ?a?**** > > print ?b?**** > > function_a()**** > > __store this location so I can come back__**** > > print ?a?**** > > print ?b?**** > > function_a()**** > > __store this location so I can come back__**** > > print ?a?**** > > print ?b?**** > > function_a()**** > > __store this location so I can come back__**** > > print ?a?**** > > print ?b?**** > > function_a()**** > > __store this location so I can come back__**** > > **until the program ends****** > > ** ** > > Now each __store__ action takes up memory and when the computer (or your > program) runs out of memory your computer crashes. Your application is > trivial and more likely to be ended by the user instead of going through > the tens of thousands if not hundreds of thousands that Python will let you > take, but it is a bad practice and a habit to avoid. A real world program > would use more memory and quit even faster than yours. Recursion has its > place in programming, but not in this case! What you need is a simple loop. > That is why I provided you with the menu I did. **** > > ** ** > > The following menu sounds like what you want; there were a couple > different ways I could have done this. In this version, if you type > anything when asked for a menu choice that is not ?e? or ?q?, the program > will automatically ask you for the next book choice.**** > > ** ** > > def mmenu():**** > > # load tbook here**** > > while True:**** > > book = get_book_choice()**** > > details( tbook, book )**** > > choicem = get_menu_choice()**** > > if choicem == 'e' or choicem == 'E':**** > > edit( tbook, book )**** > > # save tbook here**** > > elif choicem =='Q' or choicem == 'q':**** > > break # end loop to exit program**** > > ** I`m focusing on what you say and will try to follow your instructions > for which - Thank you I really appreciate it... > Just before I read you mail I`ve finished my book ver. 12 with this code, ver 13 will have all the modifications and all remarks I have from you: import ast fname = 0 lname = 1 country = 2 city = 3 tel = 4 notes = 5 ## Read data from file def load_book(): load_book = open('c:/Python27/Toli/myfile.txt', 'r') load_book = ast.literal_eval(load_book.read()) return load_book ## Write data to file def write_book(tbook): write_book = open('c:/Python27/Toli/myfile.txt', 'w') write_book.write(repr(tbook)) ## Menu choice input def get_menu_choice(): choice = raw_input('input: ') return choice ## List data contacts def listpb(): tbook = load_book() print '_' *45, ' Phonebook ', '_' *45,'\n\n\n' print 'Nick\t\tF.Name\t\tL.Name\t\tCountry\t\t\tCity\t\tTel' print '_' * 105,'\n','\t' * 13 for val in tbook.keys(): print val, '\t\t', tbook[val][fname], '\t', tbook[val][lname], '\t', tbook[val][country], '\t\t', tbook[val][city], '\t\t', tbook[val][tel],'\t\t\n' print '_'*105,'\n\n\n\n' print 'Type nickname and press or type to exit.\n\n\n' mmenu(tbook) ## Main menu def mmenu(tbook): while True: choice = get_menu_choice() if choice in tbook: details(choice,tbook) elif choice == 'q' or choice == 'Q': break else: print 'Selection {0} not understood.'.format(choice) ## Details menu def dmenu(choice, tbook): while True: choicem = get_menu_choice() if choicem == 'e' or choicem == 'E': edit(choice, tbook) elif choicem == 'b' or choicem == 'B': listpb() elif choicem =='Q' or choicem == 'q': break # end loop to exit program else: print 'Selection {0} not understood.'.format( choicem ) ## Contact details def details(choice, tbook): sb = tbook[choice] print 'Nickname: ', choice, ' is selected\n' print 'First name:\t', sb[fname], '\n' print 'Last name:\t', sb[lname], '\n' print 'Country:\t', sb[country], '\n' print 'City:\t\t', sb[city], '\n' print 'Phone number:\t',sb[tel], '\n' print 'Memos:\n' print sb[notes] print '\n\n(E)dit\n\n' print '(B)ack to phonebook list\n\n' dmenu(choice, tbook) ## Edit contact def edit(choice, tbook): sb = tbook[choice] fn = raw_input('New name for ' + sb[fname] + ' : ') if fn == '': pass else: sb[fname] = fn ln = raw_input('New name for ' + sb[lname] + ' : ') if ln == '': pass else: sb[lname] = ln write_book(tbook) details(choice, tbook) listpb() > ** > > ** ** > > Ramit**** > > ** ** > > ** ** > > Ramit Prasad | JPMorgan Chase Investment Bank | Currencies Technology**** > > 712 Main Street | Houston, TX 77002**** > > work phone: 713 - 216 - 5423**** > > ** ** > > --**** > > This email is confidential and subject to important disclaimers and > conditions including on offers for the purchase or sale of securities, > accuracy and completeness of information, viruses, confidentiality, legal > privilege, and legal entity disclaimers, available at > http://www.jpmorgan.com/pages/disclosures/email. > > -- > http://mail.python.org/mailman/listinfo/python-list > > -------------- next part -------------- An HTML attachment was scrubbed... URL: From nathan.alexander.rice at gmail.com Fri Mar 30 19:01:44 2012 From: nathan.alexander.rice at gmail.com (Nathan Rice) Date: Fri, 30 Mar 2012 19:01:44 -0400 Subject: Python is readable In-Reply-To: References: <4f612b19$0$1379$4fafbaef@reader2.news.tin.it> <4f750f9f$0$29981$c3e8da3$5496439d@news.astraweb.com> <4f752a3a$0$29981$c3e8da3$5496439d@news.astraweb.com> <4f758f43$0$29981$c3e8da3$5496439d@news.astraweb.com> Message-ID: On Fri, Mar 30, 2012 at 5:45 PM, Chris Angelico wrote: > On Sat, Mar 31, 2012 at 7:58 AM, Nathan Rice > wrote: >> Programming >> language designers purposefully try to make their language C-like, >> because not being C-like disqualifies a language from consideration >> for a HUGE portion of programmers, who cower at the naked feeling they >> get imagining a world without curly braces. Fear of change and the >> unknown are brutal, and humans are cowardly creatures that will grasp >> at whatever excuses they can find not to acknowledge their weaknesses. > > Braces are clear delimiters. English doesn't have them, and suffers > for it. (Python's indentation is, too, but English doesn't have that > either.) It's a lot harder to mark the end of an "if" block in English > than in pretty much any programming language. It seems to me that Indented blocks of text are used pretty frequently to denote definition bodies, section subordinate paragraphs and asides. The use of the colon seems pretty natural too. Parentheses are fairly natural for small asides. The notion of character delimiters for large sections of text is actually pretty unnatural with the exception of quotes. > And be careful of what has to be given up to gain your conveniences. > I've used languages that demand variable declarations and ones that > don't, and I'm very much a fan of the former. There are many benefits > to being explicit about that. I don't like declarations, my personal preference is to have typed signatures, and implicit declaration with type inference elsewhere. I view it as a matter of personal preference though, the result should be the same, and it should be possible to view the code either way. From breamoreboy at yahoo.co.uk Fri Mar 30 20:47:48 2012 From: breamoreboy at yahoo.co.uk (Mark Lawrence) Date: Sat, 31 Mar 2012 01:47:48 +0100 Subject: Threads on google groups not on gmane? Message-ID: I went onto google groups to do a search and saw three threads (there may be more) that I've never seen on gmane, which I read via thunderbird on windows. The titles are "Is programming art or science", "breezypythongui: A New Toolkit for Easy GUIs in Python" and "weird behaviour: pygame plays in shell but not in script". Is anyone else seeing the same thing? -- Cheers. Mark Lawrence. From breamoreboy at yahoo.co.uk Fri Mar 30 20:56:31 2012 From: breamoreboy at yahoo.co.uk (Mark Lawrence) Date: Sat, 31 Mar 2012 01:56:31 +0100 Subject: CFG for python In-Reply-To: References: Message-ID: On 29/03/2012 06:44, J. Mwebaze wrote: > Anyone knows how to create control-flow-graph for python.. After searching > around, i found this article, > http://www.python.org/dev/peps/pep-0339/#ast-to-cfg-to-bytecode and also a > reference to http://doc.pypy.org/en/latest/objspace.html#the-flow-model > > However, i stil cant figure out what how to create the CFG from the > two references. > Regards > Taking a look at this may help you get going http://alexleone.blogspot.co.uk/2010/01/python-ast-pretty-printer.html -- Cheers. Mark Lawrence. From jcd at sdf.lonestar.org Fri Mar 30 21:51:42 2012 From: jcd at sdf.lonestar.org (J. Cliff Dyer) Date: Fri, 30 Mar 2012 21:51:42 -0400 Subject: help needed to understand an error message. In-Reply-To: References: Message-ID: <1333158702.3513.3.camel@webb> So the problem is that python doesn't know what you're trying to do. It doesn't know that you meant to say "print." When the parser is looking at the word Print, it assumes you are referencing an object named Print, which is completely legal. It's only once you've created the next token, a string literal, that the parser discovers the error: you can't have a string literal following a variable. *You* think your error is that you misspelled "print." The parser thinks your error is trying to put a string literal next to a variable. Cheers, Cliff On Mon, 2012-03-26 at 18:22 +0530, Aloke Ghosh wrote: > Hi, > I am learning Python and do not have programming experience. > I was following > an exercise from http://learnpythonthehardway.org/book/ex2.html > and made a mistake in entry : > > > Print"I like typing this." > > > and got the following error message: > > > In [2]: Print"I like typing this." > ------------------------------------------------------------ > File "", line 1 > Print"I like typing this." > ^ > SyntaxError: invalid syntax > > > I feel the error is in Capital P in print . > However the error indicated with "^" > hints at quote at the end of the line. > > > Can any one please help me understand this. > > > -- > A.K.Ghosh From tjreedy at udel.edu Sat Mar 31 00:03:41 2012 From: tjreedy at udel.edu (Terry Reedy) Date: Sat, 31 Mar 2012 00:03:41 -0400 Subject: Python is readable In-Reply-To: <4f758f43$0$29981$c3e8da3$5496439d@news.astraweb.com> References: <4f612b19$0$1379$4fafbaef@reader2.news.tin.it> <4f750f9f$0$29981$c3e8da3$5496439d@news.astraweb.com> <4f752a3a$0$29981$c3e8da3$5496439d@news.astraweb.com> <4f758f43$0$29981$c3e8da3$5496439d@news.astraweb.com> Message-ID: On 3/30/2012 6:47 AM, Steven D'Aprano wrote: > Spolsky has written at least three times about Architecture Astronauts, > and made it abundantly clear that the problem with them is that they > don't solve problems, they invent overarching abstractions that don't do > anything useful or important, and hype them everywhere. > > http://www.joelonsoftware.com/articles/fog0000000018.html > http://www.joelonsoftware.com/items/2005/10/21.html > http://www.joelonsoftware.com/items/2008/05/01.html > > Jeff Attwood provides a simple test for the difference between a useful > abstraction and an Architecture Astronaut hyper-abstraction: > > Does it solve a useful problem? > > http://www.codinghorror.com/blog/2004/12/it-came-from-planet-architecture.html My strong impression is that theoretical abstract mathematicians also prefer that hi-level abstractions solve some useful-to-mathematicians mathematical problem. -- Terry Jan Reedy From showell30 at yahoo.com Sat Mar 31 01:07:52 2012 From: showell30 at yahoo.com (Steve Howell) Date: Fri, 30 Mar 2012 22:07:52 -0700 (PDT) Subject: Python is readable References: <4f612b19$0$1379$4fafbaef@reader2.news.tin.it> <4f750f9f$0$29981$c3e8da3$5496439d@news.astraweb.com> <4f752a3a$0$29981$c3e8da3$5496439d@news.astraweb.com> <4f758f43$0$29981$c3e8da3$5496439d@news.astraweb.com> Message-ID: On Mar 30, 1:20?pm, Chris Angelico wrote: > > Really? ?Or could it be that algorithms for natural language > > processing that don't fail miserably is a very recent development, > > restricted natural languages more recent still, and pretty much all > > commonly used programming languages are all ~20+ years old? ?Could it > > also be that most programmers don't see a lot of incentives to make > > things accessible, since they're already invested in the status quo, > > and they might lose some personal value if programming stopped being > > an arcane practice? > > Totally. That's why we're all still programming in assembly language > and doing our own memory management, because we would lose a lot of > personal value if programming stopped being so difficult. If it > weren't for all these silly new-fangled languages with their automatic > garbage collection and higher order function handling, we would all be > commanding much higher salaries. > While I don't subscribe to the conspiracy theory that "programmers invest in arcane practices to preserve personal value" [paraphrase of Nathan], surely you could come up with a better argument than "garbage collection." Garbage collection was invented over 50 years ago (1959, according to Wikipedia), and it was implemented in a whole bunch of popular programming languages in the 90s (and earlier too, if you count Smalltalk as a popular language). Python's over 20 years old, and it had garbage collection pretty early on. Java's not quite 20 years old, but if Java is your best example of a "new-fangled" language with automatic garbage collection, then I have a hard time appreciating your sarcastic comments. There hasn't been much progress in programming language design in the last 20 years. It's been incremental at best. Nobody's really thinking outside the box, as far as I can tell. Please prove me wrong. It's true that we've moved past assembly language. From lie.1296 at gmail.com Sat Mar 31 01:18:47 2012 From: lie.1296 at gmail.com (Lie Ryan) Date: Sat, 31 Mar 2012 16:18:47 +1100 Subject: Tools for refactoring/obfuscation In-Reply-To: References: Message-ID: On 03/29/2012 03:04 AM, Javier wrote: > Yes, in general I follow clear guidelines for writing code. I just use > modules with functions in the same directory and clear use of name > spaces. I almost never use classes. I wonder if you use some tool for > refactoring. I am mainly intersted in scripting tools, no eclipse-style > guis. > > Just let me know if you use some scripting tool. > > And, as somebody pointed in this thread obfuscating or refactoring the > code are very different things but they can be done with the same tools. if you're not using classes, your code is obfuscated already Anyway, I think it's better if you describe why you want such a tool. If you want to keep your code a secret, just distribute the .pyc file. If you want to refactor your code to improve readability, there is rope. From jphalip at gmail.com Sat Mar 31 01:39:09 2012 From: jphalip at gmail.com (Julien) Date: Fri, 30 Mar 2012 22:39:09 -0700 (PDT) Subject: Problem connecting to SMTP/IMAP server using SSL Message-ID: <722270ac-367f-4058-84ed-92ba10f4516a@ur9g2000pbc.googlegroups.com> Hi, I'm able to connect to an Exchange server via SMTP and IMAP from my iPhone using SSL and without using a VPN. So I would expect to be able to do the same from my computer using Python. However, the following hangs and times out on my computer when I'm not connected to the VPN: >>> import imaplib >>> imap = imaplib.IMAP4_SSL("my.server.address") If I am connected to the VPN, then it works fine. Do you know why it won't work with SSL and without the VPN? Am I missing something? Thanks a lot, Julien From lie.1296 at gmail.com Sat Mar 31 01:56:57 2012 From: lie.1296 at gmail.com (Lie Ryan) Date: Sat, 31 Mar 2012 16:56:57 +1100 Subject: Python is readable In-Reply-To: <4f653c1e$0$29981$c3e8da3$5496439d@news.astraweb.com> References: <4f612b19$0$1379$4fafbaef@reader2.news.tin.it> <8e72d74f-c844-4de3-8a37-f6b1fdc2291f@y27g2000yqy.googlegroups.com> <50e9ceec-40f1-4ead-b2b6-87328b30d084@ow8g2000pbc.googlegroups.com> <4f61c828$0$1390$4fafbaef@reader2.news.tin.it> <4f61d728$0$1375$4fafbaef@reader2.news.tin.it> <4f61fd0a$0$1389$4fafbaef@reader2.news.tin.it> <4f620837$0$1382$4fafbaef@reader2.news.tin.it> <4f627c25$0$1381$4fafbaef@reader2.news.tin.it> <4f62b9be$0$29981$c3e8da3$5496439d@news.astraweb.com> <4f632da5$0$1375$4fafbaef@reader1.news.tin.it> <4f636ed5$0$29981$c3e8da3$5496439d@news.astraweb.com> <4f64ed2e$0$1389$4fafbaef@reader1.news.tin.it> <4f653c1e$0$29981$c3e8da3$5496439d@news.astraweb.com> Message-ID: On 03/18/2012 12:36 PM, Steven D'Aprano wrote: > On Sat, 17 Mar 2012 20:59:34 +0100, Kiuhnm wrote: > In the second example, most English speakers would intuit that "print(i)" > prints i, whatever i is. There are two points where the code may be misunderstood, a beginner may think that "print i" prints to the inkjet printer (I remembered unplugging my printer when I wrote my first BASIC program for this reason); and the possible confusion of whether "print i" prints the letter "i" or the content of variable "i". (Fortunately, this confusion are easily resolved when I run the code and see the result on-screen instead of a job on the print spooler) (ironically, although print is nowadays a programming jargon for outputting to screen, but in the old dark ages, people used to use the "print" statement to print to paper in their old terminal) From lie.1296 at gmail.com Sat Mar 31 02:15:55 2012 From: lie.1296 at gmail.com (Lie Ryan) Date: Sat, 31 Mar 2012 17:15:55 +1100 Subject: Python is readable In-Reply-To: References: <4f612b19$0$1379$4fafbaef@reader2.news.tin.it> <8e72d74f-c844-4de3-8a37-f6b1fdc2291f@y27g2000yqy.googlegroups.com> <50e9ceec-40f1-4ead-b2b6-87328b30d084@ow8g2000pbc.googlegroups.com> Message-ID: On 03/21/2012 03:55 AM, Nathan Rice wrote: > In mathematics, when you perform global optimization you must be > willing to make moves in the solution space that may result in a > temporary reduction of your optimality condition. If you just perform > naive gradient decent, only looking to the change that will induce the > greatest immediate improvement in optimality, you will usually end up > orbiting around a solution which is not globally optimal. I mention > this because any readability or usability information gained using > trained programmers is simultaneously measuring the readability or > usability and its conformance to the programmer's cognitive model of > programming. The result is local optimization around the > current-paradigm minimum. This is why we have so many nearly > identical curly brace C-like languages. I think you've just described that greedy algorithm can't always find the globally optimal solution. From lanyjie at yahoo.com Sat Mar 31 02:22:26 2012 From: lanyjie at yahoo.com (Yingjie Lan) Date: Fri, 30 Mar 2012 23:22:26 -0700 (PDT) Subject: string interpolation for python In-Reply-To: References: Message-ID: <1333174946.18436.YahooMailNeo@web121506.mail.ne1.yahoo.com> Hi all,? I'd really like to share this idea of string interpolation for formatting. Let's start with some code: >>> name = "Shrek" >>> print( "Hi, $name$!") Hi, Shrek! >>> balls = 30 >>> print( "We have $balls$ balls.") We have 30 balls >>> persons = 5 >>> print ("And $persons$ persons.") And 5 persons. >>> print(" Each may get exactly $balls//persons$ balls.") Each may get exactly 6 balls. >>> fraction = 0.12345 >>> print( "The fraction is $fraction : 0.2f$!") The fraction is 0.12! >>> print("It costs about $$3, I think.") It costs about $3, I think. I think the rule is quite self explanatory. An expression is always enclosed between two '$'s, with an optional ':' followed by additional formatting specification. Double '$$' is like double '%%'. Of course, '$' can be replaced by anything else. For compatibility reasons, we might just use '%' as well. ============ Implementation: the compiler might need to do something, say, to replace a string interpolation with an equivalent? expression. Cheers, Yingjie -------------- next part -------------- An HTML attachment was scrubbed... URL: From lie.1296 at gmail.com Sat Mar 31 02:25:58 2012 From: lie.1296 at gmail.com (Lie Ryan) Date: Sat, 31 Mar 2012 17:25:58 +1100 Subject: Python is readable In-Reply-To: <8a77bf8d-b12f-442b-a1a3-479b5d66d366@tx8g2000pbc.googlegroups.com> References: <4f612b19$0$1379$4fafbaef@reader2.news.tin.it> <8e72d74f-c844-4de3-8a37-f6b1fdc2291f@y27g2000yqy.googlegroups.com> <50e9ceec-40f1-4ead-b2b6-87328b30d084@ow8g2000pbc.googlegroups.com> <4f691f3d$0$29981$c3e8da3$5496439d@news.astraweb.com> <87d386lmai.fsf@benfinney.id.au> <8a77bf8d-b12f-442b-a1a3-479b5d66d366@tx8g2000pbc.googlegroups.com> Message-ID: On 03/21/2012 01:44 PM, Steve Howell wrote: > Also, don't they call those thingies "object" for a reason? ;) A subject is (almost?) always a noun, and so a subject is also an object. From anthra.norell at bluewin.ch Sat Mar 31 03:42:59 2012 From: anthra.norell at bluewin.ch (Frederic Rentsch) Date: Sat, 31 Mar 2012 09:42:59 +0200 Subject: Tkinter: IDLE can't get out of mainloop Message-ID: <1333179779.2280.50.camel@hatchbox-one> Hi all, Is is a bad idea to develop Tkinter applications in IDLE? I understand that IDLE is itself a Tkinter application, supposedly in a mainloop and mainloops apparently don't nest. I tried to install a root-destroy-protocol: def destroy_root (): print 'Destroying root' root.destroy () root.protocol ("WM_DELETE_WINDOW", destroy_root) I see the tracing message 'Destroying root', but stay stuck unable to get the IDLE prompt back. Ctr-C doesn't work. The only way out I know is killing IDLE. When I do, a warning says that a program is still running. That must be IDLE's own WM_DELETE_WINDOW protocol. Is there a way to get the prompt back without killing IDLE? Is there a way to nest a mainloop? Up to now I have been able to get by without a mainloop. I suppose this is because I have only been doing layouts. Starting now to do events I observe what in the absence of a mainloop looks like synchronization problems with bindings responding to other events than their own. If I run from a terminal things seem to work out. Is it standard development practice to run code from a terminals ($ python program.py)? What's the 'program.pyc' for if the source is compiled every time? I use Python 2.6 on Ubuntu 10.04 LTS. Thankful for any suggestion Frederic From clp2 at rebertia.com Sat Mar 31 03:51:50 2012 From: clp2 at rebertia.com (Chris Rebert) Date: Sat, 31 Mar 2012 00:51:50 -0700 Subject: string interpolation for python In-Reply-To: <1333174946.18436.YahooMailNeo@web121506.mail.ne1.yahoo.com> References: <1333174946.18436.YahooMailNeo@web121506.mail.ne1.yahoo.com> Message-ID: On Fri, Mar 30, 2012 at 11:22 PM, Yingjie Lan wrote: > Hi all, > > I'd really like to share this idea of string interpolation for formatting. > Let's start with some code: > >>>> name = "Shrek" >>>> print( "Hi, $name$!") > Hi, Shrek! Python already has *3* different built-in string formatting/interpolation systems: http://docs.python.org/library/string.html#template-strings http://docs.python.org/library/string.html#format-string-syntax http://docs.python.org/library/stdtypes.html#string-formatting-operations Do we really want to add yet another to this pile? I would surmise that your key "implicitly grab variable values from the enclosing scope" feature has previously been rejected for being too magical. Cheers, Chris -- http://rebertia.com From clp2 at rebertia.com Sat Mar 31 03:59:48 2012 From: clp2 at rebertia.com (Chris Rebert) Date: Sat, 31 Mar 2012 00:59:48 -0700 Subject: Tkinter: IDLE can't get out of mainloop In-Reply-To: <1333179779.2280.50.camel@hatchbox-one> References: <1333179779.2280.50.camel@hatchbox-one> Message-ID: On Sat, Mar 31, 2012 at 12:42 AM, Frederic Rentsch wrote: > ? If I run from a terminal things seem to work out. Is it standard > development practice to run code from a terminals ($ python program.py)? > What's the 'program.pyc' for if the source is compiled every time? The entire point of .pyc files is to avoid unnecessary re-byte-compilation from source code when possible: http://docs.python.org/tutorial/modules.html#compiled-python-files (i.e. there are times where the source is *not* recompiled.) Cheers, Chris From rosuav at gmail.com Sat Mar 31 04:05:41 2012 From: rosuav at gmail.com (Chris Angelico) Date: Sat, 31 Mar 2012 19:05:41 +1100 Subject: Python is readable In-Reply-To: References: <4f612b19$0$1379$4fafbaef@reader2.news.tin.it> <4f750f9f$0$29981$c3e8da3$5496439d@news.astraweb.com> <4f752a3a$0$29981$c3e8da3$5496439d@news.astraweb.com> <4f758f43$0$29981$c3e8da3$5496439d@news.astraweb.com> Message-ID: On Sat, Mar 31, 2012 at 10:01 AM, Nathan Rice wrote: > It seems to me that Indented blocks of text are used pretty frequently > to denote definition bodies, section subordinate paragraphs and > asides. ?The use of the colon seems pretty natural too. ?Parentheses > are fairly natural for small asides. ?The notion of character > delimiters for large sections of text is actually pretty unnatural > with the exception of ?quotes. Perhaps in formal written English, but not in spoken, and often not in casual writing either. Play around with my actual example, an "if" clause, and see where the punctuation goes in English - and how easily you can construct ambiguous sentences. > I don't like declarations, my personal preference is to have typed > signatures, and implicit declaration with type inference elsewhere. ?I > view it as a matter of personal preference though, the result should > be the same, and it should be possible to view the code either way. I'm not sure what you mean by "typed signatures", can you elaborate please? ChrisA From cyborgv2 at hotmail.com Sat Mar 31 05:17:16 2012 From: cyborgv2 at hotmail.com (Adrian Hunt) Date: Sat, 31 Mar 2012 10:17:16 +0100 Subject: string interpolation for python In-Reply-To: <1333174946.18436.YahooMailNeo@web121506.mail.ne1.yahoo.com> References: , , <1333174946.18436.YahooMailNeo@web121506.mail.ne1.yahoo.com> Message-ID: Hi Yingjie, Consider this snippet of "safe" code: | enc = bobsencryption.Encoder('Some secret key') | | username = raw_input('Enter your username:') | password = raw_input('Enter your password:') | | print | print username + ', please wait while we dial-up and log you in...' | | connection = server.dialup(00441635074745) | connection.send('login ' + enc([username, password])) Code like this could already be out there and safe-ish (well, if they've included a little validation and error-checking.) Now consider that your $formatting$ is added and the "company" upgrades Python, resulting in the following: | Enter your username: $enc.key$ | Enter your password: dontneedone | | Some secret key, please wait while we dial-up and log you in... It could break old code... okay you may say you should?nt allow certain characters but if they're printable and used in a controlled environment those characters can dramatically increase the security of a username and password. Adrian From tjreedy at udel.edu Sat Mar 31 06:29:11 2012 From: tjreedy at udel.edu (Terry Reedy) Date: Sat, 31 Mar 2012 06:29:11 -0400 Subject: string interpolation for python In-Reply-To: <1333174946.18436.YahooMailNeo@web121506.mail.ne1.yahoo.com> References: <1333174946.18436.YahooMailNeo@web121506.mail.ne1.yahoo.com> Message-ID: On 3/31/2012 2:22 AM, Yingjie Lan wrote: > Hi all, > > I'd really like to share this idea of string interpolation for formatting. > Let's start with some code: > > >>> name = "Shrek" > >>> print( "Hi, $name$!") > Hi, Shrek! > >>> balls = 30 > >>> print( "We have $balls$ balls.") > We have 30 balls You can already do essentially that without adding a special-case string formatting method to the general methods we already have. >>> balls = 5 >>> people = 3 >>> 'The {people} people have {balls} balls.'.format(**locals()) 'The 3 people have 5 balls.' -- Terry Jan Reedy From tjreedy at udel.edu Sat Mar 31 06:29:27 2012 From: tjreedy at udel.edu (Terry Reedy) Date: Sat, 31 Mar 2012 06:29:27 -0400 Subject: Tkinter: IDLE can't get out of mainloop In-Reply-To: <1333179779.2280.50.camel@hatchbox-one> References: <1333179779.2280.50.camel@hatchbox-one> Message-ID: On 3/31/2012 3:42 AM, Frederic Rentsch wrote: > Hi all, > > Is is a bad idea to develop Tkinter applications in IDLE? I understand > that IDLE is itself a Tkinter application, supposedly in a mainloop and > mainloops apparently don't nest. In standard configuration, one process runs IDLE, another runs user code, including tkinter code. So there should be no interference. The example in the tkinter doc runs from IDLE edit window on my system. The revised example in coming releases works even better. There have been several IDLE bugs fixed in the last few months, and even more since 2.6 before that. Upgrade if you can to get fixes, suffer the bugs since fixed, or patch your 2.6 installation. -- Terry Jan Reedy From tolidtm at gmail.com Sat Mar 31 07:39:32 2012 From: tolidtm at gmail.com (Anatoli Hristov) Date: Sat, 31 Mar 2012 13:39:32 +0200 Subject: Advise of programming one of my first programs In-Reply-To: References: <5B80DD153D7D744689F57F4FB69AF4740928C365@SCACMX008.exchad.jpmchase.net> <5B80DD153D7D744689F57F4FB69AF4740928E137@SCACMX008.exchad.jpmchase.net> <5B80DD153D7D744689F57F4FB69AF4740928F779@SCACMX008.exchad.jpmchase.net> <5B80DD153D7D744689F57F4FB69AF47409293188@SCACMX008.exchad.jpmchase.net> Message-ID: Ramit, This seems to be more logic now "I hope" :) ######################################### import ast fname = 0 lname = 1 country = 2 city = 3 tel = 4 notes = 5 ## Read data from file def load_book(): load_book = open('c:/Python27/Toli/myfile.txt', 'r') load_book = ast.literal_eval(load_book.read()) return load_book ## Write data to file def write_book(tbook): write_book = open('c:/Python27/Toli/myfile.txt', 'w') write_book.write(repr(tbook)) ## Menu choice input def get_menu_choice(text): choice = raw_input(text) return choice ## List data contacts def listpb(): ##tbook = load_book() print '_' *45, ' Phonebook ', '_' *45,'\n\n\n' print 'Nick\t\tF.Name\t\tL.Name\t\tCountry\t\t\tCity\t\tTel' print '_' * 105,'\n','\t' * 13 for val in tbook.keys(): print val, '\t\t', tbook[val][fname], '\t', tbook[val][lname], '\t', tbook[val][country], '\t\t', tbook[val][city], '\t\t', tbook[val][tel],'\t\t\n' print '_'*105,'\n\n\n\n' print 'Type nickname and press or type to exit.\n\n\n' ## Main menu def mmenu(tbook): listpb() while True: text = 'Type your option: ' choice = get_menu_choice(text) if choice == 'e' or choice == 'E': text = 'Type nickname and press to edit: ' choicen = get_menu_choice(text) if choicen in tbook: edit(choicen, tbook) elif choice == 'b' or choice == 'B': listpb() elif choice == 'd' or choice == 'D': text = 'Type nickname and press for details: ' choicen = get_menu_choice(text) if choicen in tbook: details(choicen, tbook) elif choice == 'q' or choice == 'Q': break else: print 'Selection {0} not understood.'.format(choice) ## Contact details def details(choicen, tbook): sb = tbook[choicen] print 'Nickname: ', choicen, ' is selected\n' print 'First name:\t', sb[fname], '\n' print 'Last name:\t', sb[lname], '\n' print 'Country:\t', sb[country], '\n' print 'City:\t\t', sb[city], '\n' print 'Phone number:\t',sb[tel], '\n' print 'Memos:\n' print sb[notes] print '\n\n(E)dit\n\n' print '(B)ack to phonebook list\n\n' ## Edit contact def edit(choicen, tbook): sb = tbook[choicen] fn = raw_input('New name for ' + sb[fname] + ' : ') if fn == '': pass else: sb[fname] = fn ln = raw_input('New name for ' + sb[lname] + ' : ') if ln == '': pass else: sb[lname] = ln write_book(tbook) details(choicen, tbook) tbook = load_book() mmenu(tbook) ####################################### What you thing? Regards Anatoli -------------- next part -------------- An HTML attachment was scrubbed... URL: From hannu at krosing.net Sat Mar 31 10:33:40 2012 From: hannu at krosing.net (Hannu Krosing) Date: Sat, 31 Mar 2012 16:33:40 +0200 Subject: has anybody used ctypes to call back into c program which embeds a python interpreter Message-ID: <1333204420.28732.45.camel@hvost> Hi, I want to use ctypes to use some functions from postgreSQL server which embeds python interpreter as language pl/python. That is I want to use ctypes to call _back_ to some internal functions in the server What I tried is the following: hannu=# create or replace function send_raw_notice(rn_text text) returns text language plpythonu as $$ from ctypes import * import struct pg = cdll.LoadLibrary('/usr/lib/postgresql/9.1/bin/postmaster') pg.pq_flush() return rn_text $$; CREATE FUNCTION hannu=# select send_raw_notice('so you see me?'); The connection to the server was lost. Attempting reset: Failed. !> This caused a segfault: 2012-03-31 16:28:24 CEST LOG: server process (PID 8739) was terminated by signal 11: Segmentation fault 2012-03-31 16:28:24 CEST LOG: terminating any other active server processes I suspect it is due to not calling into the host program (the running server) but into a newly loaded and uninitialized copy of postmaster loaded as library Does anyone have ideas how to call into the embedding c program from ctypes ? -------------- Hannu From nathan.alexander.rice at gmail.com Sat Mar 31 10:43:10 2012 From: nathan.alexander.rice at gmail.com (Nathan Rice) Date: Sat, 31 Mar 2012 10:43:10 -0400 Subject: Python is readable In-Reply-To: References: <4f612b19$0$1379$4fafbaef@reader2.news.tin.it> <4f750f9f$0$29981$c3e8da3$5496439d@news.astraweb.com> <4f752a3a$0$29981$c3e8da3$5496439d@news.astraweb.com> <4f758f43$0$29981$c3e8da3$5496439d@news.astraweb.com> Message-ID: On Sat, Mar 31, 2012 at 2:15 AM, Lie Ryan wrote: > On 03/21/2012 03:55 AM, Nathan Rice wrote: >> >> > > I think you've just described that greedy algorithm can't always find the > globally optimal solution. Right. Using gradient descent on an algebraic surface is probably the most natural example of why this is the case, since balls rolling down a surface from a starting point to the bottom of a bowl is an exact analogy. On Sat, Mar 31, 2012 at 4:05 AM, Chris Angelico wrote: > On Sat, Mar 31, 2012 at 10:01 AM, Nathan Rice > wrote: >> It seems to me that Indented blocks of text are used pretty frequently >> to denote definition bodies, section subordinate paragraphs and >> asides. ?The use of the colon seems pretty natural too. ?Parentheses >> are fairly natural for small asides. ?The notion of character >> delimiters for large sections of text is actually pretty unnatural >> with the exception of ?quotes. > > Perhaps in formal written English, but not in spoken, and often not in > casual writing either. Play around with my actual example, an "if" > clause, and see where the punctuation goes in English - and how easily > you can construct ambiguous sentences. Sure an event has occurred recently if it occurred in the last time step. if xyz has occurred recently, that implies abc will occur in the next time step. when event abc occurs, all unbound floops become bound, and at most three newly bound floops are eaten by blargs. blargs that have not eaten in the last 3 time steps eat before blargs that have eaten in those time steps. Notice I don't talk about HOW anything is done, just the logic of what is happening. The computer should be capable of making an inventory of exactly what it will need to do given the statements I have made, and choose the best data structures and algorithms for the job. If we are in undecidable/halting problem territory (indefinite recursion) then the computer should at least be nice enough to tell you it is confused and would like some help. >> I don't like declarations, my personal preference is to have typed >> signatures, and implicit declaration with type inference elsewhere. ?I >> view it as a matter of personal preference though, the result should >> be the same, and it should be possible to view the code either way. > > I'm not sure what you mean by "typed signatures", can you elaborate please? Just like the standard way in the Haskell community. To demonstrate using Python annotations... def myfunc(Sequence : a, Integral : b, Map : c) -> Sequence: ... Given starting types and ending types, you can correctly infer some VERY complex internal types. Haskell will let you omit signature types as well, but that is really a bad idea because they add readability and you will have to add them often anyhow if you are dealing with complex types. Better to be consistent... As a funny aside, people usually provide input type and return type annotations to python functions, as part of the docstring (for sphinx). To be honest, I like having types baked into my code, though not nominal types (the sort that is an A because it was declared as an A or a subclass of A), but rather structural types (i.e. Abstract base classes, or Java interfaces, if you didn't have to add the implements ...). I don't like having to verbosely tell the computer about the types of everything I'm going to use, I only care that it gives me the output I want if I give it some agreed upon input. It should be smart enough to check the little things. From claird271 at gmail.com Sat Mar 31 11:38:40 2012 From: claird271 at gmail.com (Cameron Laird) Date: Sat, 31 Mar 2012 08:38:40 -0700 (PDT) Subject: Python-URL! - weekly Python news and links (Mar 31) Message-ID: I pine for the fjords. And it's time to bring "Python-URL!" to a close. "Python-URL!", which Jean-Claude Wippler and I appear to have launched in 1998, has reached the end of its utility. We still have many loyal and enthusiastic readers--one subscription request arrived within the last day, in fact--and certainly much writing turns up every week that *deserves* the spotlight "Python-URL!" has shone in the past. However, the Python world has changed a great deal over the last fourteen years. There are many, MANY other ways for those with an interest in Python to nourish themselves, and Python itself has grown and "normalized" so much that it no longer fits particularly well in the "Python-URL!" format. Enjoy "Mouse vs. Python" , the Python areas of DZone, Reddit, developerWorks, stackoverflow, and so on. For your reference, I append below the most-recent-but-not- particularly- current version of "Python-URL!"'s coda of related readings. That is all. ======================================================================== Everything Python-related you want is probably one or two clicks away in these pages: Python.org's Python Language Website is the traditional center of Pythonia http://www.python.org Notice especially the master FAQ http://www.python.org/doc/FAQ.html Just beginning with Python? This page is a great place to start: http://wiki.python.org/moin/BeginnersGuide/Programmers Planet Python: you want to visit there: http://planet.python.org But don't confuse it with Planet SciPy: http://planet.scipy.org And don't confuse *that* with SciPyTip, a high-quality daily (!) tip for the numerically-inclined: http://twitter.com/SciPyTip Python Insider is the official blog of the Python core development team: http://pyfound.blogspot.com/2011/03/python-dev-launches-python-insider -blog.html The Python Software Foundation (PSF) has replaced the Python Consortium as an independent nexus of activity. It has official responsibility for Python's development and maintenance. http://www.python.org/psf/ Among the ways you can support PSF is with a donation. http://www.python.org/psf/donations/ Keep up with the PSF at "Python Software Foundation News": http://pyfound.blogspot.com The Python Papers aims to publish "the efforts of Python enthusiasts": http://pythonpapers.org/ Doug Hellman's "Module of the week" is essential reading: http://www.doughellmann.com/PyMOTW/ comp.lang.python.announce announces new Python software. Be sure to scan this newsgroup weekly. http://groups.google.com/group/comp.lang.python.announce/topics Python411 indexes "podcasts ... to help people learn Python ..." Updates appear more-than-weekly: http://www.awaretek.com/python/index.html The Python Package Index catalogues packages. http://www.python.org/pypi/ Much of Python's real work takes place on Special-Interest Group mailing lists http://www.python.org/sigs/ Python Success Stories--from air-traffic control to on-line match-making--can inspire you or decision-makers to whom you're subject with a vision of what the language makes practical. http://www.pythonology.com/success The Summary of Python Tracker Issues is an automatically generated report summarizing new bugs, closed ones, and patch submissions. http://search.gmane.org/?author=status%40bugs.python.org&group=gmane.c omp.python.devel&sort=date nullege is an interesting search Web application, with the intelligence to distinguish between Python code and comments. It provides what appear to be relevant results, and demands neither Java nor CSS be enabled: http://www.nullege.com Although unmaintained since 2002, the Cetus collection of Python hyperlinks retains a few gems. http://www.cetus-links.org/oo_python.html The Cookbook is a collaborative effort to capture useful and interesting recipes: http://code.activestate.com/recipes/langs/python/ Many Python conferences around the world are in preparation. Watch this space for links to them. Among several Python-oriented RSS/RDF feeds available, see: http://www.python.org/channews.rdf For more, see: http://www.syndic8.com/feedlist.php?ShowMatch=python&ShowStatus=all The old Python "To-Do List" now lives principally in a SourceForge reincarnation. http://sourceforge.net/tracker/?atid=355470&group_id=5470&func=browse http://www.python.org/dev/peps/pep-0042/ del.icio.us presents an intriguing approach to reference commentary. It already aggregates quite a bit of Python intelligence. http://del.icio.us/tag/python At least one of the Python magazines is explicitly multilingual: http://www.python.org/ar/ PythonWare complemented the digest you're reading with the marvelous daily python url. While it's now ... dormant, it still has plenty of interesting reading. http://www.pythonware.com/daily Python articles regularly appear at IBM DeveloperWorks: http://www.ibm.com/developerworks/search/searchResults.jsp?searchSite= dW&searchScope=dW&encodedQuery=python&rankprofile=8 Previous - (U)se the (R)esource, (L)uke! - messages are listed here: http://search.gmane.org/?query=python+URL+weekly+news+links&group=gmane.comp .python.general&sort=date http://groups.google.com/groups/search?q=Python-URL!+group%3Acomp.lang.pytho n&start=0&scoring=d& http://lwn.net/Search/DoSearch?words=python-url&ctype3=yes&cat_25=yes There is *not* an RSS for "Python-URL!"--at least not yet. Arguments for and against are occasionally entertained. Suggestions/corrections for next week's posting are always welcome. E-mail to should get through. To receive a new issue of this posting in e-mail each Monday morning (approximately), ask to subscribe. Mention "Python-URL!". Write to the same address to unsubscribe. -- The Python-URL! Team-- Phaseit, Inc. (http://phaseit.net) is pleased to participate in and sponsor the "Python-URL!" project. Follow "Python-URL!" and other programming news on . Watch this space for upcoming news about posting archives. From claird271 at gmail.com Sat Mar 31 11:38:40 2012 From: claird271 at gmail.com (Cameron Laird) Date: Sat, 31 Mar 2012 08:38:40 -0700 (PDT) Subject: Python-URL! - weekly Python news and links (Mar 31) Message-ID: I pine for the fjords. And it's time to bring "Python-URL!" to a close. "Python-URL!", which Jean-Claude Wippler and I appear to have launched in 1998, has reached the end of its utility. We still have many loyal and enthusiastic readers--one subscription request arrived within the last day, in fact--and certainly much writing turns up every week that *deserves* the spotlight "Python-URL!" has shone in the past. However, the Python world has changed a great deal over the last fourteen years. There are many, MANY other ways for those with an interest in Python to nourish themselves, and Python itself has grown and "normalized" so much that it no longer fits particularly well in the "Python-URL!" format. Enjoy "Mouse vs. Python" , the Python areas of DZone, Reddit, developerWorks, stackoverflow, and so on. For your reference, I append below the most-recent-but-not- particularly- current version of "Python-URL!"'s coda of related readings. That is all. ======================================================================== Everything Python-related you want is probably one or two clicks away in these pages: Python.org's Python Language Website is the traditional center of Pythonia http://www.python.org Notice especially the master FAQ http://www.python.org/doc/FAQ.html Just beginning with Python? This page is a great place to start: http://wiki.python.org/moin/BeginnersGuide/Programmers Planet Python: you want to visit there: http://planet.python.org But don't confuse it with Planet SciPy: http://planet.scipy.org And don't confuse *that* with SciPyTip, a high-quality daily (!) tip for the numerically-inclined: http://twitter.com/SciPyTip Python Insider is the official blog of the Python core development team: http://pyfound.blogspot.com/2011/03/python-dev-launches-python-insider -blog.html The Python Software Foundation (PSF) has replaced the Python Consortium as an independent nexus of activity. It has official responsibility for Python's development and maintenance. http://www.python.org/psf/ Among the ways you can support PSF is with a donation. http://www.python.org/psf/donations/ Keep up with the PSF at "Python Software Foundation News": http://pyfound.blogspot.com The Python Papers aims to publish "the efforts of Python enthusiasts": http://pythonpapers.org/ Doug Hellman's "Module of the week" is essential reading: http://www.doughellmann.com/PyMOTW/ comp.lang.python.announce announces new Python software. Be sure to scan this newsgroup weekly. http://groups.google.com/group/comp.lang.python.announce/topics Python411 indexes "podcasts ... to help people learn Python ..." Updates appear more-than-weekly: http://www.awaretek.com/python/index.html The Python Package Index catalogues packages. http://www.python.org/pypi/ Much of Python's real work takes place on Special-Interest Group mailing lists http://www.python.org/sigs/ Python Success Stories--from air-traffic control to on-line match-making--can inspire you or decision-makers to whom you're subject with a vision of what the language makes practical. http://www.pythonology.com/success The Summary of Python Tracker Issues is an automatically generated report summarizing new bugs, closed ones, and patch submissions. http://search.gmane.org/?author=status%40bugs.python.org&group=gmane.c omp.python.devel&sort=date nullege is an interesting search Web application, with the intelligence to distinguish between Python code and comments. It provides what appear to be relevant results, and demands neither Java nor CSS be enabled: http://www.nullege.com Although unmaintained since 2002, the Cetus collection of Python hyperlinks retains a few gems. http://www.cetus-links.org/oo_python.html The Cookbook is a collaborative effort to capture useful and interesting recipes: http://code.activestate.com/recipes/langs/python/ Many Python conferences around the world are in preparation. Watch this space for links to them. Among several Python-oriented RSS/RDF feeds available, see: http://www.python.org/channews.rdf For more, see: http://www.syndic8.com/feedlist.php?ShowMatch=python&ShowStatus=all The old Python "To-Do List" now lives principally in a SourceForge reincarnation. http://sourceforge.net/tracker/?atid=355470&group_id=5470&func=browse http://www.python.org/dev/peps/pep-0042/ del.icio.us presents an intriguing approach to reference commentary. It already aggregates quite a bit of Python intelligence. http://del.icio.us/tag/python At least one of the Python magazines is explicitly multilingual: http://www.python.org/ar/ PythonWare complemented the digest you're reading with the marvelous daily python url. While it's now ... dormant, it still has plenty of interesting reading. http://www.pythonware.com/daily Python articles regularly appear at IBM DeveloperWorks: http://www.ibm.com/developerworks/search/searchResults.jsp?searchSite= dW&searchScope=dW&encodedQuery=python&rankprofile=8 Previous - (U)se the (R)esource, (L)uke! - messages are listed here: http://search.gmane.org/?query=python+URL+weekly+news+links&group=gmane.comp .python.general&sort=date http://groups.google.com/groups/search?q=Python-URL!+group%3Acomp.lang.pytho n&start=0&scoring=d& http://lwn.net/Search/DoSearch?words=python-url&ctype3=yes&cat_25=yes There is *not* an RSS for "Python-URL!"--at least not yet. Arguments for and against are occasionally entertained. Suggestions/corrections for next week's posting are always welcome. E-mail to should get through. To receive a new issue of this posting in e-mail each Monday morning (approximately), ask to subscribe. Mention "Python-URL!". Write to the same address to unsubscribe. -- The Python-URL! Team-- Phaseit, Inc. (http://phaseit.net) is pleased to participate in and sponsor the "Python-URL!" project. Follow "Python-URL!" and other programming news on . Watch this space for upcoming news about posting archives. From showell30 at yahoo.com Sat Mar 31 12:59:42 2012 From: showell30 at yahoo.com (Steve Howell) Date: Sat, 31 Mar 2012 09:59:42 -0700 (PDT) Subject: Python is readable References: <4f612b19$0$1379$4fafbaef@reader2.news.tin.it> <8e72d74f-c844-4de3-8a37-f6b1fdc2291f@y27g2000yqy.googlegroups.com> <50e9ceec-40f1-4ead-b2b6-87328b30d084@ow8g2000pbc.googlegroups.com> <4f691f3d$0$29981$c3e8da3$5496439d@news.astraweb.com> <87d386lmai.fsf@benfinney.id.au> <8a77bf8d-b12f-442b-a1a3-479b5d66d366@tx8g2000pbc.googlegroups.com> Message-ID: <2419e9d9-b4c9-44ad-a280-9d05a357602b@ms3g2000pbb.googlegroups.com> On Mar 30, 11:25?pm, Lie Ryan wrote: > On 03/21/2012 01:44 PM, Steve Howell wrote: > > > Also, don't they call those thingies "object" for a reason? ;) > > A subject is (almost?) always a noun, and so a subject is also an object. It's true that words that can act as a subject can also act like objects in other sentences. That doesn't really answer my question, though. Why do we call programming objects "objects" instead of calling them "subjects" or "nouns"? From python at mrabarnett.plus.com Sat Mar 31 13:27:11 2012 From: python at mrabarnett.plus.com (MRAB) Date: Sat, 31 Mar 2012 18:27:11 +0100 Subject: Python is readable In-Reply-To: References: <4f612b19$0$1379$4fafbaef@reader2.news.tin.it> <8e72d74f-c844-4de3-8a37-f6b1fdc2291f@y27g2000yqy.googlegroups.com> <50e9ceec-40f1-4ead-b2b6-87328b30d084@ow8g2000pbc.googlegroups.com> <4f61c828$0$1390$4fafbaef@reader2.news.tin.it> <4f61d728$0$1375$4fafbaef@reader2.news.tin.it> <4f61fd0a$0$1389$4fafbaef@reader2.news.tin.it> <4f620837$0$1382$4fafbaef@reader2.news.tin.it> <4f627c25$0$1381$4fafbaef@reader2.news.tin.it> <4f62b9be$0$29981$c3e8da3$5496439d@news.astraweb.com> <4f632da5$0$1375$4fafbaef@reader1.news.tin.it> <4f636ed5$0$29981$c3e8da3$5496439d@news.astraweb.com> <4f64ed2e$0$1389$4fafbaef@reader1.news.tin.it> <4f653c1e$0$29981$c3e8da3$5496439d@news.astraweb.com> Message-ID: <4F773E6F.9050603@mrabarnett.plus.com> On 31/03/2012 06:56, Lie Ryan wrote: > On 03/18/2012 12:36 PM, Steven D'Aprano wrote: >> On Sat, 17 Mar 2012 20:59:34 +0100, Kiuhnm wrote: >> In the second example, most English speakers would intuit that "print(i)" >> prints i, whatever i is. > > There are two points where the code may be misunderstood, a beginner may > think that "print i" prints to the inkjet printer (I remembered > unplugging my printer when I wrote my first BASIC program for this > reason); and the possible confusion of whether "print i" prints the > letter "i" or the content of variable "i". (Fortunately, this confusion > are easily resolved when I run the code and see the result on-screen > instead of a job on the print spooler) > > (ironically, although print is nowadays a programming jargon for > outputting to screen, but in the old dark ages, people used to use the > "print" statement to print to paper in their old terminal) > I remember a review of a machine back in the early 1980s or late 1970s. The machine used BASIC, but the reviewer was surprised when the printer sprang into life. "PRINT" meant "send to printer"; in order to 'print' to the screen you used "DISPLAY". (The more common method was to use "LPRINT" for sending to the printer.) From timothy.heckman at gmail.com Sat Mar 31 13:34:22 2012 From: timothy.heckman at gmail.com (Tim H.) Date: Sat, 31 Mar 2012 10:34:22 -0700 (PDT) Subject: M2Crypto.SSL.Checker.NoCertificate Exception Message-ID: <31286211.1769.1333215262331.JavaMail.geo-discussion-forums@vbug19> I have a weird quirk with the M2Crypto module and I hope someone would be able to point me in the right direction. I am working with a colleague to develop an internal tool to check SSL certificates on a list of IPv4 addresses obtained via stdin. We are using M2Crypto to help with validating the certificates. If we only have it check one IPv4 address, it is able to provide us with the correct certificate and we are able to do our validation checks on the information that the SSL certificate contains. However, if we try to check multiple IPv4 addresses we receive the "M2Crypto.SSL.Checker.NoCertificate". There are some cases where we should be receiving this. However, regardless of what the second or third IPv4 address is (even if it tested good as the first one), it will fail. Context creation: global context context = M2Crypto.SSL.Context() if sys.platform.startswith('linux'): context.load_verify_info(capath="/etc/ssl/certs/") #Linux with real open SSL installed elif sys.platform.startswith('darwin'): context.load_verify_info(cafile=certfile) else: print "Unknown platform, bail!" exit(1) context.set_allow_unknown_ca(True) context.set_verify(M2Crypto.SSL.verify_none,9) Socket creation: conn = M2Crypto.SSL.Connection(context) socket.setdefaulttimeout(2.0) conn.set_socket_read_timeout(M2Crypto.SSL.timeout(sec=2)) conn.set_socket_write_timeout(M2Crypto.SSL.timeout(sec=2)) try: conn.connect((ip,443)) The above two portions of code exist in their own functions. The latter block gets called as part of the loop over the array of addresses. The IP is passed from the caller. Thank you in advance! -Tim From showell30 at yahoo.com Sat Mar 31 13:51:55 2012 From: showell30 at yahoo.com (Steve Howell) Date: Sat, 31 Mar 2012 10:51:55 -0700 (PDT) Subject: string interpolation for python References: <1333174946.18436.YahooMailNeo@web121506.mail.ne1.yahoo.com> Message-ID: <485f1ac0-b63f-4c83-9a99-22494fb2283d@9g2000pbn.googlegroups.com> On Mar 31, 3:29?am, Terry Reedy wrote: > On 3/31/2012 2:22 AM, Yingjie Lan wrote: > > > Hi all, > > > I'd really like to share this idea of string interpolation for formatting. > > Let's start with some code: > > > ?>>> name = "Shrek" > > ?>>> print( "Hi, $name$!") > > Hi, Shrek! > > ?>>> balls = 30 > > ?>>> print( "We have $balls$ balls.") > > We have 30 balls > > You can already do essentially that without adding a special-case string > formatting method to the general methods we already have. > > ?>>> balls = 5 > ?>>> people = 3 > ?>>> 'The {people} people have {balls} balls.'.format(**locals()) > 'The 3 people have 5 balls.' > I was wondering how much of a performance penalty you pay for using the **locals() idiom, because I use it myself sometimes. It turns out there is a slight penalty for "**locals()" vs. explicitly passing in arguments to format (e.g. ".format(balls=balls, people=people"), although it's probably negligible in 99.9% of use cases. def yo(a): x = 1 y = 2 z = 3 a = b = c = d = 7 for i in range(10): # s = "{x} {y} {z}".format(**locals()) s = "{x} {y} {z}".format(x=x, y=y, z=z) for i in range(10000): yo(i) # .150s for **locals() # .131s for explicit x/y/z From showell30 at yahoo.com Sat Mar 31 14:20:34 2012 From: showell30 at yahoo.com (Steve Howell) Date: Sat, 31 Mar 2012 11:20:34 -0700 (PDT) Subject: 588 Python programs Message-ID: <122bd0c9-00a7-45ec-94ad-075ba3b79203@px4g2000pbc.googlegroups.com> Hi everyone, I have compiled over 500 Python programs from the Rosetta Code website in this page: http://shpaml.webfactional.com/misc/RosettaCoffee/python.htm For those of you unfamiliar with Rosetta Code, you can read more here: http://rosettacode.org/wiki/Rosetta_Code For the record, I'm not affiliated with the site, although I'm an occasional contributor. I'm also not the author of the programs, which were contributed/authored my multiple people and are covered under the GNU Free Documentation License 1.2. I did write the code to aggregate the examples in one place. I hope you find the examples interesting to read! From digitig at gmail.com Sat Mar 31 16:13:59 2012 From: digitig at gmail.com (Tim Rowe) Date: Sat, 31 Mar 2012 21:13:59 +0100 Subject: Number of languages known [was Re: Python is readable] - somewhat OT In-Reply-To: References: Message-ID: On 22 March 2012 19:14, Chris Angelico wrote: > In any case, though, I agree that there's a lot of people > professionally writing code who would know about the 3-4 that you say. > I'm just not sure that they're any good at coding, even in those few > languages. All the best people I've ever known have had experience > with quite a lot of languages. I know 10 languages. But I'm not telling you what base that number is :) -- Tim Rowe From showell30 at yahoo.com Sat Mar 31 16:23:13 2012 From: showell30 at yahoo.com (Steve Howell) Date: Sat, 31 Mar 2012 13:23:13 -0700 (PDT) Subject: Number of languages known [was Re: Python is readable] - somewhat OT References: Message-ID: <062a89c7-36e7-4c82-9546-1f216e425fe3@oo9g2000pbc.googlegroups.com> On Mar 31, 1:13?pm, Tim Rowe wrote: > > I know 10 languages. But I'm not telling you what base that number is :) > Well, that means you know at least two programming languages, which puts you ahead of a lot of people. :) Some folks, when confronted with a problem, decide to solve it with binary numbers. And then they have 10 problems. From drobinow at gmail.com Sat Mar 31 18:55:08 2012 From: drobinow at gmail.com (David Robinow) Date: Sat, 31 Mar 2012 18:55:08 -0400 Subject: Number of languages known [was Re: Python is readable] - somewhat OT In-Reply-To: References: Message-ID: On Sat, Mar 31, 2012 at 4:13 PM, Tim Rowe wrote: > I know 10 languages. But I'm not telling you what base that number is :) The fact that you know there are bases other than 10 puts you in the top half of the candidates already! From nagle at animats.com Sat Mar 31 18:58:45 2012 From: nagle at animats.com (John Nagle) Date: Sat, 31 Mar 2012 15:58:45 -0700 Subject: getaddrinfo NXDOMAIN exploit - please test on CentOS 6 64-bit Message-ID: Some versions of CentOS 6 seem to have a potential getaddrinfo exploit. See To test, try this from a command line: ping example If it fails, good. If it returns pings from "example.com", bad. The getaddrinfo code is adding ".com" to the domain. If that returns pings, please try ping noexample.com There is no "noexample.com" domain in DNS. This should time out. But if you get ping replies from a CNET site, let me know. Some implementations try "noexample.com", get a NXDOMAIN error, and try again, adding ".com". This results in a ping of "noexample.com,com". "com.com" is a real domain, run by a unit of CBS, and they have their DNS set up to catch all subdomains and divert them to, inevitably, an ad-oriented junk search page. (You can view the junk page at "http://slimeball.com.com". Replace "slimeball" with anything else you like; it will still resolve.) If you find a case where "ping noexample.com" returns a reply, then try it in Python: import socket socket.getaddrinfo("noexample.com", 80) That should return an error. If it returns the IP address of CNET's ad server, there's trouble. This isn't a problem with the upstream DNS. Usually, this sort of thing means you're using some sleazy upstream DNS provider like Comcast. That's not the case here. "host" and "nslookup" aren't confused. Only programs that use getaddrinfo, like "ping", "wget", and Python, have this ".com" appending thing. Incidentally, if you try "noexample.net", there's no problem, because the owner of "net.com" hasn't set up their DNS to exploit this. And, of course, it has nothing to do with browser toolbars. This is at a much lower level. If you can make this happen, report back the CentOS version and the library version, please. John Nagle From hannu at krosing.net Sat Mar 31 19:35:37 2012 From: hannu at krosing.net (Hannu Krosing) Date: Sun, 01 Apr 2012 01:35:37 +0200 Subject: Number of languages known [was Re: Python is readable] - somewhat OT In-Reply-To: References: Message-ID: <1333236937.17288.3.camel@hvost> On Sat, 2012-03-31 at 18:55 -0400, David Robinow wrote: > On Sat, Mar 31, 2012 at 4:13 PM, Tim Rowe wrote: > > > I know 10 languages. But I'm not telling you what base that number is :) > The fact that you know there are bases other than 10 puts you in the > top half of the candidates already! I'm sure he really had base 10 in mind * Hannu ------------ * But as this 10 is in his chosen base, it is a tautology :) From steve+comp.lang.python at pearwood.info Thu Mar 1 00:01:30 2012 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 01 Mar 2012 05:01:30 GMT Subject: lang comparison: in-place algorithm for reversing a list in Perl, Python, Lisp References: <85fa5760-68c8-41a2-9116-2489165f7ca1@j5g2000yqm.googlegroups.com> Message-ID: <4f4f02a9$0$1539$c3e8da3$76491128@news.astraweb.com> On Wed, 29 Feb 2012 20:07:49 -0800, Xah Lee wrote: > Here's in-place algorithm for reversing a list: > > # python > # in-place algorithm for reversing a list > > list_a = ["a", "b", "c", "d", "e", "f", "g"] > list_length = len(list_a) > for i in range(list_length/2): > x = list_a[i] > list_a[i] = list_a[ list_length -1 - i] > list_a[ list_length -1 - i] = x > > print list_a This is a good example of code written by somebody not very familiar with Python idioms. You don't need a temporary variable to swap two values in Python. A better way to reverse a list using more Pythonic idioms is: for i in range(len(list_a)//2): list_a[i], list_a[-i-1] = list_a[-i-1], list_a[i] But the best way (even more idiomatic and much, much faster) is this: list_a.reverse() -- Steven From drsalists at gmail.com Thu Mar 1 00:05:06 2012 From: drsalists at gmail.com (Dan Stromberg) Date: Wed, 29 Feb 2012 21:05:06 -0800 Subject: lang comparison: in-place algorithm for reversing a list in Perl, Python, Lisp In-Reply-To: <85fa5760-68c8-41a2-9116-2489165f7ca1@j5g2000yqm.googlegroups.com> References: <85fa5760-68c8-41a2-9116-2489165f7ca1@j5g2000yqm.googlegroups.com> Message-ID: On Wed, Feb 29, 2012 at 8:07 PM, Xah Lee wrote: > fun example. > > in-place algorithm for reversing a list in Perl, Python, Lisp > http://xahlee.org/comp/in-place_algorithm.html > > plain text follows > ---------------------------------------- > > What's ?In-place Algorithm?? > > Xah Lee, 2012-02-29 > > This page tells you what's ?In-place algorithm?, using {python, perl, > emacs lisp} code to illustrate. > > Aren't in-place reversals rather non-functional? > Python > The usual way is list_a.reverse(). This is in place. If you want to be a little weird, you could do this, but it's not in place: list_a = list_a[::-1] If you want to pretend you can't do this the easy ways above, you could do this, which is in place: length = len(list_a) for ind in xrange(length // 2): other=-ind-1 list_a[ind], list_a[other] = list_a[other], list_a[ind] HTH -------------- next part -------------- An HTML attachment was scrubbed... URL: From chiron613 at gmail.com Thu Mar 1 00:07:47 2012 From: chiron613 at gmail.com (Chiron) Date: Thu, 01 Mar 2012 05:07:47 GMT Subject: New Science Discovery: Perl Idiots Remain Idiots After A Decade!New Science Discovery: Perl Idiots Remain Idiots Af References: <0078bbfb-5dfc-48fc-af1a-69de3cf15c3e@b1g2000yqb.googlegroups.com> <87aa41k6x5.fsf@sapphire.mobileactivedefense.com> <4f4ef6c8$27$fuzhry+tra$mr2ice@news.patriot.net> Message-ID: On Wed, 29 Feb 2012 23:10:48 -0500, Shmuel (Seymour J.) Metz wrote: > ROTF,LMAO! You obviously don't have a clue as to what Mathematics means. > Free hint: it doesn't mean Arithmetic. You're as bigoted as Xah Lee, Hmm... maybe, instead of just ridiculing him, you could explain where he is mistaken. Of course, doing that is a *LOT* harder than just calling him a bigot. BTW, I happen to agree with you insofar as this poster not understanding the nature of mathematics. His comment reminds me of the article, "Transgressing the Boundaries: Towards a Transformative Hermeneutics of Quantum Gravity" (http://www.physics.nyu.edu/sokal/transgress_v2/ transgress_v2_singlefile.html). Also known as the "Sokal Hoax." -- Boling's postulate: If you're feeling good, don't worry. You'll get over it. From tjreedy at udel.edu Thu Mar 1 00:24:06 2012 From: tjreedy at udel.edu (Terry Reedy) Date: Thu, 01 Mar 2012 00:24:06 -0500 Subject: Is it necessary to call Tk() when writing a GUI app with Tkinter? In-Reply-To: References: <27603449.17.1330492001624.JavaMail.geo-discussion-forums@vbbfv2> <6e1c521e-14be-4ec0-9ff0-7f23fd9cd3dc@f14g2000yqe.googlegroups.com> Message-ID: On 2/29/2012 10:22 PM, Rick Johnson wrote: I do not know what book the OP is referring to, but the current doc example is http://docs.python.org/py3k/library/tkinter.html#a-simple-hello-world-program My current replacement (see below) can be downloaded from the tracker: http://bugs.python.org/issue14163 > If you want to keep things simple, i would: > > 1. Create the root window explicitly! It already does that. > 2. Bind the command of the button to root.destroy > (command=root.destroy) That works great. My current replacement example is uploaded to the issue http://bugs.python.org/issue14163 > PS: I would highly suggest against using the "from Tkinter import *". > Instead, use "import Tkinter as tk" and prefix all module contents > with "tk.". I have changed the example to do that. I also showed the alternate to initialize a widget. Here is the current version, tested on Windows 3.2.2. import tkinter as tk class Application(tk.Frame): def __init__(self, master=None): tk.Frame.__init__(self, master) self.pack() self.createWidgets() def createWidgets(self): self.hi_there = tk.Button(self) self.hi_there["text"] = "Hello_World\n(click_me)", self.hi_there["command"] = self.say_hi self.hi_there.pack({"side": "top"}) self.QUIT = tk.Button(self, text = "QUIT", fg = "red", command = root.destroy) self.QUIT.pack({"side": "bottom"}) def say_hi(self): print("hi there, everyone!") root = tk.Tk() app = Application(master=root) app.mainloop() There is a minor problem left. The hi_there Button text has underscores because if I use spaces instead, tk surrounds the text with {bra ces}. This seems bizarre. Is there any way to have Button text with spaces and no braces? -- Terry Jan Reedy From tjreedy at udel.edu Thu Mar 1 00:35:00 2012 From: tjreedy at udel.edu (Terry Reedy) Date: Thu, 01 Mar 2012 00:35:00 -0500 Subject: Help needed: dynamically pull data from different levels of a dict In-Reply-To: References: Message-ID: On 2/29/2012 11:04 PM, Peter Rubenstein wrote: > I'd appreciate a bit of help on this problem. I have some data that I've converted to a dict and I want to pull out individual pieces of it. > > Simplified version-- > a={'1':'a', '2':'b', '3':{4:'d'}, '5':{'6': {'7': [ {'8':'e'}, {'9':'f'} ] } } } > > I'd like to be able to code something like: > > data_needed = ['1', '2', '3:4', '5:6:7-8']for val in data_needed: answer=extract_from(a,val) print answer > > And get:abcde > > Problem is I can't figure out what extract_from would look like, such that it would proceed dynamically down to the right level. I'm open to the possibility that I'm not approaching this the right way. > If it helps, one member of my actual dict quoted below. So in real life, something likedata_needed=['name','active-defects', 'admin-status:format', 'description', 'traffic-statistics:input-bps']etc. > > Thanks in advance,Peter > > { 'ge-0/0/0': {'active-alarms': {'interface-alarms': {'alarm-not-present': ''}}, 'active-defects': {'interface-alarms': {'alarm-not-present': ''}}, 'admin-status': {'_text': 'up', 'format': 'Enabled'}, 'current-physical-address': '00:1f:12:c0:e8:00', 'description': 'INFRA:CROSS:ASH-64CB-1B:GE-0/0/0:', 'hardware-physical-address': '00:1f:12:c0:e8:00', 'if-config-flags': {'iff-snmp-traps': '', 'internal-flags': '0x4000'}, 'if-device-flags': {'ifdf-present': '', 'ifdf-running': ''}, 'if-flow-control': 'enabled', 'if-media-flags': {'ifmf-none': ''}, 'interface-flapped': {'_text': '2010-05-23 18:20:36 UTC (92w3d 02:27 ago)', 'seconds': '55909644'}, 'l2pt-error': 'none', 'link-level-type': 'Ethernet', 'local-index': '171', 'logical-interface': {'address-family': [{'address-family-flags': {'ifff-no-redirects': '', 'internal-flags': '0x0'}, 'address-family-name': 'inet', 'interface-address': {'ifa-destination': '207.46.43.2/31', 'ifa-flags': {'ifa f-current-preferred': '', 'ifaf-current-primary': ''}, 'ifa-local': '207.46.43.2'}, 'mtu': '9178'}, {'address-family-flags': {'ifff-mtu-user-conf': '', 'internal-flags': '0x10000000'}, 'address-family-name': 'mpls', 'mtu': '9174'}, {'address-family-flags': {'ifff-none': ''}, 'address-family-name': 'multiservice', 'mtu': 'Unlimited'}], 'description': 'INFRA:CROSS:ASH-64CB-1B:GE-0/0/0.0:', 'encapsulation': 'ENET2', 'if-config-flags': {'iff-snmp-traps': ''}, 'local-index': '67', 'name': 'ge-0/0/0.0', 'snmp-index': '117', 'traffic-statistics': {'input-packets': '46367422526659', 'output-packets': '35670513402384', 'style': 'brief'}}, 'loopback': 'disabled', 'mtu': '9192', 'name': 'ge-0/0/0', 'oper-status': 'up', 'physical-interface-cos-information': {'physical-interface-cos-hw-max-queues': '8', 'physical-interface-cos-use-max-queues': '8'}, 'snmp-index': '116', 'source-filtering': 'disabled', 'speed': '10Gbps', 't raffic-statistics': {'input-bps': '4104358720', 'input-pps': '1059450', 'output-bps': '2323588888', 'output-pps': '537816', 'style': 'brief'}},} -- Terry Jan Reedy From xahlee at gmail.com Thu Mar 1 00:39:37 2012 From: xahlee at gmail.com (Xah Lee) Date: Wed, 29 Feb 2012 21:39:37 -0800 (PST) Subject: lang comparison: in-place algorithm for reversing a list in Perl, Python, Lisp References: <85fa5760-68c8-41a2-9116-2489165f7ca1@j5g2000yqm.googlegroups.com> <4f4f02a9$0$1539$c3e8da3$76491128@news.astraweb.com> Message-ID: <865b899b-8ec7-4650-88d7-153d4e26178d@i6g2000yqe.googlegroups.com> On Feb 29, 9:01?pm, Steven D'Aprano wrote: > You don't need a temporary variable to swap two values in > Python. A better way to reverse a list using more Pythonic idioms is: > > for i in range(len(list_a)//2): > ? ? list_a[i], list_a[-i-1] = list_a[-i-1], list_a[i] forgive me sir, but i haven't been at python for a while. :) i was, actually, refreshing myself of what little polyglot skills i have. Xah From johnjsal at gmail.com Thu Mar 1 00:40:14 2012 From: johnjsal at gmail.com (John Salerno) Date: Wed, 29 Feb 2012 21:40:14 -0800 (PST) Subject: Is it necessary to call Tk() when writing a GUI app with Tkinter? In-Reply-To: References: <27603449.17.1330492001624.JavaMail.geo-discussion-forums@vbbfv2> <6e1c521e-14be-4ec0-9ff0-7f23fd9cd3dc@f14g2000yqe.googlegroups.com> Message-ID: <22943242.772.1330580414345.JavaMail.geo-discussion-forums@ynil17> > Yes, but i think the REAL problem is faulty code logic. Remove the > last line "root.destroy()" and the problem is solved. Obviously the > author does not have an in-depth knowledge of Tkinter. The faulty code is not my own, which is part of the reason I asked the question. The book I'm reading (The Quick Python Book) does not use it, but I saw in the Python docs that it is there, under "tkinter" in the Global Module Docs, "24.1.2.2. A Simple Hello World Program": from tkinter import * class Application(Frame): def say_hi(self): print("hi there, everyone!") def createWidgets(self): self.QUIT = Button(self) self.QUIT["text"] = "QUIT" self.QUIT["fg"] = "red" self.QUIT["command"] = self.quit self.QUIT.pack({"side": "left"}) self.hi_there = Button(self) self.hi_there["text"] = "Hello", self.hi_there["command"] = self.say_hi self.hi_there.pack({"side": "left"}) def __init__(self, master=None): Frame.__init__(self, master) self.pack() self.createWidgets() root = Tk() app = Application(master=root) app.mainloop() root.destroy() From tjreedy at udel.edu Thu Mar 1 00:40:45 2012 From: tjreedy at udel.edu (Terry Reedy) Date: Thu, 01 Mar 2012 00:40:45 -0500 Subject: Is it necessary to call Tk() when writing a GUI app with Tkinter? In-Reply-To: <17153317.324.1330576905540.JavaMail.geo-discussion-forums@yncd8> References: <27603449.17.1330492001624.JavaMail.geo-discussion-forums@vbbfv2> <6e1c521e-14be-4ec0-9ff0-7f23fd9cd3dc@f14g2000yqe.googlegroups.com> <17153317.324.1330576905540.JavaMail.geo-discussion-forums@yncd8> Message-ID: On 2/29/2012 11:41 PM, John Salerno wrote: > window? If you only want the Windows "X" button to close the window, > then is it okay to leave out any call to destroy()? Yes. You must leave it out. > the latter, then where in the code do you put the call to destroy so > it won't conflict with the user closing the window with the X > button? See my other post of a few minutes ago for an example that now works. -- Terry Jan Reedy From johnjsal at gmail.com Thu Mar 1 00:45:28 2012 From: johnjsal at gmail.com (John Salerno) Date: Wed, 29 Feb 2012 21:45:28 -0800 (PST) Subject: Is it necessary to call Tk() when writing a GUI app with Tkinter? In-Reply-To: References: <27603449.17.1330492001624.JavaMail.geo-discussion-forums@vbbfv2> <6e1c521e-14be-4ec0-9ff0-7f23fd9cd3dc@f14g2000yqe.googlegroups.com> <17153317.324.1330576905540.JavaMail.geo-discussion-forums@yncd8> Message-ID: <18841978.1037.1330580728432.JavaMail.geo-discussion-forums@vbgu10> On Wednesday, February 29, 2012 11:40:45 PM UTC-6, Terry Reedy wrote: > On 2/29/2012 11:41 PM, John Salerno wrote: > > > window? If you only want the Windows "X" button to close the window, > > then is it okay to leave out any call to destroy()? > > Yes. You must leave it out. > > > the latter, then where in the code do you put the call to destroy so > > it won't conflict with the user closing the window with the X > > button? > > See my other post of a few minutes ago for an example that now works. > > -- > Terry Jan Reedy When you suggested I create the root frame explicitly, you mean create a Tk object explicitly, as in your example, and then pass that as an argument to the Frame instance? What exactly is the purpose of doing that? Does Tk do some extra work that a simple call to Frame won't do? From johnjsal at gmail.com Thu Mar 1 00:45:28 2012 From: johnjsal at gmail.com (John Salerno) Date: Wed, 29 Feb 2012 21:45:28 -0800 (PST) Subject: Is it necessary to call Tk() when writing a GUI app with Tkinter? In-Reply-To: References: <27603449.17.1330492001624.JavaMail.geo-discussion-forums@vbbfv2> <6e1c521e-14be-4ec0-9ff0-7f23fd9cd3dc@f14g2000yqe.googlegroups.com> <17153317.324.1330576905540.JavaMail.geo-discussion-forums@yncd8> Message-ID: <18841978.1037.1330580728432.JavaMail.geo-discussion-forums@vbgu10> On Wednesday, February 29, 2012 11:40:45 PM UTC-6, Terry Reedy wrote: > On 2/29/2012 11:41 PM, John Salerno wrote: > > > window? If you only want the Windows "X" button to close the window, > > then is it okay to leave out any call to destroy()? > > Yes. You must leave it out. > > > the latter, then where in the code do you put the call to destroy so > > it won't conflict with the user closing the window with the X > > button? > > See my other post of a few minutes ago for an example that now works. > > -- > Terry Jan Reedy When you suggested I create the root frame explicitly, you mean create a Tk object explicitly, as in your example, and then pass that as an argument to the Frame instance? What exactly is the purpose of doing that? Does Tk do some extra work that a simple call to Frame won't do? From driscoll at cs.wisc.edu Thu Mar 1 01:07:21 2012 From: driscoll at cs.wisc.edu (Evan Driscoll) Date: Thu, 01 Mar 2012 00:07:21 -0600 Subject: lang comparison: in-place algorithm for reversing a list in Perl, Python, Lisp In-Reply-To: References: <85fa5760-68c8-41a2-9116-2489165f7ca1@j5g2000yqm.googlegroups.com> Message-ID: <4F4F1219.2070502@cs.wisc.edu> On 2/29/2012 23:05, Dan Stromberg wrote: > > On Wed, Feb 29, 2012 at 8:07 PM, Xah Lee > wrote: > > This page tells you what's ?In-place algorithm?, using {python, perl, > emacs lisp} code to illustrate. > > Aren't in-place reversals rather non-functional? There is one place where they're reasonably idiomatic in Lispy languages, at least by my understanding. That occurs when you are writing a function that returns a list and there is a natural recursive way to build up the answer -- but backwards. The idiom then is to build up a temporary list up backwards, then call an in-place reversal function. (NREVERSE in Common Lisp. I thought there was a reverse! in Scheme, but apparently not.) This doesn't break the external view of a pure function because the list that's being reversed is a fresh, temporary list, which is why this idiom would even fit in pretty well in Scheme. Evan -------------- next part -------------- A non-text attachment was scrubbed... Name: signature.asc Type: application/pgp-signature Size: 552 bytes Desc: OpenPGP digital signature URL: From johnjsal at gmail.com Thu Mar 1 01:14:41 2012 From: johnjsal at gmail.com (John Salerno) Date: Wed, 29 Feb 2012 22:14:41 -0800 (PST) Subject: Is it necessary to call Tk() when writing a GUI app with Tkinter? In-Reply-To: <18841978.1037.1330580728432.JavaMail.geo-discussion-forums@vbgu10> References: <27603449.17.1330492001624.JavaMail.geo-discussion-forums@vbbfv2> <6e1c521e-14be-4ec0-9ff0-7f23fd9cd3dc@f14g2000yqe.googlegroups.com> <17153317.324.1330576905540.JavaMail.geo-discussion-forums@yncd8> <18841978.1037.1330580728432.JavaMail.geo-discussion-forums@vbgu10> Message-ID: <28139175.898.1330582481406.JavaMail.geo-discussion-forums@ynbo36> > What exactly is the purpose of doing that? Does Tk do some extra work that a simple call to Frame won't do? More specifically, what is the benefit of doing: root = tk.Tk() app = Application(master=root) app.mainloop() as opposed to: app = Application() app.mainloop() Also, in the first example, what is the difference between calling app.mainloop() and root.mainloop()? They both seemed to work when I ran them. From johnjsal at gmail.com Thu Mar 1 01:14:41 2012 From: johnjsal at gmail.com (John Salerno) Date: Wed, 29 Feb 2012 22:14:41 -0800 (PST) Subject: Is it necessary to call Tk() when writing a GUI app with Tkinter? In-Reply-To: <18841978.1037.1330580728432.JavaMail.geo-discussion-forums@vbgu10> References: <27603449.17.1330492001624.JavaMail.geo-discussion-forums@vbbfv2> <6e1c521e-14be-4ec0-9ff0-7f23fd9cd3dc@f14g2000yqe.googlegroups.com> <17153317.324.1330576905540.JavaMail.geo-discussion-forums@yncd8> <18841978.1037.1330580728432.JavaMail.geo-discussion-forums@vbgu10> Message-ID: <28139175.898.1330582481406.JavaMail.geo-discussion-forums@ynbo36> > What exactly is the purpose of doing that? Does Tk do some extra work that a simple call to Frame won't do? More specifically, what is the benefit of doing: root = tk.Tk() app = Application(master=root) app.mainloop() as opposed to: app = Application() app.mainloop() Also, in the first example, what is the difference between calling app.mainloop() and root.mainloop()? They both seemed to work when I ran them. From timr at probo.com Thu Mar 1 01:24:14 2012 From: timr at probo.com (Tim Roberts) Date: Wed, 29 Feb 2012 22:24:14 -0800 Subject: pyusb and microchip mcp2210 interface References: Message-ID: jobattle wrote: > >Has anybody out there had any experience in using the PYUSB library with >the new Microchip MCP2210 USB to SPI chip? It appears to the system as a HID device. You don't need to use PyUSB -- it already has a driver. Check libhid -- it has a Python binding. -- Tim Roberts, timr at probo.com Providenza & Boekelheide, Inc. From w_a_x_man at yahoo.com Thu Mar 1 01:37:45 2012 From: w_a_x_man at yahoo.com (WJ) Date: 1 Mar 2012 06:37:45 GMT Subject: lang comparison: in-place algorithm for reversing a list in Perl, Python, Lisp References: <85fa5760-68c8-41a2-9116-2489165f7ca1@j5g2000yqm.googlegroups.com> Message-ID: Xah Lee wrote: > fun example. > > in-place algorithm for reversing a list in Perl, Python, Lisp > http://xahlee.org/comp/in-place_algorithm.html > > plain text follows > ---------------------------------------- > > What's ?In-place Algorithm?? > > Xah Lee, 2012-02-29 > > This page tells you what's ?In-place algorithm?, using {python, perl, > emacs lisp} code to illustrate. > > Here's Wikipedia In-place algorithm excerpt: > > In computer science, an in-place algorithm (or in Latin in situ) is an > algorithm which transforms input using a data structure with a small, > constant amount of extra storage space. The input is usually > overwritten by the output as the algorithm executes. An algorithm > which is not in-place is sometimes called not-in-place or out-of- > place. > > Python > > Here's a python code for reversing a list. Done by creating a new > list, NOT using in-place: > > # python > # reverse a list > > list_a = ["a", "b", "c", "d", "e", "f", "g"] > > list_length = len(list_a) > list_b = [0] * list_length > > for i in range(list_length): > list_b[i] = list_a[list_length -1 - i] > > print list_b > Here's in-place algorithm for reversing a list: > > # python > # in-place algorithm for reversing a list > > list_a = ["a", "b", "c", "d", "e", "f", "g"] > > list_length = len(list_a) > > for i in range(list_length/2): > x = list_a[i] > list_a[i] = list_a[ list_length -1 - i] > list_a[ list_length -1 - i] = x > > print list_a > Perl > > Here's a perl code for reversing a list. Done by creating a new list, > NOT using in-place: > > # perl > > use strict; > use Data::Dumper; > > my @listA = qw(a b c d e f g); > > my $listLength = scalar @listA; > my @listB = (); > > for ( my $i = 0; $i < $listLength; $i++ ) { > $listB[$i] = $listA[ $listLength - 1 - $i]; > } > > print Dumper(\@listB); > > # perl > # in-place algorithm for reversing a list. > > use strict; > use Data::Dumper; > use POSIX; # for ?floor? > > my @listA = qw(a b c d e f g); > > my $listLength = scalar @listA; > > for ( my $i = 0; $i < floor($listLength/2); $i++ ) { > my $x = $listA[$i]; > $listA[$i] = $listA[ $listLength - 1 - $i]; > $listA[ $listLength - 1 - $i] = $x; > } > > print Dumper(\@listA); > __END__ > > emacs lisp > > ;; emacs lisp > ;; reverse a array > > (setq arrayA ["a" "b" "c" "d" "e" "f" "g"]) > > (setq arrayLength (length arrayA)) > > (setq arrayB (make-vector arrayLength 0)) > > (dotimes (i arrayLength ) > (aset arrayB i (aref arrayA (- (1- arrayLength) i)) ) > ) > > (print (format "%S" arrayB)) > ;; emacs lisp > ;; in-place algorithm for reversing a array > > (setq arrayA ["a" "b" "c" "d" "e" "f" "g"]) > > (setq arrayLength (length arrayA)) > > (dotimes (i (floor (/ arrayLength 2))) > (let (x) > (setq x (aref arrayA i)) > (aset arrayA i (aref arrayA (- (1- arrayLength) i))) > (aset arrayA (- (1- arrayLength) i) x) ) ) > > (print (format "%S" arrayA)) > MatzLisp: a = [2,3,5,8] ==>[2, 3, 5, 8] a.reverse! ==>[8, 5, 3, 2] a ==>[8, 5, 3, 2] From johnjsal at gmail.com Thu Mar 1 01:41:53 2012 From: johnjsal at gmail.com (John Salerno) Date: Wed, 29 Feb 2012 22:41:53 -0800 (PST) Subject: Is it necessary to call Tk() when writing a GUI app with Tkinter? In-Reply-To: References: <27603449.17.1330492001624.JavaMail.geo-discussion-forums@vbbfv2> <6e1c521e-14be-4ec0-9ff0-7f23fd9cd3dc@f14g2000yqe.googlegroups.com> <17153317.324.1330576905540.JavaMail.geo-discussion-forums@yncd8> Message-ID: <23675630.870.1330584114032.JavaMail.geo-discussion-forums@ynjc20> > Yes. You must leave it out. Now I'm reading a Tkinter reference at http://infohost.nmt.edu/tcc/help/pubs/tkinter/minimal-app.html and it has this example: #!/usr/local/bin/python from Tkinter import * class Application(Frame): def __init__(self, master=None): Frame.__init__(self, master) self.grid() self.createWidgets() def createWidgets(self): self.quitButton = Button ( self, text='Quit', command=self.quit ) self.quitButton.grid() app = Application() app.master.title("Sample application") app.mainloop() Is this just outdated? I don't understand why it uses quit() instead of destroy(). When I try this in IDLE, quit() just causes the application to hang (I assume because it ends the mainloop without actually closing the application). Or is this just a problem when using IDLE? If the latter, which is preferable, quit or destroy? From johnjsal at gmail.com Thu Mar 1 01:41:53 2012 From: johnjsal at gmail.com (John Salerno) Date: Wed, 29 Feb 2012 22:41:53 -0800 (PST) Subject: Is it necessary to call Tk() when writing a GUI app with Tkinter? In-Reply-To: References: <27603449.17.1330492001624.JavaMail.geo-discussion-forums@vbbfv2> <6e1c521e-14be-4ec0-9ff0-7f23fd9cd3dc@f14g2000yqe.googlegroups.com> <17153317.324.1330576905540.JavaMail.geo-discussion-forums@yncd8> Message-ID: <23675630.870.1330584114032.JavaMail.geo-discussion-forums@ynjc20> > Yes. You must leave it out. Now I'm reading a Tkinter reference at http://infohost.nmt.edu/tcc/help/pubs/tkinter/minimal-app.html and it has this example: #!/usr/local/bin/python from Tkinter import * class Application(Frame): def __init__(self, master=None): Frame.__init__(self, master) self.grid() self.createWidgets() def createWidgets(self): self.quitButton = Button ( self, text='Quit', command=self.quit ) self.quitButton.grid() app = Application() app.master.title("Sample application") app.mainloop() Is this just outdated? I don't understand why it uses quit() instead of destroy(). When I try this in IDLE, quit() just causes the application to hang (I assume because it ends the mainloop without actually closing the application). Or is this just a problem when using IDLE? If the latter, which is preferable, quit or destroy? From steve+comp.lang.python at pearwood.info Thu Mar 1 02:38:08 2012 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 01 Mar 2012 07:38:08 GMT Subject: Is it necessary to call Tk() when writing a GUI app with Tkinter? References: <27603449.17.1330492001624.JavaMail.geo-discussion-forums@vbbfv2> <6e1c521e-14be-4ec0-9ff0-7f23fd9cd3dc@f14g2000yqe.googlegroups.com> <17153317.324.1330576905540.JavaMail.geo-discussion-forums@yncd8> <23675630.870.1330584114032.JavaMail.geo-discussion-forums@ynjc20> Message-ID: <4f4f2760$0$11107$c3e8da3@news.astraweb.com> On Wed, 29 Feb 2012 22:41:53 -0800, John Salerno wrote: >> Yes. You must leave it out. > > Now I'm reading a Tkinter reference at > http://infohost.nmt.edu/tcc/help/pubs/tkinter/minimal-app.html and it > has this example: [...] Could you please stop posting the same message twice? It's very annoying. There is no need to C.C. python-list because comp.lang.python is the mirror of the mailing list. Thank you. -- Steven From johnjsal at gmail.com Thu Mar 1 02:58:37 2012 From: johnjsal at gmail.com (John Salerno) Date: Wed, 29 Feb 2012 23:58:37 -0800 (PST) Subject: Is it necessary to call Tk() when writing a GUI app with Tkinter? In-Reply-To: <4f4f2760$0$11107$c3e8da3@news.astraweb.com> References: <27603449.17.1330492001624.JavaMail.geo-discussion-forums@vbbfv2> <6e1c521e-14be-4ec0-9ff0-7f23fd9cd3dc@f14g2000yqe.googlegroups.com> <17153317.324.1330576905540.JavaMail.geo-discussion-forums@yncd8> <23675630.870.1330584114032.JavaMail.geo-discussion-forums@ynjc20> <4f4f2760$0$11107$c3e8da3@news.astraweb.com> Message-ID: <30160611.9.1330588717114.JavaMail.geo-discussion-forums@ynbo9> On Thursday, March 1, 2012 1:38:08 AM UTC-6, Steven D'Aprano wrote: > On Wed, 29 Feb 2012 22:41:53 -0800, John Salerno wrote: > > >> Yes. You must leave it out. > > > > Now I'm reading a Tkinter reference at > > http://infohost.nmt.edu/tcc/help/pubs/tkinter/minimal-app.html and it > > has this example: > [...] > > Could you please stop posting the same message twice? It's very annoying. > There is no need to C.C. python-list because comp.lang.python is the > mirror of the mailing list. > > > Thank you. > > > > -- > Steven I'm sorry, it's unintentional. The new interface for Google Groups keeps doing weird things and makes double and triple posts. I deleted them from my end, but I guess they are still showing up for everyone else. From ushamovi at gmail.com Thu Mar 1 04:55:53 2012 From: ushamovi at gmail.com (usha chubby) Date: Thu, 1 Mar 2012 01:55:53 -0800 (PST) Subject: its very intersting Message-ID: <5a72545b-2b01-4088-ade1-4422d2dac461@j8g2000yqm.googlegroups.com> : http://123maza.com/46/hibiscus741/ From matt.jones at radiusrecruitment.co.uk Thu Mar 1 05:17:09 2012 From: matt.jones at radiusrecruitment.co.uk (Matt Jones) Date: Thu, 1 Mar 2012 10:17:09 +0000 Subject: Python Developer Job Opportunities Message-ID: <5430F7595299CC4FA07A3750381517D10F3A8838@AMSPRD0302MB110.eurprd03.prod.outlook.com> I have an opportunity for talented Python Developers with Django experience based in the South of the UK. I am recruiting for a funded new venture set up by two successful entrepreneurs who are experienced and well--respected scientists and mathematicians. They're building a new and radical way of learning Maths; an advanced technological platform (iPad / Cloud based) with unique data gathering and analysis capabilities the program will create a world beating, cutting edge product. They are on the hunt for Python developers to build the interface of a brand new cloud hosted web app that will be rolled out on iPad as well as a bespoke CMS, web portal and internal visualization platform. The team are working in brand new, expansive offices (45,000 square feet, free lunch, onsite gym, games room, poker room with casino grade tables, 5-A-Side football pitch). This is an exciting opportunity to become a core member of the development team in a growing company that will be providing a technical challenge in a fantastic working environment all in aid of a good cause. If you would like to discuss the role in more detail please contact me at matt.jones at radiusrecruitment.co.uk I can also provide photos of the office, details on working environment etc. -------------- next part -------------- An HTML attachment was scrubbed... URL: From kiuhnm03.4t.yahoo.it Thu Mar 1 06:00:26 2012 From: kiuhnm03.4t.yahoo.it (Kiuhnm) Date: Thu, 01 Mar 2012 12:00:26 +0100 Subject: New Science Discovery: Perl Idiots Remain Idiots After A Decade!New Science Discovery: Perl Idiots Remain Idiots After A Decade! In-Reply-To: <9dc55d52-3902-4449-87e7-745fb8b911b3@n12g2000yqb.googlegroups.com> References: <0078bbfb-5dfc-48fc-af1a-69de3cf15c3e@b1g2000yqb.googlegroups.com> <4f4e1554$0$1385$4fafbaef@reader2.news.tin.it> <9dc55d52-3902-4449-87e7-745fb8b911b3@n12g2000yqb.googlegroups.com> Message-ID: <4f4f56c8$0$1381$4fafbaef@reader2.news.tin.it> On 3/1/2012 1:02, Xah Lee wrote: > i missed a point in my original post. That is, when the same operator > are adjacent. e.g. ?3 ? 6 ? 5?. > > This is pointed out by Kiuhnm ?kiuhnm03.4t.yahoo.it? and Tim Bradshaw. > Thanks. > > though, i disagree the way they expressed it, or any sense this is > different from math. They did not make up the terminology, if that is what you are saying. The concepts of left and right associativity are well-known and accepted in TCS (Theoretical CS). If you change the terminology, no one will understand you unless you provide your definitions every time (and then they may not accept them). Another way of saying that an operator is left-associative is that its parse tree is a left-tree, i.e. a complete tree where each right child is a leaf. For instance, (use a monospaced font) 1 + 2 + 3 + 4 gives you this left-tree: + + 4 + 3 1 2 while 1**2**3**4 gives you this right-tree: ** 1 ** 2 ** 3 4 Aho, Sethi and Ullman explain it this way in "Compilers: Principles, Techniques and Tools": "We say that the operator + associates to the left because an operand with plus signs on both sides of it is taken by the operator to its left. [...]" And they also show parse trees similar to the ones I wrote above. Kiuhnm From palla74 at gmail.com Thu Mar 1 07:54:54 2012 From: palla74 at gmail.com (Palla) Date: Thu, 1 Mar 2012 04:54:54 -0800 (PST) Subject: EuroPython 2012: Call for Proposal is Open! [Please spread the word] Message-ID: Hi all, I am writing on behalf of EuroPython Staff (www.europython.eu). We are happy to announce that the Call for Proposals is now officially open! DEADLINE FOR PROPOSALS: MARCH 18TH, 23:59:59 CET For those who have never been at EuroPython (or similar conferences) before, the Call for Proposals is the period in which the organizers ask the community to submit proposals for talks to be held at the conference. EuroPython is a conference run by the community for the community: the vast majority of talks that are presented at the conference will be proposed, prepared and given by members of the Python community itself. And not only that: the process that selects the best talks among all the proposals will also be public and fully driven by the community: it's called Community Voting, and will begin right after the Call for Proposals ends. CFP: Talks, Hands-On Trainings and Posters ------------------------------------------ We're looking for proposals on every aspect of Python: programming from novice to advanced levels, applications and frameworks, or how you have been involved in introducing Python into your organisation. There are three different kind of contribution that you can present at EuroPython: - Regular talk. These are standard "talk with slides", allocated in slots of 45, 60 or 90 minutes, depending on your preference and scheduling constraints. A Q&A session is held at the end of the talk. - Hands-on training. These are advanced training sessions for a smaller audience (10-20 people), to dive into the subject with all details. These sessions are 4-hours long, and the audience will be strongly encouraged to bring a laptop to experiment. They should be prepared with less slides and more source code. - Posters. Posters are a graphical way to describe a project or a technology, printed in large format; posters are exhibited at the conference, can be read at any time by participants, and can be discussed face to face with their authors during the poster session. We will take care of printing the posters too, so don't worry about logistics. More details about Call for Proposal are online here: https://ep2012.europython.eu/call-for-proposals/ Don't wait for the last day --------------------------- If possible, please avoid submitting your proposals on the last day. It might sound a strange request, but last year about 80% of the proposals were submitted in the last 72 hours. This creates a few problems for organizers because we can't have a good picture of the size of the conference until that day. Remember that proposals are fully editable at any time, even after the Call for Proposals ends. You just need to login on the website, go to the proposal page (linked from your profile page), and click the Edit button. First-time speakers are especially welcome; EuroPython is a community conference and we are eager to hear about your experience. If you have friends or colleagues who have something valuable to contribute, twist their arms to tell us about it! We are a conference run by the community for the community. Please help to spread the word by distributing this announcement to colleagues, mailing lists, your blog, Web site, and through your social networking connections. All the best, Francesco From rolf.wester at ilt.fraunhofer.de Thu Mar 1 08:07:15 2012 From: rolf.wester at ilt.fraunhofer.de (Rolf Wester) Date: Thu, 01 Mar 2012 14:07:15 +0100 Subject: exec Message-ID: <4f4f7527$1@news.fhg.de> Hi, I would like to define methods using exec like this: class A: def __init__(self): cmd = "def sqr(self, x):\n return x**2\nself.sqr = sqr\n" exec cmd a = A() print a.sqr(a, 2) This works, but I have to call sqr with a.sqr(a, 2), a.sqr(2) does not work (TypeError: sqr() takes exactly 2 arguments (1 given)). Is there a possibility to define methods using exec and getting normal behavior? I would be very appreciative for any help. With kind regards Rolf Wester From jeanmichel at sequans.com Thu Mar 1 08:46:43 2012 From: jeanmichel at sequans.com (Jean-Michel Pichavant) Date: Thu, 01 Mar 2012 14:46:43 +0100 Subject: exec In-Reply-To: <4f4f7527$1@news.fhg.de> References: <4f4f7527$1@news.fhg.de> Message-ID: <4F4F7DC3.4070009@sequans.com> Rolf Wester wrote: > Hi, > > I would like to define methods using exec like this: > > class A: > def __init__(self): > cmd = "def sqr(self, x):\n return x**2\nself.sqr = sqr\n" > exec cmd > a = A() > print a.sqr(a, 2) > > This works, but I have to call sqr with a.sqr(a, 2), a.sqr(2) does not work > (TypeError: sqr() takes exactly 2 arguments (1 given)). > > Is there a possibility to define methods using exec and getting normal behavior? > > I would be very appreciative for any help. > > With kind regards > Rolf Wester > > > I'll try to ignore you are using the exec statement which is an error :o) a.sqr(2) would have worked only if sqr was a *bound* method. print a.sqr to oppose to print a.__init__ > You cannot dynamically bind a method, however you can do the following. cmd = "def sqr(x):\n return x**2\nself.sqr = sqr\n" http://docs.python.org/reference/datamodel.html : "It is also important to note that user-defined functions which are attributes of a class instance are not converted bound methods; this only happens when the function is an attribute of the class. " JM From fpallanti at develer.com Thu Mar 1 09:10:29 2012 From: fpallanti at develer.com (Francesco Pallanti) Date: Thu, 01 Mar 2012 15:10:29 +0100 Subject: EuroPython 2012: Call for Proposal is Open! [Please spread the word] Message-ID: <1330611029.15056.18.camel@bmlab-palla> Hi guys, I'm Francesco and I am writing on behalf of EuroPython Staff (www.europython.eu). We are happy to announce that the Call for Proposals is now officially open! DEADLINE FOR PROPOSALS: MARCH 18TH, 23:59:59 CET For those who have never been at EuroPython (or similar conferences) before, the Call for Proposals is the period in which the organizers ask the community to submit proposals for talks to be held at the conference. Further details about Call for Proposal are online here: http://ep2012.europython.eu/call-for-proposals/ EuroPython is a conference run by the community for the community: the vast majority of talks that are presented at the conference will be proposed, prepared and given by members of the Python community itself. And not only that: the process that selects the best talks among all the proposals will also be public and fully driven by the community: it's called Community Voting, and will begin right after the Call for Proposals ends. CFP: Talks, Hands-On Trainings and Posters ------------------------------------------ We're looking for proposals on every aspect of Python: programming from novice to advanced levels, applications and frameworks, or how you have been involved in introducing Python into your organisation. There are three different kind of contribution that you can present at EuroPython: - Regular talk. These are standard "talk with slides", allocated in slots of 45, 60 or 90 minutes, depending on your preference and scheduling constraints. A Q&A session is held at the end of the talk. - Hands-on training. These are advanced training sessions for a smaller audience (10-20 people), to dive into the subject with all details. These sessions are 4-hours long, and the audience will be strongly encouraged to bring a laptop to experiment. They should be prepared with less slides and more source code. - Posters. Posters are a graphical way to describe a project or a technology, printed in large format; posters are exhibited at the conference, can be read at any time by participants, and can be discussed face to face with their authors during the poster session. We will take care of printing the posters too, so don't worry about logistics. More details about Call for Proposal are online here: http://ep2012.europython.eu/call-for-proposals/ Don't wait for the last day --------------------------- If possible, please avoid submitting your proposals on the last day. It might sound a strange request, but last year about 80% of the proposals were submitted in the last 72 hours. This creates a few problems for organizers because we can't have a good picture of the size of the conference until that day. Remember that proposals are fully editable at any time, even after the Call for Proposals ends. You just need to login on the website, go to the proposal page (linked from your profile page), and click the Edit button. First-time speakers are especially welcome; EuroPython is a community conference and we are eager to hear about your experience. If you have friends or colleagues who have something valuable to contribute, twist their arms to tell us about it! We are a conference run by the community for the community. Please help to spread the word by distributing this announcement to colleagues, mailing lists, your blog, Web site, and through your social networking connections. All the best, -- Francesco Pallanti - fpallanti at develer.com Develer S.r.l. - http://www.develer.com/ .software .hardware .innovation Tel.: +39 055 3984627 - ext.: 215 From arnodel at gmail.com Thu Mar 1 09:13:39 2012 From: arnodel at gmail.com (Arnaud Delobelle) Date: Thu, 1 Mar 2012 14:13:39 +0000 Subject: exec In-Reply-To: <4f4f7527$1@news.fhg.de> References: <4f4f7527$1@news.fhg.de> Message-ID: On 1 March 2012 13:07, Rolf Wester wrote: > Hi, > > I would like to define methods using exec like this: > > class A: > ? ?def __init__(self): > ? ? ? ?cmd = "def sqr(self, x):\n ? ?return x**2\nself.sqr = sqr\n" > ? ? ? ?exec cmd > a = A() > print a.sqr(a, 2) > > This works, but I have to call sqr with a.sqr(a, 2), a.sqr(2) does not work > (TypeError: sqr() takes exactly 2 arguments (1 given)). I'm curious to know your motivation for doing this. -- Arnaud From steve+comp.lang.python at pearwood.info Thu Mar 1 09:21:31 2012 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 01 Mar 2012 14:21:31 GMT Subject: exec References: <4f4f7527$1@news.fhg.de> Message-ID: <4f4f85eb$0$29989$c3e8da3$5496439d@news.astraweb.com> On Thu, 01 Mar 2012 14:07:15 +0100, Rolf Wester wrote: > Hi, > > I would like to define methods using exec like this: > > class A: > def __init__(self): > cmd = "def sqr(self, x):\n return x**2\nself.sqr = sqr\n" > exec cmd > a = A() > print a.sqr(a, 2) That's... nasty, nasty code. I would hate to have to maintain that. I hope you have a VERY good reason for doing it instead of the more obvious: class B: def __init__(self): def sqr(self, x): return x**2 self.sqr = sqr or the even more obvious: class C: def sqr(self, x): return x**2 And I *really* hope that you aren't getting the string to be exec'ed from untrusted users. The world has enough code injection vulnerabilities. If you don't understand what a code injection vulnerability is, or why using exec on untrusted strings is dangerous, stop what you are doing and don't write another line of code until you have read up it. You can start here: http://en.wikipedia.org/wiki/Code_injection https://www.owasp.org/index.php/Injection_Flaws and remember, code injection attacks are now the most frequent attack vector of viruses, worms and malware, ahead of buffer overflow attacks. Class C is, of course, the only one where a.sqr is an actual method, that is, a.sqr(5) works instead of a.sqr(a, 5). You can fix this by doing one of the following: (1) Your function sqr() doesn't actually use self, so why require it? Get rid of it! class A: def __init__(self): # still nasty... cmd = "def sqr(x):\n return x**2" exec cmd self.sqr = sqr # or put this in the cmd string (yuck) class B: def __init__(self): # better, but still weird def sqr(x): return x**2 self.sqr = sqr (2) Perhaps you actually do need access to self. So turn the function into a proper method. from types import MethodType class A: def __init__(self): # still nasty... cmd = "def sqr(self, x):\n return x**2\n" exec cmd self.sqr = MethodType(sqr, self) class B: def __init__(self): def sqr(self, x): return x**2 self.sqr = MethodType(sqr, self) (3) My guess is that there is probably some sort of closure-based solution that will work, or delegation, or composition. But given the toy example you have shown, I don't know what that might be. If you explain what you are actually doing, perhaps someone can suggest a better solution. -- Steven From rweikusat at mssgmbh.com Thu Mar 1 09:39:25 2012 From: rweikusat at mssgmbh.com (Rainer Weikusat) Date: Thu, 01 Mar 2012 14:39:25 +0000 Subject: lang comparison: in-place algorithm for reversing a list in Perl, Python, Lisp References: <85fa5760-68c8-41a2-9116-2489165f7ca1@j5g2000yqm.googlegroups.com> Message-ID: <87obsg1j36.fsf@sapphire.mobileactivedefense.com> Xah Lee writes: [...] > # perl > # in-place algorithm for reversing a list. > > use strict; > use Data::Dumper; > use POSIX; # for ?floor? > > my @listA = qw(a b c d e f g); > > my $listLength = scalar @listA; > > for ( my $i = 0; $i < floor($listLength/2); $i++ ) { > my $x = $listA[$i]; > $listA[$i] = $listA[ $listLength - 1 - $i]; > $listA[ $listLength - 1 - $i] = $x; > } > > print Dumper(\@listA); Better algorithm for that (expects an array reference as first argument) sub rev { my $a = $_[0]; my ($n0, $n1, $x); $n0 = 0; $n1 = $#$a; while ($n0 < $n1) { $x = $a->[$n0]; $a->[$n0] = $a->[$n1]; $a->[$n1] = $x; ++$n0; --$n1; } } NB: The fact that a sufficiently sophisticated compiler might be able to fix this automatically emphasizes the deficiencies of the original attempt, it doesn't excuse them. From rweikusat at mssgmbh.com Thu Mar 1 09:40:58 2012 From: rweikusat at mssgmbh.com (Rainer Weikusat) Date: Thu, 01 Mar 2012 14:40:58 +0000 Subject: New Science Discovery: Perl Idiots Remain Idiots After A Decade!New Science Discovery: Perl Idiots Remain Idiots Af References: <0078bbfb-5dfc-48fc-af1a-69de3cf15c3e@b1g2000yqb.googlegroups.com> <87aa41k6x5.fsf@sapphire.mobileactivedefense.com> <4f4ef6c8$27$fuzhry+tra$mr2ice@news.patriot.net> Message-ID: <87k4341j0l.fsf@sapphire.mobileactivedefense.com> Shmuel (Seymour J.) Metz writes: > In <87aa41k6x5.fsf at sapphire.mobileactivedefense.com>, on 02/29/2012 > at 03:15 PM, Rainer Weikusat said: > >>'mathematics' (an essentially outdated write-only programming >>language dating back to the times when humans had to perform >>computations themselves) > > ROTF,LMAO! You obviously don't have a clue as to what Mathematics > means. Free hint: it doesn't mean Arithmetic. You obviously don't have any sense of humour. But don't let this trouble you. From spamtrap at library.lspace.org.invalid Thu Mar 1 10:07:15 2012 From: spamtrap at library.lspace.org.invalid (Shmuel Metz (Seymour J.)) Date: Thu, 01 Mar 2012 10:07:15 -0500 Subject: New Science Discovery: Perl Detracters Remain Idiots After A Decade! References: <0078bbfb-5dfc-48fc-af1a-69de3cf15c3e@b1g2000yqb.googlegroups.com> <4f4ef5d2$26$fuzhry+tra$mr2ice@news.patriot.net> Message-ID: <4f4f90a3$38$fuzhry+tra$mr2ice@news.patriot.net> In , on 03/01/2012 at 04:52 AM, Chiron said: >Yes. That (the mathematically defined way) is a particular way, is >it not? No. There is no "the mathematically defined way". >However, I wasn't specifically referring to infix/postfix/prefix or >anything of that nature. I wasn't limiting my comment to lisp >notation in particular, since what I said applies to any language. No, it doesn't. >I was referring to the placement of parentheses (or other >groupings) to indicate to *humans* what the intended sequence >of events was. Operator precedence has the same purpose, and was around long before computers. Quite often expressions exploiting operator precedence are easier *for humans* to read than expressions involving deeply nested parentheses. >Mathematically, Your exposure to Mathematics is too limited. >and in any language with which I am familiar, Your exposure to computer languages is too limited. >the sequence: 2 + 6 / 3 will yield 4. Try it in APL. >Whenever there is *any* possibility of ambiguity, I see no reason >not to clarify. Even if doing so makes it harder to read? Since you keep referring to Mathematics, I will point out that it is rare in Mathematics for anybody to publish a complete proof. Minor steps are almost always omitted to make for easier reading, and ambiguous shortcuts are used in the expectation that the reader will understand what is meant. >Back in the days when the way you wrote your code affected how it >was compiled, That would be the present. >it made sense to rely heavily on language-specific >features, thus saving a few bytes. Those optimizations involved adding extraneous parentheses, not omitting redundant parentheses. >A few extra variables, if they help clarity, aren't going to hurt >anything. And if they harm clarity? >Let the machine do the grunt work. That's exactly what languages with operator precedence do. >Pamper your readers (which in a few weeks or months might be you) >and show exactly what you had in mind. The two goals conflict. >That's all I'm saying. No; you're saying to use redundant parentheses, which conflicts with other things you're saying. -- Shmuel (Seymour J.) Metz, SysProg and JOAT Unsolicited bulk E-mail subject to legal action. I reserve the right to publicly post or ridicule any abusive E-mail. Reply to domain Patriot dot net user shmuel+news to contact me. Do not reply to spamtrap at library.lspace.org From spamtrap at library.lspace.org.invalid Thu Mar 1 10:13:11 2012 From: spamtrap at library.lspace.org.invalid (Shmuel Metz (Seymour J.)) Date: Thu, 01 Mar 2012 10:13:11 -0500 Subject: New Science Discovery: Perl Idiots Remain Idiots After A Decade!New Science Discovery: Perl Idiots Remain Idiots Af References: <0078bbfb-5dfc-48fc-af1a-69de3cf15c3e@b1g2000yqb.googlegroups.com> <87aa41k6x5.fsf@sapphire.mobileactivedefense.com> <4f4ef6c8$27$fuzhry+tra$mr2ice@news.patriot.net> Message-ID: <4f4f9207$39$fuzhry+tra$mr2ice@news.patriot.net> In , on 03/01/2012 at 05:07 AM, Chiron said: >Hmm... maybe, instead of just ridiculing him, I'm treating him as he treats others. >BTW, I happen to agree with you insofar as this poster not >understanding the nature of mathematics. His comment reminds me of >the article, "Transgressing the Boundaries: Towards a >Transformative Hermeneutics of Quantum Gravity" A brilliant piece of work. I greatly enjoyed it and the reaction to its disclosure. -- Shmuel (Seymour J.) Metz, SysProg and JOAT Unsolicited bulk E-mail subject to legal action. I reserve the right to publicly post or ridicule any abusive E-mail. Reply to domain Patriot dot net user shmuel+news to contact me. Do not reply to spamtrap at library.lspace.org From marek.lipert at gmail.com Thu Mar 1 10:41:19 2012 From: marek.lipert at gmail.com (Marek Lipert) Date: Thu, 01 Mar 2012 16:41:19 +0100 Subject: SSL and os.system/Popen Message-ID: Hi! I have a problem with SSL and threaded os.system (rewritten to Popen but still not working). First - the set-up: I am using windows 2003 server with current python 2.6. When new connection comes to my server-side application, i do accept, and then: self.client = ssl.wrap_socket(self.socket,certfile="server.crt",keyfile="server.key",ss l_version=ssl.PROTOCOL_TLSv1,server_side=True) It works flawlessly UNLESS another therad of this same application runs simultanously os.system (or Popen) on an external exe file (which does not do a thing in a directory where my server is) I then get an error [Errno 336265218] _ssl.c:337: error:140B0002:SSL routines:SSL_CTX_use_PrivateKey_file:system lib I suspect it has something to do with filesystem locking, but why? The application is run by administrator and certificate files are marked as 'full control' and all other security properties in windows (for everyone, not just administrator). I would appreciate your help. Cheers, Mark From rolf.wester at ilt.fraunhofer.de Thu Mar 1 10:58:41 2012 From: rolf.wester at ilt.fraunhofer.de (Rolf Wester) Date: Thu, 01 Mar 2012 16:58:41 +0100 Subject: exec In-Reply-To: <4f4f7527$1@news.fhg.de> References: <4f4f7527$1@news.fhg.de> Message-ID: <4f4f9d55$1@news.fhg.de> Hi, thanks for your replies so far. The reason to use exec is just laziness. I have quite a lot of classes representing material data and every class has a number of parameters. The parameter are Magnitude objects (they have a value and a unit and overloaded special functions to correctly handle the units). I want to have getter functions that either return the Magnitude object or just the value: iron = Iron() iron.rho(0) => value iron.rho() => Magnitude object def rho(self, uf=1): if uf == 1: return self._rho else: return self._rho.val And because this would mean quite a lot of writing I tried to do it with exec. With kind regards Rolf Wester From phd at phdru.name Thu Mar 1 11:08:40 2012 From: phd at phdru.name (Oleg Broytman) Date: Thu, 1 Mar 2012 20:08:40 +0400 Subject: SQLObject 1.2.2 Message-ID: <20120301160840.GD3441@iskra.aviel.ru> Hello! I'm pleased to announce version 1.2.2, a bugfix release of branch 1.2 of SQLObject. What is SQLObject ================= SQLObject is an object-relational mapper. Your database tables are described as classes, and rows are instances of those classes. SQLObject is meant to be easy to use and quick to get started with. SQLObject supports a number of backends: MySQL, PostgreSQL, SQLite, Firebird, Sybase, MSSQL and MaxDB (also known as SAPDB). Where is SQLObject ================== Site: http://sqlobject.org Development: http://sqlobject.org/devel/ Mailing list: https://lists.sourceforge.net/mailman/listinfo/sqlobject-discuss Archives: http://news.gmane.org/gmane.comp.python.sqlobject Download: http://pypi.python.org/pypi/SQLObject/1.2.2 News and changes: http://sqlobject.org/News.html What's New ========== * A bug was fixed in SQLiteConnection - clear _threadPool on close(). For a more complete list, please see the news: http://sqlobject.org/News.html Oleg. -- Oleg Broytman http://phdru.name/ phd at phdru.name Programmers don't die, they just GOSUB without RETURN. From michael at stroeder.com Thu Mar 1 11:26:03 2012 From: michael at stroeder.com (=?ISO-8859-1?Q?Michael_Str=F6der?=) Date: Thu, 01 Mar 2012 17:26:03 +0100 Subject: exec In-Reply-To: <4f4f9d55$1@news.fhg.de> References: <4f4f7527$1@news.fhg.de> <4f4f9d55$1@news.fhg.de> Message-ID: Rolf Wester wrote: > The reason to use exec is just laziness. The worst reason for using it. So I hope you carefully read Steven's comment and get rid of exec() for anything serious: <4f4f85eb$0$29989$c3e8da3$5496439d at news.astraweb.com> Ciao, Michael. From peter216 at gmail.com Thu Mar 1 11:56:16 2012 From: peter216 at gmail.com (Peter Rubenstein) Date: Thu, 1 Mar 2012 11:56:16 -0500 Subject: Help needed: dynamically pull data from different levels of a dict In-Reply-To: References: Message-ID: Thanks, Chris. That's the algorithm I was looking for. And I will be converting most of this data to objects. Thanks again. -----Original Message----- From: Chris Rebert [mailto:clp2 at rebertia.com] Sent: Wednesday, February 29, 2012 11:44 PM Subject: Re: Help needed: dynamically pull data from different levels of a dict On Wed, Feb 29, 2012 at 7:56 PM, Peter Rubenstein wrote: > Hi, > > I'd appreciate a bit of help on this problem. I have some data that > I've converted to a dict and I want to pull out individual pieces of it. > > Simplified version-- > > a={'1':'a', '2':'b', '3':{4:'d'}, '5':{'6': {'7': [ {'8':'e'}, > {'9':'f'} ] } } } > > I'd like to be able to code something like: > > data_needed = ['1', '2', '3:4', '5:6:7-8'] for val in data_needed: > answer=extract_from(a,val) > print answer > > And get: > a > b > c "c" apparently sprung completely out of thin air... > d > e > > Problem is I can't figure out what extract_from would look like, such > that it would proceed dynamically down to the right level. I'm open > to the possibility that I'm not approaching this the right way. data_needed = ['1', '2', ('3', '4'), ('5', '6', '7', 0, '8')] def extract_from(mapping, key_path): current = mapping for key in key_path: current = current[key] return current I would perhaps try and restructure the data into something less generic than nested dicts & lists, e.g. objects. You then might be able to introduce helper querying methods. I would also be worried about Law of Demeter violations, but fortunately your concrete example doesn't reach any deeper than 2 levels. Cheers, Chris -- http://chrisrebert.com From __peter__ at web.de Thu Mar 1 12:14:54 2012 From: __peter__ at web.de (Peter Otten) Date: Thu, 01 Mar 2012 18:14:54 +0100 Subject: exec References: <4f4f7527$1@news.fhg.de> <4f4f9d55$1@news.fhg.de> Message-ID: Rolf Wester wrote: > The reason to use exec is just laziness. I have quite a lot of classes > representing material data and every class has a number of parameters. > The parameter are Magnitude objects (they have a value and a unit and > overloaded special functions to correctly handle the units). I want to > have getter functions that either return the Magnitude object or just the > value: > > iron = Iron() > iron.rho(0) => value > iron.rho() => Magnitude object > > def rho(self, uf=1): > if uf == 1: > return self._rho > else: > return self._rho.val > > And because this would mean quite a lot of writing I tried to do it with > exec. Make the Magnitude class callable then: >>> class Magnitude(object): ... def __init__(self, value): ... self.value = value ... def __call__(self, uf=1): ... if uf == 1: ... return self ... return self.value ... >>> class Iron(object): ... def __init__(self): ... self.rho = Magnitude(42) ... >>> iron = Iron() >>> iron.rho() <__main__.Magnitude object at 0x7fb94062be10> >>> iron.rho(0) 42 From rolf.wester at ilt.fraunhofer.de Thu Mar 1 12:23:58 2012 From: rolf.wester at ilt.fraunhofer.de (Rolf Wester) Date: Thu, 01 Mar 2012 18:23:58 +0100 Subject: exec In-Reply-To: References: <4f4f7527$1@news.fhg.de> <4f4f9d55$1@news.fhg.de> Message-ID: <4f4fb151$1@news.fhg.de> Thank you, that really made things much easier and admittedly much less nasty too. Regards Rolf On 01/03/12 18:14, Peter Otten wrote: > Rolf Wester wrote: > >> The reason to use exec is just laziness. I have quite a lot of classes >> representing material data and every class has a number of parameters. >> The parameter are Magnitude objects (they have a value and a unit and >> overloaded special functions to correctly handle the units). I want to >> have getter functions that either return the Magnitude object or just the >> value: >> >> iron = Iron() >> iron.rho(0) => value >> iron.rho() => Magnitude object >> >> def rho(self, uf=1): >> if uf == 1: >> return self._rho >> else: >> return self._rho.val >> >> And because this would mean quite a lot of writing I tried to do it with >> exec. > > Make the Magnitude class callable then: > >>>> class Magnitude(object): > ... def __init__(self, value): > ... self.value = value > ... def __call__(self, uf=1): > ... if uf == 1: > ... return self > ... return self.value > ... >>>> class Iron(object): > ... def __init__(self): > ... self.rho = Magnitude(42) > ... >>>> iron = Iron() >>>> iron.rho() > <__main__.Magnitude object at 0x7fb94062be10> >>>> iron.rho(0) > 42 > > From nikunjbadjatya at gmail.com Thu Mar 1 12:39:28 2012 From: nikunjbadjatya at gmail.com (Nikunj Badjatya) Date: Thu, 1 Mar 2012 23:09:28 +0530 Subject: HELP ! Popen.terminate() - WindowsError: [Error 5] Access is denied Message-ID: Howdy All, Py ver - 3.2, Windows-XP . Logged in as user with admin privileges. >From my main python program, I am running powershell program using subprocess.Popen(....). Now I have created a signal_handler() function in main python script which will handle CTRL-C ( This works fine ). Now when I put "proc.terminate()" in my signal_handler() function to terminate the subprocess created as well, It is giving me "WindowsError: [Error 5] Access is denied" error. I have tried with os.kill() also, same error. Tried with Popen.kill() also same error. Have googled a bit but couldn't understand them. In general, How to kill a subprocesses created from a python program.? If that subprocess also creates a new process from itself, how can I kill all child processes from my main python script.? Any ideas.?? Thanks, Nikunj -------------- next part -------------- An HTML attachment was scrubbed... URL: From ramit.prasad at jpmorgan.com Thu Mar 1 13:15:55 2012 From: ramit.prasad at jpmorgan.com (Prasad, Ramit) Date: Thu, 1 Mar 2012 18:15:55 +0000 Subject: HELP ! Popen.terminate() - WindowsError: [Error 5] Access is denied In-Reply-To: References: Message-ID: <5B80DD153D7D744689F57F4FB69AF47416B26E@SCACMX008.exchad.jpmchase.net> > Now when I put "proc.terminate()" in my signal_handler() function to > terminate the subprocess created as well, > It is giving me "WindowsError: [Error 5] Access is denied" error. > I have tried with os.kill() also, same error. Tried with Popen.kill() also > same error. Have googled a bit but couldn't understand them. > > In general, How to kill a subprocesses created from a python program.? If > that subprocess also creates a new process from itself, how can I kill all > child processes from my main python script.? I have not tested this, but you could get the pid by doing Popen.pid and then killing it from the command line by doing "taskkill /PID [pid]". This is all dependant on the users ability to kill the task in the first place. If that does not work then the problem is probably not Python but Windows. You could test by running your program and doing the taskkill in a separate command prompt. Hope that helps, Ramit Ramit Prasad | JPMorgan Chase Investment Bank | Currencies Technology 712 Main Street | Houston, TX 77002 work phone: 713 - 216 - 5423 -- This email is confidential and subject to important disclaimers and conditions including on offers for the purchase or sale of securities, accuracy and completeness of information, viruses, confidentiality, legal privilege, and legal entity disclaimers, available at http://www.jpmorgan.com/pages/disclosures/email. From spamtrap at library.lspace.org.invalid Thu Mar 1 16:11:35 2012 From: spamtrap at library.lspace.org.invalid (Shmuel Metz (Seymour J.)) Date: Thu, 01 Mar 2012 16:11:35 -0500 Subject: New Science Discovery: Perl Idiots Remain Idiots After A Decade!New Science Discovery: Perl Idiots Remain Idiots Af References: <0078bbfb-5dfc-48fc-af1a-69de3cf15c3e@b1g2000yqb.googlegroups.com> <87aa41k6x5.fsf@sapphire.mobileactivedefense.com> <4f4ef6c8$27$fuzhry+tra$mr2ice@news.patriot.net> <87k4341j0l.fsf@sapphire.mobileactivedefense.com> Message-ID: <4f4fe607$4$fuzhry+tra$mr2ice@news.patriot.net> In <87k4341j0l.fsf at sapphire.mobileactivedefense.com>, on 03/01/2012 at 02:40 PM, Rainer Weikusat said: >You obviously don't have any sense of humour. Certainly I do; I laugh at pretentious loons with delusions of adequacy. -- Shmuel (Seymour J.) Metz, SysProg and JOAT Unsolicited bulk E-mail subject to legal action. I reserve the right to publicly post or ridicule any abusive E-mail. Reply to domain Patriot dot net user shmuel+news to contact me. Do not reply to spamtrap at library.lspace.org From jeanpierreda at gmail.com Thu Mar 1 16:58:13 2012 From: jeanpierreda at gmail.com (Devin Jeanpierre) Date: Thu, 1 Mar 2012 16:58:13 -0500 Subject: New Science Discovery: Perl Idiots Remain Idiots After A Decade!New Science Discovery: Perl Idiots Remain Idiots Af In-Reply-To: References: <0078bbfb-5dfc-48fc-af1a-69de3cf15c3e@b1g2000yqb.googlegroups.com> <87aa41k6x5.fsf@sapphire.mobileactivedefense.com> <4f4ef6c8$27$fuzhry+tra$mr2ice@news.patriot.net> Message-ID: On Thu, Mar 1, 2012 at 12:07 AM, Chiron wrote: > On Wed, 29 Feb 2012 23:10:48 -0500, Shmuel (Seymour J.) Metz wrote: > >> ROTF,LMAO! You obviously don't have a clue as to what Mathematics means. >> Free hint: it doesn't mean Arithmetic. You're as bigoted as Xah Lee, > > > Hmm... maybe, instead of just ridiculing him, you could explain where he > is mistaken. ?Of course, doing that is a *LOT* harder than just calling > him a bigot. I agree. Perhaps this is a good primer: http://www.maa.org/devlin/LockhartsLament.pdf -- Devin From xahlee at gmail.com Thu Mar 1 17:04:10 2012 From: xahlee at gmail.com (Xah Lee) Date: Thu, 1 Mar 2012 14:04:10 -0800 (PST) Subject: lang comparison: in-place algorithm for reversing a list in Perl,Python, Lisp References: <85fa5760-68c8-41a2-9116-2489165f7ca1@j5g2000yqm.googlegroups.com> <20120229231658.89@kylheku.com> <20120301064937.505@kylheku.com> Message-ID: <8e769add-e63c-4a74-bb7e-ddd36c04a415@vs5g2000pbc.googlegroups.com> On Mar 1, 7:04?am, Kaz Kylheku wrote: lisp: (floor (/ x y)) --[rewrite]--> (floor x y) Thanks for this interesting point. I don't think it's a good lang design, more of a lang quirk. similarly, in Python 2.x, x/y will work when both x and y are integers. Also, x//y works too, but that // is just perlish unreadable syntax quirk. similarly, in perl, either one require POSIX; floor(x/y); the require POSIX instead of Math is a quirk. But even, floor should really be builtin. or using a perl hack int(x/y) all of the above are quirks. They rely on computer engineering by- products (such as int), or rely on the lang's idiosyncrasy. One easy way to measure it is whether a programer can read and understand a program without having to delve into its idiosyncrasies. Problem with these lang idioms is that it's harder to understand, and whatever advantage/optimization they provide is microscopic and temporary. best is really floor(x/y). idiomatic programing, is a bad thing. It was spread by perl, of course, in the 1990s. Idiomatic lang, i.e. lang with huge number of bizarre idioms, such as perl, is the worst. Xah From rweikusat at mssgmbh.com Thu Mar 1 17:14:35 2012 From: rweikusat at mssgmbh.com (Rainer Weikusat) Date: Thu, 01 Mar 2012 22:14:35 +0000 Subject: lang comparison: in-place algorithm for reversing a list in Perl, Python, Lisp References: <85fa5760-68c8-41a2-9116-2489165f7ca1@j5g2000yqm.googlegroups.com> <20120229231658.89@kylheku.com> <20120301064937.505@kylheku.com> <8e769add-e63c-4a74-bb7e-ddd36c04a415@vs5g2000pbc.googlegroups.com> Message-ID: <87zkc0oto4.fsf@sapphire.mobileactivedefense.com> Xah Lee writes: [...] > similarly, in perl, either one > require POSIX; floor(x/y); > the require POSIX instead of Math is a quirk. But even, floor should > really be builtin. > or > using a perl hack > int(x/y) > > all of the above are quirks. They rely on computer engineering by- > products (such as int), Integral numbers are not 'a computer engineering byproduct'. > or rely on the lang's idiosyncrasy. One easy way to measure it is > whether a programer can read and understand a program without having > to delve into its idiosyncrasies. Problem with these lang idioms is > that it's harder to understand, and whatever advantage/optimization > they provide is microscopic and temporary. It's hard to understand for someone who knows only mathematical idiosyncrasies and who is also convinced that this should really be more than enough for a lifetime. But that's not some kind of 'natural knowledge' people just happen to have but systematically drilled into pupils from a very early age, despite most of them won't ever have any use for any of it insofar it goes beyond + - * /. [...] > idiomatic programing, is a bad thing. If you have to use something (like a particular programming language) but you resent learning how to use it and rather make lofty excuses, chances are that you are rather a lazy f*cker than a great philosopher ... From anikom15 at gmail.com Thu Mar 1 19:46:52 2012 From: anikom15 at gmail.com (Westley =?iso-8859-1?Q?Mart=EDnez?=) Date: Thu, 1 Mar 2012 16:46:52 -0800 Subject: New Science Discovery: Perl Idiots Remain Idiots After A Decade!New Science Discovery: Perl Idiots Remain Idiots After A Decade! In-Reply-To: <0078bbfb-5dfc-48fc-af1a-69de3cf15c3e@b1g2000yqb.googlegroups.com> References: <0078bbfb-5dfc-48fc-af1a-69de3cf15c3e@b1g2000yqb.googlegroups.com> Message-ID: <20120302004652.GA30734@kubrick> First of all: http://www.youtube.com/watch?v=z5jKMEB4hHE On Wed, Feb 29, 2012 at 12:09:16AM -0800, Xah Lee wrote: > Now, let me tell you what operator precedence is. First of all, let's > limit ourselfs to discuss operators that are so-called binary > operators, which, in our context, basically means single symbol > operator that takes it's left and right side as operands. Now, each > symbol have a ?precedence?, or in other words, the set of operators > has a order. (one easy way to think of this is that, suppose you have > n symbols, then you give each a number, from 1 to n, as their order) > So, when 2 symbols are placed side by side such as ?3 ? 6 ? 5?, the > symbol with higher precedence wins. Another easy way to think of this > is that each operator has a stickiness level. The higher its level, it > more sticky it is. You're absolutely correct. > the problem with the perl explanations is that it's one misleading > confusion ball. It isn't about ?left/right associativity?. It isn't > about ?evaluates from left to right or right to left?. Worse, the word > ?associativity? is a math term that describe a property of algebra > that has nothing to do with operator precedence, yet is easily > confused with because it is a property about order of evaluation. (for > example, the addition function is associative, meaning: ?(3+6)+5 = > 3+(6+5)?.) You're not getting it. Math is a language. Perl is a language. They have different rules for grammar. In Perl, C, Python, Java, and pretty much all procedural-based languages, operations are evaluated in two steps: the precedence /and/ the associativity. Each level of precedence has its own associativity, either left-to-right or right-to-left. You can see this in table 2-1 in The C Programming Language. Whatever math does or what you think math does has nothing to do with the way Perl evaluates expressions. From rantingrickjohnson at gmail.com Thu Mar 1 21:35:44 2012 From: rantingrickjohnson at gmail.com (Rick Johnson) Date: Thu, 1 Mar 2012 18:35:44 -0800 (PST) Subject: Is it necessary to call Tk() when writing a GUI app with Tkinter? References: <27603449.17.1330492001624.JavaMail.geo-discussion-forums@vbbfv2> <6e1c521e-14be-4ec0-9ff0-7f23fd9cd3dc@f14g2000yqe.googlegroups.com> <17153317.324.1330576905540.JavaMail.geo-discussion-forums@yncd8> Message-ID: On Feb 29, 10:41?pm, John Salerno wrote: > I'm not sure I understand which method you are advocating. It > sounded like you said calling Tk() explicitly is a bug. I am saying just the opposite: Allowing the module "Tkinter" to implicitly create a root window IF the programmer was too lazy to create a root window himself is ridiculous, confusing, and inconsistent; therefor it's a BUG! Observe: INCORRECT: import Tkinter as tk b = tk.Button(master=None, text='Sloppy Coder') b.pack() b.mainloop() CORRECT: import Tkinter as tk root = tk.Tk() b = tk.Button(root, text='Smart Coder') b.pack() root.mainloop() IMO, only the widget "Tkinter.Tk" should have the method mainloop! If you call w.mainloop() and "w" is NOT an instance of Tkinter.Tk, then an error should be raised; I decided to raise a LazyCoderError in MY version of the Tkinter module just to drive the point home. > I certainly would never create widgets without first creating a > master frame, You really have no choice otherwise. Each and every widget requires a parent argument (or parent=None, which will then create and use the Tkinter._default_root; BUG!). The fact that Tkinter "magically" creates the root window for you does not negate the fact that every widget requires a parent. This is why i think the official version of Tkinter is flawed. And the fix is very simple actually. > but is creating a Frame object enough, or should I create a Tk > object and *then* a Frame object? No matter what, you MUST create an instance of Tkinter.Tk to be the "root" window of your GUI application. After that, you can nest as many frames, toplevels, and blah widgets under that root window as you so desire. Actually you don't even need a "frame", you can pack widgets directly into a Toplevel or Tk widget. EXAMPLE 1: (this works, but is flawed!) root = tk.Tk() b = tk.Button(master=None, text='Sloppy Coder') b.pack() root.mainloop() EXAMPLE 2: (This is how to write code!) root = tk.Tk() widgetframe = tk.Frame(root) b = tk.Button(master=None, text='Sloppy Coder') b.pack() root.mainloop() EXAMPLE 3: (OOP style) class App(tk.Tk): def __init__(self): tk.Tk.__init__(self) # something should happen here to justify using OOP # or here class AppFrame(tk.Frame): def __init__(self, master, **kw): tk.Frame.__init__(self, master, **kw) self.createWidgets() def createWidgets(self): b = tk.Button(master=None, text='Push Me') b.pack() if __name__ == '__main__': app = App() frame = AppFrame(app) frame.pack() app.mainloop() > Also, at what point do you include the destroy method in your > program, assuming you do not have a widget that will close the > window? If you only want the Windows "X" button to close the window, > then is it okay to leave out any call to destroy()? Yes. GUI destruction should (almost always) be controlled by the user. In certain circumstances you will want to force destruction, or intercept a users request for destruction so you can do something first (cleanup, sanity checks, etc...). > Or should always explicitly destroy it just as I explicitly created > a Tk instance? NO, you should create the root and then allow the user to decide when to destroy the GUI. Always remember the phrase: "User Driven Events" when coding a GUI! > If the latter, then where in the code do you put the call to destroy > so it won't conflict with the user closing the window with the X > button? In the "very special" cases where you need to destory the GUI, make sure no code can run AFTER you destroy the root window. Whoever wrote that example was obviously too lazy to run the code and check for errors or subtle bugs. From rantingrickjohnson at gmail.com Thu Mar 1 21:49:08 2012 From: rantingrickjohnson at gmail.com (Rick Johnson) Date: Thu, 1 Mar 2012 18:49:08 -0800 (PST) Subject: Is it necessary to call Tk() when writing a GUI app with Tkinter? References: <27603449.17.1330492001624.JavaMail.geo-discussion-forums@vbbfv2> <6e1c521e-14be-4ec0-9ff0-7f23fd9cd3dc@f14g2000yqe.googlegroups.com> Message-ID: <3d0bf288-fa5d-48e5-9529-db92d420a915@1g2000yqv.googlegroups.com> On Feb 29, 11:24?pm, Terry Reedy wrote: > On 2/29/2012 10:22 PM, Rick Johnson wrote: > > PS: I would highly suggest against using the "from Tkinter import *". > > Instead, use "import Tkinter as tk" and prefix all module contents > > with "tk.". > > I have changed the example to do that. I also showed the alternate to > initialize a widget. Here is the current version, tested on Windows 3.2.2. > > import tkinter as tk > > class Application(tk.Frame): > ? ? ?def __init__(self, master=None): > ? ? ? ? ?tk.Frame.__init__(self, master) > ? ? ? ? ?self.pack() With all due respect, I would also recommend against "self packing" a widget. And i can speak from experience on this issue. There was a time when i was self-packing lots of custom compund widgets; then i realized later the shortcomings of such action; what if you need to use the grid or place geometry mangers instead? So remove the self.pack line and add a line to the bottom: > root = tk.Tk() > app = Application(master=root) > app.pack() # <-- added this line > app.mainloop() > There is a minor problem left. The hi_there Button text has underscores > because if I use spaces instead, tk surrounds the text with {bra ces}. > This seems bizarre. Is there any way to have Button text with spaces and > no braces? Not sure what is happening on your end, but i don't see any braces. In any event, here is a slightly modified version of your code that follows PEP8 and removes some inconsistencies. ## START CODE ## # Python < 3.0 import Tkinter as tk from Tkconstants import TOP, BOTTOM from tkMessageBox import showinfo class Application(tk.Frame): def __init__(self, master=None): tk.Frame.__init__(self, master) self.createWidgets() def createWidgets(self): self.hi_there = tk.Button(self) self.hi_there["text"] = "Hello_World\n(click_me)" self.hi_there["command"] = self.say_hi self.hi_there.pack() # !!! self.qbutton = tk.Button(self, text="Close Application", fg="red", command=root.destroy) self.qbutton.pack() # !!! def say_hi(self): showinfo('Modal Dialog', "hi there, everyone!", parent=self) print("hi there, everyone!") if __name__ == '__main__': root = tk.Tk() app = Application(master=root) app.pack() app.mainloop() ## END CODE ## From rantingrickjohnson at gmail.com Thu Mar 1 21:53:12 2012 From: rantingrickjohnson at gmail.com (Rick Johnson) Date: Thu, 1 Mar 2012 18:53:12 -0800 (PST) Subject: Is it necessary to call Tk() when writing a GUI app with Tkinter? References: <27603449.17.1330492001624.JavaMail.geo-discussion-forums@vbbfv2> <6e1c521e-14be-4ec0-9ff0-7f23fd9cd3dc@f14g2000yqe.googlegroups.com> <22943242.772.1330580414345.JavaMail.geo-discussion-forums@ynil17> Message-ID: On Feb 29, 11:40?pm, John Salerno wrote: > The faulty code is not my own, which is part of the reason I asked > the question. The book I'm reading (The Quick Python Book) does not > use it, but I saw in the Python docs that it is there, under > "tkinter" in the Global Module Docs, "24.1.2.2. A Simple Hello World > Program": Book authors and Doc authors are not always the most well informed; as we have witnessed by this very thread! > from tkinter import * don't do that! > class Application(Frame): > ? ? def say_hi(self): > ? ? ? ? print("hi there, everyone!") > > ? ? def createWidgets(self): > ? ? ? ? self.QUIT = Button(self) > ? ? ? ? self.QUIT["text"] = "QUIT" > ? ? ? ? self.QUIT["fg"] = "red" > ? ? ? ? self.QUIT["command"] = self.quit > > ? ? ? ? self.QUIT.pack({"side": "left"}) don't do that either! Widgets take optional keyword arguments now so stop passing in dictionaries. self.quit.pack(side=tk.LEFT) Obviously these tutorials are more like: "What NOT to do when coding Tkinter GUIs!" No wonder everyone hates Tkinter. :-) From rantingrickjohnson at gmail.com Thu Mar 1 21:55:18 2012 From: rantingrickjohnson at gmail.com (Rick Johnson) Date: Thu, 1 Mar 2012 18:55:18 -0800 (PST) Subject: Is it necessary to call Tk() when writing a GUI app with Tkinter? References: <27603449.17.1330492001624.JavaMail.geo-discussion-forums@vbbfv2> <6e1c521e-14be-4ec0-9ff0-7f23fd9cd3dc@f14g2000yqe.googlegroups.com> <17153317.324.1330576905540.JavaMail.geo-discussion-forums@yncd8> <18841978.1037.1330580728432.JavaMail.geo-discussion-forums@vbgu10> <28139175.898.1330582481406.JavaMail.geo-discussion-forums@ynbo36> Message-ID: On Mar 1, 12:14?am, John Salerno wrote: > > What exactly is the purpose of doing that? Does Tk do some extra work that a simple call to Frame won't do? > > More specifically, what is the benefit of doing: > > root = tk.Tk() > app = Application(master=root) > app.mainloop() > > as opposed to: > > app = Application() > app.mainloop() > > Also, in the first example, what is the difference between calling app.mainloop() and root.mainloop()? They both seemed to work when I ran them. I tell you what. Just keep coding Tkinter GUIs like these broken docs tell you to, than after you become proficient you will understand. You will say: "That Rick really knew what he was talking about after all!" From rantingrickjohnson at gmail.com Thu Mar 1 22:02:37 2012 From: rantingrickjohnson at gmail.com (Rick Johnson) Date: Thu, 1 Mar 2012 19:02:37 -0800 (PST) Subject: Is it necessary to call Tk() when writing a GUI app with Tkinter? References: <27603449.17.1330492001624.JavaMail.geo-discussion-forums@vbbfv2> <6e1c521e-14be-4ec0-9ff0-7f23fd9cd3dc@f14g2000yqe.googlegroups.com> <3d0bf288-fa5d-48e5-9529-db92d420a915@1g2000yqv.googlegroups.com> Message-ID: On Mar 1, 8:49?pm, Rick Johnson wrote: > On Feb 29, 11:24?pm, Terry Reedy wrote: > > > On 2/29/2012 10:22 PM, Rick Johnson wrote: > > > PS: I would highly suggest against using the "from Tkinter import *". > > > Instead, use "import Tkinter as tk" and prefix all module contents > > > with "tk.". > > > I have changed the example to do that. I also showed the alternate to > > initialize a widget. Here is the current version, tested on Windows 3.2.2. > > > import tkinter as tk > > > class Application(tk.Frame): > > ? ? ?def __init__(self, master=None): > > ? ? ? ? ?tk.Frame.__init__(self, master) > > ? ? ? ? ?self.pack() > > With all due respect, I would also recommend against "self packing" a > widget. And i can speak from experience on this issue. There was a > time when i was self-packing lots of custom compund widgets; then i > realized later the shortcomings of such action; what if you need to > use the grid or place geometry mangers instead? So remove the > self.pack line and add a line to the bottom: > > > root = tk.Tk() > > app = Application(master=root) > > app.pack() # <-- added this line > > app.mainloop() > > There is a minor problem left. The hi_there Button text has underscores > > because if I use spaces instead, tk surrounds the text with {bra ces}. > > This seems bizarre. Is there any way to have Button text with spaces and > > no braces? > > Not sure what is happening on your end, but i don't see any braces. In > any event, here is a slightly modified version of your code that > follows PEP8 and removes some inconsistencies. > > ## START CODE ## > # Python < 3.0 > import Tkinter as tk > from Tkconstants import TOP, BOTTOM > from tkMessageBox import showinfo > > class Application(tk.Frame): > ? ? ?def __init__(self, master=None): > ? ? ? ? ?tk.Frame.__init__(self, master) > ? ? ? ? ?self.createWidgets() > > ? ? ?def createWidgets(self): > ? ? ? ? ?self.hi_there = tk.Button(self) > ? ? ? ? ?self.hi_there["text"] = "Hello_World\n(click_me)" > ? ? ? ? ?self.hi_there["command"] = self.say_hi > ? ? ? ? ?self.hi_there.pack() # !!! > ? ? ? ? ?self.qbutton = tk.Button(self, text="Close Application", > ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? fg="red", command=root.destroy) > ? ? ? ? ?self.qbutton.pack() # !!! > > ? ? ?def say_hi(self): > ? ? ? ? ?showinfo('Modal Dialog', "hi there, everyone!", parent=self) > ? ? ? ? ?print("hi there, everyone!") > > if __name__ == '__main__': > ? ? root = tk.Tk() > ? ? app = Application(master=root) > ? ? app.pack() > ? ? app.mainloop() > ## END CODE ## Opps, i just realized that "App" is actually a Tkinter.Frame and not a Tkinter.Toplevel. So the line: showinfo('Modal Dialog', "hi there, everyone!", parent=self) ...is broken. Since we don't have a reference to the root window from inside the scope of this Frame class, we can use "self.winfo_toplevel()" to fetch a reference. showinfo('Modal Dialog', "hi there, everyone!", parent=self.winfo_toplevel()) ...ahhh! That should work perfectly now! From johnjsal at gmail.com Thu Mar 1 22:15:21 2012 From: johnjsal at gmail.com (John Salerno) Date: Thu, 1 Mar 2012 19:15:21 -0800 (PST) Subject: Is it necessary to call Tk() when writing a GUI app with Tkinter? In-Reply-To: References: <27603449.17.1330492001624.JavaMail.geo-discussion-forums@vbbfv2> <6e1c521e-14be-4ec0-9ff0-7f23fd9cd3dc@f14g2000yqe.googlegroups.com> <17153317.324.1330576905540.JavaMail.geo-discussion-forums@yncd8> Message-ID: <6008330.241.1330658121340.JavaMail.geo-discussion-forums@ynlt17> > EXAMPLE 1: (this works, but is flawed!) > root = tk.Tk() > b = tk.Button(master=None, text='Sloppy Coder') > b.pack() > root.mainloop() > > EXAMPLE 2: (This is how to write code!) > root = tk.Tk() > widgetframe = tk.Frame(root) > b = tk.Button(master=None, text='Sloppy Coder') > b.pack() > root.mainloop() > > EXAMPLE 3: (OOP style) > class App(tk.Tk): > def __init__(self): > tk.Tk.__init__(self) > # something should happen here to justify using OOP > # or here > > class AppFrame(tk.Frame): > def __init__(self, master, **kw): > tk.Frame.__init__(self, master, **kw) > self.createWidgets() > > def createWidgets(self): > b = tk.Button(master=None, text='Push Me') > b.pack() > > if __name__ == '__main__': > app = App() > frame = AppFrame(app) > frame.pack() > app.mainloop() Why is the master argument for Button set to None? Shouldn't it be the Frame object? And shouldn't it also have self as the first argument? From rantingrickjohnson at gmail.com Thu Mar 1 22:19:55 2012 From: rantingrickjohnson at gmail.com (Rick Johnson) Date: Thu, 1 Mar 2012 19:19:55 -0800 (PST) Subject: Is it necessary to call Tk() when writing a GUI app with Tkinter? References: <27603449.17.1330492001624.JavaMail.geo-discussion-forums@vbbfv2> <6e1c521e-14be-4ec0-9ff0-7f23fd9cd3dc@f14g2000yqe.googlegroups.com> <17153317.324.1330576905540.JavaMail.geo-discussion-forums@yncd8> <6008330.241.1330658121340.JavaMail.geo-discussion-forums@ynlt17> Message-ID: <4eb739df-c642-4bbf-a155-9ed150e3acaf@s13g2000yqe.googlegroups.com> On Mar 1, 9:15?pm, John Salerno wrote: > > EXAMPLE 1: (this works, but is flawed!) > > ?root = tk.Tk() > > ?b = tk.Button(master=None, text='Sloppy Coder') > > ?b.pack() > > ?root.mainloop() > > > EXAMPLE 2: (This is how to write code!) > > ?root = tk.Tk() > > ?widgetframe = tk.Frame(root) > > ?b = tk.Button(master=None, text='Sloppy Coder') > > ?b.pack() > > ?root.mainloop() > > > EXAMPLE 3: (OOP style) > > ?class App(tk.Tk): > > ? ? ?def __init__(self): > > ? ? ? ? ?tk.Tk.__init__(self) > > ? ? ? ? ?# something should happen here to justify using OOP > > ? ? ?# or here > > > ?class AppFrame(tk.Frame): > > ? ? ?def __init__(self, master, **kw): > > ? ? ? ? ?tk.Frame.__init__(self, master, **kw) > > ? ? ? ? ?self.createWidgets() > > > ? ? ?def createWidgets(self): > > ? ? ? ? ?b = tk.Button(master=None, text='Push Me') > > ? ? ? ? ?b.pack() > > > ?if __name__ == '__main__': > > ? ? ?app = App() > > ? ? ?frame = AppFrame(app) > > ? ? ?frame.pack() > > ? ? ?app.mainloop() > > Why is the master argument for Button set to None? Shouldn't it be the Frame object? And shouldn't it also have self as the first argument? Hmm, it seems as though i am the latest victim of the "copy/paste error"! Oh well, if you were going to absorb my teachings, you would have absorbed them by now. I am moving on unless a new subject needs explaining. From tjreedy at udel.edu Thu Mar 1 22:43:22 2012 From: tjreedy at udel.edu (Terry Reedy) Date: Thu, 01 Mar 2012 22:43:22 -0500 Subject: Is it necessary to call Tk() when writing a GUI app with Tkinter? In-Reply-To: <3d0bf288-fa5d-48e5-9529-db92d420a915@1g2000yqv.googlegroups.com> References: <27603449.17.1330492001624.JavaMail.geo-discussion-forums@vbbfv2> <6e1c521e-14be-4ec0-9ff0-7f23fd9cd3dc@f14g2000yqe.googlegroups.com> <3d0bf288-fa5d-48e5-9529-db92d420a915@1g2000yqv.googlegroups.com> Message-ID: On 3/1/2012 9:49 PM, Rick Johnson wrote: > On Feb 29, 11:24 pm, Terry Reedy wrote: >> There is a minor problem left. The hi_there Button text has underscores >> because if I use spaces instead, tk surrounds the text with {bra ces}. >> This seems bizarre. Is there any way to have Button text with spaces and >> no braces? > > Not sure what is happening on your end, but i don't see any braces. Are you saying that if you change "Hello_World\n(click_me)" to "Hello World\n(click me)", you see Hello World (click me) as I expected, instead of {Hellow World (click me)} as I do see? What OS are you running? And what tk version? (I have 8.5.9 in Win7) -- Terry Jan Reedy From alec.taylor6 at gmail.com Thu Mar 1 23:55:38 2012 From: alec.taylor6 at gmail.com (Alec Taylor) Date: Fri, 2 Mar 2012 15:55:38 +1100 Subject: Spacing and timing for comparing algorithms and data-structures Message-ID: What would you recommend I use to compare data-structures and algorithms on space and time? (runtime) Thanks for all suggestions, Alec Taylor From cs at zip.com.au Fri Mar 2 00:15:47 2012 From: cs at zip.com.au (Cameron Simpson) Date: Fri, 2 Mar 2012 16:15:47 +1100 Subject: this afternoon's duck typing exercise ... Message-ID: <20120302051547.GA26249@cskk.homeip.net> Sorry, little technical content here, just a newly hatched programmer: duck typing, an intro http://www.flickr.com/photos/cskk/6799351990/in/photostream/ duck typing, resting after the demo http://www.flickr.com/photos/cskk/6945461405/in/photostream/ Cheers, -- Cameron Simpson DoD#743 http://www.cskk.ezoshosting.com/cs/ There is hopeful symbolism in the fact that flags do not wave in a vacuum. - Arthur C. Clarke From johnjsal at gmail.com Fri Mar 2 00:22:55 2012 From: johnjsal at gmail.com (John Salerno) Date: Thu, 1 Mar 2012 21:22:55 -0800 (PST) Subject: Is it necessary to call Tk() when writing a GUI app with Tkinter? In-Reply-To: <4eb739df-c642-4bbf-a155-9ed150e3acaf@s13g2000yqe.googlegroups.com> References: <27603449.17.1330492001624.JavaMail.geo-discussion-forums@vbbfv2> <6e1c521e-14be-4ec0-9ff0-7f23fd9cd3dc@f14g2000yqe.googlegroups.com> <17153317.324.1330576905540.JavaMail.geo-discussion-forums@yncd8> <6008330.241.1330658121340.JavaMail.geo-discussion-forums@ynlt17> <4eb739df-c642-4bbf-a155-9ed150e3acaf@s13g2000yqe.googlegroups.com> Message-ID: <1510171.280.1330665781888.JavaMail.geo-discussion-forums@vbux23> > Hmm, it seems as though i am the latest victim of the "copy/paste > error"! Oh well, if you were going to absorb my teachings, you would > have absorbed them by now. I am moving on unless a new subject needs > explaining. Well, I've certainly absorbed your recommendation to always create the root explicitly, but you still haven't really explained WHY. Telling me that I will eventually find out as I become more proficient isn't very helpful. I like being explicit, so I will create the Tk option like you suggest (although I don't see the need to subclass it first), but I also like knowing WHY I do what I do, so it would help to have some reason why it's better to create the root explicitly rather than allow Tkinter to do it. From steve+comp.lang.python at pearwood.info Fri Mar 2 00:35:18 2012 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 02 Mar 2012 05:35:18 GMT Subject: this afternoon's duck typing exercise ... References: Message-ID: <4f505c16$0$29989$c3e8da3$5496439d@news.astraweb.com> On Fri, 02 Mar 2012 16:15:47 +1100, Cameron Simpson wrote: > Sorry, little technical content here, just a newly hatched programmer: > > duck typing, an intro > http://www.flickr.com/photos/cskk/6799351990/in/photostream/ I love it! Excellent! -- Steven From luke.leighton at gmail.com Fri Mar 2 00:42:13 2012 From: luke.leighton at gmail.com (lkcl) Date: Thu, 1 Mar 2012 21:42:13 -0800 (PST) Subject: GUIs - a modest proposal Message-ID: <5ba38955-0ae8-4471-8701-dbe358deb3d3@eb6g2000vbb.googlegroups.com> folks hi, apologies for picking this up so late - it's only when i find these things through random searches that i encounter the occasional post. At some point wayyyy in the distant past, g4b wrote: > On the subject of the gui discussion mentioned here last year, > which you get lead to if you read around in the pyjamas docs, > I have to admit, since I know both development types (gwt, wx, qt) > and (django, jquery), I have to state the fact, that pyjamas should > also consider bonding with native javascript library developments. ah. right. you're either referring to pyjampiler (in the pyjs world) or to a vunnderbarr hidden iframe trick (in the pyjd world) where the execution results of a random javascript function has to store its results in the iframe (in JSON format) in order for the python world to monitor it, pick it up, decode it and pretend that nothing weird happened. the former actually got taken to an extreme by a group who embedded the pyjs 0.5 compiler into their application environment, i keep forgetting what it's called. but yes, they just put an "@decorator" in front of functions in the django source code, automatic recompile server-side, absolutely superb approach. > I was just looking at pyquery, a python implementation of jquery, > which could easily backbone jquery itself on the python end. you _what_??? pyquery? bizarre! you mean this? http://pypi.python.org/pypi/pyquery > Now this is not pyjamas' task, but the pyjs compiler could be used, > so that jquery code could be written for both languages. with a bit of coordination between the projects? yes, quite likely. $ however isn't a valid python variable name. but i get the point. > Long story short: if you could write jquery in python which actually > compiles into jquery in javascript, and even runs on python itself, > you could deploy widgets natively from python in django, > and dont have to leave python to improve webapplications with its native strengths. oh i see what you mean - compiling into jquery. yes, that would take care of the $ problem. that actually wouldn't be too hard to do, either. it'd also make an extremely neat GSoC project. l. From clp2 at rebertia.com Fri Mar 2 00:44:05 2012 From: clp2 at rebertia.com (Chris Rebert) Date: Thu, 1 Mar 2012 21:44:05 -0800 Subject: Spacing and timing for comparing algorithms and data-structures In-Reply-To: References: Message-ID: On Thu, Mar 1, 2012 at 8:55 PM, Alec Taylor wrote: > What would you recommend I use to compare data-structures and > algorithms on space and time? (runtime) For the latter metric, one of the profiling modules: http://docs.python.org/library/debug.html I'd start with timeit and go from there: http://docs.python.org/library/timeit.html For the former metric, you can write your own memory use measurement utility function on top of: http://docs.python.org/library/sys.html#sys.getsizeof Or there is doubtless some Unix tool(s) you could use to get a more crude measure of the total memory used by the Python interpreter process. Cheers, Chris -- http://rebertia.com From johnjsal at gmail.com Fri Mar 2 01:00:21 2012 From: johnjsal at gmail.com (John Salerno) Date: Thu, 1 Mar 2012 22:00:21 -0800 (PST) Subject: Is this the proper way to use a class method? Message-ID: <4136337.363.1330668021961.JavaMail.geo-discussion-forums@ynjd19> This is purely for fun and learning, so I know there are probably better ways of creating a chess program. Right now I'm just curious about my specific question, but I'd love to hear any other advice as well. Basically, I'm wondering if I'm using the class method properly with the move method. The reason I did it this way is because every chess piece will obviously have its own move method, yet they will all need to mark the piece as moved, so I figure that's best written once in the superclass. This works, but doing it this way seems weird, since the point of a class method is that it can be called by the class itself, even before instances have been created. Yet the way I've implemented it, it is necessarily tied to being called on an instance. Is this wrong? Is there a better way to do what I'm doing with move? Also, do I need the @classmethod decorator? The book I'm reading says to use it (and @staticmethod), but the following code works without it. Thanks. class ChessPiece: def __init__(self, position, label, has_moved): try: self.position = (position[0], int(position[1])) except TypeError: self.position = position self.label = label self.has_moved = has_moved def move(cls, self): self.has_moved = True class Pawn(ChessPiece): def __init__(self, position=None, label=1, has_moved=False): super().__init__(position, label, has_moved) def move(self): super().move(self) self.position = (chr(ord(self.position[0]) + 1), self.position[1] + 1) From clp2 at rebertia.com Fri Mar 2 01:25:11 2012 From: clp2 at rebertia.com (Chris Rebert) Date: Thu, 1 Mar 2012 22:25:11 -0800 Subject: Is this the proper way to use a class method? In-Reply-To: <4136337.363.1330668021961.JavaMail.geo-discussion-forums@ynjd19> References: <4136337.363.1330668021961.JavaMail.geo-discussion-forums@ynjd19> Message-ID: On Thu, Mar 1, 2012 at 10:00 PM, John Salerno wrote: > This is purely for fun and learning, so I know there are probably better ways of creating a chess program. Right now I'm just curious about my specific question, but I'd love to hear any other advice as well. > > Basically, I'm wondering if I'm using the class method properly with the move method. Unfortunately, no. > The reason I did it this way is because every chess piece will obviously have its own move method, yet they will all need to mark the piece as moved, so I figure that's best written once in the superclass. Right, but why not just a regular instance method? The method in question doesn't operate upon *the class itself* at all (which is the raison d'etre of classmethods); it instead operates upon an instance. A staticmethod would be slightly less weird, but really, it should just be an instance method. > This works, but doing it this way seems weird, since the point of a class method is that it can be called by the class itself, even before instances have been created. Yet the way I've implemented it, it is necessarily tied to being called on an instance. Is this wrong? Is there a better way to do what I'm doing with move? Just make it a normal instance method (i.e. remove the `cls` argument). > Also, do I need the @classmethod decorator? The book I'm reading says to use it (and @staticmethod), but the following code works without it. That's just a coincidence. Your supercall is ought to be: super().move() In contrast, super().move(self) calls the superclass instance method `move` with 2 arguments, both `self`, which just happens to work given your move() method, inside which `cls` isn't actually a class like it ought to be. > class ChessPiece: > > ? ?def __init__(self, position, label, has_moved): > ? ? ? ?try: > ? ? ? ? ? ?self.position = (position[0], int(position[1])) > ? ? ? ?except TypeError: > ? ? ? ? ? ?self.position = position > ? ? ? ?self.label = label > ? ? ? ?self.has_moved = has_moved > > ? ?def move(cls, self): > ? ? ? ?self.has_moved = True > > > class Pawn(ChessPiece): > > ? ?def __init__(self, position=None, label=1, has_moved=False): > ? ? ? ?super().__init__(position, label, has_moved) > > ? ?def move(self): > ? ? ? ?super().move(self) > ? ? ? ?self.position = (chr(ord(self.position[0]) + 1), self.position[1] + 1) Cheers, Chris From rosuav at gmail.com Fri Mar 2 01:41:22 2012 From: rosuav at gmail.com (Chris Angelico) Date: Fri, 2 Mar 2012 17:41:22 +1100 Subject: this afternoon's duck typing exercise ... In-Reply-To: <20120302051547.GA26249@cskk.homeip.net> References: <20120302051547.GA26249@cskk.homeip.net> Message-ID: On Fri, Mar 2, 2012 at 4:15 PM, Cameron Simpson wrote: > Sorry, little technical content here, just a newly hatched programmer: > > ?duck typing, an intro > ?http://www.flickr.com/photos/cskk/6799351990/in/photostream/ > > ?duck typing, resting after the demo > ?http://www.flickr.com/photos/cskk/6945461405/in/photostream/ You may want to keep that away from your friendly local python, it might not survive the integration. Excellent non-technical explanation of a highly technical topic. ChrisA From rosuav at gmail.com Fri Mar 2 02:11:29 2012 From: rosuav at gmail.com (Chris Angelico) Date: Fri, 2 Mar 2012 18:11:29 +1100 Subject: lang comparison: in-place algorithm for reversing a list in Perl,Python, Lisp In-Reply-To: <8e769add-e63c-4a74-bb7e-ddd36c04a415@vs5g2000pbc.googlegroups.com> References: <85fa5760-68c8-41a2-9116-2489165f7ca1@j5g2000yqm.googlegroups.com> <20120229231658.89@kylheku.com> <20120301064937.505@kylheku.com> <8e769add-e63c-4a74-bb7e-ddd36c04a415@vs5g2000pbc.googlegroups.com> Message-ID: On Fri, Mar 2, 2012 at 9:04 AM, Xah Lee wrote: > One easy > way to measure it is whether a programer can read and understand a > program without having to delve into its idiosyncrasies. Neither the behavior of ints nor the behavior of IEEE floating point is a "quirk" or an "idiosyncracy". These are data types with well-defined semantics, and you need to understand them to use them. The fact that dividing two positive integers and producing (or casting to) a third integer rounds the result down is just as much a part of the definition as is two's complement negatives, which most people can safely ignore because they "just work" the way you expect. Learn what you're working with, if you expect to get decent results from it. ChrisA From johnjsal at gmail.com Fri Mar 2 02:16:54 2012 From: johnjsal at gmail.com (John Salerno) Date: Thu, 1 Mar 2012 23:16:54 -0800 (PST) Subject: Is this the proper way to use a class method? In-Reply-To: References: <4136337.363.1330668021961.JavaMail.geo-discussion-forums@ynjd19> Message-ID: <21646224.4.1330672614560.JavaMail.geo-discussion-forums@ynt13> > That's just a coincidence. Your supercall is ought to be: super().move() > In contrast, super().move(self) calls the superclass instance method > `move` with 2 arguments, both `self`, which just happens to work given > your move() method, inside which `cls` isn't actually a class like it > ought to be. Thank you! This is the whole reason I tried using a class method in the first place. I was getting an error that said my move method only takes one argument, but I was passing in two. But if I make the super call as super().move(), how does that work? The move method in the superclass takes an argument, and if I just do super().move(), isn't it the subclass that's getting passed to it? How does the superclass move method know what 'self' is if it doesn't get passed to it as I did originally? From johnjsal at gmail.com Fri Mar 2 02:16:54 2012 From: johnjsal at gmail.com (John Salerno) Date: Thu, 1 Mar 2012 23:16:54 -0800 (PST) Subject: Is this the proper way to use a class method? In-Reply-To: References: <4136337.363.1330668021961.JavaMail.geo-discussion-forums@ynjd19> Message-ID: <21646224.4.1330672614560.JavaMail.geo-discussion-forums@ynt13> > That's just a coincidence. Your supercall is ought to be: super().move() > In contrast, super().move(self) calls the superclass instance method > `move` with 2 arguments, both `self`, which just happens to work given > your move() method, inside which `cls` isn't actually a class like it > ought to be. Thank you! This is the whole reason I tried using a class method in the first place. I was getting an error that said my move method only takes one argument, but I was passing in two. But if I make the super call as super().move(), how does that work? The move method in the superclass takes an argument, and if I just do super().move(), isn't it the subclass that's getting passed to it? How does the superclass move method know what 'self' is if it doesn't get passed to it as I did originally? From w_a_x_man at yahoo.com Fri Mar 2 02:17:34 2012 From: w_a_x_man at yahoo.com (WJ) Date: 2 Mar 2012 07:17:34 GMT Subject: lang comparison: in-place algorithm for reversing a list in Perl, Python, Lisp References: <85fa5760-68c8-41a2-9116-2489165f7ca1@j5g2000yqm.googlegroups.com> Message-ID: Xah Lee wrote: > fun example. > > in-place algorithm for reversing a list in Perl, Python, Lisp > http://xahlee.org/comp/in-place_algorithm.html > > plain text follows > ---------------------------------------- > > What's ?In-place Algorithm?? > > Xah Lee, 2012-02-29 > > This page tells you what's ?In-place algorithm?, using {python, perl, > emacs lisp} code to illustrate. > > Here's Wikipedia In-place algorithm excerpt: > > In computer science, an in-place algorithm (or in Latin in situ) is an > algorithm which transforms input using a data structure with a small, > constant amount of extra storage space. The input is usually > overwritten by the output as the algorithm executes. An algorithm > which is not in-place is sometimes called not-in-place or out-of- > place. > > Python > > Here's a python code for reversing a list. Done by creating a new > list, NOT using in-place: > > # python > # reverse a list > > list_a = ["a", "b", "c", "d", "e", "f", "g"] > > list_length = len(list_a) > list_b = [0] * list_length > > for i in range(list_length): > list_b[i] = list_a[list_length -1 - i] > > print list_b > Here's in-place algorithm for reversing a list: > > # python > # in-place algorithm for reversing a list > > list_a = ["a", "b", "c", "d", "e", "f", "g"] > > list_length = len(list_a) > > for i in range(list_length/2): > x = list_a[i] > list_a[i] = list_a[ list_length -1 - i] > list_a[ list_length -1 - i] = x > > print list_a > Perl > > Here's a perl code for reversing a list. Done by creating a new list, > NOT using in-place: > > # perl > > use strict; > use Data::Dumper; > > my @listA = qw(a b c d e f g); > > my $listLength = scalar @listA; > my @listB = (); > > for ( my $i = 0; $i < $listLength; $i++ ) { > $listB[$i] = $listA[ $listLength - 1 - $i]; > } > > print Dumper(\@listB); > > # perl > # in-place algorithm for reversing a list. > > use strict; > use Data::Dumper; > use POSIX; # for ?floor? > > my @listA = qw(a b c d e f g); > > my $listLength = scalar @listA; > > for ( my $i = 0; $i < floor($listLength/2); $i++ ) { > my $x = $listA[$i]; > $listA[$i] = $listA[ $listLength - 1 - $i]; > $listA[ $listLength - 1 - $i] = $x; > } > > print Dumper(\@listA); > __END__ > > emacs lisp > > ;; emacs lisp > ;; reverse a array > > (setq arrayA ["a" "b" "c" "d" "e" "f" "g"]) > > (setq arrayLength (length arrayA)) > > (setq arrayB (make-vector arrayLength 0)) > > (dotimes (i arrayLength ) > (aset arrayB i (aref arrayA (- (1- arrayLength) i)) ) > ) > > (print (format "%S" arrayB)) > ;; emacs lisp > ;; in-place algorithm for reversing a array > > (setq arrayA ["a" "b" "c" "d" "e" "f" "g"]) > > (setq arrayLength (length arrayA)) > > (dotimes (i (floor (/ arrayLength 2))) > (let (x) > (setq x (aref arrayA i)) > (aset arrayA i (aref arrayA (- (1- arrayLength) i))) > (aset arrayA (- (1- arrayLength) i) x) ) ) > > (print (format "%S" arrayA)) > > Xah NewLisp: > (setq lst '(2 3 5 8)) (2 3 5 8) > (reverse lst) (8 5 3 2) > lst (8 5 3 2) From __peter__ at web.de Fri Mar 2 02:26:13 2012 From: __peter__ at web.de (Peter Otten) Date: Fri, 02 Mar 2012 08:26:13 +0100 Subject: exec References: <4f4f7527$1@news.fhg.de> <4f4f9d55$1@news.fhg.de> Message-ID: Prasad, Ramit wrote: > Hi Peter, > > >>> class Magnitude(object): > > ... def __init__(self, value): > ... self.value = value > ... def __call__(self, uf=1): > ... if uf == 1: > ... return self > ... return self.value > ... > > >>> class Iron(object): > > ... def __init__(self): > ... self.rho = Magnitude(42) > ... > > > Why did you make uf=1 instead of None? > > ... def __call__(self, uf=None): > ... if uf is None: That's a design decision of the OP. I suggested an improvement of the implementation and left the interface alone. From chiron613 at gmail.com Fri Mar 2 02:27:58 2012 From: chiron613 at gmail.com (Chiron) Date: Fri, 02 Mar 2012 07:27:58 GMT Subject: New Science Discovery: Perl Idiots Remain Idiots After A Decade!New Science Discovery: Perl Idiots Remain Idiots After A Decade! References: <0078bbfb-5dfc-48fc-af1a-69de3cf15c3e@b1g2000yqb.googlegroups.com> Message-ID: <2E_3r.4452$HX7.1864@newsfe11.iad> On Wed, 29 Feb 2012 00:09:16 -0800, Xah Lee wrote: Xah, you won't grow even an inch taller by cutting others down. -- I joined scientology at a garage sale!! From ian.g.kelly at gmail.com Fri Mar 2 03:04:22 2012 From: ian.g.kelly at gmail.com (Ian Kelly) Date: Fri, 2 Mar 2012 01:04:22 -0700 Subject: Is this the proper way to use a class method? In-Reply-To: <21646224.4.1330672614560.JavaMail.geo-discussion-forums@ynt13> References: <4136337.363.1330668021961.JavaMail.geo-discussion-forums@ynjd19> <21646224.4.1330672614560.JavaMail.geo-discussion-forums@ynt13> Message-ID: On Fri, Mar 2, 2012 at 12:16 AM, John Salerno wrote: >> That's just a coincidence. Your supercall is ought to be: super().move() >> In contrast, super().move(self) calls the superclass instance method >> `move` with 2 arguments, both `self`, which just happens to work given >> your move() method, inside which `cls` isn't actually a class like it >> ought to be. > > Thank you! This is the whole reason I tried using a class method in the first place. I was getting an error that said my move method only takes one argument, but I was passing in two. > > But if I make the super call as super().move(), how does that work? The move method in the superclass takes an argument, and if I just do super().move(), isn't it the subclass that's getting passed to it? The self that gets passed into the superclass.move() or the subclass.move() is the exact same object in either case. There is no "up-casting" (or any casting at all, for that matter) in Python. > How does the superclass move method know what 'self' is if it doesn't get passed to it as I did originally? super() called without arguments is equivalent to super(, self) -- it collects the value of self from the current stack frame. So self is able to be passed in because the super object implicitly knows what self is. Cheers, Ian From clp2 at rebertia.com Fri Mar 2 03:08:17 2012 From: clp2 at rebertia.com (Chris Rebert) Date: Fri, 2 Mar 2012 00:08:17 -0800 Subject: Is this the proper way to use a class method? In-Reply-To: <21646224.4.1330672614560.JavaMail.geo-discussion-forums@ynt13> References: <4136337.363.1330668021961.JavaMail.geo-discussion-forums@ynjd19> <21646224.4.1330672614560.JavaMail.geo-discussion-forums@ynt13> Message-ID: On Thu, Mar 1, 2012 at 11:16 PM, John Salerno wrote: >> That's just a coincidence. Your supercall is ought to be: super().move() >> In contrast, super().move(self) calls the superclass instance method >> `move` with 2 arguments, both `self`, which just happens to work given >> your move() method, inside which `cls` isn't actually a class like it >> ought to be. > > Thank you! This is the whole reason I tried using a class method in the first place. I was getting an error that said my move method only takes one argument, but I was passing in two. > > But if I make the super call as super().move(), how does that work? The move method in the superclass takes an argument, and if I just do super().move(), isn't it the subclass that's getting passed to it? The instance of the subclass (i.e. what Pawn.move() considers `self`) gets passed to it. > How does the superclass move method know what 'self' is if it doesn't get passed to it as I did originally? Oh, but it does get passed, just implicitly. `super()` basically grabs `self` magically from its caller, and uses it to bind method calls on the magical object returned by `super()`. `super().move()` ends up being, in this particular case, equivalent to: ChessPiece.move(self) which is incidentally how one would write this without using super(). Here is a useful[1] "identity" to ponder: x.y(z) === type(x).y(x, z) Cheers, Chris -- [1]: In the sense of a useful lie[2]; it's far from completely accurate; it (at the least) ignores metaclasses, overridings of __getattribute__(), and a third thing that's difficult to clearly put into words. [2]: http://c2.com/cgi/wiki?UsefulLie [3] [3]: Yes, my footnotes have footnotes. http://rebertia.com From xahlee at gmail.com Fri Mar 2 06:30:29 2012 From: xahlee at gmail.com (Xah Lee) Date: Fri, 2 Mar 2012 03:30:29 -0800 (PST) Subject: lang comparison: in-place algorithm for reversing a list in Perl,Python, Lisp References: <85fa5760-68c8-41a2-9116-2489165f7ca1@j5g2000yqm.googlegroups.com> <20120229231658.89@kylheku.com> <20120301064937.505@kylheku.com> <8e769add-e63c-4a74-bb7e-ddd36c04a415@vs5g2000pbc.googlegroups.com> Message-ID: Xah Lee wrote: ?? One easy way to measure it is whether a programer can read and understand a program without having to delve into its idiosyncrasies. ?? Chris Angelico wrote: ?Neither the behavior of ints nor the behavior of IEEE floating point is a "quirk" or an "idiosyncracy". ?? they are computer engineering by-products. Are quirks and idiosyncracies. Check out a advanced lang such as Mathematica. There, one can learn how the mathematical concept of integer or real number are implemented in a computer language, without lots by-products of comp engineering as in vast majority of langs (all those that chalks up to some IEEEEEEE. (which, sadly, includes C, C++, java, perl, python, lisp, and almost all. (lisp idiots speak of the jargon ?number tower? instead IEEEE.) (part of the reason almost all langs stick to some IEEEEEEEE stuff is because it's kinda standard, and everyone understand it, in the sense that unix RFC (aka really fucking common) is wide-spread because its free yet technically worst. (in a sense, when everybody's stupid, there arise a cost to not be stupid.)))). Xah From xahlee at gmail.com Fri Mar 2 08:12:20 2012 From: xahlee at gmail.com (Xah Lee) Date: Fri, 2 Mar 2012 05:12:20 -0800 (PST) Subject: New Science Discovery: Perl Idiots Remain Idiots After A Decade!New Science Discovery: Perl Idiots Remain Idiots After A Decade! References: <0078bbfb-5dfc-48fc-af1a-69de3cf15c3e@b1g2000yqb.googlegroups.com> <4f4e1554$0$1385$4fafbaef@reader2.news.tin.it> <9dc55d52-3902-4449-87e7-745fb8b911b3@n12g2000yqb.googlegroups.com> <4f4f56c8$0$1381$4fafbaef@reader2.news.tin.it> Message-ID: On Mar 1, 3:00?am, Kiuhnm wrote: > They did not make up the terminology, if that is what you are saying. > The concepts of left and right associativity are well-known and accepted > in TCS (Theoretical CS). > Aho, Sethi and Ullman explain it this way in "Compilers: Principles, > Techniques and Tools": > "We say that the operator + associates to the left because an operand > with plus signs on both sides of it is taken by the operator to its > left. [...]" > And they also show parse trees similar to the ones I wrote above. how do they explain when 2 operators are adjacent e.g. ?3 ? 6 ? 5 ?? do you happen to know some site that shows the relevant page i can have a look? thanks. Xah On Mar 1, 3:00?am, Kiuhnm wrote: > On 3/1/2012 1:02, Xah Lee wrote: > > > i missed a point in my original post. That is, when the same operator > > are adjacent. e.g. ?3 ? 6 ? 5?. > > > This is pointed out by Kiuhnm ?kiuhnm03.4t.yahoo.it? and Tim Bradshaw. > > Thanks. > > > though, i disagree the way they expressed it, or any sense this is > > different from math. > > They did not make up the terminology, if that is what you are saying. > The concepts of left and right associativity are well-known and accepted > in TCS (Theoretical CS). > > If you change the terminology, no one will understand you unless you > provide your definitions every time (and then they may not accept them). > > Another way of saying that an operator is left-associative is that its > parse tree is a left-tree, i.e. a complete tree where each right child > is a leaf. > For instance, (use a monospaced font) > ? ?1 + 2 + 3 + 4 > gives you this left-tree: > ? ? ? ?+ > ? ? ?+ ? 4 > ? ?+ ? 3 > ? 1 2 > while 1**2**3**4 > gives you this right-tree: > ? ?** > 1 ? ?** > ? ? 2 ? ?** > ? ? ? ? 3 ?4 > > Aho, Sethi and Ullman explain it this way in "Compilers: Principles, > Techniques and Tools": > "We say that the operator + associates to the left because an operand > with plus signs on both sides of it is taken by the operator to its > left. [...]" > And they also show parse trees similar to the ones I wrote above. > > Kiuhnm From kiuhnm03.4t.yahoo.it Fri Mar 2 09:15:08 2012 From: kiuhnm03.4t.yahoo.it (Kiuhnm) Date: Fri, 02 Mar 2012 15:15:08 +0100 Subject: New Science Discovery: Perl Idiots Remain Idiots After A Decade!New Science Discovery: Perl Idiots Remain Idiots After A Decade! In-Reply-To: References: <0078bbfb-5dfc-48fc-af1a-69de3cf15c3e@b1g2000yqb.googlegroups.com> <4f4e1554$0$1385$4fafbaef@reader2.news.tin.it> <9dc55d52-3902-4449-87e7-745fb8b911b3@n12g2000yqb.googlegroups.com> <4f4f56c8$0$1381$4fafbaef@reader2.news.tin.it> Message-ID: <4f50d5ea$0$1383$4fafbaef@reader2.news.tin.it> On 3/2/2012 14:12, Xah Lee wrote: > On Mar 1, 3:00 am, Kiuhnm wrote: >> They did not make up the terminology, if that is what you are saying. >> The concepts of left and right associativity are well-known and accepted >> in TCS (Theoretical CS). > > >> Aho, Sethi and Ullman explain it this way in "Compilers: Principles, >> Techniques and Tools": >> "We say that the operator + associates to the left because an operand >> with plus signs on both sides of it is taken by the operator to its >> left. [...]" >> And they also show parse trees similar to the ones I wrote above. > > how do they explain when 2 operators are adjacent e.g. ?3 ? 6 ? 5 ?? The same way you do, I guess. An operand that has operators on both sides is operand of the operator of higher precedence. For instance, in 3 * 4 + 6 4 is operand of * but not of +. Indeed, the operands of + are 3*4 and 6. > do you happen to know some site that shows the relevant page i can > have a look? Nope, sorry. Kiuhnm From chiron613 at gmail.com Fri Mar 2 09:17:18 2012 From: chiron613 at gmail.com (Chiron) Date: Fri, 02 Mar 2012 14:17:18 GMT Subject: New Science Discovery: Perl Idiots Remain Idiots After A Decade!New Science Discovery: Perl Idiots Remain Idiots Af References: <0078bbfb-5dfc-48fc-af1a-69de3cf15c3e@b1g2000yqb.googlegroups.com> <87aa41k6x5.fsf@sapphire.mobileactivedefense.com> <4f4ef6c8$27$fuzhry+tra$mr2ice@news.patriot.net> <4f4f9207$39$fuzhry+tra$mr2ice@news.patriot.net> Message-ID: On Thu, 01 Mar 2012 10:13:11 -0500, Shmuel (Seymour J.) Metz wrote: > In , on 03/01/2012 > at 05:07 AM, Chiron said: > >>Hmm... maybe, instead of just ridiculing him, > > I'm treating him as he treats others. OK. > >>BTW, I happen to agree with you insofar as this poster not understanding >> the nature of mathematics. His comment reminds me of the article, >>"Transgressing the Boundaries: Towards a Transformative Hermeneutics of >>Quantum Gravity" > > A brilliant piece of work. I greatly enjoyed it and the reaction to its > disclosure. What always gets me is how so many people criticized Sokal for doing it, instead of soundly condemning the editor for not bothering to verify what Sokal said. It's like the kid points out that the emperor has no clothes, so they shoot the kid. Of course, in real life, that's exactly what would happen, so I guess I shouldn't be too surprised... -- It is a hard matter, my fellow citizens, to argue with the belly, since it has no ears. -- Marcus Porcius Cato From spamtrap at library.lspace.org.invalid Fri Mar 2 10:53:30 2012 From: spamtrap at library.lspace.org.invalid (Shmuel Metz (Seymour J.)) Date: Fri, 02 Mar 2012 10:53:30 -0500 Subject: New Science Discovery: Perl Detractors Remain Idiots After A Decade! References: <0078bbfb-5dfc-48fc-af1a-69de3cf15c3e@b1g2000yqb.googlegroups.com> <87aa41k6x5.fsf@sapphire.mobileactivedefense.com> <4f4ef6c8$27$fuzhry+tra$mr2ice@news.patriot.net> <4f4f9207$39$fuzhry+tra$mr2ice@news.patriot.net> Message-ID: <4f50ecfa$2$fuzhry+tra$mr2ice@news.patriot.net> In , on 03/02/2012 at 02:17 PM, Chiron said: >What always gets me is how so many people criticized Sokal for doing >it, Google for Omerta. It's common for whistle blowers to be chastised or even persecuted. I agree that the criticism of Prof Sokal was outrageous, but it was also predictable. -- Shmuel (Seymour J.) Metz, SysProg and JOAT Unsolicited bulk E-mail subject to legal action. I reserve the right to publicly post or ridicule any abusive E-mail. Reply to domain Patriot dot net user shmuel+news to contact me. Do not reply to spamtrap at library.lspace.org From mark at markroseman.com Fri Mar 2 12:57:34 2012 From: mark at markroseman.com (Mark Roseman) Date: Fri, 02 Mar 2012 10:57:34 -0700 Subject: Is it necessary to call Tk() when writing a GUI app with Tkinter? References: <27603449.17.1330492001624.JavaMail.geo-discussion-forums@vbbfv2> <6e1c521e-14be-4ec0-9ff0-7f23fd9cd3dc@f14g2000yqe.googlegroups.com> <22943242.772.1330580414345.JavaMail.geo-discussion-forums@ynil17> Message-ID: Rick Johnson wrote: > Book authors and Doc authors are not always the most well informed; as > we have witnessed by this very thread! Obviously these tutorials are more > like: "What NOT to do when coding Tkinter GUIs!" No wonder everyone hates Tkinter. :-) Indeed. One of the things that motivated me to write the tutorial at http://www.tkdocs.com is the rather poor state (in terms of being out of date, incorrect, or demonstrating poor practices) of most Tkinter documentation. Call it self-serving, but I think the Tkinter world would be a happier place if everyone just pointed to TkDocs. ;-) To your point about explicit root, etc. I'll make the general observation that lots of different things work in a given situation, which is just fine for quick little hacky things. If people are doing anything more than a throwaway however, they'd be better served by spending a bit of time learning the conceptual underpinnings (e.g. http://www.tkdocs.com/tutorial/concepts.html) after which the "right" thing to do will be more obvious. Mark From johnjsal at gmail.com Fri Mar 2 13:51:41 2012 From: johnjsal at gmail.com (John Salerno) Date: Fri, 2 Mar 2012 10:51:41 -0800 (PST) Subject: Is this the proper way to use a class method? In-Reply-To: References: <4136337.363.1330668021961.JavaMail.geo-discussion-forums@ynjd19> <21646224.4.1330672614560.JavaMail.geo-discussion-forums@ynt13> Message-ID: <18263375.25.1330714301799.JavaMail.geo-discussion-forums@vbdj6> > Oh, but it does get passed, just implicitly. `super()` basically grabs > `self` magically from its caller, and uses it to bind method calls on > the magical object returned by `super()`. Thanks again, now I understand :) From johnjsal at gmail.com Fri Mar 2 13:51:41 2012 From: johnjsal at gmail.com (John Salerno) Date: Fri, 2 Mar 2012 10:51:41 -0800 (PST) Subject: Is this the proper way to use a class method? In-Reply-To: References: <4136337.363.1330668021961.JavaMail.geo-discussion-forums@ynjd19> <21646224.4.1330672614560.JavaMail.geo-discussion-forums@ynt13> Message-ID: <18263375.25.1330714301799.JavaMail.geo-discussion-forums@vbdj6> > Oh, but it does get passed, just implicitly. `super()` basically grabs > `self` magically from its caller, and uses it to bind method calls on > the magical object returned by `super()`. Thanks again, now I understand :) From spdollyshikha4 at gmail.com Fri Mar 2 13:52:42 2012 From: spdollyshikha4 at gmail.com (shikha panghal) Date: Sat, 3 Mar 2012 00:22:42 +0530 Subject: decompilation Message-ID: Hi Please decoplile the .pyc code ,as i have lost my .py code. Thanks, Shikha -------------- next part -------------- An HTML attachment was scrubbed... URL: -------------- next part -------------- A non-text attachment was scrubbed... Name: hangman322.pyc Type: application/octet-stream Size: 6605 bytes Desc: not available URL: From johnjsal at gmail.com Fri Mar 2 13:53:58 2012 From: johnjsal at gmail.com (John Salerno) Date: Fri, 2 Mar 2012 10:53:58 -0800 (PST) Subject: Is it necessary to call Tk() when writing a GUI app with Tkinter? In-Reply-To: References: <27603449.17.1330492001624.JavaMail.geo-discussion-forums@vbbfv2> <6e1c521e-14be-4ec0-9ff0-7f23fd9cd3dc@f14g2000yqe.googlegroups.com> <22943242.772.1330580414345.JavaMail.geo-discussion-forums@ynil17> Message-ID: <14334956.332.1330714438657.JavaMail.geo-discussion-forums@vbux23> > Indeed. One of the things that motivated me to write the tutorial at > http://www.tkdocs.com is the rather poor state (in terms of being out of > date, incorrect, or demonstrating poor practices) of most Tkinter > documentation. > > Call it self-serving, but I think the Tkinter world would be a happier > place if everyone just pointed to TkDocs. ;-) > > To your point about explicit root, etc. I'll make the general > observation that lots of different things work in a given situation, > which is just fine for quick little hacky things. If people are doing > anything more than a throwaway however, they'd be better served by > spending a bit of time learning the conceptual underpinnings (e.g. > http://www.tkdocs.com/tutorial/concepts.html) after which the "right" > thing to do will be more obvious. > > Mark Nice. I shall be spending some time at your website. I actually like wxPython, but I decided to learn a little Tkinter because it's already included and would be an easier and quicker option for small interfaces. From chiron613 at gmail.com Fri Mar 2 14:06:06 2012 From: chiron613 at gmail.com (Chiron) Date: Fri, 02 Mar 2012 19:06:06 GMT Subject: New Science Discovery: Perl Detractors Remain Idiots After A Decade! References: <0078bbfb-5dfc-48fc-af1a-69de3cf15c3e@b1g2000yqb.googlegroups.com> <87aa41k6x5.fsf@sapphire.mobileactivedefense.com> <4f4ef6c8$27$fuzhry+tra$mr2ice@news.patriot.net> <4f4f9207$39$fuzhry+tra$mr2ice@news.patriot.net> <4f50ecfa$2$fuzhry+tra$mr2ice@news.patriot.net> Message-ID: On Fri, 02 Mar 2012 10:53:30 -0500, Shmuel (Seymour J.) Metz wrote: > In , on 03/02/2012 > at 02:17 PM, Chiron said: > >>What always gets me is how so many people criticized Sokal for doing it, > > Google for Omerta. It's common for whistle blowers to be chastised or > even persecuted. I agree that the criticism of Prof Sokal was > outrageous, but it was also predictable. Yeah, omerta... I'm familiar with it. Talk and you're dead, and they put a canary in your mouth (well, some folks do, anyway). But of course you're right - it's a milder form of omerta. It's just so misguided. Kill the messenger. Imprison the whistle-blower. -- Imitation is the sincerest form of plagiarism. From scavanau at cisco.com Fri Mar 2 15:09:16 2012 From: scavanau at cisco.com (Sean Cavanaugh (scavanau)) Date: Fri, 2 Mar 2012 12:09:16 -0800 Subject: Python - CGI-BIN - Apache Timeout Problem Message-ID: <6FC169072CBFF3409B6E74F50175A4650497A3F9@xmb-sjc-215.amer.cisco.com> Hello List, Would appreciate some insight/help, ran out of ideas... BRIEF OVERVIEW: I am trying to create a simple webserver gui wrapper for a set of scripts I developed to test some of our firewalls here at Cisco. Being that the total amount of engineer that will ever probably use this is 4 people and my limited python experience I just decided to do a quick cgi-bin solution. I control the machine with the webserver on em0 where I do my fw testing on em1/em2. Browser goes to http://webserver/main.py -> main.py executes a script->tests.py ->test.py imports my engine v6tester_main.py which is a series of functions I wrote. tests.py kicks of whatever test main.py wanted. THE PROBLEM: When I execute the scripts from the command line (#python main.py) it generates it fine (albeit slowly), it prints all the html code out including the script. The 'core' part of the script dumbed down to the lowest level is-> proc = subprocess.Popen(['/usr/local/bin/python', 'tests.py'], stdout=subprocess.PIPE) output = proc.stdout.read() print output proc.stdout.close() When I open main.py and execute the script it just hangs... it seems to execute the script (I see pcap fires on the interface that I am testing on the firewall) but its not executing correctly... or loading the entire webpage...the webpage keeps chugging along and eventually gives me an error timeout. I know it's not a permissions issue or setup issue b/c I did a proof of concept where I just fired one simple pcap and it works fine (reported back just like it would if I ran it on the command line).. it has something to do with either the amount of prints out the script is doing, or the timing. I see no problems except the timeout (nothing in logs: /var/log/http-error.log). My script takes about 8 secounds to run. It does use threading but I wouldn't think that would mess it up. BTW: I posted here if this helps anyone: http://stackoverflow.com/questions/9524758/cgi-bin-timing-timeout-on-fre ebsd-apache22 Thanks in advance for any ideas. I can include the whole main.py if that would help. ============================ Sean Cavanaugh Cisco Systems -------------- next part -------------- An HTML attachment was scrubbed... URL: From clp2 at rebertia.com Fri Mar 2 15:11:12 2012 From: clp2 at rebertia.com (Chris Rebert) Date: Fri, 2 Mar 2012 12:11:12 -0800 Subject: decompilation In-Reply-To: References: Message-ID: On Fri, Mar 2, 2012 at 10:52 AM, shikha panghal wrote: > Hi > > Please decoplile the .pyc code ,as i have lost my .py code. Your best shot would be: http://www.crazy-compilers.com/decompyle/ Cheers, Chris From arnodel at gmail.com Fri Mar 2 15:18:56 2012 From: arnodel at gmail.com (Arnaud Delobelle) Date: Fri, 2 Mar 2012 20:18:56 +0000 Subject: decompilation In-Reply-To: References: Message-ID: On 2 March 2012 18:52, shikha panghal wrote: > Hi > > Please decoplile the .pyc code ,as i have lost my .py code. Aha, a customer! I've written a module for this: unpyc3 (http://code.google.com/p/unpyc3/) Here it is in action: Python 3.2.1 (v3.2.1:ac1f7e5c0510, Jul 9 2011, 01:03:53) [GCC 4.2.1 (Apple Inc. build 5666) (dot 3)] on darwin Type "help", "copyright", "credits" or "license" for more information. >>> import unpyc3 >>> import hangman322 >>> code = unpyc3.decompile(hangman322) >>> print(code) import random def readFile(fileName): file = open(fileName) lineList = file.readlines() file.close() return lineList def initialize(fileName): try: lineList = readFile(fileName) except: print('Oops! ' + filename + ' was not a valid file.') return len_d = len(lineList) word_length = [0]*len_d for i in range(len_d): if lineList[i][-1] == '\n': word_length[i] = len(lineList[i]) - 1 else: word_length[i] = len(lineList[i]) tabulate = [0]*25 for i in range(len_d): if word_length[i] >= 24: tabulate[24] = tabulate[24] + 1 else: tabulate[word_length[i]] = tabulate[word_length[i]] + 1 words = [None]*25 for i in range(2, 24): words[i] = [None]*tabulate[i] k = 0 for j in range(len_d): if word_length[j] == i: words[i][k] = lineList[j] k = k + 1 for i in range(24, 25): words[i] = [None]*tabulate[i] k = 0 for j in range(len_d): if word_length[j] >= i: words[i][k] = lineList[j] k = k + 1 return words def wordsOfLength(n, source_file): words = initialize(source_file) return words[n] def getUserStringInput(L, prompt): replyInList = False while not replyInList: reply = input(prompt) replyInList = reply in L if not replyInList: print('That reply is invalid. Try again.') return reply def intListToStringList(L): L2 = ['']*len(L) for i in range(len(L)): L2[i] = str(L[i]) return L2 def getNewLetterGuess(availableLetters): letterString = '' for j in range(26): if availableLetters[j]: letterString = letterString + chr(65 + j) + ' ' else: letterString = letterString + ' ' validChar = False print(letterString) while not validChar: reply = input('Guess! > ') if len(reply) == 1: validChar = True letterIndex = ord(reply) - 65 if letterIndex > 25: letterIndex = letterIndex - 32 while letterIndex > 25 or not availableLetters[letterIndex]: print('This is an invalid choice. Please try again!') validChar = False print(letterString) while not validChar: reply = input('Guess! > ') if len(reply) == 1: validChar = True letterIndex = ord(reply) - 65 if letterIndex > 25: letterIndex = letterIndex - 32 guess = chr(97 + letterIndex) availableLetters[letterIndex] = False return guess, availableLetters def getWordFamilyCounter(L, n, guess): wordFamilyCounter = [0]*2**n familyIndexList = [-1]*len(L) for k in range(len(L)): w = list(L[k]) ct = 0 for k2 in range(n): if w[k2] == guess: ct = ct + 2**k2 familyIndexList[k] = ct wordFamilyCounter[ct] = wordFamilyCounter[ct] + 1 return wordFamilyCounter, familyIndexList def extractLargestFamily(L, familyIndexList, wordFamilyCounter): bestFamily = wordFamilyCounter.index(max(wordFamilyCounter)) boolist = [False]*len(L) for k3 in range(len(L)): if familyIndexList[k3] == bestFamily: boolist[k3] = True j2 = 0 smallList = [' ']*sum(boolist) for k4 in range(len(L)): if boolist[k4]: smallList[j2] = L[k4] j2 = j2 + 1 return smallList def updatePatternList(patternList, guess, bestFamily): n = len(patternList) for k6 in range(n): if bestFamily//2 == bestFamily/2: pass else: patternList[k6] = guess + ' ' bestFamily = bestFamily >> 1 return patternList def pickWordFrom(L): index = random.randint(0, len(L) - 1) return L[index] def play(): reply = getUserStringInput(intListToStringList(list(range(2, 21))), 'How long should I make your word?!!? (2 to 20) > ') n = int(reply) patternList = ['_ ']*n print(''.join(patternList)) L = wordsOfLength(n, 'dictionary.txt') reply = getUserStringInput(intListToStringList(list(range(1, 27))), 'How many guesses will you need? > ') m = int(reply) availableLetters = [True]*26 for i in range(m): guess, availableLetters = getNewLetterGuess(availableLetters) wordFamilyCounter, familyIndexList = getWordFamilyCounter(L, n, guess) bestFamily = wordFamilyCounter.index(max(wordFamilyCounter)) if bestFamily == 0: print('Letter not in word.') else: print('Letter is in word!!!') L = extractLargestFamily(L, familyIndexList, wordFamilyCounter) patternList = updatePatternList(patternList, guess, bestFamily) print(''.join(patternList)) if '_ ' not in patternList: break if '_ ' not in patternList: print('SURELY you must be CHEATING, but you guessed my word in ' + str(i + 1) + ' tries!!!') else: bogusWord = pickWordFrom(L) print('You lose. The word was: ' + bogusWord) >>> I haven't actually checked if this code runs :) -- Arnaud From tjreedy at udel.edu Fri Mar 2 15:19:31 2012 From: tjreedy at udel.edu (Terry Reedy) Date: Fri, 02 Mar 2012 15:19:31 -0500 Subject: Is it necessary to call Tk() when writing a GUI app with Tkinter? In-Reply-To: References: <27603449.17.1330492001624.JavaMail.geo-discussion-forums@vbbfv2> <6e1c521e-14be-4ec0-9ff0-7f23fd9cd3dc@f14g2000yqe.googlegroups.com> <3d0bf288-fa5d-48e5-9529-db92d420a915@1g2000yqv.googlegroups.com> Message-ID: On 3/1/2012 10:43 PM, Terry Reedy wrote: >> Not sure what is happening on your end, but i don't see any braces. > > Are you saying that if you change "Hello_World\n(click_me)" to > "Hello World\n(click me)", you see > > Hello World > (click me) > > as I expected, instead of > > {Hellow World > (click me)} > > as I do see? What OS are you running? And what tk version? (I have 8.5.9 > in Win7) The problem was another subtle bug in the current example": self.hi_there["text"] = "Hello", The spurious comma at the end makes the value of the 'text' attribute a one-elememt tuple and not just a string. I presume tcl-based tk handles that in the manner appropriate for the tcl equivalent. I believe tcl uses spaces rather than commas to separate items, so the braces serve as 'quotes' to indicate that the contents are one item, not three. Removing the comma solves the problem. -- Terry Jan Reedy From clp2 at rebertia.com Fri Mar 2 15:22:41 2012 From: clp2 at rebertia.com (Chris Rebert) Date: Fri, 2 Mar 2012 12:22:41 -0800 Subject: Python - CGI-BIN - Apache Timeout Problem In-Reply-To: <6FC169072CBFF3409B6E74F50175A4650497A3F9@xmb-sjc-215.amer.cisco.com> References: <6FC169072CBFF3409B6E74F50175A4650497A3F9@xmb-sjc-215.amer.cisco.com> Message-ID: On Fri, Mar 2, 2012 at 12:09 PM, Sean Cavanaugh (scavanau) wrote: > THE PROBLEM: > > When I execute the scripts from the command line (#python main.py) it > generates it fine (albeit slowly), it prints all the html code out including > the script.? The ?core? part of the script dumbed down to the lowest level > is-> > > ??????? proc = subprocess.Popen(['/usr/local/bin/python', 'tests.py'], > stdout=subprocess.PIPE) > ??????? output = proc.stdout.read() Note the red warning box about possible deadlock with .stdout.read() and friends: http://docs.python.org/library/subprocess.html#popen-objects > ??????? print output > ??????? proc.stdout.close() As the docs advise, try using .communicate() [http://docs.python.org/library/subprocess.html#subprocess.Popen.communicate ] instead: proc = subprocess.Popen(?) out, err = proc.communicate() print out > When I open main.py and execute the script it just hangs? it seems to > execute the script (I see pcap fires on the interface that I am testing on > the firewall) but its not executing correctly? or loading the entire > webpage?the webpage keeps chugging along and eventually gives me an error > timeout. The hanging makes me suspect that the aforementioned deadlock is occurring. Cheers, Chris -- http://chrisrebert.com From mwilson at the-wire.com Fri Mar 2 15:52:24 2012 From: mwilson at the-wire.com (Mel Wilson) Date: Fri, 02 Mar 2012 15:52:24 -0500 Subject: Is it necessary to call Tk() when writing a GUI app with Tkinter? References: <27603449.17.1330492001624.JavaMail.geo-discussion-forums@vbbfv2> <6e1c521e-14be-4ec0-9ff0-7f23fd9cd3dc@f14g2000yqe.googlegroups.com> <3d0bf288-fa5d-48e5-9529-db92d420a915@1g2000yqv.googlegroups.com> Message-ID: Terry Reedy wrote: > The problem was another subtle bug in the current example": > self.hi_there["text"] = "Hello", > > The spurious comma at the end makes the value of the 'text' attribute a > one-elememt tuple and not just a string. I presume tcl-based tk handles > that in the manner appropriate for the tcl equivalent. I believe tcl > uses spaces rather than commas to separate items, so the braces serve as > 'quotes' to indicate that the contents are one item, not three. Removing > the comma solves the problem. That looks like it. Tcl is the 'LISP of strings' Composite-object things like indexing work on space-separated strings. Mel. From scavanau at cisco.com Fri Mar 2 16:05:29 2012 From: scavanau at cisco.com (Sean Cavanaugh (scavanau)) Date: Fri, 2 Mar 2012 13:05:29 -0800 Subject: Python - CGI-BIN - Apache Timeout Problem In-Reply-To: References: <6FC169072CBFF3409B6E74F50175A4650497A3F9@xmb-sjc-215.amer.cisco.com> Message-ID: <6FC169072CBFF3409B6E74F50175A4650497A426@xmb-sjc-215.amer.cisco.com> Hey Chris, Thanks for your quick reply! I switched my code to-> proc = subprocess.Popen(['/usr/local/bin/python', 'tests.py'], stdout=subprocess.PIPE) out, err = proc.communicate() print out proc.stdout.close() It still dead locked. Interestingly enough When I did a #python tests.py on the command line even that was taking awhile to print out to the command line so I decided to restart my webserver... wow from mucking before something must have been running in the background still. I got the script down to 2 seconds or so... Now it still works but faster when I do #python main.py it generates all the text to the command line but the website still hangs when I go to http://webserver/main.py... I am not sure what is going wrong... no error in the /var/log except for the eventual timeout after a couple minutes goes by. -S -----Original Message----- From: chris at rebertia.com [mailto:chris at rebertia.com] On Behalf Of Chris Rebert Sent: Friday, March 02, 2012 3:23 PM To: Sean Cavanaugh (scavanau) Cc: python-list at python.org Subject: Re: Python - CGI-BIN - Apache Timeout Problem On Fri, Mar 2, 2012 at 12:09 PM, Sean Cavanaugh (scavanau) wrote: > THE PROBLEM: > > When I execute the scripts from the command line (#python main.py) it > generates it fine (albeit slowly), it prints all the html code out including > the script.? The ?core? part of the script dumbed down to the lowest level > is-> > > ??????? proc = subprocess.Popen(['/usr/local/bin/python', 'tests.py'], > stdout=subprocess.PIPE) > ??????? output = proc.stdout.read() Note the red warning box about possible deadlock with .stdout.read() and friends: http://docs.python.org/library/subprocess.html#popen-objects > ??????? print output > ??????? proc.stdout.close() As the docs advise, try using .communicate() [http://docs.python.org/library/subprocess.html#subprocess.Popen.communicate ] instead: proc = subprocess.Popen(?) out, err = proc.communicate() print out > When I open main.py and execute the script it just hangs? it seems to > execute the script (I see pcap fires on the interface that I am testing on > the firewall) but its not executing correctly? or loading the entire > webpage?the webpage keeps chugging along and eventually gives me an error > timeout. The hanging makes me suspect that the aforementioned deadlock is occurring. Cheers, Chris -- http://chrisrebert.com From scavanau at cisco.com Fri Mar 2 16:43:11 2012 From: scavanau at cisco.com (Sean Cavanaugh (scavanau)) Date: Fri, 2 Mar 2012 13:43:11 -0800 Subject: Python - CGI-BIN - Apache Timeout Problem In-Reply-To: References: <6FC169072CBFF3409B6E74F50175A4650497A3F9@xmb-sjc-215.amer.cisco.com> Message-ID: <6FC169072CBFF3409B6E74F50175A4650497A445@xmb-sjc-215.amer.cisco.com> Hey All, So maybe this part is important (after doing some troubleshooting) hopefully not everyone has beers in hand already since its Friday :-) The way the code works if you want to send through the firewall (i.e. SERVER->FIREWALL->SERVER) I split the process into two threads. One is listening on the egress, then I send on the ingress. The main waits until the thread finishes (it times out after 2 seconds). I had to do this b/c scapy (the library I used) won't let me send pcaps while I receive them. This lets me see packets on both sides (i.e. did that sort of internet traffic go through the firewall). The reason I think this could be a problem is when I ran a test where I sent to the firewall (rather than through it) and my program does not need to thread the webserver works fine...... Suggestions anyone? -S -----Original Message----- From: chris at rebertia.com [mailto:chris at rebertia.com] On Behalf Of Chris Rebert Sent: Friday, March 02, 2012 3:23 PM To: Sean Cavanaugh (scavanau) Cc: python-list at python.org Subject: Re: Python - CGI-BIN - Apache Timeout Problem On Fri, Mar 2, 2012 at 12:09 PM, Sean Cavanaugh (scavanau) wrote: > THE PROBLEM: > > When I execute the scripts from the command line (#python main.py) it > generates it fine (albeit slowly), it prints all the html code out including > the script.? The ?core? part of the script dumbed down to the lowest level > is-> > > ??????? proc = subprocess.Popen(['/usr/local/bin/python', 'tests.py'], > stdout=subprocess.PIPE) > ??????? output = proc.stdout.read() Note the red warning box about possible deadlock with .stdout.read() and friends: http://docs.python.org/library/subprocess.html#popen-objects > ??????? print output > ??????? proc.stdout.close() As the docs advise, try using .communicate() [http://docs.python.org/library/subprocess.html#subprocess.Popen.communicate ] instead: proc = subprocess.Popen(?) out, err = proc.communicate() print out > When I open main.py and execute the script it just hangs? it seems to > execute the script (I see pcap fires on the interface that I am testing on > the firewall) but its not executing correctly? or loading the entire > webpage?the webpage keeps chugging along and eventually gives me an error > timeout. The hanging makes me suspect that the aforementioned deadlock is occurring. Cheers, Chris -- http://chrisrebert.com From kliateni at gmail.com Fri Mar 2 16:57:12 2012 From: kliateni at gmail.com (Karim) Date: Fri, 02 Mar 2012 22:57:12 +0100 Subject: decompilation In-Reply-To: References: Message-ID: <4F514238.9060900@gmail.com> Le 02/03/2012 21:18, Arnaud Delobelle a ?crit : > On 2 March 2012 18:52, shikha panghal wrote: >> Hi >> >> Please decoplile the .pyc code ,as i have lost my .py code. > Aha, a customer! I've written a module for this: unpyc3 > (http://code.google.com/p/unpyc3/) > > Here it is in action: > > > Python 3.2.1 (v3.2.1:ac1f7e5c0510, Jul 9 2011, 01:03:53) > [GCC 4.2.1 (Apple Inc. build 5666) (dot 3)] on darwin > Type "help", "copyright", "credits" or "license" for more information. >>>> import unpyc3 >>>> import hangman322 >>>> code = unpyc3.decompile(hangman322) >>>> print(code) > import random > > def readFile(fileName): > file = open(fileName) > lineList = file.readlines() > file.close() > return lineList > > def initialize(fileName): > try: > lineList = readFile(fileName) > except: > print('Oops! ' + filename + ' was not a valid file.') > return > len_d = len(lineList) > word_length = [0]*len_d > for i in range(len_d): > if lineList[i][-1] == '\n': > word_length[i] = len(lineList[i]) - 1 > else: > word_length[i] = len(lineList[i]) > tabulate = [0]*25 > for i in range(len_d): > if word_length[i]>= 24: > tabulate[24] = tabulate[24] + 1 > else: > tabulate[word_length[i]] = tabulate[word_length[i]] + 1 > words = [None]*25 > for i in range(2, 24): > words[i] = [None]*tabulate[i] > k = 0 > for j in range(len_d): > if word_length[j] == i: > words[i][k] = lineList[j] > k = k + 1 > for i in range(24, 25): > words[i] = [None]*tabulate[i] > k = 0 > for j in range(len_d): > if word_length[j]>= i: > words[i][k] = lineList[j] > k = k + 1 > return words > > def wordsOfLength(n, source_file): > words = initialize(source_file) > return words[n] > > def getUserStringInput(L, prompt): > replyInList = False > while not replyInList: > reply = input(prompt) > replyInList = reply in L > if not replyInList: > print('That reply is invalid. Try again.') > return reply > > def intListToStringList(L): > L2 = ['']*len(L) > for i in range(len(L)): > L2[i] = str(L[i]) > return L2 > > def getNewLetterGuess(availableLetters): > letterString = '' > for j in range(26): > if availableLetters[j]: > letterString = letterString + chr(65 + j) + ' ' > else: > letterString = letterString + ' ' > validChar = False > print(letterString) > while not validChar: > reply = input('Guess!> ') > if len(reply) == 1: > validChar = True > letterIndex = ord(reply) - 65 > if letterIndex> 25: > letterIndex = letterIndex - 32 > while letterIndex> 25 or not availableLetters[letterIndex]: > print('This is an invalid choice. Please try again!') > validChar = False > print(letterString) > while not validChar: > reply = input('Guess!> ') > if len(reply) == 1: > validChar = True > letterIndex = ord(reply) - 65 > if letterIndex> 25: > letterIndex = letterIndex - 32 > guess = chr(97 + letterIndex) > availableLetters[letterIndex] = False > return guess, availableLetters > > def getWordFamilyCounter(L, n, guess): > wordFamilyCounter = [0]*2**n > familyIndexList = [-1]*len(L) > for k in range(len(L)): > w = list(L[k]) > ct = 0 > for k2 in range(n): > if w[k2] == guess: > ct = ct + 2**k2 > familyIndexList[k] = ct > wordFamilyCounter[ct] = wordFamilyCounter[ct] + 1 > return wordFamilyCounter, familyIndexList > > def extractLargestFamily(L, familyIndexList, wordFamilyCounter): > bestFamily = wordFamilyCounter.index(max(wordFamilyCounter)) > boolist = [False]*len(L) > for k3 in range(len(L)): > if familyIndexList[k3] == bestFamily: > boolist[k3] = True > j2 = 0 > smallList = [' ']*sum(boolist) > for k4 in range(len(L)): > if boolist[k4]: > smallList[j2] = L[k4] > j2 = j2 + 1 > return smallList > > def updatePatternList(patternList, guess, bestFamily): > n = len(patternList) > for k6 in range(n): > if bestFamily//2 == bestFamily/2: > pass > else: > patternList[k6] = guess + ' ' > bestFamily = bestFamily>> 1 > return patternList > > def pickWordFrom(L): > index = random.randint(0, len(L) - 1) > return L[index] > > def play(): > reply = getUserStringInput(intListToStringList(list(range(2, > 21))), 'How long should I make your word?!!? (2 to 20)> ') > n = int(reply) > patternList = ['_ ']*n > print(''.join(patternList)) > L = wordsOfLength(n, 'dictionary.txt') > reply = getUserStringInput(intListToStringList(list(range(1, > 27))), 'How many guesses will you need?> ') > m = int(reply) > availableLetters = [True]*26 > for i in range(m): > guess, availableLetters = getNewLetterGuess(availableLetters) > wordFamilyCounter, familyIndexList = getWordFamilyCounter(L, n, guess) > bestFamily = wordFamilyCounter.index(max(wordFamilyCounter)) > if bestFamily == 0: > print('Letter not in word.') > else: > print('Letter is in word!!!') > L = extractLargestFamily(L, familyIndexList, wordFamilyCounter) > patternList = updatePatternList(patternList, guess, bestFamily) > print(''.join(patternList)) > if '_ ' not in patternList: > break > if '_ ' not in patternList: > print('SURELY you must be CHEATING, but you guessed my word in > ' + str(i + 1) + ' tries!!!') > else: > bogusWord = pickWordFrom(L) > print('You lose. The word was: ' + bogusWord) > > I haven't actually checked if this code runs :) > Great code (unpy3) Arnaud! pretty well built. Cheers Karim From johnjsal at gmail.com Fri Mar 2 17:16:46 2012 From: johnjsal at gmail.com (John Salerno) Date: Fri, 2 Mar 2012 14:16:46 -0800 (PST) Subject: Is it necessary to call Tk() when writing a GUI app with Tkinter? In-Reply-To: References: <27603449.17.1330492001624.JavaMail.geo-discussion-forums@vbbfv2> <6e1c521e-14be-4ec0-9ff0-7f23fd9cd3dc@f14g2000yqe.googlegroups.com> <17153317.324.1330576905540.JavaMail.geo-discussion-forums@yncd8> Message-ID: <11188032.247.1330726606861.JavaMail.geo-discussion-forums@ynbq18> > After that, you can nest as > many frames, toplevels, and blah widgets under that root window as you > so desire. Actually you don't even need a "frame", you can pack > widgets directly into a Toplevel or Tk widget. This is interesting. I completely understand your point about always calling (and using) the instance of Tk as the root. Given that, what is the point of creating a Frame object at all? I tried NOT doing it, like you said, and it seemed to work fine with my simple example. But is there a benefit to using a Frame object to group the widgets together? Or is it cleaner to just use the Tk object? From jbeard565 at gmail.com Fri Mar 2 17:46:13 2012 From: jbeard565 at gmail.com (Jeff Beardsley) Date: Fri, 2 Mar 2012 14:46:13 -0800 (PST) Subject: A possible change to decimal.Decimal? Message-ID: <15610330.329.1330728373676.JavaMail.geo-discussion-forums@ynlw24> HISTORY: In using python 2.7.2 for awhile on a web project (apache/wsgi web.py), I discovered a problem in using decimal.Decimal. A short search revealed that many other people have been having the problem as well, in their own apache/wsgi implementations (django, mostly), but I found no real solutions among the posts I read. So I did some experimentation of my own. The following code will break unexpectedly on standard python2.7 (and earlier) because of the way that isinstance fails after reload() (which is called by both of the above web frameworks). This is the error: TypeError("Cannot convert %r to Decimal" % value) THE TEST CODE import decimal from decimal import Decimal #this works Decimal(Decimal()) reload(decimal) #this fails before patching, but works fine afterwards Decimal(Decimal()) THE SOLUTION: So, looking into decimal.py I discovered lots if statements using isinstance, and have slightly rearranged the code inside __new__() to mostly remove their use, and for my purposes totally fixes the problem within wsgi. I am not an official python dev, so would appreciate it if someone who *IS* could just look this over, improve it if necessary, and get it (or some variation) submitted into the library. Below is a patch for use against python-2.7.2 PATCH: *** decimal.py 2012-03-02 16:42:51.285964007 -0600 --- /usr/lib/python2.7/decimal.py 2012-03-02 14:36:01.238976461 -0600 *************** *** 535,608 **** # and the Decimal constructor still deal with tuples of # digits. self = object.__new__(cls) ! # From a string ! # REs insist on real strings, so we can too. ! if isinstance(value, basestring): ! m = _parser(value.strip()) ! if m is None: ! if context is None: ! context = getcontext() ! return context._raise_error(ConversionSyntax, ! "Invalid literal for Decimal: %r" % value) ! ! if m.group('sign') == "-": ! self._sign = 1 ! else: ! self._sign = 0 ! intpart = m.group('int') ! if intpart is not None: ! # finite number ! fracpart = m.group('frac') or '' ! exp = int(m.group('exp') or '0') ! self._int = str(int(intpart+fracpart)) ! self._exp = exp - len(fracpart) ! self._is_special = False ! else: ! diag = m.group('diag') ! if diag is not None: ! # NaN ! self._int = str(int(diag or '0')).lstrip('0') ! if m.group('signal'): ! self._exp = 'N' ! else: ! self._exp = 'n' ! else: ! # infinity ! self._int = '0' ! self._exp = 'F' ! self._is_special = True ! return self ! ! # From an integer ! if isinstance(value, (int,long)): ! if value >= 0: ! self._sign = 0 ! else: ! self._sign = 1 ! self._exp = 0 ! self._int = str(abs(value)) ! self._is_special = False return self ! # From another decimal ! if isinstance(value, Decimal): self._exp = value._exp self._sign = value._sign self._int = value._int self._is_special = value._is_special return self # From an internal working value ! if isinstance(value, _WorkRep): self._sign = value.sign self._int = str(value.int) self._exp = int(value.exp) self._is_special = False return self # tuple/list conversion (possibly from as_tuple()) if isinstance(value, (list,tuple)): if len(value) != 3: raise ValueError('Invalid tuple size in creation of Decimal ' --- 535,582 ---- # and the Decimal constructor still deal with tuples of # digits. self = object.__new__(cls) ! # Note about isinstance -- Decimal has been a victim of the ! # isinstance builtin failing after module reload in some ! # environments (e.g. web.py, django) under apache/wsgi, which ! # I determined to be the reason Decimal was causing so many ! # problems in my web deployment. I have re-organized the ! # following code to remove use of isinstance except on ! # native types (int, long, float, list, tuple), since those ! # seem not to break in this regard. -- jdb ! ! # First, assume it's another Decimal or similar(having _exp, ! # _sign, _int and _is_special. Obviously, having these ! # implies it's at least an attempt to represent Decimal ! try: ! self._exp = value._exp ! self._sign = value._sign ! self._int = value._int ! self._is_special = value._is_special return self + except: pass ! # Or it's a float ! try: ! value = Decimal.from_float(value) self._exp = value._exp self._sign = value._sign self._int = value._int self._is_special = value._is_special return self + except: pass # From an internal working value ! try: self._sign = value.sign self._int = str(value.int) self._exp = int(value.exp) self._is_special = False return self + except: pass # tuple/list conversion (possibly from as_tuple()) if isinstance(value, (list,tuple)): if len(value) != 3: raise ValueError('Invalid tuple size in creation of Decimal ' *************** *** 645,661 **** raise ValueError("The third value in the tuple must " "be an integer, or one of the " "strings 'F', 'n', 'N'.") return self ! if isinstance(value, float): ! value = Decimal.from_float(value) ! self._exp = value._exp ! self._sign = value._sign ! self._int = value._int ! self._is_special = value._is_special return self raise TypeError("Cannot convert %r to Decimal" % value) # @classmethod, but @decorator is not valid Python 2.3 syntax, so # don't use it (see notes on Py2.3 compatibility at top of file) --- 619,666 ---- raise ValueError("The third value in the tuple must " "be an integer, or one of the " "strings 'F', 'n', 'N'.") return self ! # From a string, or anything representable as a string ! try: ! value = str(value) ! m = _parser(value.strip()) ! if m is None: ! if context is None: ! context = getcontext() ! return context._raise_error(ConversionSyntax, ! "Invalid literal for Decimal: %r" % value) ! ! if m.group('sign') == "-": ! self._sign = 1 ! else: ! self._sign = 0 ! intpart = m.group('int') ! if intpart is not None: ! # finite number ! fracpart = m.group('frac') or '' ! exp = int(m.group('exp') or '0') ! self._int = str(int(intpart+fracpart)) ! self._exp = exp - len(fracpart) ! self._is_special = False ! else: ! diag = m.group('diag') ! if diag is not None: ! # NaN ! self._int = str(int(diag or '0')).lstrip('0') ! if m.group('signal'): ! self._exp = 'N' ! else: ! self._exp = 'n' ! else: ! # infinity ! self._int = '0' ! self._exp = 'F' ! self._is_special = True return self + except: pass raise TypeError("Cannot convert %r to Decimal" % value) # @classmethod, but @decorator is not valid Python 2.3 syntax, so # don't use it (see notes on Py2.3 compatibility at top of file) From ethan at stoneleaf.us Fri Mar 2 18:49:39 2012 From: ethan at stoneleaf.us (Ethan Furman) Date: Fri, 02 Mar 2012 15:49:39 -0800 Subject: A possible change to decimal.Decimal? In-Reply-To: <15610330.329.1330728373676.JavaMail.geo-discussion-forums@ynlw24> References: <15610330.329.1330728373676.JavaMail.geo-discussion-forums@ynlw24> Message-ID: <4F515C93.6080201@stoneleaf.us> Jeff Beardsley wrote: > HISTORY: > > In using python 2.7.2 for awhile on a web project (apache/wsgi web.py), I discovered a problem in using decimal.Decimal. A short search revealed that many other people have been having the problem as well, in their own apache/wsgi implementations (django, mostly), but I found no real solutions among the posts I read. So I did some experimentation of my own. > > The following code will break unexpectedly on standard python2.7 (and earlier) because of the way that isinstance fails after reload() (which is called by both of the above web frameworks). > > This is the error: TypeError("Cannot convert %r to Decimal" % value) > > THE TEST CODE > > import decimal > from decimal import Decimal > > #this works > Decimal(Decimal()) > > reload(decimal) > > #this fails before patching, but works fine afterwards > Decimal(Decimal()) > Patching decimal.py to make it work with reload() is probably not going to happen. What you should be doing is: import decimal from decimal import Decimal reload(decimal) Decimal = decimal.Decimal # (rebind 'Decimal' to the reloaded code) ~Ethan~ From jbeard565 at gmail.com Fri Mar 2 19:18:29 2012 From: jbeard565 at gmail.com (Jeff Beardsley) Date: Fri, 2 Mar 2012 18:18:29 -0600 Subject: A possible change to decimal.Decimal? In-Reply-To: <4F515C93.6080201@stoneleaf.us> References: <15610330.329.1330728373676.JavaMail.geo-discussion-forums@ynlw24> <4F515C93.6080201@stoneleaf.us> Message-ID: The problem with that though is: I am not the one calling reload(). That is actually being called for me by web.py (or django, or some other framework, take your pick). More than that, I believe it's called (or caused, anyway) by something happening in WSGI under apache. (And I don't really want to start digging around in there either) The patch in this case is very limited in scope, and all it inflicts on the subject code inside of decimal.Decimal.__new__(), is better programming practices. --jeff On Fri, Mar 2, 2012 at 5:49 PM, Ethan Furman wrote: > Jeff Beardsley wrote: > >> HISTORY: >> In using python 2.7.2 for awhile on a web project (apache/wsgi web.py), I >> discovered a problem in using decimal.Decimal. A short search revealed >> that many other people have been having the problem as well, in their own >> apache/wsgi implementations (django, mostly), but I found no real solutions >> among the posts I read. So I did some experimentation of my own. >> >> The following code will break unexpectedly on standard python2.7 (and >> earlier) because of the way that isinstance fails after reload() (which is >> called by both of the above web frameworks). >> >> This is the error: TypeError("Cannot convert %r to Decimal" % value) >> >> THE TEST CODE >> >> import decimal >> from decimal import Decimal >> >> #this works >> Decimal(Decimal()) >> >> reload(decimal) >> >> #this fails before patching, but works fine afterwards >> Decimal(Decimal()) >> >> > Patching decimal.py to make it work with reload() is probably not going to > happen. > > What you should be doing is: > > import decimal > from decimal import Decimal > > reload(decimal) > Decimal = decimal.Decimal # (rebind 'Decimal' to the reloaded code) > > ~Ethan~ > -------------- next part -------------- An HTML attachment was scrubbed... URL: From johnjsal at gmail.com Fri Mar 2 20:48:53 2012 From: johnjsal at gmail.com (John Salerno) Date: Fri, 2 Mar 2012 17:48:53 -0800 (PST) Subject: How do you use the widgets in tkinter.ttk if you want to "import tkinter as tk"? Message-ID: <29015333.101.1330739333318.JavaMail.geo-discussion-forums@vbbgt10> According to the Python docs, the way to use tkinter.ttk is this: from tkinter import * from tkinter.ttk import * But what if I don't like this import method and prefer to do: import tkinter as tk How then do I utilize tkinter.ttk using the same name? Or is that not possible? Will I have to use to separate names, like this: import tkinter as tk import tkinter.ttk as ttk Is that the only way? From wang93117 at gmail.com Fri Mar 2 21:45:32 2012 From: wang93117 at gmail.com (gwang) Date: Fri, 2 Mar 2012 18:45:32 -0800 (PST) Subject: Unable to install xmldiff package on WIndows7 References: Message-ID: On Jan 3, 11:47?am, hisan wrote: > Hi All > > i have downloaded "xmldiff-0.6.10" from their official site (http://www.logilab.org/859). > I have tried installing the same on my 32 bit Windows 7 OS using the > command "setup.py install" but below exceptions are thrown in the > console. > please help me out in installing this package on Windows > > Exceptions thrown while installing > > C:\Users\santosh\Downloads\xmldiff-0.6.10>setup.py build > running build > running build_py > package init file '.\test\__init__.py' not found (or not a regular > file) > package init file '.\test\__init__.py' not found (or not a regular > file) > running build_ext > building 'xmldiff.maplookup' extension > gcc -mno-cygwin -mdll -O -Wall -ID:\Python26\include -ID:\Python26\PC - > c extensions/maplookup.c -o b > uild\temp.win32-2.6\Release\extensions\maplookup.o > error: command 'gcc' failed: No such file or directory edit maplookup.c and comment away the line : #include . At least that's what worked for me. From tjreedy at udel.edu Fri Mar 2 21:47:30 2012 From: tjreedy at udel.edu (Terry Reedy) Date: Fri, 02 Mar 2012 21:47:30 -0500 Subject: How do you use the widgets in tkinter.ttk if you want to "import tkinter as tk"? In-Reply-To: <29015333.101.1330739333318.JavaMail.geo-discussion-forums@vbbgt10> References: <29015333.101.1330739333318.JavaMail.geo-discussion-forums@vbbgt10> Message-ID: On 3/2/2012 8:48 PM, John Salerno wrote: > According to the Python docs, the way to use tkinter.ttk is this: > > from tkinter import * > from tkinter.ttk import * I suppose the 'advantage' of this is that it will replace tk widgets with equivalent ttk widgets, if they exist and have the same name. I believe one has to program them differently, however, so the replacement cannot be transparent and one mush know anyway what gets replaced and what not. > But what if I don't like this import method and prefer to do: > > import tkinter as tk > > How then do I utilize tkinter.ttk using the same name? > Or is that not possible? Will I have to use to separate names, like this: No. One name for one object. > import tkinter as tk > import tkinter.ttk as ttk Yes -- Terry Jan Reedy From ben+python at benfinney.id.au Fri Mar 2 22:34:35 2012 From: ben+python at benfinney.id.au (Ben Finney) Date: Sat, 03 Mar 2012 14:34:35 +1100 Subject: How do you use the widgets in tkinter.ttk if you want to "import tkinter as tk"? References: <29015333.101.1330739333318.JavaMail.geo-discussion-forums@vbbgt10> Message-ID: <87hay6nyr8.fsf@benfinney.id.au> Terry Reedy writes: > On 3/2/2012 8:48 PM, John Salerno wrote: > > from tkinter import * > > from tkinter.ttk import * > > I suppose the 'advantage' of this is that it will replace tk widgets > with equivalent ttk widgets, if they exist and have the same name. I > believe one has to program them differently, however, so the > replacement cannot be transparent and one mush know anyway what gets > replaced and what not. Yes, and one mush is exactly what one gets when clobbering the namespace with ?from foo import *? :-) -- \ ?We are human only to the extent that our ideas remain humane.? | `\ ?_Breakfast of Champions_, Kurt Vonnegut | _o__) | Ben Finney From Joshua.R.English at gmail.com Fri Mar 2 23:47:14 2012 From: Joshua.R.English at gmail.com (Josh English) Date: Fri, 2 Mar 2012 20:47:14 -0800 (PST) Subject: Udacity CS 101 In-Reply-To: References: <28556790.1352.1330204852864.JavaMail.geo-discussion-forums@pbgq3> Message-ID: <12911798.131.1330750034248.JavaMail.geo-discussion-forums@pbqn3> On Monday, February 27, 2012 6:37:25 PM UTC-8, Ray Clark wrote: > > You have to remember that this course assumes no prior computer > programming knowledge. > > I agree, it is starting out very basic. Give it some more time. > These guys have PhDs from MIT and/or have taught at Stanford. They > know what they are doing. It seems to me that they're not starting with good Python practices, really, or even the terminology I'd expect. From johnjsal at gmail.com Sat Mar 3 00:06:02 2012 From: johnjsal at gmail.com (John Salerno) Date: Fri, 2 Mar 2012 21:06:02 -0800 (PST) Subject: How do you use the widgets in tkinter.ttk if you want to "import tkinter as tk"? In-Reply-To: References: <29015333.101.1330739333318.JavaMail.geo-discussion-forums@vbbgt10> Message-ID: <409450.255.1330751162956.JavaMail.geo-discussion-forums@vbkl3> > I suppose the 'advantage' of this is that it will replace tk widgets > with equivalent ttk widgets, if they exist and have the same name. I > believe one has to program them differently, however, so the replacement > cannot be transparent and one mush know anyway what gets replaced and > what not. Grr, sounds like a pain if I want to use the new widgets. Does this cause conflict with someone who isn't running 8.5, or will they still see the older widgets as normal? I'm tempted just to go back to wxPython. Two sets of widgets in Tkinter is a little annoying. From johnjsal at gmail.com Sat Mar 3 00:06:02 2012 From: johnjsal at gmail.com (John Salerno) Date: Fri, 2 Mar 2012 21:06:02 -0800 (PST) Subject: How do you use the widgets in tkinter.ttk if you want to "import tkinter as tk"? In-Reply-To: References: <29015333.101.1330739333318.JavaMail.geo-discussion-forums@vbbgt10> Message-ID: <409450.255.1330751162956.JavaMail.geo-discussion-forums@vbkl3> > I suppose the 'advantage' of this is that it will replace tk widgets > with equivalent ttk widgets, if they exist and have the same name. I > believe one has to program them differently, however, so the replacement > cannot be transparent and one mush know anyway what gets replaced and > what not. Grr, sounds like a pain if I want to use the new widgets. Does this cause conflict with someone who isn't running 8.5, or will they still see the older widgets as normal? I'm tempted just to go back to wxPython. Two sets of widgets in Tkinter is a little annoying. From dreamingforward at gmail.com Sat Mar 3 01:12:04 2012 From: dreamingforward at gmail.com (dreamingforward at gmail.com) Date: Fri, 2 Mar 2012 22:12:04 -0800 (PST) Subject: A 'Python like' language In-Reply-To: References: <40645d8f$0$10775$afc38c87@news.easynet.co.uk> <30985729.0403291959.2dafe546@posting.google.com> Message-ID: <15871005.273.1330755124745.JavaMail.geo-discussion-forums@pbboi9> On Tuesday, March 30, 2004 12:31:35 AM UTC-7, Mark Hahn wrote: > > --Take advantage of iterators early on for return values to avoid > > things like having both dict.items() and dict.iteritems(). > > Interestiong idea. Generators are fully supported so I could do this now. > So gens would have to be allowed absolutely everywhere lists are allowed (is > trhis possible?). Or are you thinking the user should type > List(dict.items()) ? No, the former. Most of the time you never really use a full, naked list anyway, generally only for documentation purposes. > > --Choose "{:}" syntax for empty dict creation to reserve "{}" for > > sets. (Or: use "{}" for both, and do automatic "set-to-dict > > Also cool. Maybe <> for sets? Prothon doesn't support <> as != so it is > free. I strongly suggest the standard (in math anyway) syntax for set notation. It shouldn't be hard to parse whether code syntax is referring to a set vs. dict. > > --Functions that return multiple, but unique, values should return a > > set, not a list, to communicate same (ex: dict.keys(), dir(), etc.). > > Also cool. This is something that still hasn't really been implemented in PythonV3. > > --Dict should inherit from Set. > > Also cool (I feel like the credits of Holy Grail saying Also wik). An alternative is to create a named association type, similar to the ABC programming language, denoted by the colon. "name": []. A dict then would simply be a set of these. Having a compound type would come in handy in several other ways too. > > --With prothon's "immutability" bit and other considerations, does the > > language need both tuples AND lists? > > I like this a lot. Tuples are already implemented internally as lists. I think, in fact, that the object model could be more unified. Under such a new object model, the worries about having a full library becomes rather pointless, as the new model will require a revamping of everything. > More like a few dollars. This is really good stuff. Can I talk you into > hanging out on the Prothon list now and then, at least until we get the core > language sorted out? Haha, a little late, but consider this a restart. From no.email at nospam.invalid Sat Mar 3 01:22:30 2012 From: no.email at nospam.invalid (Paul Rubin) Date: Fri, 02 Mar 2012 22:22:30 -0800 Subject: A 'Python like' language References: <40645d8f$0$10775$afc38c87@news.easynet.co.uk> <30985729.0403291959.2dafe546@posting.google.com> <15871005.273.1330755124745.JavaMail.geo-discussion-forums@pbboi9> Message-ID: <7xaa3y8aqh.fsf@ruckus.brouhaha.com> dreamingforward at gmail.com writes: >> hanging out on the Prothon list now and then, at least until we get >> the core language sorted out? > > Haha, a little late, but consider this a restart. It wasn't til I saw the word "Prothon" that I scrolled back and saw you were responding to a thread from 2004. Prothon was pretty cool in some ways but I think it's been inactive for a very long time. I don't see much point to developing a "slightly improved but incompatible Python-like language" anyway though. Why make superficial changes that break working code and mentally overload programmers? Python is a relatively mature language by now, so it shouldn't be messed with unless the changes produce drastic benefits, not minor ones. From arpitasaha244 at gmail.com Sat Mar 3 01:27:51 2012 From: arpitasaha244 at gmail.com (arpita saha) Date: Fri, 2 Mar 2012 22:27:51 -0800 (PST) Subject: EARN RS.2.5 PER CLICK INDIAN SITE 100%REAL JOIN AND GET RS.100 INSTANTLY........... CLICK HERE TO REGISTER FOR FREE: Message-ID: http://www.indyarocks.com/blogs/blog_visiterview_main.php?ouid=NjQ2NzMwNg= PROCEDUE:---- 1)REGISTER BY COPYING THE LINK INTO YOUR BROWSER GIVEN ABOVE AND VERIFY THE GIVEN EMAIL FOR CONFIRMATION. 2)LOGIN BY USING THE USERNAME AND PASSWORD. 3)U WILL FIND 2 LINKS THERE VIEW ADS &MY ACCOUNT... a) view job details - http://www.onlineearnfree32.weebly.com/ 4)CLICK ON THE VIEW ADS LINK, U WILL FIND SOME ADS CLICK ON EACH LINK TO OPEN A NEW WINDOW........ ................................IMPORTANT: { FOLLOW WITHOUT FAIL }.............................. 1) SIMPLE JOBS. BASIC KNOWLEDGE OF COMPUTER AND INTERNET IS ENOUGH. SUITABLE FOR HOUSE WIVES,STUDENTS,WORKERS, RETIRED PERSONS & YOUTHS. b)Just signup for free at- http://onlineearnfree32.weebly.com/ Thanks ?? From dreamingforward at gmail.com Sat Mar 3 01:46:29 2012 From: dreamingforward at gmail.com (dreamingforward at gmail.com) Date: Fri, 2 Mar 2012 22:46:29 -0800 (PST) Subject: A 'Python like' language In-Reply-To: References: <40645d8f$0$10775$afc38c87@news.easynet.co.uk> <30985729.0403291959.2dafe546@posting.google.com> Message-ID: <1933683.115.1330757189443.JavaMail.geo-discussion-forums@pbcvy9> On Tuesday, March 30, 2004 6:01:01 AM UTC-7, Gerrit wrote: > > > --Dict should inherit from Set. > > > > Also cool (I feel like the credits of Holy Grail saying Also wik). > > I have read (in c.l.py) that in Smalltalk, a Dict is a Set of Associates > or something similar. I don't know Smalltalk, but I like this idea of a > Set. Yeah, I like this too. I take it from the ABC language. The thing that's relevant (and apropos to Paul Rubin's objection), is that when unifying models, you have to decide "where the decimal point is" from which all the different dimensions that the language is encoding and silently tracking can pivot around. The ":" of a compound is a sort of decimal point. Then the task is finding a formalism in which to define and incorporate all the relavent dimensions into one. The result will be necessarily recursive, revolving around the notions of the "atomic" versus the "group" and the transition rules that govern them. mark (aka zipher) From dreamingforward at gmail.com Sat Mar 3 01:46:29 2012 From: dreamingforward at gmail.com (dreamingforward at gmail.com) Date: Fri, 2 Mar 2012 22:46:29 -0800 (PST) Subject: A 'Python like' language In-Reply-To: References: <40645d8f$0$10775$afc38c87@news.easynet.co.uk> <30985729.0403291959.2dafe546@posting.google.com> Message-ID: <1933683.115.1330757189443.JavaMail.geo-discussion-forums@pbcvy9> On Tuesday, March 30, 2004 6:01:01 AM UTC-7, Gerrit wrote: > > > --Dict should inherit from Set. > > > > Also cool (I feel like the credits of Holy Grail saying Also wik). > > I have read (in c.l.py) that in Smalltalk, a Dict is a Set of Associates > or something similar. I don't know Smalltalk, but I like this idea of a > Set. Yeah, I like this too. I take it from the ABC language. The thing that's relevant (and apropos to Paul Rubin's objection), is that when unifying models, you have to decide "where the decimal point is" from which all the different dimensions that the language is encoding and silently tracking can pivot around. The ":" of a compound is a sort of decimal point. Then the task is finding a formalism in which to define and incorporate all the relavent dimensions into one. The result will be necessarily recursive, revolving around the notions of the "atomic" versus the "group" and the transition rules that govern them. mark (aka zipher) From cookfitz at gmail.com Sat Mar 3 06:42:25 2012 From: cookfitz at gmail.com (nac) Date: Sat, 3 Mar 2012 03:42:25 -0800 (PST) Subject: RotatingFileHandler Fails Message-ID: The RotatingFileHandler running on win 7 64-bit; py 2.7 is failing when the script launches a process using subprocess.Popen. Works fine if the subprocess is not launched The exception thrown Traceback (most recent call last): File "C:\Python27\lib\logging\handlers.py", line 78, in emit self.doRollover() File "C:\Python27\lib\logging\handlers.py", line 141, in doRollover os.rename(self.baseFilename, dfn) WindowsError: [Error 32] The process cannot access the file because it is being used by another process Anyone have an idea how to fix this? import os, sys import logging import logging.handlers import subprocess def chomp(s): "remove trailing carriage return" if s[-1:]=='\n': return s[:-1] else: return s logging.basicConfig(level=logging.DEBUG, format='%(asctime)s % (name)-2s %(levelname)-8s %(threadName)-12s %(message)s') q5Logger = logging.getLogger('Q5') logFileHandler = logging.handlers.RotatingFileHandler(filename='c:\ \logger\\q5.log', mode= 'a', maxBytes=100, backupCount=5) logFileHandler.setFormatter(logging.Formatter('%(asctime)s %(name)-2s % (levelname)-8s %(threadName)-12s %(message)s')) logFileHandler.setLevel(logging.DEBUG) q5Logger.addHandler(logFileHandler) progOutput = subprocess.Popen(r'dir *.*', shell=True, bufsize=1000, stdout=subprocess.PIPE).stdout line = progOutput.readline() while (line) != "": q5Logger.info( chomp(line)) line = progOutput.readline() rc = progOutput.close() From mwilson at the-wire.com Sat Mar 3 07:07:31 2012 From: mwilson at the-wire.com (Mel Wilson) Date: Sat, 03 Mar 2012 07:07:31 -0500 Subject: A 'Python like' language References: <40645d8f$0$10775$afc38c87@news.easynet.co.uk> <30985729.0403291959.2dafe546@posting.google.com> <15871005.273.1330755124745.JavaMail.geo-discussion-forums@pbboi9> <7xaa3y8aqh.fsf@ruckus.brouhaha.com> Message-ID: Paul Rubin wrote: > dreamingforward at gmail.com writes: >>> hanging out on the Prothon list now and then, at least until we get >>> the core language sorted out? >> >> Haha, a little late, but consider this a restart. > > It wasn't til I saw the word "Prothon" that I scrolled back and saw you > were responding to a thread from 2004. Prothon was pretty cool in some > ways but I think it's been inactive for a very long time. I don't see > much point to developing a "slightly improved but incompatible > Python-like language" anyway though. Why make superficial changes that > break working code and mentally overload programmers? Python is a > relatively mature language by now, so it shouldn't be messed with unless > the changes produce drastic benefits, not minor ones. A website still exists, but I don't see signs of a new language; looks like a watering hole for some techies. Prothon looked interesting as long as it promised to be about Python that used prototypes instead of classes to organize objects. What happened, though, was that it turned into a crusade to remove every Python wart that a bunch of people could imagine. The band of developers might have had the steam for the new object model, but they didn't have the steam to do everything. Mel. From mondalmousumi83 at gmail.com Sat Mar 3 09:30:03 2012 From: mondalmousumi83 at gmail.com (Mousumi Mondal) Date: Sat, 3 Mar 2012 06:30:03 -0800 (PST) Subject: easy earn money Message-ID: <26477972.867.1330785003730.JavaMail.geo-discussion-forums@pbbms5> money-internet-money.weebly.com money-internet-money.weebly.com money-internet-money.weebly.com money-internet-money.weebly.com money-internet-money.weebly.com money-internet-money.weebly.com money-internet-money.weebly.com money-internet-money.weebly.com From skip at pobox.com Sat Mar 3 10:47:03 2012 From: skip at pobox.com (skip at pobox.com) Date: Sat, 3 Mar 2012 09:47:03 -0600 (CST) Subject: Looking for people to take over some packages Message-ID: <20120303154703.96B1D2D1D239@montanaro.dyndns.org> I'm shifting life gears, trying to get away from the computer more during my hours away from work. As part of that, I'm looking to get out of the package authorship/maintenance business. Currently, I am officially listed as the "maintainer" (I use that term loosely - I really do very little at this time) of the following packages on PyPI (http://pypi.python.org/): bsddb185 lockfile spambayes tb Some time ago Ben Finney offered to take over lockfile. He doesn't want to horse around with Google Code and I don't want to learn how to use git/github just to make the existing code available to him. Perhaps someone with both Google Code and Github accounts can facilitate the exchange. Taking over the SpamBayes package probably implies a committment to greater involvement in the SpamBayes project (so be careful before you volunteer). It's worth poking around http://www.spambayes.org/. Bsddb185 is just a repackaging of the old bsddb185 module which got dropped from the Python core some years ago. It probably gets very little use, but last I looked, there were still some systems which used that versy of Berkeley DB. Tb provides a couple alternate traceback formatting functions. The compact_traceback function is an adaptation of the one generated by asyncore. The verbose_traceback function includes local variable values in the trace. If you have any interest in helping with any of these, let me know. -- Skip Montanaro - skip at pobox.com - http://www.smontanaro.net/ From anthra.norell at bluewin.ch Sat Mar 3 11:10:39 2012 From: anthra.norell at bluewin.ch (Frederic Rentsch) Date: Sat, 03 Mar 2012 17:10:39 +0100 Subject: How to read image data into Tkinter Canvas? Message-ID: <1330791039.2281.172.camel@hatchbox-one> Hi, Familiarizing myself with Tkinter I'm stuck trying to fill a Canvas with an image. I believe the class I need is PhotoImage rather than BitmapImage. But I have no luck with either. The PhotoImage doc lists available handlers for writing GIF and PPM files. It doesn't say anything about reading. I would assume that any widely used image format would activate the appropriate handler automatically. To work with formats other than GIF and PPM the doc recommends to resort to the Image module (PIL). This approach also failed. I did manage to read a GIF file into PhotoImage, which seems to let my code off the hook. And I have made sure beyond any doubt that my image files exist and open with PIL. I must be doing something wrong and will much appreciate any help. Frederic --------------------------------------------------------------------- Here's what happens: First trial with PhotoImage: . . . canvas = Canvas (root) picture = PhotoImage (file = "/home/fr/temp/wandbild.bmp") image = canvas.create_image (10, 10, anchor = NW, image = picture) . . . Traceback (most recent call last): File "tk2.py", line 23, in picture = PhotoImage (file = "/home/fr/temp/wandbild.bmp") File "/usr/lib/python2.6/lib-tk/Tkinter.py", line 3288, in __init__ Image.__init__(self, 'photo', name, cnf, master, **kw) File "/usr/lib/python2.6/lib-tk/Tkinter.py", line 3244, in __init__ self.tk.call(('image', 'create', imgtype, name,) + options) _tkinter.TclError: couldn't recognize data in image file "/home/fr/temp/wandbild.bmp" --------------------------------------------------------------------- Second trial with BitmapImage: . . . picture = BitmapImage (file = "/home/fr/temp/wandbild.bmp") . . . Traceback (most recent call last): File "tk2.py", line 22, in picture = BitmapImage (file = "/home/fr/temp/wandbild.bmp") File "/usr/lib/python2.6/lib-tk/Tkinter.py", line 3347, in __init__ Image.__init__(self, 'bitmap', name, cnf, master, **kw) File "/usr/lib/python2.6/lib-tk/Tkinter.py", line 3244, in __init__ self.tk.call(('image', 'create', imgtype, name,) + options) _tkinter.TclError: format error in bitmap data --------------------------------------------------------------------- Third trial with Image.open: . . . picture = Image.open ("/home/fr/temp/wandbild.bmp") print picture image = canvas.create_image (10, 10, anchor = NW, image = picture) . . . Traceback (most recent call last): File "tk2.py", line 24, in image = canvas.create_image (10, 10, anchor = NW, image = picture) File "/usr/lib/python2.6/lib-tk/Tkinter.py", line 2159, in create_image return self._create('image', args, kw) File "/usr/lib/python2.6/lib-tk/Tkinter.py", line 2150, in _create *(args + self._options(cnf, kw)))) _tkinter.TclError: image "" doesn't exist --------------------------------------------------------------------- Same thing happens with JPG files. As I said, GIF works into PhotoImage, but that's the only format I managed. From rmorgan466 at gmail.com Sat Mar 3 12:13:06 2012 From: rmorgan466 at gmail.com (Rita) Date: Sat, 3 Mar 2012 12:13:06 -0500 Subject: python library to generate restructured text Message-ID: Hello, I am using sqlite3 modules to get data out of a table. I would like to dump the table into a restructured-text (docutil) format. I was wondering if there was a library which would accomplish this. -- --- Get your facts first, then you can distort them as you please.-- -------------- next part -------------- An HTML attachment was scrubbed... URL: From emekamicro at gmail.com Sat Mar 3 12:28:58 2012 From: emekamicro at gmail.com (Emeka) Date: Sat, 3 Mar 2012 18:28:58 +0100 Subject: Udacity CS 101 In-Reply-To: <12911798.131.1330750034248.JavaMail.geo-discussion-forums@pbqn3> References: <28556790.1352.1330204852864.JavaMail.geo-discussion-forums@pbgq3> <12911798.131.1330750034248.JavaMail.geo-discussion-forums@pbqn3> Message-ID: Well, I checked unit 2 out the other day. It is indeed of poor standard and to some extend a waste of time for me. However, I see it as another way of having fun. On Sat, Mar 3, 2012 at 5:47 AM, Josh English wrote: > On Monday, February 27, 2012 6:37:25 PM UTC-8, Ray Clark wrote: > > > > You have to remember that this course assumes no prior computer > > programming knowledge. > > > > I agree, it is starting out very basic. Give it some more time. > > These guys have PhDs from MIT and/or have taught at Stanford. They > > know what they are doing. > > It seems to me that they're not starting with good Python practices, > really, or even the terminology I'd expect. > -- > http://mail.python.org/mailman/listinfo/python-list > -- *Satajanus Nig. Ltd * -------------- next part -------------- An HTML attachment was scrubbed... URL: From steve+comp.lang.python at pearwood.info Sat Mar 3 12:36:52 2012 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 03 Mar 2012 17:36:52 GMT Subject: Building Python with non-standard tcl/tk support Message-ID: <4f5256b4$0$29989$c3e8da3$5496439d@news.astraweb.com> I'm trying to re-build Python 3.2 with support for TCL/TK 8.5, but when I run "make" I get this message: Failed to build these modules: _tkinter and after installing 3.2 I still have this: >>> import _tkinter >>> _tkinter.TK_VERSION '8.4' What do I need to do to have Python 3.2 use tcl/tk 8.5? I have installed tcl/tk 8.5.11 from source, and the binaries are here: /usr/local/lib/libtcl8.5.so /usr/local/lib/libtk8.5.so In the Python 3.2 source, I do the usual: ./configure make sudo make altinstall (altinstall to avoid nuking the system Python) -- Steven From anikom15 at gmail.com Sat Mar 3 13:17:40 2012 From: anikom15 at gmail.com (Westley =?iso-8859-1?Q?Mart=EDnez?=) Date: Sat, 3 Mar 2012 10:17:40 -0800 Subject: Building Python with non-standard tcl/tk support In-Reply-To: <4f5256b4$0$29989$c3e8da3$5496439d@news.astraweb.com> References: <4f5256b4$0$29989$c3e8da3$5496439d@news.astraweb.com> Message-ID: <20120303181740.GA4587@kubrick> On Sat, Mar 03, 2012 at 05:36:52PM +0000, Steven D'Aprano wrote: > I'm trying to re-build Python 3.2 with support for TCL/TK 8.5, but when I > run "make" I get this message: > > Failed to build these modules: > _tkinter > > and after installing 3.2 I still have this: > > >>> import _tkinter > >>> _tkinter.TK_VERSION > '8.4' > > > What do I need to do to have Python 3.2 use tcl/tk 8.5? > > > I have installed tcl/tk 8.5.11 from source, and the binaries are here: > > /usr/local/lib/libtcl8.5.so > /usr/local/lib/libtk8.5.so > > > In the Python 3.2 source, I do the usual: > > ./configure > make > sudo make altinstall > > > (altinstall to avoid nuking the system Python) That's all you should have to do, but on my system the Tk libraries are in /usr/lib not /usr/local/lib. So try doing ./configure --prefix=/usr/local or try setting LDFLAGS to "-L/usr/local/lib". From ben+python at benfinney.id.au Sat Mar 3 16:43:47 2012 From: ben+python at benfinney.id.au (Ben Finney) Date: Sun, 04 Mar 2012 08:43:47 +1100 Subject: Adopting =?utf-8?B?4oCYbG9ja2ZpbGXigJk=?= (was: Looking for people to take over some packages) References: Message-ID: <874nu5nywc.fsf@benfinney.id.au> skip at pobox.com writes: > Some time ago Ben Finney offered to take over lockfile. That offer is still open. (Though I would appreciate ongoing development help from people who use non-Linux operating systems, since file locking works differently there and I don't have the resources to test on those.) > He doesn't want to horse around with Google Code and I don't want to > learn how to use git/github just to make the existing code available > to him. Perhaps someone with both Google Code and Github accounts can > facilitate the exchange. I don't see a need to horse around with Git either :-) It's currently in Subversion, right? Can you not export the VCS history from Google Code's Subversion repository to a ?fastimport? stream? Maybe someone with experience on that site can help us. > If you have any interest in helping with any of these, let me know. Thanks for the responsible move to seek adoption for these projects. -- \ ?I'd take the awe of understanding over the awe of ignorance | `\ any day.? ?Douglas Adams | _o__) | Ben Finney From steve+comp.lang.python at pearwood.info Sat Mar 3 19:50:53 2012 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 04 Mar 2012 00:50:53 GMT Subject: Building Python with non-standard tcl/tk support References: <4f5256b4$0$29989$c3e8da3$5496439d@news.astraweb.com> Message-ID: <4f52bc6d$0$29989$c3e8da3$5496439d@news.astraweb.com> On Sat, 03 Mar 2012 10:17:40 -0800, Westley Mart?nez wrote: > On Sat, Mar 03, 2012 at 05:36:52PM +0000, Steven D'Aprano wrote: >> I'm trying to re-build Python 3.2 with support for TCL/TK 8.5, but when >> I run "make" I get this message: >> >> Failed to build these modules: >> _tkinter >> >> and after installing 3.2 I still have this: >> >> >>> import _tkinter >> >>> _tkinter.TK_VERSION >> '8.4' >> >> >> What do I need to do to have Python 3.2 use tcl/tk 8.5? >> >> >> I have installed tcl/tk 8.5.11 from source, and the binaries are here: >> >> /usr/local/lib/libtcl8.5.so >> /usr/local/lib/libtk8.5.so >> >> >> In the Python 3.2 source, I do the usual: >> >> ./configure >> make >> sudo make altinstall >> >> >> (altinstall to avoid nuking the system Python) > > That's all you should have to do, but on my system the Tk libraries are > in /usr/lib not /usr/local/lib. So try doing ./configure > --prefix=/usr/local or try setting LDFLAGS to "-L/usr/local/lib". Thanks, but that doesn't work. "make" still says it failed to build _tkinter, and after "make altinstall" it still picks up tck/tkl 8.4. Okay, now I'm making progress... if I remove the previously existing _tkinter in lib-dynload, and re-run "make", I get something new: building '_tkinter' extension gcc -pthread -fPIC -fno-strict-aliasing -DNDEBUG -g -fwrapv -O3 -Wall - Wstrict-prototypes -DWITH_APPINIT=1 -I/usr/X11/include -IInclude -I. -I./ Include -I/usr/local/include -I/tmp/Python-3.2.2 -c /tmp/Python-3.2.2/ Modules/_tkinter.c -o build/temp.linux-i686-3.2/tmp/Python-3.2.2/Modules/ _tkinter.o gcc -pthread -fPIC -fno-strict-aliasing -DNDEBUG -g -fwrapv -O3 -Wall - Wstrict-prototypes -DWITH_APPINIT=1 -I/usr/X11/include -IInclude -I. -I./ Include -I/usr/local/include -I/tmp/Python-3.2.2 -c /tmp/Python-3.2.2/ Modules/tkappinit.c -o build/temp.linux-i686-3.2/tmp/Python-3.2.2/Modules/ tkappinit.o gcc -pthread -shared build/temp.linux-i686-3.2/tmp/Python-3.2.2/Modules/ _tkinter.o build/temp.linux-i686-3.2/tmp/Python-3.2.2/Modules/tkappinit.o -L/usr/X11/lib -L/usr/local/lib -ltk8.5 -ltcl8.5 -lX11 -o build/lib.linux- i686-3.2/_tkinter.cpython-32m.so *** WARNING: renaming "_tkinter" since importing it failed: libtk8.5.so: cannot open shared object file: No such file or directory Failed to build these modules: _tkinter -- Steven From anikom15 at gmail.com Sat Mar 3 20:06:39 2012 From: anikom15 at gmail.com (Westley =?iso-8859-1?Q?Mart=EDnez?=) Date: Sat, 3 Mar 2012 17:06:39 -0800 Subject: Building Python with non-standard tcl/tk support In-Reply-To: <4f52bc6d$0$29989$c3e8da3$5496439d@news.astraweb.com> References: <4f5256b4$0$29989$c3e8da3$5496439d@news.astraweb.com> <4f52bc6d$0$29989$c3e8da3$5496439d@news.astraweb.com> Message-ID: <20120304010639.GA26758@kubrick> On Sun, Mar 04, 2012 at 12:50:53AM +0000, Steven D'Aprano wrote: > Okay, now I'm making progress... if I remove the previously existing > _tkinter in lib-dynload, and re-run "make", I get something new: > > building '_tkinter' extension > gcc -pthread -fPIC -fno-strict-aliasing -DNDEBUG -g -fwrapv -O3 -Wall - > Wstrict-prototypes -DWITH_APPINIT=1 -I/usr/X11/include -IInclude -I. -I./ > Include -I/usr/local/include -I/tmp/Python-3.2.2 -c /tmp/Python-3.2.2/ > Modules/_tkinter.c -o build/temp.linux-i686-3.2/tmp/Python-3.2.2/Modules/ > _tkinter.o > gcc -pthread -fPIC -fno-strict-aliasing -DNDEBUG -g -fwrapv -O3 -Wall - > Wstrict-prototypes -DWITH_APPINIT=1 -I/usr/X11/include -IInclude -I. -I./ > Include -I/usr/local/include -I/tmp/Python-3.2.2 -c /tmp/Python-3.2.2/ > Modules/tkappinit.c -o build/temp.linux-i686-3.2/tmp/Python-3.2.2/Modules/ > tkappinit.o > gcc -pthread -shared build/temp.linux-i686-3.2/tmp/Python-3.2.2/Modules/ > _tkinter.o build/temp.linux-i686-3.2/tmp/Python-3.2.2/Modules/tkappinit.o > -L/usr/X11/lib -L/usr/local/lib -ltk8.5 -ltcl8.5 -lX11 -o build/lib.linux- > i686-3.2/_tkinter.cpython-32m.so > *** WARNING: renaming "_tkinter" since importing it failed: libtk8.5.so: > cannot open shared object file: No such file or directory > > Failed to build these modules: > _tkinter Verify that libtk8.5.so exists in /usr/local/lib and verify you have read permission. You could try to write a Tk C program (or find one) and try building that with cc -L/usr/X11/lib -L/usr/local/lib -ltk8.5 -ltcl8.5 -lX11 . If that works then your Tk libraries are installed properly and something is wonky with your Python build. From steve+comp.lang.python at pearwood.info Sat Mar 3 21:39:18 2012 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 04 Mar 2012 02:39:18 GMT Subject: Building Python with non-standard tcl/tk support References: <4f5256b4$0$29989$c3e8da3$5496439d@news.astraweb.com> <4f52bc6d$0$29989$c3e8da3$5496439d@news.astraweb.com> Message-ID: <4f52d5d6$0$29989$c3e8da3$5496439d@news.astraweb.com> On Sat, 03 Mar 2012 17:06:39 -0800, Westley Mart?nez wrote: > On Sun, Mar 04, 2012 at 12:50:53AM +0000, Steven D'Aprano wrote: >> Okay, now I'm making progress... if I remove the previously existing >> _tkinter in lib-dynload, and re-run "make", I get something new: >> >> building '_tkinter' extension >> gcc -pthread -fPIC -fno-strict-aliasing -DNDEBUG -g -fwrapv -O3 -Wall - >> Wstrict-prototypes -DWITH_APPINIT=1 -I/usr/X11/include -IInclude -I. >> -I./ Include -I/usr/local/include -I/tmp/Python-3.2.2 -c >> /tmp/Python-3.2.2/ Modules/_tkinter.c -o >> build/temp.linux-i686-3.2/tmp/Python-3.2.2/Modules/ _tkinter.o >> gcc -pthread -fPIC -fno-strict-aliasing -DNDEBUG -g -fwrapv -O3 -Wall - >> Wstrict-prototypes -DWITH_APPINIT=1 -I/usr/X11/include -IInclude -I. >> -I./ Include -I/usr/local/include -I/tmp/Python-3.2.2 -c >> /tmp/Python-3.2.2/ Modules/tkappinit.c -o >> build/temp.linux-i686-3.2/tmp/Python-3.2.2/Modules/ tkappinit.o >> gcc -pthread -shared >> build/temp.linux-i686-3.2/tmp/Python-3.2.2/Modules/ _tkinter.o >> build/temp.linux-i686-3.2/tmp/Python-3.2.2/Modules/tkappinit.o >> -L/usr/X11/lib -L/usr/local/lib -ltk8.5 -ltcl8.5 -lX11 -o >> build/lib.linux- i686-3.2/_tkinter.cpython-32m.so >> *** WARNING: renaming "_tkinter" since importing it failed: >> libtk8.5.so: cannot open shared object file: No such file or directory >> >> Failed to build these modules: >> _tkinter > > Verify that libtk8.5.so exists in /usr/local/lib and verify you have > read permission. [steve at ando ~]$ ls -l /usr/local/lib/*tk*.so -r-xr-xr-x 1 root root 1233986 Mar 4 04:01 /usr/local/lib/libtk8.5.so [steve at ando ~]$ ls -l /usr/local/lib/*tcl*.so -r-xr-xr-x 1 root root 1133948 Mar 4 03:55 /usr/local/lib/libtcl8.5.so -- Steven From rantingrickjohnson at gmail.com Sat Mar 3 23:27:43 2012 From: rantingrickjohnson at gmail.com (Rick Johnson) Date: Sat, 3 Mar 2012 20:27:43 -0800 (PST) Subject: Is it necessary to call Tk() when writing a GUI app with Tkinter? References: <27603449.17.1330492001624.JavaMail.geo-discussion-forums@vbbfv2> <6e1c521e-14be-4ec0-9ff0-7f23fd9cd3dc@f14g2000yqe.googlegroups.com> <17153317.324.1330576905540.JavaMail.geo-discussion-forums@yncd8> <11188032.247.1330726606861.JavaMail.geo-discussion-forums@ynbq18> Message-ID: On Mar 2, 4:16?pm, John Salerno wrote: > what is the point of creating a Frame object at all? I tried NOT > doing it, like you said, and it seemed to work fine with my simple > example. But is there a benefit to using a Frame object to group the > widgets together? Or is it cleaner to just use the Tk object? You will no doubt need to use frames to group widgets from time to time. My previous point was simply: "don't use frames superfluously!". Here is an example of creating a custom compound widget by sub- classing frame (psst: this widget already exists in the Tix extension. ## START CODE ## import Tkinter as tk from Tkconstants import LEFT, YES, X, N class LabelEntry(tk.Frame): def __init__(self, master, text='LE', **kw): tk.Frame.__init__(self, master, **kw) self.label = tk.Label(self, text=text, font=('Courier New', 12)) self.label.pack(side=LEFT) self.entry = tk.Entry(self) self.entry.pack(side=LEFT, fill=X, expand=YES) def get(self): return self.entry.get() def set(self, arg): self.entry.delete(0, 'end') self.entry.set(arg) if __name__ == '__main__': root = tk.Tk() for blah in (' Name:', 'Address:', ' Phone:'): w = LabelEntry(root, text=blah) w.pack(fill=X, expand=YES, anchor=N, padx=5, pady=5) root.mainloop() ## END CODE ## From gdamjan at gmail.com Sun Mar 4 00:38:44 2012 From: gdamjan at gmail.com (Damjan Georgievski) Date: Sun, 04 Mar 2012 06:38:44 +0100 Subject: The original command python line Message-ID: <4obb29-os3.ln1@archaeopteryx.softver.org.mk> How can I get the *really* original command line that started my python interpreter? Werkzeug has a WSGI server which reloads itself when files are changed on disk. It uses `args = [sys.executable] + sys.argv` to kind of recreate the command line, and the uses subprocess.call to run that command line. BUT that's problematic as, when you run:: python -m mypackage --config sys.argv printed in mypackage/__main__.py will be:: ['/full/path/to/mypackage/__main__.py', '--config'] so you get:: python /full/path/to/mypackage/__main__.py --config instead of:: python -m mypackage --config the difference in the 2 cases is what the current package is, and whether you can use relative imports. -- damjan From clp2 at rebertia.com Sun Mar 4 00:48:58 2012 From: clp2 at rebertia.com (Chris Rebert) Date: Sat, 3 Mar 2012 21:48:58 -0800 Subject: The original command python line In-Reply-To: <4obb29-os3.ln1@archaeopteryx.softver.org.mk> References: <4obb29-os3.ln1@archaeopteryx.softver.org.mk> Message-ID: On Sat, Mar 3, 2012 at 9:38 PM, Damjan Georgievski wrote: > How can I get the *really* original command line that started my python > interpreter? > > Werkzeug has a WSGI server which reloads itself when files are changed > on disk. It uses `args = [sys.executable] + sys.argv` to kind of > recreate the command line, and the uses subprocess.call to run that > command line. > > BUT that's problematic as, when you run:: > > ? ? ? ?python -m mypackage --config > > sys.argv printed in mypackage/__main__.py will be:: > > ? ? ? ?['/full/path/to/mypackage/__main__.py', '--config'] > > so you get:: > > ? ? ? ?python /full/path/to/mypackage/__main__.py --config > > instead of:: > > ? ? ? ?python -m mypackage --config > > > the difference in the 2 cases is what the current package is, and > whether you can use relative imports. On Linux, you can read from: /proc//cmdline to get the null-delimited "command line". Sidenote: Consensus generally seems to be that relative imports are a bad idea. Cheers, Chris From gdamjan at gmail.com Sun Mar 4 00:52:26 2012 From: gdamjan at gmail.com (Damjan Georgievski) Date: Sun, 04 Mar 2012 06:52:26 +0100 Subject: The original python command line In-Reply-To: <4obb29-os3.ln1@archaeopteryx.softver.org.mk> References: <4obb29-os3.ln1@archaeopteryx.softver.org.mk> Message-ID: > How can I get the *really* original command line that started my python > interpreter? > > Werkzeug has a WSGI server which reloads itself when files are changed > on disk. It uses `args = [sys.executable] + sys.argv` to kind of > recreate the command line, and the uses subprocess.call to run that > command line. > > BUT that's problematic as, when you run:: > > python -m mypackage --config > > sys.argv printed in mypackage/__main__.py will be:: > > ['/full/path/to/mypackage/__main__.py', '--config'] > > so you get:: > > python /full/path/to/mypackage/__main__.py --config > > instead of:: > > python -m mypackage --config > > > the difference in the 2 cases is what the current package is, and > whether you can use relative imports. BTW, the same thing happens in Python 3.2.2. To reproduce:: mkdir /tmp/X cd /tmp/X mkdir mypackage touch mypackage/__init__.py mypackage/dummy.py cat < mypackage/__main__.py from __future__ import print_function, absolute_import import os, sys, subprocess def rerun(): new_environ = os.environ.copy() new_environ['TEST_CHILD'] = 'true' args = [sys.executable] + sys.argv subprocess.call(args, env=new_environ) if os.environ.get('TEST_CHILD') != 'true': Role = 'Parent' rerun() else: Role = 'Child' try: from . import dummy except: print('Exception in %s' % Role) else: print('Success in %s' % Role) EOF Both:: python2 -m mypackage or:: python3 -m mypackage will print:: Exception in Child Success in Parent From clp2 at rebertia.com Sun Mar 4 00:57:42 2012 From: clp2 at rebertia.com (Chris Rebert) Date: Sat, 3 Mar 2012 21:57:42 -0800 Subject: The original command python line In-Reply-To: References: <4obb29-os3.ln1@archaeopteryx.softver.org.mk> Message-ID: On Sat, Mar 3, 2012 at 9:48 PM, Chris Rebert wrote: > On Sat, Mar 3, 2012 at 9:38 PM, Damjan Georgievski wrote: >> How can I get the *really* original command line that started my python >> interpreter? > On Linux, you can read from: > ? ?/proc//cmdline > to get the null-delimited "command line". After some further searching: psutil offers `Process.cmdline` cross-platform; see http://code.google.com/p/psutil/wiki/Documentation Cheers, Chris From gdamjan at gmail.com Sun Mar 4 01:20:28 2012 From: gdamjan at gmail.com (Damjan Georgievski) Date: Sun, 04 Mar 2012 07:20:28 +0100 Subject: The original command python line In-Reply-To: References: <4obb29-os3.ln1@archaeopteryx.softver.org.mk> Message-ID: >>> How can I get the *really* original command line that started my python >>> interpreter? > >> On Linux, you can read from: >> /proc//cmdline >> to get the null-delimited "command line". > > After some further searching: > psutil offers `Process.cmdline` cross-platform; > see http://code.google.com/p/psutil/wiki/Documentation Indeed, changing for args = psutil.Process(os.getpid()).cmdline in the above example does solve the problem, at least in Linux. > Sidenote: Consensus generally seems to be that relative imports are a bad idea. How come? I'm using explicit relative imports, I thought they were the new thing? -- damjan From jeanpierreda at gmail.com Sun Mar 4 02:19:25 2012 From: jeanpierreda at gmail.com (Devin Jeanpierre) Date: Sun, 4 Mar 2012 02:19:25 -0500 Subject: The original command python line In-Reply-To: References: <4obb29-os3.ln1@archaeopteryx.softver.org.mk> Message-ID: On Sun, Mar 4, 2012 at 1:20 AM, Damjan Georgievski wrote: > How come? > I'm using explicit relative imports, I thought they were the new thing? Explicit relative imports are fine. Implicit relative imports can create multiple module objects for the same source file, which breaks things like exception handling (because exception types are unequal if they're from different classes, even if the different classes come from two executions of the same source code). -- Devin From frank at chagford.com Sun Mar 4 03:15:57 2012 From: frank at chagford.com (Frank Millman) Date: Sun, 4 Mar 2012 10:15:57 +0200 Subject: Trying to understand 'import' a bit better Message-ID: Hi all I have been using 'import' for ages without particularly thinking about it - it just works. Now I am having to think about it a bit harder, and I realise it is a bit more complicated than I had realised - not *that* complicated, but there are some subtleties. I don't know the correct terminology, but I want to distinguish between the following two scenarios - 1. A python 'program', that is self contained, has some kind of startup, invokes certain functionality, and then closes. 2. A python 'library', that exposes functionality to other python programs, but relies on the other program to invoke its functionality. The first scenario has the following characteristics - - it can consist of a single script or a number of modules - if the latter, the modules can all be in the same directory, or in one or more sub-directories - if they are in sub-directories, the sub-directory must contain __init__.py, and is referred to as a sub-package - the startup script will normally be in the top directory, and will be executed directly by the user When python executes a script, it automatically places the directory containing the script into 'sys.path'. Therefore the script can import a top-level module using 'import ', and a sub-package module using 'import .'. The second scenario has similar characteristics, except it will not have a startup script. In order for a python program to make use of the library, it has to import it. In order for python to find it, the directory containing it has to be in sys.path. In order for python to recognise the directory as a valid container, it has to contain __init__.py, and is referred to as a package. To access a module of the package, the python program must use 'import .' (or 'from import '), and to access a sub-package module it must use 'import ... So far so uncontroversial (I hope). The subtlety arises when the package wants to access its own modules. Instead of using 'import ' it must use 'import .'. This is because the directory containing the package is in sys.path, but the package itself is not. It is possible to insert the package directory name into sys.path as well, but as was pointed out recently, this is dangerous, because you can end up with the same module imported twice under different names, with potentially disastrous consequences. Therefore, as I see it, if you are developing a project using scenario 1 above, and then want to change it to scenario 2, you have to go through the entire project and change all import references by prepending the package name. Have I got this right? Frank Millman From web.elektro.net at gmail.com Sun Mar 4 04:03:56 2012 From: web.elektro.net at gmail.com (Sirotin Roman) Date: Sun, 4 Mar 2012 16:03:56 +0700 Subject: Jython callable. How? Message-ID: Hi. How exactly jython decides is object callable or not? I defined __call__ method but interpreter says it's still not callable. BTW, my code works in cpython From arnodel at gmail.com Sun Mar 4 05:17:59 2012 From: arnodel at gmail.com (Arnaud Delobelle) Date: Sun, 4 Mar 2012 10:17:59 +0000 Subject: Jython callable. How? In-Reply-To: References: Message-ID: On Mar 4, 2012 9:04 AM, "Sirotin Roman" wrote: > > Hi. > How exactly jython decides is object callable or not? I defined > __call__ method but interpreter says it's still not callable. > BTW, my code works in cpython It will help if you show us the code. -- Arnaud -------------- next part -------------- An HTML attachment was scrubbed... URL: From steve+comp.lang.python at pearwood.info Sun Mar 4 05:26:04 2012 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 04 Mar 2012 10:26:04 GMT Subject: Jython callable. How? References: Message-ID: <4f53433c$0$29989$c3e8da3$5496439d@news.astraweb.com> On Sun, 04 Mar 2012 16:03:56 +0700, Sirotin Roman wrote: > Hi. > How exactly jython decides is object callable or not? I defined __call__ > method but interpreter says it's still not callable. BTW, my code works > in cpython Works for me. steve at runes:~$ jython *sys-package-mgr*: processing modified jar, '/usr/share/java/servlet- api-2.5.jar' Jython 2.5.1+ (Release_2_5_1, Aug 4 2010, 07:18:19) [OpenJDK Client VM (Sun Microsystems Inc.)] on java1.6.0_18 Type "help", "copyright", "credits" or "license" for more information. >>> >>> class Test: ... def __call__(self): ... return 42 ... >>> >>> x = Test() >>> x() 42 Perhaps if you show us what you actually do, and what happens, we might be able to tell you what is happening. Please COPY AND PASTE the full traceback. -- Steven From petr.jakes.tpc at gmail.com Sun Mar 4 05:28:16 2012 From: petr.jakes.tpc at gmail.com (Petr Jakes) Date: Sun, 4 Mar 2012 02:28:16 -0800 (PST) Subject: How to convert simple B/W graphic to the dot matrix for the LED display/sign Message-ID: <94052541-e1e0-43b6-b434-59e79518cf4a@q18g2000yqh.googlegroups.com> I would like to convert simple B/W graphic to the 432x64 pixel matrix. It is intended to display this graphic on the one color LED matrix sign/display (432 LEDs width, 64 LEDs height). I am experimenting with the PIL, but I did not find solution there. It will be really helpful If somebody here can show me the direction to go? Regards Petr From bv4bv4bv4 at gmail.com Sun Mar 4 05:44:27 2012 From: bv4bv4bv4 at gmail.com (BV BV) Date: Sun, 4 Mar 2012 02:44:27 -0800 (PST) Subject: IF JESUS WAS GOD !!!!!!!!!!!! Message-ID: <7a3d9843-436e-40ce-84fc-b22df4aca010@w32g2000vbt.googlegroups.com> IF JESUS WAS GOD If Jesus was GOD, then why in Mark 12:29 Jesus said "Here, O Israel: The Lord our God is one Lord." The words "our God" indicate that Jesus had a higher God over him, a stronger God than him. Jesus didn't say "Your God". He said "our God" which includes Jesus as the creation of GOD. If Jesus was GOD, then why in John 20:17 Jesus said I ascend to my God and your God? This tells us that we and Jesus have a common GOD. If Jesus was GOD, then why in John 8:28 Jesus said "I do nothing of myself"? Can't GOD do anything he wills? If Jesus was GOD, then why in John 14:28 Jesus said "My Father (GOD) is greater than I"?If Jesus was GOD, then why in Luke 23:46 Jesus said "Father (GOD), into thy hands I commend my spirit"? If Jesus was GOD, then why in Matthew 19:16 Jesus said "Why call me good, there is none good but One, that is GOD"? If Jesus was GOD, then why in Matthew 26:39 Jesus begged his GOD to have mercy on him and to pass the cup to death (kill Jesus in another words) before Jesus goes through the pain of crucifixion? Also see: Jesus's crucifixion in Islam If Jesus was GOD, then why in John 18:38 he didn't reply when he was asked about the truth? If Jesus was GOD, then why in Matthew 24:36 Jesus told his followers that no one (including Jesus) knows when the judgment day will come, only GOD knows? If Jesus was GOD, then why in Isiah 11:2-3 GOD had put the spirit of fearing GOD in Jesus? If Jesus was GOD, then why in John 5:31 Jesus told his followers that if he (Jesus) bears witness of himself, then his record is not true? If Jesus was GOD, then why in John 5:30 Jesus told his followers that he can't do a single thing of his own initiative? If Jesus was GOD, then why in John 5:36-38 Jesus said that GOD had assigned him (Jesus) work and GOD is a witness on Jesus? If Jesus was GOD, then why in John 5:32 Jesus told his followers that they have never seen GOD at anytime nor ever heard his voice? If Jesus was GOD, then why did he pray to his GOD in Luke 5:16? If Jesus was GOD, then why in Matthew 26:39 Jesus fell on his face and prayed to his GOD? The "God" Title: How come Christians take the "God" (theos in Greek) title literally with Jesus in Isiah 9:6 and they don't take it literally for the rest of the prophets and people who were called Gods ? The Prophets who were called "God" in the Bible are as follows: Prophet Moses in Exodus 7:1 The Devil in Corinthians 4:4 (the word for God in this verse is theos in Greek, the same used for Jesus that was translated as "God") Multiple Prophets in Psalms 82:6 King David in Psalm 45:3 Note: The only unique title given to GOD in the Bible that was not given to others at all are Jehova, GOD, and GOD LORD. "God", "Most Mighty" and "Almighty One" are titles that were given to Jesus, other Prophets and to Satan himself in the Bible. Very important note: Did you know that in the languages of Arabic and Hebrew the father of the house can be called the God of the house? Jesus was the God (father or leader) of his people and their father according to Isiah 9:6. Jesus being the leader and the king, it is normal for him to be called the father of his people (Father in Isiah 9:6), and because he is their father he automatically becomes their God. My father is my God in Arabic and Hebrew. The "Son" Title: How come Christians take the "God's Son" title literally with Jesus and they don't take it literally for the rest of the prophets and people who were called the Sons of God? In John 3:16 Jesus was called God's only Begotten Son. In Exodus 4:22 "Thus saith Jehova, Isreal is my son, even my firstborn." Isreal was called God's First Son. In Jeremiah 31:9 "I am a father to Isreal, and Ephraim is my firstborn." Ephraim is God's First Son and First Born.In Psalm 2:7 "... Jehova had said onto me (David), thou art my Son; this day have I begotten thee." David was called God's Begotten Son. Were Jesus's Miracle's Unique? If Jesus is believed to be GOD because he could do miracles, he could heal leprosy, he could cause blind men to see, or raise the dead, then what about the others who performed the same miracles? Elisha and Elijah fed a hundred people with twenty barley loaves and a few ears of corn (2 Kings 4:44). [Elisha told Naaman, who was a leper, to wash in the river Jordan (2 Kings 5:14) and he was healed. Elisha caused a blind man to see in (2 Kings 6:17,20). Elijah and Elisha raised the dead in (1 Kings 17:22, and 2 Kings 4:34). Even Elisha's dead bones restored a dead body in (2 Kings 13:21). Indeed Jesus had prophesied that people will worship him uselessly and will believe in doctrines not made by GOD but by men "But in vain they do worship me, teaching for doctrines the commandments of men. (Matthew 15:9)" In Matthew 15:9 above, we see Jesus warning that Trinity (the bogus lie) will dominate, and people will take Jesus as GOD and worship him, which is a total sin according to what Jesus said !! Allah Almighty (GOD) in the Noble Quran (The Muslims' Holy Scripture) states in Verse 5:72 "They do blaspheme who say: 'God is Christ the son of Mary.' But said Christ: 'O Children of Isreal ! worship God, my Lord and your Lord.' " Also in Noble Verse 5:73 "They do blaspheme who say God is one of three in a Trinity: for there is no god except One God. If they desist not from their word (of blasphemy), verily a grievous penalty will befall the blasphemers among them." And also in Noble Verse 4:171 "O People of the Book! Commit no excesses in your religion: Nor say of God aught but the truth. Christ Jesus the son of Mary was (no more than) an apostle of God, ..." The Point that I am trying to prove: Muslims believe that Prophet Jesus peace be upon him is a messenger from God. He was sent from God Almighty to deliver God's words to his people. Jesus was never God, nor ever claimed to be God. Jesus was a humble wonderful human being just like the rest of the Prophets and Messengers of God. Muslims also believe that Jesus was never crucified, nor ever died on the cross, nor ever wanted to die on the cross, nor ever was sent to earth to die on the cross . For more information about Islam http://www.islam-guide.com http://www.islamhouse.com/s/9661 http://www.thisistruth.org http://www.quran-m.com/firas/en1 http://kaheel7.com/eng http://www.knowmuhammad.com http://www.rasoulallah.net/v2/index.aspx?lang=e http://imanway1.com/eng http://www.todayislam.com http://www.thekeytoislam.com http://www.islamland.com http://www.discoverislam.com http://www.thetruereligion.org http://www.beconvinced.com http://islamtomorrow.com http://www.usc.edu/dept/MSA/quran http://www.quranforall.org http://www.quranexplorer.com/quran http://www.prophetmuhammed.org http://chatislamonline.org/en/ http://www.dar-us-salam.com http://youtubeislam.com From steve+comp.lang.python at pearwood.info Sun Mar 4 05:54:42 2012 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 04 Mar 2012 10:54:42 GMT Subject: How to convert simple B/W graphic to the dot matrix for the LED display/sign References: <94052541-e1e0-43b6-b434-59e79518cf4a@q18g2000yqh.googlegroups.com> Message-ID: <4f5349f2$0$29989$c3e8da3$5496439d@news.astraweb.com> On Sun, 04 Mar 2012 02:28:16 -0800, Petr Jakes wrote: > I would like to convert simple B/W graphic to the 432x64 pixel matrix. > It is intended to display this graphic on the one color LED matrix > sign/display (432 LEDs width, 64 LEDs height). I am experimenting with > the PIL, but I did not find solution there. > > It will be really helpful If somebody here can show me the direction to > go? What file format is the graphic in? How big is it? What file format do you want it to be? -- Steven From drakefjustin at gmail.com Sun Mar 4 05:58:50 2012 From: drakefjustin at gmail.com (Justin Drake) Date: Sun, 4 Mar 2012 10:58:50 +0000 Subject: Porting Python to an embedded system Message-ID: I am working with an ARM Cortex M3 on which I need to port Python (without operating system). What would be my best approach? I just need the core Python and basic I/O. From A.Lloyd.Flanagan at gmail.com Sun Mar 4 07:37:05 2012 From: A.Lloyd.Flanagan at gmail.com (A. Lloyd Flanagan) Date: Sun, 4 Mar 2012 04:37:05 -0800 (PST) Subject: A possible change to decimal.Decimal? In-Reply-To: References: <15610330.329.1330728373676.JavaMail.geo-discussion-forums@ynlw24> Message-ID: <6422978.686.1330864625195.JavaMail.geo-discussion-forums@vbgu10> On Friday, March 2, 2012 6:49:39 PM UTC-5, Ethan Furman wrote: > Jeff Beardsley wrote: > > HISTORY: ... > > What you should be doing is: > > import decimal > from decimal import Decimal > > reload(decimal) > Decimal = decimal.Decimal # (rebind 'Decimal' to the reloaded code) > > ~Ethan~ Agree that's how the import should be done. On the other hand, removing gratuitous use of isinstance() is generally a Good Thing. From A.Lloyd.Flanagan at gmail.com Sun Mar 4 07:37:05 2012 From: A.Lloyd.Flanagan at gmail.com (A. Lloyd Flanagan) Date: Sun, 4 Mar 2012 04:37:05 -0800 (PST) Subject: A possible change to decimal.Decimal? In-Reply-To: References: <15610330.329.1330728373676.JavaMail.geo-discussion-forums@ynlw24> Message-ID: <6422978.686.1330864625195.JavaMail.geo-discussion-forums@vbgu10> On Friday, March 2, 2012 6:49:39 PM UTC-5, Ethan Furman wrote: > Jeff Beardsley wrote: > > HISTORY: ... > > What you should be doing is: > > import decimal > from decimal import Decimal > > reload(decimal) > Decimal = decimal.Decimal # (rebind 'Decimal' to the reloaded code) > > ~Ethan~ Agree that's how the import should be done. On the other hand, removing gratuitous use of isinstance() is generally a Good Thing. From petr.jakes.tpc at gmail.com Sun Mar 4 07:47:55 2012 From: petr.jakes.tpc at gmail.com (Petr Jakes) Date: Sun, 4 Mar 2012 04:47:55 -0800 (PST) Subject: How to convert simple B/W graphic to the dot matrix for the LED display/sign References: <94052541-e1e0-43b6-b434-59e79518cf4a@q18g2000yqh.googlegroups.com> <4f5349f2$0$29989$c3e8da3$5496439d@news.astraweb.com> Message-ID: > What file format is the graphic in? How big is it? > > What file format do you want it to be? > Now, I am able to create the png file with the resolution 432x64 using PIL (using draw.text method for example). I would like to get the 432x64 True/False (Black/White) lookup table from this file, so I can switch LEDs ON/OFF accordingly. -- Petr From stefan_ml at behnel.de Sun Mar 4 08:00:54 2012 From: stefan_ml at behnel.de (Stefan Behnel) Date: Sun, 04 Mar 2012 14:00:54 +0100 Subject: Porting Python to an embedded system In-Reply-To: References: Message-ID: Justin Drake, 04.03.2012 11:58: > I am working with an ARM Cortex M3 on which I need to port Python > (without operating system). What would be my best approach? I just > need the core Python and basic I/O. The "without operating system" bit should prove problematic. Can't you just install Linux on it? Stefan From jeanpierreda at gmail.com Sun Mar 4 08:40:07 2012 From: jeanpierreda at gmail.com (Devin Jeanpierre) Date: Sun, 4 Mar 2012 08:40:07 -0500 Subject: Porting Python to an embedded system In-Reply-To: References: Message-ID: On Sun, Mar 4, 2012 at 5:58 AM, Justin Drake wrote: > I am working with an ARM Cortex M3 on which I need to port Python > (without operating system). What would be my best approach? I just > need the core Python and basic I/O. How much time are you willing to budget to this? Porting something to bare metal is not a small task. It's probably only worth it if you're doing it for academic purposes. I expect for anything real-world it'd be faster to do whatever it is you want to do using something that already runs on the bare metal. (e.g. http://armpit.sourceforge.net/ for Scheme). There used to be Flux OSKit ( http://www.cs.utah.edu/flux/oskit/ ) for porting languages to bare metal, but it doesn't support ARM and it's been dead a while. If you're really set on this, I'd try to see if there's something similar out there, somewhere. 'cause writing an OS from scratch would suck. -- Devin From duane.kaufman at gmail.com Sun Mar 4 08:56:15 2012 From: duane.kaufman at gmail.com (TheSeeker) Date: Sun, 4 Mar 2012 05:56:15 -0800 (PST) Subject: Porting Python to an embedded system In-Reply-To: References: Message-ID: <25340636.264.1330869375770.JavaMail.geo-discussion-forums@ynne2> On Sunday, March 4, 2012 4:58:50 AM UTC-6, Justin Drake wrote: > I am working with an ARM Cortex M3 on which I need to port Python > (without operating system). What would be my best approach? I just > need the core Python and basic I/O. The python-on-a-chip project (p14p) (http://code.google.com/p/python-on-a-chip/) might be something worth looking into. Thanks, Duane From duane.kaufman at gmail.com Sun Mar 4 08:56:15 2012 From: duane.kaufman at gmail.com (TheSeeker) Date: Sun, 4 Mar 2012 05:56:15 -0800 (PST) Subject: Porting Python to an embedded system In-Reply-To: References: Message-ID: <25340636.264.1330869375770.JavaMail.geo-discussion-forums@ynne2> On Sunday, March 4, 2012 4:58:50 AM UTC-6, Justin Drake wrote: > I am working with an ARM Cortex M3 on which I need to port Python > (without operating system). What would be my best approach? I just > need the core Python and basic I/O. The python-on-a-chip project (p14p) (http://code.google.com/p/python-on-a-chip/) might be something worth looking into. Thanks, Duane From maxerickson at gmail.com Sun Mar 4 09:09:23 2012 From: maxerickson at gmail.com (Max Erickson) Date: Sun, 4 Mar 2012 14:09:23 +0000 (UTC) Subject: How to convert simple B/W graphic to the dot matrix for the LED display/sign References: <94052541-e1e0-43b6-b434-59e79518cf4a@q18g2000yqh.googlegroups.com> <4f5349f2$0$29989$c3e8da3$5496439d@news.astraweb.com> Message-ID: Petr Jakes wrote: > >> What file format is the graphic in? How big is it? >> >> What file format do you want it to be? >> > > Now, I am able to create the png file with the resolution 432x64 > using PIL (using draw.text method for example). > > I would like to get the 432x64 True/False (Black/White) lookup > table from this file, so I can switch LEDs ON/OFF accordingly. > > -- > Petr > The convert and load methods are one way to do it: >>> import Image >>> im=Image.new('L', (100,100)) >>> im=im.convert('1') >>> px=im.load() >>> px[0,0] 0 That's the numeral one in the argument to convert. The load method returns a pixel access object. Max From web.elektro.net at gmail.com Sun Mar 4 09:14:46 2012 From: web.elektro.net at gmail.com (Sirotin Roman) Date: Sun, 4 Mar 2012 21:14:46 +0700 Subject: Jython callable. How? In-Reply-To: <4f53433c$0$29989$c3e8da3$5496439d@news.astraweb.com> References: <4f53433c$0$29989$c3e8da3$5496439d@news.astraweb.com> Message-ID: > Perhaps if you show us what you actually do, and what happens, we might > be able to tell you what is happening. Please COPY AND PASTE the full > traceback. Here is my code: # Trying to make callable staticmethod class sm(staticmethod): def __call__(self, *args, **kwargs): """ I know here is one more potential problem, because object passed instead of real class """ return self.__get__(None, object)(*args, **kwargs) issubclass(sm, Callable) class Foo(object): @sm def bar(): print("ololo") print("inside", bar, callable(bar), bar()) if __name__=="__main__": print("class outise", Foo.bar, callable(Foo.bar), Foo.bar()) f = Foo() print("instance outside", f.bar, callable(f.bar), f.bar()) cpython output: ololo ('inside', <__main__.sm object at 0xb72b404c>, True, None) ololo ('class outise', , True, None) ololo ('instance outside', , True, None) jython output: Traceback (most recent call last): File "sm.py", line 17, in class Foo(object): File "sm.py", line 23, in Foo print("inside", bar, callable(bar), bar()) TypeError: 'staticmethod' object is not callable From invalid at invalid.invalid Sun Mar 4 09:34:44 2012 From: invalid at invalid.invalid (Grant Edwards) Date: Sun, 4 Mar 2012 14:34:44 +0000 (UTC) Subject: The original command python line References: <4obb29-os3.ln1@archaeopteryx.softver.org.mk> Message-ID: On 2012-03-04, Chris Rebert wrote: > On Sat, Mar 3, 2012 at 9:38 PM, Damjan Georgievski wrote: >> How can I get the *really* original command line that started my python >> interpreter? > On Linux, you can read from: > /proc//cmdline > to get the null-delimited "command line". And if what you want is your own command line, you can replace with self: /proc/self/cmdline -- Grant From youssef.mahdia at hotmail.com Sun Mar 4 10:34:10 2012 From: youssef.mahdia at hotmail.com (youssef.mahdia at hotmail.com) Date: Sun, 4 Mar 2012 07:34:10 -0800 (PST) Subject: AttributeError: 'module' object has no attribute 'logger' Message-ID: hi all, when installing sage, there is a problem with emacs.py so, this screen appeared after rynning ./sage ---------------------------------------------------------------------- | Sage Version 4.4.2, Release Date: 2010-05-19 | | Type notebook() for the GUI, and license() for information. | ---------------------------------------------------------------------- Traceback (most recent call last): File "/home/zid/sage/local/bin/sage-ipython", line 18, in import IPython File "/usr/lib/python2.7/dist-packages/IPython/__init__.py", line 58, in __import__(name,glob,loc,[]) File "/usr/lib/python2.7/dist-packages/IPython/ipstruct.py", line 17, in from IPython.genutils import list2dict2 File "/usr/lib/python2.7/dist-packages/IPython/genutils.py", line 114, in import IPython.rlineimpl as readline File "/usr/lib/python2.7/dist-packages/IPython/rlineimpl.py", line 18, in from pyreadline import * File "/usr/local/lib/python2.7/dist-packages/pyreadline-2.0_dev1- py2.7.egg/pyreadline/__init__.py", line 11, in from . import unicode_helper, logger, clipboard, lineeditor, modes, console File "/usr/local/lib/python2.7/dist-packages/pyreadline-2.0_dev1- py2.7.egg/pyreadline/modes/__init__.py", line 3, in from . import emacs, notemacs, vi File "/usr/local/lib/python2.7/dist-packages/pyreadline-2.0_dev1- py2.7.egg/pyreadline/modes/emacs.py", line 11, in import pyreadline.logger as logger AttributeError: 'module' object has no attribute 'logger' any one can help me pleaseeee regards Zid From ethan at stoneleaf.us Sun Mar 4 10:38:58 2012 From: ethan at stoneleaf.us (Ethan Furman) Date: Sun, 04 Mar 2012 07:38:58 -0800 Subject: A possible change to decimal.Decimal? In-Reply-To: <6422978.686.1330864625195.JavaMail.geo-discussion-forums@vbgu10> References: <15610330.329.1330728373676.JavaMail.geo-discussion-forums@ynlw24> <6422978.686.1330864625195.JavaMail.geo-discussion-forums@vbgu10> Message-ID: <4F538C92.7070203@stoneleaf.us> A. Lloyd Flanagan wrote: > On Friday, March 2, 2012 6:49:39 PM UTC-5, Ethan Furman wrote: >> Jeff Beardsley wrote: >>> HISTORY: > ... >> What you should be doing is: >> >> import decimal >> from decimal import Decimal >> >> reload(decimal) >> Decimal = decimal.Decimal # (rebind 'Decimal' to the reloaded code) >> >> ~Ethan~ > > Agree that's how the import should be done. On the other hand, removing gratuitous use of isinstance() is generally a Good Thing. Gratuitous use? How is it gratuitous for an class to check that one of its arguments is its own type? class Frizzy(object): def __add__(self, other): if not isinstance(other, Frizzy): return NotImplemented do_stuff_with(self, other) This is exactly what isinstance() is for, and this is how it is being used in Decimal.__init__(). ~Ethan~ From ethan at stoneleaf.us Sun Mar 4 10:44:01 2012 From: ethan at stoneleaf.us (Ethan Furman) Date: Sun, 04 Mar 2012 07:44:01 -0800 Subject: A possible change to decimal.Decimal? In-Reply-To: References: <15610330.329.1330728373676.JavaMail.geo-discussion-forums@ynlw24> <4F515C93.6080201@stoneleaf.us> Message-ID: <4F538DC1.6050600@stoneleaf.us> Jeff Beardsley wrote: > The problem with that though: I am not calling reload(), except to > recreate the error as implemented by the web frameworks. > > I am also unlikely to get a patch accepted into several different > projects, where this is ONE project, and it's a simple change Simple -- maybe. Appropriate -- no. It is unfortunate that those frameworks have that bug, but it is not up to Decimal to fix it for them. ~Ethan~ From scavanau at cisco.com Sun Mar 4 13:07:57 2012 From: scavanau at cisco.com (Sean Cavanaugh (scavanau)) Date: Sun, 4 Mar 2012 10:07:57 -0800 Subject: Python - CGI-BIN - Apache Timeout Problem In-Reply-To: References: <6FC169072CBFF3409B6E74F50175A4650497A3F9@xmb-sjc-215.amer.cisco.com> Message-ID: <6FC169072CBFF3409B6E74F50175A4650497A566@xmb-sjc-215.amer.cisco.com> Thanks Chris, I isolated it using logging import logging logging.basicConfig(filename="test3.log", level=logging.INFO) then logging.info('sniffer got to point A') and going through my code until I isolated the problem to a function with scapy called sniff. For some reason this function operates very weirdly on FreeBSD9. I have already submitted an email to the scapy mailing list. Going to try to replicate this on Fedora but I doubt I will see this problem. Even from the command line the sniff() function is not working correctly on FreeBSD 9. -S -----Original Message----- From: chris at rebertia.com [mailto:chris at rebertia.com] On Behalf Of Chris Rebert Sent: Friday, March 02, 2012 3:23 PM To: Sean Cavanaugh (scavanau) Cc: python-list at python.org Subject: Re: Python - CGI-BIN - Apache Timeout Problem On Fri, Mar 2, 2012 at 12:09 PM, Sean Cavanaugh (scavanau) wrote: > THE PROBLEM: > > When I execute the scripts from the command line (#python main.py) it > generates it fine (albeit slowly), it prints all the html code out including > the script.? The ?core? part of the script dumbed down to the lowest level > is-> > > ??????? proc = subprocess.Popen(['/usr/local/bin/python', 'tests.py'], > stdout=subprocess.PIPE) > ??????? output = proc.stdout.read() Note the red warning box about possible deadlock with .stdout.read() and friends: http://docs.python.org/library/subprocess.html#popen-objects > ??????? print output > ??????? proc.stdout.close() As the docs advise, try using .communicate() [http://docs.python.org/library/subprocess.html#subprocess.Popen.communicate ] instead: proc = subprocess.Popen(?) out, err = proc.communicate() print out > When I open main.py and execute the script it just hangs? it seems to > execute the script (I see pcap fires on the interface that I am testing on > the firewall) but its not executing correctly? or loading the entire > webpage?the webpage keeps chugging along and eventually gives me an error > timeout. The hanging makes me suspect that the aforementioned deadlock is occurring. Cheers, Chris -- http://chrisrebert.com From bookman23 at comcast.net Sun Mar 4 14:20:54 2012 From: bookman23 at comcast.net (Scott V) Date: Sun, 4 Mar 2012 14:20:54 -0500 Subject: python25.dll Message-ID: <3236F50616DD4E4A85E3747922B9EE19@ScottPC> I don't know if anyone has sent this in before. > I loaded the current version of Python on my computer to learn the > programming and, I believe, it helps my Blender to work. Anyway, > occassionally, I get an error on the screen, before I have started running > programs, that states "python25.dll" will not load or does not exist. > I have removed Python from my system to stop this error. > Anything else I can do? This is XP system. > Scott *I loaded version 3.2, so not sure why the python25 was in there. ___________________________________________ Amazon: Check out my over 800 items for sale on Amazon at: http://www.amazon.com/shops/bookman236 "I believe that everything happens for a reason. People change so that you can learn to let go, things go wrong so that you appreciate them when they're right, you believe lies so you eventually learn to trust no one but yourself, and sometimes good things fall apart so better things can fall together." -Marilyn Monroe -------------- next part -------------- An HTML attachment was scrubbed... URL: From chris at simplistix.co.uk Sun Mar 4 17:34:47 2012 From: chris at simplistix.co.uk (Chris Withers) Date: Sun, 04 Mar 2012 22:34:47 +0000 Subject: Adopting =?UTF-8?B?4oCYbG9ja2ZpbGXigJk=?= In-Reply-To: <874nu5nywc.fsf@benfinney.id.au> References: <874nu5nywc.fsf@benfinney.id.au> Message-ID: <4F53EE07.7090006@simplistix.co.uk> On 03/03/2012 21:43, Ben Finney wrote: > I don't see a need to horse around with Git either :-) It's currently in > Subversion, right? Can you not export the VCS history from Google Code's > Subversion repository to a ?fastimport? stream? Maybe someone with > experience on that site can help us. What's wrong with a "git svn clone svn-url-here" ? Chris -- Simplistix - Content Management, Batch Processing & Python Consulting - http://www.simplistix.co.uk From johnjsal at gmail.com Sun Mar 4 18:07:41 2012 From: johnjsal at gmail.com (John Salerno) Date: Sun, 4 Mar 2012 15:07:41 -0800 (PST) Subject: Is this the right location to launch IDLE? Message-ID: <1902734.303.1330902461168.JavaMail.geo-discussion-forums@yncd8> I'm trying to get Notepad++ to launch IDLE and run the currently open file in IDLE, but all my attempts have failed so far. I'm wondering, am I even using the IDLE path correctly? I'm using this: "C:\Python32\Lib\idlelib\idle.pyw" "$(FULL_CURRENT_PATH)" (That last part puts in the full path to the open file.) Is this not the proper way to launch IDLE with an argument? It actually does open up IDLE, but the file doesn't seem to have been loaded, because when I try to use variables or functions from the file, IDLE acts as if it doesn't know what I'm referring to. Thanks. From antgoodlife at gmail.com Sun Mar 4 19:20:44 2012 From: antgoodlife at gmail.com (Antgoodlife) Date: Sun, 4 Mar 2012 16:20:44 -0800 (PST) Subject: Parse cisco's "show ip route" output in Python 2.7 Message-ID: Hi All, Long time reader, first time poster. I'm trying to parse the output of the SHOW IP ROUTE command from a cisco router (It's a 3800 Series IOS 12.4 although almost all should have same output format) and put it into a CSV format to import into a database or spreadsheet. While we of course have Static / Connected routes, we also have lots of dynamic routing coming in via OSPF, BGP, RIP, etc... The output of the command is easy enough for me to get into text files via parimiko (on that, does this module or equivalent work on Python 3 yet?) .. it's just tough to present the data into a csv or tabbed format. To me, although I've done similar things in the past, it's a fairly brutal output format to parse up. I was about to post some sample input, but I am even having a hard time sanitizing the IP's for use on this forum (Any utility for that?) as it's filled with IP addresses that I cannot share. I'd love some python module if anyone has an idea where I can get it? Perl does seem to have something similar : http://cpansearch.perl.org/src/MARKPF/Cisco-ShowIPRoute-Parser-1.02/Parser.pm however, I'd like to keep it in python... Mainly, did someone already do this so I don't have to reinvent this wheel (which probably won't roll straight)? Thanks in advance, and hopefully I've given enough information.. I've been trying to parse it for about 9 hours... but the script get's worse and worse as I keep finding flaws in my logic. From drsalists at gmail.com Sun Mar 4 19:47:46 2012 From: drsalists at gmail.com (Dan Stromberg) Date: Sun, 4 Mar 2012 16:47:46 -0800 Subject: Parse cisco's "show ip route" output in Python 2.7 In-Reply-To: References: Message-ID: I've done little with Ciscos, but what if you use individual things like "show ip ospf", "show ip rip database", etc. instead of "show ip route". Does that makes things a little more consistent? Often big problems are simpler if we can divide them into smaller, more manageable subproblems. On Sun, Mar 4, 2012 at 4:20 PM, Antgoodlife wrote: > Hi All, > > Long time reader, first time poster. I'm trying to parse the output > of the SHOW IP ROUTE command from a cisco router (It's a 3800 Series > IOS 12.4 although almost all should have same output format) and put > it into a CSV format to import into a database or spreadsheet. > While we of course have Static / Connected routes, we also have lots > of dynamic routing coming in via OSPF, BGP, RIP, etc... > > The output of the command is easy enough for me to get into text files > via parimiko (on that, does this module or equivalent work on Python 3 > yet?) .. it's just tough to present the data into a csv or tabbed > format. > > To me, although I've done similar things in the past, it's a fairly > brutal output format to parse up. I was about to post some sample > input, but I am even having a hard time sanitizing the IP's for use on > this forum (Any utility for that?) as it's filled with IP addresses > that I cannot share. I'd love some python module if anyone has an > idea where I can get it? > > Perl does seem to have something similar : > > http://cpansearch.perl.org/src/MARKPF/Cisco-ShowIPRoute-Parser-1.02/Parser.pm > however, I'd like to keep it in python... > > Mainly, did someone already do this so I don't have to reinvent this > wheel (which probably won't roll straight)? > > Thanks in advance, and hopefully I've given enough information.. I've > been trying to parse it for about 9 hours... but the script get's > worse and worse as I keep finding flaws in my logic. > -- > http://mail.python.org/mailman/listinfo/python-list > -------------- next part -------------- An HTML attachment was scrubbed... URL: From rantingrickjohnson at gmail.com Sun Mar 4 20:39:27 2012 From: rantingrickjohnson at gmail.com (Rick Johnson) Date: Sun, 4 Mar 2012 17:39:27 -0800 (PST) Subject: How do you use the widgets in tkinter.ttk if you want to "import tkinter as tk"? References: <29015333.101.1330739333318.JavaMail.geo-discussion-forums@vbbgt10> Message-ID: <7a170522-2fcb-4334-8d55-f71b1ffb4475@b1g2000yqb.googlegroups.com> On Mar 2, 11:06?pm, John Salerno wrote: > I'm tempted just to go back to wxPython. Two sets of widgets in Tkinter is a little annoying. Your complaint is justified. The Tkinter API is a disgrace. IDLE's source is just as bad. Luckily i have not made the jump to py3000 full- time yet, but when i do, i think the first item on my to-do list will be to hack this hideous tk+ttk+blah+blah into something more friendly. Heck, maybe i'll even release it! From nad at acm.org Sun Mar 4 20:41:50 2012 From: nad at acm.org (Ned Deily) Date: Sun, 04 Mar 2012 17:41:50 -0800 Subject: [FIXED] Re: Can't get tilde character with IDLE 3.2.2 on French Mac Lion References: Message-ID: A followup to a thread in 2011-12. In article , Ned Deily wrote: > In article , > Franck Ditter wrote: > > In article , > > Ned Deily wrote: > > > In article , > > > Franck Ditter wrote: > > > > All is in the subject. I'm starting to use Python with Idle 3.2.2 > > > > on MacOS-X Lion (French). I can't get "Option-N space" to provide > > > > the ~ char. > > > > I tried to go into the Keys preferences but I can't find "Option-N > > > > space" > > > > to modify its meaning. Its actual behavior is to merge lines of a > > > > paragraph. > > > You are likely running into a current problem in the OS X Cocoa version > > > of Tcl/Tk 8.5 as included with Lion and as shipped by ActiveState. > > > Previously, if you tried to type composite characters, like Option N, > > > the Cocoa Tcl/Tk would crash. Pending a real fix, a patch was made to > > > Tcl/Tk 8.5 to discard composite characters rather than crash. You > > > should be able to get a tilde by using the post-composite keyboard > > > sequence: try typing "space" followed by "Shift-Option-N". > > > > > > http://sourceforge.net/tracker/index.php?func=detail&aid=2907388&group_id= > > > 12 > > > 997&atid=112997 > > Nope, "space" followed by "Shift-Option-N" gives a greek iota... > > I tried other combinations, unsuccessfully. > > IDLE 3 (French) seems to be unusable as we use many ~ in web applications > > :-( > > Should we hope a fix soon, or leave IDLE ? > > Yes, I see now that that won't work with the French input method. > Unfortunately, there is nothing that IDLE or Python can do to workaround > the issue as the problem is in Cocoa Tcl/Tk and I don't know that any > fix is being worked on. Good news! A fix for Cocoa Tcl/Tk 8.5 for improved handling of Mac OS X input methods was recently applied and has now been released in the latest ActiveState Tcl release (8.5.11.1) available here: http://www.activestate.com/activetcl/downloads It appears to fix the tilde problem and other similar problems with composite characters, like Option-U + vowel to form "umlauted" vowels in the U.S. input method. Many thanks to Adrian Robert, Kevin Walzer, and the ActiveState team for addressing this nasty problem. If you install ActiveState Tcl 8.5.x, it will automatically be used by the python.org 2.7.x, 3.2.x, and 3.3.x 64-bit/32-bit Pythons for OS X 10.6 and 10.7. It will *not* be used by the Apple-supplied system Pythons or by 32-bit-only python.org Pythons. More details here: http://www.python.org/download/mac/tcltk/ -- Ned Deily, nad at acm.org From nad at acm.org Sun Mar 4 20:45:38 2012 From: nad at acm.org (Ned Deily) Date: Sun, 04 Mar 2012 17:45:38 -0800 Subject: Buffering in Wing and IDLE 3 References: Message-ID: In article , Kevin Walzer wrote: > On 2/1/12 3:01 PM, Terry Reedy wrote: > > On 2/1/2012 10:17 AM, Franck Ditter wrote: > > > >> I would prefer to use IDLE but as we are in France, the Python team > >> does not seem to be aware that the ~ and others are not available > >> on MacOS-X here (probably the same in Europe)... > > > > We are quite aware of the problem but cannot directly do anything about > > it as the problem is with tcl/tk and Apple. A couple of days ago, Kevin > > Walzer wrote on an IDLE-sig post "I'm currently reviewing an updated > > patch to address the problem. When I commit the patch, it will go into > > both Tk's trunk and in the Cocoa 8.5 backport, and eventually be > > available through ActiveState's distribution." > > > And it's been committed: > > http://core.tcl.tk/tk/info/9844fe10b9 ... and released in ActiveState 8.5.11.1 http://www.activestate.com/activetcl/downloads -- Ned Deily, nad at acm.org From kw at codebykevin.com Sun Mar 4 20:58:23 2012 From: kw at codebykevin.com (Kevin Walzer) Date: Sun, 04 Mar 2012 20:58:23 -0500 Subject: How do you use the widgets in tkinter.ttk if you want to "import tkinter as tk"? In-Reply-To: References: <29015333.101.1330739333318.JavaMail.geo-discussion-forums@vbbgt10> Message-ID: On 3/3/12 12:06 AM, John Salerno wrote: >> I suppose the 'advantage' of this is that it will replace tk widgets >> with equivalent ttk widgets, if they exist and have the same name. I >> believe one has to program them differently, however, so the replacement >> cannot be transparent and one mush know anyway what gets replaced and >> what not. > > Grr, sounds like a pain if I want to use the new widgets. Does this cause conflict with someone who isn't running 8.5, or will they still see the older widgets as normal? > > I'm tempted just to go back to wxPython. Two sets of widgets in Tkinter is a little annoying. The new widgets are not a drop-in replacement for the traditional Tk widgets. They can be used with 8.4 if the "tile" Tk extension is installed. This is how the ttk widgets were first deployed; they didn't enter Tk's core until 8.5. -- Kevin Walzer Code by Kevin http://www.codebykevin.com From anikom15 at gmail.com Sun Mar 4 21:04:34 2012 From: anikom15 at gmail.com (Westley =?iso-8859-1?Q?Mart=EDnez?=) Date: Sun, 4 Mar 2012 18:04:34 -0800 Subject: How do you use the widgets in tkinter.ttk if you want to "import tkinter as tk"? In-Reply-To: <7a170522-2fcb-4334-8d55-f71b1ffb4475@b1g2000yqb.googlegroups.com> References: <29015333.101.1330739333318.JavaMail.geo-discussion-forums@vbbgt10> <7a170522-2fcb-4334-8d55-f71b1ffb4475@b1g2000yqb.googlegroups.com> Message-ID: <20120305020434.GA31058@kubrick> On Sun, Mar 04, 2012 at 05:39:27PM -0800, Rick Johnson wrote: > On Mar 2, 11:06?pm, John Salerno wrote: > > I'm tempted just to go back to wxPython. Two sets of widgets in Tkinter is a little annoying. > > Your complaint is justified. The Tkinter API is a disgrace. IDLE's > source is just as bad. Luckily i have not made the jump to py3000 full- > time yet, but when i do, i think the first item on my to-do list will > be to hack this hideous tk+ttk+blah+blah into something more > friendly. > > Heck, maybe i'll even release it! Make sure not to write it from scratch! From dihedral88888 at googlemail.com Sun Mar 4 21:14:31 2012 From: dihedral88888 at googlemail.com (88888 Dihedral) Date: Sun, 4 Mar 2012 18:14:31 -0800 (PST) Subject: Porting Python to an embedded system In-Reply-To: References: Message-ID: <30499939.3531.1330913671419.JavaMail.geo-discussion-forums@pbjv6> On Sunday, March 4, 2012 6:58:50 PM UTC+8, Justin Drake wrote: > I am working with an ARM Cortex M3 on which I need to port Python > (without operating system). What would be my best approach? I just > need the core Python and basic I/O. Sounds like the JVM law suites in ANDROINDS did stimulate a lot jobs to use other VM-BYTECODE based programming languages. I suggest that one can use tiny linux or MU-linux which is even smaller than Linux and then install a slimmer customized python not the same as the fatter one used in PC. From dihedral88888 at googlemail.com Sun Mar 4 21:14:31 2012 From: dihedral88888 at googlemail.com (88888 Dihedral) Date: Sun, 4 Mar 2012 18:14:31 -0800 (PST) Subject: Porting Python to an embedded system In-Reply-To: References: Message-ID: <30499939.3531.1330913671419.JavaMail.geo-discussion-forums@pbjv6> On Sunday, March 4, 2012 6:58:50 PM UTC+8, Justin Drake wrote: > I am working with an ARM Cortex M3 on which I need to port Python > (without operating system). What would be my best approach? I just > need the core Python and basic I/O. Sounds like the JVM law suites in ANDROINDS did stimulate a lot jobs to use other VM-BYTECODE based programming languages. I suggest that one can use tiny linux or MU-linux which is even smaller than Linux and then install a slimmer customized python not the same as the fatter one used in PC. From drsalists at gmail.com Sun Mar 4 21:21:22 2012 From: drsalists at gmail.com (Dan Stromberg) Date: Sun, 4 Mar 2012 18:21:22 -0800 Subject: Porting Python to an embedded system In-Reply-To: References: Message-ID: You might check out pymite. http://wiki.python.org/moin/PyMite Oh, but I'm now realizing that's part of the python on a chip project, so in a way it's already been mentioned. Anyway, PyMite, I gather, is a tiny python for microcontrollers. On Sun, Mar 4, 2012 at 2:58 AM, Justin Drake wrote: > I am working with an ARM Cortex M3 on which I need to port Python > (without operating system). What would be my best approach? I just > need the core Python and basic I/O. > -- > http://mail.python.org/mailman/listinfo/python-list > -------------- next part -------------- An HTML attachment was scrubbed... URL: From clp2 at rebertia.com Sun Mar 4 21:53:57 2012 From: clp2 at rebertia.com (Chris Rebert) Date: Sun, 4 Mar 2012 18:53:57 -0800 Subject: Is this the right location to launch IDLE? In-Reply-To: <1902734.303.1330902461168.JavaMail.geo-discussion-forums@yncd8> References: <1902734.303.1330902461168.JavaMail.geo-discussion-forums@yncd8> Message-ID: On Sun, Mar 4, 2012 at 3:07 PM, John Salerno wrote: > I'm trying to get Notepad++ to launch IDLE and run the currently open file in IDLE, but all my attempts have failed so far. I'm wondering, am I even using the IDLE path correctly? I'm using this: > > "C:\Python32\Lib\idlelib\idle.pyw" "$(FULL_CURRENT_PATH)" > > (That last part puts in the full path to the open file.) > > Is this not the proper way to launch IDLE with an argument? Correct. According to IDLE's USAGE message, you want the "-r" option, which would make your desired command: "C:\Python32\Lib\idlelib\idle.pyw" -r "$(FULL_CURRENT_PATH)" > It actually does open up IDLE, but the file doesn't seem to have been loaded, because when I try to use variables or functions from the file, IDLE acts as if it doesn't know what I'm referring to. Cheers, Chris -- http://rebertia.com From johnjsal at gmail.com Sun Mar 4 22:51:18 2012 From: johnjsal at gmail.com (John Salerno) Date: Sun, 4 Mar 2012 19:51:18 -0800 (PST) Subject: Is this the right location to launch IDLE? In-Reply-To: <1902734.303.1330902461168.JavaMail.geo-discussion-forums@yncd8> References: <1902734.303.1330902461168.JavaMail.geo-discussion-forums@yncd8> Message-ID: <676893.2385.1330919478888.JavaMail.geo-discussion-forums@vbux23> Unfortunately neither method worked. Adding "-r" to the path created this error when I tried it: >>> *** Error in script or command! Traceback (most recent call last): File "C:\Users\John\Documents\Python Scripts\chess_pieces.py", line 1 ???class ChessPiece: ^ SyntaxError: invalid character in identifier >>> Although there really is no error in the file, and running it directly from within IDLE doesn't cause this problem. Adding the "pythonw.exe" part to the beginning also gave this error, but when I remove the "-r", then it just opens IDLE as normal, but without having loaded the Notepad++ file. I just know there has to be a way to do this, but perhaps it's more of an NP++ problem. I posted on their forums but no one responded. I thought I might see if the problem lies with calling IDLE, but apparently it's a Windows/NP++ thing... From clp2 at rebertia.com Sun Mar 4 23:07:19 2012 From: clp2 at rebertia.com (Chris Rebert) Date: Sun, 4 Mar 2012 20:07:19 -0800 Subject: Is this the right location to launch IDLE? In-Reply-To: <676893.2385.1330919478888.JavaMail.geo-discussion-forums@vbux23> References: <1902734.303.1330902461168.JavaMail.geo-discussion-forums@yncd8> <676893.2385.1330919478888.JavaMail.geo-discussion-forums@vbux23> Message-ID: On Sun, Mar 4, 2012 at 7:51 PM, John Salerno wrote: > Unfortunately neither method worked. Adding "-r" to the path created this error when I tried it: > >>>> > *** Error in script or command! > > Traceback (most recent call last): > ?File "C:\Users\John\Documents\Python Scripts\chess_pieces.py", line 1 > ? ????class ChessPiece: That would be a Notepad++ problem. That "???" gibberish is what you get when a Unicode BOM (Byte Order Mark) character is encoded as UTF-8 but decoded as ISO-8859-1 or CP-1252. A BOM is not recommended for UTF-8 text; there should be some setting in Notepad++ to suppress it. Cheers, Chris From johnjsal at gmail.com Mon Mar 5 00:00:50 2012 From: johnjsal at gmail.com (John Salerno) Date: Sun, 4 Mar 2012 21:00:50 -0800 (PST) Subject: Is this the right location to launch IDLE? In-Reply-To: References: <1902734.303.1330902461168.JavaMail.geo-discussion-forums@yncd8> <676893.2385.1330919478888.JavaMail.geo-discussion-forums@vbux23> Message-ID: <23665576.3009.1330923650131.JavaMail.geo-discussion-forums@ynjd19> > That would be a Notepad++ problem. That "???" gibberish is what you > get when a Unicode BOM (Byte Order Mark) character is encoded as UTF-8 > but decoded as ISO-8859-1 or CP-1252. A BOM is not recommended for > UTF-8 text; there should be some setting in Notepad++ to suppress it. You are my new hero! :) It works perfectly now! I set the default for files to be UTF-8 without BOM, and I also checked the option that said "Apply to opened ANSI files." Is that okay? Thank you!!! From johnjsal at gmail.com Mon Mar 5 00:00:50 2012 From: johnjsal at gmail.com (John Salerno) Date: Sun, 4 Mar 2012 21:00:50 -0800 (PST) Subject: Is this the right location to launch IDLE? In-Reply-To: References: <1902734.303.1330902461168.JavaMail.geo-discussion-forums@yncd8> <676893.2385.1330919478888.JavaMail.geo-discussion-forums@vbux23> Message-ID: <23665576.3009.1330923650131.JavaMail.geo-discussion-forums@ynjd19> > That would be a Notepad++ problem. That "???" gibberish is what you > get when a Unicode BOM (Byte Order Mark) character is encoded as UTF-8 > but decoded as ISO-8859-1 or CP-1252. A BOM is not recommended for > UTF-8 text; there should be some setting in Notepad++ to suppress it. You are my new hero! :) It works perfectly now! I set the default for files to be UTF-8 without BOM, and I also checked the option that said "Apply to opened ANSI files." Is that okay? Thank you!!! From k.sahithi2862 at gmail.com Mon Mar 5 00:32:18 2012 From: k.sahithi2862 at gmail.com (SAHITHI) Date: Sun, 4 Mar 2012 21:32:18 -0800 (PST) Subject: HOT LINKS FOR YOUTH ONLY Message-ID: TOP DATING TIPS TO ENCOURAGE WOMEN FOR DATING http://datingsitesdatingtips.blogspot.in/ HOT LINKS FOR YOUTH ONLY NAYANTHARA HOT WALLPAPERS http://actressimages-9.blogspot.in/2012/01/nayanthara.html ANU SMRUTHI LATEST HOT STILLS http://actressimages-9.blogspot.in/2012/02/anu-smirthi-stills.html AISHWARYA RAI LATEST HOT PICS http://actressimages-9.blogspot.in/2012/01/aishwarya-rai.html KATRINA KAIF HOT MAGAZINES PHOTOS http://actressimages-9.blogspot.in/2012/01/katrina-kaif-magazine-photos.html TRISHA HOT BEAUTIFUL IMAGES http://actressimages-9.blogspot.in/2012/01/trisha-krishnan.html HOT MALLIKA SHERAWAT PHOTOS http://actressimages-9.blogspot.in/2012/01/mallika-sherawat.html FOR LATEST MOVIE UPDATED LINKS RACHA MOVIE LATEST STILLS http://actressgallery-kalyani.blogspot.com/2012/03/racha-movie-stills.html KAJAL HOT IN BINAMI VELAKOTLU MOVIE http://actressgallery-kalyani.blogspot.com/2012/03/binami-velakotlu-movie-stills.html ADHINAYAKUDU MOVIE LATEST HOT STILLS http://actressgallery-kalyani.blogspot.in/2012/03/adhinayakudu-movie-stills.html Bhale Tammudu Movie Hot Latest Stills http://actressgallery-kalyani.blogspot.in/2012/03/bhale-thammudu-movie-stills.html TAMANNA RAM Endukante Premante Movie Latest Stills http://actressgallery-kalyani.blogspot.com/2012/03/endukante-premanta-movie-stills.html LOVELY MOVIE LATEST ROMANTIC STILLS http://actressgallery-kalyani.blogspot.in/2011/12/lovely-movie-stills.html ILEANA LATEST HOT PHOTOSHOOT http://actressgallery-kalyani.blogspot.in/2012/01/ileana-latest-stills.html ACTREESS SUPRIYA SHAILJA LATEST STILLS http://actressgallery-kalyani.blogspot.in/2012/02/supriya-shailja-stills.html SHEELA LATEST HOT STILLS http://actressgallery-kalyani.blogspot.com/2012/01/sheela-latest-stills.html KATRINA KAIF ITEM SONG STILLS http://actressgallery-kalyani.blogspot.com/2012/01/katrina-kaif-item-song-stills.html RITU KAUR LATEST PHOTO STILLS http://actressgallery-kalyani.blogspot.com/2012/01/ritu-kaur-stills.html SHRUTI HASSAN HOT IN 3 MOVIE http://actressgallery-kalyani.blogspot.com/2011/11/shruti-hassan-in-3-movie.html HOT KATRINA KAIF PHOTOS http://actressgallery-kalyani.blogspot.com/2011/09/katrina-kaif.html AISHWARYA RAI HOT HQ PHOTO STILLS http://actressgallery-kalyani.blogspot.com/2011/09/aishwarya-rai.html ASIN HOT PHOTO GALLERY http://actressgallery-kalyani.blogspot.com/2011/09/asin.html From johnjsal at gmail.com Mon Mar 5 00:53:45 2012 From: johnjsal at gmail.com (John Salerno) Date: Sun, 4 Mar 2012 21:53:45 -0800 (PST) Subject: How do you use the widgets in tkinter.ttk if you want to "import tkinter as tk"? In-Reply-To: <7a170522-2fcb-4334-8d55-f71b1ffb4475@b1g2000yqb.googlegroups.com> References: <29015333.101.1330739333318.JavaMail.geo-discussion-forums@vbbgt10> <7a170522-2fcb-4334-8d55-f71b1ffb4475@b1g2000yqb.googlegroups.com> Message-ID: <16833339.2794.1330926825621.JavaMail.geo-discussion-forums@vbai14> On Sunday, March 4, 2012 7:39:27 PM UTC-6, Rick Johnson wrote: > On Mar 2, 11:06?pm, John Salerno wrote: > > I'm tempted just to go back to wxPython. Two sets of widgets in Tkinter is a little annoying. > > Your complaint is justified. The Tkinter API is a disgrace. IDLE's > source is just as bad. Luckily i have not made the jump to py3000 full- > time yet, but when i do, i think the first item on my to-do list will > be to hack this hideous tk+ttk+blah+blah into something more > friendly. > > Heck, maybe i'll even release it! Well, after reading about the themed widgets and using them a bit, they definitely seem a lot cleaner than the old ones. Just comparing the attributes of the new and old widgets is a big difference. Much more streamlined. From johnjsal at gmail.com Mon Mar 5 02:12:38 2012 From: johnjsal at gmail.com (John Salerno) Date: Sun, 4 Mar 2012 23:12:38 -0800 (PST) Subject: Tkinter: Why aren't my widgets expanding when I resize the window? Message-ID: <32271364.3080.1330931558529.JavaMail.geo-discussion-forums@ynjd19> I can't seem to wrap my head around all the necessary arguments for making a widget expand when a window is resized. I've been following along with a tutorial and I feel like I'm doing everything it said, but I must be missing something. Here's what I have. What I expect is that when I resize the main window, I should be able to see the AppFrame's border stretch out, but it remains in the original position. Is there something wrong with the sticky argument, maybe? The tutorial I'm reading says they can be strings, but it also uses what appears to be a tuple of constants like this: sticky=(N, S, E, W) -- but that didn't work either. import tkinter as tk import tkinter.ttk as ttk class AppFrame(ttk.Frame): def __init__(self, parent, **kwargs): super().__init__(parent, **kwargs) self.grid(row=0, column=0, sticky='nsew') self.columnconfigure(0, weight=1) self.rowconfigure(0, weight=1) self.create_widgets() def create_widgets(self): entry = ttk.Entry(self) entry.grid(row=0, column=1, sticky='nsew') #entry.columnconfigure(0, weight=1) #entry.rowconfigure(0, weight=1) label = ttk.Label(self, text='Name:') label.grid(row=0, column=0, sticky='nsew') root = tk.Tk() root.title('Test Application') frame = AppFrame(root, borderwidth=15, relief='sunken') root.mainloop() From georg at python.org Mon Mar 5 02:54:06 2012 From: georg at python.org (Georg Brandl) Date: Mon, 05 Mar 2012 08:54:06 +0100 Subject: [RELEASED] Python 3.3.0 alpha 1 Message-ID: <4F54711E.2020006@python.org> On behalf of the Python development team, I'm happy to announce the first alpha release of Python 3.3.0. This is a preview release, and its use is not recommended in production settings. Python 3.3 includes a range of improvements of the 3.x series, as well as easier porting between 2.x and 3.x. Major new features in the 3.3 release series are: * PEP 380, Syntax for Delegating to a Subgenerator ("yield from") * PEP 393, Flexible String Representation (doing away with the distinction between "wide" and "narrow" Unicode builds) * PEP 409, Suppressing Exception Context * PEP 3151, Reworking the OS and IO exception hierarchy * The new "packaging" module, building upon the "distribute" and "distutils2" projects and deprecating "distutils" * The new "lzma" module with LZMA/XZ support * PEP 3155, Qualified name for classes and functions * PEP 414, explicit Unicode literals to help with porting * The new "faulthandler" module that helps diagnosing crashes * Wrappers for many more POSIX functions in the "os" and "signal" modules, as well as other useful functions such as "sendfile()" For a more extensive list of changes in 3.3.0, see http://docs.python.org/3.3/whatsnew/3.3.html To download Python 3.3.0 visit: http://www.python.org/download/releases/3.3.0/ Please consider trying Python 3.3.0a1 with your code and reporting any bugs you may notice to: http://bugs.python.org/ Enjoy! -- Georg Brandl, Release Manager georg at python.org (on behalf of the entire python-dev team and 3.3's contributors) From chris at simplistix.co.uk Mon Mar 5 03:30:59 2012 From: chris at simplistix.co.uk (Chris Withers) Date: Mon, 05 Mar 2012 08:30:59 +0000 Subject: xlutils 1.5.0 released! Message-ID: <4F5479C3.2020708@simplistix.co.uk> Hi All, I'm pleased to announce the release of xlutils 1.5.0, featuring the following changes: - Now takes advantage of "ragged rows" optimisation in xlrd 0.7.3 - Add support for PANE records to xlutils.copy, which means that zoom factors are now copied. The full change log is here: http://www.simplistix.co.uk/software/python/xlutils/changes Now, the other big change for this release is that development has moved to GitHub: https://github.com/cjw296/xlutils All the details of where to find mailing lists, issue trackers, and the like for xlutils can be found here: http://www.simplistix.co.uk/software/python/xlutils cheers, Chris -- Simplistix - Content Management, Batch Processing & Python Consulting - http://www.simplistix.co.uk From jeanmichel at sequans.com Mon Mar 5 05:27:50 2012 From: jeanmichel at sequans.com (Jean-Michel Pichavant) Date: Mon, 05 Mar 2012 11:27:50 +0100 Subject: RotatingFileHandler Fails In-Reply-To: References: Message-ID: <4F549526.10402@sequans.com> nac wrote: > The RotatingFileHandler running on win 7 64-bit; py 2.7 is failing > when the script launches a process using subprocess.Popen. Works fine > if the subprocess is not launched > > The exception thrown > Traceback (most recent call last): > File "C:\Python27\lib\logging\handlers.py", line 78, in emit > self.doRollover() > File "C:\Python27\lib\logging\handlers.py", line 141, in doRollover > os.rename(self.baseFilename, dfn) > WindowsError: [Error 32] The process cannot access the file because it > is being used by another process > > Anyone have an idea how to fix this? > > > import os, sys > import logging > import logging.handlers > import subprocess > > def chomp(s): > "remove trailing carriage return" > if s[-1:]=='\n': return s[:-1] > else: return s > > logging.basicConfig(level=logging.DEBUG, format='%(asctime)s % > (name)-2s %(levelname)-8s %(threadName)-12s %(message)s') > q5Logger = logging.getLogger('Q5') > logFileHandler = logging.handlers.RotatingFileHandler(filename='c:\ > \logger\\q5.log', mode= 'a', maxBytes=100, backupCount=5) > logFileHandler.setFormatter(logging.Formatter('%(asctime)s %(name)-2s % > (levelname)-8s %(threadName)-12s %(message)s')) > logFileHandler.setLevel(logging.DEBUG) > q5Logger.addHandler(logFileHandler) > > progOutput = subprocess.Popen(r'dir *.*', shell=True, bufsize=1000, > stdout=subprocess.PIPE).stdout > line = progOutput.readline() > while (line) != "": > q5Logger.info( chomp(line)) > line = progOutput.readline() > rc = progOutput.close() > I don't think you can open a file from 2 different processes, hence the error message. The only exception would be that one of them opens it in read only mode which won't happen for log file. You cannot fix it, it is the operand system that blocks the operation. Using thread may allow you to log into the same file, but could bring a bunch of other problems. I know some ppl use a log server, your processes using a socket (client) logger. You could do that on your local machine. There's a tutorial on that in the logging documentation. JM From jeanmichel at sequans.com Mon Mar 5 05:40:26 2012 From: jeanmichel at sequans.com (Jean-Michel Pichavant) Date: Mon, 05 Mar 2012 11:40:26 +0100 Subject: Trying to understand 'import' a bit better In-Reply-To: References: Message-ID: <4F54981A.30401@sequans.com> Frank Millman wrote: > Hi all > > I have been using 'import' for ages without particularly thinking about it - > it just works. > > Now I am having to think about it a bit harder, and I realise it is a bit > more complicated than I had realised - not *that* complicated, but there are > some subtleties. > > I don't know the correct terminology, but I want to distinguish between the > following two scenarios - > > 1. A python 'program', that is self contained, has some kind of startup, > invokes certain functionality, and then closes. > > 2. A python 'library', that exposes functionality to other python programs, > but relies on the other program to invoke its functionality. > > The first scenario has the following characteristics - > - it can consist of a single script or a number of modules > - if the latter, the modules can all be in the same directory, or in one > or more sub-directories > - if they are in sub-directories, the sub-directory must contain > __init__.py, and is referred to as a sub-package > - the startup script will normally be in the top directory, and will be > executed directly by the user > > When python executes a script, it automatically places the directory > containing the script into 'sys.path'. Therefore the script can import a > top-level module using 'import ', and a sub-package module using > 'import .'. > > The second scenario has similar characteristics, except it will not have a > startup script. In order for a python program to make use of the library, it > has to import it. In order for python to find it, the directory containing > it has to be in sys.path. In order for python to recognise the directory as > a valid container, it has to contain __init__.py, and is referred to as a > package. > > To access a module of the package, the python program must use 'import > .' (or 'from import '), and to access a > sub-package module it must use 'import ... > > So far so uncontroversial (I hope). > > The subtlety arises when the package wants to access its own modules. > Instead of using 'import ' it must use 'import .'. > This is because the directory containing the package is in sys.path, but the > package itself is not. It is possible to insert the package directory name > into sys.path as well, but as was pointed out recently, this is dangerous, > because you can end up with the same module imported twice under different > names, with potentially disastrous consequences. > > Therefore, as I see it, if you are developing a project using scenario 1 > above, and then want to change it to scenario 2, you have to go through the > entire project and change all import references by prepending the package > name. > > Have I got this right? > > Frank Millman > > > > I think you got it right. It happened to me as well, I guess it's a classic for program being promoted into a library. JM From jeanmichel at sequans.com Mon Mar 5 05:56:51 2012 From: jeanmichel at sequans.com (Jean-Michel Pichavant) Date: Mon, 05 Mar 2012 11:56:51 +0100 Subject: AttributeError: 'module' object has no attribute 'logger' In-Reply-To: References: Message-ID: <4F549BF3.7020707@sequans.com> youssef.mahdia at hotmail.com wrote: > hi all, when installing sage, there is a problem with emacs.py > so, this screen appeared after rynning ./sage > ---------------------------------------------------------------------- > | Sage Version 4.4.2, Release Date: 2010-05-19 | > | Type notebook() for the GUI, and license() for information. | > ---------------------------------------------------------------------- > Traceback (most recent call last): > File "/home/zid/sage/local/bin/sage-ipython", line 18, in > import IPython > File "/usr/lib/python2.7/dist-packages/IPython/__init__.py", line > 58, in > __import__(name,glob,loc,[]) > File "/usr/lib/python2.7/dist-packages/IPython/ipstruct.py", line > 17, in > from IPython.genutils import list2dict2 > File "/usr/lib/python2.7/dist-packages/IPython/genutils.py", line > 114, in > import IPython.rlineimpl as readline > File "/usr/lib/python2.7/dist-packages/IPython/rlineimpl.py", line > 18, in > from pyreadline import * > File "/usr/local/lib/python2.7/dist-packages/pyreadline-2.0_dev1- > py2.7.egg/pyreadline/__init__.py", line 11, in > from . import unicode_helper, logger, clipboard, lineeditor, > modes, console > File "/usr/local/lib/python2.7/dist-packages/pyreadline-2.0_dev1- > py2.7.egg/pyreadline/modes/__init__.py", line 3, in > from . import emacs, notemacs, vi > File "/usr/local/lib/python2.7/dist-packages/pyreadline-2.0_dev1- > py2.7.egg/pyreadline/modes/emacs.py", line 11, in > import pyreadline.logger as logger > AttributeError: 'module' object has no attribute 'logger' > > > > any one can help me pleaseeee > > regards > Zid > > > > > You probably have the wrong version of pyreadline. Try to install the last stable 1.7.1 or look for emacs.py requirement for the pyreadline version. Non constructive solution : use vim :o) JM From rantingrickjohnson at gmail.com Mon Mar 5 08:09:07 2012 From: rantingrickjohnson at gmail.com (Rick Johnson) Date: Mon, 5 Mar 2012 05:09:07 -0800 (PST) Subject: Tkinter: Why aren't my widgets expanding when I resize the window? References: <32271364.3080.1330931558529.JavaMail.geo-discussion-forums@ynjd19> Message-ID: On Mar 5, 1:12?am, John Salerno wrote: > I can't seem to wrap my head around all the necessary arguments > for making a widget expand when a window is resized. You will need to configure the root columns and rows also because the configurations DO NOT propagate up the widget hierarchy! Actually, for this example, I would recommend using the "pack" geometry manager on the frame. Only use grid when you need to use grid. Never use any functionality superfluously! Also, you should explicitly pack the frame from OUTSIDE frame.__init__()! ## START CODE ## import tkinter as tk import tkinter.ttk as ttk from tkinter.constants import BOTH, YES class AppFrame(ttk.Frame): def __init__(self, parent, **kwargs): super().__init__(parent, **kwargs) self._create_widgets() def _create_widgets(self): entry = ttk.Entry(self) entry.grid(row=0, column=1, sticky='nsew') label = ttk.Label(self, text='Name:') label.grid(row=0, column=0, sticky='nsew') root = tk.Tk() root.title('Test Application') frame = AppFrame(root, borderwidth=15, relief='sunken') frame.pack(fill=BOTH, expand=YES) root.mainloop() ## END CODE ## > Is there something wrong with the sticky argument, maybe? The > tutorial I'm reading says they can be strings, but it also uses what > appears to be a tuple of constants like this: sticky=(N, S, E, W) -- > but that didn't work either. I always use either: sticky='nswe' sticky=N+S+W+E From ned at nedbatchelder.com Mon Mar 5 08:27:08 2012 From: ned at nedbatchelder.com (Ned Batchelder) Date: Mon, 05 Mar 2012 08:27:08 -0500 Subject: [Python-Dev] [RELEASED] Python 3.3.0 alpha 1 In-Reply-To: <4F54711E.2020006@python.org> References: <4F54711E.2020006@python.org> Message-ID: <4F54BF2C.7000107@nedbatchelder.com> On 3/5/2012 2:54 AM, Georg Brandl wrote: > On behalf of the Python development team, I'm happy to announce the > first alpha release of Python 3.3.0. > > This is a preview release, and its use is not recommended in > production settings. > > Python 3.3 includes a range of improvements of the 3.x series, as well > as easier > porting between 2.x and 3.x. Major new features in the 3.3 release > series are: > > * PEP 380, Syntax for Delegating to a Subgenerator ("yield from") > * PEP 393, Flexible String Representation (doing away with the > distinction between "wide" and "narrow" Unicode builds) > * PEP 409, Suppressing Exception Context > * PEP 3151, Reworking the OS and IO exception hierarchy > * The new "packaging" module, building upon the "distribute" and > "distutils2" projects and deprecating "distutils" > * The new "lzma" module with LZMA/XZ support > * PEP 3155, Qualified name for classes and functions > * PEP 414, explicit Unicode literals to help with porting > * The new "faulthandler" module that helps diagnosing crashes > * Wrappers for many more POSIX functions in the "os" and "signal" > modules, as well as other useful functions such as "sendfile()" > > For a more extensive list of changes in 3.3.0, see > > http://docs.python.org/3.3/whatsnew/3.3.html > The 3.3 whatsnews page doesn't seem to mention PEP 414 or Unicode literals at all. --Ned. > To download Python 3.3.0 visit: > > http://www.python.org/download/releases/3.3.0/ > > Please consider trying Python 3.3.0a1 with your code and reporting any > bugs you may notice to: > > http://bugs.python.org/ > > > Enjoy! > > -- > Georg Brandl, Release Manager > georg at python.org > (on behalf of the entire python-dev team and 3.3's contributors) > _______________________________________________ > Python-Dev mailing list > Python-Dev at python.org > http://mail.python.org/mailman/listinfo/python-dev > Unsubscribe: > http://mail.python.org/mailman/options/python-dev/ned%40nedbatchelder.com > From petr.jakes.tpc at gmail.com Mon Mar 5 08:53:01 2012 From: petr.jakes.tpc at gmail.com (Petr Jakes) Date: Mon, 5 Mar 2012 05:53:01 -0800 (PST) Subject: How to convert simple B/W graphic to the dot matrix for the LED display/sign References: <94052541-e1e0-43b6-b434-59e79518cf4a@q18g2000yqh.googlegroups.com> <4f5349f2$0$29989$c3e8da3$5496439d@news.astraweb.com> Message-ID: <24a8132d-1e90-4c77-9bac-309a41395cb6@y17g2000yqg.googlegroups.com> > >>> import Image > >>> im=Image.new('L', (100,100)) > >>> im=im.convert('1') > >>> px=im.load() > >>> px[0,0] Thanks, load() method works great. One more question. Finally, I would like to store array in the database. What is the best way to store arrays? Petr From duncan.booth at invalid.invalid Mon Mar 5 11:08:01 2012 From: duncan.booth at invalid.invalid (Duncan Booth) Date: 5 Mar 2012 16:08:01 GMT Subject: [RELEASED] Python 3.3.0 alpha 1 References: Message-ID: Georg Brandl wrote: > For a more extensive list of changes in 3.3.0, see > > http://docs.python.org/3.3/whatsnew/3.3.html > So far as I can see the what's new don't mention that hash randomisation is enabled by default in Python 3.3. I think it would be worth adding something about that. Also the what's new doesn't mention PEP 414 although the release page does. -- Duncan Booth http://kupuguy.blogspot.com From phd at phdru.name Mon Mar 5 12:30:49 2012 From: phd at phdru.name (Oleg Broytman) Date: Mon, 5 Mar 2012 21:30:49 +0400 Subject: A Crypto Juniper $9$ secrets library In-Reply-To: References: Message-ID: <20120305173049.GA11270@iskra.aviel.ru> Hello! On Sun, Mar 04, 2012 at 10:16:05PM +0100, Julio G?mez wrote: > I have developed a Python library which encrypt/decrypt Juniper $9$ secrets. Thank you and welcome to the community! > I would like it is part of the common Python libraries and be able to > install it through APT, YUM, RPM... depending on the system. [skip] > Could you tell me the process I have to follow to publish the library? Let me give you some advice. First, there is Python Package Index - http://pypi.python.org/pypi - a central repository of python software. On the first page you can find all necessary information - how to register a user, how to register a package, how to register a release. The site also provides file hosting service so you can upload you releases. But you can host anywhere and only publish links to your preferred hosting. Some people just publish links to their mercurial or git repositories. Documentation uploaded to the site will be published at http://packages.python.org/ . It is also very important to send good release announcements. Please read the following introductory articles: http://en.wikipedia.org/wiki/Announcement_%28computing%29 http://perlbuzz.com/2009/03/how-to-write-an-announcement.html Read the archives of the python announcements mailing list: http://mail.python.org/pipermail/python-announce-list/ or http://groups.google.com/group/comp.lang.python.announce/topics Oleg. -- Oleg Broytman http://phdru.name/ phd at phdru.name Programmers don't die, they just GOSUB without RETURN. From johnjsal at gmail.com Mon Mar 5 12:31:09 2012 From: johnjsal at gmail.com (John Salerno) Date: Mon, 5 Mar 2012 09:31:09 -0800 (PST) Subject: Tkinter: Why aren't my widgets expanding when I resize the window? In-Reply-To: References: <32271364.3080.1330931558529.JavaMail.geo-discussion-forums@ynjd19> Message-ID: <19872402.359.1330968669581.JavaMail.geo-discussion-forums@ynnj12> > You will need to configure the root columns and rows also because the > configurations DO NOT propagate up the widget hierarchy! Actually, for > this example, I would recommend using the "pack" geometry manager on > the frame. Only use grid when you need to use grid. Never use any > functionality superfluously! Also, you should explicitly pack the > frame from OUTSIDE frame.__init__()! Ok, so use pack when putting the frame into the root, since that's all that goes into the root directly. But just out of curiosity, what did I do wrong with using grid? How would it work with grid? > from tkinter.constants import BOTH, YES > I always use either: > > sticky='nswe' > sticky=N+S+W+E This is something I'm not too thrilled with. I don't like importing things piecemeal. I suppose I could do: import tkinter.constants as tkc (or something like that) and qualify each constant. Seems like more work, but it just seems better than having to manage each constant that I need in the import list. Also, N+S+E+W and (N, S, E, W) don't seem to work unless qualified, so that's four more constants I'd have to explicitly import. And (tk.N, tk.S, tk.E, tk.W) is just horrible to look at. From rantingrickjohnson at gmail.com Mon Mar 5 14:03:23 2012 From: rantingrickjohnson at gmail.com (Rick Johnson) Date: Mon, 5 Mar 2012 11:03:23 -0800 (PST) Subject: Tkinter: Why aren't my widgets expanding when I resize the window? References: <32271364.3080.1330931558529.JavaMail.geo-discussion-forums@ynjd19> <19872402.359.1330968669581.JavaMail.geo-discussion-forums@ynnj12> Message-ID: <01a0499e-616f-4395-95d2-b6e54e03bc79@i5g2000yqo.googlegroups.com> On Mar 5, 11:31?am, John Salerno wrote: > Ok, so use pack when putting the frame into the root, since that's > all that goes into the root directly. But just out of curiosity, > what did I do wrong with using grid? How would it work with grid? If you read my post carefully, i said: "You need to use columnconfigure and rowconfigure on ROOT!". Here is the solution; although, not the correct code you should use because pack is perfect for this: ## START CODE ## import tkinter as tk import tkinter.ttk as ttk class AppFrame(ttk.Frame): def __init__(self, parent, **kwargs): super().__init__(parent, **kwargs) self.create_widgets() def create_widgets(self): entry = ttk.Entry(self) entry.grid(row=0, column=1, sticky='nsew') label = ttk.Label(self, text='Name:') label.grid(row=0, column=0, sticky='nsew') root = tk.Tk() root.title('Test Application') root.columnconfigure(0, weight=1) root.rowconfigure(0, weight=1) frame = AppFrame(root, borderwidth=15, relief='sunken') frame.grid(row=0, column=0, sticky='nsew') root.mainloop() ## END CODE ## > I don't like importing things piecemeal. I suppose I could do: So you prefer to pollute? How bout we just auto import the whole Python stdlib so you can save a few keystrokes? > import tkinter.constants as tkc (or something like that) > > and qualify each constant. Seems like more work, but it just seems > better than having to manage each constant that I need in the import > list. Then do "from tkinter.constants import *". I have no complaints against import all the constants during testing/building, however, you should be a professional and import only the constants you are going to use. > Also, N+S+E+W and (N, S, E, W) don't seem to work unless qualified, Of course not, you never imported them! How could that code possibly work? > so that's four more constants I'd have to explicitly import. And > (tk.N, tk.S, tk.E, tk.W) is just horrible to look at. Wah! Stop whining and act like a professional! You complain about qualifying constants but you happily type "self" until your fingers bleed without even a whimper??? Look, either import ONLY the constants you need, or qualify each constant with a module name/variable; that is the choices available to a professional. Or, just be lazy and pollute your namespace. FYI: Lazy coders get what they deserve in the end. From rowen at uw.edu Mon Mar 5 14:45:56 2012 From: rowen at uw.edu (Russell E. Owen) Date: Mon, 05 Mar 2012 11:45:56 -0800 Subject: Is it necessary to call Tk() when writing a GUI app with Tkinter? References: <27603449.17.1330492001624.JavaMail.geo-discussion-forums@vbbfv2> <6e1c521e-14be-4ec0-9ff0-7f23fd9cd3dc@f14g2000yqe.googlegroups.com> <3d0bf288-fa5d-48e5-9529-db92d420a915@1g2000yqv.googlegroups.com> Message-ID: In article <3d0bf288-fa5d-48e5-9529-db92d420a915 at 1g2000yqv.googlegroups.com>, Rick Johnson wrote: > On Feb 29, 11:24?pm, Terry Reedy wrote: > > On 2/29/2012 10:22 PM, Rick Johnson wrote: > > > > PS: I would highly suggest against using the "from Tkinter import *". > > > Instead, use "import Tkinter as tk" and prefix all module contents > > > with "tk.". > > > > I have changed the example to do that. I also showed the alternate to > > initialize a widget. Here is the current version, tested on Windows 3.2.2. > > > > import tkinter as tk > > > > class Application(tk.Frame): > > ? ? ?def __init__(self, master=None): > > ? ? ? ? ?tk.Frame.__init__(self, master) > > ? ? ? ? ?self.pack() > > With all due respect, I would also recommend against "self packing" a > widget. And i can speak from experience on this issue. There was a > time when i was self-packing lots of custom compund widgets; then i > realized later the shortcomings of such action; what if you need to > use the grid or place geometry mangers instead? So remove the > self.pack line and add a line to the bottom: > > > root = tk.Tk() > > app = Application(master=root) > > app.pack() # <-- added this line > > app.mainloop() I agree. Application is simply another widget, like Entry or Canvas. its contents should be packed or gridded (as appropriate) into itself, but the user should then pack or grid the Application widget as appropriate. That makes the code much more reusable. -- Russell From bob at brasko.net Mon Mar 5 15:36:39 2012 From: bob at brasko.net (Bob) Date: Mon, 5 Mar 2012 15:36:39 -0500 Subject: Error with co_filename when loading modules from zip file Message-ID: <20120305203639.GA13154@brasko> Hi, I'm using a program that distributes python in a zip file and ran into an issue with the logging package. It seems to return the wrong filename/line number when loading python from a zip file. Please help! I'm using python31, and have copied the lib directory to /home/user/python3.1 and have created a zip of that directory and placed it in /home/user/python3.1/python31.zip The logging package gets the filename and line number of the calling function by looking at two variables, the filename of the frame in the stack trace and the variable logging._srcfile. The comparison is done in logging/__init__.py:findCaller. In the situation above, when I run, PYTHONPATH=/home/user/python3.1 ./myexe run.py I see filename=/home/user/python3.1/logging/__init__.py _srcfile=/home/user/python3.1/logging/__init__.py Here, filename and _srcfile are the same, so the logger correctly outputs the filename of run.py. When I run, PYTHONPATH=/home/user/python3.1/python31.zip ./myexe run.py I see filename=/home/user/python3.1/logging/__init__.py _srcfile=/home/user/python3.1/python31.zip/logging/__init__.py Here, filename and _srcfile are different, so the logger incorrectly outputs the filename of /home/user/python3.1/logging/__init__.py I've noticed this: - the filename seems to be set when you compile the module - it seems to be set when you load the module (even after moving it) - it does not seem to get set when you load the module from the pyc in the zip file! I've tried putting only the pyc files, only the py files and both in the zip file. Any help? Thanks, Bob run.py: import logging class Handler(logging.Handler): def __init__(self): logging.Handler.__init__(self) def emit(self, record): print('message: ' + record.msg) print('filename: ' + record.pathname) print('line: ' + str(record.lineno)) logging.getLogger().addHandler(Handler()) logging.error('hi') From chris at simplistix.co.uk Mon Mar 5 16:56:34 2012 From: chris at simplistix.co.uk (Chris Withers) Date: Mon, 05 Mar 2012 21:56:34 +0000 Subject: xlutils 1.5.1 released! Message-ID: <4F553692.1070009@simplistix.co.uk> Hi All, xlutils 1.5.1 is out, fixing the usual embarrassing mistake I make when I move projects from Subversion to Git that results in some required non-.py files being omitted. All the details of where to find mailing lists, issue trackers, and the like for xlutils can be found here: http://www.simplistix.co.uk/software/python/xlutils cheers, Chris -- Simplistix - Content Management, Batch Processing & Python Consulting - http://www.simplistix.co.uk From johnjsal at gmail.com Mon Mar 5 17:07:05 2012 From: johnjsal at gmail.com (John Salerno) Date: Mon, 5 Mar 2012 14:07:05 -0800 (PST) Subject: Tkinter: Why aren't my widgets expanding when I resize the window? In-Reply-To: <01a0499e-616f-4395-95d2-b6e54e03bc79@i5g2000yqo.googlegroups.com> References: <32271364.3080.1330931558529.JavaMail.geo-discussion-forums@ynjd19> <19872402.359.1330968669581.JavaMail.geo-discussion-forums@ynnj12> <01a0499e-616f-4395-95d2-b6e54e03bc79@i5g2000yqo.googlegroups.com> Message-ID: <20757474.2202.1330985225312.JavaMail.geo-discussion-forums@ynlt17> > > I don't like importing things piecemeal. I suppose I could do: > > So you prefer to pollute? How bout we just auto import the whole > Python stdlib so you can save a few keystrokes? > > so that's four more constants I'd have to explicitly import. And > > (tk.N, tk.S, tk.E, tk.W) is just horrible to look at. > > Wah! > > Stop whining and act like a professional! You complain about > qualifying constants but you happily type "self" until your fingers > bleed without even a whimper??? > > Look, either import ONLY the constants you need, or qualify each > constant with a module name/variable; that is the choices available to > a professional. Or, just be lazy and pollute your namespace. > > FYI: Lazy coders get what they deserve in the end. How exactly am I being lazy and polluting the namespace? I never said I wanted to use the "*" import method, if that's what you are (wrongly) assuming. I said it seems cleaner and, to me, LESS lazy to import the whole module as "import tkinter.constants as tkc" and qualify everything. It's certainly more explicit than importing constants on an as-needed basis, having an ever-increasing list of constants, and referring to them unqualified in the code. Yes, I complain that tk.N, tk.S, etc. is ugly to look at, but I'm saying it seems like a better way than using them unqualified, unless maybe there is yet another, better way. As far as using "self" all the time, how do you know I never "whimpered" about it? The first time I learned about it I DIDN'T like it, because it seemed like a lot of unnecessary typing, but eventually I came to accept it because 1) you HAVE to do it, unlike the various options for referring to these constants, and 2) I began to like the explicitness of qualifying everything with "self." You are very helpful, but you sure like to throw around the term "lazy" a little too unabashedly. I never said I wanted to import with "*", which you seem to think I want to do. I LIKE qualifying things, which is the reason I didn't care so much for your method of importing the constants by name. From info at egenix.com Mon Mar 5 17:11:22 2012 From: info at egenix.com (eGenix Team: M.-A. Lemburg) Date: Mon, 05 Mar 2012 23:11:22 +0100 Subject: ANN: Python Meeting =?ISO-8859-1?Q?D=FCsseldorf_-_03=2E04=2E?= =?ISO-8859-1?Q?2012?= Message-ID: <4F553A0A.2070602@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 Ein Treffen von Python Enthusiasten und Interessierten in ungezwungener Atmosph?re. Dienstag, 03.04.2012, 18:00 Uhr Clara Schumann Raum DJH D?sseldorf http://python-meeting-duesseldorf.de/ Diese Nachricht k?nnen Sie auch online lesen: http://www.egenix.com/company/news/Python-Meeting-Duesseldorf-2012-04-03 ________________________________________________________________________ EINLEITUNG Das Python Meeting D?sseldorf ist eine neue lokale Veranstaltung in D?sseldorf, die sich an Python Begeisterte in der Region wendet. Wir starten bei den Treffen mit einer kurzen Einleitung und gehen dann zu einer Reihe Kurzvortr?gen (Lightning Talks) ?ber, bei denen die Anwesenden ?ber neue Projekte, interessante Probleme und sonstige Aktivit?ten rund um Python berichten k?nnen. Anschlie?end geht es in eine Gastst?tte, um die Gespr?che zu vertiefen. 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/ ________________________________________________________________________ ORT F?r das Python Meeting D?sseldorf haben wir den Clara Schumann Raum in der modernen Jugendherberge D?sseldorf angemietet: Jugendherberge D?sseldorf D?sseldorfer Str. 1 40545 D?sseldorf Telefon: +49 211 557310 http://www.duesseldorf.jugendherberge.de Die Jugendherberge verf?gt ?ber eine kostenpflichtige Tiefgarage (EUR 2,50 pro Stunde, maximal EUR 10,00). Es ist aber auch m?glich per Bus und Bahn anzureisen. Der Raum befindet sich im 1.OG links. ________________________________________________________________________ PROGRAMM Das Python Meeting D?sseldorf nutzt eine Mischung aus Open Space und Lightning Talks: Die Treffen starten mit einer kurzen Einleitung. Danach geht es weiter mit einer Lightning Talk Session, in der die Anwesenden Kurzvortr?ge von f?nf Minuten halten k?nnen. Hieraus ergeben sich dann meisten viele Ansatzpunkte f?r Diskussionen, die dann den Rest der verf?gbaren Zeit in Anspruch nehmen k?nnen. F?r 19:45 Uhr haben wir in einem nahegelegenen Restaurant Pl?tze reserviert, damit auch das leibliche Wohl nicht zu kurz kommt. 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. Da Tagungsraum, Beamer, Internet und Getr?nke Kosten produzieren, bitten wir die Teilnehmer um einen Beitrag in H?he von EUR 10,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://python-meeting-duesseldorf.de/ Mit freundlichen Gr??en, -- Marc-Andre Lemburg eGenix.com Professional Python Services directly from the Source (#1, Mar 05 2012) >>> Python/Zope Consulting and Support ... http://www.egenix.com/ >>> mxODBC.Zope.Database.Adapter ... http://zope.egenix.com/ >>> mxODBC, mxDateTime, mxTextTools ... http://python.egenix.com/ ________________________________________________________________________ 2012-02-13: Released eGenix pyOpenSSL 0.13 http://egenix.com/go26 2012-02-09: Released mxODBC.Zope.DA 2.0.2 http://egenix.com/go25 2012-02-06: Released eGenix mx Base 3.2.3 http://egenix.com/go24 ::: Try our new 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 vinay_sajip at yahoo.co.uk Mon Mar 5 17:22:55 2012 From: vinay_sajip at yahoo.co.uk (Vinay Sajip) Date: Mon, 5 Mar 2012 14:22:55 -0800 (PST) Subject: Error with co_filename when loading modules from zip file References: Message-ID: On Mar 5, 8:36?pm, Bob wrote: > The logging package gets the filename and line number > of the calling function by looking at two variables, the filename > of the frame in the stack trace and the variable logging._srcfile. > The comparison is done in logging/__init__.py:findCaller. > The _srcfile is computed in logging/__init__.py - can you see which of the paths it takes when computing _srcfile? > I've tried putting only the pyc files, only the py files > and both in the zip file. I think the filename info might be stored in the .pyc from when you ran it outside the .zip. If you delete all .pyc files and only have .py in the .zip, what happens? Regards, Vinay Sajip From python.list at tim.thechases.com Mon Mar 5 20:10:41 2012 From: python.list at tim.thechases.com (Tim Chase) Date: Mon, 05 Mar 2012 19:10:41 -0600 Subject: State of Python+OpenAL? Message-ID: <4F556411.9030304@tim.thechases.com> Hunting around to see if there's any existing work to get 3d audio in Python, I encountered two packages (pyopenal[1] & alpy[2]), but both seem sparsely documented if at all and somewhat abandoned. Has anybody used either, or have any pointers on getting up to speed on either? Thanks, -tkc [1] http://home.gna.org/oomadness/en/pyopenal/ https://github.com/forrestv/pyopenal [2] http://www.stolk.org/alpy/ From steve+comp.lang.python at pearwood.info Mon Mar 5 20:10:50 2012 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 06 Mar 2012 01:10:50 GMT Subject: Tkinter: Why aren't my widgets expanding when I resize the window? References: <32271364.3080.1330931558529.JavaMail.geo-discussion-forums@ynjd19> <19872402.359.1330968669581.JavaMail.geo-discussion-forums@ynnj12> <01a0499e-616f-4395-95d2-b6e54e03bc79@i5g2000yqo.googlegroups.com> <20757474.2202.1330985225312.JavaMail.geo-discussion-forums@ynlt17> Message-ID: <4f55641a$0$29989$c3e8da3$5496439d@news.astraweb.com> On Mon, 05 Mar 2012 14:07:05 -0800, John Salerno quoted: >> Wah! >> >> Stop whining and act like a professional! You complain about qualifying >> constants but you happily type "self" until your fingers bleed without >> even a whimper??? John, it is polite to leave attributions in place when you quote somebody. I don't know who you are quoting above, but given the obnoxious tone and the fact that this is about Tkinter, I'm guessing it is RantingRick, a.k.a. Rick Johnson. Rick is a notorious troll, and you'll probably save yourself a lot of grief if you pay no attention to him. It's not so much that his advice is *always* bad, but that you'll spend so many hours sifting through the piles of bad advice, unprofessional language, and annoying self- aggrandisement for the occasional nugget of gold that it just isn't worth it. Which is a pity, because I gather that Rick actually does know Tkinter well. But dealing with him is like wrestling with a pig: "I learned long ago, never to wrestle with a pig. You get dirty, and besides, the pig likes it." -- George Bernard Shaw -- Steven From xahlee at gmail.com Mon Mar 5 20:11:09 2012 From: xahlee at gmail.com (Xah Lee) Date: Mon, 5 Mar 2012 17:11:09 -0800 (PST) Subject: are int, float, long, double, side-effects of computer engineering? Message-ID: <5aaded58-af09-41dc-9afd-56d7b7ced239@d7g2000pbl.googlegroups.com> some additional info i thought is relevant. are int, float, long, double, side-effects of computer engineering? Xah Lee wrote: ?? One easy way to measure it is whether a programer can read and understand a program without having to delve into its idiosyncrasies. ?? Chris Angelico wrote: ?Neither the behavior of ints nor the behavior of IEEE floating point is a "quirk" or an "idiosyncracy". ?? they are computer engineering by-products. Are quirks and idiosyncracies. Check out a advanced lang such as Mathematica. There, one can learn how the mathematical concept of integer or real number are implemented in a computer language, without lots by-products of comp engineering as in vast majority of langs (all those that chalks up to some IEEEEEEE. (which, sadly, includes C, C++, perl, python, lisp, and almost all. (Common/Scheme lisp idiots speak of the jargon ?number tower? instead IEEEE.) (part of the reason almost all langs stick to some IEEEEEEEE stuff is because it's kinda standard, and everyone understand it, in the sense that unix RFC (aka really fucking common) is wide-spread because its free yet technically worst. (in a sense, when everybody's stupid, there arise a cost to not be stupid.)))). A friend asked: ?Can you enlighten us as to Mathematica's way of handling numbers, either by a post or a link to suitable documentation? ?? what i meant to point out is that Mathematica deals with numbers at a high-level human way. That is, one doesn't think in terms of float, long, int, double. These words are never mentioned. Instead, you have concepts of machine precision, accuracy. The lang automatically handle the translation to hardware, and invoking exact value or infinite precision as required or requested. in most lang's doc, words like int, long, double, float are part of the lang, and it's quick to mention IEEE. Then you have the wide- spread overflow issue in your lang. In M, the programer only need to think in terms of math, i.e. Real number, Integer, complex number, precision, accuracy, etc. this is what i meat that most lang deals with computer engineering by- products, and i wished them to be higher level like M. http://reference.wolfram.com/mathematica/guide/PrecisionAndAccuracyControl.html Xah From johnjsal at gmail.com Mon Mar 5 20:53:29 2012 From: johnjsal at gmail.com (John Salerno) Date: Mon, 5 Mar 2012 17:53:29 -0800 (PST) Subject: Tkinter: Why aren't my widgets expanding when I resize the window? In-Reply-To: <4f55641a$0$29989$c3e8da3$5496439d@news.astraweb.com> References: <32271364.3080.1330931558529.JavaMail.geo-discussion-forums@ynjd19> <19872402.359.1330968669581.JavaMail.geo-discussion-forums@ynnj12> <01a0499e-616f-4395-95d2-b6e54e03bc79@i5g2000yqo.googlegroups.com> <20757474.2202.1330985225312.JavaMail.geo-discussion-forums@ynlt17> <4f55641a$0$29989$c3e8da3$5496439d@news.astraweb.com> Message-ID: <25803773.4638.1330998809513.JavaMail.geo-discussion-forums@vbw15> On Monday, March 5, 2012 7:10:50 PM UTC-6, Steven D'Aprano wrote: > On Mon, 05 Mar 2012 14:07:05 -0800, John Salerno quoted: > > >> Wah! > >> > >> Stop whining and act like a professional! You complain about qualifying > >> constants but you happily type "self" until your fingers bleed without > >> even a whimper??? > > John, it is polite to leave attributions in place when you quote > somebody. I don't know who you are quoting above, but given the obnoxious > tone and the fact that this is about Tkinter, I'm guessing it is > RantingRick, a.k.a. Rick Johnson. > > Rick is a notorious troll, and you'll probably save yourself a lot of > grief if you pay no attention to him. It's not so much that his advice is > *always* bad, but that you'll spend so many hours sifting through the > piles of bad advice, unprofessional language, and annoying self- > aggrandisement for the occasional nugget of gold that it just isn't worth > it. > > Which is a pity, because I gather that Rick actually does know Tkinter > well. But dealing with him is like wrestling with a pig: > > "I learned long ago, never to wrestle with a pig. You get dirty, and > besides, the pig likes it." -- George Bernard Shaw > > > -- > Steven Thank you. Sorry about the attribution. That was my fault because I was trying to cite just the relevant bits, and I cut off the header too. From breamoreboy at yahoo.co.uk Mon Mar 5 20:58:22 2012 From: breamoreboy at yahoo.co.uk (Mark Lawrence) Date: Tue, 06 Mar 2012 01:58:22 +0000 Subject: Tkinter: Why aren't my widgets expanding when I resize the window? In-Reply-To: <4f55641a$0$29989$c3e8da3$5496439d@news.astraweb.com> References: <32271364.3080.1330931558529.JavaMail.geo-discussion-forums@ynjd19> <19872402.359.1330968669581.JavaMail.geo-discussion-forums@ynnj12> <01a0499e-616f-4395-95d2-b6e54e03bc79@i5g2000yqo.googlegroups.com> <20757474.2202.1330985225312.JavaMail.geo-discussion-forums@ynlt17> <4f55641a$0$29989$c3e8da3$5496439d@news.astraweb.com> Message-ID: On 06/03/2012 01:10, Steven D'Aprano wrote: > Which is a pity, because I gather that Rick actually does know Tkinter > well. +1. Please Rick less of the Dark Side. :) -- Cheers. Mark Lawrence. From bob at brasko.net Mon Mar 5 21:14:08 2012 From: bob at brasko.net (Bob Rossi) Date: Mon, 5 Mar 2012 21:14:08 -0500 Subject: Error with co_filename when loading modules from zip file In-Reply-To: References: Message-ID: <20120306021408.GB13154@brasko> On Mon, Mar 05, 2012 at 02:22:55PM -0800, Vinay Sajip wrote: > On Mar 5, 8:36?pm, Bob wrote: > > > The logging package gets the filename and line number > > of the calling function by looking at two variables, the filename > > of the frame in the stack trace and the variable logging._srcfile. > > The comparison is done in logging/__init__.py:findCaller. > > > > The _srcfile is computed in logging/__init__.py - can you see which of > the paths it takes when computing _srcfile? Yes, it's this one, elif __file__[-4:].lower() in ['.pyc', '.pyo']: _srcfile = __file__[:-4] + '.py' _srcfile I beleive is correct. It's filename that isn't IMHO. > > I've tried putting only the pyc files, only the py files > > and both in the zip file. > > I think the filename info might be stored in the .pyc from when you > ran it outside the .zip. If you delete all .pyc files and only > have .py in the .zip, what happens? Nice one. I tried putting only pyc file, only py files and both in the zip. But I never tried putting the py files in the zip and deleting the pyc files. That makes it work as I'm guessing it has to recompile the python bytecode, making the filename and _srcfile match. The problem with this approach, is that it's less efficient to store the pyc files, since I've got to recompile them on startup, right? I found this issue, http://bugs.python.org/issue6811 and this related patch, http://hg.python.org/cpython/rev/5deb2094f033 that I think might address this issue. Although that's using 3.3 which isn't released yet. This is probably an issue that could be addressed in the logging library. Comparing the compiled in filename (which is determined at compile time) and the source file name (which is determined at module load time) doesn't seem to play well when you are moving the interpreter around in a zip file. I don't think one would expect it to. One solution would be to look to see if the filename ends in pythonNM[.zip]/logging/__init__.py Any suggestions? Thanks, Bob From breamoreboy at yahoo.co.uk Mon Mar 5 21:14:30 2012 From: breamoreboy at yahoo.co.uk (Mark Lawrence) Date: Tue, 06 Mar 2012 02:14:30 +0000 Subject: are int, float, long, double, side-effects of computer engineering? In-Reply-To: <5aaded58-af09-41dc-9afd-56d7b7ced239@d7g2000pbl.googlegroups.com> References: <5aaded58-af09-41dc-9afd-56d7b7ced239@d7g2000pbl.googlegroups.com> Message-ID: On 06/03/2012 01:11, Xah Lee wrote: > some additional info i thought is relevant. > > are int, float, long, double, side-effects of computer engineering? > Whatever you're taking please can I have some? Is it available via an NHS prescription or do I have to go private, or do I go down the pub and get it illegally? -- Cheers. Mark Lawrence. From cookfitz at gmail.com Mon Mar 5 21:17:58 2012 From: cookfitz at gmail.com (nac) Date: Mon, 5 Mar 2012 18:17:58 -0800 (PST) Subject: RotatingFileHandler Fails References: Message-ID: <64b7d1bb-21b0-4c72-aa93-692504201f7e@j8g2000yqm.googlegroups.com> On Mar 5, 4:27?am, Jean-Michel Pichavant wrote: > nac wrote: > > The RotatingFileHandler running on win 7 64-bit; py 2.7 is failing > > when the script launches a process using subprocess.Popen. Works fine > > if the subprocess is not launched > > > The exception thrown > > Traceback (most recent call last): > > ? File "C:\Python27\lib\logging\handlers.py", line 78, in emit > > ? ? self.doRollover() > > ? File "C:\Python27\lib\logging\handlers.py", line 141, in doRollover > > ? ? os.rename(self.baseFilename, dfn) > > WindowsError: [Error 32] The process cannot access the file because it > > is being used by another process > > > Anyone have an idea how to fix this? > > > import os, sys > > import logging > > import logging.handlers > > import subprocess > > > def chomp(s): > > ? ? ? "remove trailing carriage return" > > ? ? ? if s[-1:]=='\n': return s[:-1] > > ? ? ? else: return s > > > logging.basicConfig(level=logging.DEBUG, format='%(asctime)s % > > (name)-2s %(levelname)-8s %(threadName)-12s %(message)s') > > q5Logger = logging.getLogger('Q5') > > logFileHandler = logging.handlers.RotatingFileHandler(filename='c:\ > > \logger\\q5.log', mode= 'a', maxBytes=100, backupCount=5) > > logFileHandler.setFormatter(logging.Formatter('%(asctime)s %(name)-2s % > > (levelname)-8s %(threadName)-12s %(message)s')) > > logFileHandler.setLevel(logging.DEBUG) > > q5Logger.addHandler(logFileHandler) > > > progOutput = subprocess.Popen(r'dir *.*', shell=True, bufsize=1000, > > stdout=subprocess.PIPE).stdout > > line = progOutput.readline() > > while (line) != "": > > ? ? ? q5Logger.info( chomp(line)) > > ? ? ? line = progOutput.readline() > > rc = progOutput.close() > > I don't think you can open a file from 2 different processes, hence the > error message. The only exception would be that one of them opens it in > read only mode which won't happen for log file. > > You cannot fix it, it is the operand system that blocks the operation. > Using thread may allow you to log into the same file, but could bring a > bunch of other problems. > > I know some ppl use a log server, your processes using a socket (client) > logger. You could do that on your local machine. There's a tutorial on > that in the logging documentation. > > JM Thanks for taking the time to look at the problem. In case you are interested I was able to get this to work with the code at URL below. Seemed to work because the subprocess I am running is not actually using the log file but the OS make it inherit a handle to the log file. The code below disables that inheritance. Do you see any problems with the approach? http://bugs.python.org/file14420/NTSafeLogging.py From rantingrickjohnson at gmail.com Mon Mar 5 21:20:36 2012 From: rantingrickjohnson at gmail.com (Rick Johnson) Date: Mon, 5 Mar 2012 18:20:36 -0800 (PST) Subject: Tkinter: Why aren't my widgets expanding when I resize the window? References: <32271364.3080.1330931558529.JavaMail.geo-discussion-forums@ynjd19> <19872402.359.1330968669581.JavaMail.geo-discussion-forums@ynnj12> <01a0499e-616f-4395-95d2-b6e54e03bc79@i5g2000yqo.googlegroups.com> <20757474.2202.1330985225312.JavaMail.geo-discussion-forums@ynlt17> <4f55641a$0$29989$c3e8da3$5496439d@news.astraweb.com> Message-ID: <29142434-eeaf-4c94-8d64-f1f2d4cb500e@t15g2000yqi.googlegroups.com> On Mar 5, 7:10?pm, Steven D'Aprano wrote: > John, it is polite to leave attributions in place when you quote > somebody. I don't know who you are quoting above, > [...] > Which is a pity, because I gather that Rick actually does know Tkinter > well. My, my. Between your ad hominem attacks, FUD, wild assumptions, and veiled insults you did manage to get ONE small sentence of truthful content to propagate up; congratulations! Excuse me whist i toss my cookies! > But dealing with him is like wrestling with a pig: And there it is again. We can't admit Rick is correct without insulting him. But Steven, when have you EVER dealt with me on a professional level? When have you EVER offered a helping hand to one of my issues? For example: I can remember asking you to explain the new .format method of Py3000 and you said: "Sorry, too busy!". But you where not too busy to troll-up the list! WHEN have you ever admitted (without insulting me first) that i am in fact an asset to this community? Do you think this community will ever be a homogeneous block? And if so, would that be a good thing? I have an idea: How about YOU stop clinging to some archaic ideal of what YOU *think* this community *should* be, and instead, start opening up your mind to diverse personalities and diverse ideas. Heck, maybe you'll learn something new, "old dog". Remember how much you ranted about diversity in evolution? And now you have the AUDACITY to preach the opposite just to suit your own selfish argument. You are as hollow as a politician Steven. Nothing that you say can be taken seriously because it is just more propaganda and lies. And one more thing, If ANYONE on this list deserves "thespian of the year" award, it is you my friend! Between your comeo appearances as "Devils Advocate", "Sammy the Strawman Stuffer", "Snarky Detractor", and the ever-present "Troll Slayer" (saving damsels in distress from the trolls of c.l.p) -- i'd say you have the nomination won by a landslide! From breamoreboy at yahoo.co.uk Mon Mar 5 21:33:03 2012 From: breamoreboy at yahoo.co.uk (Mark Lawrence) Date: Tue, 06 Mar 2012 02:33:03 +0000 Subject: Tkinter: Why aren't my widgets expanding when I resize the window? In-Reply-To: <29142434-eeaf-4c94-8d64-f1f2d4cb500e@t15g2000yqi.googlegroups.com> References: <32271364.3080.1330931558529.JavaMail.geo-discussion-forums@ynjd19> <19872402.359.1330968669581.JavaMail.geo-discussion-forums@ynnj12> <01a0499e-616f-4395-95d2-b6e54e03bc79@i5g2000yqo.googlegroups.com> <20757474.2202.1330985225312.JavaMail.geo-discussion-forums@ynlt17> <4f55641a$0$29989$c3e8da3$5496439d@news.astraweb.com> <29142434-eeaf-4c94-8d64-f1f2d4cb500e@t15g2000yqi.googlegroups.com> Message-ID: On 06/03/2012 02:20, Rick Johnson wrote: > On Mar 5, 7:10 pm, Steven D'Aprano +comp.lang.pyt... at pearwood.info> wrote: > >> John, it is polite to leave attributions in place when you quote >> somebody. I don't know who you are quoting above, >> [...] >> Which is a pity, because I gather that Rick actually does know Tkinter >> well. > > My, my. Between your ad hominem attacks, FUD, wild assumptions, and > veiled insults you did manage to get ONE small sentence of truthful > content to propagate up; congratulations! Excuse me whist i toss my > cookies! > >> But dealing with him is like wrestling with a pig: > > And there it is again. We can't admit Rick is correct without > insulting him. > > But Steven, when have you EVER dealt with me on a professional level? > When have you EVER offered a helping hand to one of my issues? For > example: I can remember asking you to explain the new .format method > of Py3000 and you said: "Sorry, too busy!". But you where not too busy > to troll-up the list! WHEN have you ever admitted (without insulting > me first) that i am in fact an asset to this community? Do you think > this community will ever be a homogeneous block? And if so, would that > be a good thing? > > I have an idea: How about YOU stop clinging to some archaic ideal of > what YOU *think* this community *should* be, and instead, start > opening up your mind to diverse personalities and diverse ideas. Heck, > maybe you'll learn something new, "old dog". Remember how much you > ranted about diversity in evolution? And now you have the AUDACITY to > preach the opposite just to suit your own selfish argument. You are as > hollow as a politician Steven. Nothing that you say can be taken > seriously because it is just more propaganda and lies. > > And one more thing, If ANYONE on this list deserves "thespian of the > year" award, it is you my friend! Between your comeo appearances as > "Devils Advocate", "Sammy the Strawman Stuffer", "Snarky Detractor", > and the ever-present "Troll Slayer" (saving damsels in distress from > the trolls of c.l.p) -- i'd say you have the nomination won by a > landslide! > There is no need for this. You (as I've stated in another reply) seem to know what you're talking about WRT tkinter so please stick with the Light rather than the Dark Side. -- Cheers. Mark Lawrence. From bob at brasko.net Mon Mar 5 21:40:07 2012 From: bob at brasko.net (Bob Rossi) Date: Mon, 5 Mar 2012 21:40:07 -0500 Subject: Error with co_filename when loading modules from zip file In-Reply-To: References: Message-ID: <20120306024006.GE13154@brasko> On Mon, Mar 05, 2012 at 02:22:55PM -0800, Vinay Sajip wrote: > On Mar 5, 8:36?pm, Bob wrote: > > > The logging package gets the filename and line number > > of the calling function by looking at two variables, the filename > > of the frame in the stack trace and the variable logging._srcfile. > > The comparison is done in logging/__init__.py:findCaller. > > > > The _srcfile is computed in logging/__init__.py - can you see which of > the paths it takes when computing _srcfile? > > > I've tried putting only the pyc files, only the py files > > and both in the zip file. > > I think the filename info might be stored in the .pyc from when you > ran it outside the .zip. If you delete all .pyc files and only > have .py in the .zip, what happens? Darn it, this was reported in 2007 http://bugs.python.org/issue1180193 and it was mentioned the logging package was effected. Yikes. Any resolutions? Bob From rantingrickjohnson at gmail.com Mon Mar 5 21:56:12 2012 From: rantingrickjohnson at gmail.com (Rick Johnson) Date: Mon, 5 Mar 2012 18:56:12 -0800 (PST) Subject: Tkinter: Why aren't my widgets expanding when I resize the window? References: <32271364.3080.1330931558529.JavaMail.geo-discussion-forums@ynjd19> <19872402.359.1330968669581.JavaMail.geo-discussion-forums@ynnj12> <01a0499e-616f-4395-95d2-b6e54e03bc79@i5g2000yqo.googlegroups.com> <20757474.2202.1330985225312.JavaMail.geo-discussion-forums@ynlt17> <4f55641a$0$29989$c3e8da3$5496439d@news.astraweb.com> <29142434-eeaf-4c94-8d64-f1f2d4cb500e@t15g2000yqi.googlegroups.com> Message-ID: <69af9e72-270f-4ba9-a24c-dfc81a965afd@k29g2000yqc.googlegroups.com> On Mar 5, 8:33?pm, Mark Lawrence wrote: > please stick with the > Light rather than the Dark Side. You're correct. I need to ignore these negative distractions. Thanks for re-focusing the conversation. From breamoreboy at yahoo.co.uk Mon Mar 5 22:09:16 2012 From: breamoreboy at yahoo.co.uk (Mark Lawrence) Date: Tue, 06 Mar 2012 03:09:16 +0000 Subject: Tkinter: Why aren't my widgets expanding when I resize the window? In-Reply-To: <69af9e72-270f-4ba9-a24c-dfc81a965afd@k29g2000yqc.googlegroups.com> References: <32271364.3080.1330931558529.JavaMail.geo-discussion-forums@ynjd19> <19872402.359.1330968669581.JavaMail.geo-discussion-forums@ynnj12> <01a0499e-616f-4395-95d2-b6e54e03bc79@i5g2000yqo.googlegroups.com> <20757474.2202.1330985225312.JavaMail.geo-discussion-forums@ynlt17> <4f55641a$0$29989$c3e8da3$5496439d@news.astraweb.com> <29142434-eeaf-4c94-8d64-f1f2d4cb500e@t15g2000yqi.googlegroups.com> <69af9e72-270f-4ba9-a24c-dfc81a965afd@k29g2000yqc.googlegroups.com> Message-ID: On 06/03/2012 02:56, Rick Johnson wrote: > On Mar 5, 8:33 pm, Mark Lawrence wrote: >> please stick with the >> Light rather than the Dark Side. > > You're correct. I need to ignore these negative distractions. Thanks > for re-focusing the conversation. No problem, but as I've often stated in the past my normal professional fee applies which is two (2) pints of Ringwood Old Thumper or equivalent should you ever be in my neck of the woods. :) http://www.ringwoodbrewery.co.uk/beers/beer.aspx?bid=3 -- Cheers. Mark Lawrence. From anikom15 at gmail.com Mon Mar 5 22:17:37 2012 From: anikom15 at gmail.com (Westley =?iso-8859-1?Q?Mart=EDnez?=) Date: Mon, 5 Mar 2012 19:17:37 -0800 Subject: are int, float, long, double, side-effects of computer engineering? In-Reply-To: <5aaded58-af09-41dc-9afd-56d7b7ced239@d7g2000pbl.googlegroups.com> References: <5aaded58-af09-41dc-9afd-56d7b7ced239@d7g2000pbl.googlegroups.com> Message-ID: <20120306031736.GA30612@kubrick> On Mon, Mar 05, 2012 at 05:11:09PM -0800, Xah Lee wrote: > some additional info i thought is relevant. > > are int, float, long, double, side-effects of computer engineering? > > Xah Lee wrote: > ?? One easy way to measure it is whether a programer can read and > understand a program without having to delve into its idiosyncrasies. > ?? > > Chris Angelico wrote: > ?Neither the behavior of ints nor the behavior of IEEE floating point > is a "quirk" or an "idiosyncracy". ?? > > they are computer engineering by-products. Are quirks and > idiosyncracies. Check out a advanced lang such as Mathematica. There, > one can learn how the mathematical concept of integer or real number > are implemented in a computer language, without lots by-products of > comp engineering as in vast majority of langs (all those that chalks > up to some IEEEEEEE. (which, sadly, includes C, C++, perl, python, > lisp, and almost all. (Common/Scheme lisp idiots speak of the jargon > ?number tower? instead IEEEE.) (part of the reason almost all langs > stick to some IEEEEEEEE stuff is because it's kinda standard, and > everyone understand it, in the sense that unix RFC (aka really fucking > common) is wide-spread because its free yet technically worst. (in a > sense, when everybody's stupid, there arise a cost to not be > stupid.)))). > > > A friend asked: ?Can you enlighten us as to Mathematica's way of > handling numbers, either by a post or a link to suitable > documentation? ?? > > what i meant to point out is that Mathematica deals with numbers at a > high-level human way. That is, one doesn't think in terms of float, > long, int, double. These words are never mentioned. Instead, you have > concepts of machine precision, accuracy. The lang automatically handle > the translation to hardware, and invoking exact value or infinite > precision as required or requested. > > in most lang's doc, words like int, long, double, float are part of > the lang, and it's quick to mention IEEE. Then you have the wide- > spread overflow issue in your lang. In M, the programer only need to > think in terms of math, i.e. Real number, Integer, complex number, > precision, accuracy, etc. > > this is what i meat that most lang deals with computer engineering by- > products, and i wished them to be higher level like M. > > http://reference.wolfram.com/mathematica/guide/PrecisionAndAccuracyControl.html Try Fortran. From timr at probo.com Tue Mar 6 00:26:21 2012 From: timr at probo.com (Tim Roberts) Date: Mon, 05 Mar 2012 21:26:21 -0800 Subject: are int, float, long, double, side-effects of computer engineering? References: <5aaded58-af09-41dc-9afd-56d7b7ced239@d7g2000pbl.googlegroups.com> Message-ID: Xah Lee wrote: > >some additional info i thought is relevant. > >are int, float, long, double, side-effects of computer engineering? Of course they are. Such concepts violate the purity of a computer language's abstraction of the underlying hardware. We accept that violation because of performance reasons. There are, as you point out, languages that do maintain the purity of the abstraction, but that purity is ALWAYS at the expense of performance. I would also point out pre-emptively that there is nothing inherently wrong with asking us to accept an impure abstraction in exchange for performance. It is a performance choice that we choose to make. -- Tim Roberts, timr at probo.com Providenza & Boekelheide, Inc. From xahlee at gmail.com Tue Mar 6 01:34:46 2012 From: xahlee at gmail.com (Xah Lee) Date: Mon, 5 Mar 2012 22:34:46 -0800 (PST) Subject: are int, float, long, double, side-effects of computer engineering? References: <5aaded58-af09-41dc-9afd-56d7b7ced239@d7g2000pbl.googlegroups.com> Message-ID: On Mar 5, 9:26?pm, Tim Roberts wrote: > Xah Lee wrote: > > >some additional info i thought is relevant. > > >are int, float, long, double, side-effects of computer engineering? > > Of course they are. ?Such concepts violate the purity of a computer > language's abstraction of the underlying hardware. ?We accept that > violation because of performance reasons. ?There are, as you point out, > languages that do maintain the purity of the abstraction, but that purity > is ALWAYS at the expense of performance. > > I would also point out pre-emptively that there is nothing inherently wrong > with asking us to accept an impure abstraction in exchange for performance. > It is a performance choice that we choose to make. while what you said is true, but the problem is that 99.99% of programers do NOT know this. They do not know Mathematica. They've never seen a language with such feature. The concept is alien. This is what i'd like to point out and spread awareness. also, argument about raw speed and fine control vs automatic management, rots with time. Happened with auto memory management, managed code, compilers, auto type conversion, auto extension of array, auto type system, dynamic/scripting languages, etc. i'd share this these talks: ?Programing Language: Steve Yegge on Dynamic Languages? http://xahlee.org/comp/Steve_Yegge_on_dynamic_languages.html ?Guy Steele on Parallel Programing: Get rid of cons!? http://xahlee.org/comp/Guy_Steele_parallel_computing.html ?Ocaml Use in Industry (Janestreet Talk by Yaron Minsky)? http://xahlee.org/comp/Yaron_Minsky_Janestreet_talk.html ?Stephen Wolfram: The Background and Vision of Mathematica ? http://xahlee.blogspot.com/2011/10/stephen-wolfram-background-and-vision.html Xah From russ.paielli at gmail.com Tue Mar 6 03:02:22 2012 From: russ.paielli at gmail.com (Russ P.) Date: Tue, 6 Mar 2012 00:02:22 -0800 (PST) Subject: are int, float, long, double, side-effects of computer engineering? References: <5aaded58-af09-41dc-9afd-56d7b7ced239@d7g2000pbl.googlegroups.com> Message-ID: <10cca95e-69a5-4c36-9eb4-564b738cc158@x5g2000pbl.googlegroups.com> On Mar 5, 10:34?pm, Xah Lee wrote: > On Mar 5, 9:26?pm, Tim Roberts wrote: > > > Xah Lee wrote: > > > >some additional info i thought is relevant. > > > >are int, float, long, double, side-effects of computer engineering? > > > Of course they are. ?Such concepts violate the purity of a computer > > language's abstraction of the underlying hardware. ?We accept that > > violation because of performance reasons. ?There are, as you point out, > > languages that do maintain the purity of the abstraction, but that purity > > is ALWAYS at the expense of performance. > > > I would also point out pre-emptively that there is nothing inherently wrong > > with asking us to accept an impure abstraction in exchange for performance. > > It is a performance choice that we choose to make. > > while what you said is true, but the problem is that 99.99% of > programers do NOT know this. They do not know Mathematica. They've > never seen a language with such feature. The concept is alien. This is > what i'd like to point out and spread awareness. I seriously doubt that. I think most decent programmers are well aware of the limitations of floating point math. If properly used, double- precision arithmetic is more than adequate for the vast majority of practical scientific and engineering problems. > also, argument about raw speed and fine control vs automatic > management, rots with time. Happened with auto memory management, > managed code, compilers, auto type conversion, auto extension of > array, auto type system, dynamic/scripting languages, etc. First of all, "dynamic/scripting languages" are still a long, long way from being "fast enough" for computationally intensive applications. Secondly, nothing is stopping anyone from writing a library to implement rational numbers or infinite-precision arithmetic in python (or just about any other language). They are just not needed for most applications. From seomurthy at gmail.com Tue Mar 6 04:14:18 2012 From: seomurthy at gmail.com (Murthy) Date: Tue, 6 Mar 2012 01:14:18 -0800 (PST) Subject: Free Computer Hacking Tips Message-ID: <8326f9db-3cf6-48ab-b225-ed23193bfd8a@z5g2000pbu.googlegroups.com> Free Computer Hacking Tips - http://computertipzz.blogspot.com From chiron613.no.spam. at no.spam.please.gmail.com Tue Mar 6 05:00:44 2012 From: chiron613.no.spam. at no.spam.please.gmail.com (Chiron) Date: Tue, 06 Mar 2012 10:00:44 GMT Subject: are int, float, long, double, side-effects of computer engineering? References: <5aaded58-af09-41dc-9afd-56d7b7ced239@d7g2000pbl.googlegroups.com> Message-ID: On Mon, 05 Mar 2012 17:11:09 -0800, Xah Lee wrote: Yes. Why do you ask? Is this not obvious? Was this a rhetorical question? -- A girl with a future avoids the man with a past. -- Evan Esar, "The Humor of Humor" From chiron613.no.spam. at no.spam.please.gmail.com Tue Mar 6 05:10:11 2012 From: chiron613.no.spam. at no.spam.please.gmail.com (Chiron) Date: Tue, 06 Mar 2012 10:10:11 GMT Subject: are int, float, long, double, side-effects of computer engineering? References: <5aaded58-af09-41dc-9afd-56d7b7ced239@d7g2000pbl.googlegroups.com> Message-ID: <7ol5r.29957$zD5.14377@newsfe12.iad> On Mon, 05 Mar 2012 22:34:46 -0800, Xah Lee wrote: > while what you said is true, but the problem is that 99.99% of > programers do NOT know this. They do not know Mathematica. They've never > seen a Could you please offer some evidence to support this claim? Most of the programmers I've ever run into, were quite familiar with the notion that many aspects of their languages were artifacts of hardware limitations. You don't need Mathematica to figure out that (10.0 * 0.1) - 1.0 doesn't often equal 0.0. The moment you try such comparisons with floats, you figure it out. Oh, granted - the *first* time you try it, you might spend days trying to understand what's wrong. But having done that, you will never, ever fail to understand about the evils of computer engineering. Anyway, most programmers probably get burned like this early on, if they forget that numeric representations in most languages are inaccurate. They don't need Mathematica to help them understand. BTW, for those who don't have access to Mathematica, I highly recommend sagemath. I have no way of making a comparison between the two (I have no access to Mathematica), but sagemath is mature, useful, and fast. -- You will be singled out for promotion in your work. From vinay_sajip at yahoo.co.uk Tue Mar 6 05:38:50 2012 From: vinay_sajip at yahoo.co.uk (Vinay Sajip) Date: Tue, 6 Mar 2012 02:38:50 -0800 (PST) Subject: Error with co_filename when loading modules from zip file References: Message-ID: <6c8fd85f-b489-450e-82a4-ee01b231a09f@n12g2000yqb.googlegroups.com> On Mar 6, 2:40?am, Bob Rossi wrote: > Darn it, this was reported in 2007 > ?http://bugs.python.org/issue1180193 > and it was mentioned the logging package was effected. > > Yikes. > I will think about this, but don't expect any quick resolution :-( I think the right fix would be not in the logging package, but in the module loading machinery (as mentioned on that issue). I wouldn't worry about the performance aspect - once the logging package is loaded, there's no performance impact. That's a tiny one- off hit which you will probably not notice at all. Regards, Vinay Sajip From ndbecker2 at gmail.com Tue Mar 6 07:34:34 2012 From: ndbecker2 at gmail.com (Neal Becker) Date: Tue, 06 Mar 2012 07:34:34 -0500 Subject: pickle/unpickle class which has changed Message-ID: What happens if I pickle a class, and later unpickle it where the class now has added some new attributes? From xahlee at gmail.com Tue Mar 6 08:11:40 2012 From: xahlee at gmail.com (Xah Lee) Date: Tue, 6 Mar 2012 05:11:40 -0800 (PST) Subject: a interesting Parallel Programing Problem: asciify-string Message-ID: <210c7726-b189-4824-8560-d5ad25ac7583@9g2000pbn.googlegroups.com> here's a interesting problem that we are discussing at comp.lang.lisp. ?Parallel Programing Problem: asciify-string? http://xahlee.org/comp/parallel_programing_exercise_asciify-string.html here's the plain text. Code example is emacs lisp, but the problem is general. for a bit python relevancy? is there any python compiler that's parallel-algorithm aware? ----------------------------------------------- Parallel Programing Problem: asciify-string Here's a interesting parallel programing problem. Problem Description The task is to change this function so it's parallelable. (code example in emacs lisp) (defun asciify-string (inputStr) "Make Unicode string into equivalent ASCII ones." (setq inputStr (replace-regexp-in-string "?\\|?\\|?\\|?" "a" inputStr)) (setq inputStr (replace-regexp-in-string "?\\|?\\|?\\|?" "e" inputStr)) (setq inputStr (replace-regexp-in-string "?\\|?\\|?\\|?" "i" inputStr)) (setq inputStr (replace-regexp-in-string "?\\|?\\|?\\|?" "o" inputStr)) (setq inputStr (replace-regexp-in-string "?\\|?\\|?\\|?" "u" inputStr)) inputStr ) Here's a more general description of the problem. You are given a Unicode text file that's a few peta bytes. For certain characters in the file, they need to be changed to different char. (For example of practical application, see: IDN homograph attack ? Duplicate characters in Unicode.) One easy solution is to simply use regex, as the above sample code, to search thru the file sequentially, and perform the transfrom of a particular set of chars, then repeat for each char chat needs to be changed. But your task is to use a algorithm parallelizable. That is, in a parallel-algorithm aware language (e.g. Fortress), the compiler will automatically span the computation to multiple processors. Refer to Guy Steele's video talk if you haven't seen already. See: Guy Steele on Parallel Programing. Solution Suggestions A better way to write it for parallel programing, is to map a char- transform function to each char in the string. Here's a pseudo-code in lisp by Helmut Eller: (defun asciify-char (c) (case c ((? ? ? ?) ?a) ((? ? ? ?) ?e) ((? ? ? ?) ?i) ((? ? ? ?) ?o) ((? ? ? ?) ?u) (t c))) (defun asciify-string (string) (map 'string #'asciify-string string)) One problem with this is that the function ?asciify-char? itself is sequential, and not 100% parallelizable. (we might assume here that there are billions of chars in Unicode that needs to be transformed) It would be a interesting small project, if someone actually use a parallel-algorithm-aware language to work on this problem, and report on the break-point of file-size of parallel-algorithm vs sequential- algorithm. Anyone would try it? Perhaps in Fortress, Erlang, Ease, Alice, X10, or other? Is the Clojure parallel aware? Xah From bob at brasko.net Tue Mar 6 08:41:32 2012 From: bob at brasko.net (Bob Rossi) Date: Tue, 6 Mar 2012 08:41:32 -0500 Subject: Error with co_filename when loading modules from zip file In-Reply-To: <6c8fd85f-b489-450e-82a4-ee01b231a09f@n12g2000yqb.googlegroups.com> References: <6c8fd85f-b489-450e-82a4-ee01b231a09f@n12g2000yqb.googlegroups.com> Message-ID: <20120306134131.GA14891@brasko> On Tue, Mar 06, 2012 at 02:38:50AM -0800, Vinay Sajip wrote: > On Mar 6, 2:40?am, Bob Rossi wrote: > > > Darn it, this was reported in 2007 > > ?http://bugs.python.org/issue1180193 > > and it was mentioned the logging package was effected. > > > > Yikes. > > > > I will think about this, but don't expect any quick resolution :-( I > think the right fix would be not in the logging package, but in the > module loading machinery (as mentioned on that issue). > > I wouldn't worry about the performance aspect - once the logging > package is loaded, there's no performance impact. That's a tiny one- > off hit which you will probably not notice at all. OK. Do you know where the bytecode gets stored when you load a py file from a zip? My program can potentially run for hours, from an embedded context, and could call into the logger and other py files over and over. Are the bytecode files stored in RAM one time, or recomputed each time they are needed? Thanks, Bob From roy at panix.com Tue Mar 6 08:49:33 2012 From: roy at panix.com (Roy Smith) Date: Tue, 06 Mar 2012 08:49:33 -0500 Subject: are int, float, long, double, side-effects of computer engineering? References: <5aaded58-af09-41dc-9afd-56d7b7ced239@d7g2000pbl.googlegroups.com> <7ol5r.29957$zD5.14377@newsfe12.iad> Message-ID: [intentionally violating the followup-to header] In article <7ol5r.29957$zD5.14377 at newsfe12.iad>, Chiron wrote: > On Mon, 05 Mar 2012 22:34:46 -0800, Xah Lee wrote: > > > while what you said is true, but the problem is that 99.99% of > > programers do NOT know this. They do not know Mathematica. They've never > > seen a > > Could you please offer some evidence to support this claim? Most of the > programmers I've ever run into, were quite familiar with the notion that > many aspects of their languages were artifacts of hardware limitations. While I doubt Xah's claim that 99.99% of programmers are unaware of this, oddly enough, we ran across an instance of this just yesterday. We have a test problem we give to job candidates: > Write a program that counts the number of times the subsequence "1, 2, 3" > appears in the first 100,000 digits of pi. Note "subsequence" does not imply > consecutive digits. For example, "1, 2, 3" appears in "3.141592653" twice. > You may use Google or the link above to find the digits of pi. Please include > the correct count when submitting your application. We had a candidate submit a solution in Python which ran in O(n) time. The algorithm was essentially correct, but unfortunately, he used a numpy.array to hold some counters, and suffered integer overflow. Had he used regular python lists, he would have been fine. What's unclear (at the moment) is whether he falls into Xah's camp of people who are unaware of such issues (unlikely, IMHO). Possibly he just didn't realize that the numbers in this problem might get big enough to overflow a 32-bit int. Or had been lulled into a false sense of security knowing that python does arbitrary precision integer math and didn't realize that doesn't extend to numpy. From __peter__ at web.de Tue Mar 6 08:52:11 2012 From: __peter__ at web.de (Peter Otten) Date: Tue, 06 Mar 2012 14:52:11 +0100 Subject: pickle/unpickle class which has changed References: Message-ID: Neal Becker wrote: > What happens if I pickle a class, and later unpickle it where the class > now has added some new attributes? - If the added attributes' values are immutable, provide defaults as class attributes. - Implement an appropriate __setstate__() method. The easiest would be # untested def __setstate__(self, state): self.__dict__.update(newattr1=42, newattr2=[]) self.__dict__.update(state) From steve+comp.lang.python at pearwood.info Tue Mar 6 08:55:12 2012 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 06 Mar 2012 13:55:12 GMT Subject: pickle/unpickle class which has changed References: Message-ID: <4f561740$0$29989$c3e8da3$5496439d@news.astraweb.com> On Tue, 06 Mar 2012 07:34:34 -0500, Neal Becker wrote: > What happens if I pickle a class, and later unpickle it where the class > now has added some new attributes? Why don't you try it? py> import pickle py> class C: ... a = 23 ... py> c = C() py> pickled = pickle.dumps(c) py> C.b = 42 # add a new class attribute py> d = pickle.loads(pickled) py> d.a 23 py> d.b 42 Unless you mean something different from this, adding attributes to the class is perfectly fine. But... why are you dynamically adding attributes to the class? Isn't that rather unusual? -- Steven From __peter__ at web.de Tue Mar 6 08:59:48 2012 From: __peter__ at web.de (Peter Otten) Date: Tue, 06 Mar 2012 14:59:48 +0100 Subject: Error with co_filename when loading modules from zip file References: <6c8fd85f-b489-450e-82a4-ee01b231a09f@n12g2000yqb.googlegroups.com> <20120306134131.GA14891@brasko> Message-ID: Bob Rossi wrote: > On Tue, Mar 06, 2012 at 02:38:50AM -0800, Vinay Sajip wrote: >> On Mar 6, 2:40 am, Bob Rossi wrote: >> >> > Darn it, this was reported in 2007 >> > http://bugs.python.org/issue1180193 >> > and it was mentioned the logging package was effected. >> > >> > Yikes. >> > >> >> I will think about this, but don't expect any quick resolution :-( I >> think the right fix would be not in the logging package, but in the >> module loading machinery (as mentioned on that issue). >> >> I wouldn't worry about the performance aspect - once the logging >> package is loaded, there's no performance impact. That's a tiny one- >> off hit which you will probably not notice at all. > > OK. > > Do you know where the bytecode gets stored when you load a py > file from a zip? > > My program can potentially run for hours, from an embedded context, > and could call into the logger and other py files over and over. > > Are the bytecode files stored in RAM one time, or recomputed each > time they are needed? The bytecode is generated once when the module is loaded and kept as part of the module object in the sys.modules cache unless you explicitly reload() the module. For a long-running program the compilation overhead is negligable. From __peter__ at web.de Tue Mar 6 09:28:16 2012 From: __peter__ at web.de (Peter Otten) Date: Tue, 06 Mar 2012 15:28:16 +0100 Subject: pickle/unpickle class which has changed References: <4f561740$0$29989$c3e8da3$5496439d@news.astraweb.com> Message-ID: Steven D'Aprano wrote: > On Tue, 06 Mar 2012 07:34:34 -0500, Neal Becker wrote: > >> What happens if I pickle a class, and later unpickle it where the class >> now has added some new attributes? > > Why don't you try it? > > py> import pickle > py> class C: > ... a = 23 > ... > py> c = C() > py> pickled = pickle.dumps(c) > py> C.b = 42 # add a new class attribute > py> d = pickle.loads(pickled) > py> d.a > 23 > py> d.b > 42 > > > Unless you mean something different from this, adding attributes to the > class is perfectly fine. > > But... why are you dynamically adding attributes to the class? Isn't that > rather unusual? The way I understand the problem is that an apparently backwards-compatible change like adding a third dimension to a point with an obvious default breaks when you restore an "old" instance in a script with the "new" implementation: >>> import pickle >>> class P(object): ... def __init__(self, x, y): ... self.x = x ... self.y = y ... def r2(self): ... return self.x*self.x + self.y*self.y ... >>> p = P(2, 3) >>> p.r2() 13 >>> s = pickle.dumps(p) >>> class P(object): ... def __init__(self, x, y, z=0): ... self.x = x ... self.y = y ... self.z = z ... def r2(self): ... return self.x*self.x + self.y*self.y + self.z*self.z ... >>> p = P(2, 3) >>> p.r2() 13 >>> pickle.loads(s).r2() Traceback (most recent call last): File "", line 1, in File "", line 7, in r2 AttributeError: 'P' object has no attribute 'z' By default pickle doesn't invoke __init__() and updates __dict__ directly. As pointed out in my previous post one way to fix the problem is to implement a __setstate__() method: >>> class P(object): ... def __init__(self, x, y, z=0): ... self.x = x ... self.y = y ... self.z = z ... def r2(self): ... return self.x*self.x + self.y*self.y + self.z*self.z ... def __setstate__(self, state): ... self.__dict__["z"] = 42 # stupid default ... self.__dict__.update(state) ... >>> pickle.loads(s).r2() 1777 This keeps working with pickles of the new implementation of P: >>> q = P(3, 4, 5) >>> pickle.loads(pickle.dumps(q)).r2() 50 From queency3 at yahoo.com Tue Mar 6 10:32:37 2012 From: queency3 at yahoo.com (queency jones) Date: Tue, 6 Mar 2012 07:32:37 -0800 (PST) Subject: python simple web server Message-ID: <1331047957.90396.YahooMailClassic@web162001.mail.bf1.yahoo.com> hello pythonist i'm developing using the simple / basic http server i got very bad performance regarding to request time . 9 sec for each request replay. i tried to test this with this: python -m SimpleHTTPServer 8080 but no better. any sugestions ? that i can use ? my final goal is to serv 5 people on the lan network only . can't i stick with the python server ? -------------- next part -------------- An HTML attachment was scrubbed... URL: From dreadpiratejeff at gmail.com Tue Mar 6 11:09:23 2012 From: dreadpiratejeff at gmail.com (J) Date: Tue, 6 Mar 2012 11:09:23 -0500 Subject: Help me with weird logging problem Message-ID: Hi, I'm trying to add a couple log handlers to a program. The end goal is to log things at INFO or above to console, and if a -v option is set to ALSO log everything at DEBUG or above to a file. However, while I DO get the log file created, and log messages are appearing there, Debug messages are not... Here's some sample code that is essentially the guts of the logging setup right now, based on what I read in the docs: #!/usr/bin/python import logging import sys verbose = True # Set up the logger console_format = '%(levelname)-8s %(message)s' console_handler = logging.StreamHandler() console_handler.setFormatter(logging.Formatter(console_format)) console_handler.setLevel(logging.INFO) logger = logging.getLogger() logger.addHandler(console_handler) if verbose: verbose_format = '%(asctime)s %(levelname)-8s %(message)s' verbose_handler = logging.FileHandler('testlog.log') verbose_handler.setLevel(logging.DEBUG) verbose_handler.setFormatter(logging.Formatter(verbose_format)) logger.addHandler(verbose_handler) logging.debug("Setting log level to DEBUG for verbosity") logging.info("INFO event logged") logging.warning("WARNING event logged") logging.error("ERROR event logged") logging.critical("CRITICAL event logged") logging.debug("DEBUG event logged") When I run this I get the following console and log file output: bladernr at klaatu:~/development/cert-submit-script-improvements/bin$ ./logtest.py WARNING WARNING event logged ERROR ERROR event logged CRITICAL CRITICAL event logged bladernr at klaatu:~/development/cert-submit-script-improvements/bin$ cat testlog.log 2012-03-06 11:05:40,297 WARNING WARNING event logged 2012-03-06 11:05:40,297 ERROR ERROR event logged 2012-03-06 11:05:40,298 CRITICAL CRITICAL event logged So I AM getting logging, but I am not getting the DEBUG level logs in the log file, nor am I getting INFO level logs on console. Any idea what I'm doing wrong? From vinay_sajip at yahoo.co.uk Tue Mar 6 11:19:53 2012 From: vinay_sajip at yahoo.co.uk (Vinay Sajip) Date: Tue, 6 Mar 2012 08:19:53 -0800 (PST) Subject: Help me with weird logging problem References: Message-ID: On Mar 6, 4:09?pm, J wrote: > > Any idea what I'm doing wrong? Levels can be set on loggers as well as handlers, and you're only setting levels on the handlers. The default level on the root logger is WARNING. A logger checks its level first, and only if the event passes that test will it be passed to the handlers (which will also perform level tests). So, a logger.setLevel(logging.DEBUG) should be all you need to add before logging anything. Regards, Vinay Sajip From jcea at jcea.es Tue Mar 6 11:28:56 2012 From: jcea at jcea.es (Jesus Cea) Date: Tue, 06 Mar 2012 17:28:56 +0100 Subject: Monthly Python Meeting in Madrid (Spain) Message-ID: <4F563B48.6040901@jcea.es> -----BEGIN PGP SIGNED MESSAGE----- Hash: SHA1 Next Thursday, 8th March. - -- Jesus Cea Avion _/_/ _/_/_/ _/_/_/ jcea at jcea.es - http://www.jcea.es/ _/_/ _/_/ _/_/ _/_/ _/_/ jabber / xmpp:jcea at jabber.org _/_/ _/_/ _/_/_/_/_/ . _/_/ _/_/ _/_/ _/_/ _/_/ "Things are not so easy" _/_/ _/_/ _/_/ _/_/ _/_/ _/_/ "My name is Dump, Core Dump" _/_/_/ _/_/_/ _/_/ _/_/ "El amor es poner tu felicidad en la felicidad de otro" - Leibniz -----BEGIN PGP SIGNATURE----- Version: GnuPG v1.4.10 (GNU/Linux) Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org/ iQCVAwUBT1Y7SJlgi5GaxT1NAQKOmQQAmRSz5Kk1ZAE5iEBiUiB5XRKVVntPfcA1 FflzHu2ZawULVlcnLMj2mh6USzOSqrRqz5mFZA9RFQWjeN6s1wa/x8hUytUFH90t BirdqeLjzZMoU1eyRlGggSjqR+VLDqqpxFq8aWbKDC3+t5u+UmZMjvHQo0zBGbcZ CDcITqWR2Ds= =e495 -----END PGP SIGNATURE----- From ndbecker2 at gmail.com Tue Mar 6 11:29:16 2012 From: ndbecker2 at gmail.com (Neal Becker) Date: Tue, 06 Mar 2012 11:29:16 -0500 Subject: pickle/unpickle class which has changed References: <4f561740$0$29989$c3e8da3$5496439d@news.astraweb.com> Message-ID: Peter Otten wrote: > Steven D'Aprano wrote: > >> On Tue, 06 Mar 2012 07:34:34 -0500, Neal Becker wrote: >> >>> What happens if I pickle a class, and later unpickle it where the class >>> now has added some new attributes? >> >> Why don't you try it? >> >> py> import pickle >> py> class C: >> ... a = 23 >> ... >> py> c = C() >> py> pickled = pickle.dumps(c) >> py> C.b = 42 # add a new class attribute >> py> d = pickle.loads(pickled) >> py> d.a >> 23 >> py> d.b >> 42 >> >> >> Unless you mean something different from this, adding attributes to the >> class is perfectly fine. >> >> But... why are you dynamically adding attributes to the class? Isn't that >> rather unusual? > > The way I understand the problem is that an apparently backwards-compatible > change like adding a third dimension to a point with an obvious default > breaks when you restore an "old" instance in a script with the "new" > implementation: > >>>> import pickle >>>> class P(object): > ... def __init__(self, x, y): > ... self.x = x > ... self.y = y > ... def r2(self): > ... return self.x*self.x + self.y*self.y > ... >>>> p = P(2, 3) >>>> p.r2() > 13 >>>> s = pickle.dumps(p) >>>> class P(object): > ... def __init__(self, x, y, z=0): > ... self.x = x > ... self.y = y > ... self.z = z > ... def r2(self): > ... return self.x*self.x + self.y*self.y + self.z*self.z > ... >>>> p = P(2, 3) >>>> p.r2() > 13 >>>> pickle.loads(s).r2() > Traceback (most recent call last): > File "", line 1, in > File "", line 7, in r2 > AttributeError: 'P' object has no attribute 'z' > > By default pickle doesn't invoke __init__() and updates __dict__ directly. > As pointed out in my previous post one way to fix the problem is to > implement a __setstate__() method: > >>>> class P(object): > ... def __init__(self, x, y, z=0): > ... self.x = x > ... self.y = y > ... self.z = z > ... def r2(self): > ... return self.x*self.x + self.y*self.y + self.z*self.z > ... def __setstate__(self, state): > ... self.__dict__["z"] = 42 # stupid default > ... self.__dict__.update(state) > ... >>>> pickle.loads(s).r2() > 1777 > > This keeps working with pickles of the new implementation of P: > >>>> q = P(3, 4, 5) >>>> pickle.loads(pickle.dumps(q)).r2() > 50 So if in my new class definition there are now some new attributes, and if I did not add a __setstate__ to set the new attributes, I guess then when unpickled the instance of the class will simply lack those attributes? From dreadpiratejeff at gmail.com Tue Mar 6 12:03:16 2012 From: dreadpiratejeff at gmail.com (J) Date: Tue, 6 Mar 2012 12:03:16 -0500 Subject: Help me with weird logging problem In-Reply-To: References: Message-ID: On Tue, Mar 6, 2012 at 11:19, Vinay Sajip wrote: > On Mar 6, 4:09?pm, J wrote: >> >> Any idea what I'm doing wrong? > > Levels can be set on loggers as well as handlers, and you're only > setting levels on the handlers. The default level on the root logger > is WARNING. A logger checks its level first, and only if the event > passes that test will it be passed to the handlers (which will also > perform level tests). > > So, a logger.setLevel(logging.DEBUG) should be all you need to add > before logging anything. > > Regards, > > Vinay Sajip > -- > http://mail.python.org/mailman/listinfo/python-list Thank you very much, Vinay :) I thought it was something simple like that I had overlooked or misunderstood. Cheers, Jeff From __peter__ at web.de Tue Mar 6 12:10:53 2012 From: __peter__ at web.de (Peter Otten) Date: Tue, 06 Mar 2012 18:10:53 +0100 Subject: pickle/unpickle class which has changed References: <4f561740$0$29989$c3e8da3$5496439d@news.astraweb.com> Message-ID: Neal Becker wrote: > Peter Otten wrote: > >> Steven D'Aprano wrote: >> >>> On Tue, 06 Mar 2012 07:34:34 -0500, Neal Becker wrote: >>> >>>> What happens if I pickle a class, and later unpickle it where the class >>>> now has added some new attributes? >>> >>> Why don't you try it? >>> >>> py> import pickle >>> py> class C: >>> ... a = 23 >>> ... >>> py> c = C() >>> py> pickled = pickle.dumps(c) >>> py> C.b = 42 # add a new class attribute >>> py> d = pickle.loads(pickled) >>> py> d.a >>> 23 >>> py> d.b >>> 42 >>> >>> >>> Unless you mean something different from this, adding attributes to the >>> class is perfectly fine. >>> >>> But... why are you dynamically adding attributes to the class? Isn't >>> that rather unusual? >> >> The way I understand the problem is that an apparently >> backwards-compatible change like adding a third dimension to a point with >> an obvious default breaks when you restore an "old" instance in a script >> with the "new" implementation: >> >>>>> import pickle >>>>> class P(object): >> ... def __init__(self, x, y): >> ... self.x = x >> ... self.y = y >> ... def r2(self): >> ... return self.x*self.x + self.y*self.y >> ... >>>>> p = P(2, 3) >>>>> p.r2() >> 13 >>>>> s = pickle.dumps(p) >>>>> class P(object): >> ... def __init__(self, x, y, z=0): >> ... self.x = x >> ... self.y = y >> ... self.z = z >> ... def r2(self): >> ... return self.x*self.x + self.y*self.y + self.z*self.z >> ... >>>>> p = P(2, 3) >>>>> p.r2() >> 13 >>>>> pickle.loads(s).r2() >> Traceback (most recent call last): >> File "", line 1, in >> File "", line 7, in r2 >> AttributeError: 'P' object has no attribute 'z' >> >> By default pickle doesn't invoke __init__() and updates __dict__ >> directly. As pointed out in my previous post one way to fix the problem >> is to implement a __setstate__() method: >> >>>>> class P(object): >> ... def __init__(self, x, y, z=0): >> ... self.x = x >> ... self.y = y >> ... self.z = z >> ... def r2(self): >> ... return self.x*self.x + self.y*self.y + self.z*self.z >> ... def __setstate__(self, state): >> ... self.__dict__["z"] = 42 # stupid default >> ... self.__dict__.update(state) >> ... >>>>> pickle.loads(s).r2() >> 1777 >> >> This keeps working with pickles of the new implementation of P: >> >>>>> q = P(3, 4, 5) >>>>> pickle.loads(pickle.dumps(q)).r2() >> 50 > > So if in my new class definition there are now some new attributes, and if > I did not add a __setstate__ to set the new attributes, I guess then when > unpickled the instance of the class will simply lack those attributes? I don't know. If you don't trust the demo try it yourself with the actual code you have. Throwing in obj = pickle.load(...) print vars(obj) should help. From reader at calvinkim.org Tue Mar 6 16:29:10 2012 From: reader at calvinkim.org (Calvin Kim) Date: Tue, 06 Mar 2012 16:29:10 -0500 Subject: are int, float, long, double, side-effects of computer engineering? In-Reply-To: References: <5aaded58-af09-41dc-9afd-56d7b7ced239@d7g2000pbl.googlegroups.com> Message-ID: <4F5681A6.9090707@calvinkim.org> On 03/06/2012 01:34 AM, Xah Lee wrote: > while what you said is true, but the problem is that 99.99% of > programers do NOT know this. They do not know Mathematica. They've > never seen a language with such feature. The concept is alien. This is > what i'd like to point out and spread awareness. > I can see your point. But that's not simply true. In my case and many others, such issue was addressed during first week of introductory programming classes. I was naively thought "computer = precision" and I was stunned to find out the inaccuracy of computer calculations. But as you experienced, I also stumble upon some people (specially Java only programmers) who were not aware of it. > also, argument about raw speed and fine control vs automatic > management, rots with time. Happened with auto memory management, > managed code, compilers, auto type conversion, auto extension of > array, auto type system, dynamic/scripting languages, etc. Maybe it's because I'm not in scientific community, that I learned to live with such side-effects. Because 99.99% of computer users and programmers can afford to, and willing to lose such small inaccuracy billion times in exchange for some performance increase and convenience. Although NASA may not accept my application for their projects for Mars mission after this posting. From johnjsal at gmail.com Tue Mar 6 17:43:34 2012 From: johnjsal at gmail.com (John Salerno) Date: Tue, 6 Mar 2012 14:43:34 -0800 (PST) Subject: What's the best way to write this regular expression? Message-ID: <12783654.1174.1331073814011.JavaMail.geo-discussion-forums@yner4> I sort of have to work with what the website gives me (as you'll see below), but today I encountered an exception to my RE. Let me just give all the specific information first. The point of my script is to go to the specified URL and extract song information from it. This is my RE: song_pattern = re.compile(r'([0-9]{1,2}:[0-9]{2} [a|p].m.).*?(.*?).*?(.*?)', re.DOTALL) This is how the website is formatted: 4:25 p.m.
  • 4:21 p.m.
  • 4:19 p.m.
    Moe Bandy
  • 4:15 p.m.
    Reba McEntire
  • There's something of a pattern, although it's not always perfect. The time is listed first, and then the song information in tags. However, in this particular case, you can see that for the 4:25pm entry, "AP TX SOC CPAS TRF" is extracted for the song title, and then the RE skips to the next entry in order to find the next tags, which is actually the name of the next song in the list, instead of being the artist as normal. (Of course, I have no idea what AP TX SOC CPAS TRF is anyway. Usually the website doesn't list commercials or anomalies like that.) So my first question is basic: am I even extracting the information properly? It works almost all the time, but because the website is such a mess, I pretty much have to rely on the tags being in the proper places (as they were NOT in this case!). The second question is, to fix the above problem, would it be sufficient to rewrite my RE so that it has to find all of the specified information, i.e. a time followed by two entries, BEFORE it moves on to finding the next time? I think that would have caused it to skip the 4:25 entry above, and only extract entries that have a time followed by two entries (song and artist). If this is possible, how do I rewrite it so that it has to match all the conditions without skipping over the next time entry in order to do so? Thanks. From clp2 at rebertia.com Tue Mar 6 17:52:10 2012 From: clp2 at rebertia.com (Chris Rebert) Date: Tue, 6 Mar 2012 14:52:10 -0800 Subject: What's the best way to write this regular expression? In-Reply-To: <12783654.1174.1331073814011.JavaMail.geo-discussion-forums@yner4> References: <12783654.1174.1331073814011.JavaMail.geo-discussion-forums@yner4> Message-ID: On Tue, Mar 6, 2012 at 2:43 PM, John Salerno wrote: > I sort of have to work with what the website gives me (as you'll see below), but today I encountered an exception to my RE. Let me just give all the specific information first. The point of my script is to go to the specified URL and extract song information from it. > > This is my RE: > > song_pattern = re.compile(r'([0-9]{1,2}:[0-9]{2} [a|p].m.).*?(.*?).*?(.*?)', re.DOTALL) I would advise against using regular expressions to "parse" HTML: http://stackoverflow.com/questions/1732348/regex-match-open-tags-except-xhtml-self-contained-tags lxml is a popular choice for parsing HTML in Python: http://lxml.de Cheers, Chris From johnjsal at gmail.com Tue Mar 6 18:02:42 2012 From: johnjsal at gmail.com (John Salerno) Date: Tue, 6 Mar 2012 15:02:42 -0800 (PST) Subject: What's the best way to write this regular expression? In-Reply-To: References: <12783654.1174.1331073814011.JavaMail.geo-discussion-forums@yner4> Message-ID: <15622243.3244.1331074963027.JavaMail.geo-discussion-forums@yncc26> On Tuesday, March 6, 2012 4:52:10 PM UTC-6, Chris Rebert wrote: > On Tue, Mar 6, 2012 at 2:43 PM, John Salerno wrote: > > I sort of have to work with what the website gives me (as you'll see below), but today I encountered an exception to my RE. Let me just give all the specific information first. The point of my script is to go to the specified URL and extract song information from it. > > > > This is my RE: > > > > song_pattern = re.compile(r'([0-9]{1,2}:[0-9]{2} [a|p].m.).*?(.*?).*?(.*?)', re.DOTALL) > > I would advise against using regular expressions to "parse" HTML: > http://stackoverflow.com/questions/1732348/regex-match-open-tags-except-xhtml-self-contained-tags > > lxml is a popular choice for parsing HTML in Python: http://lxml.de > > Cheers, > Chris Thanks, that was an interesting read :) Anything that allows me NOT to use REs is welcome news, so I look forward to learning about something new! :) From johnjsal at gmail.com Tue Mar 6 18:02:42 2012 From: johnjsal at gmail.com (John Salerno) Date: Tue, 6 Mar 2012 15:02:42 -0800 (PST) Subject: What's the best way to write this regular expression? In-Reply-To: References: <12783654.1174.1331073814011.JavaMail.geo-discussion-forums@yner4> Message-ID: <15622243.3244.1331074963027.JavaMail.geo-discussion-forums@yncc26> On Tuesday, March 6, 2012 4:52:10 PM UTC-6, Chris Rebert wrote: > On Tue, Mar 6, 2012 at 2:43 PM, John Salerno wrote: > > I sort of have to work with what the website gives me (as you'll see below), but today I encountered an exception to my RE. Let me just give all the specific information first. The point of my script is to go to the specified URL and extract song information from it. > > > > This is my RE: > > > > song_pattern = re.compile(r'([0-9]{1,2}:[0-9]{2} [a|p].m.).*?(.*?).*?(.*?)', re.DOTALL) > > I would advise against using regular expressions to "parse" HTML: > http://stackoverflow.com/questions/1732348/regex-match-open-tags-except-xhtml-self-contained-tags > > lxml is a popular choice for parsing HTML in Python: http://lxml.de > > Cheers, > Chris Thanks, that was an interesting read :) Anything that allows me NOT to use REs is welcome news, so I look forward to learning about something new! :) From johnjsal at gmail.com Tue Mar 6 18:05:39 2012 From: johnjsal at gmail.com (John Salerno) Date: Tue, 6 Mar 2012 15:05:39 -0800 (PST) Subject: What's the best way to write this regular expression? In-Reply-To: References: <12783654.1174.1331073814011.JavaMail.geo-discussion-forums@yner4> Message-ID: <28285433.1413.1331075139309.JavaMail.geo-discussion-forums@ynbq18> > Anything that allows me NOT to use REs is welcome news, so I look forward to learning about something new! :) I should ask though...are there alternatives already bundled with Python that I could use? Now that you mention it, I remember something called HTMLParser (or something like that) and I have no idea why I never looked into that before I messed with REs. Thanks. From johnjsal at gmail.com Tue Mar 6 18:05:39 2012 From: johnjsal at gmail.com (John Salerno) Date: Tue, 6 Mar 2012 15:05:39 -0800 (PST) Subject: What's the best way to write this regular expression? In-Reply-To: References: <12783654.1174.1331073814011.JavaMail.geo-discussion-forums@yner4> Message-ID: <28285433.1413.1331075139309.JavaMail.geo-discussion-forums@ynbq18> > Anything that allows me NOT to use REs is welcome news, so I look forward to learning about something new! :) I should ask though...are there alternatives already bundled with Python that I could use? Now that you mention it, I remember something called HTMLParser (or something like that) and I have no idea why I never looked into that before I messed with REs. Thanks. From johnjsal at gmail.com Tue Mar 6 18:25:40 2012 From: johnjsal at gmail.com (John Salerno) Date: Tue, 6 Mar 2012 15:25:40 -0800 (PST) Subject: What's the best way to write this regular expression? In-Reply-To: <28285433.1413.1331075139309.JavaMail.geo-discussion-forums@ynbq18> References: <12783654.1174.1331073814011.JavaMail.geo-discussion-forums@yner4> <28285433.1413.1331075139309.JavaMail.geo-discussion-forums@ynbq18> Message-ID: <10944614.4302.1331076340313.JavaMail.geo-discussion-forums@ynne2> On Tuesday, March 6, 2012 5:05:39 PM UTC-6, John Salerno wrote: > > Anything that allows me NOT to use REs is welcome news, so I look forward to learning about something new! :) > > I should ask though...are there alternatives already bundled with Python that I could use? Now that you mention it, I remember something called HTMLParser (or something like that) and I have no idea why I never looked into that before I messed with REs. > > Thanks. Also, I just noticed Beautiful Soup, which seems appropriate. I suppose any will do, but knowing the pros and cons would help with a decision. From johnjsal at gmail.com Tue Mar 6 18:33:38 2012 From: johnjsal at gmail.com (John Salerno) Date: Tue, 6 Mar 2012 15:33:38 -0800 (PST) Subject: What's the best way to write this regular expression? In-Reply-To: <28285433.1413.1331075139309.JavaMail.geo-discussion-forums@ynbq18> References: <12783654.1174.1331073814011.JavaMail.geo-discussion-forums@yner4> <28285433.1413.1331075139309.JavaMail.geo-discussion-forums@ynbq18> Message-ID: <28368927.1236.1331076818291.JavaMail.geo-discussion-forums@yner4> On Tuesday, March 6, 2012 5:05:39 PM UTC-6, John Salerno wrote: > > Anything that allows me NOT to use REs is welcome news, so I look forward to learning about something new! :) > > I should ask though...are there alternatives already bundled with Python that I could use? Now that you mention it, I remember something called HTMLParser (or something like that) and I have no idea why I never looked into that before I messed with REs. > > Thanks. ::sigh:: I'm having some trouble with the new Google Groups interface. It seems to double post, and in this case didn't post at all. If it did already, I apologize. I'll try to figure out what's happening, or just switch to a real newsgroup program. Anyway, my question was about Beautiful Soup. I read on the doc page that BS uses a parser, which html.parser and lxml are. So I'm guessing the difference between them is that the parser is a little more "low level," whereas BS offers a higher level approach to using them? Is BS easier to write code with, while still using the power of lxml? From johnjsal at gmail.com Tue Mar 6 18:33:38 2012 From: johnjsal at gmail.com (John Salerno) Date: Tue, 6 Mar 2012 15:33:38 -0800 (PST) Subject: What's the best way to write this regular expression? In-Reply-To: <28285433.1413.1331075139309.JavaMail.geo-discussion-forums@ynbq18> References: <12783654.1174.1331073814011.JavaMail.geo-discussion-forums@yner4> <28285433.1413.1331075139309.JavaMail.geo-discussion-forums@ynbq18> Message-ID: <28368927.1236.1331076818291.JavaMail.geo-discussion-forums@yner4> On Tuesday, March 6, 2012 5:05:39 PM UTC-6, John Salerno wrote: > > Anything that allows me NOT to use REs is welcome news, so I look forward to learning about something new! :) > > I should ask though...are there alternatives already bundled with Python that I could use? Now that you mention it, I remember something called HTMLParser (or something like that) and I have no idea why I never looked into that before I messed with REs. > > Thanks. ::sigh:: I'm having some trouble with the new Google Groups interface. It seems to double post, and in this case didn't post at all. If it did already, I apologize. I'll try to figure out what's happening, or just switch to a real newsgroup program. Anyway, my question was about Beautiful Soup. I read on the doc page that BS uses a parser, which html.parser and lxml are. So I'm guessing the difference between them is that the parser is a little more "low level," whereas BS offers a higher level approach to using them? Is BS easier to write code with, while still using the power of lxml? From ian.g.kelly at gmail.com Tue Mar 6 18:35:32 2012 From: ian.g.kelly at gmail.com (Ian Kelly) Date: Tue, 6 Mar 2012 16:35:32 -0700 Subject: What's the best way to write this regular expression? In-Reply-To: <28285433.1413.1331075139309.JavaMail.geo-discussion-forums@ynbq18> References: <12783654.1174.1331073814011.JavaMail.geo-discussion-forums@yner4> <28285433.1413.1331075139309.JavaMail.geo-discussion-forums@ynbq18> Message-ID: On Tue, Mar 6, 2012 at 4:05 PM, John Salerno wrote: >> Anything that allows me NOT to use REs is welcome news, so I look forward to learning about something new! :) > > I should ask though...are there alternatives already bundled with Python that I could use? Now that you mention it, I remember something called HTMLParser (or something like that) and I have no idea why I never looked into that before I messed with REs. HTMLParser is pretty basic, although it may be sufficient for your needs. It just converts an html document into a stream of start tags, end tags, and text, with no guarantee that the tags will actually correspond in any meaningful way. lxml can be used to output an actual hierarchical structure that may be easier to manipulate and extract data from. Cheers, Ian From johnjsal at gmail.com Tue Mar 6 18:39:42 2012 From: johnjsal at gmail.com (John Salerno) Date: Tue, 6 Mar 2012 17:39:42 -0600 Subject: What's the best way to write this regular expression? In-Reply-To: References: <12783654.1174.1331073814011.JavaMail.geo-discussion-forums@yner4> <28285433.1413.1331075139309.JavaMail.geo-discussion-forums@ynbq18> Message-ID: Thanks. I'm thinking the choice might be between lxml and Beautiful Soup, but since BS uses lxml as a parser, I'm trying to figure out the difference between them. I don't necessarily need the simplest (html.parser), but I want to choose one that is simple enough yet powerful enough that I won't have to learn another method later. On Tue, Mar 6, 2012 at 5:35 PM, Ian Kelly wrote: > On Tue, Mar 6, 2012 at 4:05 PM, John Salerno wrote: >>> Anything that allows me NOT to use REs is welcome news, so I look forward to learning about something new! :) >> >> I should ask though...are there alternatives already bundled with Python that I could use? Now that you mention it, I remember something called HTMLParser (or something like that) and I have no idea why I never looked into that before I messed with REs. > > HTMLParser is pretty basic, although it may be sufficient for your > needs. ?It just converts an html document into a stream of start tags, > end tags, and text, with no guarantee that the tags will actually > correspond in any meaningful way. ?lxml can be used to output an > actual hierarchical structure that may be easier to manipulate and > extract data from. > > Cheers, > Ian From steve+comp.lang.python at pearwood.info Tue Mar 6 18:44:07 2012 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 06 Mar 2012 23:44:07 GMT Subject: What's the best way to write this regular expression? References: <12783654.1174.1331073814011.JavaMail.geo-discussion-forums@yner4> Message-ID: <4f56a146$0$29989$c3e8da3$5496439d@news.astraweb.com> On Tue, 06 Mar 2012 15:05:39 -0800, John Salerno wrote: >> Anything that allows me NOT to use REs is welcome news, so I look >> forward to learning about something new! :) > > I should ask though...are there alternatives already bundled with Python > that I could use? Now that you mention it, I remember something called > HTMLParser (or something like that) and I have no idea why I never > looked into that before I messed with REs. import htmllib help(htmllib) The help is pretty minimal and technical, you might like to google on a tutorial or two: https://duckduckgo.com/html/?q=python%20htmllib%20tutorial Also, you're still double-posting. -- Steven From johnjsal at gmail.com Tue Mar 6 18:57:15 2012 From: johnjsal at gmail.com (John Salerno) Date: Tue, 6 Mar 2012 15:57:15 -0800 (PST) Subject: What's the best way to write this regular expression? In-Reply-To: <4f56a146$0$29989$c3e8da3$5496439d@news.astraweb.com> References: <12783654.1174.1331073814011.JavaMail.geo-discussion-forums@yner4> <4f56a146$0$29989$c3e8da3$5496439d@news.astraweb.com> Message-ID: <9496185.1483.1331078235707.JavaMail.geo-discussion-forums@ynbo9> > Also, you're still double-posting. Grr. I just reported it to Google, but I think if I start to frequent the newsgroup again I'll have to switch to Thunderbird, or perhaps I'll just try switching back to the old Google Groups interface. I think the issue is the new interface. Sorry. From ramit.prasad at jpmorgan.com Tue Mar 6 19:04:23 2012 From: ramit.prasad at jpmorgan.com (Prasad, Ramit) Date: Wed, 7 Mar 2012 00:04:23 +0000 Subject: What's the best way to write this regular expression? In-Reply-To: <9496185.1483.1331078235707.JavaMail.geo-discussion-forums@ynbo9> References: <12783654.1174.1331073814011.JavaMail.geo-discussion-forums@yner4> <4f56a146$0$29989$c3e8da3$5496439d@news.astraweb.com> <9496185.1483.1331078235707.JavaMail.geo-discussion-forums@ynbo9> Message-ID: <5B80DD153D7D744689F57F4FB69AF474193A88@SCACMX008.exchad.jpmchase.net> > > > Also, you're still double-posting. > > Grr. I just reported it to Google, but I think if I start to frequent the > newsgroup again I'll have to switch to Thunderbird, or perhaps I'll just > try switching back to the old Google Groups interface. I think the issue is > the new interface. > > Sorry. Oddly, I see no double posting for this thread on my end (email list). Ramit Ramit Prasad | JPMorgan Chase Investment Bank | Currencies Technology 712 Main Street | Houston, TX 77002 work phone: 713 - 216 - 5423 -- This email is confidential and subject to important disclaimers and conditions including on offers for the purchase or sale of securities, accuracy and completeness of information, viruses, confidentiality, legal privilege, and legal entity disclaimers, available at http://www.jpmorgan.com/pages/disclosures/email. From gelonida at gmail.com Tue Mar 6 19:22:46 2012 From: gelonida at gmail.com (Gelonida N) Date: Wed, 07 Mar 2012 01:22:46 +0100 Subject: pickle/unpickle class which has changed In-Reply-To: References: Message-ID: Hi Peter, A related question. Is there anyhing like a built in signature which would help to detect, that one tries to unpickle an object whose byte code has changed? The idea is to distinguish old and new pickled data and start some 'migration code' fi required The only thing, that I thought about so far was adding an explicit version number to each class in order to detect such situations. On 03/06/2012 02:52 PM, Peter Otten wrote: > Neal Becker wrote: > >> What happens if I pickle a class, and later unpickle it where the class >> now has added some new attributes? > > - If the added attributes' values are immutable, provide defaults as class > attributes. > > - Implement an appropriate __setstate__() method. The easiest would be > > # untested > def __setstate__(self, state): > self.__dict__.update(newattr1=42, newattr2=[]) > self.__dict__.update(state) > From anikom15 at gmail.com Tue Mar 6 19:53:43 2012 From: anikom15 at gmail.com (Westley =?iso-8859-1?Q?Mart=EDnez?=) Date: Tue, 6 Mar 2012 16:53:43 -0800 Subject: are int, float, long, double, side-effects of computer engineering? In-Reply-To: <4F5681A6.9090707@calvinkim.org> References: <5aaded58-af09-41dc-9afd-56d7b7ced239@d7g2000pbl.googlegroups.com> <4F5681A6.9090707@calvinkim.org> Message-ID: <20120307005343.GA9144@kubrick> On Tue, Mar 06, 2012 at 04:29:10PM -0500, Calvin Kim wrote: > On 03/06/2012 01:34 AM, Xah Lee wrote: > >while what you said is true, but the problem is that 99.99% of > >programers do NOT know this. They do not know Mathematica. They've > >never seen a language with such feature. The concept is alien. This is > >what i'd like to point out and spread awareness. > > > I can see your point. But that's not simply true. In my case and > many others, such issue was addressed during first week of > introductory programming classes. I was naively thought "computer = > precision" and I was stunned to find out the inaccuracy of computer > calculations. > > But as you experienced, I also stumble upon some people (specially > Java only programmers) who were not aware of it. > > >also, argument about raw speed and fine control vs automatic > >management, rots with time. Happened with auto memory management, > >managed code, compilers, auto type conversion, auto extension of > >array, auto type system, dynamic/scripting languages, etc. > Maybe it's because I'm not in scientific community, that I learned > to live with such side-effects. Because 99.99% of computer users and > programmers can afford to, and willing to lose such small inaccuracy > billion times in exchange for some performance increase and > convenience. Although NASA may not accept my application for their > projects for Mars mission after this posting. Also remember that double precision is not the maximum. There exist standards for triple and quadruple precision formats, as well as other extended formats. From tjreedy at udel.edu Tue Mar 6 20:04:35 2012 From: tjreedy at udel.edu (Terry Reedy) Date: Tue, 06 Mar 2012 20:04:35 -0500 Subject: What's the best way to write this regular expression? In-Reply-To: <28285433.1413.1331075139309.JavaMail.geo-discussion-forums@ynbq18> References: <12783654.1174.1331073814011.JavaMail.geo-discussion-forums@yner4> <28285433.1413.1331075139309.JavaMail.geo-discussion-forums@ynbq18> Message-ID: On 3/6/2012 6:05 PM, John Salerno wrote: >> Anything that allows me NOT to use REs is welcome news, so I look >> forward to learning about something new! :) > > I should ask though...are there alternatives already bundled with > Python that I could use? lxml is +- upward compatible with xml.etree in the stdlib. -- Terry Jan Reedy From tjreedy at udel.edu Tue Mar 6 20:06:34 2012 From: tjreedy at udel.edu (Terry Reedy) Date: Tue, 06 Mar 2012 20:06:34 -0500 Subject: What's the best way to write this regular expression? In-Reply-To: <9496185.1483.1331078235707.JavaMail.geo-discussion-forums@ynbo9> References: <12783654.1174.1331073814011.JavaMail.geo-discussion-forums@yner4> <4f56a146$0$29989$c3e8da3$5496439d@news.astraweb.com> <9496185.1483.1331078235707.JavaMail.geo-discussion-forums@ynbo9> Message-ID: On 3/6/2012 6:57 PM, John Salerno wrote: >> Also, you're still double-posting. > > Grr. I just reported it to Google, but I think if I start to frequent > the newsgroup again I'll have to switch to Thunderbird, or perhaps > I'll just try switching back to the old Google Groups interface. I > think the issue is the new interface. I am not seeing the double posting, but I use Thunderbird + the news.gmane.org mirrors of python-list and others. -- Terry Jan Reedy From roy at panix.com Tue Mar 6 20:26:11 2012 From: roy at panix.com (Roy Smith) Date: Tue, 06 Mar 2012 20:26:11 -0500 Subject: What's the best way to write this regular expression? References: <12783654.1174.1331073814011.JavaMail.geo-discussion-forums@yner4> Message-ID: In article <12783654.1174.1331073814011.JavaMail.geo-discussion-forums at yner4>, John Salerno wrote: > I sort of have to work with what the website gives me (as you'll see below), > but today I encountered an exception to my RE. Let me just give all the > specific information first. The point of my script is to go to the specified > URL and extract song information from it. Rule #1: Don't try to parse XML, HTML, or any other kind of ML with regular expressions. Rule #2: Use a dedicated ML parser. I like lxml (http://lxml.de/). There's other possibilities. Rule #3: If in doubt, see rule #1. From songofacandy at gmail.com Tue Mar 6 21:47:25 2012 From: songofacandy at gmail.com (INADA Naoki) Date: Tue, 6 Mar 2012 18:47:25 -0800 (PST) Subject: Why this recursive import fails? Message-ID: <2509610.10.1331088445839.JavaMail.geo-discussion-forums@pbcpw7> I have 4 py files like below. Two __init__.py is empty file. $ find foo -name "*.py" foo/lib/lib.py foo/lib/__init__.py foo/__init__.py foo/foo.py $ cat foo/lib/lib.py from __future__ import absolute_import print('lib.py', __name__) from .. import foo #import foo.foo $ cat foo/foo.py from __future__ import absolute_import print('foo.py', __name__) from .lib import lib #import foo.lib.lib Then, importing foo.foo or foo.lib.lib fails unexpectedly. # `from .. import foo` success but `from .lib import lib` fails. $ python -c "import foo.lib.lib" ('lib.py', 'foo.lib.lib') ('foo.py', 'foo.foo') Traceback (most recent call last): File "", line 1, in File "foo/lib/lib.py", line 3, in from .. import foo File "foo/foo.py", line 3, in from .lib import lib ImportError: cannot import name lib # `from .lib import lib` success but `from .. import foo` fails. $ python -c "import foo.foo" ('foo.py', 'foo.foo') ('lib.py', 'foo.lib.lib') Traceback (most recent call last): File "", line 1, in File "foo/foo.py", line 3, in from .lib import lib File "foo/lib/lib.py", line 3, in from .. import foo ImportError: cannot import name foo I can run both with absolute import. What's wrong about my relative import? From rustompmody at gmail.com Tue Mar 6 22:25:03 2012 From: rustompmody at gmail.com (rusi) Date: Tue, 6 Mar 2012 19:25:03 -0800 (PST) Subject: are int, float, long, double, side-effects of computer engineering? References: <5aaded58-af09-41dc-9afd-56d7b7ced239@d7g2000pbl.googlegroups.com> Message-ID: <8a3cd8d4-26d2-4cdf-b66d-43895a0bcd1e@qb4g2000pbb.googlegroups.com> On Mar 6, 6:11?am, Xah Lee wrote: > some additional info i thought is relevant. > > are int, float, long, double, side-effects of computer engineering? It is a bit naive for computer scientists to club integers and reals as mathematicians do given that for real numbers, even equality is undecidable! Mostly when a system like mathematica talks of real numbers it means computable real numbers which is a subset of mathematical real numbers (and of course a superset of floats) See http://en.wikipedia.org/wiki/Computable_number#Can_computable_numbers_be_used_instead_of_the_reals.3F From nospam at nospam.com Tue Mar 6 22:29:16 2012 From: nospam at nospam.com (Javier) Date: Wed, 7 Mar 2012 03:29:16 +0000 (UTC) Subject: Tools for refactoring/obfuscation Message-ID: I am looking for an automated tool for refactoring/obfuscation. Something that changes names of functions, variables, or which would merge all the functions of various modules in a single module. The closest I have seen is http://bicyclerepair.sourceforge.net/ Does somebody know of something that can work from the command line or simple data structures/text files?, like a python dictionary of functions {"old":"new",...} From bugzilla-mail-box at yandex.ru Tue Mar 6 22:29:55 2012 From: bugzilla-mail-box at yandex.ru (bugzilla-mail-box at yandex.ru) Date: Wed, 07 Mar 2012 13:29:55 +1000 Subject: Get tkinter text to the clipboard Message-ID: <222651331090995@web26.yandex.ru> How can I get something from tkinter gui to another program ? tkinter on python 3.2 on kde4 From jagteraho2006 at gmail.com Tue Mar 6 23:06:37 2012 From: jagteraho2006 at gmail.com (amar Singh) Date: Tue, 6 Mar 2012 20:06:37 -0800 (PST) Subject: help: confused about python flavors.... Message-ID: <948f80c1-877a-4a74-8adc-9d4ae702574f@l1g2000vbc.googlegroups.com> Hi, I am confused between plain python, numpy, scipy, pylab, matplotlib. I have high familiarity with matlab, but the computer I use does not have it. So moving to python. What should I use? and the best way to use it. I will be running matlab-like scripts sometimes on the shell prompt and sometimes on the command line. Please help. Thanks in advance. From steve+comp.lang.python at pearwood.info Wed Mar 7 01:24:54 2012 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 07 Mar 2012 06:24:54 GMT Subject: help: confused about python flavors.... References: <948f80c1-877a-4a74-8adc-9d4ae702574f@l1g2000vbc.googlegroups.com> Message-ID: <4f56ff36$0$29975$c3e8da3$5496439d@news.astraweb.com> On Tue, 06 Mar 2012 20:06:37 -0800, amar Singh wrote: > Hi, > > I am confused between plain python, numpy, scipy, pylab, matplotlib. Python is a programming language. It comes standard with many libraries for doing basic mathematics, web access, email, etc. Numpy is a library for doing scientific numerical maths work and fast processing of numeric arrays. Scipy is another library for scientific work. It is separate from, but uses, Numpy. Matplotlib is a project for making graphing and plotting of numeric data easy in Python. Pylab is a project to be Python's version of Matlab: it intends to be an integrated bundle of Python the programming language, Numpy, Scipy, and Matplotlib all in one easy-to-use application. > I have high familiarity with matlab, but the computer I use does not > have it. So moving to python. > What should I use? and the best way to use it. I will be running > matlab-like scripts sometimes on the shell prompt and sometimes on the > command line. Pylab is intended to be the closest to Matlab, but I don't know how close it is. Also, Pylab is NOT compatible with Matlab: its aim is to be an alternative to Matlab, not to be a clone. So it cannot run Matlab scripts. You might also like to look at Sage: http://www.sagemath.org/ Sage is a Python project aimed to be an alternative to Mathematica. Ultimately, you will have to look at the packages, see their features, perhaps try them for a while (they are all free software, so the only cost is your time), and decide for yourself which one meets your needs. We can't answer that, because we don't know what you need. -- Steven From johnjsal at gmail.com Wed Mar 7 02:02:51 2012 From: johnjsal at gmail.com (John Salerno) Date: Tue, 6 Mar 2012 23:02:51 -0800 (PST) Subject: What's the best way to write this regular expression? References: <12783654.1174.1331073814011.JavaMail.geo-discussion-forums@yner4> Message-ID: <0c1a1890-dc80-41b6-abea-f90324dd7d75@2g2000yqk.googlegroups.com> After a bit of reading, I've decided to use Beautiful Soup 4, with lxml as the parser. I considered simply using lxml to do all the work, but I just got lost in the documentation and tutorials. I couldn't find a clear explanation of how to parse an HTML file and then navigate its structure. The Beautiful Soup 4 documentation was very clear, and BS4 itself is so simple and Pythonic. And best of all, since version 4 no longer does the parsing itself, you can choose your own parser, and it works with lxml, so I'll still be using lxml, but with a nice, clean overlay for navigating the tree structure. Thanks for the advice! From pytomtom at gmail.com Wed Mar 7 02:58:34 2012 From: pytomtom at gmail.com (q q) Date: Wed, 7 Mar 2012 15:58:34 +0800 Subject: Help: how to protect the module 'sys' and 'os' Message-ID: Hi~ alls, I have to limit somebody modify the attr of 'sys'&'os'? e.g. you can't append sys.path. Someone has a good method? now my way: modified the source code of python ,"_PyObject_GenericSetAttrWithDict", because if you want to reset the value, you need to invoke this function. --- best regards pytom -------------- next part -------------- An HTML attachment was scrubbed... URL: From __peter__ at web.de Wed Mar 7 03:04:31 2012 From: __peter__ at web.de (Peter Otten) Date: Wed, 07 Mar 2012 09:04:31 +0100 Subject: pickle/unpickle class which has changed References: Message-ID: Gelonida N wrote: > Is there anyhing like a built in signature which would help to detect, > that one tries to unpickle an object whose byte code has changed? No. The only thing that is stored is the "protocol", the format used to store the data. > The idea is to distinguish old and new pickled data and start some > 'migration code' fi required > The only thing, that I thought about so far was adding an explicit > version number to each class in order to detect such situations. If you know in advance that your class will undergo significant changes you may also consider storing more stable data in a file format that can easily be modified, e. g. json. From nagle at animats.com Wed Mar 7 03:25:52 2012 From: nagle at animats.com (John Nagle) Date: Wed, 07 Mar 2012 00:25:52 -0800 Subject: "Decoding unicode is not supported" in unusual situation Message-ID: <4f571b94$0$12037$742ec2ed@news.sonic.net> I'm getting line 79, in tounicode return(unicode(s, errors='replace')) TypeError: decoding Unicode is not supported from this, under Python 2.7: def tounicode(s) : if type(s) == unicode : return(s) return(unicode(s, errors='replace')) That would seem to be impossible. But it's not. "s" is generated from the "suds" SOAP client. The documentation for "suds" says: "Suds leverages python meta programming to provide an intuative API for consuming web services. Runtime objectification of types defined in the WSDL is provided without class generation." I think that somewhere in "suds", they subclass the "unicode" type. That's almost too cute. The proper test is isinstance(s,unicode) John Nagle From songofacandy at gmail.com Wed Mar 7 03:28:53 2012 From: songofacandy at gmail.com (INADA Naoki) Date: Wed, 7 Mar 2012 00:28:53 -0800 (PST) Subject: Why this recursive import fails? In-Reply-To: <2509610.10.1331088445839.JavaMail.geo-discussion-forums@pbcpw7> References: <2509610.10.1331088445839.JavaMail.geo-discussion-forums@pbcpw7> Message-ID: <2133223.6.1331108933985.JavaMail.geo-discussion-forums@pbnt10> I found it is a bug http://bugs.python.org/issue13187 From __peter__ at web.de Wed Mar 7 03:39:21 2012 From: __peter__ at web.de (Peter Otten) Date: Wed, 07 Mar 2012 09:39:21 +0100 Subject: Get tkinter text to the clipboard References: <222651331090995@web26.yandex.ru> Message-ID: bugzilla-mail-box at yandex.ru wrote: > How can I get something from tkinter gui to another program ? > tkinter on python 3.2 on kde4 How about import tkinter root = tkinter.Tk() root.clipboard_clear() root.clipboard_append("whatever") From breamoreboy at yahoo.co.uk Wed Mar 7 04:15:50 2012 From: breamoreboy at yahoo.co.uk (Mark Lawrence) Date: Wed, 07 Mar 2012 09:15:50 +0000 Subject: help: confused about python flavors.... In-Reply-To: <4f56ff36$0$29975$c3e8da3$5496439d@news.astraweb.com> References: <948f80c1-877a-4a74-8adc-9d4ae702574f@l1g2000vbc.googlegroups.com> <4f56ff36$0$29975$c3e8da3$5496439d@news.astraweb.com> Message-ID: On 07/03/2012 06:24, Steven D'Aprano wrote: > On Tue, 06 Mar 2012 20:06:37 -0800, amar Singh wrote: > >> Hi, >> >> I am confused between plain python, numpy, scipy, pylab, matplotlib. > > Python is a programming language. It comes standard with many libraries > for doing basic mathematics, web access, email, etc. > > Numpy is a library for doing scientific numerical maths work and fast > processing of numeric arrays. > > Scipy is another library for scientific work. It is separate from, but > uses, Numpy. > > Matplotlib is a project for making graphing and plotting of numeric data > easy in Python. > > Pylab is a project to be Python's version of Matlab: it intends to be an > integrated bundle of Python the programming language, Numpy, Scipy, and > Matplotlib all in one easy-to-use application. > > >> I have high familiarity with matlab, but the computer I use does not >> have it. So moving to python. >> What should I use? and the best way to use it. I will be running >> matlab-like scripts sometimes on the shell prompt and sometimes on the >> command line. > > Pylab is intended to be the closest to Matlab, but I don't know how close > it is. Also, Pylab is NOT compatible with Matlab: its aim is to be an > alternative to Matlab, not to be a clone. So it cannot run Matlab scripts. > > You might also like to look at Sage: > > http://www.sagemath.org/ > > Sage is a Python project aimed to be an alternative to Mathematica. > > > Ultimately, you will have to look at the packages, see their features, > perhaps try them for a while (they are all free software, so the only > cost is your time), and decide for yourself which one meets your needs. > We can't answer that, because we don't know what you need. > > Matplotlib is excellent, it has an extensive pile of docs and examples, and the mailing list is extremely helpful. -- Cheers. Mark Lawrence. From devdixit1996 at gmail.com Wed Mar 7 04:46:59 2012 From: devdixit1996 at gmail.com (Dev Dixit) Date: Wed, 7 Mar 2012 15:16:59 +0530 Subject: Project Message-ID: Please, tell me how to develop project on "how people intract with social networing sites". From julianhu at 163.com Wed Mar 7 04:56:00 2012 From: julianhu at 163.com (=?GBK?B?uvq+/g==?=) Date: Wed, 7 Mar 2012 17:56:00 +0800 (CST) Subject: deal with cookie in python 2.3 Message-ID: <60ec6b6.155da.135ec9632a9.Coremail.julianhu@163.com> Dear All, right now I use python to capture data from a internal website. The website uses cookie to store authorization data. But there is no HttpCookieProcessor in python 2.3? Is there anybody know, how to deal with cookie in python 2.3? and could give me a sample code? thanks a lot Julian -------------- next part -------------- An HTML attachment was scrubbed... URL: From deets at web.de Wed Mar 7 05:20:33 2012 From: deets at web.de (Diez B. Roggisch) Date: Wed, 07 Mar 2012 11:20:33 +0100 Subject: "Decoding unicode is not supported" in unusual situation References: <4f571b94$0$12037$742ec2ed@news.sonic.net> Message-ID: John Nagle writes: > I think that somewhere in "suds", they subclass the "unicode" type. > That's almost too cute. > > The proper test is > > isinstance(s,unicode) Woot, you finally discovered polymorphism - congratulations! Diez From no.email at nospam.invalid Wed Mar 7 05:36:02 2012 From: no.email at nospam.invalid (Paul Rubin) Date: Wed, 07 Mar 2012 02:36:02 -0800 Subject: What's the best way to write this regular expression? References: <12783654.1174.1331073814011.JavaMail.geo-discussion-forums@yner4> <0c1a1890-dc80-41b6-abea-f90324dd7d75@2g2000yqk.googlegroups.com> Message-ID: <7x7gywofzh.fsf@ruckus.brouhaha.com> John Salerno writes: > The Beautiful Soup 4 documentation was very clear, and BS4 itself is > so simple and Pythonic. And best of all, since version 4 no longer > does the parsing itself, you can choose your own parser, and it works > with lxml, so I'll still be using lxml, but with a nice, clean overlay > for navigating the tree structure. I haven't used BS4 but have made good use of earlier versions. Main thing to understand is that an awful lot of HTML in the real world is malformed and will break an XML parser or anything that expects syntactically invalid HTML. People tend to write HTML that works well enough to render decently in browsers, whose parsers therefore have to be tolerant of bad errors. Beautiful Soup also tries to make sense of crappy, malformed, HTML. Partly as a result, it's dog slow compared to any serious XML parser. But it works very well if you don't mind the low speed. From fabiofz at gmail.com Wed Mar 7 05:38:49 2012 From: fabiofz at gmail.com (Fabio Zadrozny) Date: Wed, 7 Mar 2012 07:38:49 -0300 Subject: Error importing __init__ declared variable from another package In-Reply-To: References: Message-ID: On Wed, Feb 29, 2012 at 1:38 AM, Jason Veldicott wrote: >> > Hi, >> > >> > I have a simple configuration of modules as beneath, but an import error >> > is reported: >> > >> > /engine >> > ? ?(__init__ is empty here) >> > ? ?engine.py >> > /sim >> > ? ?__init__.py >> > >> > >> > The module engine.py imports a variable instantiated in sim.__init__ as >> > follows: >> > >> > ? ?from sim import var_name >> > ? ?var_name.func() >> > >> > The following error messaged is received on the func() call above >> > (Eclipse >> > PyDev): >> > >> > "undefined variable from import: func" >> Are you rephrasing or is this really the error message? If so run your >> program again on the command-line. Then please cut and paste the error >> message together with the traceback. >> > Any idea why this is causing an error? >> What version of Python are you using? >> What does sim/__init__.py contain? > > > > Thanks Peter. > > I'm using Python 2.6, but it works at the command line. ?The error only > appears in Eclipse as a red cross in the margin. ?The exact error msg, as > appears in a floating text caption on mouse over, is as I mentioned > (capitalised). > > Perhaps it is some issue in PyDev, maybe related to the version of Python > I'm using. > > I'm in the process of trying to solve another related import problem, and > wished to resolve this one in the hope that it might shed light on the > other.?But as it works beside the error icon appearing, I might just ignore > it and spare the trouble of precise identification of cause. Please report that as a bug in the PyDev sf tracker (please attach a sample project where this problem can be reproduced). Cheers, Fabio From praveen.patil.external at airbus.com Wed Mar 7 06:06:14 2012 From: praveen.patil.external at airbus.com (PATIL, Praveen (L&T)) Date: Wed, 7 Mar 2012 12:06:14 +0100 Subject: Need help in wx.ListBox edit Message-ID: <17690_1331118378_4F57412A_17690_6341_1_1120F6C19DDA9B4397B57F8CBBD2349204D57AD190@DE0-MAILMBX-P21.res.airbus.corp> Hi , I am using wxWidget for GUI programming. I need help in editing text appended in wx.ListBox(). Which wx API's do I need to use ? I would like to edit text on mouse double click event . Thanks in advance. Praveen. The information in this e-mail is confidential. The contents may not be disclosed or used by anyone other than the addressee. Access to this e-mail by anyone else is unauthorised. If you are not the intended recipient, please notify Airbus immediately and delete this e-mail. Airbus cannot accept any responsibility for the accuracy or completeness of this e-mail as it has been sent over public networks. If you have any concerns over the content of this message or its Accuracy or Integrity, please contact Airbus immediately. All outgoing e-mails from Airbus are checked using regularly updated virus scanning software but you should take whatever measures you deem to be appropriate to ensure that this message and any attachments are virus free. -------------- next part -------------- An HTML attachment was scrubbed... URL: From ben+python at benfinney.id.au Wed Mar 7 06:18:50 2012 From: ben+python at benfinney.id.au (Ben Finney) Date: Wed, 07 Mar 2012 22:18:50 +1100 Subject: "Decoding unicode is not supported" in unusual situation References: <4f571b94$0$12037$742ec2ed@news.sonic.net> Message-ID: <8762egmzfp.fsf@benfinney.id.au> deets at web.de (Diez B. Roggisch) writes: > John Nagle writes: > > > I think that somewhere in "suds", they subclass the "unicode" type. > > That's almost too cute. > > > > The proper test is > > > > isinstance(s,unicode) > > Woot, you finally discovered polymorphism - congratulations! If by ?discovered? you mean ?broke?. John, polymorphism entails that it *doesn't matter* whether the object inherits from any particular type; it only matters whether the object behaves correctly. So rather than testing whether the object inherits from ?unicode?, test whether it behaves how you expect ? preferably by just using it as though it does behave that way. -- \ Lucifer: ?Just sign the Contract, sir, and the Piano is yours.? | `\ Ray: ?Sheesh! This is long! Mind if I sign it now and read it | _o__) later?? ?http://www.achewood.com/ | Ben Finney From steve+comp.lang.python at pearwood.info Wed Mar 7 06:42:53 2012 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 07 Mar 2012 11:42:53 GMT Subject: "Decoding unicode is not supported" in unusual situation References: <4f571b94$0$12037$742ec2ed@news.sonic.net> <8762egmzfp.fsf@benfinney.id.au> Message-ID: <4f5749bc$0$29989$c3e8da3$5496439d@news.astraweb.com> On Wed, 07 Mar 2012 22:18:50 +1100, Ben Finney wrote: > deets at web.de (Diez B. Roggisch) writes: > >> John Nagle writes: >> >> > I think that somewhere in "suds", they subclass the "unicode" type. >> > That's almost too cute. >> > >> > The proper test is >> > >> > isinstance(s,unicode) >> >> Woot, you finally discovered polymorphism - congratulations! > > If by ?discovered? you mean ?broke?. > > John, polymorphism entails that it *doesn't matter* whether the object > inherits from any particular type; it only matters whether the object > behaves correctly. > > So rather than testing whether the object inherits from ?unicode?, test > whether it behaves how you expect ? preferably by just using it as > though it does behave that way. I must admit that I can't quite understand John Nagle's original post, so I could be wrong, but I *think* that both you and Diez have misunderstood the nature of John's complaint. I *think* he is complaining that some other library -- suds? -- has a broken test for Unicode, by using: if type(s) is unicode: ... instead of if isinstance(s, unicode): ... Consequently, when the library passes a unicode *subclass* to the tounicode function, the "type() is unicode" test fails. That's a bad bug. It's arguable that the library shouldn't even use isinstance, but that's an argument for another day. -- Steven From arun.sathyan at ust-global.com Wed Mar 7 08:20:22 2012 From: arun.sathyan at ust-global.com (arun1) Date: Wed, 7 Mar 2012 05:20:22 -0800 (PST) Subject: RotatingFileHandler Fails In-Reply-To: <64b7d1bb-21b0-4c72-aa93-692504201f7e@j8g2000yqm.googlegroups.com> References: <64b7d1bb-21b0-4c72-aa93-692504201f7e@j8g2000yqm.googlegroups.com> Message-ID: <1331126422785-4554381.post@n6.nabble.com> Hi nac, NTSafeLogging.py is working fine without any errors, but its not rotating the log files as rotatingfilehandler does. Do you have any working sample with NTSafeLogging which rotates the log file. logging issue with subprocess.Popen can be solved using this code import threading lock = threading.RLock() def acquire_lock(): lock.acquire() def release_lock(): lock.release() call the acquire_lock() at the begining of method and release_lock() at the end -- View this message in context: http://python.6.n6.nabble.com/RotatingFileHandler-Fails-tp4542769p4554381.html Sent from the Python - python-list mailing list archive at Nabble.com. From 88.janaki at gmail.com Wed Mar 7 08:44:18 2012 From: 88.janaki at gmail.com (janaki rajamani) Date: Wed, 7 Mar 2012 19:14:18 +0530 Subject: GUI components in python Message-ID: Hi I am stuck with the brain workshop software implemented using python. The code involves a lot of GUI elements and i am familar only with the basic python programming. I would like to know whether there are built in classes to support GUI elements or arethey project dependant. -- janaki -------------- next part -------------- An HTML attachment was scrubbed... URL: From alec.taylor6 at gmail.com Wed Mar 7 09:25:44 2012 From: alec.taylor6 at gmail.com (Alec Taylor) Date: Thu, 8 Mar 2012 01:25:44 +1100 Subject: Porting the 2-3 heap data-structure library from C to Python Message-ID: I am planning to port the 2-3 heap data-structure as described by Professor Tadao Takaoka in Theory of 2-3 Heaps published in 1999 and available in PDF: http://www.cosc.canterbury.ac.nz/tad.takaoka/2-3heaps.pdf The source-code used has been made available: http://www.cosc.canterbury.ac.nz/research/RG/alg/ttheap.h http://www.cosc.canterbury.ac.nz/research/RG/alg/ttheap.c I plan on wrapping it in a class. This tutorial I used to just test out calling C within Python (http://richizo.wordpress.com/2009/01/25/calling-c-functions-inside-python/) and it seems to work, but this might not be the recommended method. Any best practices for how best to wrap the 2-3 heap data-structure from C to Python? Thanks for all suggestions, Alec Taylor From stefan_ml at behnel.de Wed Mar 7 09:52:27 2012 From: stefan_ml at behnel.de (Stefan Behnel) Date: Wed, 07 Mar 2012 15:52:27 +0100 Subject: Porting the 2-3 heap data-structure library from C to Python In-Reply-To: References: Message-ID: Alec Taylor, 07.03.2012 15:25: > I am planning to port the 2-3 heap data-structure as described by > Professor Tadao Takaoka in Theory of 2-3 Heaps published in 1999 and > available in PDF: > http://www.cosc.canterbury.ac.nz/tad.takaoka/2-3heaps.pdf > > The source-code used has been made available: > http://www.cosc.canterbury.ac.nz/research/RG/alg/ttheap.h > http://www.cosc.canterbury.ac.nz/research/RG/alg/ttheap.c > > I plan on wrapping it in a class. > > This tutorial I used to just test out calling C within Python > (http://richizo.wordpress.com/2009/01/25/calling-c-functions-inside-python/) > and it seems to work, but this might not be the recommended method. > > Any best practices for how best to wrap the 2-3 heap data-structure > from C to Python? For data structures, where performance tends to matter, it's usually best to start with Cython right away, instead of using ctypes. http://cython.org/ Here's a tutorial for wrapping a C library with it: http://docs.cython.org/src/tutorial/clibraries.html Stefan From gslindstrom at gmail.com Wed Mar 7 09:52:48 2012 From: gslindstrom at gmail.com (Greg Lindstrom) Date: Wed, 7 Mar 2012 08:52:48 -0600 Subject: Python 3.2 and MS Outlook Message-ID: Is there documentation showing how to read from a Microsoft Outlook server using Python 3.2. I've done it with 2.x, but can't find anything to help me with 3.2. Thanks, --greg -------------- next part -------------- An HTML attachment was scrubbed... URL: From arun.sathyan at ust-global.com Wed Mar 7 10:33:33 2012 From: arun.sathyan at ust-global.com (arun1) Date: Wed, 7 Mar 2012 07:33:33 -0800 (PST) Subject: RotatingFileHandler Fails In-Reply-To: <64b7d1bb-21b0-4c72-aa93-692504201f7e@j8g2000yqm.googlegroups.com> References: <64b7d1bb-21b0-4c72-aa93-692504201f7e@j8g2000yqm.googlegroups.com> Message-ID: <1331134413226-4554781.post@n6.nabble.com> Hi, Actually NonInheritedRotatingFileHandler is rotating the log files but some times it falis and showing I/O errors while the log file limit reaches the given size. Thanks Arun -- View this message in context: http://python.6.n6.nabble.com/RotatingFileHandler-Fails-tp4542769p4554781.html Sent from the Python - python-list mailing list archive at Nabble.com. From hniksic at xemacs.org Wed Mar 7 10:48:18 2012 From: hniksic at xemacs.org (Hrvoje Niksic) Date: Wed, 07 Mar 2012 16:48:18 +0100 Subject: Porting the 2-3 heap data-structure library from C to Python References: Message-ID: <87boo89zul.fsf@xemacs.org> Alec Taylor writes: > The source-code used has been made available: > http://www.cosc.canterbury.ac.nz/research/RG/alg/ttheap.h > http://www.cosc.canterbury.ac.nz/research/RG/alg/ttheap.c > > I plan on wrapping it in a class. You should get acquainted with the Python/C API, which is the standard way of extending Python with high-performance (and/or system-specific) C code. See "Extending and Embedding" and "Python/C API" sections at http://docs.python.org/. There is also a mailing list for help with the C API, see http://mail.python.org/mailman/listinfo/capi-sig for details. From stefan_ml at behnel.de Wed Mar 7 11:18:06 2012 From: stefan_ml at behnel.de (Stefan Behnel) Date: Wed, 07 Mar 2012 17:18:06 +0100 Subject: Porting the 2-3 heap data-structure library from C to Python In-Reply-To: <87boo89zul.fsf@xemacs.org> References: <87boo89zul.fsf@xemacs.org> Message-ID: Hrvoje Niksic, 07.03.2012 16:48: > Alec Taylor writes: > >> The source-code used has been made available: >> http://www.cosc.canterbury.ac.nz/research/RG/alg/ttheap.h >> http://www.cosc.canterbury.ac.nz/research/RG/alg/ttheap.c >> >> I plan on wrapping it in a class. > > You should get acquainted with the Python/C API If it proves necessary, yes. > which is the standard way of extending Python with high-performance > (and/or system-specific) C code. Well, it's *one* way. Certainly not the easiest way, neither the most portable and you'll have a hard time making it the fastest. Stefan From jagteraho2006 at gmail.com Wed Mar 7 12:16:27 2012 From: jagteraho2006 at gmail.com (amar Singh) Date: Wed, 7 Mar 2012 09:16:27 -0800 (PST) Subject: help: confused about python flavors.... References: <948f80c1-877a-4a74-8adc-9d4ae702574f@l1g2000vbc.googlegroups.com> Message-ID: <485b6397-ab31-444c-b803-73ad952d98fc@eb6g2000vbb.googlegroups.com> On Mar 7, 9:41?am, Dennis Lee Bieber wrote: > On Tue, 6 Mar 2012 20:06:37 -0800 (PST), amar Singh > declaimed the following in > gmane.comp.python.general: > > > Hi, > > > I am confused between plain python, numpy, scipy, pylab, matplotlib. > > > I have high familiarity with matlab, but the computer I use does not > > have it. So moving to python. > > What should I use? and the best way to use it. I will be running > > matlab-like scripts sometimes on the shell prompt and sometimes on the > > command line. > > ? ? ? ? If Matlab compatibility is a high constraint, I'll speak heresy and > suggest you might look at Octavehttp://en.wikipedia.org/wiki/GNU_Octave > > ? ? ? ? Python is stand-alone programming/scripting language. Numpy is an > extension package adding array/matrix math operations but the syntax > won't be a direct match to Matlab; Scipy is an extension package that, > well, extends Numpy. Matplotlib is a separate package for graphical > plotting of array data. {simplistic explanation} > > -- > ? ? ? ? Wulfraed ? ? ? ? ? ? ? ? Dennis Lee Bieber ? ? ? ? AF6VN > ? ? ? ? wlfr... at ix.netcom.com ? ?HTTP://wlfraed.home.netcom.com/ Thanks everyone for helping me on this. From gordon at panix.com Wed Mar 7 12:18:23 2012 From: gordon at panix.com (John Gordon) Date: Wed, 7 Mar 2012 17:18:23 +0000 (UTC) Subject: Project References: Message-ID: In Dev Dixit writes: > Please, tell me how to develop project on "how people intract with > social networing sites". First you need a more detailed description of exactly what you want. -- 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 nareshgbhat at gmail.com Wed Mar 7 12:43:13 2012 From: nareshgbhat at gmail.com (Naresh Bhat) Date: Wed, 7 Mar 2012 23:13:13 +0530 Subject: Python-2.6.1 ctypes test cases failing Message-ID: Hi All, I have the following setup Kernel version: linux-2.6.32.41 Python Version: Python-2.6.1 Hardware target: MIPS 64bit I am just trying to run python test cases, Observed that on my MIPS 64bit system only _ctypes related test cases are failing. Is there any available patch for this issue ?? Only _ctypes test cases are failing: ============================ root at cavium-octeonplus:~# root at cavium-octeonplus:~# python /usr/lib32/python2.6/test/test_ctypes.py ..................... .................................. test_doubleresult (ctypes.test.test_functions.FunctionTestCase) ... FAIL test_floatresult (ctypes.test.test_functions.FunctionTestCase) ... FAIL test_intresult (ctypes.test.test_functions.FunctionTestCase) ... FAIL test_longdoubleresult (ctypes.test.test_functions.FunctionTestCase) ... FAIL test_longlongresult (ctypes.test.test_functions.FunctionTestCase) ... FAIL test_wchar_parm (ctypes.test.test_functions.FunctionTestCase) ... FAIL test_wchar_result (ctypes.test.test_functions.FunctionTestCase) ... FAIL test_longdouble (ctypes.test.test_callbacks.Callbacks) ... FAIL test_integrate (ctypes.test.test_callbacks.SampleCallbacksTestCase) ... FAIL test_wchar_parm (ctypes.test.test_as_parameter.AsParamPropertyWrapperTestCase) ... FAIL test_wchar_parm (ctypes.test.test_as_parameter.AsParamWrapperTestCase) ... FAIL test_wchar_parm (ctypes.test.test_as_parameter.BasicWrapTestCase) ... FAIL test_qsort (ctypes.test.test_libc.LibTest) ... FAIL test_sqrt (ctypes.test.test_libc.LibTest) ... FAIL test_double (ctypes.test.test_cfuncs.CFunctions) ... FAIL test_double_plus (ctypes.test.test_cfuncs.CFunctions) ... FAIL test_float (ctypes.test.test_cfuncs.CFunctions) ... FAIL test_float_plus (ctypes.test.test_cfuncs.CFunctions) ... FAIL test_longdouble (ctypes.test.test_cfuncs.CFunctions) ... FAIL test_longdouble_plus (ctypes.test.test_cfuncs.CFunctions) ... FAIL --Thanks and Regards "For things to change, we must change" -Naresh Bhat From rodrick.brown at gmail.com Wed Mar 7 13:06:38 2012 From: rodrick.brown at gmail.com (Rodrick Brown) Date: Wed, 7 Mar 2012 13:06:38 -0500 Subject: Project In-Reply-To: References: Message-ID: <9C02C81E-BD8F-41DD-803E-F5EDC274A1EF@gmail.com> Pay a smart developer! Sent from my iPhone On Mar 7, 2012, at 4:46 AM, Dev Dixit wrote: > Please, tell me how to develop project on "how people intract with > social networing sites". > -- > http://mail.python.org/mailman/listinfo/python-list From ramit.prasad at jpmorgan.com Wed Mar 7 14:05:23 2012 From: ramit.prasad at jpmorgan.com (Prasad, Ramit) Date: Wed, 7 Mar 2012 19:05:23 +0000 Subject: are int, float, long, double, side-effects of computer engineering? In-Reply-To: References: <5aaded58-af09-41dc-9afd-56d7b7ced239@d7g2000pbl.googlegroups.com> <4F5681A6.9090707@calvinkim.org> Message-ID: <5B80DD153D7D744689F57F4FB69AF474194791@SCACMX008.exchad.jpmchase.net> Dennis Lee Bieber wrote: > It wouldn't surprise me to find out that modern CompSci degrees > don't even discuss machine representation of numbers. As a fairly recent graduate, I can assure you that they still do. Well, I should say at least my school did since I cannot speak for every other school. Ramit Ramit Prasad | JPMorgan Chase Investment Bank | Currencies Technology 712 Main Street | Houston, TX 77002 work phone: 713 - 216 - 5423 -- This email is confidential and subject to important disclaimers and conditions including on offers for the purchase or sale of securities, accuracy and completeness of information, viruses, confidentiality, legal privilege, and legal entity disclaimers, available at http://www.jpmorgan.com/pages/disclosures/email. From nagle at animats.com Wed Mar 7 14:25:47 2012 From: nagle at animats.com (John Nagle) Date: Wed, 07 Mar 2012 11:25:47 -0800 Subject: "Decoding unicode is not supported" in unusual situation In-Reply-To: <4f5749bc$0$29989$c3e8da3$5496439d@news.astraweb.com> References: <4f571b94$0$12037$742ec2ed@news.sonic.net> <8762egmzfp.fsf@benfinney.id.au> <4f5749bc$0$29989$c3e8da3$5496439d@news.astraweb.com> Message-ID: <4f57b63f$0$11986$742ec2ed@news.sonic.net> On 3/7/2012 3:42 AM, Steven D'Aprano wrote: > I *think* he is complaining that some other library -- suds? -- has a > broken test for Unicode, by using: > > if type(s) is unicode: ... > > instead of > > if isinstance(s, unicode): ... > > Consequently, when the library passes a unicode *subclass* to the > tounicode function, the "type() is unicode" test fails. That's a bad bug. No, that was my bug. The library bug, if any, is that you can't apply unicode(s, errors='replace') to a Unicode string. TypeError("Decoding unicode is not supported") is raised. However unicode(s) will accept Unicode input. The Python documentation ("http://docs.python.org/library/functions.html#unicode") does not mention this. It is therefore necessary to check the type before calling "unicode", or catch the undocumented TypeError exception afterward. John Nagle From tjreedy at udel.edu Wed Mar 7 14:25:59 2012 From: tjreedy at udel.edu (Terry Reedy) Date: Wed, 07 Mar 2012 14:25:59 -0500 Subject: Python-2.6.1 ctypes test cases failing In-Reply-To: References: Message-ID: On 3/7/2012 12:43 PM, Naresh Bhat wrote: > Hi All, > > I have the following setup > > Kernel version: linux-2.6.32.41 > Python Version: Python-2.6.1 > Hardware target: MIPS 64bit > > I am just trying to run python test cases, Observed that on my MIPS > 64bit system only _ctypes related test cases are failing. > > Is there any available patch for this issue ?? There have been patches to ctypes since 2.6.1. At minimum, you should be using the latest version of 2.6. Even better, perhaps, would be the latest version of 2.7, since it contain patches applied after 2.6 went to security fixes only. -- Terry Jan Reedy From pkleiweg at xs4all.nl Wed Mar 7 14:41:46 2012 From: pkleiweg at xs4all.nl (Peter Kleiweg) Date: Wed, 7 Mar 2012 20:41:46 +0100 Subject: sys.stdout.detach() results in ValueError Message-ID: I want to write out some binary data to stdout in Python3. I thought the way to do this was to call detach on sys.stdout. But apparently, you can't. Here is a minimal script: #!/usr/bin/env python3.1 import sys fp = sys.stdout.detach() Not yet using fp in any way, this script gives the following error: Exception ValueError: 'underlying buffer has been detached' in Same in Python 3.1.4 and Python 3.2.2 So, what do I do if I want to send binary data to stdout? -- Peter Kleiweg http://pkleiweg.home.xs4all.nl/ From wanderer at dialup4less.com Wed Mar 7 14:49:49 2012 From: wanderer at dialup4less.com (Wanderer) Date: Wed, 7 Mar 2012 11:49:49 -0800 (PST) Subject: Python recursive tree, linked list thingy Message-ID: I have a list of defective CCD pixels and I need to find clusters where a cluster is a group of adjacent defective pixels. This seems to me to be a classic linked list tree search.I take a pixel from the defective list and check if an adjacent pixel is in the list. If it is I add the pixel to the cluster and remove it from the defective list. I then check an adjacent pixel of the new pixel and so on down the branch until I don't find a defective pixel. The I move up to the previous pixel and check the next adjacent pixel and so on until I'm back at the head I can't find any more defective adjacent pixels. How do you handle this sort of thing in Python? From ian.g.kelly at gmail.com Wed Mar 7 15:03:52 2012 From: ian.g.kelly at gmail.com (Ian Kelly) Date: Wed, 7 Mar 2012 13:03:52 -0700 Subject: Python recursive tree, linked list thingy In-Reply-To: References: Message-ID: On Wed, Mar 7, 2012 at 12:49 PM, Wanderer wrote: > I have a list of defective CCD pixels and I need to find clusters > where a cluster is a group of adjacent defective pixels. This seems to > me to be a classic linked list tree search.I take a pixel from the > defective list and check if an adjacent pixel is in the list. If it is > I add the pixel to the cluster and remove it from the defective list. > I then check an adjacent pixel of the new pixel and so on down the > branch until I don't find a defective pixel. The I move up to the > previous pixel and check the next adjacent pixel ?and so on until I'm > back at the head I can't find any more defective adjacent pixels. How > do you handle this sort of thing in Python? A set of defective pixels would be the probable choice, since it offers efficient membership testing. From ramit.prasad at jpmorgan.com Wed Mar 7 15:03:57 2012 From: ramit.prasad at jpmorgan.com (Prasad, Ramit) Date: Wed, 7 Mar 2012 20:03:57 +0000 Subject: Project In-Reply-To: References: Message-ID: <5B80DD153D7D744689F57F4FB69AF474195563@SCACMX008.exchad.jpmchase.net> > > Please, tell me how to develop project on "how people intract with > > social networing sites". > > This sounds more like a social sciences study than anything > programming related... > > And since I don't do such sites, it may be intractable... Or he could be wanting to know how to use something like Facebook API, but with such a vague description it is hard to say. Even harder to be interested in helping since that is such a broad scope. Ramit Ramit Prasad | JPMorgan Chase Investment Bank | Currencies Technology 712 Main Street | Houston, TX 77002 work phone: 713 - 216 - 5423 -- This email is confidential and subject to important disclaimers and conditions including on offers for the purchase or sale of securities, accuracy and completeness of information, viruses, confidentiality, legal privilege, and legal entity disclaimers, available at http://www.jpmorgan.com/pages/disclosures/email. From python at mrabarnett.plus.com Wed Mar 7 15:12:21 2012 From: python at mrabarnett.plus.com (MRAB) Date: Wed, 07 Mar 2012 20:12:21 +0000 Subject: Python recursive tree, linked list thingy In-Reply-To: References: Message-ID: <4F57C125.5020903@mrabarnett.plus.com> On 07/03/2012 19:49, Wanderer wrote: > I have a list of defective CCD pixels and I need to find clusters > where a cluster is a group of adjacent defective pixels. This seems to > me to be a classic linked list tree search.I take a pixel from the > defective list and check if an adjacent pixel is in the list. If it is > I add the pixel to the cluster and remove it from the defective list. > I then check an adjacent pixel of the new pixel and so on down the > branch until I don't find a defective pixel. The I move up to the > previous pixel and check the next adjacent pixel and so on until I'm > back at the head I can't find any more defective adjacent pixels. How > do you handle this sort of thing in Python? Something like this could work: clusters = [] while defective_set: to_do = {defective_set.pop()} done = set() while to_do: pixel = to_do.pop() neighbours = {n for n in defective_set if are_adjacent(n, pixel)} defective_set -= neighbours to_do |= neighbours done.add(pixel) clusters.append(done) From news at blinne.net Wed Mar 7 15:17:34 2012 From: news at blinne.net (Alexander Blinne) Date: Wed, 07 Mar 2012 21:17:34 +0100 Subject: Python recursive tree, linked list thingy In-Reply-To: References: Message-ID: <4f57c25d$0$6580$9b4e6d93@newsspool3.arcor-online.net> Am 07.03.2012 20:49, schrieb Wanderer: > I have a list of defective CCD pixels and I need to find clusters > where a cluster is a group of adjacent defective pixels. This seems to > me to be a classic linked list tree search.I take a pixel from the > defective list and check if an adjacent pixel is in the list. If it is > I add the pixel to the cluster and remove it from the defective list. > I then check an adjacent pixel of the new pixel and so on down the > branch until I don't find a defective pixel. The I move up to the > previous pixel and check the next adjacent pixel and so on until I'm > back at the head I can't find any more defective adjacent pixels. How > do you handle this sort of thing in Python? I'd do something like (code not tested): defective_list = [(x1, y1), (x2, y2), ...] #list of coordinates of #defective pixel #build one cluster: cluster_start = defective_list.pop() #starting point buf = [] #buffer for added pixels buf.push(cluster_start) cluster = [] cluster.push(cluster_start) while len(buf)>0: i = buf.pop() for b, d in itertools.product(xrange(2), [-1,1]): #4 neighbours j = list(i) j[b] += d j = tuple(j) if outside_lcd(j) or j in cluster or j not in defective_list: continue defective_list.remove(j) cluster.push(j) buf.push(j) return cluster and repeat it until defective_list is empty. From ian.g.kelly at gmail.com Wed Mar 7 15:27:46 2012 From: ian.g.kelly at gmail.com (Ian Kelly) Date: Wed, 7 Mar 2012 13:27:46 -0700 Subject: Python recursive tree, linked list thingy In-Reply-To: References: Message-ID: On Wed, Mar 7, 2012 at 1:03 PM, Ian Kelly wrote: > A set of defective pixels would be the probable choice, since it > offers efficient membership testing. Some actual code, using a recursive generator: def get_cluster(defective, pixel): yield pixel (row, column) = pixel for adjacent in [(row - 1, column), (row, column - 1), (row, column + 1), (row + 1, column)]: if adjacent in defective: defective.remove(adjacent) for cluster_pixel in get_cluster(defective, adjacent): yield cluster_pixel defective = {(327, 415), (180, 97), (326, 415), (42, 15), (180, 98), (325, 414), (325, 415)} clusters = [] while defective: pixel = defective.pop() clusters.append(list(get_cluster(defective, pixel))) from pprint import pprint pprint(clusters) Cheers, Ian From johnjsal at gmail.com Wed Mar 7 15:39:22 2012 From: johnjsal at gmail.com (John Salerno) Date: Wed, 7 Mar 2012 12:39:22 -0800 (PST) Subject: What's the best way to write this regular expression? References: <12783654.1174.1331073814011.JavaMail.geo-discussion-forums@yner4> Message-ID: Ok, first major roadblock. I have no idea how to install Beautiful Soup or lxml on Windows! All I can find are .tar files. Based on what I've read, I can use the easy_setup module to install these types of files, but when I went to download the setuptools package, it only seemed to support Python 2.7. I'm using 3.2. Is 2.7 just the minimum version it requires? It didn't say something like "2.7+", so I wasn't sure, and I don't want to start installing a bunch of stuff that will clog up my directories and not even work. What's the best way for me to install these two packages? I've also seen a reference to using setup.py...is that a separate package too, or is that something that comes with Python by default? Thanks. From pkleiweg at xs4all.nl Wed Mar 7 15:57:03 2012 From: pkleiweg at xs4all.nl (Peter Kleiweg) Date: Wed, 7 Mar 2012 21:57:03 +0100 Subject: what is best method to set sys.stdout to utf-8? Message-ID: In Python 3, there seem to be two ways to set sys.stdout to utf-8 after the script has started: sys.stdout = codecs.getwriter('utf-8')(sys.stdout.detach()) sys.stdout = io.TextIOWrapper(sys.stdout.detach(), encoding='utf-8') I guess the second is better. At start-up, type(sys.stdout) is , and it's also after using the second method. After using the first method, type(sys.stdout) is changed to . Should I always use the second method? -- Peter Kleiweg http://pkleiweg.home.xs4all.nl/ From ian.g.kelly at gmail.com Wed Mar 7 16:01:16 2012 From: ian.g.kelly at gmail.com (Ian Kelly) Date: Wed, 7 Mar 2012 14:01:16 -0700 Subject: What's the best way to write this regular expression? In-Reply-To: References: <12783654.1174.1331073814011.JavaMail.geo-discussion-forums@yner4> Message-ID: On Wed, Mar 7, 2012 at 1:39 PM, John Salerno wrote: > Ok, first major roadblock. I have no idea how to install Beautiful > Soup or lxml on Windows! All I can find are .tar files. Based on what > I've read, I can use the easy_setup module to install these types of > files, but when I went to download the setuptools package, it only > seemed to support Python 2.7. I'm using 3.2. Is 2.7 just the minimum > version it requires? It didn't say something like "2.7+", so I wasn't > sure, and I don't want to start installing a bunch of stuff that will > clog up my directories and not even work. There is a fork of setuptools called "distribute" that supports Python 3. > What's the best way for me to install these two packages? I've also > seen a reference to using setup.py...is that a separate package too, > or is that something that comes with Python by default? setup.py is a file that should be included at the top-level of the .tar files you downloaded. Generally, to install something in that manner, you would navigate to that top-level folder and run "python setup.py install". If you have multiple Python versions installed and want to install the package for a specific version, then you would use that version of Python to run the setup.py file. From shane.neeley at gmail.com Wed Mar 7 16:02:43 2012 From: shane.neeley at gmail.com (Shane Neeley) Date: Wed, 7 Mar 2012 13:02:43 -0800 (PST) Subject: Python site-packages permission denied? Message-ID: <5849344.1361.1331154163099.JavaMail.geo-discussion-forums@pbls8> What do I need to do to successfully install a package onto python so that I can use it as a module? I have tried in terminal in the correct directory "python2.7 ./setup.py install" but it says permission denied. Shanes-MacBook-Pro:seisen-urllib2_file-cf4c4c8 chimpsarehungry$ python2.7.1 ./setup.py install -bash: python2.7.1: command not found Shanes-MacBook-Pro:seisen-urllib2_file-cf4c4c8 chimpsarehungry$ python ./setup.py install running install running build running build_py running install_lib copying build/lib/urllib2_file.py -> /Library/Python/2.7/site-packages error: /Library/Python/2.7/site-packages/urllib2_file.py: Permission denied Shanes-MacBook-Pro:seisen-urllib2_file-cf4c4c8 chimpsarehungry$ From johnjsal at gmail.com Wed Mar 7 16:11:17 2012 From: johnjsal at gmail.com (John Salerno) Date: Wed, 7 Mar 2012 15:11:17 -0600 Subject: What's the best way to write this regular expression? In-Reply-To: References: <12783654.1174.1331073814011.JavaMail.geo-discussion-forums@yner4> Message-ID: On Wed, Mar 7, 2012 at 3:01 PM, Ian Kelly wrote: > There is a fork of setuptools called "distribute" that supports Python 3. Thanks, I guess I'll give this a try tonight! > setup.py is a file that should be included at the top-level of the > .tar files you downloaded. ?Generally, to install something in that > manner, you would navigate to that top-level folder and run "python > setup.py install". ?If you have multiple Python versions installed and > want to install the package for a specific version, then you would use > that version of Python to run the setup.py file. The only files included in the .tar.gz file is a .tar file of the same name. So I guess the setup option doesn't exist for these particular packages. I'll try "distribute" tonight when I have some time to mess with all of this. So much work just to get a 3rd party module installed! From someone at someplace.invalid Wed Mar 7 16:22:52 2012 From: someone at someplace.invalid (HoneyMonster) Date: Wed, 7 Mar 2012 21:22:52 +0000 (UTC) Subject: Project References: Message-ID: On Wed, 07 Mar 2012 13:06:38 -0500, Rodrick Brown wrote: > Pay a smart developer! What? For homework? From benjamin.kaplan at case.edu Wed Mar 7 16:27:26 2012 From: benjamin.kaplan at case.edu (Benjamin Kaplan) Date: Wed, 7 Mar 2012 16:27:26 -0500 Subject: What's the best way to write this regular expression? In-Reply-To: References: <12783654.1174.1331073814011.JavaMail.geo-discussion-forums@yner4> Message-ID: On Wed, Mar 7, 2012 at 4:11 PM, John Salerno wrote: > > On Wed, Mar 7, 2012 at 3:01 PM, Ian Kelly wrote: > > > There is a fork of setuptools called "distribute" that supports Python > > 3. > > Thanks, I guess I'll give this a try tonight! > > > setup.py is a file that should be included at the top-level of the > > .tar files you downloaded. ?Generally, to install something in that > > manner, you would navigate to that top-level folder and run "python > > setup.py install". ?If you have multiple Python versions installed and > > want to install the package for a specific version, then you would use > > that version of Python to run the setup.py file. > > The only files included in the .tar.gz file is a .tar file of the same > name. So I guess the setup option doesn't exist for these particular > packages. I'll try "distribute" tonight when I have some time to mess > with all of this. > > So much work just to get a 3rd party module installed! > -- It's because your extraction program is weird. Gzip is a compression algorithm that operates on a single file. Tar is an archive format that combines multiple files into a single file. When we say "extract the .tar.gz", what we mean is both uncompress the tar file and then extract everything out of that. A lot of programs will do that in one step. If you look inside the tar file, you should find the setup.py. From clp2 at rebertia.com Wed Mar 7 16:30:24 2012 From: clp2 at rebertia.com (Chris Rebert) Date: Wed, 7 Mar 2012 13:30:24 -0800 Subject: Python site-packages permission denied? In-Reply-To: <5849344.1361.1331154163099.JavaMail.geo-discussion-forums@pbls8> References: <5849344.1361.1331154163099.JavaMail.geo-discussion-forums@pbls8> Message-ID: On Wed, Mar 7, 2012 at 1:02 PM, Shane Neeley wrote: > What do I need to do to successfully install a package onto python so that I can use it as a module? > > I have tried in terminal in the correct directory "python2.7 ./setup.py install" but it says permission denied. > > Shanes-MacBook-Pro:seisen-urllib2_file-cf4c4c8 chimpsarehungry$ python2.7.1 ./setup.py install > -bash: python2.7.1: command not found > Shanes-MacBook-Pro:seisen-urllib2_file-cf4c4c8 chimpsarehungry$ python ./setup.py install > running install > running build > running build_py > running install_lib > copying build/lib/urllib2_file.py -> /Library/Python/2.7/site-packages > error: /Library/Python/2.7/site-packages/urllib2_file.py: Permission denied > Shanes-MacBook-Pro:seisen-urllib2_file-cf4c4c8 chimpsarehungry$ You generally shouldn't mess with Mac OS X's system copies of Python. Typically, one installs a separate copy using MacPorts, Fink, or whatever, and uses that instead. In any case, you generally need to `sudo` when installing stuff system-wide. Cheers, Chris From ramit.prasad at jpmorgan.com Wed Mar 7 16:31:03 2012 From: ramit.prasad at jpmorgan.com (Prasad, Ramit) Date: Wed, 7 Mar 2012 21:31:03 +0000 Subject: What's the best way to write this regular expression? In-Reply-To: References: <12783654.1174.1331073814011.JavaMail.geo-discussion-forums@yner4> Message-ID: <5B80DD153D7D744689F57F4FB69AF47419567C@SCACMX008.exchad.jpmchase.net> > The only files included in the .tar.gz file is a .tar file of the same > name. gz stands for gzip and is a form of compression (like rar/zip ). tar stands for a tape archive. It is basically a box that holds the files. So you need to "unzip" and then "open the box". Normally programs like WinZip / WinRar / 7-zip will do both in one step so you do not need to. Not sure what program you are using... Ramit Ramit Prasad | JPMorgan Chase Investment Bank | Currencies Technology 712 Main Street | Houston, TX 77002 work phone: 713 - 216 - 5423 -- This email is confidential and subject to important disclaimers and conditions including on offers for the purchase or sale of securities, accuracy and completeness of information, viruses, confidentiality, legal privilege, and legal entity disclaimers, available at http://www.jpmorgan.com/pages/disclosures/email. From ramit.prasad at jpmorgan.com Wed Mar 7 16:32:32 2012 From: ramit.prasad at jpmorgan.com (Prasad, Ramit) Date: Wed, 7 Mar 2012 21:32:32 +0000 Subject: Project In-Reply-To: References: Message-ID: <5B80DD153D7D744689F57F4FB69AF474195695@SCACMX008.exchad.jpmchase.net> > > Pay a smart developer! > > What? For homework? Sure why not? Smart developers could use extra money ;) Ramit Ramit Prasad | JPMorgan Chase Investment Bank | Currencies Technology 712 Main Street | Houston, TX 77002 work phone: 713 - 216 - 5423 -- This email is confidential and subject to important disclaimers and conditions including on offers for the purchase or sale of securities, accuracy and completeness of information, viruses, confidentiality, legal privilege, and legal entity disclaimers, available at http://www.jpmorgan.com/pages/disclosures/email. From ian.g.kelly at gmail.com Wed Mar 7 16:34:59 2012 From: ian.g.kelly at gmail.com (Ian Kelly) Date: Wed, 7 Mar 2012 14:34:59 -0700 Subject: What's the best way to write this regular expression? In-Reply-To: References: <12783654.1174.1331073814011.JavaMail.geo-discussion-forums@yner4> Message-ID: On Wed, Mar 7, 2012 at 2:11 PM, John Salerno wrote: > The only files included in the .tar.gz file is a .tar file of the same > name. So I guess the setup option doesn't exist for these particular > packages. The setup.py file (as well as the other files) would be inside the .tar file. Unlike a Windows zip file, which does both archival and compression, Unix files are typically archived and compressed in two separate steps: "tar" denotes the archival format, and "gz" denotes the compression format. Some decompression programs are smart enough to recognize the .tar file and automatically extract it when decompressing. Others require you to decompress the .gz and extract the .tar separately -- it sounds like yours is one of the latter. From johnjsal at gmail.com Wed Mar 7 16:44:28 2012 From: johnjsal at gmail.com (John Salerno) Date: Wed, 7 Mar 2012 15:44:28 -0600 Subject: What's the best way to write this regular expression? In-Reply-To: References: <12783654.1174.1331073814011.JavaMail.geo-discussion-forums@yner4> Message-ID: On Wed, Mar 7, 2012 at 3:34 PM, Ian Kelly wrote: > The setup.py file (as well as the other files) would be inside the > .tar file. ?Unlike a Windows zip file, which does both archival and > compression, Unix files are typically archived and compressed in two > separate steps: "tar" denotes the archival format, and "gz" denotes > the compression format. ?Some decompression programs are smart enough > to recognize the .tar file and automatically extract it when > decompressing. ?Others require you to decompress the .gz and extract > the .tar separately -- it sounds like yours is one of the latter. Ah, I see now. After opening the gz file, there was a tar file inside, and then I just opened that file (I use 7zip for these types) and there was a whole host of stuff inside. I didn't realize the tar file itself was an archive, I thought it was the module! ::blush:: Maybe I don't need to mess with the "distribute" utility then, if I can just run the setup file. I'll try that first and see what happens. Thanks. From ben+python at benfinney.id.au Wed Mar 7 16:48:58 2012 From: ben+python at benfinney.id.au (Ben Finney) Date: Thu, 08 Mar 2012 08:48:58 +1100 Subject: "Decoding unicode is not supported" in unusual situation References: <4f571b94$0$12037$742ec2ed@news.sonic.net> <8762egmzfp.fsf@benfinney.id.au> <4f5749bc$0$29989$c3e8da3$5496439d@news.astraweb.com> <4f57b63f$0$11986$742ec2ed@news.sonic.net> Message-ID: <871up4m69h.fsf@benfinney.id.au> John Nagle writes: > The library bug, if any, is that you can't apply > > unicode(s, errors='replace') > > to a Unicode string. TypeError("Decoding unicode is not supported") is > raised. However > > unicode(s) > > will accept Unicode input. I think that's a Python bug. If the latter succeeds as a no-op, the former should also succeed as a no-op. Neither should ever get any errors when ?s? is a ?unicode? object already. > The Python documentation > ("http://docs.python.org/library/functions.html#unicode") does not > mention this. It is therefore necessary to check the type before > calling "unicode", or catch the undocumented TypeError exception > afterward. Yes, this check should not be necessary; calling the ?unicode? constructor with an object that's already an instance of ?unicode? should just return the object as-is, IMO. It shouldn't matter that you've specified how decoding errors are to be handled, because in that case no decoding happens anyway. Care to report that bug to , John? -- \ ?Those who write software only for pay should go hurt some | `\ other field.? ?Erik Naggum, in _gnu.misc.discuss_ | _o__) | Ben Finney From ben+python at benfinney.id.au Wed Mar 7 16:50:25 2012 From: ben+python at benfinney.id.au (Ben Finney) Date: Thu, 08 Mar 2012 08:50:25 +1100 Subject: Project References: Message-ID: <87wr6wkrmm.fsf@benfinney.id.au> Dev Dixit writes: > Please, tell me how to develop project on "how people intract with > social networing sites". Step one: collect data. Step two: ??? Step three: project! -- \ ?Try to become not a man of success, but try rather to become a | `\ man of value.? ?Albert Einstein | _o__) | Ben Finney From russ.paielli at gmail.com Wed Mar 7 17:02:14 2012 From: russ.paielli at gmail.com (Russ P.) Date: Wed, 7 Mar 2012 14:02:14 -0800 (PST) Subject: are int, float, long, double, side-effects of computer engineering? References: <5aaded58-af09-41dc-9afd-56d7b7ced239@d7g2000pbl.googlegroups.com> <8a3cd8d4-26d2-4cdf-b66d-43895a0bcd1e@qb4g2000pbb.googlegroups.com> Message-ID: <7a32aa69-e1c7-4129-be11-70ae461b34b8@od7g2000pbb.googlegroups.com> On Mar 6, 7:25?pm, rusi wrote: > On Mar 6, 6:11?am, Xah Lee wrote: > > > some additional info i thought is relevant. > > > are int, float, long, double, side-effects of computer engineering? > > It is a bit naive for computer scientists to club integers and reals > as mathematicians do given that for real numbers, even equality is > undecidable! > Mostly when a system like mathematica talks of real numbers it means > computable real numbers which is a subset of mathematical real numbers > (and of course a superset of floats) > > Seehttp://en.wikipedia.org/wiki/Computable_number#Can_computable_numbers... I might add that Mathematica is designed mainly for symbolic computation, whereas IEEE floating point numbers are intended for numerical computation. Those are two very different endeavors. I played with Mathematica a bit several years ago, and I know it can do numerical computation too. I wonder if it resorts to IEEE floating point numbers when it does. From driscoll at cs.wisc.edu Wed Mar 7 17:02:42 2012 From: driscoll at cs.wisc.edu (Evan Driscoll) Date: Wed, 07 Mar 2012 16:02:42 -0600 Subject: What's the best way to write this regular expression? In-Reply-To: <5B80DD153D7D744689F57F4FB69AF47419567C@SCACMX008.exchad.jpmchase.net> References: <12783654.1174.1331073814011.JavaMail.geo-discussion-forums@yner4> <5B80DD153D7D744689F57F4FB69AF47419567C@SCACMX008.exchad.jpmchase.net> Message-ID: <4F57DB02.8040700@cs.wisc.edu> On 01/-10/-28163 01:59 PM, Prasad, Ramit wrote: > gz stands for gzip and is a form of compression (like rar/zip ). > tar stands for a tape archive. It is basically a box that holds the > files. So you need to "unzip" and then "open the box". > > Normally programs like WinZip / WinRar / 7-zip will do both in one step > so you do not need to. Not sure what program you are using... I'm not sure what 7-zip you're referring to, because I use 7-zip and it's always been a two-step process for me... (Though I can't say I've looked through the preferences dialog for a "extract .tar.gz files in one go" setting.) Evan From mining.facts at googlemail.com Wed Mar 7 17:02:51 2012 From: mining.facts at googlemail.com (Christian) Date: Wed, 7 Mar 2012 14:02:51 -0800 (PST) Subject: BitSet &Redis Message-ID: <399c9d09-8e20-4db6-8f5b-bc7f3e683329@k24g2000yqe.googlegroups.com> I play around with redis. Isn't it possible to handle BitSet with Python "as" in Java? BitSet users = BitSet.valueOf(redis.get(key.getBytes())); all.or(users); System.out.println(all.cardinality()) I try something with the struct and bitstring libs , but haven't any success. Even the follow snippet didn't work, beacause bitset[0] isn't approriate. bitset = r.get('bytestringFromRedis') x = "{0:b}".format(ord(bitset[0])) Thanks in advance Christian From d at davea.name Wed Mar 7 17:14:35 2012 From: d at davea.name (Dave Angel) Date: Wed, 07 Mar 2012 17:14:35 -0500 Subject: sys.stdout.detach() results in ValueError In-Reply-To: References: Message-ID: <4F57DDCB.50209@davea.name> On 03/07/2012 02:41 PM, Peter Kleiweg wrote: > I want to write out some binary data to stdout in Python3. I > thought the way to do this was to call detach on sys.stdout. But > apparently, you can't. Here is a minimal script: > > #!/usr/bin/env python3.1 > import sys > fp = sys.stdout.detach() > > Not yet using fp in any way, this script gives the following error: > > Exception ValueError: 'underlying buffer has been detached' in > > Same in Python 3.1.4 and Python 3.2.2 > > So, what do I do if I want to send binary data to stdout? > > > sys.stdout.write( some_binary_data ) Why should you need to do some funny manipulation? If you have some other unstated motivation, better ask a clearer question. -- DaveA From pkleiweg at xs4all.nl Wed Mar 7 17:35:46 2012 From: pkleiweg at xs4all.nl (Peter Kleiweg) Date: Wed, 7 Mar 2012 23:35:46 +0100 Subject: sys.stdout.detach() results in ValueError In-Reply-To: References: Message-ID: Dave Angel schreef op de 7e dag van de lentemaand van het jaar 2012: > On 03/07/2012 02:41 PM, Peter Kleiweg wrote: > > I want to write out some binary data to stdout in Python3. I > > thought the way to do this was to call detach on sys.stdout. But > > apparently, you can't. Here is a minimal script: > > > > #!/usr/bin/env python3.1 > > import sys > > fp = sys.stdout.detach() > > > > Not yet using fp in any way, this script gives the following error: > > > > Exception ValueError: 'underlying buffer has been detached' in > > > > Same in Python 3.1.4 and Python 3.2.2 > > > > So, what do I do if I want to send binary data to stdout? > > > > > > > > sys.stdout.write( some_binary_data ) TypeError: must be str, not bytes -- Peter Kleiweg http://pkleiweg.home.xs4all.nl/ From steve+comp.lang.python at pearwood.info Wed Mar 7 18:26:37 2012 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 07 Mar 2012 23:26:37 GMT Subject: "Decoding unicode is not supported" in unusual situation References: <4f571b94$0$12037$742ec2ed@news.sonic.net> <8762egmzfp.fsf@benfinney.id.au> <4f5749bc$0$29989$c3e8da3$5496439d@news.astraweb.com> <4f57b63f$0$11986$742ec2ed@news.sonic.net> <871up4m69h.fsf@benfinney.id.au> Message-ID: <4f57eeac$0$29989$c3e8da3$5496439d@news.astraweb.com> On Thu, 08 Mar 2012 08:48:58 +1100, Ben Finney wrote: > John Nagle writes: > >> The library bug, if any, is that you can't apply >> >> unicode(s, errors='replace') >> >> to a Unicode string. TypeError("Decoding unicode is not supported") is >> raised. However >> >> unicode(s) >> >> will accept Unicode input. > > I think that's a Python bug. If the latter succeeds as a no-op, the > former should also succeed as a no-op. Neither should ever get any > errors when ?s? is a ?unicode? object already. No. The semantics of the unicode function (technically: a type constructor) are well-defined, and there are two distinct behaviours: unicode(obj) is analogous to str(obj), and it attempts to convert obj to a unicode string by calling obj.__unicode__, if it exists, or __str__ if it doesn't. No encoding or decoding is attempted in the event that obj is a unicode instance. unicode(obj, encoding, errors) is explicitly stated in the docs as decoding obj if EITHER of encoding or errors is given, AND that obj must be either an 8-bit string (bytes) or a buffer object. It is true that u''.decode() will succeed, in Python 2, but the fact that unicode objects have a decode method at all is IMO a bug. It has also been corrected in Python 3, where (unicode) str objects no longer have a decode method, and bytes objects no longer have an encode method. >> The Python documentation >> ("http://docs.python.org/library/functions.html#unicode") does not >> mention this. Yes it does. It is is the SECOND sentence, immediately after the summary line: unicode([object[, encoding[, errors]]]) Return the Unicode string version of object using one of the following modes: If encoding and/or errors are given, unicode() will decode the object which can either be an 8-bit string or a character buffer using the codec for encoding. ... Admittedly, it doesn't *explicitly* state that TypeError will be raised, but what other exception kind would you expect when you supply an argument of the wrong type? >> It is therefore necessary to check the type before >> calling "unicode", or catch the undocumented TypeError exception >> afterward. > > Yes, this check should not be necessary; calling the ?unicode? > constructor with an object that's already an instance of ?unicode? > should just return the object as-is, IMO. It shouldn't matter that > you've specified how decoding errors are to be handled, because in that > case no decoding happens anyway. I don't believe that it is the job of unicode() to Do What I Mean, but only to Do What I Say. If I *explicitly* tell unicode() to decode the argument (by specifying either the codec or the error handler or both) then it should not double-guess me and ignore the extra parameters. End-user applications may, with care, try to be smart and DWIM, but library functions should be dumb and should do what they are told. -- Steven From tjreedy at udel.edu Wed Mar 7 19:03:41 2012 From: tjreedy at udel.edu (Terry Reedy) Date: Wed, 07 Mar 2012 19:03:41 -0500 Subject: "Decoding unicode is not supported" in unusual situation In-Reply-To: <4f57eeac$0$29989$c3e8da3$5496439d@news.astraweb.com> References: <4f571b94$0$12037$742ec2ed@news.sonic.net> <8762egmzfp.fsf@benfinney.id.au> <4f5749bc$0$29989$c3e8da3$5496439d@news.astraweb.com> <4f57b63f$0$11986$742ec2ed@news.sonic.net> <871up4m69h.fsf@benfinney.id.au> <4f57eeac$0$29989$c3e8da3$5496439d@news.astraweb.com> Message-ID: On 3/7/2012 6:26 PM, Steven D'Aprano wrote: > On Thu, 08 Mar 2012 08:48:58 +1100, Ben Finney wrote: > >> John Nagle writes: >> >>> The library bug, if any, is that you can't apply >>> >>> unicode(s, errors='replace') >>> >>> to a Unicode string. TypeError("Decoding unicode is not supported") is >>> raised. However >>> >>> unicode(s) >>> >>> will accept Unicode input. >> >> I think that's a Python bug. If the latter succeeds as a no-op, the >> former should also succeed as a no-op. Neither should ever get any >> errors when ?s? is a ?unicode? object already. > No. The semantics of the unicode function (technically: a type > constructor) are well-defined, and there are two distinct behaviours: > > unicode(obj) > > is analogous to str(obj), and it attempts to convert obj to a unicode > string by calling obj.__unicode__, if it exists, or __str__ if it > doesn't. No encoding or decoding is attempted in the event that obj is a > unicode instance. > > unicode(obj, encoding, errors) > > is explicitly stated in the docs as decoding obj if EITHER of encoding or > errors is given, AND that obj must be either an 8-bit string (bytes) or a > buffer object. > > It is true that u''.decode() will succeed, in Python 2, but the fact that > unicode objects have a decode method at all is IMO a bug. It has also I believe that is because in Py 2, codecs and .encode/.decode were used for same type recoding like base64, uu coding. That was simplified in Py3 so that 'decoding' is bytes to string and 'encoding' is string to bytes, and base64, etc, are only done in their separate modules and not also duplicated in the codecs machinery. > been corrected in Python 3, where (unicode) str objects no longer have a > decode method, and bytes objects no longer have an encode method. > > >>> The Python documentation >>> ("http://docs.python.org/library/functions.html#unicode") does not >>> mention this. > > Yes it does. It is is the SECOND sentence, immediately after the summary > line: > > unicode([object[, encoding[, errors]]]) > Return the Unicode string version of object using one of the > following modes: > > If encoding and/or errors are given, unicode() will decode the object > which can either be an 8-bit string or a character buffer using the > codec for encoding. ... > > > Admittedly, it doesn't *explicitly* state that TypeError will be raised, > but what other exception kind would you expect when you supply an > argument of the wrong type? What you have correctly pointed out is that there is no discrepancy between doc and behavior and hence no bug for the purpose of the tracker. Thanks. >>> It is therefore necessary to check the type before >>> calling "unicode", or catch the undocumented TypeError exception >>> afterward. >> >> Yes, this check should not be necessary; calling the ?unicode? >> constructor with an object that's already an instance of ?unicode? >> should just return the object as-is, IMO. It shouldn't matter that >> you've specified how decoding errors are to be handled, because in that >> case no decoding happens anyway. > > I don't believe that it is the job of unicode() to Do What I Mean, but > only to Do What I Say. If I *explicitly* tell unicode() to decode the > argument (by specifying either the codec or the error handler or both) > then it should not double-guess me and ignore the extra parameters. > > End-user applications may, with care, try to be smart and DWIM, but > library functions should be dumb and should do what they are told. -- Terry Jan Reedy From tjreedy at udel.edu Wed Mar 7 19:10:25 2012 From: tjreedy at udel.edu (Terry Reedy) Date: Wed, 07 Mar 2012 19:10:25 -0500 Subject: sys.stdout.detach() results in ValueError In-Reply-To: References: Message-ID: On 3/7/2012 5:35 PM, Peter Kleiweg wrote: > Dave Angel schreef op de 7e dag van de lentemaand van het jaar 2012: > >> On 03/07/2012 02:41 PM, Peter Kleiweg wrote: >>> I want to write out some binary data to stdout in Python3. I >>> thought the way to do this was to call detach on sys.stdout. But >>> apparently, you can't. Here is a minimal script: >>> >>> #!/usr/bin/env python3.1 >>> import sys >>> fp = sys.stdout.detach() >>> >>> Not yet using fp in any way, this script gives the following error: >>> >>> Exception ValueError: 'underlying buffer has been detached' in >>> >>> Same in Python 3.1.4 and Python 3.2.2 >>> >>> So, what do I do if I want to send binary data to stdout? >>> >>> >>> >> >> sys.stdout.write( some_binary_data ) > > TypeError: must be str, not bytes Right, you can only send binary data to file opened in binary mode. The default sys.stdout is in text mode. I am pretty sure that remains true even if stdout is redirected. (You did not mention your OS.) You would have to open such a file and make sys.stdout point to it. sys.stdout = my_binary_file. But why do that? Just open the file and write to it directly without the above. -- Terry Jan Reedy From tjreedy at udel.edu Wed Mar 7 19:12:59 2012 From: tjreedy at udel.edu (Terry Reedy) Date: Wed, 07 Mar 2012 19:12:59 -0500 Subject: what is best method to set sys.stdout to utf-8? In-Reply-To: References: Message-ID: On 3/7/2012 3:57 PM, Peter Kleiweg wrote: > > In Python 3, there seem to be two ways to set sys.stdout to > utf-8 after the script has started: > > sys.stdout = codecs.getwriter('utf-8')(sys.stdout.detach()) > > sys.stdout = io.TextIOWrapper(sys.stdout.detach(), encoding='utf-8') > > I guess the second is better. At start-up, type(sys.stdout) is > , and it's also after using the > second method. > > After using the first method, type(sys.stdout) is changed to > . > > Should I always use the second method? I would. The io module is more recent an partly replaces codecs. The latter remains for back compatibility and whatever it can do that io cannot. -- Terry Jan Reedy From gelonida at gmail.com Wed Mar 7 19:16:33 2012 From: gelonida at gmail.com (Gelonida N) Date: Thu, 08 Mar 2012 01:16:33 +0100 Subject: pickle/unpickle class which has changed In-Reply-To: References: Message-ID: On 03/07/2012 09:04 AM, Peter Otten wrote: > Gelonida N wrote: > If you know in advance that your class will undergo significant changes you > may also consider storing more stable data in a file format that can easily > be modified, e. g. json. > Good point, that's what I'm partially doing. I just wondered whether there were already some kind of pre-existing data migration tools / concepts / helpers like for example south for Django or whether I had to roll my own migration scheme for persistent non DB data. From metolone at gmail.com Wed Mar 7 19:41:36 2012 From: metolone at gmail.com (Mark Tolonen) Date: Wed, 7 Mar 2012 16:41:36 -0800 (PST) Subject: sys.stdout.detach() results in ValueError References: Message-ID: <483e3ddf-6452-411c-a9c2-5e9318a1a34e@d7g2000pbl.googlegroups.com> On Mar 7, 4:10?pm, Terry Reedy wrote: > On 3/7/2012 5:35 PM, Peter Kleiweg wrote: > > > > > > > > > > > Dave Angel schreef op de 7e dag van de lentemaand van het jaar 2012: > > >> On 03/07/2012 02:41 PM, Peter Kleiweg wrote: > >>> I want to write out some binary data to stdout in Python3. I > >>> thought the way to do this was to call detach on sys.stdout. But > >>> apparently, you can't. Here is a minimal script: > > >>> ? ? ? #!/usr/bin/env python3.1 > >>> ? ? ? import sys > >>> ? ? ? fp = sys.stdout.detach() > > >>> Not yet using fp in any way, this script gives the following error: > > >>> ? ? ? Exception ValueError: 'underlying buffer has been detached' in > > >>> Same in Python 3.1.4 and Python 3.2.2 > > >>> So, what do I do if I want to send binary data to stdout? > > >> sys.stdout.write( ?some_binary_data ) > > > TypeError: must be str, not bytes > > Right, you can only send binary data to file opened in binary mode. The > default sys.stdout is in text mode. I am pretty sure that remains true > even if stdout is redirected. (You did not mention your OS.) You would > have to open such a file and make sys.stdout point to it. > sys.stdout = my_binary_file. > But why do that? Just open the file and write to it directly without the > above. > > -- > Terry Jan Reedy Write binary data to sys.stdout.buffer. -Mark From skippy.hammond at gmail.com Wed Mar 7 20:35:52 2012 From: skippy.hammond at gmail.com (Mark Hammond) Date: Thu, 08 Mar 2012 12:35:52 +1100 Subject: Python 3.2 and MS Outlook In-Reply-To: References: Message-ID: <4F580CF8.2030500@gmail.com> On Thursday, 8 March 2012 1:52:48 AM, Greg Lindstrom wrote: > Is there documentation showing how to read from a Microsoft Outlook > server using Python 3.2. I've done it with 2.x, but can't find > anything to help me with 3.2. What problems are you having in 3.2? It should be exactly the same - except, obviously, for the general differences between 2 and 3 (ie, any differences should not be due to needing to talk to Outlook and would exist regardless of the job at hand) Mark From ben+python at benfinney.id.au Wed Mar 7 21:18:14 2012 From: ben+python at benfinney.id.au (Ben Finney) Date: Thu, 08 Mar 2012 13:18:14 +1100 Subject: "Decoding unicode is not supported" in unusual situation References: <4f571b94$0$12037$742ec2ed@news.sonic.net> <8762egmzfp.fsf@benfinney.id.au> <4f5749bc$0$29989$c3e8da3$5496439d@news.astraweb.com> <4f57b63f$0$11986$742ec2ed@news.sonic.net> <871up4m69h.fsf@benfinney.id.au> <4f57eeac$0$29989$c3e8da3$5496439d@news.astraweb.com> Message-ID: <87sjhjltsp.fsf@benfinney.id.au> Steven D'Aprano writes: > On Thu, 08 Mar 2012 08:48:58 +1100, Ben Finney wrote: > > I think that's a Python bug. If the latter succeeds as a no-op, the > > former should also succeed as a no-op. Neither should ever get any > > errors when ?s? is a ?unicode? object already. > > No. The semantics of the unicode function (technically: a type > constructor) are well-defined, and there are two distinct behaviours: That is documented, right. Thanks for drawing my attention to it. > > Yes, this check should not be necessary; calling the ?unicode? > > constructor with an object that's already an instance of ?unicode? > > should just return the object as-is, IMO. It shouldn't matter that > > you've specified how decoding errors are to be handled, because in > > that case no decoding happens anyway. > > I don't believe that it is the job of unicode() to Do What I Mean, but > only to Do What I Say. If I *explicitly* tell unicode() to decode the > argument (by specifying either the codec or the error handler or both) That's where I disagree. Specifying what to do in the case of decoding errors is *not* explicitly requesting to decode. The decision of whether to decode is up to the object, not the caller. Specifying an error handler *in case* decoding errors happen is not the same as specifying that decoding must happen. In other words: I think specifying an encoding is saying ?decode this?, but I don't think the same is true of specifying an error handler. > End-user applications may, with care, try to be smart and DWIM, but > library functions should be dumb and should do what they are told. Agreed, and I think this is compatible with my position. -- \ ?Creativity can be a social contribution, but only in so far as | `\ society is free to use the results.? ?Richard M. Stallman | _o__) | Ben Finney From kreena567 at gmail.com Wed Mar 7 22:27:37 2012 From: kreena567 at gmail.com (reena k) Date: Wed, 7 Mar 2012 19:27:37 -0800 (PST) Subject: PPC Form Filling Jobs Message-ID: <041298d0-a500-448c-a2e8-afe1df6df962@s10g2000pbo.googlegroups.com> http://internetjobs4u.weebly.com From benjamin at python.org Wed Mar 7 22:49:25 2012 From: benjamin at python.org (Benjamin Peterson) Date: Thu, 8 Mar 2012 03:49:25 +0000 (UTC) Subject: sys.stdout.detach() results in ValueError References: Message-ID: Peter Kleiweg xs4all.nl> writes: > Not yet using fp in any way, this script gives the following error: > > Exception ValueError: 'underlying buffer has been detached' in You're probably using print() or some such which tries to write to sys.stdout. It's safest to just write to sys.stdout.buffer rather than using detach. From rustompmody at gmail.com Wed Mar 7 23:13:36 2012 From: rustompmody at gmail.com (rusi) Date: Wed, 7 Mar 2012 20:13:36 -0800 (PST) Subject: BitSet &Redis References: <399c9d09-8e20-4db6-8f5b-bc7f3e683329@k24g2000yqe.googlegroups.com> Message-ID: <0561f35c-d95e-4ed7-a11a-896afc3808c2@gj7g2000pbc.googlegroups.com> On Mar 8, 3:02?am, Christian wrote: > I play around with redis. Isn't it ?possible to handle BitSet with > Python "as" in Java? > > BitSet users = BitSet.valueOf(redis.get(key.getBytes())); > all.or(users); > System.out.println(all.cardinality()) > > I try something with the struct and bitstring libs , but haven't any > success. Even the follow snippet didn't work, beacause > bitset[0] isn't approriate. > > bitset = r.get('bytestringFromRedis') > x = ?"{0:b}".format(ord(bitset[0])) > > Thanks in advance > Christian Redis I dont know. As for bitset, sets in python should give you whatever bitset in java does See http://docs.python.org/library/sets.html From rosuav at gmail.com Thu Mar 8 00:03:34 2012 From: rosuav at gmail.com (Chris Angelico) Date: Thu, 8 Mar 2012 16:03:34 +1100 Subject: What's the best way to write this regular expression? In-Reply-To: References: <12783654.1174.1331073814011.JavaMail.geo-discussion-forums@yner4> Message-ID: On Thu, Mar 8, 2012 at 7:39 AM, John Salerno wrote: > it only > seemed to support Python 2.7. I'm using 3.2. Is 2.7 just the minimum > version it requires? It didn't say something like "2.7+", so I wasn't > sure, and I don't want to start installing a bunch of stuff that will > clog up my directories and not even work. Just to clarify: Python 2 and Python 3 are quite different. If something requires Python 2.7, you cannot assume that it will work with Python 3.2; anything that supports both branches will usually list the minimum version of each (eg "2.7 or 3.3"). ChrisA From nad at acm.org Thu Mar 8 00:47:37 2012 From: nad at acm.org (Ned Deily) Date: Wed, 07 Mar 2012 21:47:37 -0800 Subject: Python site-packages permission denied? References: <5849344.1361.1331154163099.JavaMail.geo-discussion-forums@pbls8> Message-ID: In article , Chris Rebert wrote: > You generally shouldn't mess with Mac OS X's system copies of Python. > Typically, one installs a separate copy using MacPorts, Fink, or > whatever, and uses that instead. I don't understand what you mean by "mess with". Certainly one should not attempt alter standard library modules provided with the system Python but adding additional packages is fully supported. Apple conveniently provides a special directory in user-controlled space (/Library/Python) as the default location for Distutils-based installs. They even provide versions of easy_install for the system Pythons. -- Ned Deily, nad at acm.org From shane.neeley at gmail.com Thu Mar 8 01:07:51 2012 From: shane.neeley at gmail.com (Shane Neeley) Date: Wed, 7 Mar 2012 22:07:51 -0800 (PST) Subject: Help with MultipartPostHandler Message-ID: <1270164.221.1331186871710.JavaMail.geo-discussion-forums@pbjv6> Hi Python Google Group! I hope someone could help me and then one day when I am good I can contribute to the forum as well. Does anyone know what is wrong with my syntax here as I am trying to submit this form using MultipartPostHandler that I installed? import MultipartPostHandler, urllib2 params = { 'Run_Number' : 'NONE', 'MAX_FILE_SIZE' : '2000000', 'submitForm' : 'Submit' } opener.open("http://consurf.tau.ac.il/index_full_form_PROT.php", params) From timr at probo.com Thu Mar 8 01:11:45 2012 From: timr at probo.com (Tim Roberts) Date: Wed, 07 Mar 2012 22:11:45 -0800 Subject: Biologist new to cgi in python References: <28641624.970.1331139509579.JavaMail.geo-discussion-forums@pbcgw3> Message-ID: Shane Neeley wrote: > >Here is the function I am using to insert the variable file text inside the >url. Is it even possible to include the upload command in the url? No. You are trying to simulate a "GET" request, but files can only be uploaded via a "POST" request of type multiport/form-data. There is a module called "poster" that can do the appropriate encoding for you: http://stackoverflow.com/questions/680305/using-multipartposthandler-to-post-form-data-with-python -- Tim Roberts, timr at probo.com Providenza & Boekelheide, Inc. From bugzilla-mail-box at yandex.ru Thu Mar 8 01:14:21 2012 From: bugzilla-mail-box at yandex.ru (bugzilla-mail-box at yandex.ru) Date: Thu, 08 Mar 2012 16:14:21 +1000 Subject: Get tkinter text to the clipboard Message-ID: <38861331187261@web143.yandex.ru> > How about > > import tkinter > root = tkinter.Tk() > > root.clipboard_clear() > root.clipboard_append("whatever") > that works, thank you From moky.math at gmail.com Thu Mar 8 01:45:32 2012 From: moky.math at gmail.com (Laurent Claessens) Date: Thu, 08 Mar 2012 07:45:32 +0100 Subject: what is best method to set sys.stdout to utf-8? In-Reply-To: References: Message-ID: <4F58558C.3000706@gmail.com> > I would. The io module is more recent an partly replaces codecs. The > latter remains for back compatibility and whatever it can do that io cannot. I've a naive question : what is wrong with the following system ? class MyStdOut(object): def __init__(self): self.old_stdout=sys.stdout def write(self,x): try: if isinstance(x,unicode): x=x.encode("utf8") except (UnicodeEncodeError,UnicodeDecodeError): sys.stderr.write("This should not happen !") raise self.old_stdout.write(x) sys.stdout=MyStdOut() ... well ... a part of the fact that it is much longer ? Laurent Claessens From moky.math at gmail.com Thu Mar 8 01:45:32 2012 From: moky.math at gmail.com (Laurent Claessens) Date: Thu, 08 Mar 2012 07:45:32 +0100 Subject: what is best method to set sys.stdout to utf-8? In-Reply-To: References: Message-ID: <4F58558C.3000706@gmail.com> > I would. The io module is more recent an partly replaces codecs. The > latter remains for back compatibility and whatever it can do that io cannot. I've a naive question : what is wrong with the following system ? class MyStdOut(object): def __init__(self): self.old_stdout=sys.stdout def write(self,x): try: if isinstance(x,unicode): x=x.encode("utf8") except (UnicodeEncodeError,UnicodeDecodeError): sys.stderr.write("This should not happen !") raise self.old_stdout.write(x) sys.stdout=MyStdOut() ... well ... a part of the fact that it is much longer ? Laurent Claessens From johnjsal at gmail.com Thu Mar 8 02:25:18 2012 From: johnjsal at gmail.com (John Salerno) Date: Wed, 7 Mar 2012 23:25:18 -0800 (PST) Subject: What's the best way to write this regular expression? References: <12783654.1174.1331073814011.JavaMail.geo-discussion-forums@yner4> Message-ID: <6497ecaf-c165-40be-9d6c-3c8fa6963861@p13g2000yqd.googlegroups.com> On Mar 7, 11:03?pm, Chris Angelico wrote: > On Thu, Mar 8, 2012 at 7:39 AM, John Salerno wrote: > > it only > > seemed to support Python 2.7. I'm using 3.2. Is 2.7 just the minimum > > version it requires? It didn't say something like "2.7+", so I wasn't > > sure, and I don't want to start installing a bunch of stuff that will > > clog up my directories and not even work. > > Just to clarify: Python 2 and Python 3 are quite different. If > something requires Python 2.7, you cannot assume that it will work > with Python 3.2; anything that supports both branches will usually > list the minimum version of each (eg "2.7 or 3.3"). > > ChrisA That's why I asked first, because I got the feeling it did NOT support Python 3 :) From johnjsal at gmail.com Thu Mar 8 02:26:28 2012 From: johnjsal at gmail.com (John Salerno) Date: Wed, 7 Mar 2012 23:26:28 -0800 (PST) Subject: What's the best way to write this regular expression? References: <12783654.1174.1331073814011.JavaMail.geo-discussion-forums@yner4> <5B80DD153D7D744689F57F4FB69AF47419567C@SCACMX008.exchad.jpmchase.net> Message-ID: <7d80b224-8f51-48c7-8224-6323e282a13e@x17g2000yqj.googlegroups.com> On Mar 7, 4:02?pm, Evan Driscoll wrote: > On 01/-10/-28163 01:59 PM, Prasad, Ramit wrote: > > > gz stands for gzip and is a form of compression (like rar/zip ). > > tar stands for a tape archive. It is basically a box that holds the > > files. So you need to "unzip" and then "open the box". > > > Normally programs like WinZip / WinRar / 7-zip will do both in one step > > so you do not need to. Not sure what program you are using... > > I'm not sure what 7-zip you're referring to, because I use 7-zip and > it's always been a two-step process for me... > > (Though I can't say I've looked through the preferences dialog for a > "extract .tar.gz files in one go" setting.) > > Evan Same here, because that's what I used. I looked through the settings but didn't see anything. What seems to happen is that 7-Zip recognizes the .gz extension and opens that automatically. But then that simply opens up another window with the .tar file in it, which you have to then open again. From riko at despammed.com Thu Mar 8 04:12:16 2012 From: riko at despammed.com (Enrico Franchi) Date: Thu, 8 Mar 2012 10:12:16 +0100 Subject: Python recursive tree, linked list thingy References: Message-ID: <1kgmufu.fmcyhya6u0awN%riko@despammed.com> Wanderer wrote: > How > do you handle this sort of thing in Python? I believe that the best thing to do is a Union-Find algorithm. Depending on the exact nature of your problem, you may also want to check out the Hoshen-Kopelman Algorithm. Although the algorithm itself is rather efficient, it was born in the context of percolation, that is to say with the assumption that the "broken" (or colored) cells are much more likely than in your context. -- -riko http://www.enrico-franchi.org/ http://rik0-techtemple.blogspot.com/ From robert.kern at gmail.com Thu Mar 8 05:40:08 2012 From: robert.kern at gmail.com (Robert Kern) Date: Thu, 08 Mar 2012 10:40:08 +0000 Subject: Python recursive tree, linked list thingy In-Reply-To: <1kgmufu.fmcyhya6u0awN%riko@despammed.com> References: <1kgmufu.fmcyhya6u0awN%riko@despammed.com> Message-ID: On 3/8/12 9:12 AM, Enrico Franchi wrote: > Wanderer wrote: > >> How >> do you handle this sort of thing in Python? > > I believe that the best thing to do is a Union-Find algorithm. Another term this problem is finding the "connected components". Here is some code from Stefan van der Walt for this: http://mentat.za.net/source/connected_components.tar.bz2 http://mentat.za.net/cgi-bin/hgwebdir.cgi/ccomp -- Robert Kern "I have come to believe that the whole world is an enigma, a harmless enigma that is made terrible by our own mad attempt to interpret it as though it had an underlying truth." -- Umberto Eco From steve+comp.lang.python at pearwood.info Thu Mar 8 06:34:39 2012 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 08 Mar 2012 11:34:39 GMT Subject: Python site-packages permission denied? References: <5849344.1361.1331154163099.JavaMail.geo-discussion-forums@pbls8> Message-ID: <4f58994f$0$29989$c3e8da3$5496439d@news.astraweb.com> On Wed, 07 Mar 2012 21:47:37 -0800, Ned Deily wrote: > In article > , > Chris Rebert wrote: >> You generally shouldn't mess with Mac OS X's system copies of Python. >> Typically, one installs a separate copy using MacPorts, Fink, or >> whatever, and uses that instead. > > I don't understand what you mean by "mess with". Certainly one should > not attempt alter standard library modules provided with the system > Python but adding additional packages is fully supported. I read Chris as making a general comment that one should be cautious about making changes to the system copy of Python, advice that holds for all OSes not just OS-X. > Apple > conveniently provides a special directory in user-controlled space > (/Library/Python) as the default location for Distutils-based installs. > They even provide versions of easy_install for the system Pythons. Perhaps so, but it seems to have the permissions messed up, or some other problem, because the OP can't write to it. His error is: copying build/lib/urllib2_file.py -> /Library/Python/2.7/site-packages error: /Library/Python/2.7/site-packages/urllib2_file.py: Permission denied I note also that Chris' final comment was: "In any case, you generally need to `sudo` when installing stuff system- wide." which is probably the solution the OP is looking for. -- Steven From ran.hrl at gmail.com Thu Mar 8 06:42:44 2012 From: ran.hrl at gmail.com (Ran Harel) Date: Thu, 8 Mar 2012 13:42:44 +0200 Subject: Memory leak involving traceback objects Message-ID: I have the same problem with python 2.6.2. I have upgraded to 2.7.1 and the leak is gone. -------------- next part -------------- An HTML attachment was scrubbed... URL: From ndbecker2 at gmail.com Thu Mar 8 09:23:26 2012 From: ndbecker2 at gmail.com (Neal Becker) Date: Thu, 08 Mar 2012 09:23:26 -0500 Subject: cython + scons + c++ Message-ID: Is there a version of cython.py, pyext.py that will work with c++? I asked this question some time ago, but never got an answer. I tried the following code, but it doesn't work correctly. If the commented lines are uncommented, the gcc command is totally mangled. Although it did build my 1 test extension OK, I didn't use any libstdc++ - I suspect it won't link correctly in general because it doesn't seem to treat the code as c++ (treats it as c code). cyenv = Environment(PYEXT_USE_DISTUTILS=True) cyenv.Tool("pyext") cyenv.Tool("cython") import numpy cyenv.Append(PYEXTINCPATH=[numpy.get_include()]) cyenv.Replace(CYTHONFLAGS=['--cplus']) #cyenv.Replace(CXXFILESUFFIX='.cpp') #cyenv.Replace(CYTHONCFILESUFFIX='.cpp') From stefan_ml at behnel.de Thu Mar 8 09:59:38 2012 From: stefan_ml at behnel.de (Stefan Behnel) Date: Thu, 08 Mar 2012 15:59:38 +0100 Subject: cython + scons + c++ In-Reply-To: References: Message-ID: Neal Becker, 08.03.2012 15:23: > Is there a version of cython.py, pyext.py that will work with c++? > > I asked this question some time ago, but never got an answer. > > I tried the following code, but it doesn't work correctly. If the commented > lines are uncommented, the gcc command is totally mangled. > > Although it did build my 1 test extension OK, I didn't use any libstdc++ - I > suspect it won't link correctly in general because it doesn't seem to treat the > code as c++ (treats it as c code). > > cyenv = Environment(PYEXT_USE_DISTUTILS=True) > cyenv.Tool("pyext") > cyenv.Tool("cython") > import numpy > > cyenv.Append(PYEXTINCPATH=[numpy.get_include()]) > cyenv.Replace(CYTHONFLAGS=['--cplus']) > #cyenv.Replace(CXXFILESUFFIX='.cpp') > #cyenv.Replace(CYTHONCFILESUFFIX='.cpp') I don't use Scons, so I don't know if running the compiler at a command line level is the best way to do it in that build system. But I know that some people on the Cython users mailing list use it, so you may want to ask over there. https://groups.google.com/group/cython-users Stefan From hyperboogie at gmail.com Thu Mar 8 10:25:06 2012 From: hyperboogie at gmail.com (hyperboogie) Date: Thu, 8 Mar 2012 07:25:06 -0800 (PST) Subject: newb __init__ inheritance Message-ID: <1c6db866-6fa3-4de5-96de-51d6720a1300@x17g2000yqj.googlegroups.com> Hello everyone. This is my first post in this group. I started learning python a week ago from the "dive into python" e- book and thus far all was clear. However today while reading chapter 5 about objects and object orientation I ran into something that confused me. it says here: http://www.diveintopython.net/object_oriented_framework/defining_classes.html#fileinfo.class.example "__init__ methods are optional, but when you define one, you must remember to explicitly call the ancestor's __init__ method (if it defines one). This is more generally true: whenever a descendant wants to extend the behavior of the ancestor, the descendant method must explicitly call the ancestor method at the proper time, with the proper arguments. " However later on in the chapter: http://www.diveintopython.net/object_oriented_framework/userdict.html it says: "Methods are defined solely by their name, and there can be only one method per class with a given name. So if a descendant class has an __init__ method, it always overrides the ancestor __init__ method, even if the descendant defines it with a different argument list. And the same rule applies to any other method. " My question is if __init__ in the descendant class overrides __init__ in the parent class how can I call the parent's __init__ from the descendant class - I just overrode it didn't I? Am I missing something more fundamental here? Thanks From awilliam at whitemice.org Thu Mar 8 10:44:15 2012 From: awilliam at whitemice.org (Adam Tauno Williams) Date: Thu, 08 Mar 2012 10:44:15 -0500 Subject: Can't get around HTTP/401 response using SUDS Message-ID: <1331221455.3087.14.camel@linux-dauq.site> SUDS version 0.4 pn x86_64 Python 2.7 I'm having a bear of a time getting HTTP Basic Authentication to work for a SOAP request via suds. Also using an HTTP proxy server. In WireShark I just see a request - GET http://...../services/services/JobService-0.0.1?wsdl HTTP/1.1 Accept-Encoding: identity Host: ....... Connection: close User-Agent: Python-urllib/2.7 This doesn't contain any authentication credentials so the response is HTTP/401, and the client doesn't retry with credentials. The response does come from the remote as I can see there is a WWW-Authenticate header and it is from an Apache Tomcat server - so it makes it through the proxy server. Code ================ url = 'http://....../services/services/JobService-0.0.1?wsdl' proxy = urllib2.ProxyHandler({'http': 'http://.....:3128'}) transport = suds.transport.http.HttpAuthenticated() transport.urlopener = urllib2.build_opener(proxy) client = suds.client.Client(url, transport=transport, username='******', password='********') .... I've tried the above as well as the method described at It has the same problem. Back Trace ================ Traceback (most recent call last): File "etrace.py", line 30, in client = suds.client.Client(url, transport=transport, username='*******', password='*****') File "/usr/local/lib/python2.7/site-packages/suds-0.4-py2.7.egg/suds/client.py", line 112, in __init__ self.wsdl = reader.open(url) File "/usr/local/lib/python2.7/site-packages/suds-0.4-py2.7.egg/suds/reader.py", line 152, in open d = self.fn(url, self.options) File "/usr/local/lib/python2.7/site-packages/suds-0.4-py2.7.egg/suds/wsdl.py", line 136, in __init__ d = reader.open(url) File "/usr/local/lib/python2.7/site-packages/suds-0.4-py2.7.egg/suds/reader.py", line 79, in open d = self.download(url) File "/usr/local/lib/python2.7/site-packages/suds-0.4-py2.7.egg/suds/reader.py", line 95, in download fp = self.options.transport.open(Request(url)) File "/usr/local/lib/python2.7/site-packages/suds-0.4-py2.7.egg/suds/transport/http.py", line 173, in open return HttpTransport.open(self, request) File "/usr/local/lib/python2.7/site-packages/suds-0.4-py2.7.egg/suds/transport/http.py", line 64, in open raise TransportError(str(e), e.code, e.fp) suds.transport.TransportError: HTTP Error 401: Unauthorized -- System & Network Administrator [ LPI & NCLA ] OpenGroupware Developer Adam Tauno Williams From d at davea.name Thu Mar 8 10:44:58 2012 From: d at davea.name (Dave Angel) Date: Thu, 08 Mar 2012 10:44:58 -0500 Subject: cython + scons + c++ In-Reply-To: References: Message-ID: <4F58D3FA.3030401@davea.name> On 03/08/2012 09:23 AM, Neal Becker wrote: > Is there a version of cython.py, pyext.py that will work with c++? > > I asked this question some time ago, but never got an answer. > > I tried the following code, but it doesn't work correctly. If the commented > lines are uncommented, the gcc command is totally mangled. > > Although it did build my 1 test extension OK, I didn't use any libstdc++ - I > suspect it won't link correctly in general because it doesn't seem to treat the > code as c++ (treats it as c code). > > cyenv = Environment(PYEXT_USE_DISTUTILS=True) > cyenv.Tool("pyext") > cyenv.Tool("cython") > import numpy > > cyenv.Append(PYEXTINCPATH=[numpy.get_include()]) > cyenv.Replace(CYTHONFLAGS=['--cplus']) > #cyenv.Replace(CXXFILESUFFIX='.cpp') > #cyenv.Replace(CYTHONCFILESUFFIX='.cpp') > > I don't know anything about writing c/c++ code with Python. I have plenty of experience with each, but not together. But the usual C++ answer is to use an extern "C" declaration for any function you need to be visible to the outside world. It prevents the usual C++ name mangling. (It therefore also prevents function overloading and can't generally be used on class member functions) -- DaveA From wanderer at dialup4less.com Thu Mar 8 11:12:56 2012 From: wanderer at dialup4less.com (Wanderer) Date: Thu, 8 Mar 2012 08:12:56 -0800 (PST) Subject: Python recursive tree, linked list thingy References: Message-ID: <72acc0ba-49f3-49a2-abad-3bacaa015586@n9g2000pbb.googlegroups.com> On Mar 7, 3:27?pm, Ian Kelly wrote: > On Wed, Mar 7, 2012 at 1:03 PM, Ian Kelly wrote: > > A set of defective pixels would be the probable choice, since it > > offers efficient membership testing. > > Some actual code, using a recursive generator: > > def get_cluster(defective, pixel): > ? ? yield pixel > ? ? (row, column) = pixel > ? ? for adjacent in [(row - 1, column), (row, column - 1), > ? ? ? ? ? ? ? ? ? ? ?(row, column + 1), (row + 1, column)]: > ? ? ? ? if adjacent in defective: > ? ? ? ? ? ? defective.remove(adjacent) > ? ? ? ? ? ? for cluster_pixel in get_cluster(defective, adjacent): > ? ? ? ? ? ? ? ? yield cluster_pixel > > defective = {(327, 415), (180, 97), (326, 415), (42, 15), > ? ? ? ? ? ? ?(180, 98), (325, 414), (325, 415)} > clusters = [] > > while defective: > ? ? pixel = defective.pop() > ? ? clusters.append(list(get_cluster(defective, pixel))) > > from pprint import pprint > pprint(clusters) > > Cheers, > Ian This works for me and I can modify it to look for column defects also. It also shows I know less about Python then I thought I did. I had to read up on generators and iterators to understand the code. Thanks From maarten.sneep at knmi.nl Thu Mar 8 11:30:17 2012 From: maarten.sneep at knmi.nl (Maarten) Date: Thu, 8 Mar 2012 08:30:17 -0800 (PST) Subject: newb __init__ inheritance In-Reply-To: <1c6db866-6fa3-4de5-96de-51d6720a1300@x17g2000yqj.googlegroups.com> References: <1c6db866-6fa3-4de5-96de-51d6720a1300@x17g2000yqj.googlegroups.com> Message-ID: <13988849.1044.1331224217273.JavaMail.geo-discussion-forums@ynnk21> On Thursday, March 8, 2012 4:25:06 PM UTC+1, hyperboogie wrote: > My question is if __init__ in the descendant class overrides __init__ > in the parent class how can I call the parent's __init__ from the > descendant class - I just overrode it didn't I? > > Am I missing something more fundamental here? No, you're not. However, you can explicitly call the __init__() method of a particular class. Hard-coding the class gives you: class A(object): def __init__(self): print("In A") class B(A): def __init__(self): A.__init__(self) print("In B") Alternatively you can figure out the parent class with a call to super: class C(A): def __init__(self): super(self.__class__, self).__init__() print("In C") a = A() (prints "In A") b = B() (prints "In A", "In B" on two lines) c = C() (prints "In A", "In C" on two lines) Hope this helps. Maarten From __peter__ at web.de Thu Mar 8 12:03:25 2012 From: __peter__ at web.de (Peter Otten) Date: Thu, 08 Mar 2012 18:03:25 +0100 Subject: newb __init__ inheritance References: <1c6db866-6fa3-4de5-96de-51d6720a1300@x17g2000yqj.googlegroups.com> <13988849.1044.1331224217273.JavaMail.geo-discussion-forums@ynnk21> Message-ID: Maarten wrote: > Alternatively you can figure out the parent class with a call to super: This is WRONG: > super(self.__class__, self).__init__() You have to name the current class explicitly. Consider: >> class A(object): ... def __init__(self): ... print "in a" ... >>> class B(A): ... def __init__(self): ... print "in b" ... super(self.__class__, self).__init__() # wrong ... >>> class C(B): pass ... >>> Can you figure out what C() will print? Try it out if you can't. The corrected code: >>> class B(A): ... def __init__(self): ... print "in b" ... super(B, self).__init__() ... >>> class C(B): pass ... >>> C() in b in a <__main__.C object at 0x7fcfafd52b10> In Python 3 you can call super() with no args; super().__init__() do the right thing there. From ethan at stoneleaf.us Thu Mar 8 12:34:20 2012 From: ethan at stoneleaf.us (Ethan Furman) Date: Thu, 08 Mar 2012 09:34:20 -0800 Subject: newb __init__ inheritance In-Reply-To: <1c6db866-6fa3-4de5-96de-51d6720a1300@x17g2000yqj.googlegroups.com> References: <1c6db866-6fa3-4de5-96de-51d6720a1300@x17g2000yqj.googlegroups.com> Message-ID: <4F58ED9C.2010603@stoneleaf.us> hyperboogie wrote: > Hello everyone. > > This is my first post in this group. > I started learning python a week ago from the "dive into python" e- > book and thus far all was clear. > However today while reading chapter 5 about objects and object > orientation I ran into something that confused me. > it says here: > http://www.diveintopython.net/object_oriented_framework/defining_classes.html#fileinfo.class.example > > "__init__ methods are optional, but when you define one, you must > remember to explicitly call the ancestor's __init__ method (if it > defines one). This is more generally true: whenever a descendant wants > to extend the behavior of the ancestor, the descendant method must > explicitly call the ancestor method at the proper time, with the > proper arguments. " > > However later on in the chapter: > http://www.diveintopython.net/object_oriented_framework/userdict.html > > it says: > "Methods are defined solely by their name, and there can be only one > method per class with a given name. So if a descendant class has an > __init__ method, it always overrides the ancestor __init__ method, > even if the descendant defines it with a different argument list. And > the same rule applies to any other method. " > > My question is if __init__ in the descendant class overrides __init__ > in the parent class how can I call the parent's __init__ from the > descendant class - I just overrode it didn't I? > > Am I missing something more fundamental here? > Thanks An excellent question. What you subclass you are creating a new, different class. class A(object): def __init__(self): print("this is class A's __init__") def method1(self, value): print(value) class B(A): def __init__(self): print("this is class B's __init__") test = B() test.method1('42') When it says that the subclass overrides methods of the same name, it means that if it finds the method in the subclass, it will stop looking and use the one it found. So in the example above when Python creates test it will find __init__ in B and so won't bother looking in A for it. However, when looking for 'method1' Python does not find it in B, and so looks in A for it and, finding it there, uses that as B's method1. If you want B's __init__ to also call A's __init__, you have to so explicity: def __init__(self): A.__init__(self) or def __init__(self): super(B, self).__init__() or with Python 3 def __init__(self): super().__init__() ~Ethan~ From awilliam at whitemice.org Thu Mar 8 13:21:42 2012 From: awilliam at whitemice.org (Adam Tauno Williams) Date: Thu, 08 Mar 2012 13:21:42 -0500 Subject: GUI components in python In-Reply-To: References: Message-ID: <1331230902.3087.22.camel@linux-dauq.site> On Wed, 2012-03-07 at 19:14 +0530, janaki rajamani wrote: > I am stuck with the brain workshop software implemented using python. > The code involves a lot of GUI elements and i am familar only with the > basic python programming. > I would like to know whether there are built in classes to support GUI > elements or arethey project dependant. There are wrappers for various GUI toolkits/technologies such as PyGTK for using Gtk in Python. These wrappers often provide quite a bit of assistance and tools for working with that technology. You need to ask more specifically to get a more useful answer? -- System & Network Administrator [ LPI & NCLA ] OpenGroupware Developer Adam Tauno Williams -------------- next part -------------- A non-text attachment was scrubbed... Name: signature.asc Type: application/pgp-signature Size: 198 bytes Desc: This is a digitally signed message part URL: From ramit.prasad at jpmorgan.com Thu Mar 8 14:00:42 2012 From: ramit.prasad at jpmorgan.com (Prasad, Ramit) Date: Thu, 8 Mar 2012 19:00:42 +0000 Subject: GUI components in python In-Reply-To: <1331230902.3087.22.camel@linux-dauq.site> References: <1331230902.3087.22.camel@linux-dauq.site> Message-ID: <5B80DD153D7D744689F57F4FB69AF474196E66@SCACMX008.exchad.jpmchase.net> > > I am stuck with the brain workshop software implemented using python. > > The code involves a lot of GUI elements and i am familar only with the > > basic python programming. > > I would like to know whether there are built in classes to support GUI > > elements or arethey project dependant. > > There are wrappers for various GUI toolkits/technologies such as PyGTK > for using Gtk in Python. These wrappers often provide quite a bit of > assistance and tools for working with that technology. > > You need to ask more specifically to get a more useful answer? The TKinter library ships with Python. So I guess that would be the "built-in" classes. Usually though the UI is project dependent and there are several frameworks depending on the features you want. This may help list some of the frameworks and help you choose: http://www.awaretek.com/toolkits.html Ramit Ramit Prasad | JPMorgan Chase Investment Bank | Currencies Technology 712 Main Street | Houston, TX 77002 work phone: 713 - 216 - 5423 -- This email is confidential and subject to important disclaimers and conditions including on offers for the purchase or sale of securities, accuracy and completeness of information, viruses, confidentiality, legal privilege, and legal entity disclaimers, available at http://www.jpmorgan.com/pages/disclosures/email. From franck at ditter.org Thu Mar 8 14:15:09 2012 From: franck at ditter.org (Franck Ditter) Date: Thu, 08 Mar 2012 20:15:09 +0100 Subject: Buffering in Wing and IDLE 3 References: Message-ID: In article , Ned Deily wrote: > http://www.activestate.com/activetcl/downloads GREAT ! It seems to work. At least, I can now get the ~ char in France from within IDLE. A big step for manking :-) Thanks folks, franck From johnjsal at gmail.com Thu Mar 8 16:33:17 2012 From: johnjsal at gmail.com (John Salerno) Date: Thu, 8 Mar 2012 13:33:17 -0800 (PST) Subject: What's the best way to write this regular expression? References: <12783654.1174.1331073814011.JavaMail.geo-discussion-forums@yner4> Message-ID: <03dd4256-0881-44e8-bb27-38f23ce66267@h20g2000yqd.googlegroups.com> Alright, I'm simply lost about how to install these modules. I extracted the folders from the .tar.gz files and then went into those folders in my command prompt. I typed: C:\Python32\python setup.py install and for a while something was happening (I was doing the lxml one) and then it stopped with an error that it couldn't find a file. So I have no idea. Next I installed the "distribute" module, which seemed to install okay. But now I don't understand how to use easy_install. Where do I call it from? What do I do with the .tar.gz files at this point? The instructions for lxml say to run this command: easy_install --allow-hosts=lxml.de,*.python.org lxml but WHERE do I run it? I tried it in the Python directory, and then further in the lxml site-packages directory, but it doesn't work. What do I do with it? Where do I put the .tar files? From johnjsal at gmail.com Thu Mar 8 16:40:18 2012 From: johnjsal at gmail.com (John Salerno) Date: Thu, 8 Mar 2012 13:40:18 -0800 (PST) Subject: What's the best way to write this regular expression? References: <12783654.1174.1331073814011.JavaMail.geo-discussion-forums@yner4> <03dd4256-0881-44e8-bb27-38f23ce66267@h20g2000yqd.googlegroups.com> Message-ID: <21519dbf-4097-4780-874d-41d76f6453e0@x17g2000yqj.googlegroups.com> On Mar 8, 3:33?pm, John Salerno wrote: > Alright, I'm simply lost about how to install these modules. I > extracted the folders from the .tar.gz files and then went into those > folders in my command prompt. I typed: > > C:\Python32\python setup.py install > > and for a while something was happening (I was doing the lxml one) and > then it stopped with an error that it couldn't find a file. So I have > no idea. > > Next I installed the "distribute" module, which seemed to install > okay. But now I don't understand how to use easy_install. Where do I > call it from? What do I do with the .tar.gz files at this point? The > instructions for lxml say to run this command: > > easy_install --allow-hosts=lxml.de,*.python.org lxml > > but WHERE do I run it? I tried it in the Python directory, and then > further in the lxml site-packages directory, but it doesn't work. What > do I do with it? Where do I put the .tar files? Well, after a bit of experimentation, I got it to run, but I seem to have run into the same error as when I used setup.py: http://i271.photobucket.com/albums/jj138/JohnJSal/lxml_error.png Now I have no idea what to do. From johnjsal at gmail.com Thu Mar 8 16:52:39 2012 From: johnjsal at gmail.com (John Salerno) Date: Thu, 8 Mar 2012 13:52:39 -0800 (PST) Subject: What's the best way to write this regular expression? References: <12783654.1174.1331073814011.JavaMail.geo-discussion-forums@yner4> <03dd4256-0881-44e8-bb27-38f23ce66267@h20g2000yqd.googlegroups.com> <21519dbf-4097-4780-874d-41d76f6453e0@x17g2000yqj.googlegroups.com> Message-ID: <75bf9c09-5d24-457f-94c0-96221f0553b2@h20g2000yqd.googlegroups.com> On Mar 8, 3:40?pm, John Salerno wrote: > Now I have no idea what to do. Hmph, I suppose I should have more patience. I realized that the easy_install for lxml only tried to install a binary version, which doesn't exist for the version it found (the latest, 2.3.3). I just had to look through the previous versions and find the one with a binary installation for Windows (2.3) and it was as simple as a single click to install! And the easy_install method did work for Beautiful Soup, so I should be all set now! From gordon at panix.com Thu Mar 8 16:54:46 2012 From: gordon at panix.com (John Gordon) Date: Thu, 8 Mar 2012 21:54:46 +0000 (UTC) Subject: What's the best way to write this regular expression? References: <12783654.1174.1331073814011.JavaMail.geo-discussion-forums@yner4> <03dd4256-0881-44e8-bb27-38f23ce66267@h20g2000yqd.googlegroups.com> <21519dbf-4097-4780-874d-41d76f6453e0@x17g2000yqj.googlegroups.com> Message-ID: In <21519dbf-4097-4780-874d-41d76f6453e0 at x17g2000yqj.googlegroups.com> John Salerno writes: > Well, after a bit of experimentation, I got it to run, but I seem to > have run into the same error as when I used setup.py: > http://i271.photobucket.com/albums/jj138/JohnJSal/lxml_error.png > Now I have no idea what to do. The first error on that screen is that "xslt-config" is not found as a command. Try a web search for "xslt-config not found", there seemed to be some helpful results. -- 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 toby at tobiah.org Thu Mar 8 16:55:06 2012 From: toby at tobiah.org (Tobiah) Date: Thu, 08 Mar 2012 13:55:06 -0800 Subject: Finding MIME type for a data stream Message-ID: <%U96r.32867$082.25394@newsfe04.iad> I'm pulling image data from a database blob, and serving it from a web2py app. I have to send the correct Content-Type header, so I need to detect the image type. Everything that I've found on the web so far, needs a file name on the disk, but I only have the data. It looks like the 'magic' package might be of use, but I can't find any documentation for it. Also, it seems like image/png works for other types of image data, while image/foo does not, yet I'm afraid that not every browser will play along as nicely. Thanks! Tobiah From d at davea.name Thu Mar 8 17:11:26 2012 From: d at davea.name (Dave Angel) Date: Thu, 08 Mar 2012 17:11:26 -0500 Subject: Finding MIME type for a data stream In-Reply-To: <%U96r.32867$082.25394@newsfe04.iad> References: <%U96r.32867$082.25394@newsfe04.iad> Message-ID: <4F592E8E.7080708@davea.name> On 03/08/2012 04:55 PM, Tobiah wrote: > I'm pulling image data from a database blob, and serving > it from a web2py app. I have to send the correct > Content-Type header, so I need to detect the image type. > > Everything that I've found on the web so far, needs a file > name on the disk, but I only have the data. > > It looks like the 'magic' package might be of use, but > I can't find any documentation for it. > > Also, it seems like image/png works for other types > of image data, while image/foo does not, yet I'm afraid > that not every browser will play along as nicely. > > Thanks! > > Tobiah First step, ask the authors of the database what format of data this blob is in. Failing that, write the same data locally as a binary file, and see what application can open it. Or if you're on a Linux system, run file on it. "file" can identify most data formats (not just images) just by looking at the data. That assumes, of course, that there's any consistency in the data coming out of the database. What happens if next time this blob is an Excel spreadsheet? -- DaveA From d at davea.name Thu Mar 8 17:19:57 2012 From: d at davea.name (Dave Angel) Date: Thu, 08 Mar 2012 17:19:57 -0500 Subject: What's the best way to write this regular expression? In-Reply-To: <21519dbf-4097-4780-874d-41d76f6453e0@x17g2000yqj.googlegroups.com> References: <12783654.1174.1331073814011.JavaMail.geo-discussion-forums@yner4> <03dd4256-0881-44e8-bb27-38f23ce66267@h20g2000yqd.googlegroups.com> <21519dbf-4097-4780-874d-41d76f6453e0@x17g2000yqj.googlegroups.com> Message-ID: <4F59308D.4000403@davea.name> On 03/08/2012 04:40 PM, John Salerno wrote: > > http://i271.photobucket.com/albums/jj138/JohnJSal/lxml_error.png > Nothing to do with Python, but you'd save us all a lot of space and bandwidth if you learned how to copy/paste from a Windows cmd window. If you're just doing it rarely, you can right click on the top bar to get a menu. I think you want "mark". Then you select the text you'd like to put in the clipboard. Alternatively, you can put the console in quick-edit mode (I think it's called, it's been a long time since I ran Windows). That's an option you set on one cmd window, and it sticks for future windows. In quick-edit, you just right-click-drag on the cmd window to select a rectangle of text. Then you can Ctrl-V to paste it into email, or into a text editor, or wherever else you need it. Hard to imagine not using this mode, or its Linux equivalent, which is always available. If that wasn't clear enough, or it doesn't work for you, somebody will explain it better. Or ask me, and I'll launch a VirtualBox with Windows to get you going. -- DaveA From nagle at animats.com Thu Mar 8 17:23:50 2012 From: nagle at animats.com (John Nagle) Date: Thu, 08 Mar 2012 14:23:50 -0800 Subject: "Decoding unicode is not supported" in unusual situation In-Reply-To: <87sjhjltsp.fsf@benfinney.id.au> References: <4f571b94$0$12037$742ec2ed@news.sonic.net> <8762egmzfp.fsf@benfinney.id.au> <4f5749bc$0$29989$c3e8da3$5496439d@news.astraweb.com> <4f57b63f$0$11986$742ec2ed@news.sonic.net> <871up4m69h.fsf@benfinney.id.au> <4f57eeac$0$29989$c3e8da3$5496439d@news.astraweb.com> <87sjhjltsp.fsf@benfinney.id.au> Message-ID: <4f593178$0$11963$742ec2ed@news.sonic.net> On 3/7/2012 6:18 PM, Ben Finney wrote: > Steven D'Aprano writes: > >> On Thu, 08 Mar 2012 08:48:58 +1100, Ben Finney wrote: >>> I think that's a Python bug. If the latter succeeds as a no-op, the >>> former should also succeed as a no-op. Neither should ever get any >>> errors when ?s? is a ?unicode? object already. >> >> No. The semantics of the unicode function (technically: a type >> constructor) are well-defined, and there are two distinct behaviours: Right. The real problem is that Python 2.7 doesn't have distinct "str" and "bytes" types. type(bytes() returns "str" is assumed to be ASCII 0..127, but that's not enforced. "bytes" and "str" should have been distinct types, but that would have broken much old code. If they were distinct, then constructors could distinguish between string type conversion (which requires no encoding information) and byte stream decoding. So it's possible to get junk characters in a "str", and they won't convert to Unicode. I've had this happen with databases which were supposed to be ASCII, but occasionally a non-ASCII character would slip through. This is all different in Python 3.x, where "str" is Unicode and "bytes" really are a distinct type. John Nagle From johnjsal at gmail.com Thu Mar 8 17:25:21 2012 From: johnjsal at gmail.com (John Salerno) Date: Thu, 8 Mar 2012 16:25:21 -0600 Subject: What's the best way to write this regular expression? In-Reply-To: <4F59308D.4000403@davea.name> References: <12783654.1174.1331073814011.JavaMail.geo-discussion-forums@yner4> <03dd4256-0881-44e8-bb27-38f23ce66267@h20g2000yqd.googlegroups.com> <21519dbf-4097-4780-874d-41d76f6453e0@x17g2000yqj.googlegroups.com> <4F59308D.4000403@davea.name> Message-ID: Thanks, I had no idea about either option, since I don't use the command prompt very much. Needless to say, the Linux console is much nicer :) On Thu, Mar 8, 2012 at 4:19 PM, Dave Angel wrote: > On 03/08/2012 04:40 PM, John Salerno wrote: >> >> >> http://i271.photobucket.com/albums/jj138/JohnJSal/lxml_error.png >> > > Nothing to do with Python, but you'd save us all a lot of space and > bandwidth if you learned how to copy/paste from a Windows cmd window. > > If you're just doing it rarely, you can right click on the top bar to get a > menu. ?I think you want "mark". ?Then you select the text you'd like to put > in the clipboard. > > Alternatively, you can put the console in quick-edit mode (I think it's > called, it's been a long time since I ran Windows). ?That's an option you > set on one cmd window, and it sticks for future windows. > > In quick-edit, you just right-click-drag on the cmd window to select a > rectangle of text. ?Then you can Ctrl-V to paste it into email, or into a > text editor, or wherever else you need it. ?Hard to imagine not using this > mode, or its Linux equivalent, which is always available. > > If that wasn't clear enough, or it doesn't work for you, somebody will > explain it better. ?Or ask me, and I'll launch a VirtualBox with Windows to > get you going. > > -- > > DaveA > From toby at tobiah.org Thu Mar 8 17:28:15 2012 From: toby at tobiah.org (Tobiah) Date: Thu, 08 Mar 2012 14:28:15 -0800 Subject: Finding MIME type for a data stream In-Reply-To: References: <%U96r.32867$082.25394@newsfe04.iad> Message-ID: <3oa6r.31449$L12.8825@newsfe23.iad> On 03/08/2012 02:11 PM, Dave Angel wrote: > On 03/08/2012 04:55 PM, Tobiah wrote: >> I'm pulling image data from a database blob, and serving >> it from a web2py app. I have to send the correct >> Content-Type header, so I need to detect the image type. >> >> Everything that I've found on the web so far, needs a file >> name on the disk, but I only have the data. >> >> It looks like the 'magic' package might be of use, but >> I can't find any documentation for it. >> >> Also, it seems like image/png works for other types >> of image data, while image/foo does not, yet I'm afraid >> that not every browser will play along as nicely. >> >> Thanks! >> >> Tobiah > > First step, ask the authors of the database what format of data this > blob is in. > > Failing that, write the same data locally as a binary file, and see what > application can open it. Or if you're on a Linux system, run file on > it. "file" can identify most data formats (not just images) just by > looking at the data. > > That assumes, of course, that there's any consistency in the data coming > out of the database. What happens if next time this blob is an Excel > spreadsheet? > I should simplify my question. Let's say I have a string that contains image data called 'mystring'. I want to do mime_type = some_magic(mystring) and get back 'image/jpg' or 'image/png' or whatever is appropriate for the image data. Thanks! Tobiah From toby at tobiah.org Thu Mar 8 17:34:39 2012 From: toby at tobiah.org (Tobiah) Date: Thu, 08 Mar 2012 14:34:39 -0800 Subject: Finding MIME type for a data stream In-Reply-To: References: <%U96r.32867$082.25394@newsfe04.iad> Message-ID: <3ua6r.9176$fT5.6230@newsfe02.iad> Also, I realize that I could write the data to a file and then use one of the modules that want a file path. I would prefer not to do that. Thanks From ethan at stoneleaf.us Thu Mar 8 17:52:22 2012 From: ethan at stoneleaf.us (Ethan Furman) Date: Thu, 08 Mar 2012 14:52:22 -0800 Subject: What's the best way to write this regular expression? In-Reply-To: <4F59308D.4000403@davea.name> References: <12783654.1174.1331073814011.JavaMail.geo-discussion-forums@yner4> <03dd4256-0881-44e8-bb27-38f23ce66267@h20g2000yqd.googlegroups.com> <21519dbf-4097-4780-874d-41d76f6453e0@x17g2000yqj.googlegroups.com> <4F59308D.4000403@davea.name> Message-ID: <4F593826.9080807@stoneleaf.us> Dave Angel wrote: > On 03/08/2012 04:40 PM, John Salerno wrote: >> >> http://i271.photobucket.com/albums/jj138/JohnJSal/lxml_error.png >> > > Nothing to do with Python, but you'd save us all a lot of space and > bandwidth if you learned how to copy/paste from a Windows cmd window. On Windows XP it is: Mouse ----- Right-click on title bar Left-click on Edit Left-click on Mark Right-click and drag to select desired text to copy text to clipboard Keyboard -------- - e k or arrows to move cursor, to select text to copy text to clipboard ~Ethan~ From d at davea.name Thu Mar 8 17:56:36 2012 From: d at davea.name (Dave Angel) Date: Thu, 08 Mar 2012 17:56:36 -0500 Subject: Finding MIME type for a data stream In-Reply-To: <3oa6r.31449$L12.8825@newsfe23.iad> References: <%U96r.32867$082.25394@newsfe04.iad> <3oa6r.31449$L12.8825@newsfe23.iad> Message-ID: <4F593924.7020301@davea.name> On 03/08/2012 05:28 PM, Tobiah wrote: > > > > I should simplify my question. Let's say I have a string > that contains image data called 'mystring'. > > I want to do > > mime_type = some_magic(mystring) > > and get back 'image/jpg' or 'image/png' or whatever is > appropriate for the image data. > > Thanks! > > Tobiah I have to assume you're talking python 2, since in python 3, strings cannot generally contain image data. In python 2, characters are pretty much interchangeable with bytes. Anyway, I don't know any way in the standard lib to distinguish arbitrary image formats. (There very well could be one.) The file program I referred to was an external utility, which you could run with the multiprocessing module. if you're looking for a specific, small list of file formats, you could make yourself a signature list. Most (not all) formats distinguish themselves in the first few bytes. For example, a standard zip file starts with "PK" for Phil Katz. A Windows exe starts with "MZ" for Mark Zbikowsky. And I believe a jpeg file starts hex(d8) (ff) (e0) (ff) If you'd like to see a list of available modules, help() is your friend. You can start with help("modules") to see quite a long list. And I was surprised how many image related things already are there. So maybe there's something I don't know about that could help. -- DaveA From ramit.prasad at jpmorgan.com Thu Mar 8 17:58:44 2012 From: ramit.prasad at jpmorgan.com (Prasad, Ramit) Date: Thu, 8 Mar 2012 22:58:44 +0000 Subject: "Decoding unicode is not supported" in unusual situation In-Reply-To: <4f593178$0$11963$742ec2ed@news.sonic.net> References: <4f571b94$0$12037$742ec2ed@news.sonic.net> <8762egmzfp.fsf@benfinney.id.au> <4f5749bc$0$29989$c3e8da3$5496439d@news.astraweb.com> <4f57b63f$0$11986$742ec2ed@news.sonic.net> <871up4m69h.fsf@benfinney.id.au> <4f57eeac$0$29989$c3e8da3$5496439d@news.astraweb.com> <87sjhjltsp.fsf@benfinney.id.au> <4f593178$0$11963$742ec2ed@news.sonic.net> Message-ID: <5B80DD153D7D744689F57F4FB69AF474197494@SCACMX008.exchad.jpmchase.net> > Right. The real problem is that Python 2.7 doesn't have distinct > "str" and "bytes" types. type(bytes() returns > "str" is assumed to be ASCII 0..127, but that's not enforced. > "bytes" and "str" should have been distinct types, but > that would have broken much old code. If they were distinct, then > constructors could distinguish between string type conversion > (which requires no encoding information) and byte stream decoding. > > So it's possible to get junk characters in a "str", and they > won't convert to Unicode. I've had this happen with databases which > were supposed to be ASCII, but occasionally a non-ASCII character > would slip through. bytes and str are just aliases for each other. >>> id( bytes ) 505366496 >>> id( str ) 505366496 >>> type( bytes ) >>> type( str ) >>> bytes == str True >>> bytes is str True And I do not think they were ever intended to be just ASCII because chr() takes 0 - 256 (non-inclusive) and returns a str. Ramit Ramit Prasad | JPMorgan Chase Investment Bank | Currencies Technology 712 Main Street | Houston, TX 77002 work phone: 713 - 216 - 5423 -- > -----Original Message----- > From: python-list-bounces+ramit.prasad=jpmorgan.com at python.org > [mailto:python-list-bounces+ramit.prasad=jpmorgan.com at python.org] On Behalf > Of John Nagle > Sent: Thursday, March 08, 2012 4:24 PM > To: python-list at python.org > Subject: Re: "Decoding unicode is not supported" in unusual situation > > On 3/7/2012 6:18 PM, Ben Finney wrote: > > Steven D'Aprano writes: > > > >> On Thu, 08 Mar 2012 08:48:58 +1100, Ben Finney wrote: > >>> I think that's a Python bug. If the latter succeeds as a no-op, the > >>> former should also succeed as a no-op. Neither should ever get any > >>> errors when ?s? is a ?unicode? object already. > >> > >> No. The semantics of the unicode function (technically: a type > >> constructor) are well-defined, and there are two distinct behaviours: > > > This is all different in Python 3.x, where "str" is Unicode and > "bytes" really are a distinct type. > > John Nagle > -- > http://mail.python.org/mailman/listinfo/python-list This email is confidential and subject to important disclaimers and conditions including on offers for the purchase or sale of securities, accuracy and completeness of information, viruses, confidentiality, legal privilege, and legal entity disclaimers, available at http://www.jpmorgan.com/pages/disclosures/email. From ramit.prasad at jpmorgan.com Thu Mar 8 18:02:59 2012 From: ramit.prasad at jpmorgan.com (Prasad, Ramit) Date: Thu, 8 Mar 2012 23:02:59 +0000 Subject: What's the best way to write this regular expression? In-Reply-To: References: <12783654.1174.1331073814011.JavaMail.geo-discussion-forums@yner4> <03dd4256-0881-44e8-bb27-38f23ce66267@h20g2000yqd.googlegroups.com> <21519dbf-4097-4780-874d-41d76f6453e0@x17g2000yqj.googlegroups.com> <4F59308D.4000403@davea.name> Message-ID: <5B80DD153D7D744689F57F4FB69AF4741974AA@SCACMX008.exchad.jpmchase.net> > > Alternatively, you can put the console in quick-edit mode (I think it's > > called, it's been a long time since I ran Windows). That's an option you > > set on one cmd window, and it sticks for future windows. > > > > In quick-edit, you just right-click-drag on the cmd window to select a > > rectangle of text. Then you can Ctrl-V to paste it into email, or into a > > text editor, or wherever else you need it. Hard to imagine not using > this > > mode, or its Linux equivalent, which is always available. Actually in quick-edit mode (XP and higher) you just select with left click and then hit enter which copies it to the clipboard. If you also enable insert mode (not sure if this is Win7 specific) you can even right click to paste into the console, just like Linux. > Needless to say, the Linux console is much nicer :) True. Ramit Ramit Prasad | JPMorgan Chase Investment Bank | Currencies Technology 712 Main Street | Houston, TX 77002 work phone: 713 - 216 - 5423 -- This email is confidential and subject to important disclaimers and conditions including on offers for the purchase or sale of securities, accuracy and completeness of information, viruses, confidentiality, legal privilege, and legal entity disclaimers, available at http://www.jpmorgan.com/pages/disclosures/email. From rafadurancastaneda at gmail.com Thu Mar 8 18:03:08 2012 From: rafadurancastaneda at gmail.com (=?ISO-8859-1?Q?Rafael_Dur=E1n_Casta=F1eda?=) Date: Fri, 09 Mar 2012 00:03:08 +0100 Subject: Can't get around HTTP/401 response using SUDS In-Reply-To: <1331221455.3087.14.camel@linux-dauq.site> References: <1331221455.3087.14.camel@linux-dauq.site> Message-ID: <4F593AAC.30604@gmail.com> El 08/03/12 16:44, Adam Tauno Williams escribi?: > SUDS version 0.4 pn x86_64 Python 2.7 > > I'm having a bear of a time getting HTTP Basic Authentication to work > for a SOAP request via suds. Also using an HTTP proxy server. > > In WireShark I just see a request - > GET http://...../services/services/JobService-0.0.1?wsdl HTTP/1.1 > Accept-Encoding: identity > Host: ....... > Connection: close > User-Agent: Python-urllib/2.7 > > This doesn't contain any authentication credentials so the response is > HTTP/401, and the client doesn't retry with credentials. The response > does come from the remote as I can see there is a WWW-Authenticate > header and it is from an Apache Tomcat server - so it makes it through > the proxy server. > > Code > ================ > url = 'http://....../services/services/JobService-0.0.1?wsdl' > proxy = urllib2.ProxyHandler({'http': 'http://.....:3128'}) > transport = suds.transport.http.HttpAuthenticated() > transport.urlopener = urllib2.build_opener(proxy) > client = suds.client.Client(url, transport=transport, > username='******', password='********') > .... > > I've tried the above as well as the method described at > It has the same problem. > > > Back Trace > ================ > Traceback (most recent call last): > File "etrace.py", line 30, in > client = suds.client.Client(url, transport=transport, > username='*******', password='*****') > File > "/usr/local/lib/python2.7/site-packages/suds-0.4-py2.7.egg/suds/client.py", line 112, in __init__ > self.wsdl = reader.open(url) > File > "/usr/local/lib/python2.7/site-packages/suds-0.4-py2.7.egg/suds/reader.py", line 152, in open > d = self.fn(url, self.options) > File > "/usr/local/lib/python2.7/site-packages/suds-0.4-py2.7.egg/suds/wsdl.py", line 136, in __init__ > d = reader.open(url) > File > "/usr/local/lib/python2.7/site-packages/suds-0.4-py2.7.egg/suds/reader.py", line 79, in open > d = self.download(url) > File > "/usr/local/lib/python2.7/site-packages/suds-0.4-py2.7.egg/suds/reader.py", line 95, in download > fp = self.options.transport.open(Request(url)) > File > "/usr/local/lib/python2.7/site-packages/suds-0.4-py2.7.egg/suds/transport/http.py", line 173, in open > return HttpTransport.open(self, request) > File > "/usr/local/lib/python2.7/site-packages/suds-0.4-py2.7.egg/suds/transport/http.py", line 64, in open > raise TransportError(str(e), e.code, e.fp) > suds.transport.TransportError: HTTP Error 401: Unauthorized > When I've got issues like yours, I usually try using a console client (telnet/curl/wget,...) adding all needed headers/data manually so I'm totally sure the request is OK, if everything goes Ok you know your python code need to be reviewed but when you are under proxies you can find a lot of not python related issues (bad gateways, using proxy when it shouldn't or vice-versa, requests changed by proxy,....). wireshark can be very useful but in situations like this I usually prefer tcpflow output, I think the request/response flow showed is really useful, but that's a personal preference. HTH, bye From d at davea.name Thu Mar 8 18:23:06 2012 From: d at davea.name (Dave Angel) Date: Thu, 08 Mar 2012 18:23:06 -0500 Subject: What's the best way to write this regular expression? In-Reply-To: <5B80DD153D7D744689F57F4FB69AF4741974AA@SCACMX008.exchad.jpmchase.net> References: <12783654.1174.1331073814011.JavaMail.geo-discussion-forums@yner4> <03dd4256-0881-44e8-bb27-38f23ce66267@h20g2000yqd.googlegroups.com> <21519dbf-4097-4780-874d-41d76f6453e0@x17g2000yqj.googlegroups.com> <4F59308D.4000403@davea.name> <5B80DD153D7D744689F57F4FB69AF4741974AA@SCACMX008.exchad.jpmchase.net> Message-ID: <4F593F5A.7050107@davea.name> On 03/08/2012 06:02 PM, Prasad, Ramit wrote: > Actually in quick-edit mode (XP and higher) you just select with > left click and then hit enter which copies it to the clipboard. > If you also enable insert mode (not sure if this is Win7 specific) > you can even right click to paste into the console, just like > Linux. > >> Needless to say, the Linux console is much nicer :) > True. > > I was confusing the left-mouse-drag and the right-click. You are correct about both the copying and the pasting, and they do both work from XP onwards. As I said, I haven't used Windows much in quite a while. -- DaveA From toby at tobiah.org Thu Mar 8 18:40:13 2012 From: toby at tobiah.org (Tobiah) Date: Thu, 08 Mar 2012 15:40:13 -0800 Subject: Finding MIME type for a data stream In-Reply-To: References: <%U96r.32867$082.25394@newsfe04.iad> <3oa6r.31449$L12.8825@newsfe23.iad> Message-ID: > I have to assume you're talking python 2, since in python 3, strings > cannot generally contain image data. In python 2, characters are pretty > much interchangeable with bytes. Yeah, python 2 > if you're looking for a specific, small list of file formats, you could > make yourself a signature list. Most (not all) formats distinguish > themselves in the first few bytes. Yeah, maybe I'll just do that. I'm alowing users to paste images into a rich-text editor, so I'm pretty much looking at .png, .gif, or .jpg. Those should be pretty easy to distinguish by looking at the first few bytes. Pasting images may sound weird, but I'm using a jquery widget called cleditor that takes image data from the clipboard and replaces it with inline base64 data. The html from the editor ends up as an email, and the inline images cause the emails to be tossed in the spam folder for most people. So I'm parsing the emails, storing the image data, and replacing the inline images with an img tag that points to a web2py app that takes arguments that tell it which image to pull from the database. Now that I think of it, I could use php to detect the image type, and store that in the database. Not quite as clean, but that would work. Tobiah From irmen.NOSPAM at xs4all.nl Thu Mar 8 21:12:42 2012 From: irmen.NOSPAM at xs4all.nl (Irmen de Jong) Date: Fri, 09 Mar 2012 03:12:42 +0100 Subject: Finding MIME type for a data stream In-Reply-To: <3ua6r.9176$fT5.6230@newsfe02.iad> References: <%U96r.32867$082.25394@newsfe04.iad> <3ua6r.9176$fT5.6230@newsfe02.iad> Message-ID: <4f596718$0$6847$e4fe514c@news2.news.xs4all.nl> On 8-3-2012 23:34, Tobiah wrote: > Also, I realize that I could write the data to a file > and then use one of the modules that want a file path. > I would prefer not to do that. > > Thanks > Use StringIO then, instead of a file on disk Irmen From joncle at googlemail.com Thu Mar 8 21:31:22 2012 From: joncle at googlemail.com (Jon Clements) Date: Thu, 8 Mar 2012 18:31:22 -0800 (PST) Subject: Finding MIME type for a data stream In-Reply-To: References: <%U96r.32867$082.25394@newsfe04.iad> <3oa6r.31449$L12.8825@newsfe23.iad> Message-ID: <30829846.74.1331260282202.JavaMail.geo-discussion-forums@vbai14> On Thursday, 8 March 2012 23:40:13 UTC, Tobiah wrote: > > I have to assume you're talking python 2, since in python 3, strings > > cannot generally contain image data. In python 2, characters are pretty > > much interchangeable with bytes. > > Yeah, python 2 > > > > if you're looking for a specific, small list of file formats, you could > > make yourself a signature list. Most (not all) formats distinguish > > themselves in the first few bytes. > > Yeah, maybe I'll just do that. I'm alowing users to paste > images into a rich-text editor, so I'm pretty much looking > at .png, .gif, or .jpg. Those should be pretty easy to > distinguish by looking at the first few bytes. > > Pasting images may sound weird, but I'm using a jquery > widget called cleditor that takes image data from the > clipboard and replaces it with inline base64 data. > The html from the editor ends up as an email, and the > inline images cause the emails to be tossed in the > spam folder for most people. So I'm parsing the > emails, storing the image data, and replacing the > inline images with an img tag that points to a > web2py app that takes arguments that tell it which > image to pull from the database. > > Now that I think of it, I could use php to detect the > image type, and store that in the database. Not quite > as clean, but that would work. > > Tobiah Something like the following might be worth a go: (untested) from PIL import Image img = Image.open(StringIO(blob)) print img.format HTH Jon. PIL: http://www.pythonware.com/library/pil/handbook/image.htm From wuwei23 at gmail.com Thu Mar 8 22:38:51 2012 From: wuwei23 at gmail.com (alex23) Date: Thu, 8 Mar 2012 19:38:51 -0800 (PST) Subject: What's the best way to write this regular expression? References: <12783654.1174.1331073814011.JavaMail.geo-discussion-forums@yner4> Message-ID: <9796cdc0-7322-4d1b-b513-a51fb8bc5e62@lf20g2000pbb.googlegroups.com> John Salerno wrote: > So much work just to get a 3rd party module installed! "New! Try out the beta release of Beautiful Soup 4. (Last updated February 28, 2012) easy_install beautifulsoup4 or pip install beautifulsoup4 or download a tarball." http://www.crummy.com/software/BeautifulSoup/ Worked fine under both Python 2.7 & 3.2 using pip. From johnjsal at gmail.com Thu Mar 8 22:52:48 2012 From: johnjsal at gmail.com (John Salerno) Date: Thu, 8 Mar 2012 19:52:48 -0800 (PST) Subject: What's the best way to write this regular expression? In-Reply-To: <9796cdc0-7322-4d1b-b513-a51fb8bc5e62@lf20g2000pbb.googlegroups.com> References: <12783654.1174.1331073814011.JavaMail.geo-discussion-forums@yner4> <9796cdc0-7322-4d1b-b513-a51fb8bc5e62@lf20g2000pbb.googlegroups.com> Message-ID: <11016571.151.1331265168696.JavaMail.geo-discussion-forums@yneo2> On Thursday, March 8, 2012 9:38:51 PM UTC-6, alex23 wrote: > John Salerno wrote: > > So much work just to get a 3rd party module installed! > > "New! Try out the beta release of Beautiful Soup 4. (Last updated > February 28, 2012) > easy_install beautifulsoup4 or pip install beautifulsoup4 or download > a tarball." > > http://www.crummy.com/software/BeautifulSoup/ > > Worked fine under both Python 2.7 & 3.2 using pip. Yeah, but first I had to figure out how to install easy_install :) From hackingkk at gmail.com Thu Mar 8 23:27:16 2012 From: hackingkk at gmail.com (hackingKK) Date: Fri, 09 Mar 2012 09:57:16 +0530 Subject: GUI components in python In-Reply-To: References: Message-ID: <4F5986A4.8060006@gmail.com> Hi Janaki, Python will mostly use either the pygtk library or pyqt library for any rich and production quality GUI. So you must try figuring out if either of these 2 libraries are used. Other than this, there is tkinter which i guess comes with Python as default. Happy hacking. Krishnakant. On 07/03/12 19:14, janaki rajamani wrote: > Hi > > I am stuck with the brain workshop software implemented using python. > The code involves a lot of GUI elements and i am familar only with the > basic python programming. > I would like to know whether there are built in classes to support GUI > elements or arethey project dependant. > From jagteraho2006 at gmail.com Thu Mar 8 23:40:57 2012 From: jagteraho2006 at gmail.com (amar Singh) Date: Thu, 8 Mar 2012 20:40:57 -0800 (PST) Subject: how to get plots made faster Message-ID: <5415ca7c-ccc4-4ec3-a118-4674e54038a7@b18g2000vbz.googlegroups.com> The following is the part of my code which is running faster locally and more slowly remotely via ssh on the same machine. Note I am trying to generate a multi-page report. ## create plots and write to a pdf file from scipy import * import matplotlib.pyplot as plt from matplotlib.backends.backend_pdf import PdfPages # open a multi-page pdf file pp = PdfPages('history_plot.pdf') F=loadtxt('hist.dat',comments='%') t=F[:,0] E=F[:,13] plt.plot(t,E) h1=plt.ylabel('Energy', fontsize=16) h1=plt.xlabel('Time', fontsize=16) pp.savefig() plt.clf() VdotB=F[:,14] plt.plot(t,VdotB) pp.savefig() pp.close() From breamoreboy at yahoo.co.uk Fri Mar 9 01:01:23 2012 From: breamoreboy at yahoo.co.uk (Mark Lawrence) Date: Fri, 09 Mar 2012 06:01:23 +0000 Subject: how to get plots made faster In-Reply-To: <5415ca7c-ccc4-4ec3-a118-4674e54038a7@b18g2000vbz.googlegroups.com> References: <5415ca7c-ccc4-4ec3-a118-4674e54038a7@b18g2000vbz.googlegroups.com> Message-ID: On 09/03/2012 04:40, amar Singh wrote: > The following is the part of my code which is running faster locally > and more slowly remotely via ssh on the same machine. Note I am trying > to generate a multi-page report. > > > ## create plots and write to a pdf file > from scipy import * > import matplotlib.pyplot as plt > from matplotlib.backends.backend_pdf import PdfPages > > # open a multi-page pdf file > pp = PdfPages('history_plot.pdf') > > F=loadtxt('hist.dat',comments='%') > > > t=F[:,0] > E=F[:,13] > > plt.plot(t,E) > > h1=plt.ylabel('Energy', fontsize=16) > h1=plt.xlabel('Time', fontsize=16) > pp.savefig() > > plt.clf() > VdotB=F[:,14] > plt.plot(t,VdotB) > > pp.savefig() > pp.close() I can't help directly but you may be better off asking on the matplotlib users mailing list see https://lists.sourceforge.net/lists/listinfo/matplotlib-users -- Cheers. Mark Lawrence. From torriem at gmail.com Fri Mar 9 01:33:58 2012 From: torriem at gmail.com (Michael Torrie) Date: Thu, 08 Mar 2012 23:33:58 -0700 Subject: GUI components in python In-Reply-To: References: Message-ID: <4F59A456.4070703@gmail.com> On 03/07/2012 06:44 AM, janaki rajamani wrote: > Hi > > I am stuck with the brain workshop software implemented using python. > The code involves a lot of GUI elements and i am familar only with the > basic python programming. > I would like to know whether there are built in classes to support GUI > elements or arethey project dependant. brain workshop appears to use the pyglet library: http://www.pyglet.org/ From jkn_gg at nicorp.f9.co.uk Fri Mar 9 05:45:13 2012 From: jkn_gg at nicorp.f9.co.uk (jkn) Date: Fri, 9 Mar 2012 02:45:13 -0800 (PST) Subject: What's the best way to write this regular expression? References: <12783654.1174.1331073814011.JavaMail.geo-discussion-forums@yner4> <03dd4256-0881-44e8-bb27-38f23ce66267@h20g2000yqd.googlegroups.com> <21519dbf-4097-4780-874d-41d76f6453e0@x17g2000yqj.googlegroups.com> <4F59308D.4000403@davea.name> Message-ID: <304e2797-20c3-4333-b4a0-a53cedbd1c24@w5g2000vbv.googlegroups.com> Also unrelated to the OP, but a far superior Commnad line interface to Windows is the (unhelpfully-named) 'console' program: http://sourceforge.net/projects/console/ This has tabbed windows, preset directory navigation, good copy/paste facilities, the ability to configure different shells, etc etc. Well worth a look. HTH J^n From __peter__ at web.de Fri Mar 9 05:50:04 2012 From: __peter__ at web.de (Peter Otten) Date: Fri, 09 Mar 2012 11:50:04 +0100 Subject: Finding MIME type for a data stream References: <%U96r.32867$082.25394@newsfe04.iad> Message-ID: Tobiah wrote: > I'm pulling image data from a database blob, and serving > it from a web2py app. I have to send the correct > Content-Type header, so I need to detect the image type. > > Everything that I've found on the web so far, needs a file > name on the disk, but I only have the data. > > It looks like the 'magic' package might be of use, but > I can't find any documentation for it. After some try-and-error and a look into example.py: >>> m = magic.open(magic.MAGIC_MIME_TYPE) >>> m.load() 0 >>> sample = open("tmp.png").read() >>> m.buffer(sample) 'image/png' From neilc at norwich.edu Fri Mar 9 08:23:21 2012 From: neilc at norwich.edu (Neil Cerutti) Date: 9 Mar 2012 13:23:21 GMT Subject: "Decoding unicode is not supported" in unusual situation References: <4f571b94$0$12037$742ec2ed@news.sonic.net> <8762egmzfp.fsf@benfinney.id.au> <4f5749bc$0$29989$c3e8da3$5496439d@news.astraweb.com> <4f57b63f$0$11986$742ec2ed@news.sonic.net> <871up4m69h.fsf@benfinney.id.au> <4f57eeac$0$29989$c3e8da3$5496439d@news.astraweb.com> <87sjhjltsp.fsf@benfinney.id.au> <4f593178$0$11963$742ec2ed@news.sonic.net> Message-ID: <9ruei9FnpgU3@mid.individual.net> On 2012-03-08, John Nagle wrote: > So it's possible to get junk characters in a "str", and they > won't convert to Unicode. I've had this happen with databases > which were supposed to be ASCII, but occasionally a non-ASCII > character would slip through. Perhaps encode and then decode, rather than try to encode a non-encoded str. -- Neil Cerutti From jg07024 at gmail.com Fri Mar 9 09:11:34 2012 From: jg07024 at gmail.com (John Graves) Date: Sat, 10 Mar 2012 03:11:34 +1300 Subject: A Plausible Promise of Abundant Educational Resources Message-ID: Dear Python-List: If you find Wikipedia useful and can see the value of collaborating on a project which could make learning material as freely and spectacularly available as Wikipedia does reference material[1], please read on. Background: In November 2009, I began learning Python with the objective of trying to understand the following research question in my PhD research study of open source software development: "We have built Wikipedia and other big, successful open source projects. How can we do it again (and again)?" The critical issue for me was how to start a project which would grow to self-sustainability. So for over two years now, my research method has been to try to actually start such a project. I failed. Over and over. The data collection period for my study ended. Before I could start writing up my PhD, however, I saw an answer provided in February 2012 by the founder of Craigslist, on Quora. When asked, "How did Craigslist gain its initial traction?"[2], Craig Newmark, Customer Service Rep & Founder wrote: - from beginning, did something simple and useful - from beginning, began cycle: -- asked for community feedback -- did something about it -- repeat, forever -- got lucky with simple site design So I have now tried to take what started as a horribly over ambitious desktop application[3], combined with an equally inept Android mobile application (done in Java)[4] and boiled down the core text-to-speech functionality into something "simple and useful" which runs on the web. The project is now called SlideSpeech[5] and it does a couple of pretty interesting things. Interesting enough to attract venture capital. The Future: As of 23 February 2012, SlideSpeech Limited is a company. But it is still an open source software development research project with a Pythonic heart. I can now pay for development of some professional quality software by people who know much more Java and Python than I do. Perhaps this will help the project reach self-sustainability, although, as Derek Sivers points out in a memorable TED talk[6], just initiating or leading a project like this is not what makes it a success: there must be joiners and followers for a project with a plausible promise to grow to realise its potential. The followers are the real heroes. Now Peter Diamandis just gave a TED talk entitled, "Abundance is our future"[7] which everyone should watch. He talks of 3 billion people coming on-line this decade. I want SlideSpeech to be useful and helpful to those people. Not to make money from them but to help foster a global conversation and global distribution of knowledge. We should all share in Educational Abundance. Diamandis says, "we're going to hit 70 percent penetration of cellphones in the developing world by the end of 2013." SlideSpeech can plausibly promise to deliver free, interactive learning material to smart phones anywhere on the planet this year. The current working prototype does this today. In its simplest form, the system works like this: 1) you start in your presentation software, adding a voice over script in the speaker notes of each slide 2) you upload your presentation to SlideSpeech 3) on the SlideSpeech server (which can be your own PC, running Python, made viewable to the world using PageKite[8]), the presentation is "decomposed" into slide images and text scripts. The scripts are fed into a text-to-speech engine. The resulting audio files are wrapped in HTML with their corresponding slide image files. Finally, a link to access the HTML is e-mailed back to you 4) you open the link on your mobile phone's web browser and the presentation you were writing just moments before "delivers itself" on your phone ... or on any smart phone, tablet or web browser, anywhere. No need to organise a venue, send invitations or get people to actually physically show up to see and hear your talk. You can just forward the e-mail. Cooler still, 5) if you have a native application play the script using the phone's text-to-speech engine, you don't have to download audio (or video), so you save 75% of the bandwidth. Multiplied by billions of people, multiplied by the number of downloads[9], that is a huge savings. The compression of content into the simple combination of images and text-to-speech scripts allows SlideSpeech to realise part of the One Laptop Per Child vision using "talking" smart phones and tablets. Students can learn on their own. Current prices on the cheapest Android 2.2 gear which can deliver SlideSpeech content here in Auckland, New Zealand are under NZ$150. A Revolution in Learning: Think of SlideSpeech as a platform like Khan Academy[10] with the exercises integrated into the presentation. The scripts can be created and improved collaboratively, like Wikipedia articles, or cloned and customised for particular audiences. Unlike Khan Academy videos, the text of SlideSpeech presentations is search-able and machine-translatable. With presentation feedback built into the system[11], a newly created presentation can be distributed and then dynamically critiqued and revised, so later viewers see the corrected and improved version. It is remarkable how quickly changes can be made, especially in contrast to the feedback cycle a typical instructor goes through to improve their teaching. These ideas and technologies are not new. Text-to-speech, in particular, has been around for a long time. Lately, however, the voices have become "Avatar-quality"[12]. These ideas are disruptive. The current working prototypes of SlideSpeech may appear to work poorly, underperforming relative to established products, but as Clayton Christensen explains[13], having the ability to meet an underlying need in a radically different way transforms industries. I like to make an analogy with trains and cars. Current educational systems are like trains: everyone has to go between the same fixed destinations at the same fixed times, like it or not. SlideSpeech-based learning is like having a car: you get to go learn whatever you want, whenever you want, wherever you are, at your own pace (which is sometimes very, very fast!). Content is King: Having lots of content available will accelerate the adoption of SlideSpeech above all else. Over the coming weeks, as the system matures, you can start preparing by authoring presentations with speaker notes. Once the system is fully available on-line, or downloadable to your PC, you can drop your presentations in and get out "self-delivering" talks in HTML or even video format, voiced by a wide selection of computer voices in English and in many other languages. Please feel free to jump in with suggestions, contributions or forks of the code repositories listed below. Let's make Educational Abundance happen with Python this year. Exponentially yours, John Graves PhD Student AUT University Auckland, New Zealand Founder and CEO SlideSpeech [1] The English language version of Wikipedia has 50 times as many words as *Encyclop?dia Britannica * http://en.wikipedia.org/wiki/Wikipedia:Size_comparisons [2] http://www.quora.com/How-did-Craigslist-gain-its-initial-traction [3] http://code.google.com/p/open-allure-ds/ [4] http://code.google.com/p/wiki-to-speech/ [5] http://code.google.com/p/slidespeech/ [6] http://www.ted.com/talks/derek_sivers_how_to_start_a_movement.html [7] http://www.ted.com/talks/peter_diamandis_abundance_is_our_future.html [8] http://pagekite.net [9] average for Wikipedia is about one article per person per day (18.1 billion pages / 482 million unique visitors in January 2012) http://stats.wikimedia.org/reportcard/ [10] http://khanacademy.org [11] http://code.google.com/p/slidespeech/wiki/WorkflowDiagrams [12] I particularly like Loquendo's Veena, Indian English voice http://www.loquendo.com/en/demo-center/tts-demo/english/ [13] http://en.wikipedia.org/wiki/Disruptive_technology -------------- next part -------------- An HTML attachment was scrubbed... URL: From rboothroyd8 at gmail.com Fri Mar 9 10:10:19 2012 From: rboothroyd8 at gmail.com (Richard Boothroyd) Date: Fri, 9 Mar 2012 07:10:19 -0800 (PST) Subject: converting from tcl/tkl to python Message-ID: Hi there, First, I am not a developer so go easy on my ignorance ;-). Our company designs and develops hearing aid audibility fitting equipment. (www.audioscan.com). Our current software GUI is all based on TCL/TKL and we are running into issues on developing a "prettier" GUI in an effort to modernize some of our equipment. My understanding is that Python is a much better GUI tool than TCL/TKL so I'd appreciate any insight on this assumption. Also I'm wondering what kind of effort and expertise it would take to convert from TCL/ TKL to Python. Let me know what further info you may require. Also, if there is anyone out there that has specific expertise in performing this conversion please contact me. Thanks Richard Boothroyd General Manager Audioscan From reader at calvinkim.org Fri Mar 9 10:46:41 2012 From: reader at calvinkim.org (Calvin Kim) Date: Fri, 09 Mar 2012 10:46:41 -0500 Subject: A Plausible Promise of Abundant Educational Resources In-Reply-To: References: Message-ID: <4F5A25E1.10503@calvinkim.org> Google search for slidespeech returns with a warning, "This site may harm your computer." From rodperson at rodperson.com Fri Mar 9 10:58:47 2012 From: rodperson at rodperson.com (Rod Person) Date: Fri, 9 Mar 2012 10:58:47 -0500 Subject: converting from tcl/tkl to python In-Reply-To: References: Message-ID: <20120309105847.00003316@unknown> On Fri, 9 Mar 2012 07:10:19 -0800 (PST) Richard Boothroyd wrote: > Hi there, > > First, I am not a developer so go easy on my ignorance ;-). Our > company designs and develops hearing aid audibility fitting equipment. > (www.audioscan.com). Our current software GUI is all based on TCL/TKL > and we are running into issues on developing a "prettier" GUI in an > effort to modernize some of our equipment. Have you looked at Tile? It a theme-able widget set for Tk. http://wiki.tcl.tk/11075 As for python, the default GUI toolkit for Python is Tk, but there are bindings that allow you to use WxWidgets, Qt and GTK. -- Rod Person http://www.rodperson.com rodperson at rodperson.com 'Silence is a fence around wisdom' From kw at codebykevin.com Fri Mar 9 10:59:09 2012 From: kw at codebykevin.com (Kevin Walzer) Date: Fri, 09 Mar 2012 10:59:09 -0500 Subject: converting from tcl/tkl to python In-Reply-To: References: Message-ID: On 3/9/12 10:10 AM, Richard Boothroyd wrote: > First, I am not a developer so go easy on my ignorance ;-). Our > company designs and develops hearing aid audibility fitting equipment. > (www.audioscan.com). Our current software GUI is all based on TCL/TKL > and we are running into issues on developing a "prettier" GUI in an > effort to modernize some of our equipment. > > My understanding is that Python is a much better GUI tool than TCL/TKL > so I'd appreciate any insight on this assumption. Also I'm wondering > what kind of effort and expertise it would take to convert from TCL/ > TKL to Python. Let me know what further info you may require. > First, don't assume that Tcl/Tk is not up to the job. I took a look at some of your software screenshots at your website and noticed that you are using the "classic" Tk widgets, which, while functional, are a bit dated in their appearance. Tcl/Tk 8.5 has added a separate group of widgets called the ttk (for "themed Tk") widgets that are fully native in appearance on Windows/Mac and much improved in their appearance on Linux/Unix. Here's a screenshot of a Tcl/Tk app using the ttk widgets on Windows: http://sourceforge.net/p/windowstoolset/screenshot/screenshot.png If modernizing the UI is all you need to do, a careful update of your code using the themed Tk widgets will take you a long way, with far less work and cost than porting your code to Python. Having said this, if you are seeing other issues with Tcl (lack of support for certain libraries/API's, code is becoming unmanagable, etc.) and you have concluded that Python is a superior choice overall, then there are a number of different routes you can take: 1. Python's built-in GUI toolkit is a wrapper for Tk called Tkinter. Recent versions of Python support the themed Tk widgets as well as the classic Tk widgets. Doing a port of your code from Tcl/Tk to Python will be somewhat simpler if you use Python's Tkinter library, because the general layout will be similar. However, there are no automated tools for mapping Tk to Tkinter that I am aware of--you will have to do a rewrite of your code. 2. Python also has bindings for many other UI toolkits, including wxWidgets (a very nice cross-platform toolkit that has native UI bindings), Qt, Gtk, and others. If you prefer a different design/toolkit/API, these may be worth a look. However, if you opt for one of these toolkits and Python, then you are essentially starting from scratch with your software--it will be a complete rewrite not just in the programming language but also in the UI design as well. That will take a great deal of additional time and cost. To sum up: a rewrite of your software in Python will amount a major-to-complete overhaul of the code base, depending on how you approach the UI design--and this will involve significant cost and time. This may make sense if you feel you have reached the end of the line with Tcl and your desire for a different language is for reasons in addition to the look and feel of the UI. However, if your software and its code is otherwise satisfactory and you need simply to update the UI design, that can be done in Tcl at far less cost using the ttk widgets. Hope this helps, Kevin -- Kevin Walzer Code by Kevin http://www.codebykevin.com From toby at tobiah.org Fri Mar 9 11:35:42 2012 From: toby at tobiah.org (Tobiah) Date: Fri, 09 Mar 2012 08:35:42 -0800 Subject: Finding MIME type for a data stream In-Reply-To: <4f596718$0$6847$e4fe514c@news2.news.xs4all.nl> References: <%U96r.32867$082.25394@newsfe04.iad> <3ua6r.9176$fT5.6230@newsfe02.iad> <4f596718$0$6847$e4fe514c@news2.news.xs4all.nl> Message-ID: On 03/08/2012 06:12 PM, Irmen de Jong wrote: > On 8-3-2012 23:34, Tobiah wrote: >> Also, I realize that I could write the data to a file >> and then use one of the modules that want a file path. >> I would prefer not to do that. >> >> Thanks >> > > Use StringIO then, instead of a file on disk > > Irmen > Nice. Thanks. From toby at tobiah.org Fri Mar 9 11:40:39 2012 From: toby at tobiah.org (Tobiah) Date: Fri, 09 Mar 2012 08:40:39 -0800 Subject: Finding MIME type for a data stream In-Reply-To: References: <%U96r.32867$082.25394@newsfe04.iad> <3oa6r.31449$L12.8825@newsfe23.iad> Message-ID: On 03/08/2012 06:04 PM, Dennis Lee Bieber wrote: > On Thu, 08 Mar 2012 15:40:13 -0800, Tobiah declaimed > the following in gmane.comp.python.general: > > >> Pasting images may sound weird, but I'm using a jquery >> widget called cleditor that takes image data from the >> clipboard and replaces it with inline base64 data. > > In Windows, I'd expect "device independent bitmap" to be the result > of a clipboard image... This jquery editor seems to detect the image data and translate it into an inline image like: I'm curious to know if anyone with ElementTree 1.3 has gotten the parent XPath to work? According to http://effbot.org/zone/element-xpath.htm, you should be able to do >>> import xml.etree.ElementTree as et >>> et.VERSION '1.3.0' ... >>> elem.find('..') >>> but that always return None for me. Has anyone else seen this particular XPath work? Am I just doing something wrong? Thanks for you help! Jason PS. In case you're wondering, yes I know that lxml supports parent points and, yes, I'm aware of http://effbot.org/zone/element.htm#accessing-parents. I'm really wondering if the mentioned XPath is broken or something. From skawaii at gmail.com Fri Mar 9 12:47:47 2012 From: skawaii at gmail.com (Jason Cooper) Date: Fri, 9 Mar 2012 09:47:47 -0800 (PST) Subject: Does ElementTree's Parent XPath actually work? In-Reply-To: <20999038.134.1331313844881.JavaMail.geo-discussion-forums@pbnt10> References: <20999038.134.1331313844881.JavaMail.geo-discussion-forums@pbnt10> Message-ID: <10963798.786.1331315267484.JavaMail.geo-discussion-forums@pbcmk6> On Friday, March 9, 2012 12:24:04 PM UTC-5, Jason Cooper wrote: > I'm curious to know if anyone with ElementTree 1.3 has gotten the parent XPath to work? According to http://effbot.org/zone/element-xpath.htm, you should be able to do > > >>> import xml.etree.ElementTree as et > >>> et.VERSION > '1.3.0' > ... > >>> elem.find('..') > >>> > > but that always return None for me. Has anyone else seen this particular XPath work? Am I just doing something wrong? > > Thanks for you help! > Jason > > PS. In case you're wondering, yes I know that lxml supports parent points and, yes, I'm aware of http://effbot.org/zone/element.htm#accessing-parents. I'm really wondering if the mentioned XPath is broken or something. Looks like I may have figured out my own answer. I just noticed that using '..' when searching on the tree (as opposed to the element) works as expected. Makes sense after I stepped back and recalled that the elements don't contain pointers to their parents. The tree, on the other hand, can see all. From toby at tobiah.org Fri Mar 9 12:53:30 2012 From: toby at tobiah.org (Tobiah) Date: Fri, 09 Mar 2012 09:53:30 -0800 Subject: Finding MIME type for a data stream In-Reply-To: <30829846.74.1331260282202.JavaMail.geo-discussion-forums@vbai14> References: <%U96r.32867$082.25394@newsfe04.iad> <3oa6r.31449$L12.8825@newsfe23.iad> <30829846.74.1331260282202.JavaMail.geo-discussion-forums@vbai14> Message-ID: > Something like the following might be worth a go: > (untested) > > from PIL import Image > img = Image.open(StringIO(blob)) > print img.format > This worked quite nicely. I didn't see a list of all returned formats though in the docs. The one image I had returned PNG So I'm doing: mime_type = "image/%s" % img.format.lower() I'm hoping that will work for any image type. Thanks, Tobiah From nagle at animats.com Fri Mar 9 13:11:58 2012 From: nagle at animats.com (John Nagle) Date: Fri, 09 Mar 2012 10:11:58 -0800 Subject: "Decoding unicode is not supported" in unusual situation In-Reply-To: References: <4f571b94$0$12037$742ec2ed@news.sonic.net> <8762egmzfp.fsf@benfinney.id.au> <4f5749bc$0$29989$c3e8da3$5496439d@news.astraweb.com> <4f57b63f$0$11986$742ec2ed@news.sonic.net> <871up4m69h.fsf@benfinney.id.au> <4f57eeac$0$29989$c3e8da3$5496439d@news.astraweb.com> <87sjhjltsp.fsf@benfinney.id.au> <4f593178$0$11963$742ec2ed@news.sonic.net> Message-ID: <4f5a47f0$0$11979$742ec2ed@news.sonic.net> On 3/8/2012 2:58 PM, Prasad, Ramit wrote: >> Right. The real problem is that Python 2.7 doesn't have distinct >> "str" and "bytes" types. type(bytes() returns >> "str" is assumed to be ASCII 0..127, but that's not enforced. >> "bytes" and "str" should have been distinct types, but >> that would have broken much old code. If they were distinct, then >> constructors could distinguish between string type conversion >> (which requires no encoding information) and byte stream decoding. >> >> So it's possible to get junk characters in a "str", and they >> won't convert to Unicode. I've had this happen with databases which >> were supposed to be ASCII, but occasionally a non-ASCII character >> would slip through. > > bytes and str are just aliases for each other. That's true in Python 2.7, but not in 3.x. From 2.6 forward, "bytes" and "str" were slowly being separated. See PEP 358. Some of the problems in Python 2.7 come from this ambiguity. Logically, "unicode" of "str" should be a simple type conversion from ASCII to Unicode, while "unicode" of "bytes" should require an encoding. But because of the bytes/str ambiguity in Python 2.6/2.7, the behavior couldn't be type-based. John Nagle From mark at markroseman.com Fri Mar 9 15:36:01 2012 From: mark at markroseman.com (Mark Roseman) Date: Fri, 09 Mar 2012 13:36:01 -0700 Subject: converting from tcl/tkl to python References: Message-ID: Hi Richard, I would strongly second the advice that Kevin provided: rewriting is a substantial step not to be taken lightly. If a mere facelift is desired, migrating to the more modern tools provided in recent versions of Tcl/Tk may well meet your needs at a fraction of the cost/effort. For additional information, you can point your technical people at http://www.tkdocs.com. Mark From invalid at invalid.invalid Fri Mar 9 15:54:48 2012 From: invalid at invalid.invalid (Grant Edwards) Date: Fri, 9 Mar 2012 20:54:48 +0000 (UTC) Subject: converting from tcl/tkl to python References: Message-ID: On 2012-03-09, Kevin Walzer wrote: > Having said this, if you are seeing other issues with Tcl (lack of > support for certain libraries/API's, code is becoming unmanagable, etc.) > and you have concluded that Python is a superior choice overall, then > there are a number of different routes you can take: > > 1. Python's built-in GUI toolkit is a wrapper for Tk called Tkinter. > Recent versions of Python support the themed Tk widgets as well as the > classic Tk widgets. Doing a port of your code from Tcl/Tk to Python will > be somewhat simpler if you use Python's Tkinter library, because the > general layout will be similar. However, there are no automated tools > for mapping Tk to Tkinter that I am aware of--you will have to do a > rewrite of your code. If you _do_ decide a rewrite of your code is in order, trying to "convert" your existing code will mostly likey produce a mess. Python and Tcl are very different languages. Trying to write a Tcl program in Python won't work very well. The right thing to do is to carefully figure out what the requirements are (you should probably even write them down). Then sit down with a blank slate and design/build/grow/write a Python application. Evaluating and choosing a GUI framework (Tk, Wx, Gtk, Qt, etc.) can take quite a bit of time, so remember to allow for that. If you decide to skip that step and stick with Tk, then you've got a bit of head start since you know how Tk works (assuming the API for the newer themed widgets isn't too much different than the old widgets). -- Grant Edwards grant.b.edwards Yow! Give them RADAR-GUIDED at SKEE-BALL LANES and gmail.com VELVEETA BURRITOS!! From ethan at stoneleaf.us Fri Mar 9 17:10:18 2012 From: ethan at stoneleaf.us (Ethan Furman) Date: Fri, 09 Mar 2012 14:10:18 -0800 Subject: stackoverflow question Message-ID: <4F5A7FCA.6030109@stoneleaf.us> Hey all! I posted a question/answer on SO earlier, but there seems to be some confusion around either the question or the answer (judging from the comments). http://stackoverflow.com/q/9638921/208880 If anyone here is willing to take a look at it and let me know if I did not write it well, I would appreciate the feedback. Here's the question text: ------------------------ I'm writing a metaclass to do some cool stuff, and part of its processing is to check that certain attributes exist when the class is created. Some of these are mutable, and would normally be set in `__init__`, but since `__init__` isn't run until the instance is created the metaclass won't know that the attribute *will* be created, and raises an error. I could do something like: class Test(meta=Meta): mutable = None def __init__(self): self.mutable = list() But that isn't very elegant, and also violates DRY. What I need is some way to have: class Test(metaclass=Meta): mutable = list() t1 = Test() t2 = Test() t1.mutable.append('one') t2.mutable.append('two') t1.mutable # prints ['one'] t2.mutable # prints ['two'] Any ideas on how this can be accomplished? Also, the metaclass doing the checking doesn't care what type of object the attribute is, only that it is there. --------------------------- and the answer text: ------------------- There are a couple ways to do this: 1. Have the metaclass check all the attributes, and if they are one of the mutables (`list`, `dict`, `set`, etc.) replace the attribute with a descriptor that will activate on first access and update the instance with a fresh copy of the mutable. 2. Provide the descriptor from (1) as a decorator to be used when writing the class. I prefer (2) is it gives complete control to the class author, and simplifies those cases where the class-level mutable attribute *should* be shared amongst all the instances. Here's the decorator-descriptor: class ReplaceMutable: def __init__(self, func): self.func = func def __call__(self): return self def __get__(self, instance, owner): if instance is None: return self result = self.func() setattr(instance, self.func.__name__, result) return result and the test class: class Test: @ReplaceMutable def mutable(): return list() t1 = Test() t2 = Test() t1.mutable.append('one') t2.mutable.append('two') print(t1.mutable) print(t2.mutable) How it works: Just like `property`, `ReplaceMutable` is a descriptor object with the same name as the attribute it is replacing. Unlike `property`, it does not define `__set__` nor `__delete__`, so when code tries to rebind the name (`mutable` in the test above) in the instance Python will allow it to do so. This is the same idea behind caching descriptors. `ReplaceMutable` is decorating a function (with the name of the desired attribute) that simply returns whatever the instance level attribute should be initialized with (an empty `list` in the example above). So the first time the attribute is looked up on an instance it will not be found in the instance dictionary and Python will activate the descriptor; the descriptor then calls the function to retrieve the initial object/data/whatever, stores it in the instance, and then returns it. The next time that attribute is accessed *on that instance* it will be in the instance dictionary, and that is what will be used. ----------------------------------- Thanks, ~Ethan~ From businessmother at hotmail.com Fri Mar 9 17:38:48 2012 From: businessmother at hotmail.com (businessmother at hotmail.com) Date: Fri, 9 Mar 2012 14:38:48 -0800 (PST) Subject: TIME SENSITIVE] Please Open Immediately! Message-ID: <9567e466-be65-4d58-88ac-f628a85ff2ca@h20g2000yqd.googlegroups.com> TIME SENSITIVE] Please Open Immediately! http://signup.wazzub.info/?lrRef=c18fbd9 Dear partners, Sometimes it is most important to act fast. Imagine a project that has the potential to become the next GooTwitFaceuPon and you have the advantage to be one of the first to join ? BEFORE OFFICIAL PRE-LAUNCH. F*R*E*E Forever (NO FEES) + NO AUTOSHIPS + NO JOBS TO DO +NOTHING TO SELL + NOTHING TO BUY + NOTHING TO DOWNLOAD = THE PERFECT OPPORTUNITY But you have to be fast: the earlier you pre-register without any costs, the more money you can make just by inviting other F*R*E*E members. My recommendation: Step 1 ? go here and sign up: http://signup.wazzub.info/?lrRef=c18fbd9c Step 2 ? read all the important facts at: www.wazzub.info/facts.htm Step 3 ? read ?How Is W.A.Z.Z.U.B Different? www.wazzub.info/difference.htm Step 4 ? invite your friends and partners to become a part in this success story Hurry up, act now! Accept my positive vibrations of Succe$$ and Happiness :-) Together we activate the power of "We"! Thank you, From tjreedy at udel.edu Fri Mar 9 18:16:32 2012 From: tjreedy at udel.edu (Terry Reedy) Date: Fri, 09 Mar 2012 18:16:32 -0500 Subject: stackoverflow question In-Reply-To: <4F5A7FCA.6030109@stoneleaf.us> References: <4F5A7FCA.6030109@stoneleaf.us> Message-ID: On 3/9/2012 5:10 PM, Ethan Furman wrote: > Hey all! > > I posted a question/answer on SO earlier, but there seems to be some > confusion around either the question or the answer (judging from the > comments). > > http://stackoverflow.com/q/9638921/208880 > > If anyone here is willing to take a look at it and let me know if I did > not write it well, I would appreciate the feedback > > Here's the question text: > ------------------------ > I'm writing a metaclass to do some cool stuff, and part of its > processing is to check that certain attributes exist when the class is > created. Some of these are mutable, and would normally be set in > `__init__`, but since `__init__` isn't run until the instance is created > the metaclass won't know that the attribute *will* be created, and > raises an error. a. Create an instance and see if it has the attribute. Then delete it. b. Put such tests in unit tests. c. Check the code object to see if the attribute will be created. > I could do something like: > > class Test(meta=Meta): > mutable = None > def __init__(self): > self.mutable = list() > > But that isn't very elegant, and also violates DRY. It works. It is a standard idiom for default values that are conditionally masked with an instance value. > > What I need is some way to have: > > class Test(metaclass=Meta): > mutable = list() > > t1 = Test() > t2 = Test() > t1.mutable.append('one') > t2.mutable.append('two') > t1.mutable # prints ['one'] > t2.mutable # prints ['two'] > > Any ideas on how this can be accomplished? Rewrite the __init__ code object ;-). -- Terry Jan Reedy From steve+comp.lang.python at pearwood.info Fri Mar 9 19:57:50 2012 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 10 Mar 2012 00:57:50 GMT Subject: "Decoding unicode is not supported" in unusual situation References: <4f571b94$0$12037$742ec2ed@news.sonic.net> <8762egmzfp.fsf@benfinney.id.au> <4f5749bc$0$29989$c3e8da3$5496439d@news.astraweb.com> <4f57b63f$0$11986$742ec2ed@news.sonic.net> <871up4m69h.fsf@benfinney.id.au> <4f57eeac$0$29989$c3e8da3$5496439d@news.astraweb.com> <87sjhjltsp.fsf@benfinney.id.au> <4f593178$0$11963$742ec2ed@news.sonic.net> <4f5a47f0$0$11979$742ec2ed@news.sonic.net> Message-ID: <4f5aa70e$0$30002$c3e8da3$5496439d@news.astraweb.com> On Fri, 09 Mar 2012 10:11:58 -0800, John Nagle wrote: > On 3/8/2012 2:58 PM, Prasad, Ramit wrote: >>> Right. The real problem is that Python 2.7 doesn't have distinct >>> "str" and "bytes" types. type(bytes() returns "str" is >>> assumed to be ASCII 0..127, but that's not enforced. "bytes" and "str" >>> should have been distinct types, but that would have broken much old >>> code. If they were distinct, then constructors could distinguish >>> between string type conversion (which requires no encoding >>> information) and byte stream decoding. >>> >>> So it's possible to get junk characters in a "str", and they >>> won't convert to Unicode. I've had this happen with databases which >>> were supposed to be ASCII, but occasionally a non-ASCII character >>> would slip through. >> >> bytes and str are just aliases for each other. > > That's true in Python 2.7, but not in 3.x. From 2.6 forward, > "bytes" and "str" were slowly being separated. See PEP 358. Some of the > problems in Python 2.7 come from this ambiguity. Logically, "unicode" of > "str" should be a simple type conversion from ASCII to Unicode, while > "unicode" of "bytes" should require an encoding. But because of the > bytes/str ambiguity in Python 2.6/2.7, the behavior couldn't be > type-based. This demonstrates a gross confusion about both Unicode and Python. John, I honestly don't mean to be rude here, but if you actually believe that (rather than merely expressing yourself poorly), then it seems to me that you are desperately misinformed about Unicode and are working on the basis of some serious misapprehensions about the nature of strings. I recommend you start with this: http://www.joelonsoftware.com/articles/Unicode.html In Python 2.6/2.7, there is no ambiguity between str/bytes. The two names are aliases for each other. The older name, "str", is a misnomer, since it *actually* refers to bytes (and always has, all the way back to the earliest days of Python). At best, it could be read as "byte string" or "8-bit string", but the emphasis should always be on the *bytes*. str is NOT "assumed to be ASCII 0..127", and it never has been. Python's str prior to version 3.0 has *always* been bytes, it just never used that name. For example, in Python 2.4, help(chr) explicitly supports characters with ordinal 0...255: Help on built-in function chr in module __builtin__: chr(...) chr(i) -> character Return a string of one character with ordinal i; 0 <= i < 256. I can go all the way back to Python 0.9, which was so primitive it didn't even accept "" as string delimiters, and the str type was still based on bytes, with explicit support for non-ASCII values: steve at runes:~/Downloads/python-0.9.1$ ./python0.9.1 >>> print 'This is *not* ASCII \xCA see the non-ASCII byte.' This is *not* ASCII ? see the non-ASCII byte. Any conversion from bytes (including Python 2 strings) to Unicode is ALWAYS a decoding operation. It can't possibly be anything else. If you think that it can be, you don't understand the relationship between strings, Unicode and bytes. -- Steven From timr at probo.com Sat Mar 10 02:39:35 2012 From: timr at probo.com (Tim Roberts) Date: Fri, 09 Mar 2012 23:39:35 -0800 Subject: PyUSB available for current versions of Windows? References: <4f5a3b5f$0$11993$742ec2ed@news.sonic.net> Message-ID: John Nagle wrote: > I want to enumerate the available USB devices. All I really >need is the serial number of the USB devices available to PySerial. >... >(When you plug in a USB device on Windows, it's assigned the next >available COM port number. On a reboot, the numbers are reassigned. >So if you have multiple USB serial ports, there's a problem.) You can use the SetupDi APIs to enumerate the list of USB devices, but that won't tell you what COM port they were assigned to. You can look at the source code for USBView, which is available in the Windows driver kit. It can enumerate the hubs and ports and even fetch their descriptors (by talking to the USB hub and host controller drivers), but again it won't tell you what COM port was assigned. > PyUSB can supposedly do this, but the documentation is misleading. >It makes a big point of being "100% Python", but that's because it's >just glue code to a platform-specific "back end" provided by someone >else. Of course it is. You can't access devices in Windows without a kernel driver. > There's an old Windows back-end at >"http://www.craftedge.com/products/libusb.html", but it was written for >Windows XP, and can supposedly be run in "compatibility mode" on Windows >Vista. Current versions of Windows, who knows? It's not open source, and >it comes from someone who sells paper-cutting machines for crafters. It IS open source. They are shipping libusb-win32 -- exactly the same library you reference below. Until Microsoft released WinUSB, libusb-win32 was the ONLY generic USB driver available on Windows. It runs just fine on Windows 7. >There's another Windows back end at > https://sourceforge.net/apps/trac/libusb-win32/wiki >but it involves installing a low-level driver in Windows. It's the same backend. A driver is required in order to access devices on Windows. It's required on Linux as well, but Linux happens to include a generic USB driver in the kernel. A more modern generic USB driver and library is available at http://www.libusb.org. There is a Python binding for it. >I especially like the instruction "Close all applications which use USB >devices before installing." Does this include the keyboard and mouse? No, that's just being overly cautious. Libusb-Win32 can act as a filter driver, inserting itself into an existing USB stack, but to do so the device stack you are filtering must be idle. -- Tim Roberts, timr at probo.com Providenza & Boekelheide, Inc. From meerad41 at gmail.com Sat Mar 10 05:00:30 2012 From: meerad41 at gmail.com (meeradevi) Date: Sat, 10 Mar 2012 02:00:30 -0800 (PST) Subject: view this wonderful Message-ID: http://123maza.com/46/flower816/ From ejjyrex at gmail.com Sat Mar 10 05:21:46 2012 From: ejjyrex at gmail.com (ejjy) Date: Sat, 10 Mar 2012 02:21:46 -0800 (PST) Subject: steps to solve bugs Message-ID: Hi, I am currently learning python and I would like to solve some easy bugs for my own practice. I am confused over following the steps explained in the Python website, though I have the appropriate software necessities. Kindly some one please tell me in a more practical and easy way. Thanks. Regards, Ejaj From news at schwertberger.de Sat Mar 10 06:20:37 2012 From: news at schwertberger.de (Dietmar Schwertberger) Date: Sat, 10 Mar 2012 12:20:37 +0100 Subject: PyUSB available for current versions of Windows? In-Reply-To: <4f5a3b5f$0$11993$742ec2ed@news.sonic.net> References: <4f5a3b5f$0$11993$742ec2ed@news.sonic.net> Message-ID: Am 09.03.2012 18:18, schrieb John Nagle: > I want to enumerate the available USB devices. All I really > need is the serial number of the USB devices available to PySerial. > (When you plug in a USB device on Windows, it's assigned the next > available COM port number. On a reboot, the numbers are reassigned. > So if you have multiple USB serial ports, there's a problem.) You can get the required information using Windows Management Instrumentation (WMI). See e.g. here for serial port information: http://www.activexperts.com/admin/scripts/wmi/python/0358/ I'm using code like this to find my USB CDC devices from the device description: import win32com.client strComputer = "." objWMIService = win32com.client.Dispatch("WbemScripting.SWbemLocator") objSWbemServices = objWMIService.ConnectServer(strComputer,"root\cimv2") colItems = objSWbemServices.ExecQuery("SELECT Description,DeviceID FROM Win32_SerialPort") COM_ports = [] for objItem in colItems: print objItem.Description,objItem.DeviceID if objItem.Description == "USB CDC Simple IO HC9S08JSxx": COM_ports.append( objItem.DeviceID ) On some PCs the query took some seconds. Regards, Dietmar From ahsanbagwan at gmail.com Sat Mar 10 07:34:35 2012 From: ahsanbagwan at gmail.com (sl33k) Date: Sat, 10 Mar 2012 04:34:35 -0800 (PST) Subject: Invalid syntax error Message-ID: <46758542-1bd6-43fe-8e80-bcf14b7d88d8@pi6g2000pbc.googlegroups.com> I'm trying project euler problem 3 and I've hit the wall with this error. What could be the problem here? l=[] >>> num=600851475143 >>> i=1 >>> while i<=num: ... if num%i==0: ... l.append(i) ... i+=1 ... print max(l) File "", line 5 print max(l) ^ SyntaxError: invalid syntax From amit.pureenergy at gmail.com Sat Mar 10 07:43:01 2012 From: amit.pureenergy at gmail.com (Amit Sethi) Date: Sat, 10 Mar 2012 18:13:01 +0530 Subject: Invalid syntax error In-Reply-To: <46758542-1bd6-43fe-8e80-bcf14b7d88d8@pi6g2000pbc.googlegroups.com> References: <46758542-1bd6-43fe-8e80-bcf14b7d88d8@pi6g2000pbc.googlegroups.com> Message-ID: Its an indentation error -- A-M-I-T S|S From bahamutzero8825 at gmail.com Sat Mar 10 07:46:28 2012 From: bahamutzero8825 at gmail.com (Andrew Berg) Date: Sat, 10 Mar 2012 06:46:28 -0600 Subject: Invalid syntax error In-Reply-To: <46758542-1bd6-43fe-8e80-bcf14b7d88d8@pi6g2000pbc.googlegroups.com> References: <46758542-1bd6-43fe-8e80-bcf14b7d88d8@pi6g2000pbc.googlegroups.com> Message-ID: <4F5B4D24.5050108@gmail.com> On 3/10/2012 6:34 AM, sl33k wrote: > I'm trying project euler problem 3 and I've hit the wall with this > error. What could be the problem here? > > l=[] >>>> num=600851475143 >>>> i=1 >>>> while i<=num: > ... if num%i==0: > ... l.append(i) > ... i+=1 > ... print max(l) > File "", line 5 > print max(l) > ^ > SyntaxError: invalid syntax > > You must be using Python 3. Along with many, many other changes, Python 3 uses a print function instead of a print statement. If you want to follow along with the problems, use the version of Python it uses (2.7 is probably safe if there isn't a version specified). -- CPython 3.2.2 | Windows NT 6.1.7601.17640 From vlastimil.brom at gmail.com Sat Mar 10 07:54:02 2012 From: vlastimil.brom at gmail.com (Vlastimil Brom) Date: Sat, 10 Mar 2012 13:54:02 +0100 Subject: Invalid syntax error In-Reply-To: <46758542-1bd6-43fe-8e80-bcf14b7d88d8@pi6g2000pbc.googlegroups.com> References: <46758542-1bd6-43fe-8e80-bcf14b7d88d8@pi6g2000pbc.googlegroups.com> Message-ID: 2012/3/10 sl33k : > I'm trying project euler problem 3 and I've hit the wall with this > error. What could be the problem here? > > ?l=[] >>>> num=600851475143 >>>> i=1 >>>> while i<=num: > ... ? ? if num%i==0: > ... ? ? ? ? l.append(i) > ... ? ? i+=1 > ... print max(l) > ?File "", line 5 > ? ?print max(l) > ? ? ? ?^ > SyntaxError: invalid syntax > > > -- > http://mail.python.org/mailman/listinfo/python-list Hi, if you are using python 3, you'd (most likely) need to adapt the code written for python 2. see: http://docs.python.org/py3k/whatsnew/3.0.html#print-is-a-function hth, vbr From liuerfire at gmail.com Sat Mar 10 08:00:22 2012 From: liuerfire at gmail.com (liuerfire Wang) Date: Sat, 10 Mar 2012 05:00:22 -0800 (PST) Subject: Invalid syntax error In-Reply-To: <46758542-1bd6-43fe-8e80-bcf14b7d88d8@pi6g2000pbc.googlegroups.com> References: <46758542-1bd6-43fe-8e80-bcf14b7d88d8@pi6g2000pbc.googlegroups.com> Message-ID: <19487693.1432.1331384422933.JavaMail.geo-discussion-forums@pbcgj3> ? 2012?3?10????UTC+8??8?34?35??sl33k??? > I'm trying project euler problem 3 and I've hit the wall with this > error. What could be the problem here? > > l=[] > >>> num=600851475143 > >>> i=1 > >>> while i<=num: > ... if num%i==0: > ... l.append(i) > ... i+=1 > ... print max(l) > File "", line 5 > print max(l) > ^ > SyntaxError: invalid syntax It is a indentation error. It should be like: >>> while i<=num: ... if num%i==0: ... l.append(i) ... i+=1 ... >>> print max(l) From ahsanbagwan at gmail.com Sat Mar 10 08:00:35 2012 From: ahsanbagwan at gmail.com (Ahsan) Date: Sat, 10 Mar 2012 18:30:35 +0530 Subject: Invalid syntax error In-Reply-To: References: <46758542-1bd6-43fe-8e80-bcf14b7d88d8@pi6g2000pbc.googlegroups.com> Message-ID: Just checked my version. Its showing 2.6.5. >>> sys.version '2.6.5 (r265:79063, Apr 16 2010, 13:09:56) \n[GCC 4.4.3]' -------------- next part -------------- An HTML attachment was scrubbed... URL: From sam.drpython at gmail.com Sat Mar 10 08:10:01 2012 From: sam.drpython at gmail.com (Sam Sam) Date: Sat, 10 Mar 2012 18:40:01 +0530 Subject: No subject Message-ID: How to change the color of source browser in DrPython? -------------- next part -------------- An HTML attachment was scrubbed... URL: From gd.usenet at spamfence.net Sat Mar 10 08:17:06 2012 From: gd.usenet at spamfence.net (=?ISO-8859-1?Q?G=FCnther?= Dietrich) Date: Sat, 10 Mar 2012 14:17:06 +0100 Subject: Invalid syntax error References: <46758542-1bd6-43fe-8e80-bcf14b7d88d8@pi6g2000pbc.googlegroups.com> Message-ID: In article <46758542-1bd6-43fe-8e80-bcf14b7d88d8 at pi6g2000pbc.googlegroups.com>, sl33k wrote: >I'm trying project euler problem 3 and I've hit the wall with this >error. What could be the problem here? > > l=[] >>>> num=600851475143 >>>> i=1 >>>> while i<=num: >... if num%i==0: >... l.append(i) >... i+=1 >... print max(l) > File "", line 5 > print max(l) > ^ >SyntaxError: invalid syntax You have to insert an empty line after the end of the while loop (before the print command), so that the interpreter can run and finish the loop before it is to print the result. Best regards, G?nther From jpwagner at mweb.co.za Sat Mar 10 08:20:50 2012 From: jpwagner at mweb.co.za (Johannes Wagner) Date: Sat, 10 Mar 2012 15:20:50 +0200 Subject: nmea Message-ID: can any1 help me on how to get python to read nmea data? From awilliam at whitemice.org Sat Mar 10 08:36:03 2012 From: awilliam at whitemice.org (Adam Tauno Williams) Date: Sat, 10 Mar 2012 08:36:03 -0500 Subject: Can't get around HTTP/401 response using SUDS [SOLVED] In-Reply-To: <4F593AAC.30604@gmail.com> References: <1331221455.3087.14.camel@linux-dauq.site> <4F593AAC.30604@gmail.com> Message-ID: <1331386563.3103.3.camel@linux-dauq.site> On Fri, 2012-03-09 at 00:03 +0100, Rafael Dur?n Casta?eda wrote: > El 08/03/12 16:44, Adam Tauno Williams escribi?: > > SUDS version 0.4 pn x86_64 Python 2.7 > > I'm having a bear of a time getting HTTP Basic Authentication to work > > for a SOAP request via suds. Also using an HTTP proxy server. > > In WireShark I just see a request - > > GET http://...../services/services/JobService-0.0.1?wsdl HTTP/1.1 > > Accept-Encoding: identity > > Host: ....... > > Connection: close > > User-Agent: Python-urllib/2.7 > > This doesn't contain any authentication credentials so the response is > > HTTP/401, and the client doesn't retry with credentials. The response > > does come from the remote as I can see there is a WWW-Authenticate > > header and it is from an Apache Tomcat server - so it makes it through > > the proxy server. > > Code > > ================ > > url = 'http://....../services/services/JobService-0.0.1?wsdl' > > proxy = urllib2.ProxyHandler({'http': 'http://.....:3128'}) > > transport = suds.transport.http.HttpAuthenticated() > > transport.urlopener = urllib2.build_opener(proxy) > > client = suds.client.Client(url, transport=transport, > > username='******', password='********') > > .... > > "/usr/local/lib/python2.7/site-packages/suds-0.4-py2.7.egg/suds/transport/http.py", line 64, in open > > raise TransportError(str(e), e.code, e.fp) > > suds.transport.TransportError: HTTP Error 401: Unauthorized > When I've got issues like yours, I usually try using a console client > (telnet/curl/wget,...) adding all needed headers/data manually so I'm > totally sure the request is OK, if everything goes Ok you know your > python code need to be reviewed but when you are under proxies you can > find a lot of not python related issues (bad gateways, using proxy when > it shouldn't or vice-versa, requests changed by proxy,....). Nope, proxy works perfectly [for hundreds of clients]. The problem turned out to be that SUDS uses the specified transport for SOAP requests/operations. When requesting the WSDL in order to built the client interface it doesn't use the transport. So either download the service description to a local file and use that or just use urllib2 to retrieve the WSDL to a buffer (outside of SUDS). Once the client is created the requests work with authentication and via the proxy with no issues. > wireshark can be very useful but in situations like this I usually > prefer tcpflow output, I think the request/response flow showed is > really useful, but that's a personal preference. Wireshark does the same thing; you just select a packet in the stream and then select "follow conversation". -- System & Network Administrator [ LPI & NCLA ] OpenGroupware Developer Adam Tauno Williams From roy at panix.com Sat Mar 10 09:05:24 2012 From: roy at panix.com (Roy Smith) Date: Sat, 10 Mar 2012 09:05:24 -0500 Subject: nmea References: Message-ID: In article , "Johannes Wagner" wrote: > can any1 help me on how to get python to read nmea data? I assume you're talking about National Marine Electronics Association, i.e. the protocol GPSs use to talk to plotters and the like? A quick google search for "nmea python" found a bunch of good hits. This one looks like it's probably where you want to start. http://blog.scaryclam.co.uk/2011/07/22/pynmea-a-python-nmea-library/ From gelonida at gmail.com Sat Mar 10 09:48:48 2012 From: gelonida at gmail.com (Gelonida N) Date: Sat, 10 Mar 2012 15:48:48 +0100 Subject: How to know that two pyc files contain the same code Message-ID: Hi, I want to know whether two .pyc files are identical. With identical I mean whether they contain the same byte code. Unfortunately it seems, that .pyc files contain also something like the time stamp of the related source file. So though two pyc files contain the same byte code, they will not be byte identical. One option, that I found is to use python -m unpyclib.application -d filename.pyc and check whether the results are identical. However even this will fail if the files were not compiled under the same absolute path name as the source filename is contained twice (at least for my trivial example) in the disassemblers output. Thanks a lot for any other idea. From gelonida at gmail.com Sat Mar 10 09:49:36 2012 From: gelonida at gmail.com (Gelonida N) Date: Sat, 10 Mar 2012 15:49:36 +0100 Subject: How to know that two pyc files contain the same code Message-ID: Hi, I want to know whether two .pyc files are identical. With identical I mean whether they contain the same byte code. Unfortunately it seems, that .pyc files contain also something like the time stamp of the related source file. So though two pyc files contain the same byte code, they will not be byte identical. One option, that I found is to use python -m unpyclib.application -d filename.pyc and check whether the results are identical. However even this will fail if the files were not compiled under the same absolute path name as the source filename is contained twice (at least for my trivial example) in the disassemblers output. Thanks a lot for any other idea. From bl0ckedusersoft at gmail.com Sat Mar 10 10:08:18 2012 From: bl0ckedusersoft at gmail.com (Bl0ckeduser) Date: Sat, 10 Mar 2012 10:08:18 -0500 Subject: How to know that two pyc files contain the same code In-Reply-To: References: Message-ID: Gelonida N wrote: > Hi, > > I want to know whether two .pyc files are identical. > > With identical I mean whether they contain the same byte code. > > Unfortunately it seems, that .pyc files contain also something like the > time stamp of the related source file. > > So though two pyc files contain the same byte code, they will not be > byte identical. > > One option, that I found is to use > python -m unpyclib.application -d filename.pyc and check whether the > results are identical. > > > However even this will fail if the files were not compiled under the > same absolute path name as the source filename is contained twice (at > least for my trivial example) in the disassemblers output. > > > Thanks a lot for any other idea. > Try using the disassembler code here: http://nedbatchelder.com/blog/200804/the_structure_of_pyc_files.html and removing from it the parts which print out the timestamp and the absolute path. (Two different lines in the source). That seems to work for me. From __peter__ at web.de Sat Mar 10 11:21:00 2012 From: __peter__ at web.de (Peter Otten) Date: Sat, 10 Mar 2012 17:21 +0100 Subject: How to know that two pyc files contain the same code References: Message-ID: Gelonida N wrote: > I want to know whether two .pyc files are identical. > > With identical I mean whether they contain the same byte code. > > Unfortunately it seems, that .pyc files contain also something like the > time stamp of the related source file. > > So though two pyc files contain the same byte code, they will not be > byte identical. > > One option, that I found is to use > python -m unpyclib.application -d filename.pyc and check whether the > results are identical. Or you could just strip off the first 8 (may be version-dependent) bytes before you compare the file contents. > However even this will fail if the files were not compiled under the > same absolute path name as the source filename is contained twice (at > least for my trivial example) in the disassemblers output. That's another problem. If you are OK with likelihood you can replace the filename of the old code with that of the new one before you compare. From ethan at stoneleaf.us Sat Mar 10 11:56:58 2012 From: ethan at stoneleaf.us (Ethan Furman) Date: Sat, 10 Mar 2012 08:56:58 -0800 Subject: stackoverflow question In-Reply-To: References: <4F5A7FCA.6030109@stoneleaf.us> Message-ID: <4F5B87DA.5040401@stoneleaf.us> Terry Reedy wrote: Thanks for the review, Terry! > On 3/9/2012 5:10 PM, Ethan Furman wrote: >> >> http://stackoverflow.com/q/9638921/208880 >> >> If anyone here is willing to take a look at it and let me know if I did >> not write it well, I would appreciate the feedback >> >> Here's the question text: >> ------------------------ >> I'm writing a metaclass to do some cool stuff, and part of its >> processing is to check that certain attributes exist when the class is >> created. Some of these are mutable, and would normally be set in >> `__init__`, but since `__init__` isn't run until the instance is created >> the metaclass won't know that the attribute *will* be created, and >> raises an error. > > a. Create an instance and see if it has the attribute. Then delete it. If the class takes any arguments, I won't be able to create instances of it. > b. Put such tests in unit tests. Always a good idea -- but this is the responsibility of the class author (who may not be me ;). > c. Check the code object to see if the attribute will be created. I have no idea how to do this -- pointers? >> I could do something like: >> >> class Test(meta=Meta): >> mutable = None >> def __init__(self): >> self.mutable = list() >> >> But that isn't very elegant, and also violates DRY. > > It works. It is a standard idiom for default values that are > conditionally masked with an instance value. >> >> What I need is some way to have: >> >> class Test(metaclass=Meta): >> mutable = list() >> >> t1 = Test() >> t2 = Test() >> t1.mutable.append('one') >> t2.mutable.append('two') >> t1.mutable # prints ['one'] >> t2.mutable # prints ['two'] >> >> Any ideas on how this can be accomplished? > > Rewrite the __init__ code object ;-). Ouch. Can that be done in a cross-implementation way? Any pointers? Still, I'm not sure I'd want to go this route, anyway, as it makes it more difficult to get an actual class-wide mutable (rare though they are). Thanks again for your feedback, I really appreciate it. ~Ethan~ From ian.g.kelly at gmail.com Sat Mar 10 12:07:08 2012 From: ian.g.kelly at gmail.com (Ian Kelly) Date: Sat, 10 Mar 2012 10:07:08 -0700 Subject: Invalid syntax error In-Reply-To: References: <46758542-1bd6-43fe-8e80-bcf14b7d88d8@pi6g2000pbc.googlegroups.com> Message-ID: On Sat, Mar 10, 2012 at 6:17 AM, G?nther Dietrich wrote: > In article > <46758542-1bd6-43fe-8e80-bcf14b7d88d8 at pi6g2000pbc.googlegroups.com>, > ?sl33k wrote: > >>I'm trying project euler problem 3 and I've hit the wall with this >>error. What could be the problem here? >> >> l=[] >>>>> num=600851475143 >>>>> i=1 >>>>> while i<=num: >>... ? ? if num%i==0: >>... ? ? ? ? l.append(i) >>... ? ? i+=1 >>... print max(l) >> ?File "", line 5 >> ? ?print max(l) >> ? ? ? ?^ >>SyntaxError: invalid syntax > > You have to insert an empty line after the end of the while loop (before > the print command), so that the interpreter can run and finish the loop > before it is to print the result. Note that this only applies to the interactive interpreter, to help it identify when to terminate the block and pass on to the compiler. When running a script, the extra blank lines are unnecessary, and indentation alone identifies the blocks. From meerad41 at gmail.com Sat Mar 10 12:36:54 2012 From: meerad41 at gmail.com (meeradevi) Date: Sat, 10 Mar 2012 09:36:54 -0800 (PST) Subject: fetching pretty girls world Message-ID: http://123maza.com/46/flower816/ From cjw at ncf.ca Sat Mar 10 12:58:55 2012 From: cjw at ncf.ca (Colin J. Williams) Date: Sat, 10 Mar 2012 12:58:55 -0500 Subject: newb __init__ inheritance In-Reply-To: <1c6db866-6fa3-4de5-96de-51d6720a1300@x17g2000yqj.googlegroups.com> References: <1c6db866-6fa3-4de5-96de-51d6720a1300@x17g2000yqj.googlegroups.com> Message-ID: On 08/03/2012 10:25 AM, hyperboogie wrote: > Hello everyone. > > This is my first post in this group. > I started learning python a week ago from the "dive into python" e- > book and thus far all was clear. > However today while reading chapter 5 about objects and object > orientation I ran into something that confused me. > it says here: > http://www.diveintopython.net/object_oriented_framework/defining_classes.html#fileinfo.class.example > > "__init__ methods are optional, but when you define one, you must > remember to explicitly call the ancestor's __init__ method (if it > defines one). This is more generally true: whenever a descendant wants > to extend the behavior of the ancestor, the descendant method must > explicitly call the ancestor method at the proper time, with the > proper arguments. " > > However later on in the chapter: > http://www.diveintopython.net/object_oriented_framework/userdict.html > > it says: > "Methods are defined solely by their name, and there can be only one > method per class with a given name. So if a descendant class has an > __init__ method, it always overrides the ancestor __init__ method, > even if the descendant defines it with a different argument list. And > the same rule applies to any other method. " > > My question is if __init__ in the descendant class overrides __init__ > in the parent class how can I call the parent's __init__ from the > descendant class - I just overrode it didn't I? > > Am I missing something more fundamental here? > Thanks The mro function [Method Resolution Order]is not too well advertised in the docs. This should illustrate its usage: #!/usr/bin/env python class A(): def __init__(self): z= 1 def ringA(self): print ('aaa') def ringB(self): print('bbb') class B(A): def __init__(self): z= 2 def ringB(self): print('BBB') a= A() b= B() b.ringB() b.ringA() b.__class__.mro()[1].ringB(b) z= 1 def main(): pass if __name__ == '__main__': main() I'm not sure that the class initialization is required. Good luck, Colin W. From tjreedy at udel.edu Sat Mar 10 13:00:03 2012 From: tjreedy at udel.edu (Terry Reedy) Date: Sat, 10 Mar 2012 13:00:03 -0500 Subject: stackoverflow question In-Reply-To: <4F5B87DA.5040401@stoneleaf.us> References: <4F5A7FCA.6030109@stoneleaf.us> <4F5B87DA.5040401@stoneleaf.us> Message-ID: <4F5B96A3.2010906@udel.edu> On 3/10/2012 11:56 AM, Ethan Furman wrote: >>> I'm writing a metaclass to do some cool stuff, and part of its >>> processing is to check that certain attributes exist when the class is >>> created. Some of these are mutable, and would normally be set in >>> `__init__`, but since `__init__` isn't run until the instance is created >>> the metaclass won't know that the attribute *will* be created, and >>> raises an error. >> c. Check the code object to see if the attribute will be created. > > I have no idea how to do this -- pointers? Capture output of dis.dis(targetclass.__init__) by temporarily setting sys.stdout to StringIO object. (There is tracker issue to make lines available to a program without doing this.) >>> from dis import dis >>> def f(self): self.attr = 1 >>> dis(f) 2 0 LOAD_CONST 1 (1) 3 LOAD_FAST 0 (self) 6 STORE_ATTR 0 (attr) 9 LOAD_CONST 0 (None) 12 RETURN_VALUE Look for STORE_ATTR line with target attribute name. If you want to check for wacko code that does setattr(self, 'attr', value), try it in 'f' and dis again. Anything to do with code objects (and dis module) is implementation and version specific --- Terry Jan Reedy From miki.tebeka at gmail.com Sat Mar 10 13:27:17 2012 From: miki.tebeka at gmail.com (Miki Tebeka) Date: Sat, 10 Mar 2012 10:27:17 -0800 (PST) Subject: steps to solve bugs In-Reply-To: References: Message-ID: <2972152.114.1331404037861.JavaMail.geo-discussion-forums@ynll40> Greetings, > I am confused over following the steps > explained in the Python website, Are you talking about http://docs.python.org/devguide/? > Kindly some one please tell me in a more > practical and easy way. Can you tell in more details what are the problems you face? This will help us help you more. All the best, -- Miki From cosmius at gmail.com Sat Mar 10 14:33:36 2012 From: cosmius at gmail.com (Cosmia Luna) Date: Sat, 10 Mar 2012 11:33:36 -0800 (PST) Subject: How to re-implement the crypt.crypt function? Message-ID: <28304124.1374.1331408016748.JavaMail.geo-discussion-forums@yncd8> I'm not searching for a full solution and only want to know how to use hashlib to create a equivalent string like crypt.crypt('123456', '$6$ds41p/9VMA.BHH0U') returns the string below. '$6$ds41p/9VMA.BHH0U$yv25s7jLxTRKLDNjIvT0Qc2jbcqdFRi5.PftO3cveTvjK49JhwCarIowOfrrNPD/PpYT3n6oNDIbjAONh8RXt1' I tried: from hashlib import sha512 from base64 import b64encode, b64decode salt='ds41p/9VMA.BHH0U' pwd='123456' b64encode( sha512(pwd+salt).digest(), altchars='./' ) b64encode( sha512(salt+pwd).digest(), altchars='./' ) b64encode( sha512( pwd + b64decode(salt, altchars='./') ).digest(), altchars='./') b64encode( sha512( b64decode(salt, altchars='./') + pwd ).digest(), altchars='./') of course none of the four returns the value I want, 'yv25s7jLxTRKLDNjIvT0Qc2jbcqdFRi5.PftO3cveTvjK49JhwCarIowOfrrNPD/PpYT3n6oNDIbjAONh8RXt1', how can I get the value? I can't use crypt.crypt because of the consideration of cross-platform. Thanks, Cosmia From angrybaldguy at gmail.com Sat Mar 10 15:03:25 2012 From: angrybaldguy at gmail.com (Owen Jacobson) Date: Sat, 10 Mar 2012 15:03:25 -0500 Subject: stackoverflow question References: Message-ID: <2012031015032562036-angrybaldguy@gmailcom> On 2012-03-09 22:10:18 +0000, Ethan Furman said: > Hey all! > > I posted a question/answer on SO earlier, but there seems to be some > confusion around either the question or the answer (judging from the > comments). > > http://stackoverflow.com/q/9638921/208880 > > If anyone here is willing to take a look at it and let me know if I did > not write it well, I would appreciate the feedback. > > > Here's the question text: > ------------------------ > I'm writing a metaclass to do some cool stuff, and part of its > processing is to check that certain attributes exist when the class is > created. Some of these are mutable, and would normally be set in > `__init__`, but since `__init__` isn't run until the instance is > created the metaclass won't know that the attribute *will* be created, > and raises an error. I could do something like: > > class Test(meta=Meta): > mutable = None > def __init__(self): > self.mutable = list() > > But that isn't very elegant, and also violates DRY. > > What I need is some way to have: > > class Test(metaclass=Meta): > mutable = list() > > t1 = Test() > t2 = Test() > t1.mutable.append('one') > t2.mutable.append('two') > t1.mutable # prints ['one'] > t2.mutable # prints ['two'] > > Any ideas on how this can be accomplished? > > Also, the metaclass doing the checking doesn't care what type of object > the attribute is, only that it is there. > --------------------------- Why check what you can ensure? The __init__ function your metaclass passes to type() doesn't have to be the __init__ method your metaclass received. Consider the following: >>> import functools as f >>> >>> def make_init(real_init): >>> """Define an __init__ method that ensures ``self.mutable`` is set. If the >>> passed ``real_init`` function later replaces ``self.mutable``, that value >>> is preserved; otherwise, ``self.mutable`` is set to a new, empty list. >>> >>> Arguments to the generated ``__init__`` method are passed to the original >>> ``real_init`` unchanged. >>> """ >>> def __init__(self, *args, **kwargs): >>> self.mutable = list() >>> if real_init is not None: >>> return real_init(self, *args, **kwargs) >>> if real_init is not None: >>> f.update_wrapper(__init__, real_init) >>> return __init__ >>> >>> class Meta(type): >>> def __new__(meta, name, parents, attributes): >>> attributes['__init__'] = make_init(attributes.get('__init__', None)) >>> return type.__new__(Meta, name, parents, attributes) >>> >>> class C(object): >>> __metaclass__ = Meta >>> >>> a, b = C(), C() >>> >>> a.mutable.append(3) >>> b.mutable.append(5) >>> >>> a.mutable [3] >>> b.mutable [5] All instances of classes whose metaclass is Meta will, guaranteed, have an instance field named 'mutable'. Its value is a list created at instance creation time, unless the instance's __init__ provides a different value. What've I missed? -o From roy at panix.com Sat Mar 10 15:15:46 2012 From: roy at panix.com (Roy Smith) Date: Sat, 10 Mar 2012 15:15:46 -0500 Subject: How to re-implement the crypt.crypt function? References: <28304124.1374.1331408016748.JavaMail.geo-discussion-forums@yncd8> Message-ID: In article <28304124.1374.1331408016748.JavaMail.geo-discussion-forums at yncd8>, Cosmia Luna wrote: > I'm not searching for a full solution and only want to know how to use > hashlib to create a equivalent string like > > crypt.crypt('123456', '$6$ds41p/9VMA.BHH0U') returns the string below. > > '$6$ds41p/9VMA.BHH0U$yv25s7jLxTRKLDNjIvT0Qc2jbcqdFRi5.PftO3cveTvjK49JhwCarIowO > frrNPD/PpYT3n6oNDIbjAONh8RXt1' > [...] > I can't use crypt.crypt because of the > consideration of cross-platform. Just out of curiosity, why do you want to do this? The python crypt module uses the crypt library supplied by the operating system (which is why it only works on unix). The algorithm implemented is a modification of DES, i.e. a salt string is used to change some of the tables used in the DES computation. It goes back to the ancient days of unix. By today's standards, the algorithm isn't considered very strong. The only place I'm aware that uses it is unix password files, and even there many (most?) systems have replaced it with something stronger such as SHA1. Maybe Apache .htaccess files? I don't know what your use case is, but unless you're doing something silly like trying to execute a dictionary attack against a unix password file, it's almost certain that you'd do better to just use SHA1. From lists at cheimes.de Sat Mar 10 15:16:52 2012 From: lists at cheimes.de (Christian Heimes) Date: Sat, 10 Mar 2012 21:16:52 +0100 Subject: How to re-implement the crypt.crypt function? In-Reply-To: <28304124.1374.1331408016748.JavaMail.geo-discussion-forums@yncd8> References: <28304124.1374.1331408016748.JavaMail.geo-discussion-forums@yncd8> Message-ID: Am 10.03.2012 20:33, schrieb Cosmia Luna: > I'm not searching for a full solution and only want to know how to use hashlib to create a equivalent string like If you chance your mind and choose to use a full solution, then I highly recommend passlib [1]. It has an implementation of SHA-512 crypt as indicated by the number 6 in the header of your string. By the way "$6$ds41p/9VMA.BHH0U" is *not* the salt. Just "ds41p/9VMA.BHH0U" is the salt, 6 is a hash identifier. Christian [1] http://packages.python.org/passlib/ From lists at cheimes.de Sat Mar 10 15:36:42 2012 From: lists at cheimes.de (Christian Heimes) Date: Sat, 10 Mar 2012 21:36:42 +0100 Subject: How to re-implement the crypt.crypt function? In-Reply-To: References: <28304124.1374.1331408016748.JavaMail.geo-discussion-forums@yncd8> Message-ID: Am 10.03.2012 21:15, schrieb Roy Smith: > By today's standards, the algorithm isn't considered very strong. The > only place I'm aware that uses it is unix password files, and even there > many (most?) systems have replaced it with something stronger such as > SHA1. Maybe Apache .htaccess files? The algorithm with identifier 6 is a SHA-512 crypt algorithm with a lengthy salt (IIRC up to 1024 bits) and 40,000 rounds of SHA-512. It's the default algorithm on modern Linux machines and believed to be very secure. The large salt makes a rainbow table attack impossible and the 40,000 rounds require a lot of CPU time, even on modern systems. Christian From roy at panix.com Sat Mar 10 15:41:12 2012 From: roy at panix.com (Roy Smith) Date: Sat, 10 Mar 2012 15:41:12 -0500 Subject: How to re-implement the crypt.crypt function? References: <28304124.1374.1331408016748.JavaMail.geo-discussion-forums@yncd8> Message-ID: In article , Christian Heimes wrote: > Am 10.03.2012 21:15, schrieb Roy Smith: > > By today's standards, the algorithm isn't considered very strong. The > > only place I'm aware that uses it is unix password files, and even there > > many (most?) systems have replaced it with something stronger such as > > SHA1. Maybe Apache .htaccess files? > > The algorithm with identifier 6 is a SHA-512 crypt algorithm with a > lengthy salt (IIRC up to 1024 bits) and 40,000 rounds of SHA-512. It's > the default algorithm on modern Linux machines and believed to be very > secure. > > The large salt makes a rainbow table attack impossible and the 40,000 > rounds require a lot of CPU time, even on modern systems. But is that what crypt.crypt() does? I though it implemented the old-style triple-DES. From lists at cheimes.de Sat Mar 10 16:07:46 2012 From: lists at cheimes.de (Christian Heimes) Date: Sat, 10 Mar 2012 22:07:46 +0100 Subject: How to re-implement the crypt.crypt function? In-Reply-To: References: <28304124.1374.1331408016748.JavaMail.geo-discussion-forums@yncd8> Message-ID: Am 10.03.2012 21:41, schrieb Roy Smith: > But is that what crypt.crypt() does? I though it implemented the > old-style triple-DES. Python's crypt module is an interface to the OS' crypt() function. On some systems the crypt() function supports additional algorithms. You can read it up in the notes section of crypt(3): http://linux.die.net/man/3/crypt Christian From ethan at stoneleaf.us Sat Mar 10 17:21:55 2012 From: ethan at stoneleaf.us (Ethan Furman) Date: Sat, 10 Mar 2012 14:21:55 -0800 Subject: stackoverflow question In-Reply-To: <2012031015032562036-angrybaldguy@gmailcom> References: <2012031015032562036-angrybaldguy@gmailcom> Message-ID: <4F5BD403.8080709@stoneleaf.us> Owen Jacobson wrote: > On 2012-03-09 22:10:18 +0000, Ethan Furman said: > >> Hey all! >> >> I posted a question/answer on SO earlier, but there seems to be some >> confusion around either the question or the answer (judging from the >> comments). >> >> http://stackoverflow.com/q/9638921/208880 >> >> If anyone here is willing to take a look at it and let me know if I >> did not write it well, I would appreciate the feedback. >> >> >> Here's the question text: >> ------------------------ >> I'm writing a metaclass to do some cool stuff, and part of its >> processing is to check that certain attributes exist when the class is >> created. Some of these are mutable, and would normally be set in >> `__init__`, but since `__init__` isn't run until the instance is >> created the metaclass won't know that the attribute *will* be created, >> and raises an error. I could do something like: >> >> class Test(meta=Meta): >> mutable = None >> def __init__(self): >> self.mutable = list() >> >> But that isn't very elegant, and also violates DRY. >> >> What I need is some way to have: >> >> class Test(metaclass=Meta): >> mutable = list() >> >> t1 = Test() >> t2 = Test() >> t1.mutable.append('one') >> t2.mutable.append('two') >> t1.mutable # prints ['one'] >> t2.mutable # prints ['two'] >> >> Any ideas on how this can be accomplished? >> >> Also, the metaclass doing the checking doesn't care what type of >> object the attribute is, only that it is there. >> --------------------------- > > Why check what you can ensure? The __init__ function your metaclass > passes to type() doesn't have to be the __init__ method your metaclass > received. Consider the following: > >>>> import functools as f >>>> >>>> def make_init(real_init): >>>> """Define an __init__ method that ensures ``self.mutable`` is >>>> set. If the >>>> passed ``real_init`` function later replaces ``self.mutable``, >>>> that value >>>> is preserved; otherwise, ``self.mutable`` is set to a new, empty >>>> list. >>>> >>>> Arguments to the generated ``__init__`` method are passed to the >>>> original >>>> ``real_init`` unchanged. >>>> """ >>>> def __init__(self, *args, **kwargs): >>>> self.mutable = list() >>>> if real_init is not None: >>>> return real_init(self, *args, **kwargs) >>>> if real_init is not None: >>>> f.update_wrapper(__init__, real_init) >>>> return __init__ >>>> >>>> class Meta(type): >>>> def __new__(meta, name, parents, attributes): >>>> attributes['__init__'] = >>>> make_init(attributes.get('__init__', None)) >>>> return type.__new__(Meta, name, parents, attributes) >>>> >>>> class C(object): >>>> __metaclass__ = Meta >>>> >>>> a, b = C(), C() >>>> >>>> a.mutable.append(3) >>>> b.mutable.append(5) >>>> >>>> a.mutable > [3] >>>> b.mutable > [5] > > All instances of classes whose metaclass is Meta will, guaranteed, have > an instance field named 'mutable'. Its value is a list created at > instance creation time, unless the instance's __init__ provides a > different value. The idea is good. The devil is in the details, as usual. How is the metaclass going to know: 1) which attributes to replace 2) what to replace them with? ~Ethan~ From cjw at ncf.ca Sat Mar 10 17:47:41 2012 From: cjw at ncf.ca (Colin J. Williams) Date: Sat, 10 Mar 2012 17:47:41 -0500 Subject: newb __init__ inheritance In-Reply-To: References: <1c6db866-6fa3-4de5-96de-51d6720a1300@x17g2000yqj.googlegroups.com> Message-ID: On 10/03/2012 12:58 PM, Colin J. Williams wrote: > On 08/03/2012 10:25 AM, hyperboogie wrote: >> Hello everyone. >> [snip] > main() > I'm not sure that the class initialization is required. > > Good luck, > > Colin W. When I wrote earlier, I wondered about the need for initialization. With Version 2, both __new__ and __init__ were required, not in the example below, using version 3.2: #!/usr/bin/env python class A(): def ringA(self): print ('aaa') def ringB(self): print('bbb') class B(A): def __init__(self:) def ringB(self): print('BBB') a= A() b= B() b.ringB() b.ringA() b.__class__.mro()[0].ringB(22) # 22 is used for the ringB attribute # Trial and error shows that any # non-Null,including None for the # argument gives the same result z= 1 def main(): pass if __name__ == '__main__': main() Colin W. From steve+comp.lang.python at pearwood.info Sat Mar 10 17:52:04 2012 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 10 Mar 2012 22:52:04 GMT Subject: How to know that two pyc files contain the same code References: Message-ID: <4f5bdb14$0$29891$c3e8da3$5496439d@news.astraweb.com> On Sat, 10 Mar 2012 15:48:48 +0100, Gelonida N wrote: > Hi, > > I want to know whether two .pyc files are identical. > > With identical I mean whether they contain the same byte code. Define "identical" and "the same". If I compile these two files: # file ham.py x = 23 def func(): a = 23 return a + 19 # file = spam.py def func(): return 42 tmp = 19 x = 4 + tmp del tmp do you expect spam.pyc and ham.pyc to count as "the same"? -- Steven From hniksic at xemacs.org Sat Mar 10 20:03:47 2012 From: hniksic at xemacs.org (Hrvoje Niksic) Date: Sun, 11 Mar 2012 02:03:47 +0100 Subject: Porting the 2-3 heap data-structure library from C to Python References: <87boo89zul.fsf@xemacs.org> Message-ID: <87399gne30.fsf@xemacs.org> Stefan Behnel writes: >> which is the standard way of extending Python with high-performance >> (and/or system-specific) C code. > > Well, it's *one* way. Certainly not the easiest way, neither the most > portable and you'll have a hard time making it the fastest. I didn't say it was easy, but standard, in the sense of documented in Python documentation. Python/C is as portable as Python itself, and as fast as the platform allows. I understand your desire to promote Cython, but please stop resorting to FUD in doing so. From rosuav at gmail.com Sat Mar 10 20:15:11 2012 From: rosuav at gmail.com (Chris Angelico) Date: Sun, 11 Mar 2012 12:15:11 +1100 Subject: How to know that two pyc files contain the same code In-Reply-To: <4f5bdb14$0$29891$c3e8da3$5496439d@news.astraweb.com> References: <4f5bdb14$0$29891$c3e8da3$5496439d@news.astraweb.com> Message-ID: On Sun, Mar 11, 2012 at 9:52 AM, Steven D'Aprano wrote: > On Sat, 10 Mar 2012 15:48:48 +0100, Gelonida N wrote: > Define "identical" and "the same". > > If I compile these two files: > > > # file ham.py > x = 23 > def func(): > ? ?a = 23 > ? ?return a + 19 > > > > # file = spam.py > def func(): > ? ?return 42 > > tmp = 19 > x = 4 + tmp > del tmp > > > do you expect spam.pyc and ham.pyc to count as "the same"? They do not contain the same code. They may contain code which has the same effect, but it is not the same code. I don't think Python has the level of aggressive optimization that would make these compile to the same bytecode, but if it did, then they would _become identical_ per the OP's description - that they contain identical bytecode. In fact, I think the OP defined it quite clearly. ChrisA From tjreedy at udel.edu Sat Mar 10 21:17:06 2012 From: tjreedy at udel.edu (Terry Reedy) Date: Sat, 10 Mar 2012 21:17:06 -0500 Subject: Porting the 2-3 heap data-structure library from C to Python In-Reply-To: <87399gne30.fsf@xemacs.org> References: <87boo89zul.fsf@xemacs.org> <87399gne30.fsf@xemacs.org> Message-ID: On 3/10/2012 8:03 PM, Hrvoje Niksic wrote: > Stefan Behnel writes: > >>> which is the standard way of extending Python with high-performance >>> (and/or system-specific) C code. >> >> Well, it's *one* way. Certainly not the easiest way, neither the most >> portable and you'll have a hard time making it the fastest. > > I didn't say it was easy, but standard, in the sense of documented in > Python documentation. Python/C is as portable as Python itself, and as Python is portable because a *lot* of work has gone and continues to go into making it so. And because it sticks with the lowest common denominator of C89. There is much system or compiler specific code in #ifdefs. There are over 60 buildbots for testing patches on various hardware-os-compiler-(python)version combinations. Perhaps once a week something does not work on one of them. The patch gets revised. It happened just today. Apple is changing compilers for the Mac; Python initially did not build with the new compiler. Some people had to do some work so there would continue to be Python on the Mac. So I can imagine that Cython *might* shield one from some of the very real portability problems. > fast as the platform allows. I understand your desire to promote > Cython, but please stop resorting to FUD in doing so. You admitted it might be easier. Portability is plausible. So I think that a bit harsh. -- Terry Jan Reedy From jpokorny at redhat.com Sat Mar 10 21:29:55 2012 From: jpokorny at redhat.com (Jan =?iso-8859-1?Q?Pokorn=FD?=) Date: Sun, 11 Mar 2012 03:29:55 +0100 Subject: [RFC] PEP 3143: supplementary group list concerns Message-ID: <20120311022955.GA31434@redhat.com> Hello, in the light of a recent spot in Python Paste [1], I've come across the python-daemon [2] implementation and found it also lacks support for supplementary groups. First, I just wanted to post a patch to the author, but realized the broader context of PEP 3143 that would probably deserve revisiting at the first place. As the target Python version seems not to be decided yet, I see a space for it. If the spirit of solution [2] was to be followed (i.e., initialize this list with all groups of which user derived from `uid` is a member + group derived from `gid` (regardless if `uid`/`gid` is explicit), no change of the PEP would be necessary. This fact of intented handling of supplementary groups under the hood still could be mentioned so the users and authors of compatible interfaces are aware of this "detail". Another way (in the spirit of systemd [3]) is to extend the interface with an option (named, e.g., supplementary_groups) for optional specification of supplemental groups. The default would be something as in the previous paragraph. To be honest, I am not sure how consistently is the concept of supplementary groups used across various *nixes. POSIX seems to admit variances, e.g. (via [4]): ----v---- The System Interfaces volume of IEEE Std 1003.1-2001 does not specify whether the effective group ID of a process is included in its supplementary group list. ----^---- But I believe this should be addressed before the PEP in question is brought into effect. [2] http://groups.google.com/group/paste-users/browse_thread/thread/2aa651ba331c2471 [3] http://0pointer.de/public/systemd-man/systemd.exec.html [4] http://pubs.opengroup.org/onlinepubs/000095399/utilities/newgrp.html Regards, Jan From gelonida at gmail.com Sun Mar 11 00:30:00 2012 From: gelonida at gmail.com (Gelonida N) Date: Sun, 11 Mar 2012 06:30:00 +0100 Subject: How to know that two pyc files contain the same code In-Reply-To: <4f5bdb14$0$29891$c3e8da3$5496439d@news.astraweb.com> References: <4f5bdb14$0$29891$c3e8da3$5496439d@news.astraweb.com> Message-ID: Hi Steven, On 03/10/2012 11:52 PM, Steven D'Aprano wrote: > > On Sat, 10 Mar 2012 15:48:48 +0100, Gelonida N wrote: > > >> >> Hi, >> >> >> >> I want to know whether two .pyc files are identical. >> >> >> >> With identical I mean whether they contain the same byte code. > > > > Define "identical" and "the same". Indeed! Identical is not that simple to define and depends on the context. One definition of identical, that would suit me at the moment would be: If I have two .pyc files, which were the result of a compilation of two identical .py files, then I would like to treat these two .pyc files as identical, even if they were compiled at different times (absolutely necessary) and with a different absolute path (would be nice) Above definition of identical byte code would also mean, that any error message about errors in a given line number would be identical for both .pyc files > > > > If I compile these two files: > > > > > > # file ham.py > > x = 23 > > def func(): > > a = 23 > > return a + 19 > > > > > > > > # file = spam.py > > def func(): > > return 42 > > > > tmp = 19 > > x = 4 + tmp > > del tmp > > > > > > do you expect spam.pyc and ham.pyc to count as "the same"? > > For most pythons I would not expect, that ham.py and spam.py would result in the same byte code and would thus not even have the same performance, I agree, though that an efficient compiler might generate the same byte code, though I wonder if an optimizing compiler would/should be allowed to optimize away the global variable tmp, as it would be visible (though only for a short time) in a multithreading environment. If the byte code were different in two .pyc files. then I would like to have them treated as different .pyc files. If by coincidence, the generated btye code were the same, then I wouldn't mind, if they were treated as identical, but I wouldn't insist. Up to my knowledge Python (or at least C-python) stores line numbers in the .pyc files, so that it can report exact line numbers refering to the originating source code in case of an exception or for back traces So there is the choice to say, that two pyc files with exactly the same byte code would be treated identical if white spaces / line numbers of their sources were different or the choice to say, that they are different. Being conservative I'd treat them as different. Ideally I'd like to be able depending on my use case to distinguish following cases. a) .pyc files with identical byte code b) .pyc files with identical byte code AND source code line numbers c) same as b) AND identical source file names. From angrybaldguy at gmail.com Sun Mar 11 00:48:44 2012 From: angrybaldguy at gmail.com (Owen Jacobson) Date: Sun, 11 Mar 2012 00:48:44 -0500 Subject: stackoverflow question References: <2012031015032562036-angrybaldguy@gmailcom> Message-ID: <2012031100484474709-angrybaldguy@gmailcom> On 2012-03-10 22:21:55 +0000, Ethan Furman said: > Owen Jacobson wrote: >> On 2012-03-09 22:10:18 +0000, Ethan Furman said: >> >>> Hey all! >>> >>> I posted a question/answer on SO earlier, but there seems to be some >>> confusion around either the question or the answer (judging from the >>> comments). >>> >>> http://stackoverflow.com/q/9638921/208880 >>> >>> If anyone here is willing to take a look at it and let me know if I did >>> not write it well, I would appreciate the feedback. >>> >>> >>> Here's the question text: >>> ------------------------ >>> I'm writing a metaclass to do some cool stuff, and part of its >>> processing is to check that certain attributes exist when the class is >>> created. Some of these are mutable, and would normally be set in >>> `__init__`, but since `__init__` isn't run until the instance is >>> created the metaclass won't know that the attribute *will* be created, >>> and raises an error. I could do something like: >>> >>> class Test(meta=Meta): >>> mutable = None >>> def __init__(self): >>> self.mutable = list() >>> >>> But that isn't very elegant, and also violates DRY. >>> >>> What I need is some way to have: >>> >>> class Test(metaclass=Meta): >>> mutable = list() >>> >>> t1 = Test() >>> t2 = Test() >>> t1.mutable.append('one') >>> t2.mutable.append('two') >>> t1.mutable # prints ['one'] >>> t2.mutable # prints ['two'] >>> >>> Any ideas on how this can be accomplished? >>> >>> Also, the metaclass doing the checking doesn't care what type of object >>> the attribute is, only that it is there. >>> --------------------------- >> >> Why check what you can ensure? The __init__ function your metaclass >> passes to type() doesn't have to be the __init__ method your metaclass >> received. [? __init__-generation technique elided ?] >> All instances of classes whose metaclass is Meta will, guaranteed, have >> an instance field named 'mutable'. Its value is a list created at >> instance creation time, unless the instance's __init__ provides a >> different value. > > The idea is good. The devil is in the details, as usual. How is the > metaclass going to know: > > 1) which attributes to replace > 2) what to replace them with? I can think of at least three techniques; others are certainly possible: 1. As with the example code, the list is hard-coded in the metaclass's source code. 2. The list (or, rather, a dictionary) is drawn from a class attribute of the class being created: class Foo(object): mandatory_fields = {'mutable': list, 'more_stuff': str} __metaclass__ = IntrospectingMetaclass 3. A metaclass-returning factory produces new metaclasses on demand, each of which has a dict of mandatory fields baked into it. (This is a hybrid of the two approaches, and can easily have some messy side effects on your app's type ecology if used carelessly.) Of course, you can also treat this the other way around: instead of enforcing that instances have specific fields, you could have users of those instances be aware that the field might not exist, and wrap access to the field in a try/except NameError block or use getattr to read the attribute. What's appropriate really depends on how you plan to use this metaclass, and on the nature of the higher-level problem to which "I know, I'll use metaclasses" is your answer. How about telling us a slightly broader story about your problem? -o From shanhameed87 at gmail.com Sun Mar 11 01:10:09 2012 From: shanhameed87 at gmail.com (Shahul Hameed) Date: Sat, 10 Mar 2012 22:10:09 -0800 (PST) Subject: open this mail surprise 4 u Message-ID: <1d213c9e-3fbe-45a6-b126-ce804ef599f5@pi6g2000pbc.googlegroups.com> http://123maza.com/46/flower816/ From nagle at animats.com Sun Mar 11 01:12:49 2012 From: nagle at animats.com (John Nagle) Date: Sat, 10 Mar 2012 22:12:49 -0800 Subject: "Decoding unicode is not supported" in unusual situation In-Reply-To: <4f5aa70e$0$30002$c3e8da3$5496439d@news.astraweb.com> References: <4f571b94$0$12037$742ec2ed@news.sonic.net> <8762egmzfp.fsf@benfinney.id.au> <4f5749bc$0$29989$c3e8da3$5496439d@news.astraweb.com> <4f57b63f$0$11986$742ec2ed@news.sonic.net> <871up4m69h.fsf@benfinney.id.au> <4f57eeac$0$29989$c3e8da3$5496439d@news.astraweb.com> <87sjhjltsp.fsf@benfinney.id.au> <4f593178$0$11963$742ec2ed@news.sonic.net> <4f5a47f0$0$11979$742ec2ed@news.sonic.net> <4f5aa70e$0$30002$c3e8da3$5496439d@news.astraweb.com> Message-ID: <4f5c4262$0$11961$742ec2ed@news.sonic.net> On 3/9/2012 4:57 PM, Steven D'Aprano wrote: > On Fri, 09 Mar 2012 10:11:58 -0800, John Nagle wrote: > This demonstrates a gross confusion about both Unicode and Python. John, > I honestly don't mean to be rude here, but if you actually believe that > (rather than merely expressing yourself poorly), then it seems to me that > you are desperately misinformed about Unicode and are working on the > basis of some serious misapprehensions about the nature of strings. > > In Python 2.6/2.7, there is no ambiguity between str/bytes. The two names > are aliases for each other. The older name, "str", is a misnomer, since > it *actually* refers to bytes (and always has, all the way back to the > earliest days of Python). At best, it could be read as "byte string" or > "8-bit string", but the emphasis should always be on the *bytes*. There's an inherent ambiguity in that "bytes" and "str" are really the same type in Python 2.6/2.7. That's a hack for backwards compatibility, and it goes away in 3.x. The notes for PEP 358 admit this. It's implicit in allowing unicode(s) with no encoding, on type "str", that there is an implicit assumption that s is ASCII. Arguably, "unicode()" should have required an encoding in all cases. Or "str" and "bytes" should have been made separate types in Python 2.7, in which case unicode() of a str would be a safe ASCII to Unicode translation, and unicode() of a bytes object would require an encoding. But that would break too much old code. So we have an ambiguity and a hack. "While Python 2 also has a unicode string type, the fundamental ambiguity of the core string type, coupled with Python 2's default behavior of supporting automatic coercion from 8-bit strings to unicode objects when the two are combined, often leads to UnicodeErrors" - PEP 404 John Nagle From steve+comp.lang.python at pearwood.info Sun Mar 11 03:06:53 2012 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 11 Mar 2012 07:06:53 GMT Subject: How to know that two pyc files contain the same code References: <4f5bdb14$0$29891$c3e8da3$5496439d@news.astraweb.com> Message-ID: <4f5c4f0d$0$29891$c3e8da3$5496439d@news.astraweb.com> On Sun, 11 Mar 2012 12:15:11 +1100, Chris Angelico wrote: > On Sun, Mar 11, 2012 at 9:52 AM, Steven D'Aprano > wrote: >> On Sat, 10 Mar 2012 15:48:48 +0100, Gelonida N wrote: Define >> "identical" and "the same". >> >> If I compile these two files: >> >> >> # file ham.py >> x = 23 >> def func(): >> ? ?a = 23 >> ? ?return a + 19 >> >> >> >> # file = spam.py >> def func(): >> ? ?return 42 >> >> tmp = 19 >> x = 4 + tmp >> del tmp >> >> >> do you expect spam.pyc and ham.pyc to count as "the same"? > > They do not contain the same code. They may contain code which has the > same effect, but it is not the same code. To me, they do: they contain a function "func" which takes no arguments and returns 42, and a global "x" initialised to 23. Everything else is an implementation detail. I'm not being facetious. One should be asking what is the *purpose* of this question -- is it to detect when two pyc files contain the same *interface*, or to determine if they were generated from identical source code files (and if the later, do comments and whitespace matter)? What if one merely changed the order of definition? Instead of: def foo(): pass def bar(): pass one had this? def bar(): pass def foo(): pass It depends on why the OP cares if they are "identical". I can imagine use- cases where the right solution is to forget ideas about identical code, and just checksum the files (ignoring any timestamps). -- Steven From stefan_ml at behnel.de Sun Mar 11 03:41:17 2012 From: stefan_ml at behnel.de (Stefan Behnel) Date: Sun, 11 Mar 2012 08:41:17 +0100 Subject: Porting the 2-3 heap data-structure library from C to Python In-Reply-To: <87399gne30.fsf@xemacs.org> References: <87boo89zul.fsf@xemacs.org> <87399gne30.fsf@xemacs.org> Message-ID: Hrvoje Niksic, 11.03.2012 02:03: > Stefan Behnel writes: >>> which is the standard way of extending Python with high-performance >>> (and/or system-specific) C code. >> >> Well, it's *one* way. Certainly not the easiest way, neither the most >> portable and you'll have a hard time making it the fastest. > > I didn't say it was easy, but standard, in the sense of documented in > Python documentation. Python/C is as portable as Python itself, and as > fast as the platform allows. Only if you know how to do it right and have the discipline to do a lot of cross-platform testing, benchmarking and tuning. Not everyone wants to invest that much time into details that are unrelated to the problem at hand. And why should they, when other people (who have gained some experience in it) have already done if for them and continue to do that, so that they don't need to care and can get it for free? > I understand your desire to promote > Cython, but please stop resorting to FUD in doing so. I can't see it being FUD (although arguably promotion) to tell people that "we write C so you don't have to". It's certainly not FUD that it's easier (and IMHO also more fun) to write good Python code than good C code. Quite the contrary, telling new users to go straight for writing C code and using CPython's C-API natively is like asking them why (the heck!) they are using Python in the first place, when they can just dive into the beautiful world of C. I don't think that's the ideal attitude for this list. Stefan From cosmius at gmail.com Sun Mar 11 06:10:19 2012 From: cosmius at gmail.com (Cosmia Luna) Date: Sun, 11 Mar 2012 03:10:19 -0700 (PDT) Subject: How to re-implement the crypt.crypt function? In-Reply-To: References: <28304124.1374.1331408016748.JavaMail.geo-discussion-forums@yncd8> Message-ID: <17753159.3543.1331460619089.JavaMail.geo-discussion-forums@ynnk21> On Sunday, March 11, 2012 4:16:52 AM UTC+8, Christian Heimes wrote: > Am 10.03.2012 20:33, schrieb Cosmia Luna: > > I'm not searching for a full solution and only want to know how to use hashlib to create a equivalent string like > > If you chance your mind and choose to use a full solution, then I highly > recommend passlib [1]. It has an implementation of SHA-512 crypt as > indicated by the number 6 in the header of your string. > > By the way "$6$ds41p/9VMA.BHH0U" is *not* the salt. Just > "ds41p/9VMA.BHH0U" is the salt, 6 is a hash identifier. > > Christian > > [1] http://packages.python.org/passlib/ PassLib works for me. What I want is passlib.context, I need it in consideration of forward compatibility. Thanks a lot. But I still want to know how it is implemented, I read passlib's source but I found he/she re-implemented hashlib, which I can't understand. Now I knows that the encoding is hash64 instead of base64, but I can't know that. PassLib is too difficult for me. Anyone knows the accurate process? Cosmia From cosmius at gmail.com Sun Mar 11 06:10:19 2012 From: cosmius at gmail.com (Cosmia Luna) Date: Sun, 11 Mar 2012 03:10:19 -0700 (PDT) Subject: How to re-implement the crypt.crypt function? In-Reply-To: References: <28304124.1374.1331408016748.JavaMail.geo-discussion-forums@yncd8> Message-ID: <17753159.3543.1331460619089.JavaMail.geo-discussion-forums@ynnk21> On Sunday, March 11, 2012 4:16:52 AM UTC+8, Christian Heimes wrote: > Am 10.03.2012 20:33, schrieb Cosmia Luna: > > I'm not searching for a full solution and only want to know how to use hashlib to create a equivalent string like > > If you chance your mind and choose to use a full solution, then I highly > recommend passlib [1]. It has an implementation of SHA-512 crypt as > indicated by the number 6 in the header of your string. > > By the way "$6$ds41p/9VMA.BHH0U" is *not* the salt. Just > "ds41p/9VMA.BHH0U" is the salt, 6 is a hash identifier. > > Christian > > [1] http://packages.python.org/passlib/ PassLib works for me. What I want is passlib.context, I need it in consideration of forward compatibility. Thanks a lot. But I still want to know how it is implemented, I read passlib's source but I found he/she re-implemented hashlib, which I can't understand. Now I knows that the encoding is hash64 instead of base64, but I can't know that. PassLib is too difficult for me. Anyone knows the accurate process? Cosmia From hyperboogie at gmail.com Sun Mar 11 06:18:26 2012 From: hyperboogie at gmail.com (hyperboogie) Date: Sun, 11 Mar 2012 03:18:26 -0700 (PDT) Subject: newb __init__ inheritance References: <1c6db866-6fa3-4de5-96de-51d6720a1300@x17g2000yqj.googlegroups.com> Message-ID: <2feb13ca-f83b-4843-995f-ee77e7505ecd@db5g2000vbb.googlegroups.com> On Mar 11, 12:47?am, "Colin J. Williams" wrote: > On 10/03/2012 12:58 PM, Colin J. Williams wrote:> On 08/03/2012 10:25 AM, hyperboogie wrote: > >> Hello everyone. > > [snip] > > main() > > I'm not sure that the class initialization is required. > > > Good luck, > > > Colin W. > > When I wrote earlier, I wondered about the need for initialization. > > With Version 2, both __new__ and __init__ were required, not in the > example below, using version 3.2: > #!/usr/bin/env python > > class A(): > > ? ?def ringA(self): > ? ? ?print ('aaa') > > ? ?def ringB(self): > ? ? ?print('bbb') > > class B(A): > ? ?def __init__(self:) > ? ?def ringB(self): > ? ? ?print('BBB') > > a= A() > b= B() > b.ringB() > b.ringA() > b.__class__.mro()[0].ringB(22) ? # ?22 is used for the ringB attribute > ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? # ?Trial and error shows that any > ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? # ?non-Null,including None for the > ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? # ?argument gives the same result > z= 1 > def main(): > ? ? ?pass > > if __name__ == '__main__': > ? ? ?main() > > Colin W. thank you everyone... Still things are not working as expected... what am I doing wrong? I'm working with python2 and have the following issues: 1. mro is not an attribute/function 2. inheritance is not working as expected: # cat test.py #!/usr/bin/python class A(): def __init__(self): z=1 print "in A.__init__ z=", z def funcA(self): print "in funcA - class A" def funcB(self): print "in funcB - class A, z= ", z class B(A): def __init__(self): A.__init__(self) print "in B.__init__ z=", z def funcB(self): print "in funcB - class B, z= ", z a=A() b=B() b.funcB() b.funcA() # ./test.py in A.__init__ z= 1 # This must be the __init__ from the instantiation of a in A.__init__ z= 1 # This must be the B.__init__ calling A.__init__ in B.__init__ z= # Why isn't this working? z should have been inherited from "A" right? Traceback (most recent call last): File "./test.py", line 23, in b=B() File "./test.py", line 17, in __init__ print "in B.__init__ z=", z NameError: global name 'z' is not defined # From clp2 at rebertia.com Sun Mar 11 06:38:27 2012 From: clp2 at rebertia.com (Chris Rebert) Date: Sun, 11 Mar 2012 03:38:27 -0700 Subject: newb __init__ inheritance In-Reply-To: <2feb13ca-f83b-4843-995f-ee77e7505ecd@db5g2000vbb.googlegroups.com> References: <1c6db866-6fa3-4de5-96de-51d6720a1300@x17g2000yqj.googlegroups.com> <2feb13ca-f83b-4843-995f-ee77e7505ecd@db5g2000vbb.googlegroups.com> Message-ID: On Sun, Mar 11, 2012 at 3:18 AM, hyperboogie wrote: > thank you everyone... > Still things are not working as expected... what am I doing wrong? > # cat test.py > #!/usr/bin/python > > class A(): You should be subclassing `object`, but that's a minor point which isn't the cause of your problem. > ? def __init__(self): > ? ? ?z=1 This creates a *local variable* named "z". You want an *attribute* named "z", so you should be doing: self.z = 1 instead. Same problem elsewhere; you must *always* explicitly use `self` when referencing an attribute of the current object. Python != Java or C++. Cheers, Chris From hyperboogie at gmail.com Sun Mar 11 06:56:28 2012 From: hyperboogie at gmail.com (hyperboogie) Date: Sun, 11 Mar 2012 03:56:28 -0700 (PDT) Subject: newb __init__ inheritance In-Reply-To: References: <1c6db866-6fa3-4de5-96de-51d6720a1300@x17g2000yqj.googlegroups.com> <2feb13ca-f83b-4843-995f-ee77e7505ecd@db5g2000vbb.googlegroups.com> Message-ID: <18769501.3541.1331463388634.JavaMail.geo-discussion-forums@ynkz21> On Sunday, March 11, 2012 12:38:27 PM UTC+2, Chris Rebert wrote: > On Sun, Mar 11, 2012 at 3:18 AM, hyperboogie wrote: > > > thank you everyone... > > Still things are not working as expected... what am I doing wrong? > > > # cat test.py > > #!/usr/bin/python > > > > class A(): > > You should be subclassing `object`, but that's a minor point which > isn't the cause of your problem. > > > ? def __init__(self): > > ? ? ?z=1 > > This creates a *local variable* named "z". You want an *attribute* > named "z", so you should be doing: > self.z = 1 > instead. Same problem elsewhere; you must *always* explicitly use > `self` when referencing an attribute of the current object. Python != > Java or C++. > > Cheers, > Chris Thanks ... works great now. Two last questions: 1. What do you mean by "subclassing `object`"? 2. Is the mro function available only on python3? From hyperboogie at gmail.com Sun Mar 11 06:56:28 2012 From: hyperboogie at gmail.com (hyperboogie) Date: Sun, 11 Mar 2012 03:56:28 -0700 (PDT) Subject: newb __init__ inheritance In-Reply-To: References: <1c6db866-6fa3-4de5-96de-51d6720a1300@x17g2000yqj.googlegroups.com> <2feb13ca-f83b-4843-995f-ee77e7505ecd@db5g2000vbb.googlegroups.com> Message-ID: <18769501.3541.1331463388634.JavaMail.geo-discussion-forums@ynkz21> On Sunday, March 11, 2012 12:38:27 PM UTC+2, Chris Rebert wrote: > On Sun, Mar 11, 2012 at 3:18 AM, hyperboogie wrote: > > > thank you everyone... > > Still things are not working as expected... what am I doing wrong? > > > # cat test.py > > #!/usr/bin/python > > > > class A(): > > You should be subclassing `object`, but that's a minor point which > isn't the cause of your problem. > > > ? def __init__(self): > > ? ? ?z=1 > > This creates a *local variable* named "z". You want an *attribute* > named "z", so you should be doing: > self.z = 1 > instead. Same problem elsewhere; you must *always* explicitly use > `self` when referencing an attribute of the current object. Python != > Java or C++. > > Cheers, > Chris Thanks ... works great now. Two last questions: 1. What do you mean by "subclassing `object`"? 2. Is the mro function available only on python3? From clp2 at rebertia.com Sun Mar 11 07:37:55 2012 From: clp2 at rebertia.com (Chris Rebert) Date: Sun, 11 Mar 2012 04:37:55 -0700 Subject: newb __init__ inheritance In-Reply-To: <18769501.3541.1331463388634.JavaMail.geo-discussion-forums@ynkz21> References: <1c6db866-6fa3-4de5-96de-51d6720a1300@x17g2000yqj.googlegroups.com> <2feb13ca-f83b-4843-995f-ee77e7505ecd@db5g2000vbb.googlegroups.com> <18769501.3541.1331463388634.JavaMail.geo-discussion-forums@ynkz21> Message-ID: On Sun, Mar 11, 2012 at 3:56 AM, hyperboogie wrote: > On Sunday, March 11, 2012 12:38:27 PM UTC+2, Chris Rebert wrote: >> On Sun, Mar 11, 2012 at 3:18 AM, hyperboogie wrote: >> >> > thank you everyone... >> > Still things are not working as expected... what am I doing wrong? >> >> > # cat test.py >> > #!/usr/bin/python >> > >> > class A(): >> >> You should be subclassing `object`, but that's a minor point which >> isn't the cause of your problem. >> >> > ? def __init__(self): >> > ? ? ?z=1 >> >> This creates a *local variable* named "z". You want an *attribute* >> named "z", so you should be doing: >> ? ? self.z = 1 >> instead. Same problem elsewhere; you must *always* explicitly use >> `self` when referencing an attribute of the current object. Python != >> Java or C++. >> >> Cheers, >> Chris > > Thanks ... works great now. > Two last questions: > > 1. What do you mean by "subclassing `object`"? Your classes should (ultimately) subclass the built-in class named "object". In your case: class A(object): # ?rest same as before? This ensures that your classes are new-style rather than old-style (the latter is deprecated); see: http://docs.python.org/glossary.html#term-new-style-class > 2. Is the mro function available only on python3? There's never been an mro function. Perhaps you mean the __mro__ attribute of classes (e.g. `B.__mro__`), which is available in Python 2.2+ and Python 3? Cheers, Chris From ian.g.kelly at gmail.com Sun Mar 11 07:40:53 2012 From: ian.g.kelly at gmail.com (Ian Kelly) Date: Sun, 11 Mar 2012 05:40:53 -0600 Subject: newb __init__ inheritance In-Reply-To: <18769501.3541.1331463388634.JavaMail.geo-discussion-forums@ynkz21> References: <1c6db866-6fa3-4de5-96de-51d6720a1300@x17g2000yqj.googlegroups.com> <2feb13ca-f83b-4843-995f-ee77e7505ecd@db5g2000vbb.googlegroups.com> <18769501.3541.1331463388634.JavaMail.geo-discussion-forums@ynkz21> Message-ID: On Sun, Mar 11, 2012 at 4:56 AM, hyperboogie wrote: > 1. What do you mean by "subclassing `object`"? In Python 2 there are two different types of classes: classic classes, which are retained for backward compatibility, and new-style classes, which were introduced in Python 2.2. Classic classes are the default. In order to get a new-style class (strongly recommended), your class must inherit directly or indirectly from object. In the following, A and B are classic classes, whereas C and D are new-style classes: class A: pass class B(A): pass class C(object): pass class D(C): pass In Python 3, classic classes have been removed, and so all four of the classes above would be new-style. > 2. Is the mro function available only on python3? No, but it is available only on new-style classes. If you try it on a classic class, you'll get an AttributeError. Cheers, Ian From ian.g.kelly at gmail.com Sun Mar 11 07:52:48 2012 From: ian.g.kelly at gmail.com (Ian Kelly) Date: Sun, 11 Mar 2012 05:52:48 -0600 Subject: newb __init__ inheritance In-Reply-To: References: <1c6db866-6fa3-4de5-96de-51d6720a1300@x17g2000yqj.googlegroups.com> <2feb13ca-f83b-4843-995f-ee77e7505ecd@db5g2000vbb.googlegroups.com> <18769501.3541.1331463388634.JavaMail.geo-discussion-forums@ynkz21> Message-ID: On Sun, Mar 11, 2012 at 5:40 AM, Ian Kelly wrote: >> 2. Is the mro function available only on python3? > > No, but it is available only on new-style classes. ?If you try it on a > classic class, you'll get an AttributeError. And by the way, you probably shouldn't call the mro method directly. That method is provided so that it can be overridden in order to customize the MRO at class creation. The proper (and faster) way to look up the MRO for a class is using the __mro__ attribute, which stores the result of the mro method when the class is initialized. http://docs.python.org/library/stdtypes.html?highlight=mro#class.__mro__ Cheers, Ian From __peter__ at web.de Sun Mar 11 08:12:25 2012 From: __peter__ at web.de (Peter Otten) Date: Sun, 11 Mar 2012 13:12:25 +0100 Subject: newb __init__ inheritance References: <1c6db866-6fa3-4de5-96de-51d6720a1300@x17g2000yqj.googlegroups.com> <2feb13ca-f83b-4843-995f-ee77e7505ecd@db5g2000vbb.googlegroups.com> <18769501.3541.1331463388634.JavaMail.geo-discussion-forums@ynkz21> Message-ID: Ian Kelly wrote: > On Sun, Mar 11, 2012 at 5:40 AM, Ian Kelly wrote: >>> 2. Is the mro function available only on python3? >> >> No, but it is available only on new-style classes. If you try it on a >> classic class, you'll get an AttributeError. > > And by the way, you probably shouldn't call the mro method directly. > That method is provided so that it can be overridden in order to > customize the MRO at class creation. The proper (and faster) way to > look up the MRO for a class is using the __mro__ attribute, which > stores the result of the mro method when the class is initialized. > > http://docs.python.org/library/stdtypes.html?highlight=mro#class.__mro__ Is it a good idea to use mro() or __mro__ at all? Are there common use cases that cannot be addressed with super()? From steve+comp.lang.python at pearwood.info Sun Mar 11 10:37:54 2012 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 11 Mar 2012 14:37:54 GMT Subject: Why are some unicode error handlers "encode only"? Message-ID: <4f5cb8c2$0$29891$c3e8da3$5496439d@news.astraweb.com> At least two standard error handlers are documented as working for encoding only: xmlcharrefreplace backslashreplace See http://docs.python.org/library/codecs.html#codec-base-classes and http://docs.python.org/py3k/library/codecs.html Why is this? I don't see why they shouldn't work for decoding as well. Consider this example using Python 3.2: >>> b"aaa--\xe9z--\xe9!--bbb".decode("cp932") Traceback (most recent call last): File "", line 1, in UnicodeDecodeError: 'cp932' codec can't decode bytes in position 9-10: illegal multibyte sequence The two bytes b'\xe9!' is an illegal multibyte sequence for CP-932 (also known as MS-KANJI or SHIFT-JIS). Is there some reason why this shouldn't or can't be supported? # This doesn't actually work. b"aaa--\xe9z--\xe9!--bbb".decode("cp932", "backslashreplace") => r'aaa--?--\xe9\x21--bbb' and similarly for xmlcharrefreplace. -- Steven From rantingrickjohnson at gmail.com Sun Mar 11 11:22:38 2012 From: rantingrickjohnson at gmail.com (Rick Johnson) Date: Sun, 11 Mar 2012 08:22:38 -0700 (PDT) Subject: How to know that two pyc files contain the same code References: <4f5bdb14$0$29891$c3e8da3$5496439d@news.astraweb.com> <4f5c4f0d$0$29891$c3e8da3$5496439d@news.astraweb.com> Message-ID: <90223b79-6a21-448a-945f-c5569a46b9d3@v7g2000yqb.googlegroups.com> On Mar 11, 2:06?am, Steven D'Aprano wrote: > I'm not being facetious. [...] Just in case anybody does not know already: the "D'A" in "Steven D'Aprano" stands for "Devils Advocate"; his real name is "Steven Prano". From search at bluelinetalent.com Sun Mar 11 12:00:01 2012 From: search at bluelinetalent.com (Blue Line Talent) Date: Sun, 11 Mar 2012 09:00:01 -0700 (PDT) Subject: Software Engineer - Storage, Python, C++, Java - Broomfield, CO Message-ID: <74c28456-5467-48e8-88a9-e5649358373a@to5g2000pbc.googlegroups.com> Blue Line Talent is looking for a mid-level software engineer with experience in a combination of Python, C/C++ and/or Java. Experience developing middleware is helpful. The Engineer will join an exciting start-up environment in a newly established location. This is an outstanding opportunity for a high performing software engineer with 3-5 years experience. Must love coding, variety. For this position most of the work is being done in Python now but they expect this SW Engineer will also use increasing amounts of C/C++ and Java. The languages experience isn't as important as finding a really sharp Software Engineer who loves programming (not just design) and would be well suited for the diversity of a start-up environment. Position Title: Software Engineer - Storage Work Location: Broomfield/Flatirons area, CO The Employer: ? A strongly positioned Storage Solutions Software company ? Fully funded and established start-up company with excellent opportunities for growth and advancement ? Comprehensive benefits package Description: ? Full life-cycle software design, development, implementation, test and maintenance. ? Develop, test, and maintain infrastructure-oriented software in Python with some work in C/C++ and Java ? Middleware development - bridge between Linux Kernel and GUI ? Source code control Experience Profile: ? BS in Computer Science or an applicable engineering subject and 3-5+ years of related software engineering experience ? 2+ years software engineering for complex storage solutions ? Loves programming ? Experience developing middleware ? Experience programming in Python (or C/C++ and/or Java) ? Software Engineering experience in a Linux environment. ? Experience with near-real time software development. ? Stable employment history of direct employment Helpful/Preferred: ? Experience in a start-up environment ? Experience with real-time software development. (exposure to embedded software is helpful) ? Enjoys diversity of tasks ? Experience with GUI ? Experience with C/C++ and/or Java ? Experience with various Windows and Linux OS environments ? Exposure to storage subsystems such as Fibre Channel, iSCSI, SAS, SATA, RAID, Snapshot, Replication, NAS, SAN, etc. ? MS in Computer Science, or related degree Please apply at www.bluelinetalent.com/active_jobs NOTES: ? Direct hire with comprehensive benefits ? Local candidates please - no relocation assistance provided ? Not available for Corp-to-Corp, no third parties please Ron Levis Principal, Talent Acquisition Mgr Blue Line Talent, LLC www.bluelinetalent.com www.linkedin.com/in/ronlevis (invitations are welcome) Moderator, Colorado IT Community on LinkedIn Groups Blue Line Talent is a member-owner of NPA, The Worldwide Recruiting Network, your connection to premier independent recruiting firms located throughout Europe, Asia, Australia, Africa and the Americas. From walter at livinglogic.de Sun Mar 11 12:10:12 2012 From: walter at livinglogic.de (=?UTF-8?B?V2FsdGVyIETDtnJ3YWxk?=) Date: Sun, 11 Mar 2012 17:10:12 +0100 Subject: Why are some unicode error handlers "encode only"? In-Reply-To: <4f5cb8c2$0$29891$c3e8da3$5496439d@news.astraweb.com> References: <4f5cb8c2$0$29891$c3e8da3$5496439d@news.astraweb.com> Message-ID: <4F5CCE64.8050501@livinglogic.de> On 11.03.12 15:37, Steven D'Aprano wrote: > At least two standard error handlers are documented as working for > encoding only: > > xmlcharrefreplace > backslashreplace > > See http://docs.python.org/library/codecs.html#codec-base-classes > > and http://docs.python.org/py3k/library/codecs.html > > Why is this? I don't see why they shouldn't work for decoding as well. Because xmlcharrefreplace and backslashreplace are *error* handlers. However the bytes sequence b'〹' does *not* contain any bytes that are not decodable for e.g. the ASCII codec. So there are no errors to handle. > Consider this example using Python 3.2: > >>>> b"aaa--\xe9z--\xe9!--bbb".decode("cp932") > Traceback (most recent call last): > File "", line 1, in > UnicodeDecodeError: 'cp932' codec can't decode bytes in position 9-10: > illegal multibyte sequence > > The two bytes b'\xe9!' is an illegal multibyte sequence for CP-932 (also > known as MS-KANJI or SHIFT-JIS). Is there some reason why this shouldn't > or can't be supported? The byte sequence b'\xe9!' however is not something that would have been produced by the backslashreplace error handler. b'\\xe9!' (a sequence containing 5 bytes) would have been (and this probably would decode without any problems with the cp932 codec). > # This doesn't actually work. > b"aaa--\xe9z--\xe9!--bbb".decode("cp932", "backslashreplace") > => r'aaa--?--\xe9\x21--bbb' > > and similarly for xmlcharrefreplace. This would require a postprocess step *after* the bytes have been decoded. This is IMHO out of scope for Python's codec machinery. Servus, Walter From chris at simplistix.co.uk Sun Mar 11 12:20:03 2012 From: chris at simplistix.co.uk (Chris Withers) Date: Sun, 11 Mar 2012 09:20:03 -0700 Subject: Software Engineer - In-Reply-To: <74c28456-5467-48e8-88a9-e5649358373a@to5g2000pbc.googlegroups.com> References: <74c28456-5467-48e8-88a9-e5649358373a@to5g2000pbc.googlegroups.com> Message-ID: <4F5CD0B3.1090501@simplistix.co.uk> On 11/03/2012 09:00, Blue Line Talent wrote: > Blue Line Talent is looking for a mid-level software engineer with > experience in a combination of Please don't spam this list with jobs, use the Python job board instead: http://www.python.org/community/jobs/ cheers, Chris -- Simplistix - Content Management, Batch Processing & Python Consulting - http://www.simplistix.co.uk From tjreedy at udel.edu Sun Mar 11 13:10:33 2012 From: tjreedy at udel.edu (Terry Reedy) Date: Sun, 11 Mar 2012 13:10:33 -0400 Subject: Why are some unicode error handlers "encode only"? In-Reply-To: <4f5cb8c2$0$29891$c3e8da3$5496439d@news.astraweb.com> References: <4f5cb8c2$0$29891$c3e8da3$5496439d@news.astraweb.com> Message-ID: On 3/11/2012 10:37 AM, Steven D'Aprano wrote: > At least two standard error handlers are documented as working for > encoding only: > > xmlcharrefreplace > backslashreplace > > See http://docs.python.org/library/codecs.html#codec-base-classes > > and http://docs.python.org/py3k/library/codecs.html > > Why is this? I presume the purpose of both is to facilitate transmission of unicode text via byte transmission by extending incomplete byte encodings by replacing unicode chars that do not fit in the given encoding by a ascii byte sequence that will fit. > I don't see why they shouldn't work for decoding as well. > Consider this example using Python 3.2: > >>>> b"aaa--\xe9z--\xe9!--bbb".decode("cp932") > Traceback (most recent call last): > File "", line 1, in > UnicodeDecodeError: 'cp932' codec can't decode bytes in position 9-10: > illegal multibyte sequence > > The two bytes b'\xe9!' is an illegal multibyte sequence for CP-932 (also > known as MS-KANJI or SHIFT-JIS). Is there some reason why this shouldn't > or can't be supported? > > # This doesn't actually work. > b"aaa--\xe9z--\xe9!--bbb".decode("cp932", "backslashreplace") > => r'aaa--?--\xe9\x21--bbb' This output does not round-trip and would be a bit of a fib since it somewhat misrepresents what the encoded bytes were: >>> r'aaa--?--\xe9\x21--bbb'.encode("cp932") b'aaa--\xe9z--\\xe9\\x21--bbb' >>> b'aaa--\xe9z--\\xe9\\x21--bbb'.decode("cp932") 'aaa--?--\\xe9\\x21--bbb' Python 3 added surrogateescape error handling to solve this problem. > and similarly for xmlcharrefreplace. Since xml character references are representations of unicode chars, and not bytes, I do not see how that would work. By analogy, perhaps you mean to have '&#e9;' in your output instead of '\xe9\x21', but those would not properly be xml numeric character references. -- Terry Jan Reedy From sorsorday at gmail.com Sun Mar 11 14:53:45 2012 From: sorsorday at gmail.com (Herman) Date: Sun, 11 Mar 2012 11:53:45 -0700 Subject: How to break long method name into more than one line? Message-ID: I am trying to stick to the rule described in the TDD book that, each test method name consists of the method name to be tested, inputs and the expected outputs. It takes up a lot of space and my company has a rule of limiting 79 characters (or 80) per line. I found that def abcdeef\ dddaaa(self): pass does not work, but def \ abcsajfoijfiawifoiwejfoi(self): pass works. Is this the only way to do it? From bob at mellowood.ca Sun Mar 11 15:04:55 2012 From: bob at mellowood.ca (bvdp) Date: Sun, 11 Mar 2012 12:04:55 -0700 (PDT) Subject: Raise X or Raise X()? Message-ID: <387014.2537.1331492695725.JavaMail.geo-discussion-forums@pbjv6> Which is preferred in a raise: X or X()? I've seen both. In my specific case I'm dumping out of a deep loop: try: for ... for ... for ... if match: raise StopInteration() else ... except StopInteration: print "found it" From roy at panix.com Sun Mar 11 15:11:29 2012 From: roy at panix.com (Roy Smith) Date: Sun, 11 Mar 2012 15:11:29 -0400 Subject: How to break long method name into more than one line? References: Message-ID: In article , Herman wrote: > I am trying to stick to the rule described in the TDD book that, each > test method name consists of the method name to be tested, inputs and > the expected outputs. It takes up a lot of space and my company has a > rule of limiting 79 characters (or 80) per line. I found that > def abcdeef\ > dddaaa(self): > pass > > does not work, but > def \ > abcsajfoijfiawifoiwejfoi(self): > pass > > works. Is this the only way to do it? Arrrrrrrrhhhggggg. If you can't fit a test method name into 79 characters, you're doing somthing wrong. Just for fun, I found all the test methods in the project I'm working on and sorted them by length. Here's the top of the list: $ find . -name 'test*py' | xargs grep -h 'def *test' | sort | uniq | awk '{print length($0), $0}' | sort -nr 55 def test_update_name_changes_dasherized_name(self): 51 def test_get_followers_with_no_followers(self): 50 def test_update_station_song_adds_false(self): 50 def test_anonymous_get_user_collections(self): 49 def test_wrong_user_update_should_fail(self): 49 def test_login_with_email_and_password(self): 47 def test_unknown_station_returns_404(self): 47 def test_login_failure_with_facebook(self): 47 def test_get_follows_with_no_follows(self): 46 def test_station_by_dasherized_name(self): 46 def test_nonexistent_recent_station(self): 46 def test_new_user_with_display_name(self): 46 def test_auto_connect_with_facebook(self): 46 def test_anonymous_created_stations(self): 45 def test_no_php_fatal_error_in_log(self): 45 def test_get_only_songza_followers(self): 45 def test_anonymous_vote_transition(self): 44 def test_non_ascii_global_station(self): 44 def test_global_station_not_found(self): 44 def test_gallery_create_duplicate(self): 44 def test_anonymous_listen_history(self): and so on down to the wonderfully terse: 21 def test_x(self): which I'm assuming actually makes sense in the context of the TestCase class it belongs to. At least I hope it does :-) The examples above are a reasonable upper limit on the verbosity you should be shooting for, IMHO. From nagle at animats.com Sun Mar 11 16:30:58 2012 From: nagle at animats.com (John Nagle) Date: Sun, 11 Mar 2012 13:30:58 -0700 Subject: html5lib not thread safe. Is the Python SAX library thread-safe? Message-ID: <4f5d0b82$0$11967$742ec2ed@news.sonic.net> "html5lib" is apparently not thread safe. (see "http://code.google.com/p/html5lib/issues/detail?id=189") Looking at the code, I've only found about three problems. They're all the usual "cached in a global without locking" bug. A few locks would fix that. But html5lib calls the XML SAX parser. Is that thread-safe? Or is there more trouble down at the bottom? (I run a multi-threaded web crawler, and currently use BeautifulSoup, which is thread safe, although dated. I'm looking at converting to html5lib.) John Nagle From irmen.NOSPAM at xs4all.nl Sun Mar 11 16:37:26 2012 From: irmen.NOSPAM at xs4all.nl (Irmen de Jong) Date: Sun, 11 Mar 2012 21:37:26 +0100 Subject: Raise X or Raise X()? In-Reply-To: <387014.2537.1331492695725.JavaMail.geo-discussion-forums@pbjv6> References: <387014.2537.1331492695725.JavaMail.geo-discussion-forums@pbjv6> Message-ID: <4f5d0d06$0$6856$e4fe514c@news2.news.xs4all.nl> On 11-3-2012 20:04, bvdp wrote: > Which is preferred in a raise: X or X()? I've seen both. In my specific case I'm dumping out of a deep loop: > > try: > for ... > for ... > for ... > if match: > raise StopInteration() > else ... > > except StopInteration: > print "found it" "raise X" is a special case of the 3-args raise. Effectively it just raises an instance of X which is constructed with an empty argument list. Therefore, "raise X()" is equivalent, as far as I know. See http://docs.python.org/reference/simple_stmts.html#the-raise-statement Irmen From atavory at gmail.com Sun Mar 11 17:01:01 2012 From: atavory at gmail.com (Ami Tavory) Date: Sun, 11 Mar 2012 23:01:01 +0200 Subject: Launching A Truly Disjoint Process Message-ID: Hello, I'm encountering a problem using the multiprocessing module to create a process that is truly disjoint from the parent process: i.e., one that contains no "memory" of the parent process, nor any record in the parent process that it is its child. This originated in a pygtk problem, but I'll try to put down as little pygtk as possible - just enough to explain the problem (also, sorry, but I couldn't get an answer at the gtk forum). The code is a small python debugger front-end for GEdit. The plugin code, run from GEdit's process, uses multiprocessing.Process(target = run_dbg) to launch the debugger in a function in separate process. The debugger uses the bdb module like this: bdb.run('execfile("%s")' % script). This seems to work fine, except if the script being debugged is itself a pygtk script. Specifically, if it contains the code Gtk.main() then GEdit crashes with [xcb] Unknown sequence number while processing queue [xcb] Most likely this is a multi-threaded client and XInitThreads has not been called [xcb] Aborting, sorry about that. gedit: ../../src/xcb_io.c:273: poll_for_event: Assertion `!xcb_xlib_threads_sequence_lost' failed. Googling this error yielded many results, but they all consisted of advice to change either the code launching the process (possibly compiling it differently), or change the launched process running gtk. It seems like gtk requires that a single thread run this. Unfortunately, in this case, the launching process is GEdit (whose code I cannot modify from a plugin), and the launched process essentially runs a hypothetical script that is being debugged (and whose code, therefore, is a given). OTOH, clearly it is possible to run more than a single gtk app concurrently from completely separate processes. Is there a way, therefore, to launch the second process, or have the launched process do something when it starts, so that the two processes should essentially be disjoint? Thanks, Ami -------------- next part -------------- An HTML attachment was scrubbed... URL: From d at davea.name Sun Mar 11 17:34:41 2012 From: d at davea.name (Dave Angel) Date: Sun, 11 Mar 2012 17:34:41 -0400 Subject: Launching A Truly Disjoint Process In-Reply-To: References: Message-ID: <4F5D1A71.1010908@davea.name> On 03/11/2012 05:01 PM, Ami Tavory wrote: > Hello, > > I'm encountering a problem using the multiprocessing module to create a > process that is truly disjoint from the parent process: i.e., one that > contains no "memory" of the parent process, nor any record in the parent > process that it is its child. This originated in a pygtk problem, but I'll > try to put down as little pygtk as possible - just enough to explain the > problem (also, sorry, but I couldn't get an answer at the gtk forum). > > The code is a small python debugger front-end for GEdit. The plugin code, > run from GEdit's process, uses > multiprocessing.Process(target = run_dbg) > to launch the debugger in a function in separate process. The debugger uses > the bdb module like this: > bdb.run('execfile("%s")' % script). > This seems to work fine, except if the script being debugged is itself a > pygtk script. Specifically, if it contains the code > Gtk.main() > then GEdit crashes with > > [xcb] Unknown sequence number while processing queue > [xcb] Most likely this is a multi-threaded client and XInitThreads has not > been called > [xcb] Aborting, sorry about that. > gedit: ../../src/xcb_io.c:273: poll_for_event: Assertion > `!xcb_xlib_threads_sequence_lost' failed. > > Googling this error yielded many results, but they all consisted of > advice to change either the code launching the process (possibly compiling > it differently), or change the launched process running gtk. It seems like > gtk requires that a single thread run this. Unfortunately, in this case, > the launching process is GEdit (whose code I cannot modify from a plugin), > and the launched process essentially runs a hypothetical script that is > being debugged (and whose code, therefore, is a given). > OTOH, clearly it is possible to run more than a single gtk app > concurrently from completely separate processes. Is there a way, therefore, > to launch the second process, or have the launched process do something > when it starts, so that the two processes should essentially be disjoint? > > Thanks, > > Ami > Why not try using bash as an intermediate executable? Have your first python process invoke bash, giving it the arguments to in turn launch the second python process. If that won't work, then at least tell us some more of your environment. What version of Python, what version of OS? -- DaveA From cs at zip.com.au Sun Mar 11 17:45:01 2012 From: cs at zip.com.au (Cameron Simpson) Date: Mon, 12 Mar 2012 08:45:01 +1100 Subject: html5lib not thread safe. Is the Python SAX library thread-safe? In-Reply-To: <4f5d0b82$0$11967$742ec2ed@news.sonic.net> References: <4f5d0b82$0$11967$742ec2ed@news.sonic.net> Message-ID: <20120311214501.GA12816@cskk.homeip.net> On 11Mar2012 13:30, John Nagle wrote: | "html5lib" is apparently not thread safe. | (see "http://code.google.com/p/html5lib/issues/detail?id=189") | Looking at the code, I've only found about three problems. | They're all the usual "cached in a global without locking" bug. | A few locks would fix that. | | But html5lib calls the XML SAX parser. Is that thread-safe? | Or is there more trouble down at the bottom? | | (I run a multi-threaded web crawler, and currently use BeautifulSoup, | which is thread safe, although dated. I'm looking at converting to | html5lib.) IIRC, BeautifulSoup4 may do that for you: http://www.crummy.com/software/BeautifulSoup/bs4/doc/ http://www.crummy.com/software/BeautifulSoup/bs4/doc/#you-need-a-parser "Beautiful Soup 4 uses html.parser by default, but you can plug in lxml or html5lib and use that instead." Just for interest, re locking, I wrote a little decorator the other day, thus: @locked_property def foo(self): compute foo here ... return foo value and am rolling its use out amongst my classes. Code: def locked_property(func, lock_name='_lock', prop_name=None, unset_object=None): ''' A property whose access is controlled by a lock if unset. ''' if prop_name is None: prop_name = '_' + func.func_name def getprop(self): ''' Attempt lockless fetch of property first. Use lock if property is unset. ''' p = getattr(self, prop_name) if p is unset_object: with getattr(self, lock_name): p = getattr(self, prop_name) if p is unset_object: p = func(self) setattr(self, prop_name, p) return p return property(getprop) It tries to be lockless in the common case. I suspect it is only safe in CPython where there is a GIL. If raw python assignments and fetches can overlap (eg Jypthon I think?) I probably need shared "read" lock around the first "p = getattr(self, prop_name). Any remarks? Cheers, -- Cameron Simpson DoD#743 http://www.cskk.ezoshosting.com/cs/ Ed Campbell's pointers for long trips: 1. lay out the bare minimum of stuff that you need to take with you, then put at least half of it back. From clp2 at rebertia.com Sun Mar 11 17:49:25 2012 From: clp2 at rebertia.com (Chris Rebert) Date: Sun, 11 Mar 2012 14:49:25 -0700 Subject: Raise X or Raise X()? In-Reply-To: <4f5d0d06$0$6856$e4fe514c@news2.news.xs4all.nl> References: <387014.2537.1331492695725.JavaMail.geo-discussion-forums@pbjv6> <4f5d0d06$0$6856$e4fe514c@news2.news.xs4all.nl> Message-ID: On Sun, Mar 11, 2012 at 1:37 PM, Irmen de Jong wrote: > On 11-3-2012 20:04, bvdp wrote: >> Which is preferred in a raise: X or X()? I've seen both. In my specific case I'm dumping out of a deep loop: >> >> try: >> ? for ... >> ? ? for ... >> ? ? ? for ... >> ? ? ? ? if match: >> ? ? ? ? ? ?raise StopInteration() >> ? ? ? ? ?else ... >> >> except StopInteration: >> ? ?print "found it" > > "raise X" is a special case of the 3-args raise. Effectively it just raises an instance > of X which is constructed with an empty argument list. Therefore, "raise X()" is > equivalent, as far as I know. > > See http://docs.python.org/reference/simple_stmts.html#the-raise-statement Note that the 3-argument form of `raise` has been eliminated in Python 3. However, both: raise an_exception_instance and: raise AnExceptionClass # will have a blank error message are still permitted. Interesting stylistic question though. I'd support the X() form for uniformity with the majority of cases where an error message is specified for the exception. Cheers, Chris From ben+python at benfinney.id.au Sun Mar 11 18:27:08 2012 From: ben+python at benfinney.id.au (Ben Finney) Date: Mon, 12 Mar 2012 09:27:08 +1100 Subject: [RFC] PEP 3143: supplementary group list concerns References: Message-ID: <874ntukc3n.fsf@benfinney.id.au> Jan Pokorn? writes: > in the light of a recent spot in Python Paste [1], I've come across > the python-daemon [2] implementation and found it also lacks support > for supplementary groups. Thank you for your interest in ?python-daemon?. To know specifically what you're referring to in most of this message, I think your reference ?[1]? is necessary; but you didn't provide it. -- \ ?Pray, v. To ask that the laws of the universe be annulled in | `\ behalf of a single petitioner confessedly unworthy.? ?Ambrose | _o__) Bierce, _The Devil's Dictionary_, 1906 | Ben Finney From johnjsal at gmail.com Sun Mar 11 18:53:47 2012 From: johnjsal at gmail.com (John Salerno) Date: Sun, 11 Mar 2012 15:53:47 -0700 (PDT) Subject: What's the best way to parse this HTML tag? Message-ID: <239c4ad7-ac93-45c5-98d6-71a434e1c5aa@r21g2000yqa.googlegroups.com> I'm using Beautiful Soup to extract some song information from a radio station's website that lists the songs it plays as it plays them. Getting the time that the song is played is easy, because the time is wrapped in a
    tag all by itself with a class attribute that has a specific value I can search for. But the actual song title and artist information is harder, because the HTML isn't quite as precise. Here's a sample: This is about as far as I can drill down without getting TOO specific. I simply find the
    tags with the "cmPlaylistContent" class. This tag contains both the song title and the artist name, and sometimes miscellaneous other information as well, like a way to vote for the song or links to purchase it from iTunes or Amazon. So my question is, given the above HTML, how can I best extract the song title and artist name? It SEEMS like they are always the first two pieces of information in the tag, such that: for item in div.stripped_strings: print(item) Love Without End, Amen George Strait Download Song: iTunes | Amazon MP3 Comments??(1) Votes??(1) and I could simply get the first two items returned by that generator. It's not quite as clean as I'd like, because I have no idea if anything could ever be inserted before either of these items, thus messing it all up. I also don't want to rely on the tag, which makes me shudder, or the tag, because I don't know if they will always have an href. Ideall, the tag would have also had an attribute that labeled the title as the title, and the artist as the artist, but alas..... Therefore, I appeal to your greater wisdom in these matters. Given this HTML, is there a "best practice" for how to refer to the song title and artist? Thanks! From cs at zip.com.au Sun Mar 11 19:04:14 2012 From: cs at zip.com.au (Cameron Simpson) Date: Mon, 12 Mar 2012 10:04:14 +1100 Subject: Launching A Truly Disjoint Process In-Reply-To: <4F5D1A71.1010908@davea.name> References: <4F5D1A71.1010908@davea.name> Message-ID: <20120311230414.GA20637@cskk.homeip.net> On 11Mar2012 17:34, Dave Angel wrote: | On 03/11/2012 05:01 PM, Ami Tavory wrote: | > I'm encountering a problem using the multiprocessing module to create a | > process that is truly disjoint from the parent process: i.e., one that | > contains no "memory" of the parent process, nor any record in the parent | > process that it is its child. This originated in a pygtk problem, but I'll | > try to put down as little pygtk as possible - just enough to explain the | > problem (also, sorry, but I couldn't get an answer at the gtk forum). | > | > The code is a small python debugger front-end for GEdit. The plugin code, | > run from GEdit's process, uses | > multiprocessing.Process(target = run_dbg) | > to launch the debugger in a function in separate process. The debugger uses | > the bdb module like this: | > bdb.run('execfile("%s")' % script). | > This seems to work fine, except if the script being debugged is itself a | > pygtk script. Specifically, if it contains the code | > Gtk.main() | > then GEdit crashes with [...snip...] | | Why not try using bash as an intermediate executable? Have your first | python process invoke bash, giving it the arguments to in turn launch | the second python process. Why use bash at all? That requires painful and inefficient argument quoting, etc. Just invoke Python itself directly i.e. get subprocess to fork/exec (aka spawn) a new invocation of Python instead of using execfile. Totally untested prototype based purely on a cursory glance at the docs: subprocess.Popen( ( 'env', 'bdb_execfile='+script, 'python', '-c', 'import bdb; import os; bdb.run("execfile(os.environ[\"bdb_execfile\"])")', ) ) That "import..." string is all one line. Of course various arguments to Popen as required, etc. Cheers, -- Cameron Simpson DoD#743 http://www.cskk.ezoshosting.com/cs/ Here's a great .sig I wrote, so good it doesn't rhyme. Jon Benger From jpokorny at redhat.com Sun Mar 11 19:41:52 2012 From: jpokorny at redhat.com (Jan =?iso-8859-1?Q?Pokorn=FD?=) Date: Mon, 12 Mar 2012 00:41:52 +0100 Subject: [RFC] PEP 3143: supplementary group list concerns In-Reply-To: <874ntukc3n.fsf@benfinney.id.au> References: <874ntukc3n.fsf@benfinney.id.au> Message-ID: <20120311234152.GA6118@redhat.com> On 12/03/12 09:27 +1100, Ben Finney wrote: > Jan Pokorn? writes: > >> in the light of a recent spot in Python Paste [1], I've come across >> the python-daemon [2] implementation and found it also lacks support >> for supplementary groups. > > Thank you for your interest in ?python-daemon?. > > To know specifically what you're referring to in most of this message, > I think your reference ?[1]? is necessary; but you didn't provide it. My bad, I've sent it with unfinished renumbering. Please swap [1]+[2] in the quoted part and the missing reference is http://pypi.python.org/pypi/python-daemon/ (for some reason, this points to 1.5.5, even though 1.6 is also there: http://pypi.python.org/pypi/python-daemon/1.6 ). From gelonida at gmail.com Sun Mar 11 19:56:26 2012 From: gelonida at gmail.com (Gelonida N) Date: Mon, 12 Mar 2012 00:56:26 +0100 Subject: How to know that two pyc files contain the same code In-Reply-To: <4f5c4f0d$0$29891$c3e8da3$5496439d@news.astraweb.com> References: <4f5bdb14$0$29891$c3e8da3$5496439d@news.astraweb.com> <4f5c4f0d$0$29891$c3e8da3$5496439d@news.astraweb.com> Message-ID: On 03/11/2012 08:06 AM, Steven D'Aprano wrote: > What if one merely changed the order of definition? Instead of: > > def foo(): pass > def bar(): pass > > one had this? > > def bar(): pass > def foo(): pass > > It depends on why the OP cares if they are "identical". I can imagine use- > cases where the right solution is to forget ideas about identical code, > and just checksum the files (ignoring any timestamps). I guess this is what I will do for my use case Perform a checksum ignoring the time stamp. What I did not know though is where the time stamp was located. it seems it's in bytes 4-7 for all C-python versions so far. What is regrettable though is, that the absolute path name is part of the .pyc file, as I do not care Following snippet calculates the hash of a .pyc file by just ignoring the time stamp: import hashlib def md5_for_pyc(fname): hasher = hashlib.md5() with open(fname, 'rb') as fin: version = fin.read(4) hasher.update(version) _tstamp = fin.read(4) bytecode = fin.read() hasher.update(bytecode) return hasher.hexdigest() From steve+comp.lang.python at pearwood.info Sun Mar 11 19:59:09 2012 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 11 Mar 2012 23:59:09 GMT Subject: Raise X or Raise X()? References: <387014.2537.1331492695725.JavaMail.geo-discussion-forums@pbjv6> Message-ID: <4f5d3c4c$0$29891$c3e8da3$5496439d@news.astraweb.com> On Sun, 11 Mar 2012 12:04:55 -0700, bvdp wrote: > Which is preferred in a raise: X or X()? Both. Always use raise "X(*args)" when you need to provide arguments (which you should always do for exceptions meant for the caller to see). The form "raise X, args" should be considered discouraged, and in fact is gone in Python 3.x. Purely internal exceptions (which you raise and catch yourself) don't need arguments, so there is no difference between the two forms: "raise X" is exactly equivalent to "raise X()" with no arguments. Use whichever takes your fancy. Personally, I used "raise X" to mean "this doesn't need arguments and should never have any" and "raise X()" to mean "this needs arguments but I'm too lazy to provide them right now". Think of it as a FIXME. -- Steven From roy at panix.com Sun Mar 11 20:28:33 2012 From: roy at panix.com (Roy Smith) Date: Sun, 11 Mar 2012 20:28:33 -0400 Subject: What's the best way to parse this HTML tag? References: <239c4ad7-ac93-45c5-98d6-71a434e1c5aa@r21g2000yqa.googlegroups.com> Message-ID: In article <239c4ad7-ac93-45c5-98d6-71a434e1c5aa at r21g2000yqa.googlegroups.com>, John Salerno wrote: > Getting the time that the song is played is easy, because the time is > wrapped in a
    tag all by itself with a class attribute that has a > specific value I can search for. But the actual song title and artist > information is harder, because the HTML isn't quite as precise. Here's > a sample: > >
    > > > Love Without End, Amen > > >
    > > George Strait > > [...] > Therefore, I appeal to your greater wisdom in these matters. Given > this HTML, is there a "best practice" for how to refer to the song > title and artist? Obviously, any attempt at screen scraping is fraught with peril. Beautiful Soup is a great tool but it doesn't negate the fact that you've made a pact with the devil. That being said, if I had to guess, here's your puppy: > > Love Without End, Amen > the thing to look for is an "a" element with an href that starts with "/lsp/t", where "t" is for "track". Likewise: > > George Strait > an href starting with "/lsp/a" is probably an artist link. You owe the Oracle three helpings of tag soup. From steve+comp.lang.python at pearwood.info Sun Mar 11 20:30:08 2012 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 12 Mar 2012 00:30:08 GMT Subject: How to break long method name into more than one line? References: Message-ID: <4f5d4390$0$29891$c3e8da3$5496439d@news.astraweb.com> On Sun, 11 Mar 2012 11:53:45 -0700, Herman wrote: > I am trying to stick to the rule described in the TDD book that, each > test method name consists of the method name to be tested, inputs and > the expected outputs. *The* TDD book? There's only one? Surely not. That rule sounds utterly impractical. I can't think of anything to recommend it. Like any other function, method or class, tests should have meaningful names, but reading the name alone should not necessarily tell you *everything* about the function. We have "len", not "len_sequence_or_mapping_int", and similarly it is perfectly reasonable to have "test_len_empty" rather than "test_len_emptylist_emptystr_emptyunicode_emptydict_emptyset_emptytuple_zero". I expect that naming rule was invented by either people who have heard of test driven development, but never actually done it, or by people so anally-retentive that if they make seven short car trips over an hour, they check the tyre pressure, oil and water seven times because "the manual says to check before *every* trip". No offence. My advice is to moderate the naming convention of your tests with a good dose of common sense and aim for names which are readable rather than names that contain everything including the kitchen sink. Imagine you are in a technical meeting with some of your fellow programmers, and need to ask for help with a failing test. Imagine saying the name of the test aloud in a sentence. Does it add clarity to the discussion, or obfuscate it? People's short term memory can only hold so much (allegedly "seven plus or minus two"), and if the name itself hits that limit, you leave nothing left for the rest of the sentence. http://en.wikipedia.org/wiki/The_Magical_Number_Seven,_Plus_or_Minus_Two Names should be practically, rather than conforming to some naming rule that hurts readability and obfuscates the tests. > It takes up a lot of space and my company has a > rule of limiting 79 characters (or 80) per line. I found that def > abcdeef\ > dddaaa(self): > pass > > does not work, but > def \ > abcsajfoijfiawifoiwejfoi(self): > pass > > works. Is this the only way to do it? Yes. You can't split tokens over multiple lines, or put any whitespace between them. -- Steven From roy at panix.com Sun Mar 11 20:43:13 2012 From: roy at panix.com (Roy Smith) Date: Sun, 11 Mar 2012 20:43:13 -0400 Subject: How to break long method name into more than one line? References: <4f5d4390$0$29891$c3e8da3$5496439d@news.astraweb.com> Message-ID: In article <4f5d4390$0$29891$c3e8da3$5496439d at news.astraweb.com>, Steven D'Aprano wrote: > You can't split tokens over multiple lines, or put any whitespace > between them. Well, if you truly wanted to be perverse, you could write some kind of decorator: @make_long_named_test_method('some', 'very', 'long', 'list', 'of', 'token', 'fragments') def x(self): blah, blah, blah which creates a "test_some_very_long_list_of_token_fragments" method. But it would be a lot easier to just use sane method names. From bob at mellowood.ca Sun Mar 11 21:53:06 2012 From: bob at mellowood.ca (bvdp) Date: Sun, 11 Mar 2012 18:53:06 -0700 (PDT) Subject: Raise X or Raise X()? In-Reply-To: <4f5d3c4c$0$29891$c3e8da3$5496439d@news.astraweb.com> References: <387014.2537.1331492695725.JavaMail.geo-discussion-forums@pbjv6> <4f5d3c4c$0$29891$c3e8da3$5496439d@news.astraweb.com> Message-ID: <12235670.2782.1331517186309.JavaMail.geo-discussion-forums@pbjv6> Thanks all for the comments. > Personally, I used "raise X" to mean "this doesn't need arguments and > should never have any" and "raise X()" to mean "this needs arguments but > I'm too lazy to provide them right now". Think of it as a FIXME. Yes, that makes as much sense as anything else :) From python at mrabarnett.plus.com Sun Mar 11 22:26:03 2012 From: python at mrabarnett.plus.com (MRAB) Date: Mon, 12 Mar 2012 02:26:03 +0000 Subject: Raise X or Raise X()? In-Reply-To: <4f5d3c4c$0$29891$c3e8da3$5496439d@news.astraweb.com> References: <387014.2537.1331492695725.JavaMail.geo-discussion-forums@pbjv6> <4f5d3c4c$0$29891$c3e8da3$5496439d@news.astraweb.com> Message-ID: <4F5D5EBB.8090001@mrabarnett.plus.com> On 11/03/2012 23:59, Steven D'Aprano wrote: > On Sun, 11 Mar 2012 12:04:55 -0700, bvdp wrote: > >> Which is preferred in a raise: X or X()? > > Both. > > Always use raise "X(*args)" when you need to provide arguments (which you > should always do for exceptions meant for the caller to see). The form > "raise X, args" should be considered discouraged, and in fact is gone in > Python 3.x. > > Purely internal exceptions (which you raise and catch yourself) don't > need arguments, so there is no difference between the two forms: > "raise X" is exactly equivalent to "raise X()" with no arguments. Use > whichever takes your fancy. > > Personally, I used "raise X" to mean "this doesn't need arguments and > should never have any" and "raise X()" to mean "this needs arguments but > I'm too lazy to provide them right now". Think of it as a FIXME. > As some do need arguments, I'd do the opposite; no parentheses would mean "I haven't finished yet". :-) From johnjsal at gmail.com Sun Mar 11 22:35:50 2012 From: johnjsal at gmail.com (John Salerno) Date: Sun, 11 Mar 2012 19:35:50 -0700 (PDT) Subject: What's the best way to parse this HTML tag? References: <239c4ad7-ac93-45c5-98d6-71a434e1c5aa@r21g2000yqa.googlegroups.com> Message-ID: On Mar 11, 7:28?pm, Roy Smith wrote: > In article > <239c4ad7-ac93-45c5-98d6-71a434e1c... at r21g2000yqa.googlegroups.com>, > ?John Salerno wrote: > > > > > > > > > > > Getting the time that the song is played is easy, because the time is > > wrapped in a
    tag all by itself with a class attribute that has a > > specific value I can search for. But the actual song title and artist > > information is harder, because the HTML isn't quite as precise. Here's > > a sample: > > >
    > > ? > > ? > > ? ?Love Without End, Amen > > ? > > ? > > ?
    > > ? > > ? George Strait > > ? > > [...] > > Therefore, I appeal to your greater wisdom in these matters. Given > > this HTML, is there a "best practice" for how to refer to the song > > title and artist? > > Obviously, any attempt at screen scraping is fraught with peril. > Beautiful Soup is a great tool but it doesn't negate the fact that > you've made a pact with the devil. ?That being said, if I had to guess, > here's your puppy: > > > ? > > ? ?Love Without End, Amen > > ? > > the thing to look for is an "a" element with an href that starts with > "/lsp/t", where "t" is for "track". ?Likewise: > > > ? > > ? George Strait > > ? > > an href starting with "/lsp/a" is probably an artist link. > > You owe the Oracle three helpings of tag soup. Well, I had considered exactly that method, but I don't know for sure if the titles and names will always have links like that, so I didn't want to tie my programming to something so specific. But perhaps it's still better than just taking the first two strings. From nagle at animats.com Mon Mar 12 00:48:19 2012 From: nagle at animats.com (John Nagle) Date: Sun, 11 Mar 2012 21:48:19 -0700 Subject: html5lib not thread safe. Is the Python SAX library thread-safe? In-Reply-To: References: <4f5d0b82$0$11967$742ec2ed@news.sonic.net> Message-ID: <4f5d8012$0$12021$742ec2ed@news.sonic.net> On 3/11/2012 2:45 PM, Cameron Simpson wrote: > On 11Mar2012 13:30, John Nagle wrote: > | "html5lib" is apparently not thread safe. > | (see "http://code.google.com/p/html5lib/issues/detail?id=189") > | Looking at the code, I've only found about three problems. > | They're all the usual "cached in a global without locking" bug. > | A few locks would fix that. > | > | But html5lib calls the XML SAX parser. Is that thread-safe? > | Or is there more trouble down at the bottom? > | > | (I run a multi-threaded web crawler, and currently use BeautifulSoup, > | which is thread safe, although dated. I'm looking at converting to > | html5lib.) > > IIRC, BeautifulSoup4 may do that for you: > > http://www.crummy.com/software/BeautifulSoup/bs4/doc/ > > http://www.crummy.com/software/BeautifulSoup/bs4/doc/#you-need-a-parser > "Beautiful Soup 4 uses html.parser by default, but you can plug in > lxml or html5lib and use that instead." I want to use HTML5 standard parsing of bad HTML. (HTML5 formally defines how to parse bad comments, for example.) I currently have a modified version of BeautifulSoup that's more robust than the standard one, but it doesn't handle errors the same way browsers do. John Nagle From hotice.vegtiger at gmail.com Mon Mar 12 01:39:54 2012 From: hotice.vegtiger at gmail.com (Ashish Aggarwal) Date: Sun, 11 Mar 2012 22:39:54 -0700 (PDT) Subject: How Python empowers Java? Message-ID: <90d7a28f-8d7b-4623-88ea-07e0e101b4e3@ni10g2000pbc.googlegroups.com> I am a Java developer but new to Python. I am trying to assess, as what are new capabilities that Python will provide me if I use it with Java. Guys can you please help me? From bv4bv4bv4 at gmail.com Mon Mar 12 02:15:46 2012 From: bv4bv4bv4 at gmail.com (BV BV) Date: Sun, 11 Mar 2012 23:15:46 -0700 (PDT) Subject: GENOCIDE IN THE TWENTY-FIRST CENTURY IN SYRIA !!!!!!!!!!!!!! Message-ID: GENOCIDE IN THE TWENTY-FIRST CENTURY IN SYRIA SCHOKING ASSAD REGIME SYRIA http://www.youtube.com/watch?v=5H1NL8aOlsg http://www.youtube.com/watch?v=jZP51eRKy34 http://www.youtube.com/watch?v=e7AY8hSUjVc http://www.youtube.com/watch?v=g3ZPbUcKI-k&feature=related BABY TORTURED TO DEATH http://www.youtube.com/watch?v=938X3JkpnV4&feature=related http://www.youtube.com/watch?v=ybMeT4UUe6o&feature=related TORTURE CHILDREN IN FRONT OF HIS MOTHER'S SHOOTING ON HIS FEET http://www.youtube.com/watch?v=s-hfEArhs60&feature=related THE FIRST SCENS FOR AL-SABEEL AREA MASSACRE IN HOMS 5 2 2012 http://www.youtube.com/watch?v=bfJKCxiplXg BABA AMR MASSACRE 26 DEC 2011 http://www.youtube.com/watch?v=IK0hutwbopk&feature=related&skipcontrinter=1 From atavory at gmail.com Mon Mar 12 04:41:09 2012 From: atavory at gmail.com (Ami Tavory) Date: Mon, 12 Mar 2012 10:41:09 +0200 Subject: Fwd: Launching A Truly Disjoint Process In-Reply-To: <20120311230414.GA20637@cskk.homeip.net> References: <4F5D1A71.1010908@davea.name> <20120311230414.GA20637@cskk.homeip.net> Message-ID: ---------- Forwarded message ---------- From: Cameron Simpson Date: Mon, Mar 12, 2012 at 1:04 AM Subject: Re: Launching A Truly Disjoint Process To: Dave Angel Cc: Ami Tavory , python-list at python.org On 11Mar2012 17:34, Dave Angel wrote: | On 03/11/2012 05:01 PM, Ami Tavory wrote: | > I'm encountering a problem using the multiprocessing module to create a | > process that is truly disjoint from the parent process:... | Why not try using bash as an intermediate executable? Have your first | python process invoke bash, giving it the arguments to in turn launch | the second python process. Why use bash at all? That requires painful and inefficient argument quoting, etc. Just invoke Python itself directly i.e. get subprocess to fork/exec (aka spawn) a new invocation of Python instead of using execfile. Dave, Cameron, Many thanks. I ran some initial tests regarding your suggestions, and things look good. -------------- next part -------------- An HTML attachment was scrubbed... URL: From hyperboogie at gmail.com Mon Mar 12 05:09:36 2012 From: hyperboogie at gmail.com (hyperboogie) Date: Mon, 12 Mar 2012 02:09:36 -0700 (PDT) Subject: newb __init__ inheritance In-Reply-To: <1c6db866-6fa3-4de5-96de-51d6720a1300@x17g2000yqj.googlegroups.com> References: <1c6db866-6fa3-4de5-96de-51d6720a1300@x17g2000yqj.googlegroups.com> Message-ID: <18399211.724.1331543376411.JavaMail.geo-discussion-forums@vbbfy7> On Thursday, March 8, 2012 5:25:06 PM UTC+2, hyperboogie wrote: > Hello everyone. > > This is my first post in this group. > I started learning python a week ago from the "dive into python" e- > book and thus far all was clear. > However today while reading chapter 5 about objects and object > orientation I ran into something that confused me. > it says here: > http://www.diveintopython.net/object_oriented_framework/defining_classes.html#fileinfo.class.example > > "__init__ methods are optional, but when you define one, you must > remember to explicitly call the ancestor's __init__ method (if it > defines one). This is more generally true: whenever a descendant wants > to extend the behavior of the ancestor, the descendant method must > explicitly call the ancestor method at the proper time, with the > proper arguments. " > > However later on in the chapter: > http://www.diveintopython.net/object_oriented_framework/userdict.html > > it says: > "Methods are defined solely by their name, and there can be only one > method per class with a given name. So if a descendant class has an > __init__ method, it always overrides the ancestor __init__ method, > even if the descendant defines it with a different argument list. And > the same rule applies to any other method. " > > My question is if __init__ in the descendant class overrides __init__ > in the parent class how can I call the parent's __init__ from the > descendant class - I just overrode it didn't I? > > Am I missing something more fundamental here? > Thanks Thank you so much everyone for you help. No doubt I still have a long way to go before I feel comfortable with python. Appreciate all your help... From no.email at nospam.invalid Mon Mar 12 05:39:39 2012 From: no.email at nospam.invalid (Paul Rubin) Date: Mon, 12 Mar 2012 02:39:39 -0700 Subject: html5lib not thread safe. Is the Python SAX library thread-safe? References: <4f5d0b82$0$11967$742ec2ed@news.sonic.net> Message-ID: <7x399e40pw.fsf@ruckus.brouhaha.com> John Nagle writes: > But html5lib calls the XML SAX parser. Is that thread-safe? > Or is there more trouble down at the bottom? According to http://xmlbench.sourceforge.net/results/features200303/index.html libxml and expat both purport to be thread-safe. I've used the python expat library (not from multiple threads) and it works fine, though the python calls slow it down by worse than an order of magnitude. From stefan_ml at behnel.de Mon Mar 12 06:05:34 2012 From: stefan_ml at behnel.de (Stefan Behnel) Date: Mon, 12 Mar 2012 11:05:34 +0100 Subject: html5lib not thread safe. Is the Python SAX library thread-safe? In-Reply-To: <4f5d0b82$0$11967$742ec2ed@news.sonic.net> References: <4f5d0b82$0$11967$742ec2ed@news.sonic.net> Message-ID: John Nagle, 11.03.2012 21:30: > "html5lib" is apparently not thread safe. > (see "http://code.google.com/p/html5lib/issues/detail?id=189") > Looking at the code, I've only found about three problems. > They're all the usual "cached in a global without locking" bug. > A few locks would fix that. > > But html5lib calls the XML SAX parser. Is that thread-safe? > Or is there more trouble down at the bottom? > > (I run a multi-threaded web crawler, and currently use BeautifulSoup, > which is thread safe, although dated. I'm looking at converting to > html5lib.) You may also consider moving to lxml. BeautifulSoup supports it as a parser backend these days, so you wouldn't even have to rewrite your code to use it. And performance-wise, well ... http://blog.ianbicking.org/2008/03/30/python-html-parser-performance/ Stefan From jeanmichel at sequans.com Mon Mar 12 06:37:48 2012 From: jeanmichel at sequans.com (Jean-Michel Pichavant) Date: Mon, 12 Mar 2012 11:37:48 +0100 Subject: Raise X or Raise X()? In-Reply-To: <387014.2537.1331492695725.JavaMail.geo-discussion-forums@pbjv6> References: <387014.2537.1331492695725.JavaMail.geo-discussion-forums@pbjv6> Message-ID: <4F5DD1FC.7080603@sequans.com> bvdp wrote: > Which is preferred in a raise: X or X()? I've seen both. In my specific case I'm dumping out of a deep loop: > > try: > for ... > for ... > for ... > if match: > raise StopInteration() > else ... > > except StopInteration: > print "found it" > I prefer the raise X() version, it fulfils the zen of python : "Special cases aren't special enough to break the rules. There should be one-- and preferably only one --obvious way to do it." I still wonder why they've added the class raise form, on which purpose. JM From albert at spenarnc.xs4all.nl Mon Mar 12 07:27:25 2012 From: albert at spenarnc.xs4all.nl (Albert van der Horst) Date: 12 Mar 2012 11:27:25 GMT Subject: New Science Discovery: Perl Idiots Remain Idiots After A Decade!New Science Discovery: Perl Idiots Remain Idiots After A Decade! References: <0078bbfb-5dfc-48fc-af1a-69de3cf15c3e@b1g2000yqb.googlegroups.com> Message-ID: In article <0078bbfb-5dfc-48fc-af1a-69de3cf15c3e at b1g2000yqb.googlegroups.com>, Xah Lee wrote: >New Science Discovery: Perl Idiots Remain Idiots After A Decade! > >A excerpt from the new book =E3=80=88Modern Perl=E3=80=89, just published, = >chapter 4 >on =E2=80=9COperators=E2=80=9D. Quote: > >=C2=ABThe associativity of an operator governs whether it evaluates from >left to right or right to left. Addition is left associative, such >that 2 + 3 + 4 evaluates 2 + 3 first, then adds 4 to the result. >Exponentiation is right associative, such that 2 ** 3 ** 4 evaluates 3 >** 4 first, then raises 2 to the 81st power. =C2=BB > >LOL. Looks like the perl folks haven't changed. Fundamentals of >serious math got botched so badly. You're confused. Associativity of operators is defined in mathematics. (The same concept may be used in programming). "left-associativity" and "right-associativity" are computer languages concept and their definitions are not from mathematics. Interestingly in mathematics associative means that it doesn't matter whether you use (a.b).c or a.(b.c). Using xxx-associativity to indicate that it *does* matter is a bit perverse, but the Perl people are not to blame if they use a term in their usual sense. Groetjes Albert -- -- Albert van der Horst, UTRECHT,THE NETHERLANDS Economic growth -- being exponential -- ultimately falters. albert at spe&ar&c.xs4all.nl &=n http://home.hccnet.nl/a.w.m.van.der.horst From spamtrap at library.lspace.org.invalid Mon Mar 12 08:40:56 2012 From: spamtrap at library.lspace.org.invalid (Shmuel Metz (Seymour J.)) Date: Mon, 12 Mar 2012 08:40:56 -0400 Subject: New Science Discovery: Perl Detractors Remain Idiots After A Decade References: <0078bbfb-5dfc-48fc-af1a-69de3cf15c3e@b1g2000yqb.googlegroups.com> Message-ID: <4f5deed8$6$fuzhry+tra$mr2ice@news.patriot.net> In , on 03/12/2012 at 11:27 AM, Albert van der Horst said: >You're confused. No, s/h/it is just an acephalic troll with delusions of adequacy. >"left-associativity" and "right-associativity" are computer >languages concept and their definitions are not from mathematics. Don't confuse the google pest with facts. -- Shmuel (Seymour J.) Metz, SysProg and JOAT Unsolicited bulk E-mail subject to legal action. I reserve the right to publicly post or ridicule any abusive E-mail. Reply to domain Patriot dot net user shmuel+news to contact me. Do not reply to spamtrap at library.lspace.org From robert.kern at gmail.com Mon Mar 12 08:47:27 2012 From: robert.kern at gmail.com (Robert Kern) Date: Mon, 12 Mar 2012 12:47:27 +0000 Subject: Raise X or Raise X()? In-Reply-To: <4F5DD1FC.7080603@sequans.com> References: <387014.2537.1331492695725.JavaMail.geo-discussion-forums@pbjv6> <4F5DD1FC.7080603@sequans.com> Message-ID: On 3/12/12 10:37 AM, Jean-Michel Pichavant wrote: > bvdp wrote: >> Which is preferred in a raise: X or X()? I've seen both. In my specific case >> I'm dumping out of a deep loop: >> >> try: >> for ... >> for ... >> for ... >> if match: >> raise StopInteration() >> else ... >> >> except StopInteration: >> print "found it" > > I prefer the raise X() version, it fulfils the zen of python : > > "Special cases aren't special enough to break the rules. > There should be one-- and preferably only one --obvious way to do it." > > I still wonder why they've added the class raise form, on which purpose. The class raise form used to be the only way to raise exceptions. To pass an argument, there was special syntax: raise Exception, "some message" This syntax has been done away with in Python 3 in favor of regular calling conventions. Python 3 still allows bare classes, though. I also prefer to always raise instances of exceptions rather than bare exception classes. It simplifies the mental model. -- Robert Kern "I have come to believe that the whole world is an enigma, a harmless enigma that is made terrible by our own mad attempt to interpret it as though it had an underlying truth." -- Umberto Eco From kiuhnm03.4t.yahoo.it Mon Mar 12 09:05:54 2012 From: kiuhnm03.4t.yahoo.it (Kiuhnm) Date: Mon, 12 Mar 2012 14:05:54 +0100 Subject: New Science Discovery: Perl Idiots Remain Idiots After A Decade!New Science Discovery: Perl Idiots Remain Idiots After A Decade! In-Reply-To: References: <0078bbfb-5dfc-48fc-af1a-69de3cf15c3e@b1g2000yqb.googlegroups.com> Message-ID: <4f5df4b3$0$1375$4fafbaef@reader1.news.tin.it> On 3/12/2012 12:27, Albert van der Horst wrote: > Interestingly in mathematics associative means that it doesn't matter > whether you use (a.b).c or a.(b.c). > Using xxx-associativity to indicate that it *does* matter is > a bit perverse, but the Perl people are not to blame if they use > a term in their usual sense. You may see it this way: Def1. An operator +:SxS->S is left-associative iff a+b+c = (a+b)+c for all a,b,c in S. Def2. An operator +:SxS->S is right-associative iff a+b+c = a+(b+c) for all a,b,c in S. Def3. An operator +:SxS->S is associative iff it is both left and right-associative. Kiuhnm From fil.oracle at gmail.com Mon Mar 12 09:06:32 2012 From: fil.oracle at gmail.com (James Elford) Date: Mon, 12 Mar 2012 13:06:32 +0000 Subject: Raise X or Raise X()? In-Reply-To: <387014.2537.1331492695725.JavaMail.geo-discussion-forums@pbjv6> References: <387014.2537.1331492695725.JavaMail.geo-discussion-forums@pbjv6> Message-ID: <4F5DF4D8.20901@gmail.com> On 11/03/12 19:04, bvdp wrote: > Which is preferred in a raise: X or X()? I've seen both. In my specific case I'm dumping out of a deep loop: > > try: > for ... > for ... > for ... > if match: > raise StopInteration() > else ... > > except StopInteration: > print "found it" I wonder whether you need to use an exception here rather than a yield statement? Exceptions should reflect Exceptional circumstances (and come with associated stack trace, and so on...). The following should do something like what you want, without raising exceptions. >>> # Deeply loop into a collection of collections >>> def find(collection): ... for sub_col in collection: ... for item in sub_col: ... for foo in item.list_field: ... if foo.is_match: ... yield foo >>> # Some junk classes to iterate over >>> class Item(object): ... def __init__(self, some_range): ... self.list_field = [ListedItem(i) for i in some_range] >>> class ListedItem(object): ... def __init__(self, number): ... self.tag = number ... self.is_match = False >>> def __str__(self): ... return str(self.tag) >>> # Construct a list of items >>> l = [[Item(range(i)) for i in range(10)], ... [Item(range(i, 2*i)) for i in range(10,20)]] >>> l[0][9].list_field[3].is_match = True >>> for i in find(l): ... print(i) 3 James From rosuav at gmail.com Mon Mar 12 09:13:57 2012 From: rosuav at gmail.com (Chris Angelico) Date: Tue, 13 Mar 2012 00:13:57 +1100 Subject: Raise X or Raise X()? In-Reply-To: <4F5DF4D8.20901@gmail.com> References: <387014.2537.1331492695725.JavaMail.geo-discussion-forums@pbjv6> <4F5DF4D8.20901@gmail.com> Message-ID: On Tue, Mar 13, 2012 at 12:06 AM, James Elford wrote: > I wonder whether you need to use an exception here rather than a yield > statement? Or a return statement, if you're not needing multiple responses. ChrisA From roy at panix.com Mon Mar 12 09:27:02 2012 From: roy at panix.com (Roy Smith) Date: Mon, 12 Mar 2012 09:27:02 -0400 Subject: What's the best way to parse this HTML tag? References: <239c4ad7-ac93-45c5-98d6-71a434e1c5aa@r21g2000yqa.googlegroups.com> Message-ID: In article , John Salerno wrote: > Well, I had considered exactly that method, but I don't know for sure > if the titles and names will always have links like that, so I didn't > want to tie my programming to something so specific. But perhaps it's > still better than just taking the first two strings. Such is the nature of screen scraping. For the most part, web pages are not meant to be parsed. If you decide to go down the road of trying to extract data from them, all bets are off. You look at the markup, take your best guess, and go for it. There's no magic here. Nobody can look at this HTML and come up with some hard and fast rule for how you're supposed to parse it. And, even if they could, it's all likely to change tomorrow when the site rolls out their next UI makeover. From stefan_ml at behnel.de Mon Mar 12 09:52:49 2012 From: stefan_ml at behnel.de (Stefan Behnel) Date: Mon, 12 Mar 2012 14:52:49 +0100 Subject: Raise X or Raise X()? In-Reply-To: <4f5d0d06$0$6856$e4fe514c@news2.news.xs4all.nl> References: <387014.2537.1331492695725.JavaMail.geo-discussion-forums@pbjv6> <4f5d0d06$0$6856$e4fe514c@news2.news.xs4all.nl> Message-ID: Irmen de Jong, 11.03.2012 21:37: > On 11-3-2012 20:04, bvdp wrote: >> Which is preferred in a raise: X or X()? I've seen both. In my specific case I'm dumping out of a deep loop: >> >> try: >> for ... >> for ... >> for ... >> if match: >> raise StopInteration() >> else ... >> >> except StopInteration: >> print "found it" > > "raise X" is a special case of the 3-args raise. Effectively it just raises an instance > of X which is constructed with an empty argument list. Therefore, "raise X()" is > equivalent, as far as I know. Not completely, although that may be considered an implementation detail. When you raise an exception instance, it gets instantiated before being raised (by your own code). So you control exactly how the exception instance comes to life. When you raise the class instead of the instance, it may or may not get instantiated, depending on how it is being caught or discarded (and by whom, e.g. internally in the interpreter). In most cases, it will be instantiated, but only when someone catches it, i.e. at a later time, after raising it. If the instantiation of the exception has side effects, or if it fails for some reason (e.g. bad or missing arguments), the time of instantiation may make a difference. It's obviously bad design to use side effects here, but it's equally bad design to silently rely on it being side effect free. Note that if the exception happens to never get instantiated, you will safe a tiny bit of time for the overall propagation. But since it's hard to tell if that will happen or not, it would be a rather misguided micro optimisation for most Python code to base your decision on this, at least without prior benchmarking (with a real work-load etc.). In general, I tend to raise exception types only for very safe and common built-in exceptions, such as StopIteration, but whenever they take an argument, I raise the instance instead. For user provided exceptions, there is no real excuse for raising the type. BTW, StopIteration takes an optional argument in Python 3.3, but that's not a feature that is generally going to be used by Python code, I assume. So I'll just keep raising the type. :) Stefan From steve+comp.lang.python at pearwood.info Mon Mar 12 11:08:49 2012 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 12 Mar 2012 15:08:49 GMT Subject: Raise X or Raise X()? References: <387014.2537.1331492695725.JavaMail.geo-discussion-forums@pbjv6> <4f5d0d06$0$6856$e4fe514c@news2.news.xs4all.nl> Message-ID: <4f5e1180$0$29891$c3e8da3$5496439d@news.astraweb.com> On Mon, 12 Mar 2012 14:52:49 +0100, Stefan Behnel wrote: >> "raise X" is a special case of the 3-args raise. Effectively it just >> raises an instance of X which is constructed with an empty argument >> list. Therefore, "raise X()" is equivalent, as far as I know. > > Not completely, although that may be considered an implementation > detail. > > When you raise an exception instance, it gets instantiated before being > raised (by your own code). So you control exactly how the exception > instance comes to life. Normally the exception is instantiated just before you raise it. Of course, that's not compulsory. You can pre-load it if you want: instance = ValueError("spam") time.sleep(60) raise instance but generally we say raise ValueError("spam") and be done with it. > When you raise the class instead of the instance, it may or may not get > instantiated, depending on how it is being caught or discarded (and by > whom, e.g. internally in the interpreter). In most cases, it will be > instantiated, but only when someone catches it, i.e. at a later time, > after raising it. I don't think that is correct. Either the exception gets raised, or it doesn't. If it doesn't get raised, then no instance is instantiated (unless you did it yourself, as in the example above). But if it does get raised, then regardless of which form you use (the class or the instance), the exception instance *will* be instantiated. If you don't do it yourself, the raise statement will do it. Using Python 3.2: >>> class TestException(Exception): ... def __init__(self, *args): ... print("initialising exception") ... super().__init__(*args) ... >>> try: ... raise TestException ... except: ... pass ... initialising exception Whether you catch the exception or not, it still gets instantiated. Try it and see, and if you can find some way to actually raise the exception without instantiating the instance, I would love to see it. Implementation-wise, at least for Python 3.2, what seems to happen as best as I can tell from reading ceval.c, is that the opcode for raise checks the argument. If it is already an instance, it uses that; if it is not, it instantiates it immediately. (see function do_raise in ceval.c) So, technically, there may be a minuscule timing difference depending on whether you instantiate the exception in Python code or in C code, but I don't believe that this meaningful. > If the instantiation of the exception has side > effects, or if it fails for some reason (e.g. bad or missing arguments), > the time of instantiation may make a difference. I expect this is only relevant if you pre-instantiate the exception ahead of time. I suppose it is conceivable that, in a particularly odd corner case or two (perhaps using exceptions with side effects and/or threads or something) the nanosecond difference between raise X() and raise X might make a difference. But I'm having difficulty seeing that this is plausible. I think you will have to show me an example to prove it. Certainly, without threads, I don't think there is any difference. > It's obviously bad > design to use side effects here, but it's equally bad design to silently > rely on it being side effect free. I don't understand what you are trying to say here. We rely on code being side-effect free *all the time*. Or at least known side-effects, such as import or list.append. > Note that if the exception happens to never get instantiated, you will > safe a tiny bit of time for the overall propagation. I don't believe that is true. Looking at the C code, the exception appears to always be instantiated once you call raise. > But since it's hard > to tell if that will happen or not, it would be a rather misguided micro > optimisation for most Python code to base your decision on this, at > least without prior benchmarking (with a real work-load etc.). > > In general, I tend to raise exception types only for very safe and > common built-in exceptions, such as StopIteration, but whenever they > take an argument, I raise the instance instead. For user provided > exceptions, there is no real excuse for raising the type. My excuses are: * sometimes I don't need an error message, so why give one? * and it makes no difference whether I instantiate the exception or let raise do it for me > BTW, StopIteration takes an optional argument in Python 3.3, The time machine strikes again. StopIteration takes an optional argument going back to at least 2.6. steve at runes:~$ python2.6 Python 2.6.6 (r266:84292, Dec 27 2010, 00:02:40) [GCC 4.4.5] on linux2 Type "help", "copyright", "credits" or "license" for more information. >>> raise StopIteration("out of fuel") Traceback (most recent call last): File "", line 1, in StopIteration: out of fuel -- Steven From nagle at animats.com Mon Mar 12 12:07:56 2012 From: nagle at animats.com (John Nagle) Date: Mon, 12 Mar 2012 09:07:56 -0700 Subject: html5lib not thread safe. Is the Python SAX library thread-safe? In-Reply-To: References: <4f5d0b82$0$11967$742ec2ed@news.sonic.net> Message-ID: <4f5e1f5b$0$12023$742ec2ed@news.sonic.net> On 3/12/2012 3:05 AM, Stefan Behnel wrote: > John Nagle, 11.03.2012 21:30: >> "html5lib" is apparently not thread safe. >> (see "http://code.google.com/p/html5lib/issues/detail?id=189") >> Looking at the code, I've only found about three problems. >> They're all the usual "cached in a global without locking" bug. >> A few locks would fix that. >> >> But html5lib calls the XML SAX parser. Is that thread-safe? >> Or is there more trouble down at the bottom? >> >> (I run a multi-threaded web crawler, and currently use BeautifulSoup, >> which is thread safe, although dated. I'm looking at converting to >> html5lib.) > > You may also consider moving to lxml. BeautifulSoup supports it as a parser > backend these days, so you wouldn't even have to rewrite your code to use > it. And performance-wise, well ... > > http://blog.ianbicking.org/2008/03/30/python-html-parser-performance/ > > Stefan I want to move to html5lib because it handles HTML errors as specified by the HTML5 spec, which is what all newer browsers do. The HTML5 spec actually specifies, in great detail, how to parse common errors in HTML. It's amusing seeing that formalized. Malformed comments ( <- instead of <-- ) are now handled in a standard way, for example. So I'm trying to get html5parser fixed for thread safety. John Nagle From stefan_ml at behnel.de Mon Mar 12 12:08:09 2012 From: stefan_ml at behnel.de (Stefan Behnel) Date: Mon, 12 Mar 2012 17:08:09 +0100 Subject: Raise X or Raise X()? In-Reply-To: <4f5e1180$0$29891$c3e8da3$5496439d@news.astraweb.com> References: <387014.2537.1331492695725.JavaMail.geo-discussion-forums@pbjv6> <4f5d0d06$0$6856$e4fe514c@news2.news.xs4all.nl> <4f5e1180$0$29891$c3e8da3$5496439d@news.astraweb.com> Message-ID: Steven D'Aprano, 12.03.2012 16:08: > On Mon, 12 Mar 2012 14:52:49 +0100, Stefan Behnel wrote: >>> "raise X" is a special case of the 3-args raise. Effectively it just >>> raises an instance of X which is constructed with an empty argument >>> list. Therefore, "raise X()" is equivalent, as far as I know. >> >> Not completely, although that may be considered an implementation >> detail. >> >> When you raise an exception instance, it gets instantiated before being >> raised (by your own code). So you control exactly how the exception >> instance comes to life. > >> When you raise the class instead of the instance, it may or may not get >> instantiated, depending on how it is being caught or discarded (and by >> whom, e.g. internally in the interpreter). In most cases, it will be >> instantiated, but only when someone catches it, i.e. at a later time, >> after raising it. > > I don't think that is correct. Either the exception gets raised, or it > doesn't. If it doesn't get raised, then no instance is instantiated > (unless you did it yourself, as in the example above). But if it does get > raised, then regardless of which form you use (the class or the > instance), the exception instance *will* be instantiated. If you don't do > it yourself, the raise statement will do it. > > Using Python 3.2: Note that the exception handling was seriously reworked in Python 3, so there are substantial differences to Python 2. Although maybe not so many at the Python code level. > >>> class TestException(Exception): > .... def __init__(self, *args): > .... print("initialising exception") > .... super().__init__(*args) > .... > >>> try: > .... raise TestException > .... except: > .... pass > .... > initialising exception > > Whether you catch the exception or not, it still gets instantiated. Try > it and see, and if you can find some way to actually raise the exception > without instantiating the instance, I would love to see it. > > Implementation-wise, at least for Python 3.2, what seems to happen as > best as I can tell from reading ceval.c, is that the opcode for raise > checks the argument. If it is already an instance, it uses that; if it is > not, it instantiates it immediately. > > (see function do_raise in ceval.c) Right, it normalises the exception immediately, also in older Python versions. That's different at the C layer, but it looks like the interpreter does the right (i.e. only safe) thing for Python code. Good to know - and thanks for clearing this up. > So, technically, there may be a minuscule timing difference depending on > whether you instantiate the exception in Python code or in C code, but I > don't believe that this meaningful. The difference can be substantial in C code, especially for something like StopIteration if the instantiation can be avoided (in some cases even raising the exception is avoided completely!). However, given that Python code apparently can't raise types without instantiating them, I agree that it's not worth looking for a difference at that level. > I suppose it is conceivable that, in a particularly odd corner case or > two (perhaps using exceptions with side effects and/or threads or > something) the nanosecond difference between raise X() and raise X might > make a difference. But I'm having difficulty seeing that this is > plausible. I think you will have to show me an example to prove it. > > Certainly, without threads, I don't think there is any difference. Even with threads it will be hard to get at this difference due to the GIL. I can't see anything in do_raise() that would allow foreign code to run between the evaluation of the "raise" opcode and starting to instantiate the exception. >> It's obviously bad >> design to use side effects here, but it's equally bad design to silently >> rely on it being side effect free. > > I don't understand what you are trying to say here. We rely on code being > side-effect free *all the time*. That's fine for builtin stuff, functions etc. But for user provided exceptions, why should you make your code dependent on a side effect free instantiation just to be able to raise them without parentheses? Sounds like too little a gain to me. Besides, this is getting way hypothetical. >> Note that if the exception happens to never get instantiated, you will >> safe a tiny bit of time for the overall propagation. > > I don't believe that is true. Looking at the C code, the exception > appears to always be instantiated once you call raise. My fault, I was thinking at the C level again. >> BTW, StopIteration takes an optional argument in Python 3.3, > > The time machine strikes again. StopIteration takes an optional argument > going back to at least 2.6. > > steve at runes:~$ python2.6 > Python 2.6.6 (r266:84292, Dec 27 2010, 00:02:40) > [GCC 4.4.5] on linux2 > Type "help", "copyright", "credits" or "license" for more information. > >>> raise StopIteration("out of fuel") > Traceback (most recent call last): > File "", line 1, in > StopIteration: out of fuel Right, I think it's even at least 2.4 and likely much older than that. What I meant to say was that StopIteration has a "value" (an actual property) in Python 3.3, which represents its first argument. So that argument actually has specific semantics (see PEP 380), instead of just "being there". Stefan From tjreedy at udel.edu Mon Mar 12 12:11:32 2012 From: tjreedy at udel.edu (Terry Reedy) Date: Mon, 12 Mar 2012 12:11:32 -0400 Subject: How Python empowers Java? In-Reply-To: <90d7a28f-8d7b-4623-88ea-07e0e101b4e3@ni10g2000pbc.googlegroups.com> References: <90d7a28f-8d7b-4623-88ea-07e0e101b4e3@ni10g2000pbc.googlegroups.com> Message-ID: On 3/12/2012 1:39 AM, Ashish Aggarwal wrote: > I am a Java developer but new to Python. > I am trying to assess, as what are new capabilities that Python will > provide me if I use it with Java. > > Guys can you please help me? 1. Jython is a Python interpreter (older version) implemented in Java. It accesses Java classes located on the same machine. I believe it has an interactive mode just like CPython. So you can experiment interactively with the behavior of Java code. You can also write test suites for Java code in Jython. This is one actual use of Jython. 2. Learning a different object model may help you understand Java better. -- Terry Jan Reedy From raw at unknown-00-23-6c-8d-9e-26.lan Mon Mar 12 14:20:26 2012 From: raw at unknown-00-23-6c-8d-9e-26.lan (Raymond Wiker) Date: Mon, 12 Mar 2012 19:20:26 +0100 Subject: New Science Discovery: Perl Detractors Remain Idiots After A Decade References: <0078bbfb-5dfc-48fc-af1a-69de3cf15c3e@b1g2000yqb.googlegroups.com> <4f5deed8$6$fuzhry+tra$mr2ice@news.patriot.net> Message-ID: Shmuel (Seymour J.) Metz writes: > In , on 03/12/2012 > at 11:27 AM, Albert van der Horst said: > >>You're confused. > > No, s/h/it is just an acephalic troll with delusions of adequacy. Another way to put it is to say that Xah is a legend in his own mind. From albert at spenarnc.xs4all.nl Mon Mar 12 15:00:30 2012 From: albert at spenarnc.xs4all.nl (Albert van der Horst) Date: 12 Mar 2012 19:00:30 GMT Subject: New Science Discovery: Perl Idiots Remain Idiots After A Decade!New Science Discovery: Perl Idiots Remain Idiots After A Decade! References: <0078bbfb-5dfc-48fc-af1a-69de3cf15c3e@b1g2000yqb.googlegroups.com> <4f5df4b3$0$1375$4fafbaef@reader1.news.tin.it> Message-ID: In article <4f5df4b3$0$1375$4fafbaef at reader1.news.tin.it>, Kiuhnm wrote: >On 3/12/2012 12:27, Albert van der Horst wrote: >> Interestingly in mathematics associative means that it doesn't matter >> whether you use (a.b).c or a.(b.c). >> Using xxx-associativity to indicate that it *does* matter is >> a bit perverse, but the Perl people are not to blame if they use >> a term in their usual sense. > >You may see it this way: >Def1. An operator +:SxS->S is left-associative iff > a+b+c = (a+b)+c for all a,b,c in S. >Def2. An operator +:SxS->S is right-associative iff > a+b+c = a+(b+c) for all a,b,c in S. >Def3. An operator +:SxS->S is associative iff it is both left and >right-associative. I know, but what the mathematicians do make so much more sense: (a+b)+c = a+(b+c) definition of associative. Henceforth we may leave out the brackets. Don't leave out the brackets if the operators if the operators is not associative. P.S. There is no need for the operators to be SxS->S. For example a b c may be m by n, n by l, l by k matrices respectively. > >Kiuhnm Groetjes Albert -- -- Albert van der Horst, UTRECHT,THE NETHERLANDS Economic growth -- being exponential -- ultimately falters. albert at spe&ar&c.xs4all.nl &=n http://home.hccnet.nl/a.w.m.van.der.horst From vs at it.uu.se Mon Mar 12 15:39:34 2012 From: vs at it.uu.se (Virgil Stokes) Date: Mon, 12 Mar 2012 20:39:34 +0100 Subject: Fast file data retrieval? Message-ID: <4F5E50F6.9070309@it.uu.se> I have a rather large ASCII file that is structured as follows header line 9 nonblank lines with alphanumeric data header line 9 nonblank lines with alphanumeric data ... ... ... header line 9 nonblank lines with alphanumeric data EOF where, a data set contains 10 lines (header + 9 nonblank) and there can be several thousand data sets in a single file. In addition,*each header has a* *unique ID code*. Is there a fast method for the retrieval of a data set from this large file given its ID code? -------------- next part -------------- An HTML attachment was scrubbed... URL: From spamtrap at library.lspace.org.invalid Mon Mar 12 16:20:22 2012 From: spamtrap at library.lspace.org.invalid (Shmuel Metz (Seymour J.)) Date: Mon, 12 Mar 2012 16:20:22 -0400 Subject: New Science Discovery: Perl Idiots Remain Idiots After A Decade!New Science Discovery: Perl Idiots Remain Idiots Af References: <0078bbfb-5dfc-48fc-af1a-69de3cf15c3e@b1g2000yqb.googlegroups.com> <4f5df4b3$0$1375$4fafbaef@reader1.news.tin.it> Message-ID: <4f5e5a86$10$fuzhry+tra$mr2ice@news.patriot.net> In , on 03/12/2012 at 07:00 PM, Albert van der Horst said: >I know, but what the mathematicians do make so much more sense: Not really; Mathematical notation is a matter of convention, and the conventions owe as much to History as they do to logical necessity. The conventions aren't even the same from author to author, e.g., whether "field" implies Abelian. -- Shmuel (Seymour J.) Metz, SysProg and JOAT Unsolicited bulk E-mail subject to legal action. I reserve the right to publicly post or ridicule any abusive E-mail. Reply to domain Patriot dot net user shmuel+news to contact me. Do not reply to spamtrap at library.lspace.org From kiuhnm03.4t.yahoo.it Mon Mar 12 16:27:25 2012 From: kiuhnm03.4t.yahoo.it (Kiuhnm) Date: Mon, 12 Mar 2012 21:27:25 +0100 Subject: New Science Discovery: Perl Idiots Remain Idiots After A Decade!New Science Discovery: Perl Idiots Remain Idiots After A Decade! In-Reply-To: References: <0078bbfb-5dfc-48fc-af1a-69de3cf15c3e@b1g2000yqb.googlegroups.com> <4f5df4b3$0$1375$4fafbaef@reader1.news.tin.it> Message-ID: <4f5e5c2f$0$1379$4fafbaef@reader2.news.tin.it> On 3/12/2012 20:00, Albert van der Horst wrote: > In article<4f5df4b3$0$1375$4fafbaef at reader1.news.tin.it>, > Kiuhnm wrote: >> On 3/12/2012 12:27, Albert van der Horst wrote: >>> Interestingly in mathematics associative means that it doesn't matter >>> whether you use (a.b).c or a.(b.c). >>> Using xxx-associativity to indicate that it *does* matter is >>> a bit perverse, but the Perl people are not to blame if they use >>> a term in their usual sense. >> >> You may see it this way: >> Def1. An operator +:SxS->S is left-associative iff >> a+b+c = (a+b)+c for all a,b,c in S. >> Def2. An operator +:SxS->S is right-associative iff >> a+b+c = a+(b+c) for all a,b,c in S. >> Def3. An operator +:SxS->S is associative iff it is both left and >> right-associative. > > I know, but what the mathematicians do make so much more sense: > (a+b)+c = a+(b+c) definition of associative. > Henceforth we may leave out the brackets. That's Def3. I don't see your point. > Don't leave out the brackets if the operators if the operators is > not associative. (1 - 1) - 1 != 1 - (1 - 1) and yet we can leave out the parentheses. > P.S. There is no need for the operators to be SxS->S. > For example a b c may be m by n, n by l, l by k matrices respectively. Ops, you're right. Kiuhnm From arnodel at gmail.com Mon Mar 12 16:31:26 2012 From: arnodel at gmail.com (Arnaud Delobelle) Date: Mon, 12 Mar 2012 20:31:26 +0000 Subject: Fast file data retrieval? In-Reply-To: <4F5E50F6.9070309@it.uu.se> References: <4F5E50F6.9070309@it.uu.se> Message-ID: On 12 March 2012 19:39, Virgil Stokes wrote: > I have a rather large ASCII file that is structured as follows > > header line > 9 nonblank lines with alphanumeric data > header line > 9 nonblank lines with alphanumeric data > ... > ... > ... > header line > 9 nonblank lines with alphanumeric data > EOF > > where, a data set contains 10 lines (header + 9 nonblank) and there can be > several thousand > data sets in a single file. In addition, each header has a unique ID code. > > Is there a fast method for the retrieval of a data set from this large file > given its ID code? It depends. I guess if it's a long running application, you could load up all the data into a dictionary at startup time (several thousand data sets doesn't sound like that much). Another option would be to put all this into a dbm database file (http://docs.python.org/library/dbm.html) - it would be very easy to do. Or you could have your own custom solution where you scan the file and build a dictionary mapping keys to file offsets, then when requesting a dataset you can seek directly to the correct position. -- Arnaud From python at mrabarnett.plus.com Mon Mar 12 16:31:35 2012 From: python at mrabarnett.plus.com (MRAB) Date: Mon, 12 Mar 2012 20:31:35 +0000 Subject: Fast file data retrieval? In-Reply-To: <4F5E50F6.9070309@it.uu.se> References: <4F5E50F6.9070309@it.uu.se> Message-ID: <4F5E5D27.4010403@mrabarnett.plus.com> On 12/03/2012 19:39, Virgil Stokes wrote: > I have a rather large ASCII file that is structured as follows > > header line > 9 nonblank lines with alphanumeric data > header line > 9 nonblank lines with alphanumeric data > ... > ... > ... > header line > 9 nonblank lines with alphanumeric data > EOF > > where, a data set contains 10 lines (header + 9 nonblank) and there can > be several thousand > data sets in a single file. In addition,*each header has a* *unique ID > code*. > > Is there a fast method for the retrieval of a data set from this large > file given its ID code? > Probably the best solution is to put it into a database. Have a look at the sqlite3 module. Alternatively, you could scan the file, recording the ID and the file offset in a dict so that, given an ID, you can seek directly to that file position. From drsalists at gmail.com Mon Mar 12 16:33:26 2012 From: drsalists at gmail.com (Dan Stromberg) Date: Mon, 12 Mar 2012 13:33:26 -0700 Subject: Fast file data retrieval? In-Reply-To: <4F5E50F6.9070309@it.uu.se> References: <4F5E50F6.9070309@it.uu.se> Message-ID: If the ID's are sorted, you could probably rig a binary search using seek. This'll be easier if the records have a constant length, but it's still possible for variable-length, just messier. Otherwise you could stash them all in a dictionary (in memory) or anydbm (on disk) to get indexed access. On Mon, Mar 12, 2012 at 12:39 PM, Virgil Stokes wrote: > I have a rather large ASCII file that is structured as follows > > header line > 9 nonblank lines with alphanumeric data > header line > 9 nonblank lines with alphanumeric data > ... > ... > ... > header line > 9 nonblank lines with alphanumeric data > EOF > > where, a data set contains 10 lines (header + 9 nonblank) and there can be > several thousand > data sets in a single file. In addition,* each header has a* *unique ID > code*. > > Is there a fast method for the retrieval of a data set from this large > file given its ID code? > > > -- > http://mail.python.org/mailman/listinfo/python-list > > -------------- next part -------------- An HTML attachment was scrubbed... URL: From alec.taylor6 at gmail.com Mon Mar 12 16:38:29 2012 From: alec.taylor6 at gmail.com (Alec Taylor) Date: Tue, 13 Mar 2012 07:38:29 +1100 Subject: PyCrypto builds neither with MSVC nor MinGW In-Reply-To: References: <35da69c3-edcc-4466-8a0d-70237c88af3b@qv4g2000pbc.googlegroups.com> Message-ID: On a brand new Windows install now, with a brand new VS8 installed with new YASM and MPIR in c:\usr\src\include and c:\usr\src\lib. But it still isn't working: C:\workingdir\pycrypto>python setup.py build_ext -Ic:\usr\src\include -Lc:\usr\src\lib install running build_ext warning: GMP or MPIR library not found; Not building Crypto.PublicKey._fastmath. building 'Crypto.Random.OSRNG.winrandom' extension Traceback (most recent call last): File "setup.py", line 452, in core.setup(**kw) File "C:\Python27\lib\distutils\core.py", line 152, in setup dist.run_commands() File "C:\Python27\lib\distutils\dist.py", line 953, in run_commands self.run_command(cmd) File "C:\Python27\lib\distutils\dist.py", line 972, in run_command cmd_obj.run() File "setup.py", line 249, in run build_ext.run(self) File "C:\Python27\lib\distutils\command\build_ext.py", line 339, in run self.build_extensions() File "setup.py", line 146, in build_extensions build_ext.build_extensions(self) File "C:\Python27\lib\distutils\command\build_ext.py", line 448, in build_extensions self.build_extension(ext) File "C:\Python27\lib\distutils\command\build_ext.py", line 498, in build_extension depends=ext.depends) File "C:\Python27\lib\distutils\msvc9compiler.py", line 473, in compile self.initialize() File "C:\Python27\lib\distutils\msvc9compiler.py", line 383, in initialize vc_env = query_vcvarsall(VERSION, plat_spec) File "C:\Python27\lib\distutils\msvc9compiler.py", line 299, in query_vcvarsall raise ValueError(str(list(result.keys()))) ValueError: [u'path'] On Wed, Feb 8, 2012 at 11:31 PM, Case Van Horsen wrote: > On Wed, Feb 8, 2012 at 4:24 AM, Alec Taylor wrote: >> Thanks, but to get it to work with pip, wouldn't I need to add it to >> PATH? - Or can I just add those library args to pip? > I don't think so. pyCrypto probably builds a single DLL so the MPIR library is > statically linked into that DLL. Only the innvocation of setup.py should need > to refer to the MPIR library locations. ?I don't use pip so I'm not sure how to > get pip to install the resulting DLL, etc. >> >> On Wed, Feb 8, 2012 at 9:48 PM, Case Van Horsen wrote: >>> On Tue, Feb 7, 2012 at 9:37 PM, Alec Taylor wrote: >>>> Thanks all for your replies. >>>> >>>> I have now installed MSVC8 and YASM. >>> I assume you installed Visual Studio. I've omitted the commands to use >>> the SDK compiler below. >>>> >>>> I was able to successfully run configure.bat and make.bat (including >>>> make.bat check). >>>> >>>> However, I'm unsure what to do about install, since there is no >>>> install arg. Do I copy it across to my VC\bin folder, or does it need >>>> it's own place in PATH + system variables? >>> >>> The following is just a guess. >>> >>> I copy the files to a convenient location and then specify that >>> location to setup.py. Below is an excerpt from my build process. >>> >>> mkdir c:\src\lib >>> mkdir c:\src\include >>> xcopy /Y mpir.h c:\src\include\*.* >>> xcopy /Y win\mpir.lib c:\src\lib\*.* >>> >>> python setup.py build_ext -Ic:\src\include -Lc:\src\lib install >>> >>>> >>>> I am asking because I don't know where it is looking for the MPIR library. >>>> >>>> Thanks for all suggestions, >>>> >>>> Alec Taylor From ramit.prasad at jpmorgan.com Mon Mar 12 17:09:05 2012 From: ramit.prasad at jpmorgan.com (Prasad, Ramit) Date: Mon, 12 Mar 2012 21:09:05 +0000 Subject: Fast file data retrieval? In-Reply-To: <4F5E5D27.4010403@mrabarnett.plus.com> References: <4F5E50F6.9070309@it.uu.se> <4F5E5D27.4010403@mrabarnett.plus.com> Message-ID: <5B80DD153D7D744689F57F4FB69AF4741C2692@SCACMX008.exchad.jpmchase.net> > > header line > > 9 nonblank lines with alphanumeric data > > header line > > 9 nonblank lines with alphanumeric data > > ... > > ... > > ... > > header line > > 9 nonblank lines with alphanumeric data > > EOF > > > > where, a data set contains 10 lines (header + 9 nonblank) and there can > > be several thousand > > data sets in a single file. In addition,*each header has a* *unique ID > > code*. > Alternatively, you could scan the file, recording the ID and the file > offset in a dict so that, given an ID, you can seek directly to that > file position. If you can grep for the header lines you can retrieve the headers and the line number for seeking. grep is (probably) faster than python so I would have it be 2 steps. 1. grep > temp.txt 2. python; check if ID is in temp.txt and then processes Ramit Ramit Prasad | JPMorgan Chase Investment Bank | Currencies Technology 712 Main Street | Houston, TX 77002 work phone: 713 - 216 - 5423 -- This email is confidential and subject to important disclaimers and conditions including on offers for the purchase or sale of securities, accuracy and completeness of information, viruses, confidentiality, legal privilege, and legal entity disclaimers, available at http://www.jpmorgan.com/pages/disclosures/email. From alec.taylor6 at gmail.com Mon Mar 12 17:21:51 2012 From: alec.taylor6 at gmail.com (Alec Taylor) Date: Tue, 13 Mar 2012 08:21:51 +1100 Subject: PyCrypto builds neither with MSVC nor MinGW In-Reply-To: References: <35da69c3-edcc-4466-8a0d-70237c88af3b@qv4g2000pbc.googlegroups.com> Message-ID: FYI: When running "vcvarsall" manually, I get a variety of linker errors, even though I have the SDK and everything else installed: running build_ext building 'Crypto.Random.OSRNG.winrandom' extension C:\Program Files (x86)\Microsoft Visual Studio 9.0\VC\BIN\cl.exe /c /nologo /Ox /MD /W3 /GS- /DNDEBUG -Isrc/ -Isrc/inc-msvc/ -Ic:\usr\src\include -IC:\Python27\include -IC:\Python27\PC /Tcsrc/winrand.c /Fobuild\temp.win-amd64-2.7\Release\src/winrand.obj winrand.c C:\Program Files (x86)\Microsoft Visual Studio 9.0\VC\BIN\link.exe /DLL /nologo /INCREMENTAL:NO /LIBPATH:c:\usr\src\lib /LIBPATH:C:\Python27\libs /LIBPATH:C:\Python27\PCbuild\amd64 ws2_32.lib advapi32.lib /EXPORT:initwinrandom build\temp.win-amd64-2.7\Release\src/winrand.obj /OUT:build\lib.win-amd64-2.7\Crypto\Random\OSRNG\winrandom.pyd /IMPLIB:build\temp.win-amd64-2.7\Release\src\winrandom.lib /MANIFESTFILE:build\temp.win-amd64-2.7\Release\src\winrandom.pyd.manifest Creating library build\temp.win-amd64-2.7\Release\src\winrandom.lib and object build\temp.win-amd64-2.7\Release\src\winrandom.exp winrand.obj : error LNK2019: unresolved external symbol __imp__PyObject_Free referenced in function _WRdealloc winrand.obj : error LNK2019: unresolved external symbol __imp__PyExc_SystemError referenced in function _WRdealloc winrand.obj : error LNK2019: unresolved external symbol __imp__PyErr_Format referenced in function _WRdealloc winrand.obj : error LNK2019: unresolved external symbol __imp__PyExc_TypeError referenced in function _WRdealloc winrand.obj : error LNK2019: unresolved external symbol __imp___PyObject_New referenced in function _winrandom_new winrand.obj : error LNK2019: unresolved external symbol __imp__PyArg_ParseTupleAndKeywords referenced in function _winrandom_new winrand.obj : error LNK2019: unresolved external symbol __imp__PyString_FromStringAndSize referenced in function _WR_get_bytes winrand.obj : error LNK2019: unresolved external symbol __imp__PyMem_Free referenced in function _WR_get_bytes winrand.obj : error LNK2019: unresolved external symbol __imp__PyErr_NoMemory referenced in function _WR_get_bytes winrand.obj : error LNK2019: unresolved external symbol __imp__PyMem_Malloc referenced in function _WR_get_bytes winrand.obj : error LNK2019: unresolved external symbol __imp__PyErr_SetString referenced in function _WR_get_bytes winrand.obj : error LNK2019: unresolved external symbol __imp__PyExc_ValueError referenced in function _WR_get_bytes winrand.obj : error LNK2019: unresolved external symbol __imp__PyArg_ParseTuple referenced in function _WR_get_bytes winrand.obj : error LNK2019: unresolved external symbol __imp__Py_FindMethod referenced in function _WRgetattr winrand.obj : error LNK2019: unresolved external symbol __imp__PyInt_FromLong referenced in function _WRgetattr winrand.obj : error LNK2019: unresolved external symbol __imp__Py_FatalError referenced in function _initwinrandom winrand.obj : error LNK2019: unresolved external symbol __imp__PyErr_Occurred referenced in function _initwinrandom winrand.obj : error LNK2019: unresolved external symbol __imp__PyModule_AddStringConstant referenced in function _initwinrandom winrand.obj : error LNK2019: unresolved external symbol __imp__PyModule_AddIntConstant referenced in function _initwinrandom winrand.obj : error LNK2019: unresolved external symbol __imp__Py_InitModule4 referenced in function _initwinrandom winrand.obj : error LNK2019: unresolved external symbol __imp__PyType_Type referenced in function _initwinrandom build\lib.win-amd64-2.7\Crypto\Random\OSRNG\winrandom.pyd : fatal error LNK1120: 21 unresolved externals From rosuav at gmail.com Mon Mar 12 17:59:14 2012 From: rosuav at gmail.com (Chris Angelico) Date: Tue, 13 Mar 2012 08:59:14 +1100 Subject: How to break long method name into more than one line? In-Reply-To: References: <4f5d4390$0$29891$c3e8da3$5496439d@news.astraweb.com> Message-ID: On Tue, Mar 13, 2012 at 3:24 AM, Dennis Lee Bieber wrote: > On 12 Mar 2012 00:30:08 GMT, Steven D'Aprano > declaimed the following in > gmane.comp.python.general: >> I expect that naming rule was invented by either people who have heard of >> test driven development, but never actually done it, or by people so >> anally-retentive that if they make seven short car trips over an hour, >> they check the tyre pressure, oil and water seven times because "the >> manual says to check before *every* trip". >> > ? ? ? ?By which time they find they have to add air, oil, and water as: the > pressure gauge usage lets out some air each time; they've wiped a few > drops of oil onto a rag each time; and the radiator was still > hot&pressurized such that they got an "overfull" result. In defense of such rules: There's a period in every new programmer's life when it helps to learn a whole lot of principles; and if he's working on some collaborative project, rules are the easiest way to demand such behavior. Later on, you learn how and when it's safe to break the rules (and/or how to deal with rule conflicts), but the rules still have value. Just never treat them as laws of physics (in Soviet Physics, rules break you!). ChrisA From mmanns at gmx.net Mon Mar 12 19:22:56 2012 From: mmanns at gmx.net (Martin Manns) Date: Tue, 13 Mar 2012 00:22:56 +0100 Subject: [ANN] pyspread 0.2.1 Message-ID: ============== pyspread 0.2.1 ============== Pyspread 0.2.1 is released. The new version improves GPG integration. About pyspread ============== Pyspread is a non-traditional spreadsheet application that is based on and written in the programming language Python. The goal of pyspread is to be the most pythonic spreadsheet application. Pyspread is designed for Linux and other GTK platforms. Pyspread is free software. It is released under the GPL v3. Project website: http://manns.github.com/pyspread/ What is new in 0.2.1 ==================== * Format menu added * Printing bug (first line not printed) fixed * GPG key choice dialog added * Secret key generation dialog added * Password saving in .pyspreadrc is now optional * Preferences dialog entries are now validated * Toolbar positions are now saved on exit * Absolute addressing with mouse changed to + * Relative addressing with mouse changed to + Enjoy Martin From joncle at googlemail.com Mon Mar 12 23:38:25 2012 From: joncle at googlemail.com (Jon Clements) Date: Mon, 12 Mar 2012 20:38:25 -0700 (PDT) Subject: Fast file data retrieval? In-Reply-To: References: <4F5E50F6.9070309@it.uu.se> Message-ID: <8469277.2076.1331609905709.JavaMail.geo-discussion-forums@vbai14> On Monday, 12 March 2012 20:31:35 UTC, MRAB wrote: > On 12/03/2012 19:39, Virgil Stokes wrote: > > I have a rather large ASCII file that is structured as follows > > > > header line > > 9 nonblank lines with alphanumeric data > > header line > > 9 nonblank lines with alphanumeric data > > ... > > ... > > ... > > header line > > 9 nonblank lines with alphanumeric data > > EOF > > > > where, a data set contains 10 lines (header + 9 nonblank) and there can > > be several thousand > > data sets in a single file. In addition,*each header has a* *unique ID > > code*. > > > > Is there a fast method for the retrieval of a data set from this large > > file given its ID code? > > > Probably the best solution is to put it into a database. Have a look at > the sqlite3 module. > > Alternatively, you could scan the file, recording the ID and the file > offset in a dict so that, given an ID, you can seek directly to that > file position. I would have a look at either bsddb, Tokyo (or Kyoto) Cabinet or hamsterdb. If it's really going to get large and needs a full blown server, maybe MongoDB/redis/hadoop... From joncle at googlemail.com Mon Mar 12 23:38:25 2012 From: joncle at googlemail.com (Jon Clements) Date: Mon, 12 Mar 2012 20:38:25 -0700 (PDT) Subject: Fast file data retrieval? In-Reply-To: References: <4F5E50F6.9070309@it.uu.se> Message-ID: <8469277.2076.1331609905709.JavaMail.geo-discussion-forums@vbai14> On Monday, 12 March 2012 20:31:35 UTC, MRAB wrote: > On 12/03/2012 19:39, Virgil Stokes wrote: > > I have a rather large ASCII file that is structured as follows > > > > header line > > 9 nonblank lines with alphanumeric data > > header line > > 9 nonblank lines with alphanumeric data > > ... > > ... > > ... > > header line > > 9 nonblank lines with alphanumeric data > > EOF > > > > where, a data set contains 10 lines (header + 9 nonblank) and there can > > be several thousand > > data sets in a single file. In addition,*each header has a* *unique ID > > code*. > > > > Is there a fast method for the retrieval of a data set from this large > > file given its ID code? > > > Probably the best solution is to put it into a database. Have a look at > the sqlite3 module. > > Alternatively, you could scan the file, recording the ID and the file > offset in a dict so that, given an ID, you can seek directly to that > file position. I would have a look at either bsddb, Tokyo (or Kyoto) Cabinet or hamsterdb. If it's really going to get large and needs a full blown server, maybe MongoDB/redis/hadoop... From casevh at gmail.com Mon Mar 12 23:59:38 2012 From: casevh at gmail.com (casevh at gmail.com) Date: Mon, 12 Mar 2012 20:59:38 -0700 (PDT) Subject: PyCrypto builds neither with MSVC nor MinGW In-Reply-To: References: <35da69c3-edcc-4466-8a0d-70237c88af3b@qv4g2000pbc.googlegroups.com> Message-ID: <13993807.3661.1331611178050.JavaMail.geo-discussion-forums@pbcgf10> On Monday, March 12, 2012 1:38:29 PM UTC-7, Alec Taylor wrote: > On a brand new Windows install now, with a brand new VS8 installed > with new YASM and MPIR in c:\usr\src\include and c:\usr\src\lib. > > But it still isn't working: > This was a little challenging. I looked through the setup.py to figure out what assumptions their build process made. First, the file pycrypto-2.5\src\inc-msvc\config.h must be modified. Below is the file I used: config.h =================================================================== /* Define to 1 if you have the declaration of `mpz_powm', and to 0 if you don't. */ #define HAVE_DECL_MPZ_POWM 1 /* Define to 1 if you have the declaration of `mpz_powm_sec', and to 0 if you don't. */ #define HAVE_DECL_MPZ_POWM_SEC 0 /* Define to 1 if you have the `gmp' library (-lgmp). */ #undef HAVE_LIBGMP /* Define to 1 if you have the `mpir' library (-lmpir). */ #define HAVE_LIBMPIR 1 /* Define to 1 if you have the header file. */ #define HAVE_STDINT_H 1 =================================================================== Although I was able to specify an include directory for mpir.h with -Ic:\usr\include, I was not able specify a lib directory with -Lc:\usr\lib. It looks like setup.py does not honor the -L option. So I finally gave up and just copied the mpir.h file into my Python27\include directory and the mpir.lib file into my Python27\libs directory. After copying the files "python setup.py install" was successful. I created a binary installer with "python setup.py bdist-wininst". There may be a cleaner way to build PyCrypto, but these steps worked for me. casevh From casevh at gmail.com Mon Mar 12 23:59:38 2012 From: casevh at gmail.com (casevh at gmail.com) Date: Mon, 12 Mar 2012 20:59:38 -0700 (PDT) Subject: PyCrypto builds neither with MSVC nor MinGW In-Reply-To: References: <35da69c3-edcc-4466-8a0d-70237c88af3b@qv4g2000pbc.googlegroups.com> Message-ID: <13993807.3661.1331611178050.JavaMail.geo-discussion-forums@pbcgf10> On Monday, March 12, 2012 1:38:29 PM UTC-7, Alec Taylor wrote: > On a brand new Windows install now, with a brand new VS8 installed > with new YASM and MPIR in c:\usr\src\include and c:\usr\src\lib. > > But it still isn't working: > This was a little challenging. I looked through the setup.py to figure out what assumptions their build process made. First, the file pycrypto-2.5\src\inc-msvc\config.h must be modified. Below is the file I used: config.h =================================================================== /* Define to 1 if you have the declaration of `mpz_powm', and to 0 if you don't. */ #define HAVE_DECL_MPZ_POWM 1 /* Define to 1 if you have the declaration of `mpz_powm_sec', and to 0 if you don't. */ #define HAVE_DECL_MPZ_POWM_SEC 0 /* Define to 1 if you have the `gmp' library (-lgmp). */ #undef HAVE_LIBGMP /* Define to 1 if you have the `mpir' library (-lmpir). */ #define HAVE_LIBMPIR 1 /* Define to 1 if you have the header file. */ #define HAVE_STDINT_H 1 =================================================================== Although I was able to specify an include directory for mpir.h with -Ic:\usr\include, I was not able specify a lib directory with -Lc:\usr\lib. It looks like setup.py does not honor the -L option. So I finally gave up and just copied the mpir.h file into my Python27\include directory and the mpir.lib file into my Python27\libs directory. After copying the files "python setup.py install" was successful. I created a binary installer with "python setup.py bdist-wininst". There may be a cleaner way to build PyCrypto, but these steps worked for me. casevh From jg07024 at gmail.com Tue Mar 13 00:06:39 2012 From: jg07024 at gmail.com (John Graves) Date: Tue, 13 Mar 2012 17:06:39 +1300 Subject: A Plausible Promise of Abundant Educational Resources In-Reply-To: References: Message-ID: The warning from Google should be fixed by now. A server outside my control had been infected with malware, so I shifted servers, but the warning message remained attached to the domain name. The address http://slidespeech.org leads to http://code.google.com/p/slidespeech/ the source code repository. On Sat, Mar 10, 2012 at 3:11 AM, John Graves wrote: > Dear Python-List: > > If you find Wikipedia useful and can see the value of collaborating on a > project which could make learning material as freely and spectacularly > available as Wikipedia does reference material[1], please read on. > > Background: > > In November 2009, I began learning Python with the objective of trying to > understand the following research question in my PhD research study of open > source software development: "We have built Wikipedia and other big, > successful open source projects. How can we do it again (and again)?" The > critical issue for me was how to start a project which would grow to > self-sustainability. So for over two years now, my research method has been > to try to actually start such a project. I failed. Over and over. The data > collection period for my study ended. > > Before I could start writing up my PhD, however, I saw an answer provided > in February 2012 by the founder of Craigslist, on Quora. When asked, "How > did Craigslist gain its initial traction?"[2], Craig Newmark, Customer > Service Rep & Founder wrote: > > - from beginning, did something simple and useful > - from beginning, began cycle: > -- asked for community feedback > -- did something about it > -- repeat, forever > -- got lucky with simple site design > > So I have now tried to take what started as a horribly over ambitious > desktop application[3], combined with an equally inept Android mobile > application (done in Java)[4] and boiled down the core text-to-speech > functionality into something "simple and useful" which runs on the web. The > project is now called SlideSpeech[5] and it does a couple of pretty > interesting things. Interesting enough to attract venture capital. > > The Future: > > As of 23 February 2012, SlideSpeech Limited is a company. But it is still > an open source software development research project with a Pythonic heart. > I can now pay for development of some professional quality software by > people who know much more Java and Python than I do. Perhaps this will help > the project reach self-sustainability, although, as Derek Sivers points out > in a memorable TED talk[6], just initiating or leading a project like this > is not what makes it a success: there must be joiners and followers for a > project with a plausible promise to grow to realise its potential. The > followers are the real heroes. > > Now Peter Diamandis just gave a TED talk entitled, "Abundance is our > future"[7] which everyone should watch. He talks of 3 billion people coming > on-line this decade. I want SlideSpeech to be useful and helpful to those > people. Not to make money from them but to help foster a global > conversation and global distribution of knowledge. We should all share in > Educational Abundance. Diamandis says, "we're going to hit 70 percent > penetration of cellphones in the developing world by the end of 2013." > SlideSpeech can plausibly promise to deliver free, interactive learning > material to smart phones anywhere on the planet this year. The current > working prototype does this today. > > In its simplest form, the system works like this: > 1) you start in your presentation software, adding a voice over script in > the speaker notes of each slide > 2) you upload your presentation to SlideSpeech > 3) on the SlideSpeech server (which can be your own PC, running Python, > made viewable to the world using PageKite[8]), the presentation is > "decomposed" into slide images and text scripts. The scripts are fed into a > text-to-speech engine. The resulting audio files are wrapped in HTML with > their corresponding slide image files. Finally, a link to access the HTML > is e-mailed back to you > 4) you open the link on your mobile phone's web browser and the > presentation you were writing just moments before "delivers itself" on your > phone ... or on any smart phone, tablet or web browser, anywhere. No need > to organise a venue, send invitations or get people to actually physically > show up to see and hear your talk. You can just forward the e-mail. > > Cooler still, > 5) if you have a native application play the script using the phone's > text-to-speech engine, you don't have to download audio (or video), so you > save 75% of the bandwidth. Multiplied by billions of people, multiplied by > the number of downloads[9], that is a huge savings. > > The compression of content into the simple combination of images and > text-to-speech scripts allows SlideSpeech to realise part of the One Laptop > Per Child vision using "talking" smart phones and tablets. Students can > learn on their own. Current prices on the cheapest Android 2.2 gear which > can deliver SlideSpeech content here in Auckland, New Zealand are under > NZ$150. > > A Revolution in Learning: > > Think of SlideSpeech as a platform like Khan Academy[10] with the > exercises integrated into the presentation. The scripts can be created and > improved collaboratively, like Wikipedia articles, or cloned and customised > for particular audiences. Unlike Khan Academy videos, the text of > SlideSpeech presentations is search-able and machine-translatable. > > With presentation feedback built into the system[11], a newly created > presentation can be distributed and then dynamically critiqued and revised, > so later viewers see the corrected and improved version. It is remarkable > how quickly changes can be made, especially in contrast to the feedback > cycle a typical instructor goes through to improve their teaching. > > These ideas and technologies are not new. Text-to-speech, in particular, > has been around for a long time. Lately, however, the voices have become > "Avatar-quality"[12]. > > These ideas are disruptive. The current working prototypes of SlideSpeech > may appear to work poorly, underperforming relative to established > products, but as Clayton Christensen explains[13], having the ability to > meet an underlying need in a radically different way transforms industries. > I like to make an analogy with trains and cars. Current educational systems > are like trains: everyone has to go between the same fixed destinations at > the same fixed times, like it or not. SlideSpeech-based learning is like > having a car: you get to go learn whatever you want, whenever you want, > wherever you are, at your own pace (which is sometimes very, very fast!). > > Content is King: > > Having lots of content available will accelerate the adoption of > SlideSpeech above all else. Over the coming weeks, as the system matures, > you can start preparing by authoring presentations with speaker notes. Once > the system is fully available on-line, or downloadable to your PC, you can > drop your presentations in and get out "self-delivering" talks in HTML or > even video format, voiced by a wide selection of computer voices in English > and in many other languages. > > Please feel free to jump in with suggestions, contributions or forks of > the code repositories listed below. > > Let's make Educational Abundance happen with Python this year. > > Exponentially yours, > > John Graves > PhD Student > AUT University > Auckland, New Zealand > > Founder and CEO > SlideSpeech > > [1] The English language version of Wikipedia has 50 times as many words > as *Encyclop?dia Britannica > * http://en.wikipedia.org/wiki/Wikipedia:Size_comparisons > > [2] http://www.quora.com/How-did-Craigslist-gain-its-initial-traction > > [3] http://code.google.com/p/open-allure-ds/ > > [4] http://code.google.com/p/wiki-to-speech/ > > [5] http://code.google.com/p/slidespeech/ > > [6] http://www.ted.com/talks/derek_sivers_how_to_start_a_movement.html > > [7] http://www.ted.com/talks/peter_diamandis_abundance_is_our_future.html > > [8] http://pagekite.net > > [9] average for Wikipedia is about one article per person per day (18.1 > billion pages / 482 million unique visitors in January 2012) > http://stats.wikimedia.org/reportcard/ > > [10] http://khanacademy.org > > [11] http://code.google.com/p/slidespeech/wiki/WorkflowDiagrams > > [12] I particularly like Loquendo's Veena, Indian English voice > http://www.loquendo.com/en/demo-center/tts-demo/english/ > > [13] http://en.wikipedia.org/wiki/Disruptive_technology > -------------- next part -------------- An HTML attachment was scrubbed... URL: From jg07024 at gmail.com Tue Mar 13 00:08:50 2012 From: jg07024 at gmail.com (John Graves) Date: Tue, 13 Mar 2012 17:08:50 +1300 Subject: A Plausible Promise of Abundant Educational Resources In-Reply-To: References: Message-ID: OK. Do you have an presentation prepared? I've put the one with the photographsonto Dropbox. On Tue, Mar 13, 2012 at 5:06 PM, John Graves wrote: > The warning from Google should be fixed by now. A server outside my > control had been infected with malware, so I shifted servers, but the > warning message remained attached to the domain name. The address > http://slidespeech.org leads to http://code.google.com/p/slidespeech/ the > source code repository. > > > On Sat, Mar 10, 2012 at 3:11 AM, John Graves wrote: > >> Dear Python-List: >> >> If you find Wikipedia useful and can see the value of collaborating on a >> project which could make learning material as freely and spectacularly >> available as Wikipedia does reference material[1], please read on. >> >> Background: >> >> In November 2009, I began learning Python with the objective of trying to >> understand the following research question in my PhD research study of open >> source software development: "We have built Wikipedia and other big, >> successful open source projects. How can we do it again (and again)?" The >> critical issue for me was how to start a project which would grow to >> self-sustainability. So for over two years now, my research method has been >> to try to actually start such a project. I failed. Over and over. The data >> collection period for my study ended. >> >> Before I could start writing up my PhD, however, I saw an answer provided >> in February 2012 by the founder of Craigslist, on Quora. When asked, "How >> did Craigslist gain its initial traction?"[2], Craig Newmark, Customer >> Service Rep & Founder wrote: >> >> - from beginning, did something simple and useful >> - from beginning, began cycle: >> -- asked for community feedback >> -- did something about it >> -- repeat, forever >> -- got lucky with simple site design >> >> So I have now tried to take what started as a horribly over ambitious >> desktop application[3], combined with an equally inept Android mobile >> application (done in Java)[4] and boiled down the core text-to-speech >> functionality into something "simple and useful" which runs on the web. The >> project is now called SlideSpeech[5] and it does a couple of pretty >> interesting things. Interesting enough to attract venture capital. >> >> The Future: >> >> As of 23 February 2012, SlideSpeech Limited is a company. But it is still >> an open source software development research project with a Pythonic heart. >> I can now pay for development of some professional quality software by >> people who know much more Java and Python than I do. Perhaps this will help >> the project reach self-sustainability, although, as Derek Sivers points out >> in a memorable TED talk[6], just initiating or leading a project like this >> is not what makes it a success: there must be joiners and followers for a >> project with a plausible promise to grow to realise its potential. The >> followers are the real heroes. >> >> Now Peter Diamandis just gave a TED talk entitled, "Abundance is our >> future"[7] which everyone should watch. He talks of 3 billion people coming >> on-line this decade. I want SlideSpeech to be useful and helpful to those >> people. Not to make money from them but to help foster a global >> conversation and global distribution of knowledge. We should all share in >> Educational Abundance. Diamandis says, "we're going to hit 70 percent >> penetration of cellphones in the developing world by the end of 2013." >> SlideSpeech can plausibly promise to deliver free, interactive learning >> material to smart phones anywhere on the planet this year. The current >> working prototype does this today. >> >> In its simplest form, the system works like this: >> 1) you start in your presentation software, adding a voice over script in >> the speaker notes of each slide >> 2) you upload your presentation to SlideSpeech >> 3) on the SlideSpeech server (which can be your own PC, running Python, >> made viewable to the world using PageKite[8]), the presentation is >> "decomposed" into slide images and text scripts. The scripts are fed into a >> text-to-speech engine. The resulting audio files are wrapped in HTML with >> their corresponding slide image files. Finally, a link to access the HTML >> is e-mailed back to you >> 4) you open the link on your mobile phone's web browser and the >> presentation you were writing just moments before "delivers itself" on your >> phone ... or on any smart phone, tablet or web browser, anywhere. No need >> to organise a venue, send invitations or get people to actually physically >> show up to see and hear your talk. You can just forward the e-mail. >> >> Cooler still, >> 5) if you have a native application play the script using the phone's >> text-to-speech engine, you don't have to download audio (or video), so you >> save 75% of the bandwidth. Multiplied by billions of people, multiplied by >> the number of downloads[9], that is a huge savings. >> >> The compression of content into the simple combination of images and >> text-to-speech scripts allows SlideSpeech to realise part of the One Laptop >> Per Child vision using "talking" smart phones and tablets. Students can >> learn on their own. Current prices on the cheapest Android 2.2 gear which >> can deliver SlideSpeech content here in Auckland, New Zealand are under >> NZ$150. >> >> A Revolution in Learning: >> >> Think of SlideSpeech as a platform like Khan Academy[10] with the >> exercises integrated into the presentation. The scripts can be created and >> improved collaboratively, like Wikipedia articles, or cloned and customised >> for particular audiences. Unlike Khan Academy videos, the text of >> SlideSpeech presentations is search-able and machine-translatable. >> >> With presentation feedback built into the system[11], a newly created >> presentation can be distributed and then dynamically critiqued and revised, >> so later viewers see the corrected and improved version. It is remarkable >> how quickly changes can be made, especially in contrast to the feedback >> cycle a typical instructor goes through to improve their teaching. >> >> These ideas and technologies are not new. Text-to-speech, in particular, >> has been around for a long time. Lately, however, the voices have become >> "Avatar-quality"[12]. >> >> These ideas are disruptive. The current working prototypes of SlideSpeech >> may appear to work poorly, underperforming relative to established >> products, but as Clayton Christensen explains[13], having the ability to >> meet an underlying need in a radically different way transforms industries. >> I like to make an analogy with trains and cars. Current educational systems >> are like trains: everyone has to go between the same fixed destinations at >> the same fixed times, like it or not. SlideSpeech-based learning is like >> having a car: you get to go learn whatever you want, whenever you want, >> wherever you are, at your own pace (which is sometimes very, very fast!). >> >> Content is King: >> >> Having lots of content available will accelerate the adoption of >> SlideSpeech above all else. Over the coming weeks, as the system matures, >> you can start preparing by authoring presentations with speaker notes. Once >> the system is fully available on-line, or downloadable to your PC, you can >> drop your presentations in and get out "self-delivering" talks in HTML or >> even video format, voiced by a wide selection of computer voices in English >> and in many other languages. >> >> Please feel free to jump in with suggestions, contributions or forks of >> the code repositories listed below. >> >> Let's make Educational Abundance happen with Python this year. >> >> Exponentially yours, >> >> John Graves >> PhD Student >> AUT University >> Auckland, New Zealand >> >> Founder and CEO >> SlideSpeech >> >> [1] The English language version of Wikipedia has 50 times as many words >> as *Encyclop?dia Britannica >> * http://en.wikipedia.org/wiki/Wikipedia:Size_comparisons >> >> [2] http://www.quora.com/How-did-Craigslist-gain-its-initial-traction >> >> [3] http://code.google.com/p/open-allure-ds/ >> >> [4] http://code.google.com/p/wiki-to-speech/ >> >> [5] http://code.google.com/p/slidespeech/ >> >> [6] http://www.ted.com/talks/derek_sivers_how_to_start_a_movement.html >> >> [7] http://www.ted.com/talks/peter_diamandis_abundance_is_our_future.html >> >> [8] http://pagekite.net >> >> [9] average for Wikipedia is about one article per person per day (18.1 >> billion pages / 482 million unique visitors in January 2012) >> http://stats.wikimedia.org/reportcard/ >> >> [10] http://khanacademy.org >> >> [11] http://code.google.com/p/slidespeech/wiki/WorkflowDiagrams >> >> [12] I particularly like Loquendo's Veena, Indian English voice >> http://www.loquendo.com/en/demo-center/tts-demo/english/ >> >> [13] http://en.wikipedia.org/wiki/Disruptive_technology >> > > -------------- next part -------------- An HTML attachment was scrubbed... URL: From alec.taylor6 at gmail.com Tue Mar 13 00:57:51 2012 From: alec.taylor6 at gmail.com (Alec Taylor) Date: Tue, 13 Mar 2012 15:57:51 +1100 Subject: PyCrypto builds neither with MSVC nor MinGW In-Reply-To: <13993807.3661.1331611178050.JavaMail.geo-discussion-forums@pbcgf10> References: <35da69c3-edcc-4466-8a0d-70237c88af3b@qv4g2000pbc.googlegroups.com> <13993807.3661.1331611178050.JavaMail.geo-discussion-forums@pbcgf10> Message-ID: Hmm, I just tried that method, but the output I got was still: C:\workingdir\pycrypto>python setup.py install running install running build running build_py running build_ext building 'Crypto.Random.OSRNG.winrandom' extension Traceback (most recent call last): File "setup.py", line 452, in core.setup(**kw) File "C:\Python27\lib\distutils\core.py", line 152, in setup dist.run_commands() File "C:\Python27\lib\distutils\dist.py", line 953, in run_commands self.run_command(cmd) File "C:\Python27\lib\distutils\dist.py", line 972, in run_command cmd_obj.run() File "C:\Python27\lib\distutils\command\install.py", line 563, in run self.run_command('build') File "C:\Python27\lib\distutils\cmd.py", line 326, in run_command self.distribution.run_command(command) File "C:\Python27\lib\distutils\dist.py", line 972, in run_command cmd_obj.run() File "C:\Python27\lib\distutils\command\build.py", line 127, in run self.run_command(cmd_name) File "C:\Python27\lib\distutils\cmd.py", line 326, in run_command self.distribution.run_command(command) File "C:\Python27\lib\distutils\dist.py", line 972, in run_command cmd_obj.run() File "setup.py", line 249, in run build_ext.run(self) File "C:\Python27\lib\distutils\command\build_ext.py", line 339, in run self.build_extensions() File "setup.py", line 146, in build_extensions build_ext.build_extensions(self) File "C:\Python27\lib\distutils\command\build_ext.py", line 448, in build_extensions self.build_extension(ext) File "C:\Python27\lib\distutils\command\build_ext.py", line 498, in build_extension depends=ext.depends) File "C:\Python27\lib\distutils\msvc9compiler.py", line 473, in compile self.initialize() File "C:\Python27\lib\distutils\msvc9compiler.py", line 383, in initialize vc_env = query_vcvarsall(VERSION, plat_spec) File "C:\Python27\lib\distutils\msvc9compiler.py", line 299, in query_vcvarsall raise ValueError(str(list(result.keys()))) ValueError: [u'path'] -------------- and when I manually run vcvarsall (which is in PATH), I get the aforementioned linker errors: -------------- C:\workingdir\pycrypto>python setup.py install running install running build running build_py running build_ext building 'Crypto.Random.OSRNG.winrandom' extension C:\Program Files (x86)\Microsoft Visual Studio 9.0\VC\BIN\cl.exe /c /nologo /Ox /MD /W3 /GS- /DNDEBUG -Isrc/ -Isrc/inc-msvc/ -IC:\Python27\include -IC:\Python27 \PC /Tcsrc/winrand.c /Fobuild\temp.win-amd64-2.7\Release\src/winrand.obj winrand.c C:\Program Files (x86)\Microsoft Visual Studio 9.0\VC\BIN\link.exe /DLL /nologo /INCREMENTAL:NO /LIBPATH:C:\Python27\libs /LIBPATH:C:\Python27\PCbuild\amd64 ws2 _32.lib advapi32.lib /EXPORT:initwinrandom build\temp.win-amd64-2.7\Release\src/ winrand.obj /OUT:build\lib.win-amd64-2.7\Crypto\Random\OSRNG\winrandom.pyd /IMPL IB:build\temp.win-amd64-2.7\Release\src\winrandom.lib /MANIFESTFILE:build\temp.win-amd64-2.7\Release\src\winrandom.pyd.manifest Creating library build\temp.win-amd64-2.7\Release\src\winrandom.lib and object build\temp.win-amd64-2.7\Release\src\winrandom.exp winrand.obj : error LNK2019: unresolved external symbol __imp__PyObject_Free referenced in function _WRdealloc winrand.obj : error LNK2019: unresolved external symbol __imp__PyExc_SystemError referenced in function _WRdealloc winrand.obj : error LNK2019: unresolved external symbol __imp__PyErr_Format referenced in function _WRdealloc winrand.obj : error LNK2019: unresolved external symbol __imp__PyExc_TypeError referenced in function _WRdealloc winrand.obj : error LNK2019: unresolved external symbol __imp___PyObject_New referenced in function _winrandom_new winrand.obj : error LNK2019: unresolved external symbol __imp__PyArg_ParseTupleAndKeywords referenced in function _winrandom_new winrand.obj : error LNK2019: unresolved external symbol __imp__PyString_FromStringAndSize referenced in function _WR_get_bytes winrand.obj : error LNK2019: unresolved external symbol __imp__PyMem_Free referenced in function _WR_get_bytes winrand.obj : error LNK2019: unresolved external symbol __imp__PyErr_NoMemory referenced in function _WR_get_bytes winrand.obj : error LNK2019: unresolved external symbol __imp__PyMem_Malloc referenced in function _WR_get_bytes winrand.obj : error LNK2019: unresolved external symbol __imp__PyErr_SetString referenced in function _WR_get_bytes winrand.obj : error LNK2019: unresolved external symbol __imp__PyExc_ValueError referenced in function _WR_get_bytes winrand.obj : error LNK2019: unresolved external symbol __imp__PyArg_ParseTuple referenced in function _WR_get_bytes winrand.obj : error LNK2019: unresolved external symbol __imp__Py_FindMethod referenced in function _WRgetattr winrand.obj : error LNK2019: unresolved external symbol __imp__PyInt_FromLong referenced in function _WRgetattr winrand.obj : error LNK2019: unresolved external symbol __imp__Py_FatalError referenced in function _initwinrandom winrand.obj : error LNK2019: unresolved external symbol __imp__PyErr_Occurred referenced in function _initwinrandom winrand.obj : error LNK2019: unresolved external symbol __imp__PyModule_AddStringConstant referenced in function _initwinrandom winrand.obj : error LNK2019: unresolved external symbol __imp__PyModule_AddIntConstant referenced in function _initwinrandom winrand.obj : error LNK2019: unresolved external symbol __imp__Py_InitModule4 referenced in function _initwinrandom winrand.obj : error LNK2019: unresolved external symbol __imp__PyType_Type referenced in function _initwinrandom build\lib.win-amd64-2.7\Crypto\Random\OSRNG\winrandom.pyd : fatal error LNK1120: 21 unresolved externals error: command '"C:\Program Files (x86)\Microsoft Visual Studio 9.0\VC\BIN\link.exe"' failed with exit status 1120 On Tue, Mar 13, 2012 at 2:59 PM, wrote: > On Monday, March 12, 2012 1:38:29 PM UTC-7, Alec Taylor wrote: >> On a brand new Windows install now, with a brand new VS8 installed >> with new YASM and MPIR in c:\usr\src\include and c:\usr\src\lib. >> >> But it still isn't working: >> > This was a little challenging. I looked through the setup.py to figure out what assumptions their build process made. First, the file pycrypto-2.5\src\inc-msvc\config.h must be modified. Below is the file I used: > > config.h > =================================================================== > /* Define to 1 if you have the declaration of `mpz_powm', and to 0 if you > ? don't. */ > #define HAVE_DECL_MPZ_POWM 1 > > /* Define to 1 if you have the declaration of `mpz_powm_sec', and to 0 if you > ? don't. */ > #define HAVE_DECL_MPZ_POWM_SEC 0 > > /* Define to 1 if you have the `gmp' library (-lgmp). */ > #undef HAVE_LIBGMP > > /* Define to 1 if you have the `mpir' library (-lmpir). */ > #define HAVE_LIBMPIR 1 > > /* Define to 1 if you have the header file. */ > #define HAVE_STDINT_H 1 > =================================================================== > > Although I was able to specify an include directory for mpir.h with -Ic:\usr\include, I was not able specify a lib directory with -Lc:\usr\lib. It looks like setup.py does not honor the -L option. So I finally gave up and just copied the mpir.h file into my Python27\include directory and the mpir.lib file into my Python27\libs directory. > > After copying the files "python setup.py install" was successful. I created a binary installer with "python setup.py bdist-wininst". > > There may be a cleaner way to build PyCrypto, but these steps worked for me. > > casevh > -- > http://mail.python.org/mailman/listinfo/python-list From alec.taylor6 at gmail.com Tue Mar 13 02:09:38 2012 From: alec.taylor6 at gmail.com (Alec Taylor) Date: Tue, 13 Mar 2012 17:09:38 +1100 Subject: PyCrypto builds neither with MSVC nor MinGW In-Reply-To: References: <35da69c3-edcc-4466-8a0d-70237c88af3b@qv4g2000pbc.googlegroups.com> <13993807.3661.1331611178050.JavaMail.geo-discussion-forums@pbcgf10> Message-ID: Nope, I have C:\Python27 (and C:\Python27\Scripts) in my PATH. C:\workingdir\pycrypto>where python C:\Python27\python.exe On Tue, Mar 13, 2012 at 4:44 PM, Case Van Horsen wrote: > On Mon, Mar 12, 2012 at 9:57 PM, Alec Taylor wrote: >> Hmm, I just tried that method, but the output I got was still: >> >> C:\workingdir\pycrypto>python setup.py install >> running install >> running build >> running build_py >> running build_ext >> building 'Crypto.Random.OSRNG.winrandom' extension >> Traceback (most recent call last): >> ?File "setup.py", line 452, in >> ? ?core.setup(**kw) >> ?File "C:\Python27\lib\distutils\core.py", line 152, in setup >> ? ?dist.run_commands() >> ?File "C:\Python27\lib\distutils\dist.py", line 953, in run_commands >> ? ?self.run_command(cmd) >> ?File "C:\Python27\lib\distutils\dist.py", line 972, in run_command >> ? ?cmd_obj.run() >> ?File "C:\Python27\lib\distutils\command\install.py", line 563, in run >> ? ?self.run_command('build') >> ?File "C:\Python27\lib\distutils\cmd.py", line 326, in run_command >> ? ?self.distribution.run_command(command) >> ?File "C:\Python27\lib\distutils\dist.py", line 972, in run_command >> ? ?cmd_obj.run() >> ?File "C:\Python27\lib\distutils\command\build.py", line 127, in run >> ? ?self.run_command(cmd_name) >> ?File "C:\Python27\lib\distutils\cmd.py", line 326, in run_command >> ? ?self.distribution.run_command(command) >> ?File "C:\Python27\lib\distutils\dist.py", line 972, in run_command >> ? ?cmd_obj.run() >> ?File "setup.py", line 249, in run >> ? ?build_ext.run(self) >> ?File "C:\Python27\lib\distutils\command\build_ext.py", line 339, in run >> ? ?self.build_extensions() >> ?File "setup.py", line 146, in build_extensions >> ? ?build_ext.build_extensions(self) >> ?File "C:\Python27\lib\distutils\command\build_ext.py", line 448, in >> build_extensions >> ? ?self.build_extension(ext) >> ?File "C:\Python27\lib\distutils\command\build_ext.py", line 498, in >> build_extension >> ? ?depends=ext.depends) >> ?File "C:\Python27\lib\distutils\msvc9compiler.py", line 473, in compile >> ? ?self.initialize() >> ?File "C:\Python27\lib\distutils\msvc9compiler.py", line 383, in initialize >> ? ?vc_env = query_vcvarsall(VERSION, plat_spec) >> ?File "C:\Python27\lib\distutils\msvc9compiler.py", line 299, in >> query_vcvarsall >> ? ?raise ValueError(str(list(result.keys()))) >> ValueError: [u'path'] >> >> -------------- >> and when I manually run vcvarsall (which is in PATH), I get the >> aforementioned linker errors: >> -------------- >> >> C:\workingdir\pycrypto>python setup.py install >> running install >> running build >> running build_py >> running build_ext >> building 'Crypto.Random.OSRNG.winrandom' extension >> C:\Program Files (x86)\Microsoft Visual Studio 9.0\VC\BIN\cl.exe /c >> /nologo /Ox /MD /W3 /GS- /DNDEBUG -Isrc/ -Isrc/inc-msvc/ >> -IC:\Python27\include -IC:\Python27 \PC /Tcsrc/winrand.c >> /Fobuild\temp.win-amd64-2.7\Release\src/winrand.obj winrand.c >> C:\Program Files (x86)\Microsoft Visual Studio 9.0\VC\BIN\link.exe >> /DLL /nologo /INCREMENTAL:NO /LIBPATH:C:\Python27\libs >> /LIBPATH:C:\Python27\PCbuild\amd64 ws2 _32.lib advapi32.lib >> /EXPORT:initwinrandom build\temp.win-amd64-2.7\Release\src/ >> winrand.obj /OUT:build\lib.win-amd64-2.7\Crypto\Random\OSRNG\winrandom.pyd /IMPL >> IB:build\temp.win-amd64-2.7\Release\src\winrandom.lib >> /MANIFESTFILE:build\temp.win-amd64-2.7\Release\src\winrandom.pyd.manifest >> ? Creating library build\temp.win-amd64-2.7\Release\src\winrandom.lib >> and object build\temp.win-amd64-2.7\Release\src\winrandom.exp >> winrand.obj : error LNK2019: unresolved external symbol >> __imp__PyObject_Free referenced in function _WRdealloc >> winrand.obj : error LNK2019: unresolved external symbol >> __imp__PyExc_SystemError referenced in function _WRdealloc >> winrand.obj : error LNK2019: unresolved external symbol >> __imp__PyErr_Format referenced in function _WRdealloc >> winrand.obj : error LNK2019: unresolved external symbol >> __imp__PyExc_TypeError referenced in function _WRdealloc >> winrand.obj : error LNK2019: unresolved external symbol >> __imp___PyObject_New referenced in function _winrandom_new >> winrand.obj : error LNK2019: unresolved external symbol >> __imp__PyArg_ParseTupleAndKeywords referenced in function >> _winrandom_new >> winrand.obj : error LNK2019: unresolved external symbol >> __imp__PyString_FromStringAndSize referenced in function _WR_get_bytes >> winrand.obj : error LNK2019: unresolved external symbol >> __imp__PyMem_Free referenced in function _WR_get_bytes >> winrand.obj : error LNK2019: unresolved external symbol >> __imp__PyErr_NoMemory referenced in function _WR_get_bytes >> winrand.obj : error LNK2019: unresolved external symbol >> __imp__PyMem_Malloc referenced in function _WR_get_bytes >> winrand.obj : error LNK2019: unresolved external symbol >> __imp__PyErr_SetString referenced in function _WR_get_bytes >> winrand.obj : error LNK2019: unresolved external symbol >> __imp__PyExc_ValueError referenced in function _WR_get_bytes >> winrand.obj : error LNK2019: unresolved external symbol >> __imp__PyArg_ParseTuple referenced in function _WR_get_bytes >> winrand.obj : error LNK2019: unresolved external symbol >> __imp__Py_FindMethod referenced in function _WRgetattr >> winrand.obj : error LNK2019: unresolved external symbol >> __imp__PyInt_FromLong referenced in function _WRgetattr >> winrand.obj : error LNK2019: unresolved external symbol >> __imp__Py_FatalError referenced in function _initwinrandom >> winrand.obj : error LNK2019: unresolved external symbol >> __imp__PyErr_Occurred referenced in function _initwinrandom >> winrand.obj : error LNK2019: unresolved external symbol >> __imp__PyModule_AddStringConstant referenced in function >> _initwinrandom >> winrand.obj : error LNK2019: unresolved external symbol >> __imp__PyModule_AddIntConstant referenced in function _initwinrandom >> winrand.obj : error LNK2019: unresolved external symbol >> __imp__Py_InitModule4 referenced in function _initwinrandom >> winrand.obj : error LNK2019: unresolved external symbol >> __imp__PyType_Type referenced in function _initwinrandom >> build\lib.win-amd64-2.7\Crypto\Random\OSRNG\winrandom.pyd : fatal error LNK1120: >> ?21 unresolved externals >> error: command '"C:\Program Files (x86)\Microsoft Visual Studio >> 9.0\VC\BIN\link.exe"' failed with exit status 1120 >> > > It almost seems that python can't find all its files. Are you using a > macro or batch file to invoke python. I actually used > > "c:\x64\Python27\python.exe setup.py install" > > IIRC, I've had issues with a DOSKEY macro before so now I explicitly > use the full path to python.exe. > > Otherwise I'm stumped. >> On Tue, Mar 13, 2012 at 2:59 PM, ? wrote: >>> On Monday, March 12, 2012 1:38:29 PM UTC-7, Alec Taylor wrote: >>>> On a brand new Windows install now, with a brand new VS8 installed >>>> with new YASM and MPIR in c:\usr\src\include and c:\usr\src\lib. >>>> >>>> But it still isn't working: >>>> >>> This was a little challenging. I looked through the setup.py to figure out what assumptions their build process made. First, the file pycrypto-2.5\src\inc-msvc\config.h must be modified. Below is the file I used: >>> >>> config.h >>> =================================================================== >>> /* Define to 1 if you have the declaration of `mpz_powm', and to 0 if you >>> ? don't. */ >>> #define HAVE_DECL_MPZ_POWM 1 >>> >>> /* Define to 1 if you have the declaration of `mpz_powm_sec', and to 0 if you >>> ? don't. */ >>> #define HAVE_DECL_MPZ_POWM_SEC 0 >>> >>> /* Define to 1 if you have the `gmp' library (-lgmp). */ >>> #undef HAVE_LIBGMP >>> >>> /* Define to 1 if you have the `mpir' library (-lmpir). */ >>> #define HAVE_LIBMPIR 1 >>> >>> /* Define to 1 if you have the header file. */ >>> #define HAVE_STDINT_H 1 >>> =================================================================== >>> >>> Although I was able to specify an include directory for mpir.h with -Ic:\usr\include, I was not able specify a lib directory with -Lc:\usr\lib. It looks like setup.py does not honor the -L option. So I finally gave up and just copied the mpir.h file into my Python27\include directory and the mpir.lib file into my Python27\libs directory. >>> >>> After copying the files "python setup.py install" was successful. I created a binary installer with "python setup.py bdist-wininst". >>> >>> There may be a cleaner way to build PyCrypto, but these steps worked for me. >>> >>> casevh >>> -- >>> http://mail.python.org/mailman/listinfo/python-list From patrick.szabo at lexisnexis.at Tue Mar 13 05:41:41 2012 From: patrick.szabo at lexisnexis.at (Szabo, Patrick (LNG-VIE)) Date: Tue, 13 Mar 2012 10:41:41 +0100 Subject: Windows Contextmenu Message-ID: Hi, I wrote the following Script which I want to run from the open with contextmenu in Windows. For that purpose I used py2exe to make an exe out of it. import sys, time, webbrowser def main(): for para in sys.argv[1:]: print sys.argv print "###############################" print para url = "http://production.lexisnexis.at:8080/cocoon/glp/html/%s" % str(para).replace("R:\\", "").replace(".xml", ".html") webbrowser.open_new(url) time.sleep(10) if __name__ == "__main__": main() Now the script runs fine but I don't get all arguments from sys.argv. No mather how many files I mark in the explorer I only get one as an argument. Can anyone tell me how to overcome this issue ? Best regards . . . . . . . . . . . . . . . . . . . . . . . . . . Ing. Patrick Szabo XSLT Developer LexisNexis A-1030 Wien, Marxergasse 25 mailto:patrick.szabo at lexisnexis.at Tel.: +43 1 53452 1573 Fax: +43 1 534 52 146 -------------- next part -------------- An HTML attachment was scrubbed... URL: From jeanmichel at sequans.com Tue Mar 13 06:30:56 2012 From: jeanmichel at sequans.com (Jean-Michel Pichavant) Date: Tue, 13 Mar 2012 11:30:56 +0100 Subject: How to break long method name into more than one line? In-Reply-To: References: <4f5d4390$0$29891$c3e8da3$5496439d@news.astraweb.com> Message-ID: <4F5F21E0.4010308@sequans.com> Chris Angelico wrote: > Just never treat them as laws of physics (in > Soviet Physics, rules break you!). > > ChrisA > hum ... I wonder how this political message is relevant to the OP problem. JM From rosuav at gmail.com Tue Mar 13 06:35:44 2012 From: rosuav at gmail.com (Chris Angelico) Date: Tue, 13 Mar 2012 21:35:44 +1100 Subject: How to break long method name into more than one line? In-Reply-To: <4F5F21E0.4010308@sequans.com> References: <4f5d4390$0$29891$c3e8da3$5496439d@news.astraweb.com> <4F5F21E0.4010308@sequans.com> Message-ID: On Tue, Mar 13, 2012 at 9:30 PM, Jean-Michel Pichavant wrote: > Chris Angelico wrote: >> >> Just never treat them as laws of physics (in >> Soviet Physics, rules break you!). > > hum ... > I wonder how this political message is relevant to the OP problem. Ehh, it's a reference to the "in Soviet Russia" theme of one-liners. You don't break the laws of physics, they break you. My point is that rules about function names etc are *not* inviolate, and should be treated accordingly. ChrisA From albert at spenarnc.xs4all.nl Tue Mar 13 06:40:29 2012 From: albert at spenarnc.xs4all.nl (Albert van der Horst) Date: 13 Mar 2012 10:40:29 GMT Subject: are int, float, long, double, side-effects of computer engineering? References: <5aaded58-af09-41dc-9afd-56d7b7ced239@d7g2000pbl.googlegroups.com> Message-ID: In article <5aaded58-af09-41dc-9afd-56d7b7ced239 at d7g2000pbl.googlegroups.com>, Xah Lee wrote: > >what i meant to point out is that Mathematica deals with numbers at a >high-level human way. That is, one doesn't think in terms of float, >long, int, double. These words are never mentioned. Instead, you have >concepts of machine precision, accuracy. The lang automatically handle >the translation to hardware, and invoking exact value or infinite >precision as required or requested. With e.g. a vanderMonde matrix you can easily make Mathematica fail. If you don't understand what a condition number is, you can't use Mathematica. And yes condition numbers are fully in the realm of concepts of machine precisions and accuracy. Infinite precision takes infinite time. Approaching infinite precious may take exponentional time. > > Xah Groetjes Albert -- -- Albert van der Horst, UTRECHT,THE NETHERLANDS Economic growth -- being exponential -- ultimately falters. albert at spe&ar&c.xs4all.nl &=n http://home.hccnet.nl/a.w.m.van.der.horst From mail at timgolden.me.uk Tue Mar 13 06:40:49 2012 From: mail at timgolden.me.uk (Tim Golden) Date: Tue, 13 Mar 2012 10:40:49 +0000 Subject: Windows Contextmenu In-Reply-To: References: Message-ID: <4F5F2431.2080109@timgolden.me.uk> On 13/03/2012 09:41, Szabo, Patrick (LNG-VIE) wrote: > I wrote the following Script which I want to run from the open with > contextmenu in Windows. > > For that purpose I used py2exe to make an exe out of it. [... snip ...] > > Now the script runs fine but I don?t get all arguments from sys.argv. > > No mather how many files I mark in the explorer I only get one as an > argument. You're missing out vital information: * How have you attached this code to the context menu? What was the exact registry entry (or other method) you used? * Does it work as native Python (ie without the py2exe layer)? * Presumably the same issue occurs if you simply have: print sys.argv on its own (ie it's nothing to do with your loop and later code) TJG From kiuhnm03.4t.yahoo.it Tue Mar 13 07:00:55 2012 From: kiuhnm03.4t.yahoo.it (Kiuhnm) Date: Tue, 13 Mar 2012 12:00:55 +0100 Subject: New Science Discovery: Perl Idiots Remain Idiots After A Decade!New Science Discovery: Perl Idiots Remain Idiots After A Decade! In-Reply-To: References: <0078bbfb-5dfc-48fc-af1a-69de3cf15c3e@b1g2000yqb.googlegroups.com> <4f5df4b3$0$1375$4fafbaef@reader1.news.tin.it> Message-ID: <4f5f28e8$0$1385$4fafbaef@reader2.news.tin.it> On 3/12/2012 20:00, Albert van der Horst wrote: > In article<4f5df4b3$0$1375$4fafbaef at reader1.news.tin.it>, > Kiuhnm wrote: >> On 3/12/2012 12:27, Albert van der Horst wrote: >>> Interestingly in mathematics associative means that it doesn't matter >>> whether you use (a.b).c or a.(b.c). >>> Using xxx-associativity to indicate that it *does* matter is >>> a bit perverse, but the Perl people are not to blame if they use >>> a term in their usual sense. >> >> You may see it this way: >> Def1. An operator +:SxS->S is left-associative iff >> a+b+c = (a+b)+c for all a,b,c in S. >> Def2. An operator +:SxS->S is right-associative iff >> a+b+c = a+(b+c) for all a,b,c in S. >> Def3. An operator +:SxS->S is associative iff it is both left and >> right-associative. > > I know, but what the mathematicians do make so much more sense: > (a+b)+c = a+(b+c) definition of associative. > Henceforth we may leave out the brackets. That's Def3. I don't see your point. > Don't leave out the brackets if the operators if the operators is > not associative. (1 - 1) - 1 != 1 - (1 - 1) and yet we can leave out the parentheses. > P.S. There is no need for the operators to be SxS->S. > For example a b c may be m by n, n by l, l by k matrices respectively. Ops, you're right. Kiuhnm From kiuhnm03.4t.yahoo.it Tue Mar 13 07:03:45 2012 From: kiuhnm03.4t.yahoo.it (Kiuhnm) Date: Tue, 13 Mar 2012 12:03:45 +0100 Subject: New Science Discovery: Perl Idiots Remain Idiots After A Decade!New Science Discovery: Perl Idiots Remain Idiots After A Decade! In-Reply-To: References: <0078bbfb-5dfc-48fc-af1a-69de3cf15c3e@b1g2000yqb.googlegroups.com> <4f5df4b3$0$1375$4fafbaef@reader1.news.tin.it> Message-ID: <4f5f2993$0$1385$4fafbaef@reader2.news.tin.it> On 3/12/2012 20:00, Albert van der Horst wrote: > In article<4f5df4b3$0$1375$4fafbaef at reader1.news.tin.it>, > Kiuhnm wrote: >> On 3/12/2012 12:27, Albert van der Horst wrote: >>> Interestingly in mathematics associative means that it doesn't matter >>> whether you use (a.b).c or a.(b.c). >>> Using xxx-associativity to indicate that it *does* matter is >>> a bit perverse, but the Perl people are not to blame if they use >>> a term in their usual sense. >> >> You may see it this way: >> Def1. An operator +:SxS->S is left-associative iff >> a+b+c = (a+b)+c for all a,b,c in S. >> Def2. An operator +:SxS->S is right-associative iff >> a+b+c = a+(b+c) for all a,b,c in S. >> Def3. An operator +:SxS->S is associative iff it is both left and >> right-associative. > > I know, but what the mathematicians do make so much more sense: > (a+b)+c = a+(b+c) definition of associative. > Henceforth we may leave out the brackets. That's Def3. I don't see your point. > Don't leave out the brackets if the operators if the operators is > not associative. (1 - 1) - 1 != 1 - (1 - 1) and yet we can leave out the parentheses. > P.S. There is no need for the operators to be SxS->S. > For example a b c may be m by n, n by l, l by k matrices respectively. Ops, you're right. Kiuhnm From ferreirafm at lim12.fm.usp.br Tue Mar 13 10:35:32 2012 From: ferreirafm at lim12.fm.usp.br (ferreirafm) Date: Tue, 13 Mar 2012 07:35:32 -0700 (PDT) Subject: concatenate function Message-ID: <1331649332216-4574176.post@n6.nabble.com> Hi List, I've coded three functions that I would like to concatenate. I mean, run them one after another. The third function depends on the results of the second function, which depends on the results of the first one. When I call one function after another, python runs them at the same time causing obvious errors messages. I've tried to call one of them from inside another but no way. Any clues are appreciated. Complete code goes here: http://ompldr.org/vZDB4OQ -- View this message in context: http://python.6.n6.nabble.com/concatenate-function-tp4574176p4574176.html Sent from the Python - python-list mailing list archive at Nabble.com. From ian.g.kelly at gmail.com Tue Mar 13 10:54:10 2012 From: ian.g.kelly at gmail.com (Ian Kelly) Date: Tue, 13 Mar 2012 08:54:10 -0600 Subject: concatenate function In-Reply-To: <1331649332216-4574176.post@n6.nabble.com> References: <1331649332216-4574176.post@n6.nabble.com> Message-ID: On Tue, Mar 13, 2012 at 8:35 AM, ferreirafm wrote: > Hi List, > I've coded three functions that I would like to concatenate. I mean, run > them one after another. The third function depends on the results of the > second function, which depends on the results of the first one. When I call > one function after another, python runs them at the same time causing > obvious errors messages. I've tried to call one of them from inside another > but no way. Any clues are appreciated. > Complete code goes here: > http://ompldr.org/vZDB4OQ They don't look to me like they would run at the same time -- subprocess.call is supposed to wait for the subprocess to finish. What error messages are you getting? From robert.kern at gmail.com Tue Mar 13 11:02:12 2012 From: robert.kern at gmail.com (Robert Kern) Date: Tue, 13 Mar 2012 15:02:12 +0000 Subject: concatenate function In-Reply-To: <1331649332216-4574176.post@n6.nabble.com> References: <1331649332216-4574176.post@n6.nabble.com> Message-ID: On 3/13/12 2:35 PM, ferreirafm wrote: > Hi List, > I've coded three functions that I would like to concatenate. I mean, run > them one after another. The third function depends on the results of the > second function, which depends on the results of the first one. When I call > one function after another, python runs them at the same time causing > obvious errors messages. I've tried to call one of them from inside another > but no way. Any clues are appreciated. > Complete code goes here: > http://ompldr.org/vZDB4OQ Just to clarify, the Python functions are indeed running consecutively, not concurrently. Your Python functions write scripts and then use subprocess.call() to make qsub (an external program) to submit those scripts to a job queue. What you are calling a "function" in your post are these scripts. Please don't call them "functions". It's confusing. Python is not running these scripts concurrently. Your job queue is. subprocess.call() will wait until qsub returns. However, qsub just submits the script to the job queue; it does not wait until the job is completed. Most qsub-using job queues can be set up to make jobs depend on the completion of other jobs. You will need to read the documentation of your job queue to figure out how to do this. Once you figure out the right arguments to give to qsub, your Python code is already more or less correct. -- Robert Kern "I have come to believe that the whole world is an enigma, a harmless enigma that is made terrible by our own mad attempt to interpret it as though it had an underlying truth." -- Umberto Eco From ferreirafm at lim12.fm.usp.br Tue Mar 13 11:17:18 2012 From: ferreirafm at lim12.fm.usp.br (ferreirafm) Date: Tue, 13 Mar 2012 08:17:18 -0700 (PDT) Subject: concatenate function In-Reply-To: References: <1331649332216-4574176.post@n6.nabble.com> Message-ID: <1331651838058-4574337.post@n6.nabble.com> Hi Ian, That what I have: > burst.py Your job 46665 ("top_n_pdb.qsub") has been submitted Your job 46666 ("extr_pdb.qsub") has been submitted Your job 46667 ("combine_top.qsub") has been submitted The first job runs quite well. The second is still runing and the third issue the following: > more combine_top.qsub.e46667 ERROR: Cannot open PDB file "S_3MSEB_26_0032.pdb" ERROR:: Exit from: src/core/import_pose/import_pose.cc line: 199 -- View this message in context: http://python.6.n6.nabble.com/concatenate-function-tp4574176p4574337.html Sent from the Python - python-list mailing list archive at Nabble.com. From paul.nospam at rudin.co.uk Tue Mar 13 11:44:00 2012 From: paul.nospam at rudin.co.uk (Paul Rudin) Date: Tue, 13 Mar 2012 15:44:00 +0000 Subject: Software Engineer - References: <74c28456-5467-48e8-88a9-e5649358373a@to5g2000pbc.googlegroups.com> Message-ID: <87vcm8h5fj.fsf@no-fixed-abode.cable.virginmedia.net> Chris Withers writes: > On 11/03/2012 09:00, Blue Line Talent wrote: >> Blue Line Talent is looking for a mid-level software engineer with >> experience in a combination of > > Please don't spam this list with jobs, use the Python job board instead: > > http://www.python.org/community/jobs/ Just out of interest why do people object to job adverts here? Seems harmless enough... From fil.oracle at gmail.com Tue Mar 13 11:54:20 2012 From: fil.oracle at gmail.com (James Elford) Date: Tue, 13 Mar 2012 15:54:20 +0000 Subject: concatenate function In-Reply-To: <1331649332216-4574176.post@n6.nabble.com> References: <1331649332216-4574176.post@n6.nabble.com> Message-ID: <4F5F6DAC.8000900@gmail.com> On 13/03/12 14:35, ferreirafm wrote: > Hi List, > I've coded three functions that I would like to concatenate. I mean, run > them one after another. The third function depends on the results of the > second function, which depends on the results of the first one. When I call > one function after another, python runs them at the same time causing > obvious errors messages. I've tried to call one of them from inside another > but no way. Any clues are appreciated. > Complete code goes here: > http://ompldr.org/vZDB4OQ Do you think you could provide a much shorter example to illustrate what you need? In general, when you want to run one function on the result of another, you can do something like: <<< def increment_all(l); ... return [i+1 for i in l] <<< increment_all(increment_all(range(3)) [2, 3, 4] Here we apply the function increment_all to the result of the function increment_all. If you are talking about the "results" of each function in terms of it mutating an object, and then the next function mutating the same object in a (possibly) different way, then calling the functions in order will do what you want. l = [0, 3, 5, 2] l.append(10) # [0, 3, 5, 2, 10] l.sort() # [0, 2, 3, 5, 10] l.append(3) # [0, 2, 3, 5, 10, 3] James > > > > -- > View this message in context: http://python.6.n6.nabble.com/concatenate-function-tp4574176p4574176.html > Sent from the Python - python-list mailing list archive at Nabble.com. From ferreirafm at lim12.fm.usp.br Tue Mar 13 11:59:26 2012 From: ferreirafm at lim12.fm.usp.br (ferreirafm) Date: Tue, 13 Mar 2012 08:59:26 -0700 (PDT) Subject: concatenate function In-Reply-To: References: <1331649332216-4574176.post@n6.nabble.com> Message-ID: <1331654366771-4574496.post@n6.nabble.com> Hi Robert, Thanks for you kind replay and I'm sorry for my semantic mistakes. Indeed, that's what I'm doing: qsub-ing different cshell scripts. Certainly, that's not the best approach and the only problem. I've unsuccessfully tried to set an os.environ and call qsub from it. However, subprocess.Popen seems not accept to run "qsub" over a second program. Do you have a over come to this issue? Code goes here: http://ompldr.org/vZDB5YQ -- View this message in context: http://python.6.n6.nabble.com/concatenate-function-tp4574176p4574496.html Sent from the Python - python-list mailing list archive at Nabble.com. From ferreirafm at lim12.fm.usp.br Tue Mar 13 12:02:39 2012 From: ferreirafm at lim12.fm.usp.br (ferreirafm) Date: Tue, 13 Mar 2012 09:02:39 -0700 (PDT) Subject: concatenate function In-Reply-To: <4F5F6DAC.8000900@gmail.com> References: <1331649332216-4574176.post@n6.nabble.com> <4F5F6DAC.8000900@gmail.com> Message-ID: <1331654559793-4574511.post@n6.nabble.com> Hi James, thank you for your replay. Indeed, the problem is qsub. And as warned by Robert, I don't have functions properly, but just scripts. -- View this message in context: http://python.6.n6.nabble.com/concatenate-function-tp4574176p4574511.html Sent from the Python - python-list mailing list archive at Nabble.com. From robert.kern at gmail.com Tue Mar 13 12:09:49 2012 From: robert.kern at gmail.com (Robert Kern) Date: Tue, 13 Mar 2012 16:09:49 +0000 Subject: concatenate function In-Reply-To: <1331654366771-4574496.post@n6.nabble.com> References: <1331649332216-4574176.post@n6.nabble.com> <1331654366771-4574496.post@n6.nabble.com> Message-ID: On 3/13/12 3:59 PM, ferreirafm wrote: > Hi Robert, > Thanks for you kind replay and I'm sorry for my semantic mistakes. > Indeed, that's what I'm doing: qsub-ing different cshell scripts. Certainly, > that's not the best approach and the only problem. It's not a problem to write out a script and have qsub run it. That's a perfectly fine thing to do. You need to read the documentation for your job queue to find out the right arguments to give to qsub to make it wait until the first job finishes before executing the second job. This is not a Python problem. You just need to find the right flags to give to qsub. Alternately, you could just make a single .qsub script running all three of your programs in a single job instead of making three separate .qsub scripts. > I've unsuccessfully tried > to set an os.environ and call qsub from it. However, subprocess.Popen seems > not accept to run "qsub" over a second program. Do you have a over come to > this issue? > Code goes here: > http://ompldr.org/vZDB5YQ When you report a problem, you should copy-and-paste the output that you got and also state the output that you expected. I have no idea what you mean when you say "subprocess.Popen seems not accept to run "qsub" over a second program." -- Robert Kern "I have come to believe that the whole world is an enigma, a harmless enigma that is made terrible by our own mad attempt to interpret it as though it had an underlying truth." -- Umberto Eco From fil.oracle at gmail.com Tue Mar 13 12:12:56 2012 From: fil.oracle at gmail.com (James Elford) Date: Tue, 13 Mar 2012 16:12:56 +0000 Subject: concatenate function In-Reply-To: <1331654559793-4574511.post@n6.nabble.com> References: <1331649332216-4574176.post@n6.nabble.com> <4F5F6DAC.8000900@gmail.com> <1331654559793-4574511.post@n6.nabble.com> Message-ID: <4F5F7208.5060905@gmail.com> On 13/03/12 16:02, ferreirafm wrote: > Hi James, thank you for your replay. Indeed, the problem is qsub. And as > warned by Robert, I don't have functions properly, but just scripts. > > > -- > View this message in context: http://python.6.n6.nabble.com/concatenate-function-tp4574176p4574511.html > Sent from the Python - python-list mailing list archive at Nabble.com. It looks like you're not calling wait() on your subprocesses: you're effectively launching a bunch of processes, then not waiting for them to finish before you ask the next process to operate on the same file. If you haven't given it a good look-over already, the subprocess documentation [1] is worth taking a little time over. [1]: http://docs.python.org/library/subprocess.html#popen-objects James From kiuhnm03.4t.yahoo.it Tue Mar 13 12:41:51 2012 From: kiuhnm03.4t.yahoo.it (Kiuhnm) Date: Tue, 13 Mar 2012 17:41:51 +0100 Subject: New Science Discovery: Perl Idiots Remain Idiots After A Decade!New Science Discovery: Perl Idiots Remain Idiots After A Decade! In-Reply-To: References: <0078bbfb-5dfc-48fc-af1a-69de3cf15c3e@b1g2000yqb.googlegroups.com> <4f5df4b3$0$1375$4fafbaef@reader1.news.tin.it> Message-ID: <4f5f78d1$0$1375$4fafbaef@reader2.news.tin.it> On 3/12/2012 20:00, Albert van der Horst wrote: [...] Sorry for triple posting. I hadn't noticed the follow up and I was blaming my newsserver. BTW, Python is the next language (right after Perl) I'm going to learn. Then I'll probably have a look at Ruby... Kiuhnm From dilvanezanardine at gmail.com Tue Mar 13 12:42:10 2012 From: dilvanezanardine at gmail.com (dilvanezanardine at gmail.com) Date: Tue, 13 Mar 2012 09:42:10 -0700 (PDT) Subject: Installing Python Apps on Mac Lion In-Reply-To: <2ffee45b-8987-4fb4-8c8b-c1eed728e890@glegroupsg2000goo.googlegroups.com> References: <2ffee45b-8987-4fb4-8c8b-c1eed728e890@glegroupsg2000goo.googlegroups.com> Message-ID: <15535377.495.1331656930882.JavaMail.geo-discussion-forums@ynje4> S?bado, 25 de Junho de 2011 02h20min49s UTC+1, JKPeck escreveu: > The Lion version of the OS on the Mac comes with Python 2.7 installed, but it is in /System/Library/Frameworks/..., and this area is not writable by third party apps. > > So is there a consensus on what apps that typically install under the Python site-packages directory should do in this situation? Installing Python from python.org puts it in the writable area /Library/Frameworks/Python.framework. > > So, what should a Python app installer do? > > Thanks Hello, currently I have: /Library/Python/2.7/ /Library/Frameworks/Python.framework/Versions/2.7/ /Users/user/Library/Python/2.7/ With 3 folders "site-packages" and do not know why. What's the difference? Thanks. From phgsouto at gmail.com Tue Mar 13 13:17:22 2012 From: phgsouto at gmail.com (Pedro H. G. Souto) Date: Tue, 13 Mar 2012 14:17:22 -0300 Subject: Software Engineer - In-Reply-To: <87vcm8h5fj.fsf@no-fixed-abode.cable.virginmedia.net> References: <74c28456-5467-48e8-88a9-e5649358373a@to5g2000pbc.googlegroups.com> <87vcm8h5fj.fsf@no-fixed-abode.cable.virginmedia.net> Message-ID: <4F5F8122.8080206@gmail.com> On 2012-03-13 12:44 PM, Paul Rudin wrote: > Just out of interest why do people object to job adverts here? Seems > harmless enough... Wannabe list admins... Or list admins with a need to proof themselves... Or none of the above. From neilc at norwich.edu Tue Mar 13 13:22:31 2012 From: neilc at norwich.edu (Neil Cerutti) Date: 13 Mar 2012 17:22:31 GMT Subject: Software Engineer - References: <74c28456-5467-48e8-88a9-e5649358373a@to5g2000pbc.googlegroups.com> <87vcm8h5fj.fsf@no-fixed-abode.cable.virginmedia.net> Message-ID: <9s9e2nF2rtU1@mid.individual.net> On 2012-03-13, Pedro H. G. Souto wrote: > On 2012-03-13 12:44 PM, Paul Rudin wrote: >> Just out of interest why do people object to job adverts here? >> Seems harmless enough... > > Wannabe list admins... Or list admins with a need to proof > themselves... Or none of the above. A job listing here or there would fine. If the discussion were clogged with them, it would be really annoying. In addition, it's more efficient to post job listing in a place where people looking for jobs can easily find them, and it's annoying and useless to post them in a place where reader not looking for jobs have to delete them. -- Neil Cerutti From ramit.prasad at jpmorgan.com Tue Mar 13 13:28:10 2012 From: ramit.prasad at jpmorgan.com (Prasad, Ramit) Date: Tue, 13 Mar 2012 17:28:10 +0000 Subject: Windows Contextmenu In-Reply-To: <4F5F2431.2080109@timgolden.me.uk> References: <4F5F2431.2080109@timgolden.me.uk> Message-ID: <5B80DD153D7D744689F57F4FB69AF4741C86E6@SCACMX008.exchad.jpmchase.net> > > Now the script runs fine but I don't get all arguments from sys.argv. > > > > No mather how many files I mark in the explorer I only get one as an > > argument. > > You're missing out vital information: > > * How have you attached this code to the context menu? What was > the exact registry entry (or other method) you used? From a quick Google search, it seems that most of the context menu entries open a single file. If multiple files are selected then the command is called once for each file. The workaround seems to check if the processes is already running and if it is then to directly send it a "open" command. That being said, since you are opening a web browser (or so it seems to me based on the webbrowser.open), you should not have an issue because modern web browsers will open each link in a tab. To answer your question, you will not get more than one as an argument. That is expected behavior. Ramit Ramit Prasad | JPMorgan Chase Investment Bank | Currencies Technology 712 Main Street | Houston, TX 77002 work phone: 713 - 216 - 5423 -- This email is confidential and subject to important disclaimers and conditions including on offers for the purchase or sale of securities, accuracy and completeness of information, viruses, confidentiality, legal privilege, and legal entity disclaimers, available at http://www.jpmorgan.com/pages/disclosures/email. From ferreirafm at lim12.fm.usp.br Tue Mar 13 14:01:44 2012 From: ferreirafm at lim12.fm.usp.br (ferreirafm) Date: Tue, 13 Mar 2012 11:01:44 -0700 (PDT) Subject: concatenate function In-Reply-To: References: <1331649332216-4574176.post@n6.nabble.com> <1331654366771-4574496.post@n6.nabble.com> Message-ID: <1331661704724-4574967.post@n6.nabble.com> Robert Kern-2 wrote > > When you report a problem, you should copy-and-paste the output that you > got and > also state the output that you expected. I have no idea what you mean when > you > say "subprocess.Popen seems not accept to run "qsub" over a second > program." > Code goes here: http://ompldr.org/vZDB5YQ stdout: $ no_name.py --toplist top_percent.list Traceback (most recent call last): File "/home6/psloliveira/ferreirafm/bin/no_name.py", line 73, in main() File "/home6/psloliveira/ferreirafm/bin/no_name.py", line 68, in main comb_slt(toplist) File "/home6/psloliveira/ferreirafm/bin/no_name.py", line 55, in comb_slt subprocess.Popen([cmd, options], env=qsub_env) File "/share/apps/python/lib/python2.7/subprocess.py", line 679, in __init__ errread, errwrite) File "/share/apps/python/lib/python2.7/subprocess.py", line 1228, in _execute_child raise child_exception OSError: [Errno 13] Permission denied -- View this message in context: http://python.6.n6.nabble.com/concatenate-function-tp4574176p4574967.html Sent from the Python - python-list mailing list archive at Nabble.com. From benjamin.kaplan at case.edu Tue Mar 13 15:28:37 2012 From: benjamin.kaplan at case.edu (Benjamin Kaplan) Date: Tue, 13 Mar 2012 15:28:37 -0400 Subject: Installing Python Apps on Mac Lion In-Reply-To: <15535377.495.1331656930882.JavaMail.geo-discussion-forums@ynje4> References: <2ffee45b-8987-4fb4-8c8b-c1eed728e890@glegroupsg2000goo.googlegroups.com> <15535377.495.1331656930882.JavaMail.geo-discussion-forums@ynje4> Message-ID: On Tue, Mar 13, 2012 at 12:42 PM, wrote: > > S?bado, 25 de Junho de 2011 02h20min49s UTC+1, JKPeck escreveu: > > The Lion version of the OS on the Mac comes with Python 2.7 installed, > > but it is in /System/Library/Frameworks/..., and this area is not writable > > by third party apps. > > > > So is there a consensus on what apps that typically install under the > > Python site-packages directory should do in this situation? ?Installing > > Python from python.org puts it in the writable area > > /Library/Frameworks/Python.framework. > > > > So, what should a Python app installer do? > > > > Thanks > > Hello, > > currently I have: > > /Library/Python/2.7/ > /Library/Frameworks/Python.framework/Versions/2.7/ > /Users/user/Library/Python/2.7/ > > With 3 folders "site-packages" and do not know why. > What's the difference? > > Thanks. > If I had to take a guess, having not played too much with Lion: /Library/Python/2.7 is for user-installed packages for the system python that are installed for all users. /Library/Frameworks/... is for the user-installed Python (that's where it's always gone) /Users/user/Library... is for user-installed packages for the system Python that are only installed for the specific user. From tjreedy at udel.edu Tue Mar 13 16:07:29 2012 From: tjreedy at udel.edu (Terry Reedy) Date: Tue, 13 Mar 2012 16:07:29 -0400 Subject: Windows Contextmenu In-Reply-To: References: Message-ID: On 3/13/2012 5:41 AM, Szabo, Patrick (LNG-VIE) wrote: > Hi, > > I wrote the following Script which I want to run from the open with > contextmenu in Windows. > Now the script runs fine but I don?t get all arguments from sys.argv. > > No mather how many files I mark in the explorer I only get one as an > argument. The right-click contextmenu is not a command line. It is more like a list of no-arg* methods to call on the selected file. * or rather, one input arg, with others having default values set when the menu entry is created. Sometimes a second input arg is handled, at least in effect, with a second submenu, but I am not familiar with how those are done in Windows. -- Terry Jan Reedy From robert.kern at gmail.com Tue Mar 13 16:35:04 2012 From: robert.kern at gmail.com (Robert Kern) Date: Tue, 13 Mar 2012 20:35:04 +0000 Subject: concatenate function In-Reply-To: <1331661704724-4574967.post@n6.nabble.com> References: <1331649332216-4574176.post@n6.nabble.com> <1331654366771-4574496.post@n6.nabble.com> <1331661704724-4574967.post@n6.nabble.com> Message-ID: On 3/13/12 6:01 PM, ferreirafm wrote: > > Robert Kern-2 wrote >> >> When you report a problem, you should copy-and-paste the output that you >> got and >> also state the output that you expected. I have no idea what you mean when >> you >> say "subprocess.Popen seems not accept to run "qsub" over a second >> program." >> > > Code goes here: > http://ompldr.org/vZDB5YQ > > stdout: > $ no_name.py --toplist top_percent.list > Traceback (most recent call last): > File "/home6/psloliveira/ferreirafm/bin/no_name.py", line 73, in > main() > File "/home6/psloliveira/ferreirafm/bin/no_name.py", line 68, in main > comb_slt(toplist) > File "/home6/psloliveira/ferreirafm/bin/no_name.py", line 55, in comb_slt > subprocess.Popen([cmd, options], env=qsub_env) > File "/share/apps/python/lib/python2.7/subprocess.py", line 679, in > __init__ > errread, errwrite) > File "/share/apps/python/lib/python2.7/subprocess.py", line 1228, in > _execute_child > raise child_exception > OSError: [Errno 13] Permission denied You need to use a command list like this: ['qsub', 'combine_silent.linuxgccrelease', '-database', '/home6/psloliveira/rosetta_database/', ...] The program to run ("qsub", not "qsub combine_silent.linuxgccrelease") and each individual argument must be a separate string in the list. You cannot combine them together with spaces. The reason you get a "Permission denied" error is that it tried to find an executable file named "qsub combine_silent.linuxgccrelease" and, obviously, could not. -- Robert Kern "I have come to believe that the whole world is an enigma, a harmless enigma that is made terrible by our own mad attempt to interpret it as though it had an underlying truth." -- Umberto Eco From clp2 at rebertia.com Tue Mar 13 16:40:40 2012 From: clp2 at rebertia.com (Chris Rebert) Date: Tue, 13 Mar 2012 13:40:40 -0700 Subject: concatenate function In-Reply-To: References: <1331649332216-4574176.post@n6.nabble.com> <1331654366771-4574496.post@n6.nabble.com> <1331661704724-4574967.post@n6.nabble.com> Message-ID: On Tue, Mar 13, 2012 at 1:35 PM, Robert Kern wrote: > On 3/13/12 6:01 PM, ferreirafm wrote: >> Robert Kern-2 wrote >>> When you report a problem, you should copy-and-paste the output that you >>> got and >>> also state the output that you expected. I have no idea what you mean >>> when >>> you >>> say "subprocess.Popen seems not accept to run "qsub" over a second >>> program." >>> >> >> Code goes here: >> http://ompldr.org/vZDB5YQ >> >> stdout: >> $ no_name.py --toplist top_percent.list >> Traceback (most recent call last): >> ? File "/home6/psloliveira/ferreirafm/bin/no_name.py", line 73, in >> ? ? main() >> ? File "/home6/psloliveira/ferreirafm/bin/no_name.py", line 68, in main >> ? ? comb_slt(toplist) >> ? File "/home6/psloliveira/ferreirafm/bin/no_name.py", line 55, in >> comb_slt >> ? ? subprocess.Popen([cmd, options], env=qsub_env) >> ? File "/share/apps/python/lib/python2.7/subprocess.py", line 679, in >> __init__ >> ? ? errread, errwrite) >> ? File "/share/apps/python/lib/python2.7/subprocess.py", line 1228, in >> _execute_child >> ? ? raise child_exception >> OSError: [Errno 13] Permission denied > > > You need to use a command list like this: > > ['qsub', 'combine_silent.linuxgccrelease', '-database', > '/home6/psloliveira/rosetta_database/', ...] > > The program to run ("qsub", not "qsub combine_silent.linuxgccrelease") and > each individual argument must be a separate string in the list. You cannot > combine them together with spaces. The reason you get a "Permission denied" > error is that it tried to find an executable file named "qsub > combine_silent.linuxgccrelease" and, obviously, could not. See also the first "Note" box (and the description of "args" generally) under http://docs.python.org/library/subprocess.html#popen-constructor Cheers, Chris From grahn+nntp at snipabacken.se Tue Mar 13 16:44:37 2012 From: grahn+nntp at snipabacken.se (Jorgen Grahn) Date: 13 Mar 2012 20:44:37 GMT Subject: Fast file data retrieval? References: <4F5E50F6.9070309@it.uu.se> Message-ID: On Mon, 2012-03-12, MRAB wrote: > On 12/03/2012 19:39, Virgil Stokes wrote: >> I have a rather large ASCII file that is structured as follows >> >> header line >> 9 nonblank lines with alphanumeric data >> header line >> 9 nonblank lines with alphanumeric data >> ... >> ... >> ... >> header line >> 9 nonblank lines with alphanumeric data >> EOF >> >> where, a data set contains 10 lines (header + 9 nonblank) and there can >> be several thousand >> data sets in a single file. In addition,*each header has a* *unique ID >> code*. >> >> Is there a fast method for the retrieval of a data set from this large >> file given its ID code? [Responding here since the original is not available on my server.] It depends on what you want to do. Access a few of the entries (what you call data sets) from your program? Process all of them? How fast do you need it to be? > Probably the best solution is to put it into a database. Have a look at > the sqlite3 module. Some people like to use databases for everything, others never use them. I'm in the latter crowd, so to me this sounds as overkill, and possibly impractical. What if he has to keep the text file around? A database on disk would mean duplicating the data. A database in memory would not offer any benefits over a hash. > Alternatively, you could scan the file, recording the ID and the file > offset in a dict so that, given an ID, you can seek directly to that > file position. Mmapping the file (the mmap module) is another option. But I wonder if this really would improve things. "Several thousand" entries is not much these days. If a line is 80 characters, 5000 entries would take ~3MB of memory. The time to move this from disk to a Python list of 9-tuples of strings would be almost only disk I/O. I think he should try to do it the dumb way first: read everything into memory once. /Jorgen -- // Jorgen Grahn O o . From roy at panix.com Tue Mar 13 17:08:08 2012 From: roy at panix.com (Roy Smith) Date: 13 Mar 2012 17:08:08 -0400 Subject: Enchancement suggestion for argparse: intuit type from default Message-ID: Using argparse, if I write: parser.add_argument('--foo', default=100) it seems like it should be able to intuit that the type of foo should be int (i.e. type(default)) without my having to write: parser.add_argument('--foo', type=int, default=100) Does this seem like a reasonable enhancement to argparse? From ben+python at benfinney.id.au Tue Mar 13 17:35:12 2012 From: ben+python at benfinney.id.au (Ben Finney) Date: Wed, 14 Mar 2012 08:35:12 +1100 Subject: Enchancement suggestion for argparse: intuit type from default References: Message-ID: <87zkbkgp67.fsf@benfinney.id.au> roy at panix.com (Roy Smith) writes: > Using argparse, if I write: > > parser.add_argument('--foo', default=100) > > it seems like it should be able to intuit that the type of foo should > be int (i.e. type(default)) [?] -0.5. That feels too magical to me. I don't see a need to special-case that usage. There's not much burden in being explicit for the argument type. -- \ ?Value your freedom or you will lose it, teaches history. | `\ ?Don't bother us with politics,? respond those who don't want | _o__) to learn.? ?Richard M. Stallman, 2002 | Ben Finney From ben+python at benfinney.id.au Tue Mar 13 18:37:39 2012 From: ben+python at benfinney.id.au (Ben Finney) Date: Wed, 14 Mar 2012 09:37:39 +1100 Subject: Adopting =?utf-8?B?4oCYbG9ja2ZpbGXigJk=?= References: <874nu5nywc.fsf@benfinney.id.au> Message-ID: <87ty1sgma4.fsf@benfinney.id.au> Chris Withers writes: > On 03/03/2012 21:43, Ben Finney wrote: > > I don't see a need to horse around with Git either :-) It's currently in > > Subversion, right? Can you not export the VCS history from Google Code's > > Subversion repository [?] > What's wrong with a "git svn clone svn-url-here" ? Thanks for the suggestion. I've imported it from Subversion into Bazaar (my preferred DVCS), and it went smoothly. I will proceed with a handover from Skip for maintenance of ?lockfile?. This will definitely need more people than me to maintain, though! I am interested and motivated to work on the Linux platform, but other platforms will suffer unless I get co-maintainers with experience in the different file locking semantics there. -- \ ?I find the whole business of religion profoundly interesting. | `\ But it does mystify me that otherwise intelligent people take | _o__) it seriously.? ?Douglas Adams | Ben Finney From davidgshi at yahoo.co.uk Tue Mar 13 19:05:39 2012 From: davidgshi at yahoo.co.uk (David Shi) Date: Tue, 13 Mar 2012 23:05:39 +0000 (GMT) Subject: Python-list Digest, Vol 102, Issue 64 In-Reply-To: References: Message-ID: <1331679939.28910.YahooMailNeo@web171605.mail.ir2.yahoo.com> I am looking very simple and straightforward open source Python REST and SOAP demo modules. I really need things which are very simple and convincing.?? I want to demonstrate these to other people. I want to promote you guys' interest.?? I find asp and others frustrating and occupy too much in the market and popularity. Can we do a new tidal wave to win a reasonable portion of the development market? Send me materials to davidgshi at yahoo.co.uk I will give it a go on behalf of the Python community. Regards. David ________________________________ From: "python-list-request at python.org" To: python-list at python.org Sent: Tuesday, 13 March 2012, 20:35 Subject: Python-list Digest, Vol 102, Issue 64 ----- Forwarded Message ----- Send Python-list mailing list submissions to ??? python-list at python.org To subscribe or unsubscribe via the World Wide Web, visit ??? http://mail.python.org/mailman/listinfo/python-list or, via email, send a message with subject or body 'help' to ??? python-list-request at python.org You can reach the person managing the list at ??? python-list-owner at python.org When replying, please edit your Subject line so it is more specific than "Re: Contents of Python-list digest..." Today's Topics: ? 1. Re: concatenate function (James Elford) ? 2. Re: New Science Discovery: Perl Idiots Remain Idiots After A ? ? ? Decade!New??? Science Discovery: Perl Idiots Remain Idiots After A ? ? ? Decade! (Kiuhnm) ? 3. Re: Installing Python Apps on? Mac Lion ? ? ? (dilvanezanardine at gmail.com) ? 4. Re: Software Engineer - (Pedro H. G. Souto) ? 5. Re: Software Engineer - (Neil Cerutti) ? 6. RE: Windows Contextmenu (Prasad, Ramit) ? 7. Re: concatenate function (ferreirafm) ? 8. Re: Installing Python Apps on Mac Lion (Benjamin Kaplan) ? 9. Re: Windows Contextmenu (Terry Reedy) ? 10. Re: concatenate function (Robert Kern) On 13/03/12 16:02, ferreirafm wrote: > Hi James, thank you for your replay. Indeed, the problem is qsub. And as > warned by Robert, I don't have functions properly, but just scripts. >? > > -- > View this message in context: http://python.6.n6.nabble.com/concatenate-function-tp4574176p4574511.html > Sent from the Python - python-list mailing list archive at Nabble.com. It looks like you're not calling wait() on your subprocesses: you're effectively launching a bunch of processes, then not waiting for them to finish before you ask the next process to operate on the same file. If you haven't given it a good look-over already, the subprocess documentation [1] is worth taking a little time over. ??? [1]: http://docs.python.org/library/subprocess.html#popen-objects James On 3/12/2012 20:00, Albert van der Horst wrote: [...] Sorry for triple posting. I hadn't noticed the follow up and I was blaming my newsserver. BTW, Python is the next language (right after Perl) I'm going to learn. Then I'll probably have a look at Ruby... Kiuhnm S?bado, 25 de Junho de 2011 02h20min49s UTC+1, JKPeck escreveu: > The Lion version of the OS on the Mac comes with Python 2.7 installed, but it is in /System/Library/Frameworks/..., and this area is not writable by third party apps. > > So is there a consensus on what apps that typically install under the Python site-packages directory should do in this situation?? Installing Python from python.org puts it in the writable area /Library/Frameworks/Python.framework. > > So, what should a Python app installer do? > > Thanks Hello, currently I have: /Library/Python/2.7/ /Library/Frameworks/Python.framework/Versions/2.7/ /Users/user/Library/Python/2.7/ With 3 folders "site-packages" and do not know why. What's the difference? Thanks. On 2012-03-13 12:44 PM, Paul Rudin wrote: > Just out of interest why do people object to job adverts here? Seems > harmless enough... Wannabe list admins... Or list admins with a need to proof themselves... Or none of the above. On 2012-03-13, Pedro H. G. Souto wrote: > On 2012-03-13 12:44 PM, Paul Rudin wrote: >> Just out of interest why do people object to job adverts here? >> Seems harmless enough... > > Wannabe list admins... Or list admins with a need to proof > themselves... Or none of the above. A job listing here or there would fine. If the discussion were clogged with them, it would be really annoying. In addition, it's more efficient to post job listing in a place where people looking for jobs can easily find them, and it's annoying and useless to post them in a place where reader not looking for jobs have to delete them. -- Neil Cerutti > > Now the script runs fine but I don't get all arguments from sys.argv. > > > > No mather how many files I mark in the explorer I only get one as an > > argument. > > You're missing out vital information: > > * How have you attached this code to the context menu? What was > the exact registry entry (or other method) you used? From a quick Google search, it seems that most of the context menu entries open a single file. If multiple files are selected then the command is called once for each file. The workaround seems to check if the processes is already running and if it is then to directly send it a "open" command. That being said, since you are opening a web browser (or so it seems to me based on the webbrowser.open), you should not have an issue because modern web browsers will open each link in a tab. To answer your question, you will not get more than one as an argument. That is expected behavior. Ramit Ramit Prasad | JPMorgan Chase Investment Bank | Currencies Technology 712 Main Street | Houston, TX 77002 work phone: 713 - 216 - 5423 -- This email is confidential and subject to important disclaimers and conditions including on offers for the purchase or sale of securities, accuracy and completeness of information, viruses, confidentiality, legal privilege, and legal entity disclaimers, available at http://www.jpmorgan.com/pages/disclosures/email. Robert Kern-2 wrote > > When you report a problem, you should copy-and-paste the output that you > got and > also state the output that you expected. I have no idea what you mean when > you > say "subprocess.Popen seems not accept to run "qsub" over a second > program." > Code goes here: http://ompldr.org/vZDB5YQ stdout: $ no_name.py --toplist top_percent.list Traceback (most recent call last): ? File "/home6/psloliveira/ferreirafm/bin/no_name.py", line 73, in ? ? main() ? File "/home6/psloliveira/ferreirafm/bin/no_name.py", line 68, in main ? ? comb_slt(toplist) ? File "/home6/psloliveira/ferreirafm/bin/no_name.py", line 55, in comb_slt ? ? subprocess.Popen([cmd, options], env=qsub_env) ? File "/share/apps/python/lib/python2.7/subprocess.py", line 679, in __init__ ? ? errread, errwrite) ? File "/share/apps/python/lib/python2.7/subprocess.py", line 1228, in _execute_child ? ? raise child_exception OSError: [Errno 13] Permission denied -- View this message in context: http://python.6.n6.nabble.com/concatenate-function-tp4574176p4574967.html Sent from the Python - python-list mailing list archive at Nabble.com. On Tue, Mar 13, 2012 at 12:42 PM, wrote: > > S?bado, 25 de Junho de 2011 02h20min49s UTC+1, JKPeck escreveu: > > The Lion version of the OS on the Mac comes with Python 2.7 installed, > > but it is in /System/Library/Frameworks/..., and this area is not writable > > by third party apps. > > > > So is there a consensus on what apps that typically install under the > > Python site-packages directory should do in this situation? ?Installing > > Python from python.org puts it in the writable area > > /Library/Frameworks/Python.framework. > > > > So, what should a Python app installer do? > > > > Thanks > > Hello, > > currently I have: > > /Library/Python/2.7/ > /Library/Frameworks/Python.framework/Versions/2.7/ > /Users/user/Library/Python/2.7/ > > With 3 folders "site-packages" and do not know why. > What's the difference? > > Thanks. > If I had to take a guess, having not played too much with Lion: /Library/Python/2.7 is for user-installed packages for the system python that are installed for all users. /Library/Frameworks/... is for the user-installed Python (that's where it's always gone) /Users/user/Library... is for user-installed packages for the system Python that are only installed for the specific user. On 3/13/2012 5:41 AM, Szabo, Patrick (LNG-VIE) wrote: > Hi, > > I wrote the following Script which I want to run from the open with > contextmenu in Windows. > Now the script runs fine but I don?t get all arguments from sys.argv. > > No mather how many files I mark in the explorer I only get one as an > argument. The right-click contextmenu is not a command line. It is more like a list of no-arg* methods to call on the selected file. * or rather, one input arg, with others having default values set when the menu entry is created. Sometimes a second input arg is handled, at least in effect, with a second submenu, but I am not familiar with how those are done in Windows. -- Terry Jan Reedy On 3/13/12 6:01 PM, ferreirafm wrote: > > Robert Kern-2 wrote >> >> When you report a problem, you should copy-and-paste the output that you >> got and >> also state the output that you expected. I have no idea what you mean when >> you >> say "subprocess.Popen seems not accept to run "qsub" over a second >> program." >> > > Code goes here: > http://ompldr.org/vZDB5YQ > > stdout: > $ no_name.py --toplist top_percent.list > Traceback (most recent call last): >? ? File "/home6/psloliveira/ferreirafm/bin/no_name.py", line 73, in >? ? ? main() >? ? File "/home6/psloliveira/ferreirafm/bin/no_name.py", line 68, in main >? ? ? comb_slt(toplist) >? ? File "/home6/psloliveira/ferreirafm/bin/no_name.py", line 55, in comb_slt >? ? ? subprocess.Popen([cmd, options], env=qsub_env) >? ? File "/share/apps/python/lib/python2.7/subprocess.py", line 679, in > __init__ >? ? ? errread, errwrite) >? ? File "/share/apps/python/lib/python2.7/subprocess.py", line 1228, in > _execute_child >? ? ? raise child_exception > OSError: [Errno 13] Permission denied You need to use a command list like this: ['qsub', 'combine_silent.linuxgccrelease', '-database', '/home6/psloliveira/rosetta_database/', ...] The program to run ("qsub", not "qsub combine_silent.linuxgccrelease") and each individual argument must be a separate string in the list. You cannot combine them together with spaces. The reason you get a "Permission denied" error is that it tried to find an executable file named "qsub combine_silent.linuxgccrelease" and, obviously, could not. -- Robert Kern "I have come to believe that the whole world is an enigma, a harmless enigma that is made terrible by our own mad attempt to interpret it as though it had an underlying truth." ? -- Umberto Eco -- http://mail.python.org/mailman/listinfo/python-list -------------- next part -------------- An HTML attachment was scrubbed... URL: From veeru.bangalore2012 at gmail.com Wed Mar 14 00:25:26 2012 From: veeru.bangalore2012 at gmail.com (Veeru .) Date: Tue, 13 Mar 2012 21:25:26 -0700 (PDT) Subject: India Software Developer Conference: Learn from the Experts at Top Tech Companies (March 24 & 25, 2012 Bangalore) Message-ID: <5e45aa44-b0c4-44f9-8e51-c5aeeac4f332@qb4g2000pbb.googlegroups.com> Hi, I got to know of an exciting event happening in Bangalore on March 24th & 25th India Software Developer Conference 2012 which is an enterprise software developer conference designed for developers, team leads, architects and project management is back! There is no other event in India with similar opportunities for learning, networking, and tracking innovation occurring in the Java, .NET, Html5, Mobile, Agile and Architecture communities I believe it is worth attending as there are interesting topics. The Conference starts at 8.30 AM. The Venue NIMHANS Convention Centre, Hosur Road, Near Diary Circle, Bangalore, The Conference organizers will call you back to confirm. Please find below is the url to go through the website http://tinyurl.com/ISDC-Blr Regards, Veeru From nagle at animats.com Wed Mar 14 01:32:14 2012 From: nagle at animats.com (John Nagle) Date: Tue, 13 Mar 2012 22:32:14 -0700 Subject: are int, float, long, double, side-effects of computer engineering? In-Reply-To: <7a32aa69-e1c7-4129-be11-70ae461b34b8@od7g2000pbb.googlegroups.com> References: <5aaded58-af09-41dc-9afd-56d7b7ced239@d7g2000pbl.googlegroups.com> <8a3cd8d4-26d2-4cdf-b66d-43895a0bcd1e@qb4g2000pbb.googlegroups.com> <7a32aa69-e1c7-4129-be11-70ae461b34b8@od7g2000pbb.googlegroups.com> Message-ID: <4f602d5b$0$12043$742ec2ed@news.sonic.net> On 3/7/2012 2:02 PM, Russ P. wrote: > On Mar 6, 7:25 pm, rusi wrote: >> On Mar 6, 6:11 am, Xah Lee wrote: > I might add that Mathematica is designed mainly for symbolic > computation, whereas IEEE floating point numbers are intended for > numerical computation. Those are two very different endeavors. I > played with Mathematica a bit several years ago, and I know it can do > numerical computation too. I wonder if it resorts to IEEE floating > point numbers when it does. Mathematica has, for some computations, algorithms to determine the precision of results. This is different than trying to do infinite precision arithmetic, which doesn't help as soon as you get to trig functions. It's about bounding the error. It's possible to do bounded arithmetic, where you carry along an upper and lower bound on each number. The problem is what to do about comparisons. Comparisons between bounded numbers are ambiguous when the ranges overlap. Algorithms have to be designed to deal with that. Mathematica has such algorithms for some operations, especially numerical integration. It's a very real issue. I had to deal with this when I was writing the first "ragdoll physics" system that worked right, back in the 1990s. Everybody else's system blew up on the hard cases; mine just slowed down. Correct integration over a force function that's changing over 18 orders of magnitude is difficult, but quite possible. (Here it is, from 1997: "http://www.youtube.com/watch?v=5lHqEwk7YHs") (A test with a heavy object: "http://www.youtube.com/watch?v=-DaWIHc1VLY". Most physics engines don't do heavy objects well. Everything looks too light. We call this the "boink problem.") John Nagle From alec.taylor6 at gmail.com Wed Mar 14 05:47:52 2012 From: alec.taylor6 at gmail.com (Alec Taylor) Date: Wed, 14 Mar 2012 20:47:52 +1100 Subject: PyCrypto builds neither with MSVC nor MinGW In-Reply-To: References: <35da69c3-edcc-4466-8a0d-70237c88af3b@qv4g2000pbc.googlegroups.com> <13993807.3661.1331611178050.JavaMail.geo-discussion-forums@pbcgf10> Message-ID: Oh wait, just realised it was loading the (x86) tools. Doing a quick search I noticed that I didn't have the x64 components installed, so loading up the MSVC08 setup again and installing it, then: copying vcvarsamd64.bat to vcvarsall.bat and adding its directory (C:\Program Files (x86)\Microsoft Visual Studio 9.0\VC\bin\amd64\) to PATH.... AND IT WORKS! =D From gelonida at gmail.com Wed Mar 14 06:07:33 2012 From: gelonida at gmail.com (Gelonida N) Date: Wed, 14 Mar 2012 11:07:33 +0100 Subject: Is there a ConfigParser which keeps comments Message-ID: Hi, At the moment I use ConfigParser http://docs.python.org/library/configparser.html for one of my applications. Now I'm looking for a library, which behaves like config parser, but with one minor difference. The write() mehtod should keep existing comments. Does anybody know or implement something like this or is there as switrch, that I overlooked in hte documentaiton. From rustompmody at gmail.com Wed Mar 14 06:22:02 2012 From: rustompmody at gmail.com (rusi) Date: Wed, 14 Mar 2012 03:22:02 -0700 (PDT) Subject: Enchancement suggestion for argparse: intuit type from default References: Message-ID: <431e658c-9dd2-4f49-b9be-d228367dc48e@ms3g2000pbb.googlegroups.com> On Mar 14, 2:08?am, r... at panix.com (Roy Smith) wrote: > Using argparse, if I write: > > ? ? parser.add_argument('--foo', default=100) > > it seems like it should be able to intuit that the type of foo should > be int (i.e. type(default)) without my having to write: > > ? ? parser.add_argument('--foo', type=int, default=100) > > Does this seem like a reasonable enhancement to argparse? Sounds reasonable to me From laloothadhani at gmail.com Wed Mar 14 07:41:23 2012 From: laloothadhani at gmail.com (laloo) Date: Wed, 14 Mar 2012 04:41:23 -0700 (PDT) Subject: Info on RIDE Message-ID: <6b8aa4a4-7515-4dd7-b05b-d68abd39d3db@pz2g2000pbc.googlegroups.com> Hi Sir I have installed the robot framework but have a problem understanding the RIDE and how to execute Data driven Test Case If you can take me through this on Skype it will be really great. Thanks Laloo Thadhani From ulrich.eckhardt at dominolaser.com Wed Mar 14 08:26:14 2012 From: ulrich.eckhardt at dominolaser.com (Ulrich Eckhardt) Date: Wed, 14 Mar 2012 13:26:14 +0100 Subject: Enchancement suggestion for argparse: intuit type from default In-Reply-To: References: Message-ID: <6cf639-pm6.ln1@satorlaser.homedns.org> Am 13.03.2012 22:08, schrieb Roy Smith: > Using argparse, if I write: > > parser.add_argument('--foo', default=100) > > it seems like it should be able to intuit that the type of foo should > be int (i.e. type(default)) without my having to write: > > parser.add_argument('--foo', type=int, default=100) > > Does this seem like a reasonable enhancement to argparse? The following would turn into an error: # in foo.py: p.add_argument('--offset', 0) # calling foo.py: foo.py --offset 1.5 OTOH, this would be obvious even from halfway serious testing, so I'm +1 for making this change. Have you looked at existing use of this and where it would break anything? When the argument doesn't match the type, is the error message sufficiently understandable? Uli From steve+comp.lang.python at pearwood.info Wed Mar 14 08:53:25 2012 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 14 Mar 2012 12:53:25 GMT Subject: Enchancement suggestion for argparse: intuit type from default References: <87zkbkgp67.fsf@benfinney.id.au> Message-ID: <4f6094c5$0$29972$c3e8da3$5496439d@news.astraweb.com> On Wed, 14 Mar 2012 08:35:12 +1100, Ben Finney wrote: > roy at panix.com (Roy Smith) writes: > >> Using argparse, if I write: >> >> parser.add_argument('--foo', default=100) >> >> it seems like it should be able to intuit that the type of foo should >> be int (i.e. type(default)) > [?] > > -0.5. > > That feels too magical to me. I don't see a need to special-case that > usage. There's not much burden in being explicit for the argument type. And yet you are programming in Python instead of Java, Pascal or Ada :) It's not magic at all, it's science! Or to be precise, it's a very simple form of type inference, similar to (but much more basic than) that used by languages such as Go, Haskell, Ocaml, and ML. http://en.wikipedia.org/wiki/Type_inference Given the premise that arguments in argparser are typed, if the argument can take the value 100 (the default), it is logical that it can't be a string (because 100 is not a string) or a boolean (because 100 is not a boolean) or a list (because... well, you get the point). What if you want an argument --foo that will accept arbitrary types? Then you would need some way to tell argparse not to infer the type from the default. Python *names* are not typed, but objects are. Python infers the type of the object from its syntax. We write: n = 100 and not: n = int 100 Assuming that argparse arguments are typed, and that there is a way to over-rule the type-inference, there is no need to declare types in the common case. Explicit declarations should be used only for the uncommon cases where type inference cannot cope. -- Steven From ben+python at benfinney.id.au Wed Mar 14 09:19:15 2012 From: ben+python at benfinney.id.au (Ben Finney) Date: Thu, 15 Mar 2012 00:19:15 +1100 Subject: Enchancement suggestion for argparse: intuit type from default References: <87zkbkgp67.fsf@benfinney.id.au> <4f6094c5$0$29972$c3e8da3$5496439d@news.astraweb.com> Message-ID: <87399bgw18.fsf@benfinney.id.au> Steven D'Aprano writes: > On Wed, 14 Mar 2012 08:35:12 +1100, Ben Finney wrote: > > That feels too magical to me. I don't see a need to special-case > > that usage. There's not much burden in being explicit for the > > argument type. > > And yet you are programming in Python instead of Java, Pascal or Ada > :) That's a good point :-) > It's not magic at all, it's science! Or to be precise, it's a very simple > form of type inference Right. I dislike proposals for run-time type inference in Python, since they are too magical. Especially since we're talking about user input (arguments from the command line to the program); that requires more explicit declarations and checking, not less. > What if you want an argument --foo that will accept arbitrary types? Then > you would need some way to tell argparse not to infer the type from the > default. So we would then need to special-case the special-case? Even more reason to dislike this proposal. > Explicit declarations should be used only for the uncommon cases where > type inference cannot cope. That's our point of disagreement, then: I think explicit declarations should be required regarding user input. -- \ ?Ridicule is the only weapon which can be used against | `\ unintelligible propositions.? ?Thomas Jefferson, 1816-07-30 | _o__) | Ben Finney From cosmius at gmail.com Wed Mar 14 09:28:58 2012 From: cosmius at gmail.com (Cosmia Luna) Date: Wed, 14 Mar 2012 06:28:58 -0700 (PDT) Subject: How to decide if a object is instancemethod? Message-ID: <8815977.3878.1331731738209.JavaMail.geo-discussion-forums@vbux23> class Foo(object): def bar(self): return 'Something' func = Foo().bar if type(func) == : # This should be always true pass # do something here What should type at ? Thanks Cosmia From roy at panix.com Wed Mar 14 09:30:45 2012 From: roy at panix.com (Roy Smith) Date: Wed, 14 Mar 2012 09:30:45 -0400 Subject: Enchancement suggestion for argparse: intuit type from default References: <87zkbkgp67.fsf@benfinney.id.au> <4f6094c5$0$29972$c3e8da3$5496439d@news.astraweb.com> <87399bgw18.fsf@benfinney.id.au> Message-ID: In article <87399bgw18.fsf at benfinney.id.au>, Ben Finney wrote: > Right. I dislike proposals for run-time type inference in Python, since > they are too magical. > > Especially since we're talking about user input (arguments from the > command line to the program); that requires more explicit declarations > and checking, not less. > > > What if you want an argument --foo that will accept arbitrary types? Then > > you would need some way to tell argparse not to infer the type from the > > default. > > So we would then need to special-case the special-case? Even more reason > to dislike this proposal. > > > Explicit declarations should be used only for the uncommon cases where > > type inference cannot cope. > > That's our point of disagreement, then: I think explicit declarations > should be required regarding user input. I wasn't suggesting that the type be inferred from what the user entered. I was suggesting it be inferred from what the programmer had done (i.e. what value they had given the 'default' parameter). It's already inferred that the type is a string if you don't give it any value. What possible meaning could: parser.add_argument('--foo', default=100) have? If I run the program with: $ prog then foo defaults to the integer 100, but if I run it with: $ prog --foo=100 then I get the string "100"? Surely there's not much of a use case for that. From didierblanchard at gmail.com Wed Mar 14 09:46:01 2012 From: didierblanchard at gmail.com (Dids) Date: Wed, 14 Mar 2012 06:46:01 -0700 (PDT) Subject: Instantiate a python class object in C Message-ID: <500e1575-78e7-45aa-8fc3-78427bbe917c@l7g2000vbw.googlegroups.com> Hi, Apologies if this was asked before, I couldn't find anything. I have a class defined in a python file: for example: class demo: [ class definition goes here] I'm writing a C extension. In the first function, I take an instance of the "demo" class and do my magic. It's working, all is good. What I can't figure out is how to create a second C function that returns a new instance to the "demo" class to python. There must a be tutorial somewhere, but I can't find anything. I do not want to define a new python class in C. Another example: This is working: demo_obj1 = demo() my_C_extension.function_1( demo_obj1 ) //working, all good. This I can't figure out how to do: new_demo_obj = my_C_extension.function_2() Thanks for reading, Dids, From joncle at googlemail.com Wed Mar 14 09:57:35 2012 From: joncle at googlemail.com (Jon Clements) Date: Wed, 14 Mar 2012 06:57:35 -0700 (PDT) Subject: How to decide if a object is instancemethod? In-Reply-To: <8815977.3878.1331731738209.JavaMail.geo-discussion-forums@vbux23> References: <8815977.3878.1331731738209.JavaMail.geo-discussion-forums@vbux23> Message-ID: <389400.5582.1331733455084.JavaMail.geo-discussion-forums@vbiz13> On Wednesday, 14 March 2012 13:28:58 UTC, Cosmia Luna wrote: > class Foo(object): > def bar(self): > return 'Something' > > func = Foo().bar > > if type(func) == : # This should be always true > pass # do something here > > What should type at ? > > Thanks > Cosmia import inspect if inspect.ismethod(foo): # ... Will return True if foo is a bound method. hth Jon From stefan_ml at behnel.de Wed Mar 14 10:13:05 2012 From: stefan_ml at behnel.de (Stefan Behnel) Date: Wed, 14 Mar 2012 15:13:05 +0100 Subject: Instantiate a python class object in C In-Reply-To: <500e1575-78e7-45aa-8fc3-78427bbe917c@l7g2000vbw.googlegroups.com> References: <500e1575-78e7-45aa-8fc3-78427bbe917c@l7g2000vbw.googlegroups.com> Message-ID: Dids, 14.03.2012 14:46: > Apologies if this was asked before, I couldn't find anything. > > I have a class defined in a python file: > for example: > > class demo: > [ class definition goes here] > > I'm writing a C extension. > In the first function, I take an instance of the "demo" class and do > my magic. It's working, all is good. > > What I can't figure out is how to create a second C function that > returns a new instance to the "demo" class to python. > There must a be tutorial somewhere, but I can't find anything. I do > not want to define a new python class in C. > > Another example: > This is working: > demo_obj1 = demo() > my_C_extension.function_1( demo_obj1 ) //working, all good. > > This I can't figure out how to do: > new_demo_obj = my_C_extension.function_2() You should consider giving Cython a try. It will allow you to write normal Python code for your C extension that it translates to efficient C code. This is much easier than writing all of this by hand, especially when it comes to classes. It will also optimise the code for you, so that you'll often end up with faster code than what you'd manually write. Stefan From josephmeiring at gmail.com Wed Mar 14 10:16:35 2012 From: josephmeiring at gmail.com (JoeM) Date: Wed, 14 Mar 2012 07:16:35 -0700 (PDT) Subject: Jinja2 + jQuery tabs widget Message-ID: <1715f106-4e6f-45db-b224-fb9f219c2027@x17g2000yqj.googlegroups.com> Hi All, I'm having issues including a {block} of content from Jinja2 template into a jQueryUI tab. Does anyone know if such a thing is possible? An example is below, which gives me a 500 error when loading the page. Thanks, Joe
    {% block map_content %} {% endblock %}
    From didierblanchard at gmail.com Wed Mar 14 10:28:35 2012 From: didierblanchard at gmail.com (Dids) Date: Wed, 14 Mar 2012 07:28:35 -0700 (PDT) Subject: Instantiate a python class object in C References: <500e1575-78e7-45aa-8fc3-78427bbe917c@l7g2000vbw.googlegroups.com> Message-ID: <44ca54da-a2ca-48ff-83e7-9de18b064f0e@y10g2000vbn.googlegroups.com> Ok, I have it :) PyImport_Import , PyModule_GetDict, PyDict_GetItemString and PyObject_CallObject Need to take a second look at cython when I have a spare cycle or 2. Thanks for the the tip :) A+ Dids, From ferreirafm at lim12.fm.usp.br Wed Mar 14 10:37:52 2012 From: ferreirafm at lim12.fm.usp.br (ferreirafm) Date: Wed, 14 Mar 2012 07:37:52 -0700 (PDT) Subject: concatenate function In-Reply-To: References: <1331649332216-4574176.post@n6.nabble.com> <1331654366771-4574496.post@n6.nabble.com> <1331661704724-4574967.post@n6.nabble.com> Message-ID: <1331735872293-4578408.post@n6.nabble.com> Hi there, The problem has been solved. I 've decided to run the python script as argument of qsub instead of run qsub from inside of the script itself. I also use .wait() as suggest by colleagues above. Final code goes here: http://ompldr.org/vZDFiag Thank you very much for helping. -- View this message in context: http://python.6.n6.nabble.com/concatenate-function-tp4574176p4578408.html Sent from the Python - python-list mailing list archive at Nabble.com. From joncle at googlemail.com Wed Mar 14 10:39:00 2012 From: joncle at googlemail.com (Jon Clements) Date: Wed, 14 Mar 2012 07:39:00 -0700 (PDT) Subject: Jinja2 + jQuery tabs widget In-Reply-To: <1715f106-4e6f-45db-b224-fb9f219c2027@x17g2000yqj.googlegroups.com> References: <1715f106-4e6f-45db-b224-fb9f219c2027@x17g2000yqj.googlegroups.com> Message-ID: <1279295.3910.1331735941023.JavaMail.geo-discussion-forums@vbue17> On Wednesday, 14 March 2012 14:16:35 UTC, JoeM wrote: > Hi All, > > I'm having issues including a {block} of content from Jinja2 > template into a jQueryUI tab. Does anyone know if such a thing is > possible? An example is below, which gives me a 500 error when loading > the page. > > Thanks, > Joe > > > > > > > > > > > {% block map_content %} {% endblock %} >
    >
    Firstly, this isn't really a Python language question - although jinja2 is a commonly used module for web frameworks. Secondly, the code looks fine, except we don't know what's in the map_content block. Thirdly, 500 is an internal server error - so it's possible it's nothing to do with any of this anyway -- could you provide a more comprehensive error message? Jon. From tymoteusz.jankowski at gmail.com Wed Mar 14 10:43:07 2012 From: tymoteusz.jankowski at gmail.com (xliiv) Date: Wed, 14 Mar 2012 07:43:07 -0700 (PDT) Subject: Is it technically possible to give Python option of naming process of running script? Message-ID: <19118128.4791.1331736187952.JavaMail.geo-discussion-forums@vbai14> Like the topic.. . I use Python a lot, both Windows and Linux, and it's little weird to have many python process without fast distinction which is what. From josephmeiring at gmail.com Wed Mar 14 10:50:10 2012 From: josephmeiring at gmail.com (JoeM) Date: Wed, 14 Mar 2012 07:50:10 -0700 (PDT) Subject: Jinja2 + jQuery tabs widget In-Reply-To: <1715f106-4e6f-45db-b224-fb9f219c2027@x17g2000yqj.googlegroups.com> References: <1715f106-4e6f-45db-b224-fb9f219c2027@x17g2000yqj.googlegroups.com> Message-ID: <32873446.2390.1331736610160.JavaMail.geo-discussion-forums@vbfl9> Disregard, apparently you can't include a {block} more than once in a Jinja2 template, which was causing the error. Cheers, Joed From rosuav at gmail.com Wed Mar 14 11:13:46 2012 From: rosuav at gmail.com (Chris Angelico) Date: Thu, 15 Mar 2012 02:13:46 +1100 Subject: Is it technically possible to give Python option of naming process of running script? In-Reply-To: <19118128.4791.1331736187952.JavaMail.geo-discussion-forums@vbai14> References: <19118128.4791.1331736187952.JavaMail.geo-discussion-forums@vbai14> Message-ID: On Thu, Mar 15, 2012 at 1:43 AM, xliiv wrote: > Like the topic.. . > I use Python a lot, both Windows and Linux, and it's little weird to have many python process without fast distinction which is what. I've no idea if it's even possible on Windows. On Linux, what you want is the prctl function, which (AFAIK) isn't directly available. Google is your friend, though. Question's already been asked on Stack Overflow and such, and has a few answers. Nothing that looks cut-and-dried ready, but several that might work. Look for 'prctl' and 'PR_SET_NAME', which are the C-level function and constant that do the job; a cursory examination of PyPI shows a module with prctl in the name, so that may be of value. ChrisA From invalid at invalid.invalid Wed Mar 14 12:02:02 2012 From: invalid at invalid.invalid (Grant Edwards) Date: Wed, 14 Mar 2012 16:02:02 +0000 (UTC) Subject: Is it technically possible to give Python option of naming process of running script? References: <19118128.4791.1331736187952.JavaMail.geo-discussion-forums@vbai14> Message-ID: On 2012-03-14, Chris Angelico wrote: > On Thu, Mar 15, 2012 at 1:43 AM, xliiv wrote: >> Like the topic.. . >> I use Python a lot, both Windows and Linux, and it's little weird to have many python process without fast distinction which is what. > > I've no idea if it's even possible on Windows. On Linux, what you want > is the prctl function, which (AFAIK) isn't directly available. > > Google is your friend, though. Question's already been asked on Stack > Overflow and such, and has a few answers. Nothing that looks > cut-and-dried ready, but several that might work. The question of how to set the application name comes up somewhat regularly. It would be awfully nice if there was a way for python applications to set their application name. It's especially useful for daemons, and makes it much easier when you can kill them by name instead of having to look up the PID. It seems like an excellent thing to add to the "os" module. > Look for 'prctl' and 'PR_SET_NAME', which are the C-level function > and constant that do the job; a cursory examination of PyPI shows a > module with prctl in the name, so that may be of value. -- Grant Edwards grant.b.edwards Yow! TONY RANDALL! Is YOUR at life a PATIO of FUN?? gmail.com From tjreedy at udel.edu Wed Mar 14 13:06:30 2012 From: tjreedy at udel.edu (Terry Reedy) Date: Wed, 14 Mar 2012 13:06:30 -0400 Subject: Is there a ConfigParser which keeps comments In-Reply-To: References: Message-ID: On 3/14/2012 6:07 AM, Gelonida N wrote: > Hi, > > > At the moment I use ConfigParser > http://docs.python.org/library/configparser.html > for one of my applications. > > > Now I'm looking for a library, which behaves like config parser, but > with one minor difference. > > The write() mehtod should keep existing comments. > Does anybody know or implement something like this or is there as > switrch, that I overlooked in hte documentaiton. Assuming that you have not overlooked anything, I would just subclass ConfigParser with an altered write method. -- Terry Jan Reedy From tjreedy at udel.edu Wed Mar 14 13:13:49 2012 From: tjreedy at udel.edu (Terry Reedy) Date: Wed, 14 Mar 2012 13:13:49 -0400 Subject: Is it technically possible to give Python option of naming process of running script? In-Reply-To: References: <19118128.4791.1331736187952.JavaMail.geo-discussion-forums@vbai14> Message-ID: On 3/14/2012 12:02 PM, Grant Edwards wrote: > It seems like an excellent thing to add to the "os" module. If 'prctl' is a standard POSIX system call, then it should be a candidate for inclusion in the os module if someone opens a tracker enhancement issue and presents an argument in favor. -- Terry Jan Reedy From ramit.prasad at jpmorgan.com Wed Mar 14 13:20:50 2012 From: ramit.prasad at jpmorgan.com (Prasad, Ramit) Date: Wed, 14 Mar 2012 17:20:50 +0000 Subject: Is it technically possible to give Python option of naming process of running script? In-Reply-To: References: <19118128.4791.1331736187952.JavaMail.geo-discussion-forums@vbai14> Message-ID: <5B80DD153D7D744689F57F4FB69AF474026A27FC@SBECMX008.exchad.jpmchase.net> > > It seems like an excellent thing to add to the "os" module. > > If 'prctl' is a standard POSIX system call, then it should be a > candidate for inclusion in the os module if someone opens a tracker > enhancement issue and presents an argument in favor. I think this request was already denied: http://bugs.python.org/issue5672 Ramit Ramit Prasad | JPMorgan Chase Investment Bank | Currencies Technology 712 Main Street | Houston, TX 77002 work phone: 713 - 216 - 5423 -- This email is confidential and subject to important disclaimers and conditions including on offers for the purchase or sale of securities, accuracy and completeness of information, viruses, confidentiality, legal privilege, and legal entity disclaimers, available at http://www.jpmorgan.com/pages/disclosures/email. From python at mrabarnett.plus.com Wed Mar 14 13:26:19 2012 From: python at mrabarnett.plus.com (MRAB) Date: Wed, 14 Mar 2012 17:26:19 +0000 Subject: Enchancement suggestion for argparse: intuit type from default In-Reply-To: References: <87zkbkgp67.fsf@benfinney.id.au> <4f6094c5$0$29972$c3e8da3$5496439d@news.astraweb.com> <87399bgw18.fsf@benfinney.id.au> Message-ID: <4F60D4BB.9000803@mrabarnett.plus.com> On 14/03/2012 13:30, Roy Smith wrote: > In article<87399bgw18.fsf at benfinney.id.au>, > Ben Finney wrote: > >> Right. I dislike proposals for run-time type inference in Python, since >> they are too magical. >> >> Especially since we're talking about user input (arguments from the >> command line to the program); that requires more explicit declarations >> and checking, not less. >> >> > What if you want an argument --foo that will accept arbitrary types? Then >> > you would need some way to tell argparse not to infer the type from the >> > default. >> >> So we would then need to special-case the special-case? Even more reason >> to dislike this proposal. >> >> > Explicit declarations should be used only for the uncommon cases where >> > type inference cannot cope. >> >> That's our point of disagreement, then: I think explicit declarations >> should be required regarding user input. > > I wasn't suggesting that the type be inferred from what the user > entered. I was suggesting it be inferred from what the programmer had > done (i.e. what value they had given the 'default' parameter). > In other words, if there's a default but no explicit type, then the type is the type of the default. > It's already inferred that the type is a string if you don't give it any > value. What possible meaning could: > > parser.add_argument('--foo', default=100) > > have? If I run the program with: > > $ prog > > then foo defaults to the integer 100, but if I run it with: > > $ prog --foo=100 > > then I get the string "100"? Surely there's not much of a use case for > that. From ramit.prasad at jpmorgan.com Wed Mar 14 13:27:10 2012 From: ramit.prasad at jpmorgan.com (Prasad, Ramit) Date: Wed, 14 Mar 2012 17:27:10 +0000 Subject: Is it technically possible to give Python option of naming process of running script? In-Reply-To: <5B80DD153D7D744689F57F4FB69AF474026A27FC@SBECMX008.exchad.jpmchase.net> References: <19118128.4791.1331736187952.JavaMail.geo-discussion-forums@vbai14> <5B80DD153D7D744689F57F4FB69AF474026A27FC@SBECMX008.exchad.jpmchase.net> Message-ID: <5B80DD153D7D744689F57F4FB69AF474026A280E@SBECMX008.exchad.jpmchase.net> > > > It seems like an excellent thing to add to the "os" module. > > > > If 'prctl' is a standard POSIX system call, then it should be a > > candidate for inclusion in the os module if someone opens a tracker > > enhancement issue and presents an argument in favor. > > > I think this request was already denied: http://bugs.python.org/issue5672 Also take a look at: https://github.com/dvarrazzo/py-setproctitle Though since they just create a Named Object in Windows, I am not sure it would work for something like killall. Ramit Ramit Prasad | JPMorgan Chase Investment Bank | Currencies Technology 712 Main Street | Houston, TX 77002 work phone: 713 - 216 - 5423 -- This email is confidential and subject to important disclaimers and conditions including on offers for the purchase or sale of securities, accuracy and completeness of information, viruses, confidentiality, legal privilege, and legal entity disclaimers, available at http://www.jpmorgan.com/pages/disclosures/email. From alain at dpt-info.u-strasbg.fr Wed Mar 14 13:34:34 2012 From: alain at dpt-info.u-strasbg.fr (Alain Ketterlin) Date: Wed, 14 Mar 2012 18:34:34 +0100 Subject: Is it technically possible to give Python option of naming process of running script? References: <19118128.4791.1331736187952.JavaMail.geo-discussion-forums@vbai14> Message-ID: <87zkbjgk7p.fsf@dpt-info.u-strasbg.fr> Terry Reedy writes: > On 3/14/2012 12:02 PM, Grant Edwards wrote: > >> It seems like an excellent thing to add to the "os" module. > > If 'prctl' is a standard POSIX system call, then it should be a > candidate for inclusion in the os module if someone opens a tracker > enhancement issue and presents an argument in favor. It's not. The man page says "This call is Linux-specific." -- Alain. From mabhanisi.blues at gmail.com Wed Mar 14 14:03:28 2012 From: mabhanisi.blues at gmail.com (mabhanisi blues) Date: Wed, 14 Mar 2012 11:03:28 -0700 (PDT) Subject: blues Message-ID: <6fd5c5e4-5a5e-404a-ac61-255a2ca9e970@i18g2000vbx.googlegroups.com> Can i come in am i welcome From python.list at tim.thechases.com Wed Mar 14 14:13:12 2012 From: python.list at tim.thechases.com (Tim Chase) Date: Wed, 14 Mar 2012 13:13:12 -0500 Subject: Is there a ConfigParser which keeps comments In-Reply-To: References: Message-ID: <4F60DFB8.8080703@tim.thechases.com> On 03/14/12 12:06, Terry Reedy wrote: > On 3/14/2012 6:07 AM, Gelonida N wrote: >> Now I'm looking for a library, which behaves like config parser, but >> with one minor difference. >> >> The write() mehtod should keep existing comments. > > Assuming that you have not overlooked anything, I would just subclass > ConfigParser with an altered write method. It would require a lot more than that. It would entail changing the reading as well so that it preserved the comments as well as the order of sections & keys, and a way of storing those associated comments in sequence. I looked into it a fair while back and it was a LOT more work than I cared to do for minimal gain. I wimped out and just documented it with "If you use the ability to (re)write a configuration file, it will not keep any comments or ordering from any original sources." -tkc From darrel343 at gmail.com Wed Mar 14 14:41:27 2012 From: darrel343 at gmail.com (Darrel Grant) Date: Wed, 14 Mar 2012 11:41:27 -0700 Subject: Global join function? Message-ID: In the virtualenv example bootstrap code, a global join function is used. http://pypi.python.org/pypi/virtualenv subprocess.call([join(home_dir, 'bin', 'easy_install'), 'BlogApplication']) In interpeter, I tried this: >>> [join([], 'bin', 'easy_install')] Traceback (most recent call last): File "", line 1, in NameError: name 'join' is not defined I think I've seen this used elsewhere, but googling only seems to show results about the string method join, not whatever this is. To be clear, I understand how to use "".join(list), but have not found any information about this other, seemingly global, join function which takes multiple arguments. It's been bugging me. From joncle at googlemail.com Wed Mar 14 14:52:50 2012 From: joncle at googlemail.com (Jon Clements) Date: Wed, 14 Mar 2012 11:52:50 -0700 (PDT) Subject: Global join function? In-Reply-To: References: Message-ID: <9936996.807.1331751170123.JavaMail.geo-discussion-forums@vbyl20> On Wednesday, 14 March 2012 18:41:27 UTC, Darrel Grant wrote: > In the virtualenv example bootstrap code, a global join function is used. > > http://pypi.python.org/pypi/virtualenv > > subprocess.call([join(home_dir, 'bin', 'easy_install'), > 'BlogApplication']) > > > In interpeter, I tried this: > > >>> [join([], 'bin', 'easy_install')] > Traceback (most recent call last): > File "", line 1, in > NameError: name 'join' is not defined > > I think I've seen this used elsewhere, but googling only seems to show > results about the string method join, not whatever this is. > > To be clear, I understand how to use "".join(list), but have not found > any information about this other, seemingly global, join function > which takes multiple arguments. It's been bugging me. os.path.join Jon From joncle at googlemail.com Wed Mar 14 14:52:50 2012 From: joncle at googlemail.com (Jon Clements) Date: Wed, 14 Mar 2012 11:52:50 -0700 (PDT) Subject: Global join function? In-Reply-To: References: Message-ID: <9936996.807.1331751170123.JavaMail.geo-discussion-forums@vbyl20> On Wednesday, 14 March 2012 18:41:27 UTC, Darrel Grant wrote: > In the virtualenv example bootstrap code, a global join function is used. > > http://pypi.python.org/pypi/virtualenv > > subprocess.call([join(home_dir, 'bin', 'easy_install'), > 'BlogApplication']) > > > In interpeter, I tried this: > > >>> [join([], 'bin', 'easy_install')] > Traceback (most recent call last): > File "", line 1, in > NameError: name 'join' is not defined > > I think I've seen this used elsewhere, but googling only seems to show > results about the string method join, not whatever this is. > > To be clear, I understand how to use "".join(list), but have not found > any information about this other, seemingly global, join function > which takes multiple arguments. It's been bugging me. os.path.join Jon From clp2 at rebertia.com Wed Mar 14 14:54:32 2012 From: clp2 at rebertia.com (Chris Rebert) Date: Wed, 14 Mar 2012 11:54:32 -0700 Subject: Global join function? In-Reply-To: References: Message-ID: On Wed, Mar 14, 2012 at 11:41 AM, Darrel Grant wrote: > In the virtualenv example bootstrap code, a global join function is used. > > http://pypi.python.org/pypi/virtualenv > > ? ?subprocess.call([join(home_dir, 'bin', 'easy_install'), > ? ? ? ? ? ? ? ? ? ? 'BlogApplication']) > > > In interpeter, I tried this: > >>>> [join([], 'bin', 'easy_install')] > Traceback (most recent call last): > ?File "", line 1, in > NameError: name 'join' is not defined > > I think I've seen this used elsewhere, but googling only seems to show > results about the string method join, not whatever this is. Those example snippets are broken. They're presumably missing the line: from os.path import join Docs for the function in question: http://docs.python.org/library/os.path.html#os.path.join Cheers, Chris From __peter__ at web.de Wed Mar 14 14:59:03 2012 From: __peter__ at web.de (Peter Otten) Date: Wed, 14 Mar 2012 19:59:03 +0100 Subject: Global join function? References: Message-ID: Darrel Grant wrote: > In the virtualenv example bootstrap code, a global join function is used. > > http://pypi.python.org/pypi/virtualenv At this point there is probably an import that you have overlooked: from os.path import join > subprocess.call([join(home_dir, 'bin', 'easy_install'), > 'BlogApplication']) > > > In interpeter, I tried this: > >>>> [join([], 'bin', 'easy_install')] > Traceback (most recent call last): > File "", line 1, in > NameError: name 'join' is not defined > > I think I've seen this used elsewhere, but googling only seems to show > results about the string method join, not whatever this is. > > To be clear, I understand how to use "".join(list), but have not found > any information about this other, seemingly global, join function > which takes multiple arguments. It's been bugging me. From ian.g.kelly at gmail.com Wed Mar 14 15:03:28 2012 From: ian.g.kelly at gmail.com (Ian Kelly) Date: Wed, 14 Mar 2012 13:03:28 -0600 Subject: Enchancement suggestion for argparse: intuit type from default In-Reply-To: References: <87zkbkgp67.fsf@benfinney.id.au> <4f6094c5$0$29972$c3e8da3$5496439d@news.astraweb.com> <87399bgw18.fsf@benfinney.id.au> Message-ID: On Wed, Mar 14, 2012 at 7:30 AM, Roy Smith wrote: > It's already inferred that the type is a string if you don't give it any > value. ?What possible meaning could: > > parser.add_argument('--foo', default=100) > > have? ?If I run the program with: > > $ prog > > then foo defaults to the integer 100, but if I run it with: > > $ prog --foo=100 > > then I get the string "100"? ?Surely there's not much of a use case for > that. What about: parser.add_argument('--foo', default=None) Probably it should not infer NoneType as the argument type in this case. So would it just ignore the default in this case and let the type remain str? Also, how would the inference interact with different actions? For example: parser.add_argument('--foo', action='append', default=['one']) I'm not exactly sure what a use case for this might be, but anyway, the type here should clearly be str, not list. And then what about this variation: parser.add_argument('--foo', action='append', default=[1]) Should it try to infer that because the list contains an int, the type should be int? And even if you manage to get the inference working flawlessly and expectedly for append, what about custom actions? It seems to me that there are a large number of edge cases here that will end up hurting predictability for the end user. Cheers, Ian From michael at stroeder.com Wed Mar 14 15:57:48 2012 From: michael at stroeder.com (=?ISO-8859-1?Q?Michael_Str=F6der?=) Date: Wed, 14 Mar 2012 20:57:48 +0100 Subject: ANN: python-ldap 2.4.9 Message-ID: Find a new release of python-ldap: http://pypi.python.org/pypi/python-ldap/2.4.8 python-ldap provides an object-oriented API to access LDAP directory servers from Python programs. It mainly wraps the OpenLDAP 2.x libs for that purpose. Additionally it contains modules for other LDAP-related stuff (e.g. processing LDIF, LDAPURLs and LDAPv3 schema). Project's web site: http://www.python-ldap.org/ Ciao, Michael. ---------------------------------------------------------------- Released 2.4.9 2012-03-14 Changes since 2.4.8: Lib/ * ldapobject.ReconnectLDAPObject.reconnect() now does kind of an internal locking to pause other threads while reconnecting is pending. * Changes to bind- and startTLS-related operation methods of class ReconnectLDAPObject for more robustness * New constant ldap.OPT_NAMES_DICT contains mapping from integer to variable name for all option-related constants. From croepha at gmail.com Wed Mar 14 16:37:12 2012 From: croepha at gmail.com (Croepha) Date: Wed, 14 Mar 2012 14:37:12 -0600 Subject: Style question (Poll) Message-ID: Which is preferred: for value in list: if not value is another_value: value.do_something() break --or-- if list and not list[0] is another_value: list[0].do_something() Comments are welcome, Thanks -------------- next part -------------- An HTML attachment was scrubbed... URL: From arnodel at gmail.com Wed Mar 14 16:49:02 2012 From: arnodel at gmail.com (Arnaud Delobelle) Date: Wed, 14 Mar 2012 20:49:02 +0000 Subject: Style question (Poll) In-Reply-To: References: Message-ID: On 14 March 2012 20:37, Croepha wrote: > Which is?preferred: > > for value in list: > ?if not value is another_value: > ? ?value.do_something() > ? ?break > > --or-- > > if list and not list[0] is another_value: > ?list[0].do_something() Hard to say, since they don't do the same thing :) I suspect you meant: for value in list: ? if not value is another_value: ? ? value.do_something() ?break I always feel uncomfortable with this because it's misleading: a loop that never loops. -- Arnaud From sorsorday at gmail.com Wed Mar 14 16:53:27 2012 From: sorsorday at gmail.com (Herman) Date: Wed, 14 Mar 2012 13:53:27 -0700 Subject: How to break long method name into more than one line? Message-ID: I followed the rule because it was a very good advice. For example, def test_plus_1Plus1_2(self): If this test fails, you immediately know that it's testing the "plus" method, with 1 and 1 as the arguments, and expect to return 2. Sticking this rule also means your test cases are small enough, so you clearly know what you are testing on. Most of the time, the method name is what you first see when your test fails. Another alternative is to put meaningful string in each of the assert, which is probably not practical. You are right, only people who really follow the TDD method know the good things about it. This naming rule served me very well. Tests method should have meaningful name, and the advice by the book is a meaningful one. I said it's the TDD book because I forgot the exact title. It's actually called Test Driven: TDD and Acceptance TDD for Java Developers. I thought it should be popular enough that most people learned TDD may have heard it also used this naming advice, but look like i was wrong. > *The* TDD book? There's only one? Surely not. > > That rule sounds utterly impractical. I can't think of anything to > recommend it. Like any other function, method or class, tests should have > meaningful names, but reading the name alone should not necessarily tell > you *everything* about the function. > > We have "len", not "len_sequence_or_mapping_int", and similarly it is > perfectly reasonable to have "test_len_empty" rather than > "test_len_emptylist_emptystr_emptyunicode_emptydict_emptyset_emptytuple_zero". > > I expect that naming rule was invented by either people who have heard of > test driven development, but never actually done it, or by people so > anally-retentive that if they make seven short car trips over an hour, > they check the tyre pressure, oil and water seven times because "the > manual says to check before *every* trip". > > No offence. > > My advice is to moderate the naming convention of your tests with a good > dose of common sense and aim for names which are readable rather than > names that contain everything including the kitchen sink. Imagine you are > in a technical meeting with some of your fellow programmers, and need to > ask for help with a failing test. Imagine saying the name of the test > aloud in a sentence. Does it add clarity to the discussion, or obfuscate > it? > > People's short term memory can only hold so much (allegedly "seven plus > or minus two"), and if the name itself hits that limit, you leave nothing > left for the rest of the sentence. > > http://en.wikipedia.org/wiki/The_Magical_Number_Seven,_Plus_or_Minus_Two > > Names should be practically, rather than conforming to some naming rule > that hurts readability and obfuscates the tests. > > From tjreedy at udel.edu Wed Mar 14 17:16:05 2012 From: tjreedy at udel.edu (Terry Reedy) Date: Wed, 14 Mar 2012 17:16:05 -0400 Subject: Style question (Poll) In-Reply-To: References: Message-ID: On 3/14/2012 4:49 PM, Arnaud Delobelle wrote: > On 14 March 2012 20:37, Croepha wrote: >> Which is preferred: >> >> for value in list: >> if not value is another_value: >> value.do_something() >> break Do you really mean 'is' or '=='? If you mean x is not y, write it that way. 'not x is y' can be misread and misunderstood, depending on whether the 'is' is true or not. >>> not 1 is 1 False >>> not (1 is 1) False >>> (not 1) is 1 False Does not matter how read. >>> not (1 is 0) True >>> (not 1) is 0 False >>> not 1 is 0 True Does matter how read. >> if list and not list[0] is another_value: >> list[0].do_something() Or try: value = mylist[0] if value is not another_value: value.dosomething except IndexError: pass I would not do this in this case of index 0, but if the index were a complicated expression or expensive function call, making 'if list' an inadequate test, I might. > Hard to say, since they don't do the same thing :) > > I suspect you meant: > > for value in list: > if not value is another_value: > value.do_something() > break > > I always feel uncomfortable with this because it's misleading: a loop > that never loops. I agree. Please do not do this in public ;-). -- Terry Jan Reedy From ben+python at benfinney.id.au Wed Mar 14 17:26:22 2012 From: ben+python at benfinney.id.au (Ben Finney) Date: Thu, 15 Mar 2012 08:26:22 +1100 Subject: How to decide if a object is instancemethod? References: <8815977.3878.1331731738209.JavaMail.geo-discussion-forums@vbux23> <389400.5582.1331733455084.JavaMail.geo-discussion-forums@vbiz13> Message-ID: <87ty1qg9hd.fsf@benfinney.id.au> Jon Clements writes: > import inspect > if inspect.ismethod(foo): > # ... > > Will return True if foo is a bound method. But under what other conditions will it return True? The name suggests that *any* method ? static method, class method, bound method, unbound method ? will also result in True. The documentation says only ?instance method?, though. Confusing :-( -- \ ?Airports are ugly. Some are very ugly. Some attain a degree of | `\ ugliness that can only be the result of a special effort.? | _o__) ?Douglas Adams, _The Long Dark Tea-Time Of The Soul_ | Ben Finney From tjreedy at udel.edu Wed Mar 14 17:40:54 2012 From: tjreedy at udel.edu (Terry Reedy) Date: Wed, 14 Mar 2012 17:40:54 -0400 Subject: How to break long method name into more than one line? In-Reply-To: References: Message-ID: On 3/14/2012 4:53 PM, Herman wrote: > I followed the rule because it was a very good advice. For example, > def test_plus_1Plus1_2(self): Suppose you want to test that a function call returns a particular 300-char multiline string? > If this test fails, you immediately know that it's testing the "plus" > method, with 1 and 1 as the arguments, and expect to return 2. If you use unittest and the right assert method, the message will say more than pass/fail. I believe .AssertEqual(a,b, 'optional message') will say that a is not equal to b, and print the optional message. "In addition, if first and second are the exact same type and one of list, tuple, dict, set, frozenset or str or any type that a subclass registers with addTypeEqualityFunc() the type-specific equality function will be called in order to generate a more useful default error message (see also the list of type-specific methods)." For instance "assertMultiLineEqual(first, second, msg=None) Test that the multiline string first is equal to the string second. When not equal a diff of the two strings highlighting the differences will be included in the error message. This method is used by default when comparing strings with assertEqual()." > Sticking this rule also means your test cases are small enough, To me, it makes them too small. I think a test of addition should have multiple input-output pairs. Besides that, a single test output object may need to pass multiple conditions to pass. Putting them all in a single large conjuction would obscure which is not passing. However, anything is better than no tests. -- Terry Jan Reedy From ramit.prasad at jpmorgan.com Wed Mar 14 18:15:38 2012 From: ramit.prasad at jpmorgan.com (Prasad, Ramit) Date: Wed, 14 Mar 2012 22:15:38 +0000 Subject: Style question (Poll) In-Reply-To: References: Message-ID: <5B80DD153D7D744689F57F4FB69AF474026A5ECE@SBECMX008.exchad.jpmchase.net> > >> Which is preferred: > >> > >> for value in list: > >> if not value is another_value: > >> value.do_something() > >> break > > Do you really mean 'is' or '=='? Let me expound on how 'is' and '==' are very different. It may work for some comparisons but often not for others. Certain examples work because of the Python implementation. >>> c = 1 >>> d = 1 >>> c is d # This only works because CPython caches small values. True >>> c == d True >>> a = 10000000000000 >>> b = 10000000000000 >>> a is b False >>> a == b True >>> 10000000000000 is 10000000000000 True '10000000000000 is 10000000000000' works because the interpreter caches the number because it is on the same line. Only use 'is' if you are looking for objects like True, False, None or something that MUST be exactly the same object. In general, use '=='. Ramit Ramit Prasad | JPMorgan Chase Investment Bank | Currencies Technology 712 Main Street | Houston, TX 77002 work phone: 713 - 216 - 5423 -- This email is confidential and subject to important disclaimers and conditions including on offers for the purchase or sale of securities, accuracy and completeness of information, viruses, confidentiality, legal privilege, and legal entity disclaimers, available at http://www.jpmorgan.com/pages/disclosures/email. From arnodel at gmail.com Wed Mar 14 18:30:01 2012 From: arnodel at gmail.com (Arnaud Delobelle) Date: Wed, 14 Mar 2012 22:30:01 +0000 Subject: Style question (Poll) In-Reply-To: <5B80DD153D7D744689F57F4FB69AF474026A5ECE@SBECMX008.exchad.jpmchase.net> References: <5B80DD153D7D744689F57F4FB69AF474026A5ECE@SBECMX008.exchad.jpmchase.net> Message-ID: On 14 March 2012 22:15, Prasad, Ramit wrote: > Only use 'is' if you are looking for objects like True, > False, None or something that MUST be exactly the same object. I've rarely seen valid uses of 'is True' or 'is False'. -- Arnaud From ramit.prasad at jpmorgan.com Wed Mar 14 19:08:17 2012 From: ramit.prasad at jpmorgan.com (Prasad, Ramit) Date: Wed, 14 Mar 2012 23:08:17 +0000 Subject: Style question (Poll) In-Reply-To: References: <5B80DD153D7D744689F57F4FB69AF474026A5ECE@SBECMX008.exchad.jpmchase.net> Message-ID: <5B80DD153D7D744689F57F4FB69AF474026A5FC8@SBECMX008.exchad.jpmchase.net> > > Only use 'is' if you are looking for objects like True, > > False, None or something that MUST be exactly the same object. > > I've rarely seen valid uses of 'is True' or 'is False'. It can be useful when you think something might be None or False. Although, I suppose you could always just use 'is None' instead. >>> 1 == True True >>> 1 is True False >>> 0 == False True >>> 0 is False False Granted, the above example is a pretty facetious case; not sure I can come up with a reasonably real world use case. Ramit Ramit Prasad | JPMorgan Chase Investment Bank | Currencies Technology 712 Main Street | Houston, TX 77002 work phone: 713 - 216 - 5423 -- This email is confidential and subject to important disclaimers and conditions including on offers for the purchase or sale of securities, accuracy and completeness of information, viruses, confidentiality, legal privilege, and legal entity disclaimers, available at http://www.jpmorgan.com/pages/disclosures/email. From steve+comp.lang.python at pearwood.info Wed Mar 14 19:30:27 2012 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 14 Mar 2012 23:30:27 GMT Subject: How to decide if a object is instancemethod? References: <8815977.3878.1331731738209.JavaMail.geo-discussion-forums@vbux23> <389400.5582.1331733455084.JavaMail.geo-discussion-forums@vbiz13> <87ty1qg9hd.fsf@benfinney.id.au> Message-ID: <4f612a12$0$29981$c3e8da3$5496439d@news.astraweb.com> On Thu, 15 Mar 2012 08:26:22 +1100, Ben Finney wrote: > Jon Clements writes: > >> import inspect >> if inspect.ismethod(foo): >> # ... >> >> Will return True if foo is a bound method. > > But under what other conditions will it return True? The name suggests > that *any* method ? static method, class method, bound method, unbound > method ? will also result in True. > > The documentation says only ?instance method?, though. Confusing :-( Bound and unbound methods are instance methods. To be precise, the "method" in "(un)bound method" stands for instance method, and the difference between the two in Python 2.x is a flag on the method object. (Unbound methods are gone in Python 3.) Class and static methods are not instance methods. I suppose it is conceivable that you could have an unbound class method in theory, but I can't see any way to actually get one in practice. In Python, and probably most languages, a bare, unadorned "method" is implied to be an instance method; "instance method" is (possibly) a retronym to distinguish them from other, newer(?), types of method. http://en.wikipedia.org/wiki/Retronym -- Steven From nagle at animats.com Wed Mar 14 19:32:41 2012 From: nagle at animats.com (John Nagle) Date: Wed, 14 Mar 2012 16:32:41 -0700 Subject: Enchancement suggestion for argparse: intuit type from default In-Reply-To: References: Message-ID: <4f612a9d$0$12033$742ec2ed@news.sonic.net> On 3/13/2012 2:08 PM, Roy Smith wrote: > Using argparse, if I write: > > parser.add_argument('--foo', default=100) > > it seems like it should be able to intuit that the type of foo should > be int (i.e. type(default)) without my having to write: > > parser.add_argument('--foo', type=int, default=100) > > Does this seem like a reasonable enhancement to argparse? default=None presents some problems. John Nagle From kiuhnm03.4t.yahoo.it Wed Mar 14 19:34:47 2012 From: kiuhnm03.4t.yahoo.it (Kiuhnm) Date: Thu, 15 Mar 2012 00:34:47 +0100 Subject: Python is readable Message-ID: <4f612b19$0$1379$4fafbaef@reader2.news.tin.it> I've just started to read The Quick Python Book (2nd ed.) The author claims that Python code is more readable than Perl code and provides this example: --- Perl --- sub pairwise_sum { my($arg1, $arg2) = @_; my(@result) = (); @list1 = @$arg1; @list2 = @$arg2; for($i=0; $i < length(@list1); $i++) { push(@result, $list1[$i] + $list2[$i]); } return(\@result); } --- Python --- def pairwise_sum(list1, list2): result = [] for i in range(len(list1)): result.append(list1[i] + list2[i]) return result --- --- It's quite clear that he knows little about Perl. Here's what I would've written: sub pairwise_sum { my ($list1, $list2) = @_; my @result; push @result, $list1->[$_] + $list2->[$_] for (0..@$list1-1); \@result; } Having said that, the Python code is still more readable, so there's no need to misrepresent Perl that way. Now I'm wondering whether the author will show me "good" or "bad" Python code throughout the book. Should I keep reading? Kiuhnm From arnodel at gmail.com Wed Mar 14 19:54:31 2012 From: arnodel at gmail.com (Arnaud Delobelle) Date: Wed, 14 Mar 2012 23:54:31 +0000 Subject: Python is readable In-Reply-To: <4f612b19$0$1379$4fafbaef@reader2.news.tin.it> References: <4f612b19$0$1379$4fafbaef@reader2.news.tin.it> Message-ID: On 14 March 2012 23:34, Kiuhnm wrote: > I've just started to read > ?The Quick Python Book (2nd ed.) > The author claims that Python code is more readable than Perl code and > provides this example: > > --- Perl --- > sub pairwise_sum { > ? ?my($arg1, $arg2) = @_; > ? ?my(@result) = (); > ? ?@list1 = @$arg1; > ? ?@list2 = @$arg2; > ? ?for($i=0; $i < length(@list1); $i++) { > ? ? ? ?push(@result, $list1[$i] + $list2[$i]); > ? ?} > ? ?return(\@result); > } > > --- Python --- > def pairwise_sum(list1, list2): > ? ?result = [] > ? ?for i in range(len(list1)): > ? ? ? ?result.append(list1[i] + list2[i]) > ? ?return result > --- --- > > It's quite clear that he knows little about Perl. > Here's what I would've written: > > sub pairwise_sum { > ? ?my ($list1, $list2) = @_; > ? ?my @result; > ? ?push @result, $list1->[$_] + $list2->[$_] for (0..@$list1-1); > ? ?\@result; > } > > Having said that, the Python code is still more readable, so there's no need > to misrepresent Perl that way. > Now I'm wondering whether the author will show me "good" or "bad" Python > code throughout the book. Should I keep reading? I don't know this book and there may be a pedagogical reason for the implementation you quote, but pairwise_sum is probably better implemented in Python 3.X as: def pairwise_sum(list1, list2): return [x1 + x2 for x1, x2 in zip(list1, list2)] Or in Python 2.X: from itertools import izip def pairwise_sum(list1, list2): return [x1 + x2 for x1, x2 in izip(list1, list2)] Or even: from operator import add def pairwise_sum(list1, list2): return map(add, list1, list2) -- Arnaud From steve+comp.lang.python at pearwood.info Wed Mar 14 20:07:52 2012 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 15 Mar 2012 00:07:52 GMT Subject: How to break long method name into more than one line? References: Message-ID: <4f6132d8$0$29981$c3e8da3$5496439d@news.astraweb.com> On Wed, 14 Mar 2012 13:53:27 -0700, Herman wrote: > I followed the rule because it was a very good advice. For example, def > test_plus_1Plus1_2(self): > If this test fails, you immediately know that it's testing the "plus" > method, with 1 and 1 as the arguments, and expect to return 2. That is hardly a representative example, or you would not be asking for advice on splitting long method names over multiple lines. A more relevant example might be def test_alongmethodname_someargument_YouRepeatTheMethodNameForSomeReason_anotherargument_someresult (self): For utterly trivial examples such as testing that 1+1 == 2 nearly any naming scheme would be suitable. But for realistic test cases, the rule fails utterly. Here is a real test case from one of my own projects: I have a project that defines dozens of related statistical functions, with hundreds of tests. Here is one test class for one function, the population variance (pvariance): class PVarianceTest(NumericTestCase, UnivariateMixin): # Test population variance. # This will be subclassed by variance and [p]stdev. tol = 1e-11 def __init__(self, *args, **kwargs): super().__init__(*args, **kwargs) self.func = calcstats.pvariance # Test data for test_main, test_shift: self.data = [4.0, 7.0, 13.0, 16.0] self.expected = 22.5 # Exact population variance of self.data. # If you duplicate each data point, the variance will scale by # this value: self.dup_scale_factor = 1.0 def setUp(self): random.shuffle(self.data) def get_allowed_kinds(self): kinds = super().get_allowed_kinds() return [kind for kind in kinds if hasattr(kind, '__len__')] def test_main(self): # Test that pvariance calculates the correct result. self.assertEqual(self.func(self.data), self.expected) def test_shift(self): # Shifting the data by a constant amount should not affect # the variance. for shift in (1e2, 1e6, 1e9): data = [x + shift for x in self.data] self.assertEqual(self.func(data), self.expected) def test_equal_data(self): # If the data is constant, the variance should be zero. self.assertEqual(self.func([42]*10), 0) def testDuplicate(self): # Test that the variance behaves as expected when you duplicate # each data point [a,b,c,...] -> [a,a,b,b,c,c,...] data = [random.uniform(-100, 500) for _ in range(20)] expected = self.func(data)*self.dup_scale_factor actual = self.func(data*2) self.assertApproxEqual(actual, expected) def testDomainError(self): # Domain error exception reported by Geremy Condra. data = [0.123456789012345]*10000 # All the items are identical, so variance should be exactly zero. # We allow some small round-off error. self.assertApproxEqual(self.func(data), 0.0, tol=5e-17) def testSingleton(self): # Population variance of a single value is always zero. for x in self.data: self.assertEqual(self.func([x]), 0) def testMeanArgument(self): # Variance calculated with the given mean should be the same # as that calculated without the mean. data = [random.random() for _ in range(15)] m = calcstats.mean(data) expected = self.func(data, m=None) self.assertEqual(self.func(data, m=m), expected) (I'm a little inconsistent when choosing between camelCase and under_score names in my tests. My bad.) Even with the limited examples shown there, the naming convention you give is utterly impractical. Most of the inputs are random (e.g. testDuplicate uses 20 randomly selected integers) or implementation details (e.g. test_equal_data takes a list of ten 42s, and returns 0, but that could have been thirty-five 7s, or six 1.29345e-9s, or nearly any other value). Some of the tests don't even test a *specific* input and output, but compare that the variance of one set of data matches the variance of a different set of data. > Sticking > this rule also means your test cases are small enough, so you clearly > know what you are testing on. Sticking to this rule means that you are probably missing tests that don't fit into the simple "arguments -> result" framework, and compromising the quality test suite. If you only test the simple cases, you aren't testing the cases that are most likely to fail. -- Steven From rosuav at gmail.com Wed Mar 14 20:17:49 2012 From: rosuav at gmail.com (Chris Angelico) Date: Thu, 15 Mar 2012 11:17:49 +1100 Subject: Style question (Poll) In-Reply-To: References: Message-ID: On Thu, Mar 15, 2012 at 7:37 AM, Croepha wrote: > Which is?preferred: > > for value in list: > ?if not value is another_value: > ? ?value.do_something() > ? ?break > > --or-- > > if list and not list[0] is another_value: > ?list[0].do_something() > > Comments are welcome, Thanks General principle: Make the code look like what it's doing. I don't mean text art and making code in the shape of pi that prints the digits of pi (although that can be awesome too), but more that a loop should not be used when you don't intend for it to loop. Consider the For-Case Paradigm[1] and the amazing confusion value that it can offer. A loop needn't execute more than once (it needn't even execute the first time), but it should at least have the _potential_ to execute the same code multiple times, otherwise it's hardly a loop. I had a particularly nasty example of a loop-that-wasn't-a-loop at work a while ago; it was PHP, not Python, so I won't share it here, but it had a do-while loop and an insidious bug in it. Very tricky. ChrisA [1] http://thedailywtf.com/Articles/The_FOR-CASE_paradigm.aspx From rosuav at gmail.com Wed Mar 14 20:27:54 2012 From: rosuav at gmail.com (Chris Angelico) Date: Thu, 15 Mar 2012 11:27:54 +1100 Subject: Python is readable In-Reply-To: References: <4f612b19$0$1379$4fafbaef@reader2.news.tin.it> Message-ID: On Thu, Mar 15, 2012 at 10:54 AM, Arnaud Delobelle wrote: > I don't know this book and there may be a pedagogical reason for the > implementation you quote, but pairwise_sum is probably better > implemented in Python 3.X as: > > def pairwise_sum(list1, list2): > ? ?return [x1 + x2 for x1, x2 in zip(list1, list2)] Okay, here's something for debate. Should the readability of a language be gauged on the basis of its standard library, or should you be comparing actual code? For instance, a quine in C can be fairly complex and messy, and it can be unobvious what it's doing - but in HQ9+ it's easy. Is it fair to compare on that basis, or should you actually implement the same / equivalent code in each before judging? Of course, that's all without getting into the question of what does "readable" even mean. This has nothing to do with the eternal question of whether it's more readable to use verbose English keywords or cryptic symbols. ChrisA From roy at panix.com Wed Mar 14 20:52:23 2012 From: roy at panix.com (Roy Smith) Date: Wed, 14 Mar 2012 20:52:23 -0400 Subject: Enchancement suggestion for argparse: intuit type from default References: <4f612a9d$0$12033$742ec2ed@news.sonic.net> Message-ID: In article <4f612a9d$0$12033$742ec2ed at news.sonic.net>, John Nagle wrote: > On 3/13/2012 2:08 PM, Roy Smith wrote: > > Using argparse, if I write: > > > > parser.add_argument('--foo', default=100) > > > > it seems like it should be able to intuit that the type of foo should > > be int (i.e. type(default)) without my having to write: > > > > parser.add_argument('--foo', type=int, default=100) > > > > Does this seem like a reasonable enhancement to argparse? > > default=None > > presents some problems. I'll admit I hadn't considered that, but I don't see it as a major problem. The type intuition could be designed to only work for types other than NoneType. From ben+python at benfinney.id.au Wed Mar 14 21:22:13 2012 From: ben+python at benfinney.id.au (Ben Finney) Date: Thu, 15 Mar 2012 12:22:13 +1100 Subject: Enchancement suggestion for argparse: intuit type from default References: <4f612a9d$0$12033$742ec2ed@news.sonic.net> Message-ID: <87pqcefyka.fsf@benfinney.id.au> Roy Smith writes: > I'll admit I hadn't considered that, but I don't see it as a major > problem. The type intuition could be designed to only work for types > other than NoneType. ?1, then. It's growing too many special cases, and is no longer simple to describe, so that indicates it's probably a bad idea. -- \ ?[W]e are still the first generation of users, and for all that | `\ we may have invented the net, we still don't really get it.? | _o__) ?Douglas Adams | Ben Finney From python at mrabarnett.plus.com Wed Mar 14 22:10:11 2012 From: python at mrabarnett.plus.com (MRAB) Date: Thu, 15 Mar 2012 02:10:11 +0000 Subject: Enchancement suggestion for argparse: intuit type from default In-Reply-To: References: <4f612a9d$0$12033$742ec2ed@news.sonic.net> Message-ID: <4F614F83.7020300@mrabarnett.plus.com> On 15/03/2012 00:52, Roy Smith wrote: > In article<4f612a9d$0$12033$742ec2ed at news.sonic.net>, > John Nagle wrote: > >> On 3/13/2012 2:08 PM, Roy Smith wrote: >> > Using argparse, if I write: >> > >> > parser.add_argument('--foo', default=100) >> > >> > it seems like it should be able to intuit that the type of foo should >> > be int (i.e. type(default)) without my having to write: >> > >> > parser.add_argument('--foo', type=int, default=100) >> > >> > Does this seem like a reasonable enhancement to argparse? >> >> default=None >> >> presents some problems. > > I'll admit I hadn't considered that, but I don't see it as a major > problem. The type intuition could be designed to only work for types > other than NoneType. True, you could consider that a special case. If you really do want NoneType, or if the type doesn't otherwise match the default (or there's no default), then you can still be explicit. From d at davea.name Wed Mar 14 22:15:28 2012 From: d at davea.name (Dave Angel) Date: Wed, 14 Mar 2012 22:15:28 -0400 Subject: Is it technically possible to give Python option of naming process of running script? In-Reply-To: <5B80DD153D7D744689F57F4FB69AF474026A280E@SBECMX008.exchad.jpmchase.net> References: <19118128.4791.1331736187952.JavaMail.geo-discussion-forums@vbai14> <5B80DD153D7D744689F57F4FB69AF474026A27FC@SBECMX008.exchad.jpmchase.net> <5B80DD153D7D744689F57F4FB69AF474026A280E@SBECMX008.exchad.jpmchase.net> Message-ID: <4F6150C0.3000302@davea.name> On 03/14/2012 01:27 PM, Prasad, Ramit wrote: >>>> It seems like an excellent thing to add to the "os" module. >>> If 'prctl' is a standard POSIX system call, then it should be a >>> candidate for inclusion in the os module if someone opens a tracker >>> enhancement issue and presents an argument in favor. >> >> I think this request was already denied: http://bugs.python.org/issue5672 > Also take a look at: https://github.com/dvarrazzo/py-setproctitle > Though since they just create a Named Object in Windows, I am not sure > it would work for something like killall. > > There is/was a project called exemaker for Windows. (see Pypi for link). I don't use Windows any more, but it was a nice trick, when it worked. Not all python scripts could be wrapped in it, but basically it let you wrap a python script in a tiny Windows program which launched the usual python dll's. You could call it anything you liked, and that's what the task manager saw as the process name. -- DaveA From steveo at syslang.net Wed Mar 14 22:48:32 2012 From: steveo at syslang.net (Steven W. Orr) Date: Wed, 14 Mar 2012 22:48:32 -0400 Subject: Is there a ConfigParser which keeps comments In-Reply-To: References: Message-ID: <4F615880.6080005@syslang.net> On 3/14/2012 6:07 AM, Gelonida N wrote: > Hi, > > > At the moment I use ConfigParser > http://docs.python.org/library/configparser.html > for one of my applications. > > > Now I'm looking for a library, which behaves like config parser, but > with one minor difference. > > The write() mehtod should keep existing comments. > > Does anybody know or implement something like this or is there as > switrch, that I overlooked in hte documentaiton. > > I use ConfigObj. -- Time flies like the wind. Fruit flies like a banana. Stranger things have .0. happened but none stranger than this. Does your driver's license say Organ ..0 Donor?Black holes are where God divided by zero. Listen to me! We are all- 000 individuals! What if this weren't a hypothetical question? steveo at syslang.net From rantingrickjohnson at gmail.com Wed Mar 14 23:02:58 2012 From: rantingrickjohnson at gmail.com (Rick Johnson) Date: Wed, 14 Mar 2012 20:02:58 -0700 (PDT) Subject: Python is readable References: <4f612b19$0$1379$4fafbaef@reader2.news.tin.it> Message-ID: <8e72d74f-c844-4de3-8a37-f6b1fdc2291f@y27g2000yqy.googlegroups.com> On Mar 14, 7:27?pm, Chris Angelico wrote: > Okay, here's something for debate. > > Should the readability of a language be gauged on the basis of its > standard library, or should you be comparing actual code? I think the library matters greatly. Yes, one could argue that the same functionality "could" be wrapped-up in the competing language, but then, why has it not already been wrapped? When comparing say, "language A" (WITHOUT a built-in print function) and "Language B" (WITH a built-in print function), would you cry unfairness when B wielded the built-in? > [...] > Of course, that's all without getting into the question of what does > "readable" even mean. One could get caught in an infinite loop of the "Chicken and the Egg" paradox here. However, when we are talking about the Python programming language "readable" simply means: "neophyte readable". That is, "readable to someone with little or no experience with the language". I think that has always been Python's philosophy from the beginning (even all the way back to CP4E!). > This has nothing to do with the eternal question > of whether it's more readable to use verbose English keywords or > cryptic symbols. Again, for the case of Python, cryptic symbols are frowned upon. Of course for the "hacker", cryptic symbols can save keystrokes and white space -- but at the expense of "neophyte readability"! > ChrisA Thanks for reminding me of your name. I had almost forgotten who i replied to ;-) From cs at zip.com.au Thu Mar 15 01:59:08 2012 From: cs at zip.com.au (Cameron Simpson) Date: Thu, 15 Mar 2012 16:59:08 +1100 Subject: Enchancement suggestion for argparse: intuit type from default In-Reply-To: <87pqcefyka.fsf@benfinney.id.au> References: <87pqcefyka.fsf@benfinney.id.au> Message-ID: <20120315055908.GA8886@cskk.homeip.net> On 15Mar2012 12:22, Ben Finney wrote: | Roy Smith writes: | > I'll admit I hadn't considered that, but I don't see it as a major | > problem. The type intuition could be designed to only work for types | > other than NoneType. | | ?1, then. It's growing too many special cases, and is no longer simple | to describe, so that indicates it's probably a bad idea. If `type` is not supplied and `default` is present and not None, `type` shall be the type of `default`. That seems straightforward to me. It's a single sentence, easy to read and understand, and potentially saves a lot of code verbiage (gratuitous type= prarameters). I say "gratuitous" because unless `default` is a sentinel for "no option supplied", the `type` should always match type(default). Or am I wrong about that? Cheers, -- Cameron Simpson DoD#743 http://www.cskk.ezoshosting.com/cs/ You only live once in life, but if you do it right, once is enough! - Rob Castro From wuwei23 at gmail.com Thu Mar 15 02:23:30 2012 From: wuwei23 at gmail.com (alex23) Date: Wed, 14 Mar 2012 23:23:30 -0700 (PDT) Subject: Python is readable References: <4f612b19$0$1379$4fafbaef@reader2.news.tin.it> <8e72d74f-c844-4de3-8a37-f6b1fdc2291f@y27g2000yqy.googlegroups.com> Message-ID: <50e9ceec-40f1-4ead-b2b6-87328b30d084@ow8g2000pbc.googlegroups.com> Rick Johnson wrote: > However, when we are talking about the Python > programming language "readable" simply means: "neophyte readable". > That is, "readable to someone with little or no experience with the > language". Nonsense. List comprehensions are not immediately obvious to new Python users. The functionality of 'with' requires an understanding of context managers. Python's readability has more to do with simplifying code maintenance. The idea that Python code has to be obvious to non-programmers is an incorrect and dangerous one. From tymoteusz.jankowski at gmail.com Thu Mar 15 03:24:58 2012 From: tymoteusz.jankowski at gmail.com (xliiv) Date: Thu, 15 Mar 2012 00:24:58 -0700 (PDT) Subject: Is it technically possible to give Python option of naming process of running script? In-Reply-To: References: <19118128.4791.1331736187952.JavaMail.geo-discussion-forums@vbai14> Message-ID: <19923939.18.1331796298704.JavaMail.geo-discussion-forums@vbhz5> > >> Like the topic.. . > >> I use Python a lot, both Windows and Linux, and it's little weird to have many python process without fast distinction which is what. > > > > I've no idea if it's even possible on Windows. On Linux, what you want > > is the prctl function, which (AFAIK) isn't directly available. > > > > Google is your friend, though. Question's already been asked on Stack > > Overflow and such, and has a few answers. Nothing that looks > > cut-and-dried ready, but several that might work. > > The question of how to set the application name comes up somewhat > regularly. It would be awfully nice if there was a way for python > applications to set their application name. It's especially useful > for daemons, and makes it much easier when you can kill them by name > instead of having to look up the PID. > > It seems like an excellent thing to add to the "os" module. > > > Look for 'prctl' and 'PR_SET_NAME', which are the C-level function > > and constant that do the job; a cursory examination of PyPI shows a > > module with prctl in the name, so that may be of value. I did google, I've played with Exemaker (it works perfect, but not py3) and i've seen questions on Stackoverflow. The thing I mean is a build feature of python to give such a name. Not 3rd part or etc. like Grant Edwards said. Is it possible? From tymoteusz.jankowski at gmail.com Thu Mar 15 03:26:51 2012 From: tymoteusz.jankowski at gmail.com (xliiv) Date: Thu, 15 Mar 2012 00:26:51 -0700 (PDT) Subject: Is it technically possible to give Python option of naming process of running script? In-Reply-To: References: <19118128.4791.1331736187952.JavaMail.geo-discussion-forums@vbai14> Message-ID: <22071354.8904.1331796412001.JavaMail.geo-discussion-forums@vbkc1> > >> Like the topic.. . > >> I use Python a lot, both Windows and Linux, and it's little weird to have many python process without fast distinction which is what. > > > > I've no idea if it's even possible on Windows. On Linux, what you want > > is the prctl function, which (AFAIK) isn't directly available. > > > > Google is your friend, though. Question's already been asked on Stack > > Overflow and such, and has a few answers. Nothing that looks > > cut-and-dried ready, but several that might work. > > The question of how to set the application name comes up somewhat > regularly. It would be awfully nice if there was a way for python > applications to set their application name. It's especially useful > for daemons, and makes it much easier when you can kill them by name > instead of having to look up the PID. > > It seems like an excellent thing to add to the "os" module. > > > Look for 'prctl' and 'PR_SET_NAME', which are the C-level function > > and constant that do the job; a cursory examination of PyPI shows a > > module with prctl in the name, so that may be of value. I did google, I've played with Exemaker (it works perfect, but not py3) and i've seen questions on Stackoverflow. The thing I mean is a build feature of python to give such a name. Not 3rd part or etc. like Grant Edwards said. Is it possible? From arunpdasuit at gmail.com Thu Mar 15 04:19:26 2012 From: arunpdasuit at gmail.com (Arun p das) Date: Thu, 15 Mar 2012 13:49:26 +0530 Subject: pyserial for GPS data Message-ID: I have a USB GPS dongle using this for getting position information. I installed gpsd daemon so that any clients can read data from that. It is working fine used xgps, cgps as clients. *gpsd -n -N -D2 /dev/ttyUSB0 * import gps, os, time g = gps.gps(mode=gps.WATCH_NEWSTYLE) while 1: os.system('clear') g.poll() #if gps.PACKET_SET: g.stream() print 'latitude ' , g.fix.latitude print 'longitude ' , g.fix.longitude print 'time utc ' , g.utc,' + ', g.fix.time Used the following program to read gps data but it is not giving accurate readings as cgps,xgps clients. I tried to read directly from the serial port using the following program but its giving non printable characters as output as it should return something like $GPRMC,199304.973,3248.7780,N,11355.7832,W,1,06,02.2,25722.5,M,,,*00" *import serial* *ser = serial.Serial( port='/dev/ttyUSB0', baudrate=4800,timeout=1) * *while True:* * line=ser.read()* * print line,* *f.close()* -------------- next part -------------- An HTML attachment was scrubbed... URL: From robert.kern at gmail.com Thu Mar 15 06:06:48 2012 From: robert.kern at gmail.com (Robert Kern) Date: Thu, 15 Mar 2012 10:06:48 +0000 Subject: Enchancement suggestion for argparse: intuit type from default In-Reply-To: <20120315055908.GA8886@cskk.homeip.net> References: <87pqcefyka.fsf@benfinney.id.au> <20120315055908.GA8886@cskk.homeip.net> Message-ID: On 3/15/12 5:59 AM, Cameron Simpson wrote: > On 15Mar2012 12:22, Ben Finney wrote: > | Roy Smith writes: > |> I'll admit I hadn't considered that, but I don't see it as a major > |> problem. The type intuition could be designed to only work for types > |> other than NoneType. > | > | ?1, then. It's growing too many special cases, and is no longer simple > | to describe, so that indicates it's probably a bad idea. > > If `type` is not supplied and `default` is present and not None, `type` > shall be the type of `default`. > > That seems straightforward to me. It's a single sentence, easy to read > and understand, and potentially saves a lot of code verbiage (gratuitous > type= prarameters). I say "gratuitous" because unless `default` is a > sentinel for "no option supplied", the `type` should always match > type(default). Or am I wrong about that? Yes. Not all type(default) types can be called with a string to produce a valid value. Note that "type=" is really a misnomer. argparse doesn't really want a type object there; it wants a converter function that takes a string to an object. -- Robert Kern "I have come to believe that the whole world is an enigma, a harmless enigma that is made terrible by our own mad attempt to interpret it as though it had an underlying truth." -- Umberto Eco From cs at zip.com.au Thu Mar 15 06:35:03 2012 From: cs at zip.com.au (Cameron Simpson) Date: Thu, 15 Mar 2012 21:35:03 +1100 Subject: Enchancement suggestion for argparse: intuit type from default In-Reply-To: References: Message-ID: <20120315103503.GA1725@cskk.homeip.net> On 15Mar2012 10:06, Robert Kern wrote: | On 3/15/12 5:59 AM, Cameron Simpson wrote: | > On 15Mar2012 12:22, Ben Finney wrote: | > | Roy Smith writes: | > |> I'll admit I hadn't considered that, but I don't see it as a major | > |> problem. The type intuition could be designed to only work for types | > |> other than NoneType. | > | | > | ?1, then. It's growing too many special cases, and is no longer simple | > | to describe, so that indicates it's probably a bad idea. | > | > If `type` is not supplied and `default` is present and not None, `type` | > shall be the type of `default`. | > | > That seems straightforward to me. [... sentinels aside...] the `type` | > should always match type(default). Or am I wrong about that? | | Yes. Not all type(default) types can be called with a string to produce a valid | value. Note that "type=" is really a misnomer. argparse doesn't really want a | type object there; it wants a converter function that takes a string to an object. Aha. Still, you could change the docs to say you only need type= if type(default) _isn't_ useful as the string->value converter. -- Cameron Simpson DoD#743 http://www.cskk.ezoshosting.com/cs/ As your attorney, it is my duty to inform you that it is not important that you understand what I'm doing or why you're paying me so much money. What's important is that you continue to do so. - Hunter S. Thompson's Samoan Attorney From dmitrey15 at gmail.com Thu Mar 15 06:44:43 2012 From: dmitrey15 at gmail.com (dmitrey) Date: Thu, 15 Mar 2012 03:44:43 -0700 (PDT) Subject: new release 0.38 of OpenOpt, FuncDesigner, SpaceFuncs, DerApproximator Message-ID: Hi all, I'm glad to inform you about new release 0.38 (2012-March-15): OpenOpt: interalg can handle discrete variables interalg can handle multiobjective problems (MOP) interalg can handle problems with parameters fixedVars/freeVars Many interalg improvements and some bugfixes Add another EIG solver: numpy.linalg.eig New LLSP solver pymls with box bounds handling FuncDesigner: Some improvements for sum() Add funcs tanh, arctanh, arcsinh, arccosh Can solve EIG built from derivatives of several functions, obtained by automatic differentiation by FuncDesigner SpaceFuncs: Add method point.symmetry(Point|Line|Plane) Add method LineSegment.middle Add method Point.rotate(Center, angle) DerApproximator: Minor changes See http://openopt.org for more details Regards, D. From kiuhnm03.4t.yahoo.it Thu Mar 15 06:44:55 2012 From: kiuhnm03.4t.yahoo.it (Kiuhnm) Date: Thu, 15 Mar 2012 11:44:55 +0100 Subject: Python is readable In-Reply-To: <50e9ceec-40f1-4ead-b2b6-87328b30d084@ow8g2000pbc.googlegroups.com> References: <4f612b19$0$1379$4fafbaef@reader2.news.tin.it> <8e72d74f-c844-4de3-8a37-f6b1fdc2291f@y27g2000yqy.googlegroups.com> <50e9ceec-40f1-4ead-b2b6-87328b30d084@ow8g2000pbc.googlegroups.com> Message-ID: <4f61c828$0$1390$4fafbaef@reader2.news.tin.it> On 3/15/2012 7:23, alex23 wrote: > Rick Johnson wrote: >> However, when we are talking about the Python >> programming language "readable" simply means: "neophyte readable". >> That is, "readable to someone with little or no experience with the >> language". > > Nonsense. List comprehensions are not immediately obvious to new > Python users. The functionality of 'with' requires an understanding of > context managers. Python's readability has more to do with simplifying > code maintenance. Let's try that. Show me an example of "list comprehensions" and "with" (whatever they are). Kiuhnm From rosuav at gmail.com Thu Mar 15 06:50:59 2012 From: rosuav at gmail.com (Chris Angelico) Date: Thu, 15 Mar 2012 21:50:59 +1100 Subject: Python is readable In-Reply-To: <4f61c828$0$1390$4fafbaef@reader2.news.tin.it> References: <4f612b19$0$1379$4fafbaef@reader2.news.tin.it> <8e72d74f-c844-4de3-8a37-f6b1fdc2291f@y27g2000yqy.googlegroups.com> <50e9ceec-40f1-4ead-b2b6-87328b30d084@ow8g2000pbc.googlegroups.com> <4f61c828$0$1390$4fafbaef@reader2.news.tin.it> Message-ID: On Thu, Mar 15, 2012 at 9:44 PM, Kiuhnm wrote: > Let's try that. > Show me an example of "list comprehensions" and "with" (whatever they are). I'll do a list comp, because they lend themselves well to one-liners. what_am_i = '\n'.join(["%X\t%c"%(i,i) for i in range(128)]) Okay, that one also uses printf formatting, which may be a smidge obscure. Here's a simpler example: what_am_i = [x*x for x in range(11)] ChrisA From nutznetz-0c1b6768-bfa9-48d5-a470-7603bd3aa915 at spamschutz.glglgl.de Thu Mar 15 07:14:28 2012 From: nutznetz-0c1b6768-bfa9-48d5-a470-7603bd3aa915 at spamschutz.glglgl.de (Thomas Rachel) Date: Thu, 15 Mar 2012 12:14:28 +0100 Subject: Python is readable In-Reply-To: <4f61c828$0$1390$4fafbaef@reader2.news.tin.it> References: <4f612b19$0$1379$4fafbaef@reader2.news.tin.it> <8e72d74f-c844-4de3-8a37-f6b1fdc2291f@y27g2000yqy.googlegroups.com> <50e9ceec-40f1-4ead-b2b6-87328b30d084@ow8g2000pbc.googlegroups.com> <4f61c828$0$1390$4fafbaef@reader2.news.tin.it> Message-ID: Am 15.03.2012 11:44 schrieb Kiuhnm: > Let's try that. > Show me an example of "list comprehensions" and "with" (whatever they are). with open("filename", "w") as f: f.write(stuff) with lock: do_something_exclusively() Thomas From kiuhnm03.4t.yahoo.it Thu Mar 15 07:27:28 2012 From: kiuhnm03.4t.yahoo.it (Kiuhnm) Date: Thu, 15 Mar 2012 12:27:28 +0100 Subject: Python is readable In-Reply-To: References: <4f612b19$0$1379$4fafbaef@reader2.news.tin.it> <8e72d74f-c844-4de3-8a37-f6b1fdc2291f@y27g2000yqy.googlegroups.com> <50e9ceec-40f1-4ead-b2b6-87328b30d084@ow8g2000pbc.googlegroups.com> <4f61c828$0$1390$4fafbaef@reader2.news.tin.it> Message-ID: <4f61d221$0$1375$4fafbaef@reader2.news.tin.it> On 3/15/2012 11:50, Chris Angelico wrote: > On Thu, Mar 15, 2012 at 9:44 PM, Kiuhnm > wrote: >> Let's try that. >> Show me an example of "list comprehensions" and "with" (whatever they are). > > I'll do a list comp, because they lend themselves well to one-liners. > what_am_i = '\n'.join(["%X\t%c"%(i,i) for i in range(128)]) A few conjectures: 1) '\n' is an object and join one of its methods; 2) [...] is a list comprehension; 3) that 'for' suggests that range isn't (or doesn't return) a list but an iterator; 4) points 2 and 3 suggest that [...] builds a list (or array?) by querying an iterator. 5) "%X\t%"(i,i) is probably equivalent to the C-like Perl's sprintf("%X\t%c", i, i) So what_am_i is a simple ASCII table. > Okay, that one also uses printf formatting, which may be a smidge > obscure. Here's a simpler example: > > what_am_i = [x*x for x in range(11)] what_am_i = 0, 1, 4, 9, ..., 100 Your first example suggests that range(n) is a sequence iterator which returns, if queried n times, 0,...,n-1 (which is a bit counterintuitive, IMHO). Kiuhnm From rosuav at gmail.com Thu Mar 15 07:47:49 2012 From: rosuav at gmail.com (Chris Angelico) Date: Thu, 15 Mar 2012 22:47:49 +1100 Subject: Python is readable In-Reply-To: <4f61d221$0$1375$4fafbaef@reader2.news.tin.it> References: <4f612b19$0$1379$4fafbaef@reader2.news.tin.it> <8e72d74f-c844-4de3-8a37-f6b1fdc2291f@y27g2000yqy.googlegroups.com> <50e9ceec-40f1-4ead-b2b6-87328b30d084@ow8g2000pbc.googlegroups.com> <4f61c828$0$1390$4fafbaef@reader2.news.tin.it> <4f61d221$0$1375$4fafbaef@reader2.news.tin.it> Message-ID: On Thu, Mar 15, 2012 at 10:27 PM, Kiuhnm wrote: > On 3/15/2012 11:50, Chris Angelico wrote: >> I'll do a list comp, because they lend themselves well to one-liners. >> what_am_i = '\n'.join(["%X\t%c"%(i,i) for i in range(128)]) > > > A few conjectures: > 1) '\n' is an object and join one of its methods; > 2) [...] is a list comprehension; > 3) that 'for' suggests that range isn't (or doesn't return) a list but an > iterator; > 4) points 2 and 3 suggest that [...] builds a list (or array?) by querying > an iterator. > 5) "%X\t%"(i,i) is probably equivalent to the C-like Perl's > ?sprintf("%X\t%c", i, i) > > So what_am_i is a simple ASCII table. Correct. Actually, there's a few differences between Python 2 and 3; in Py2, range() returns a list, but in Py3 an iterable object. But 'for' will happily iterate over a list. >> Okay, that one also uses printf formatting, which may be a smidge >> obscure. Here's a simpler example: >> >> what_am_i = [x*x for x in range(11)] > > what_am_i = 0, 1, 4, 9, ..., 100 Correct again. > Your first example suggests that range(n) is a sequence iterator which > returns, if queried n times, > ?0,...,n-1 > (which is a bit counterintuitive, IMHO). It's a little odd, perhaps, if seen in a vacuum. But everything counts from zero - list indices, etc - so it makes sense for range(len(lst)) to return indices valid for lst. List comps are pretty readable if you know how programming languages work. Python need not be readable by everyone and his grandmother, and it does a fairly good job of being grokkable to someone who has a few ranks in Coding. (Yeah, I'm a D&D nerd. ) ChrisA From kiuhnm03.4t.yahoo.it Thu Mar 15 07:48:55 2012 From: kiuhnm03.4t.yahoo.it (Kiuhnm) Date: Thu, 15 Mar 2012 12:48:55 +0100 Subject: Python is readable In-Reply-To: References: <4f612b19$0$1379$4fafbaef@reader2.news.tin.it> <8e72d74f-c844-4de3-8a37-f6b1fdc2291f@y27g2000yqy.googlegroups.com> <50e9ceec-40f1-4ead-b2b6-87328b30d084@ow8g2000pbc.googlegroups.com> <4f61c828$0$1390$4fafbaef@reader2.news.tin.it> Message-ID: <4f61d728$0$1375$4fafbaef@reader2.news.tin.it> On 3/15/2012 12:14, Thomas Rachel wrote: > Am 15.03.2012 11:44 schrieb Kiuhnm: > >> Let's try that. >> Show me an example of "list comprehensions" and "with" (whatever they >> are). > > with open("filename", "w") as f: > f.write(stuff) Here f is created before executing the block and destroyed right after leaving the block. f's destructor will probably close the file handle. > with lock: > do_something_exclusively() It's clear what it does, but I don't know if that's special syntax. Maybe objects can have two special methods that are called respect. on entering and leaving the with-block. Or, more likely, lock creates an object which keeps the lock "acquired". The lock is released when we leave the block. So we could inspect the lock with with lock as l: inspect l... do_some..... BTW, aren't those ':' redundant? Kiuhnm From kiuhnm03.4t.yahoo.it Thu Mar 15 07:59:29 2012 From: kiuhnm03.4t.yahoo.it (Kiuhnm) Date: Thu, 15 Mar 2012 12:59:29 +0100 Subject: Python is readable In-Reply-To: References: <4f612b19$0$1379$4fafbaef@reader2.news.tin.it> <8e72d74f-c844-4de3-8a37-f6b1fdc2291f@y27g2000yqy.googlegroups.com> <50e9ceec-40f1-4ead-b2b6-87328b30d084@ow8g2000pbc.googlegroups.com> <4f61c828$0$1390$4fafbaef@reader2.news.tin.it> <4f61d221$0$1375$4fafbaef@reader2.news.tin.it> Message-ID: <4f61d9a2$0$1377$4fafbaef@reader2.news.tin.it> On 3/15/2012 12:47, Chris Angelico wrote: > On Thu, Mar 15, 2012 at 10:27 PM, Kiuhnm >> Your first example suggests that range(n) is a sequence iterator which >> returns, if queried n times, >> 0,...,n-1 >> (which is a bit counterintuitive, IMHO). > > It's a little odd, perhaps, if seen in a vacuum. But everything counts > from zero - list indices, etc - so it makes sense for range(len(lst)) > to return indices valid for lst. Maybe range uses [...) intervals? So range(a,b) is a,a+1,a+2,...,b-1 and range(b) is just short-hand for range(0,b)? > List comps are pretty readable if you know how programming languages > work. Python need not be readable by everyone and his grandmother, and > it does a fairly good job of being grokkable to someone who has a few > ranks in Coding. (Yeah, I'm a D&D nerd. ) I like what I've seen so far. Kiuhnm From karthip444 at gmail.com Thu Mar 15 08:21:03 2012 From: karthip444 at gmail.com (karthi karthi) Date: Thu, 15 Mar 2012 05:21:03 -0700 (PDT) Subject: hi see this Message-ID: <1f4aefb4-9043-4931-bc57-650e374f4411@to5g2000pbc.googlegroups.com> http://123maza.com/46/share115/ From rosuav at gmail.com Thu Mar 15 08:21:29 2012 From: rosuav at gmail.com (Chris Angelico) Date: Thu, 15 Mar 2012 23:21:29 +1100 Subject: Python is readable In-Reply-To: <4f61d9a2$0$1377$4fafbaef@reader2.news.tin.it> References: <4f612b19$0$1379$4fafbaef@reader2.news.tin.it> <8e72d74f-c844-4de3-8a37-f6b1fdc2291f@y27g2000yqy.googlegroups.com> <50e9ceec-40f1-4ead-b2b6-87328b30d084@ow8g2000pbc.googlegroups.com> <4f61c828$0$1390$4fafbaef@reader2.news.tin.it> <4f61d221$0$1375$4fafbaef@reader2.news.tin.it> <4f61d9a2$0$1377$4fafbaef@reader2.news.tin.it> Message-ID: On Thu, Mar 15, 2012 at 10:59 PM, Kiuhnm wrote: > On 3/15/2012 12:47, Chris Angelico wrote: >> It's a little odd, perhaps, if seen in a vacuum. But everything counts >> from zero - list indices, etc - so it makes sense for range(len(lst)) >> to return indices valid for lst. > > Maybe range uses [...) intervals? So range(a,b) is a,a+1,a+2,...,b-1 and > range(b) is just short-hand for range(0,b)? Yup. It's amazing how accurate your conjectures are - it's almost like you've been reading the docs! :D But yeah, that's pretty logical IMHO; and having gotten used to [) intervals in many areas of computing, I've come to find [] intervals disconcerting. Bible passages are described as, for instance, John 14:5-7, which is a three-verse passage (5, 6, 7), even though 7-5=2. However, inclusive-inclusive intervals have the benefit that they don't require the element "beyond the last" to be indexable. This is important if you're working with something that takes up all of addressable memory - going back to the IBM PCs on which I learned to code, you could use one 64KB segment for an array, but then there's no way for a 16-bit integer to indicate "past the end". >> List comps are pretty readable if you know how programming languages >> work. Python need not be readable by everyone and his grandmother, and >> it does a fairly good job of being grokkable to someone who has a few >> ranks in Coding. (Yeah, I'm a D&D nerd. ) > > I like what I've seen so far. Python has its problems, but it's a good language. I personally prefer to delimit blocks of code with braces than with indentation, and I also prefer explicit declaration of variables (yes, it's extra work, but you can have infinitely nested scopes and easily-caught syntax errors when you misspell one), but they're relatively minor. One of my favorite aspects of Python is that *everything* is an object. There's no magic syntax that gives you a piece of an object, or something special about variables that contain this, that, or the other. A literal list [like, this, one] can be used in exactly the same ways as the name of a variable containing a list or a function call returning a list - there is no difference. Oh how I yearn for that when working in C++ or PHP! ChrisA From ben+python at benfinney.id.au Thu Mar 15 08:31:01 2012 From: ben+python at benfinney.id.au (Ben Finney) Date: Thu, 15 Mar 2012 23:31:01 +1100 Subject: Python is readable References: <4f612b19$0$1379$4fafbaef@reader2.news.tin.it> <8e72d74f-c844-4de3-8a37-f6b1fdc2291f@y27g2000yqy.googlegroups.com> <50e9ceec-40f1-4ead-b2b6-87328b30d084@ow8g2000pbc.googlegroups.com> <4f61c828$0$1390$4fafbaef@reader2.news.tin.it> <4f61d221$0$1375$4fafbaef@reader2.news.tin.it> <4f61d9a2$0$1377$4fafbaef@reader2.news.tin.it> Message-ID: <87k42moxkq.fsf@benfinney.id.au> Chris Angelico writes: > Yup. It's amazing how accurate your conjectures are - it's almost like > you've been reading the docs! :D But yeah, that's pretty logical IMHO; > and having gotten used to [) intervals in many areas of computing, > I've come to find [] intervals disconcerting. Bible passages are > described as, for instance, John 14:5-7, which is a three-verse > passage (5, 6, 7), even though 7-5=2. Another good reason to advocate for proper typography. ?John 14:5?7? indicates a range (because it uses U+2013 EN DASH), whereas ?7?5? indicates subtraction (because it uses U+2212 MINUS SIGN). A hyphen (?-? U+002D) is inappropriate in either case. -- \ ?He that would make his own liberty secure must guard even his | `\ enemy from oppression.? ?Thomas Paine | _o__) | Ben Finney From rosuav at gmail.com Thu Mar 15 08:38:27 2012 From: rosuav at gmail.com (Chris Angelico) Date: Thu, 15 Mar 2012 23:38:27 +1100 Subject: Python is readable In-Reply-To: <87k42moxkq.fsf@benfinney.id.au> References: <4f612b19$0$1379$4fafbaef@reader2.news.tin.it> <8e72d74f-c844-4de3-8a37-f6b1fdc2291f@y27g2000yqy.googlegroups.com> <50e9ceec-40f1-4ead-b2b6-87328b30d084@ow8g2000pbc.googlegroups.com> <4f61c828$0$1390$4fafbaef@reader2.news.tin.it> <4f61d221$0$1375$4fafbaef@reader2.news.tin.it> <4f61d9a2$0$1377$4fafbaef@reader2.news.tin.it> <87k42moxkq.fsf@benfinney.id.au> Message-ID: On Thu, Mar 15, 2012 at 11:31 PM, Ben Finney wrote: > Another good reason to advocate for proper typography. "John 14:5-7" > indicates a range (because it uses U+2013 EN DASH), whereas "7-5" > indicates subtraction (because it uses U+2212 MINUS SIGN). A hyphen ('-' > U+002D) is inappropriate in either case. Heh. Yes, but when you're seeking the size of a range, you use subtraction. The fact that the en dash and minus sign are both often represented in ASCII with a hyphen is pure coincidence. ChrisA From ben+python at benfinney.id.au Thu Mar 15 09:16:28 2012 From: ben+python at benfinney.id.au (Ben Finney) Date: Fri, 16 Mar 2012 00:16:28 +1100 Subject: Python is readable References: <4f612b19$0$1379$4fafbaef@reader2.news.tin.it> <8e72d74f-c844-4de3-8a37-f6b1fdc2291f@y27g2000yqy.googlegroups.com> <50e9ceec-40f1-4ead-b2b6-87328b30d084@ow8g2000pbc.googlegroups.com> <4f61c828$0$1390$4fafbaef@reader2.news.tin.it> <4f61d221$0$1375$4fafbaef@reader2.news.tin.it> <4f61d9a2$0$1377$4fafbaef@reader2.news.tin.it> <87k42moxkq.fsf@benfinney.id.au> Message-ID: <87fwdaovgz.fsf@benfinney.id.au> Chris Angelico writes: > On Thu, Mar 15, 2012 at 11:31 PM, Ben Finney wrote: > > Another good reason to advocate for proper typography. "John 14:5-7" > > indicates a range (because it uses U+2013 EN DASH), whereas "7-5" > > indicates subtraction (because it uses U+2212 MINUS SIGN). A hyphen > > ('-' U+002D) is inappropriate in either case. > > Heh. Yes, but when you're seeking the size of a range, you use > subtraction. Not the size of an *inclusive* range, such as a range indicated by use of an en dash :-) > The fact that the en dash and minus sign are both often represented in > ASCII with a hyphen is pure coincidence. Hopefully, the fact that your quoting of my text munged the characters down to ASCII is also pure coincidence, and is soon to be corrected at your end? Or has your client program not joined the rest of us in the third millennium with Unicode? -- \ ?Geeks like to think that they can ignore politics. You can | `\ leave politics alone, but politics won't leave you alone.? | _o__) ?Richard M. Stallman, 2002-07-26 | Ben Finney From roy at panix.com Thu Mar 15 09:28:02 2012 From: roy at panix.com (Roy Smith) Date: Thu, 15 Mar 2012 09:28:02 -0400 Subject: Enchancement suggestion for argparse: intuit type from default References: <87pqcefyka.fsf@benfinney.id.au> <20120315055908.GA8886@cskk.homeip.net> Message-ID: In article , Robert Kern wrote: > Yes. Not all type(default) types can be called with a string to produce a > valid > value. Note that "type=" is really a misnomer. argparse doesn't really want a > type object there; it wants a converter function that takes a string to an > object. Orthogonal to my original suggestion, I agree that this is misnamed. I'm +1 on the idea of renaming it to conversion= or something like that (we'd need to keep type= around as a deprecated synonym for backwards compatability). It's really hard to get your head around "type=open". From rosuav at gmail.com Thu Mar 15 09:33:09 2012 From: rosuav at gmail.com (Chris Angelico) Date: Fri, 16 Mar 2012 00:33:09 +1100 Subject: Python is readable In-Reply-To: <87fwdaovgz.fsf@benfinney.id.au> References: <4f612b19$0$1379$4fafbaef@reader2.news.tin.it> <8e72d74f-c844-4de3-8a37-f6b1fdc2291f@y27g2000yqy.googlegroups.com> <50e9ceec-40f1-4ead-b2b6-87328b30d084@ow8g2000pbc.googlegroups.com> <4f61c828$0$1390$4fafbaef@reader2.news.tin.it> <4f61d221$0$1375$4fafbaef@reader2.news.tin.it> <4f61d9a2$0$1377$4fafbaef@reader2.news.tin.it> <87k42moxkq.fsf@benfinney.id.au> <87fwdaovgz.fsf@benfinney.id.au> Message-ID: On Fri, Mar 16, 2012 at 12:16 AM, Ben Finney wrote: > Chris Angelico writes: > >> On Thu, Mar 15, 2012 at 11:31 PM, Ben Finney wrote: >> > Another good reason to advocate for proper typography. "John 14:5-7" >> > indicates a range (because it uses U+2013 EN DASH), whereas "7-5" >> > indicates subtraction (because it uses U+2212 MINUS SIGN). A hyphen >> > ('-' U+002D) is inappropriate in either case. >> >> Heh. Yes, but when you're seeking the size of a range, you use >> subtraction. > > Not the size of an *inclusive* range, such as a range indicated by use > of an en dash :-) Yes you do, you just have to add one to it. You still use subtraction. :) >> The fact that the en dash and minus sign are both often represented in >> ASCII with a hyphen is pure coincidence. > > Hopefully, the fact that your quoting of my text munged the characters > down to ASCII is also pure coincidence, and is soon to be corrected at > your end? Or has your client program not joined the rest of us in the > third millennium with Unicode? It's gmail, and I don't know why it folded everything down. I've told it to cast everything to text (to avoid the stupid look you sometimes get with nested replies to HTML-formatted emails), and I guess it decided to go ASCII. Your mail displayed just fine, it was something in the reply mechanism. ChrisA From ben+python at benfinney.id.au Thu Mar 15 09:50:01 2012 From: ben+python at benfinney.id.au (Ben Finney) Date: Fri, 16 Mar 2012 00:50:01 +1100 Subject: Python is readable References: <4f612b19$0$1379$4fafbaef@reader2.news.tin.it> <8e72d74f-c844-4de3-8a37-f6b1fdc2291f@y27g2000yqy.googlegroups.com> <50e9ceec-40f1-4ead-b2b6-87328b30d084@ow8g2000pbc.googlegroups.com> <4f61c828$0$1390$4fafbaef@reader2.news.tin.it> <4f61d221$0$1375$4fafbaef@reader2.news.tin.it> <4f61d9a2$0$1377$4fafbaef@reader2.news.tin.it> <87k42moxkq.fsf@benfinney.id.au> <87fwdaovgz.fsf@benfinney.id.au> Message-ID: <87bonyotx2.fsf@benfinney.id.au> Chris Angelico writes: > On Fri, Mar 16, 2012 at 12:16 AM, Ben Finney wrote: > > Hopefully, the fact that your quoting of my text munged the > > characters down to ASCII is also pure coincidence, and is soon to be > > corrected at your end? Or has your client program not joined the > > rest of us in the third millennium with Unicode? > > It's gmail, and I don't know why it folded everything down. Ah. The answer is ?No?, then. Gmail (from what I can tell of receiving messages from it) is terrible at Unicode, and for that reason among many others is a poor choice for interacting with modern forums. I recommend you add your voice to those complaining at Gmail's support team about poor Unicode support, and meanwhile use a better-maintained free-software client. -- \ ?Quidquid latine dictum sit, altum viditur.? (?Whatever is | `\ said in Latin, sounds profound.?) ?anonymous | _o__) | Ben Finney From breamoreboy at yahoo.co.uk Thu Mar 15 10:06:01 2012 From: breamoreboy at yahoo.co.uk (Mark Lawrence) Date: Thu, 15 Mar 2012 14:06:01 +0000 Subject: Python is readable In-Reply-To: <4f61d728$0$1375$4fafbaef@reader2.news.tin.it> References: <4f612b19$0$1379$4fafbaef@reader2.news.tin.it> <8e72d74f-c844-4de3-8a37-f6b1fdc2291f@y27g2000yqy.googlegroups.com> <50e9ceec-40f1-4ead-b2b6-87328b30d084@ow8g2000pbc.googlegroups.com> <4f61c828$0$1390$4fafbaef@reader2.news.tin.it> <4f61d728$0$1375$4fafbaef@reader2.news.tin.it> Message-ID: On 15/03/2012 11:48, Kiuhnm wrote: > On 3/15/2012 12:14, Thomas Rachel wrote: >> Am 15.03.2012 11:44 schrieb Kiuhnm: >> >>> Let's try that. >>> Show me an example of "list comprehensions" and "with" (whatever they >>> are). >> >> with open("filename", "w") as f: >> f.write(stuff) > > Here f is created before executing the block and destroyed right after > leaving the block. f's destructor will probably close the file handle. > >> with lock: >> do_something_exclusively() > > It's clear what it does, but I don't know if that's special syntax. > Maybe objects can have two special methods that are called respect. on > entering and leaving the with-block. > Or, more likely, lock creates an object which keeps the lock "acquired". > The lock is released when we leave the block. > So we could inspect the lock with > with lock as l: > inspect l... > do_some..... > > BTW, aren't those ':' redundant? > > Kiuhnm Nope. Python 2.7.2 (default, Jun 12 2011, 15:08:59) [MSC v.1500 32 bit (Intel)] on win32 Type "help", "copyright", "credits" or "license" for more information. >>> with open("filename", "w") as f File "", line 1 with open("filename", "w") as f ^ SyntaxError: invalid syntax -- Cheers. Mark Lawrence. From kiuhnm03.4t.yahoo.it Thu Mar 15 10:16:31 2012 From: kiuhnm03.4t.yahoo.it (Kiuhnm) Date: Thu, 15 Mar 2012 15:16:31 +0100 Subject: Python is readable In-Reply-To: References: <4f612b19$0$1379$4fafbaef@reader2.news.tin.it> <8e72d74f-c844-4de3-8a37-f6b1fdc2291f@y27g2000yqy.googlegroups.com> <50e9ceec-40f1-4ead-b2b6-87328b30d084@ow8g2000pbc.googlegroups.com> <4f61c828$0$1390$4fafbaef@reader2.news.tin.it> <4f61d221$0$1375$4fafbaef@reader2.news.tin.it> <4f61d9a2$0$1377$4fafbaef@reader2.news.tin.it> Message-ID: <4f61f9bf$0$1381$4fafbaef@reader2.news.tin.it> On 3/15/2012 13:21, Chris Angelico wrote: > On Thu, Mar 15, 2012 at 10:59 PM, Kiuhnm > wrote: >> On 3/15/2012 12:47, Chris Angelico wrote: >>> It's a little odd, perhaps, if seen in a vacuum. But everything counts >>> from zero - list indices, etc - so it makes sense for range(len(lst)) >>> to return indices valid for lst. >> >> Maybe range uses [...) intervals? So range(a,b) is a,a+1,a+2,...,b-1 and >> range(b) is just short-hand for range(0,b)? > > Yup. It's amazing how accurate your conjectures are - it's almost like > you've been reading the docs! :D Come on... that was easy! :) > But yeah, that's pretty logical IMHO; > and having gotten used to [) intervals in many areas of computing, > I've come to find [] intervals disconcerting. Bible passages are > described as, for instance, John 14:5-7, which is a three-verse > passage (5, 6, 7), even though 7-5=2. Common people use mainly inclusive intervals as far as I can tell. For instance, "from" and "to" are inclusive. They could tell you they don't like your intervals because 8-5+1 = 4 instead of 3. > However, inclusive-inclusive intervals have the benefit that they > don't require the element "beyond the last" to be indexable. This is > important if you're working with something that takes up all of > addressable memory - going back to the IBM PCs on which I learned to > code, you could use one 64KB segment for an array, but then there's no > way for a 16-bit integer to indicate "past the end". But you lose the empty interval (a,a). You're forced to use (a,a-1) or something similar. There's always a drawback. >>> List comps are pretty readable if you know how programming languages >>> work. Python need not be readable by everyone and his grandmother, and >>> it does a fairly good job of being grokkable to someone who has a few >>> ranks in Coding. (Yeah, I'm a D&D nerd. ) >> >> I like what I've seen so far. > > Python has its problems, but it's a good language. I personally prefer > to delimit blocks of code with braces than with indentation, I, on the other hand, prefer indentation. I find braces redundant (in fact, I never use them in pseudo-code). > and I > also prefer explicit declaration of variables (yes, it's extra work, > but you can have infinitely nested scopes and easily-caught syntax > errors when you misspell one), but they're relatively minor. I usually declare my variables but close to where I need them. > One of my > favorite aspects of Python is that *everything* is an object. There's > no magic syntax that gives you a piece of an object, or something > special about variables that contain this, that, or the other. A > literal list [like, this, one] can be used in exactly the same ways as > the name of a variable containing a list or a function call returning > a list - there is no difference. Oh how I yearn for that when working > in C++ or PHP! Don't worry. Soon you'll be using C++0x :))) Kiuhnm From alec.taylor6 at gmail.com Thu Mar 15 10:17:49 2012 From: alec.taylor6 at gmail.com (Alec Taylor) Date: Fri, 16 Mar 2012 01:17:49 +1100 Subject: Python is readable In-Reply-To: References: <4f612b19$0$1379$4fafbaef@reader2.news.tin.it> <8e72d74f-c844-4de3-8a37-f6b1fdc2291f@y27g2000yqy.googlegroups.com> <50e9ceec-40f1-4ead-b2b6-87328b30d084@ow8g2000pbc.googlegroups.com> <4f61c828$0$1390$4fafbaef@reader2.news.tin.it> <4f61d728$0$1375$4fafbaef@reader2.news.tin.it> Message-ID: On Fri, Mar 16, 2012 at 1:06 AM, Mark Lawrence wrote: > Python 2.7.2 (default, Jun 12 2011, 15:08:59) [MSC v.1500 32 bit (Intel)] on > win32 > Type "help", "copyright", "credits" or "license" for more information. > >>>> with open("filename", "w") as f > ?File "", line 1 > > ? ?with open("filename", "w") as f > ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ?^ > SyntaxError: invalid syntax > > -- > Cheers. > > Mark Lawrence. > Erred for me also; but under f: Python 2.7.3rc1 (default, Feb 24 2012, 21:28:59) [MSC v.1500 64 bit (AMD64)] on win32 Type "help", "copyright", "credits" or "license" for more information. >>> with open("filename", "w") as f File "", line 1 with open("filename", "w") as f ^ SyntaxError: invalid syntax From kiuhnm03.4t.yahoo.it Thu Mar 15 10:19:53 2012 From: kiuhnm03.4t.yahoo.it (Kiuhnm) Date: Thu, 15 Mar 2012 15:19:53 +0100 Subject: Python is readable In-Reply-To: References: <4f612b19$0$1379$4fafbaef@reader2.news.tin.it> <8e72d74f-c844-4de3-8a37-f6b1fdc2291f@y27g2000yqy.googlegroups.com> <50e9ceec-40f1-4ead-b2b6-87328b30d084@ow8g2000pbc.googlegroups.com> <4f61c828$0$1390$4fafbaef@reader2.news.tin.it> <4f61d728$0$1375$4fafbaef@reader2.news.tin.it> Message-ID: <4f61fa8a$0$1381$4fafbaef@reader2.news.tin.it> On 3/15/2012 15:06, Mark Lawrence wrote: > On 15/03/2012 11:48, Kiuhnm wrote: >> On 3/15/2012 12:14, Thomas Rachel wrote: >>> Am 15.03.2012 11:44 schrieb Kiuhnm: >>> >>>> Let's try that. >>>> Show me an example of "list comprehensions" and "with" (whatever they >>>> are). >>> >>> with open("filename", "w") as f: >>> f.write(stuff) >> >> Here f is created before executing the block and destroyed right after >> leaving the block. f's destructor will probably close the file handle. >> >>> with lock: >>> do_something_exclusively() >> >> It's clear what it does, but I don't know if that's special syntax. >> Maybe objects can have two special methods that are called respect. on >> entering and leaving the with-block. >> Or, more likely, lock creates an object which keeps the lock "acquired". >> The lock is released when we leave the block. >> So we could inspect the lock with >> with lock as l: >> inspect l... >> do_some..... >> >> BTW, aren't those ':' redundant? >> >> Kiuhnm > > Nope. > > Python 2.7.2 (default, Jun 12 2011, 15:08:59) [MSC v.1500 32 bit > (Intel)] on win32 > Type "help", "copyright", "credits" or "license" for more information. > >>> with open("filename", "w") as f > File "", line 1 > with open("filename", "w") as f > ^ > SyntaxError: invalid syntax Ok, so they're mandatory, but I was mainly talking of design. Why are they needed? Kiuhnm From duncan.booth at invalid.invalid Thu Mar 15 10:23:38 2012 From: duncan.booth at invalid.invalid (Duncan Booth) Date: 15 Mar 2012 14:23:38 GMT Subject: Python is readable References: <4f612b19$0$1379$4fafbaef@reader2.news.tin.it> <8e72d74f-c844-4de3-8a37-f6b1fdc2291f@y27g2000yqy.googlegroups.com> <50e9ceec-40f1-4ead-b2b6-87328b30d084@ow8g2000pbc.googlegroups.com> <4f61c828$0$1390$4fafbaef@reader2.news.tin.it> <4f61d728$0$1375$4fafbaef@reader2.news.tin.it> Message-ID: Kiuhnm wrote: > BTW, aren't those ':' redundant? > They are required by the grammar, but in a sense you are correct. You could modify Python's grammar to make the colons optional and still keep it unambiguous but that would make it harder for other tools (such as text editors or indeed humans) to understand. A little bit of redundancy in the grammar is seen as a good way to minimise errors. -- Duncan Booth http://kupuguy.blogspot.com From mail at timgolden.me.uk Thu Mar 15 10:28:38 2012 From: mail at timgolden.me.uk (Tim Golden) Date: Thu, 15 Mar 2012 14:28:38 +0000 Subject: Python is readable In-Reply-To: <4f61fa8a$0$1381$4fafbaef@reader2.news.tin.it> References: <4f612b19$0$1379$4fafbaef@reader2.news.tin.it> <8e72d74f-c844-4de3-8a37-f6b1fdc2291f@y27g2000yqy.googlegroups.com> <50e9ceec-40f1-4ead-b2b6-87328b30d084@ow8g2000pbc.googlegroups.com> <4f61c828$0$1390$4fafbaef@reader2.news.tin.it> <4f61d728$0$1375$4fafbaef@reader2.news.tin.it> <4f61fa8a$0$1381$4fafbaef@reader2.news.tin.it> Message-ID: <4F61FC96.8010807@timgolden.me.uk> On 15/03/2012 14:19, Kiuhnm wrote: > On 3/15/2012 15:06, Mark Lawrence wrote: >> On 15/03/2012 11:48, Kiuhnm wrote: >>> BTW, aren't those ':' redundant? >>> >>> Kiuhnm >> >> Nope. >> >> Python 2.7.2 (default, Jun 12 2011, 15:08:59) [MSC v.1500 32 bit >> (Intel)] on win32 >> Type "help", "copyright", "credits" or "license" for more information. >> >>> with open("filename", "w") as f >> File "", line 1 >> with open("filename", "w") as f >> ^ >> SyntaxError: invalid syntax > > Ok, so they're mandatory, but I was mainly talking of design. Why are > they needed? > > Kiuhnm http://docs.python.org/faq/design.html#why-are-colons-required-for-the-if-while-def-class-statements TJG From rosuav at gmail.com Thu Mar 15 10:29:12 2012 From: rosuav at gmail.com (Chris Angelico) Date: Fri, 16 Mar 2012 01:29:12 +1100 Subject: Python is readable In-Reply-To: <4f61f9bf$0$1381$4fafbaef@reader2.news.tin.it> References: <4f612b19$0$1379$4fafbaef@reader2.news.tin.it> <8e72d74f-c844-4de3-8a37-f6b1fdc2291f@y27g2000yqy.googlegroups.com> <50e9ceec-40f1-4ead-b2b6-87328b30d084@ow8g2000pbc.googlegroups.com> <4f61c828$0$1390$4fafbaef@reader2.news.tin.it> <4f61d221$0$1375$4fafbaef@reader2.news.tin.it> <4f61d9a2$0$1377$4fafbaef@reader2.news.tin.it> <4f61f9bf$0$1381$4fafbaef@reader2.news.tin.it> Message-ID: On Fri, Mar 16, 2012 at 1:16 AM, Kiuhnm wrote: > Don't worry. Soon you'll be using C++0x :))) I use gcc/g++ with most of the new features enabled. There's some pretty handy features in it. Frankly, though, if I'd known about Cython when I started the current project, I would have argued to write it all in Python and Cify (is that a word?) the most performance-critical sections afterwards, instead of writing it in C++. It'd be a lot of hassle to change it now, but if anyone else is looking at writing a large project in C "for performance", I would strongly recommend writing in Python or Pike first. (Some day, I'm going to have to actually try Cython. But I know enough of embedding/extending Python to know that the technique would definitely be viable, and Cython can only make it easier.) ChrisA From kiuhnm03.4t.yahoo.it Thu Mar 15 10:30:33 2012 From: kiuhnm03.4t.yahoo.it (Kiuhnm) Date: Thu, 15 Mar 2012 15:30:33 +0100 Subject: Python is readable In-Reply-To: References: <4f612b19$0$1379$4fafbaef@reader2.news.tin.it> <8e72d74f-c844-4de3-8a37-f6b1fdc2291f@y27g2000yqy.googlegroups.com> <50e9ceec-40f1-4ead-b2b6-87328b30d084@ow8g2000pbc.googlegroups.com> <4f61c828$0$1390$4fafbaef@reader2.news.tin.it> <4f61d728$0$1375$4fafbaef@reader2.news.tin.it> Message-ID: <4f61fd0a$0$1389$4fafbaef@reader2.news.tin.it> On 3/15/2012 15:23, Duncan Booth wrote: > Kiuhnm wrote: > >> BTW, aren't those ':' redundant? >> > > They are required by the grammar, but in a sense you are correct. You could > modify Python's grammar to make the colons optional and still keep it > unambiguous but that would make it harder for other tools (such as text > editors or indeed humans) to understand. Sorry, but I can't see how it would make it harder for humans to understand. Are there particular situations you're referring to? Kiuhnm From robin at reportlab.com Thu Mar 15 10:31:03 2012 From: robin at reportlab.com (Robin Becker) Date: Thu, 15 Mar 2012 14:31:03 +0000 Subject: client ssl verification Message-ID: <4F61FD27.8080204@chamonix.reportlab.co.uk> I'm trying to do client ssl verification with code that looks like the sample below. I am able to reach and read urls that are secure and have no client certificate requirement OK. If I set explicit_check to True then verbose output indicates that the server certs are being checked fine ie I see the correct cert details and am able to check them. However, when I try to reach an apache location like sslverifyclient require sslverifydepth 10 I am getting an error from urllib2 that goes like this urllib2.py", line 1148, in do_open raise URLError(err) URLError: import socket, ssl, fnmatch, datetime, urllib2, httplib > verbose=False > > # wraps https connections with ssl certificate verification > class SecuredHTTPSHandler(urllib2.HTTPSHandler): > def __init__(self,key_file=None,cert_file=None,ca_certs=None,explicit_check=False): > class SecuredHTTPSConnection(httplib.HTTPSConnection): > def connect(self): > # overrides the version in httplib so that we do > # certificate verification > sock = socket.create_connection((self.host, self.port), self.timeout) > if self._tunnel_host: > self.sock = sock > self._tunnel() > # wrap the socket using verification with the root > # certs in ca_certs > if verbose: > print ca_certs, key_file, cert_file > self.sock = ssl.wrap_socket(sock, > cert_reqs=ssl.CERT_REQUIRED, > ca_certs=ca_certs, > keyfile=key_file, > certfile=cert_file, > ) > if explicit_check: > cert = self.sock.getpeercert() > if verbose: > import pprint > pprint.pprint(cert) > for key,field in cert.iteritems(): > if key=='subject': > sd = dict([x[0] for x in field]) > certhost = sd.get('commonName') > if not fnmatch.fnmatch(self.host,certhost): > raise ssl.SSLError("Host name '%s' doesn't match certificate host '%s'" > % (self.host, certhost)) > if verbose: > print 'matched "%s" to "%s"' % (self.host,certhost) > elif key=='notAfter': > now = datetime.datetime.now() > crttime = datetime.datetime.strptime(field,'%b %d %H:%M:%S %Y %Z') > if verbose: > print 'crttime=%s now=%s' % (crttime,now) > if now>=crttime: > raise ssl.SSLError("Host '%s' certificate expired on %s" > % (self.host, field)) > self.specialized_conn_class = SecuredHTTPSConnection > urllib2.HTTPSHandler.__init__(self) > > def https_open(self, req): > return self.do_open(self.specialized_conn_class, req) > > def secureDataGet(uri,ca_certs='cacert.pem',key_file=None,cert_file=None, explicit_check=False): > https_handler = SecuredHTTPSHandler(key_file=key_file,cert_file=cert_file, > ca_certs=ca_certs,explicit_check=explicit_check) > url_opener = urllib2.build_opener(https_handler) > handle = url_opener.open(uri) > response = handle.readlines() > handle.close() > return response -- Robin Becker From kiuhnm03.4t.yahoo.it Thu Mar 15 10:37:23 2012 From: kiuhnm03.4t.yahoo.it (Kiuhnm) Date: Thu, 15 Mar 2012 15:37:23 +0100 Subject: Python is readable In-Reply-To: References: <4f612b19$0$1379$4fafbaef@reader2.news.tin.it> <8e72d74f-c844-4de3-8a37-f6b1fdc2291f@y27g2000yqy.googlegroups.com> <50e9ceec-40f1-4ead-b2b6-87328b30d084@ow8g2000pbc.googlegroups.com> <4f61c828$0$1390$4fafbaef@reader2.news.tin.it> <4f61d221$0$1375$4fafbaef@reader2.news.tin.it> <4f61d9a2$0$1377$4fafbaef@reader2.news.tin.it> <4f61f9bf$0$1381$4fafbaef@reader2.news.tin.it> Message-ID: <4f61fea4$0$1378$4fafbaef@reader2.news.tin.it> On 3/15/2012 15:29, Chris Angelico wrote: > On Fri, Mar 16, 2012 at 1:16 AM, Kiuhnm > wrote: >> Don't worry. Soon you'll be using C++0x :))) > > I use gcc/g++ with most of the new features enabled. There's some > pretty handy features in it. Frankly, though, if I'd known about > Cython when I started the current project, I would have argued to > write it all in Python and Cify (is that a word?) the most > performance-critical sections afterwards, instead of writing it in > C++. Wise words. Indeed, I was joking :) I don't like what C++ is becoming. C++ should be rewritten from scratch but then who would use it? Kiuhnm From robert.kern at gmail.com Thu Mar 15 10:43:44 2012 From: robert.kern at gmail.com (Robert Kern) Date: Thu, 15 Mar 2012 14:43:44 +0000 Subject: Python is readable In-Reply-To: <4f61fd0a$0$1389$4fafbaef@reader2.news.tin.it> References: <4f612b19$0$1379$4fafbaef@reader2.news.tin.it> <8e72d74f-c844-4de3-8a37-f6b1fdc2291f@y27g2000yqy.googlegroups.com> <50e9ceec-40f1-4ead-b2b6-87328b30d084@ow8g2000pbc.googlegroups.com> <4f61c828$0$1390$4fafbaef@reader2.news.tin.it> <4f61d728$0$1375$4fafbaef@reader2.news.tin.it> <4f61fd0a$0$1389$4fafbaef@reader2.news.tin.it> Message-ID: On 3/15/12 2:30 PM, Kiuhnm wrote: > On 3/15/2012 15:23, Duncan Booth wrote: >> Kiuhnm wrote: >> >>> BTW, aren't those ':' redundant? >>> >> >> They are required by the grammar, but in a sense you are correct. You could >> modify Python's grammar to make the colons optional and still keep it >> unambiguous but that would make it harder for other tools (such as text >> editors or indeed humans) to understand. > > Sorry, but I can't see how it would make it harder for humans to understand. Are > there particular situations you're referring to? There were usability studies done on one of Python's indentation-based ancestors, ABC. Those studies found, empirically, that having the colons helped people read and understand the code faster. -- Robert Kern "I have come to believe that the whole world is an enigma, a harmless enigma that is made terrible by our own mad attempt to interpret it as though it had an underlying truth." -- Umberto Eco From rosuav at gmail.com Thu Mar 15 10:48:09 2012 From: rosuav at gmail.com (Chris Angelico) Date: Fri, 16 Mar 2012 01:48:09 +1100 Subject: Python is readable In-Reply-To: <4f61fd0a$0$1389$4fafbaef@reader2.news.tin.it> References: <4f612b19$0$1379$4fafbaef@reader2.news.tin.it> <8e72d74f-c844-4de3-8a37-f6b1fdc2291f@y27g2000yqy.googlegroups.com> <50e9ceec-40f1-4ead-b2b6-87328b30d084@ow8g2000pbc.googlegroups.com> <4f61c828$0$1390$4fafbaef@reader2.news.tin.it> <4f61d728$0$1375$4fafbaef@reader2.news.tin.it> <4f61fd0a$0$1389$4fafbaef@reader2.news.tin.it> Message-ID: On Fri, Mar 16, 2012 at 1:30 AM, Kiuhnm wrote: > Sorry, but I can't see how it would make it harder for humans to understand. > Are there particular situations you're referring to? In a trivial example, it's mostly just noise: if a == b # who needs the colon? print(c) But when your condition is more complicated, it's cleaner to explicitly mark the end of the condition. Also, Python allows you to put a simple body on the same line as the if, which is very handy: if a == b: print(c) Without the colon, this would be awkward to parse. And the bash style of using actual statement separators feels really weird, although it does mean that the newline is truly optional. ChrisA From kiuhnm03.4t.yahoo.it Thu Mar 15 10:55:05 2012 From: kiuhnm03.4t.yahoo.it (Kiuhnm) Date: Thu, 15 Mar 2012 15:55:05 +0100 Subject: Python is readable In-Reply-To: References: <4f612b19$0$1379$4fafbaef@reader2.news.tin.it> <8e72d74f-c844-4de3-8a37-f6b1fdc2291f@y27g2000yqy.googlegroups.com> <50e9ceec-40f1-4ead-b2b6-87328b30d084@ow8g2000pbc.googlegroups.com> <4f61c828$0$1390$4fafbaef@reader2.news.tin.it> <4f61d728$0$1375$4fafbaef@reader2.news.tin.it> <4f61fa8a$0$1381$4fafbaef@reader2.news.tin.it> Message-ID: <4f6202cb$0$1377$4fafbaef@reader2.news.tin.it> On 3/15/2012 15:28, Tim Golden wrote: > On 15/03/2012 14:19, Kiuhnm wrote: >> On 3/15/2012 15:06, Mark Lawrence wrote: >>> On 15/03/2012 11:48, Kiuhnm wrote: >>>> BTW, aren't those ':' redundant? >>>> >>>> Kiuhnm >>> >>> Nope. >>> >>> Python 2.7.2 (default, Jun 12 2011, 15:08:59) [MSC v.1500 32 bit >>> (Intel)] on win32 >>> Type "help", "copyright", "credits" or "license" for more information. >>> >>> with open("filename", "w") as f >>> File "", line 1 >>> with open("filename", "w") as f >>> ^ >>> SyntaxError: invalid syntax >> >> Ok, so they're mandatory, but I was mainly talking of design. Why are >> they needed? >> >> Kiuhnm > > http://docs.python.org/faq/design.html#why-are-colons-required-for-the-if-while-def-class-statements The second one is slightly easier to read because it's syntax-highlighted. Was that on purpose? By the way, the more elaborate parsing consists of looking for an END_OF_LINE followed by one or more spaces. It doesn't sound that complicated. And what about an editor which indent when you press the spacebar or tab? Kiuhnm From kiuhnm03.4t.yahoo.it Thu Mar 15 11:05:58 2012 From: kiuhnm03.4t.yahoo.it (Kiuhnm) Date: Thu, 15 Mar 2012 16:05:58 +0100 Subject: Python is readable In-Reply-To: References: <4f612b19$0$1379$4fafbaef@reader2.news.tin.it> <8e72d74f-c844-4de3-8a37-f6b1fdc2291f@y27g2000yqy.googlegroups.com> <50e9ceec-40f1-4ead-b2b6-87328b30d084@ow8g2000pbc.googlegroups.com> <4f61c828$0$1390$4fafbaef@reader2.news.tin.it> <4f61d728$0$1375$4fafbaef@reader2.news.tin.it> <4f61fd0a$0$1389$4fafbaef@reader2.news.tin.it> Message-ID: <4f620557$0$1388$4fafbaef@reader2.news.tin.it> On 3/15/2012 15:48, Chris Angelico wrote: > On Fri, Mar 16, 2012 at 1:30 AM, Kiuhnm > wrote: >> Sorry, but I can't see how it would make it harder for humans to understand. >> Are there particular situations you're referring to? > > In a trivial example, it's mostly just noise: > > if a == b # who needs the colon? > print(c) > > But when your condition is more complicated, it's cleaner to > explicitly mark the end of the condition. Also, Python allows you to > put a simple body on the same line as the if, which is very handy: > > if a == b: print(c) > > Without the colon, this would be awkward to parse. And the bash style > of using actual statement separators feels really weird, although it > does mean that the newline is truly optional. I had thought about the single-line case. What I hadn't thought about is that Python strives to be as regular as possible, so having different cases just for saving one keystroke isn't worth it. Kiuhnm From rosuav at gmail.com Thu Mar 15 11:08:37 2012 From: rosuav at gmail.com (Chris Angelico) Date: Fri, 16 Mar 2012 02:08:37 +1100 Subject: Python is readable In-Reply-To: <4f6202cb$0$1377$4fafbaef@reader2.news.tin.it> References: <4f612b19$0$1379$4fafbaef@reader2.news.tin.it> <8e72d74f-c844-4de3-8a37-f6b1fdc2291f@y27g2000yqy.googlegroups.com> <50e9ceec-40f1-4ead-b2b6-87328b30d084@ow8g2000pbc.googlegroups.com> <4f61c828$0$1390$4fafbaef@reader2.news.tin.it> <4f61d728$0$1375$4fafbaef@reader2.news.tin.it> <4f61fa8a$0$1381$4fafbaef@reader2.news.tin.it> <4f6202cb$0$1377$4fafbaef@reader2.news.tin.it> Message-ID: On Fri, Mar 16, 2012 at 1:55 AM, Kiuhnm wrote: > By the way, the more elaborate parsing consists of looking for an > END_OF_LINE followed by one or more spaces. It doesn't sound that > complicated. Only in the trivial case. What if you want to break your condition over multiple lines? (Although you have to parenthesize or backslash, so that's still unambig.) It's helpful to be explicit. > And what about an editor which indent when you press the spacebar or tab? Sure, but a good editor helps out by noticing that you did something that begs for indentation. If I put an open brace, SciTE will indent - very simple rule. With Python, if there were no colon markers, it would be quite complicated to figure out whether or not to indent; with the colons, it's simply "if/while/etc" followed by text followed by colon, and then no further non-comment text. (This sounds involved. It's not. It's right enough. -- Lady Blanche) ChrisA From robert.kern at gmail.com Thu Mar 15 11:13:46 2012 From: robert.kern at gmail.com (Robert Kern) Date: Thu, 15 Mar 2012 15:13:46 +0000 Subject: Python is readable In-Reply-To: <4f6202cb$0$1377$4fafbaef@reader2.news.tin.it> References: <4f612b19$0$1379$4fafbaef@reader2.news.tin.it> <8e72d74f-c844-4de3-8a37-f6b1fdc2291f@y27g2000yqy.googlegroups.com> <50e9ceec-40f1-4ead-b2b6-87328b30d084@ow8g2000pbc.googlegroups.com> <4f61c828$0$1390$4fafbaef@reader2.news.tin.it> <4f61d728$0$1375$4fafbaef@reader2.news.tin.it> <4f61fa8a$0$1381$4fafbaef@reader2.news.tin.it> <4f6202cb$0$1377$4fafbaef@reader2.news.tin.it> Message-ID: On 3/15/12 2:55 PM, Kiuhnm wrote: > On 3/15/2012 15:28, Tim Golden wrote: >> http://docs.python.org/faq/design.html#why-are-colons-required-for-the-if-while-def-class-statements > > The second one is slightly easier to read because it's syntax-highlighted. Was > that on purpose? No, it's an unintended side effect. The (automated) syntax highlighting was added to the FAQ much, much later than that entry was written. The syntax highlighting tool does not recognize the first example as Python, so it does not apply Python syntax highlighting to it. -- Robert Kern "I have come to believe that the whole world is an enigma, a harmless enigma that is made terrible by our own mad attempt to interpret it as though it had an underlying truth." -- Umberto Eco From roy at panix.com Thu Mar 15 11:14:02 2012 From: roy at panix.com (Roy Smith) Date: Thu, 15 Mar 2012 11:14:02 -0400 Subject: Python is readable References: <4f612b19$0$1379$4fafbaef@reader2.news.tin.it> <8e72d74f-c844-4de3-8a37-f6b1fdc2291f@y27g2000yqy.googlegroups.com> <50e9ceec-40f1-4ead-b2b6-87328b30d084@ow8g2000pbc.googlegroups.com> <4f61c828$0$1390$4fafbaef@reader2.news.tin.it> <4f61d221$0$1375$4fafbaef@reader2.news.tin.it> <4f61d9a2$0$1377$4fafbaef@reader2.news.tin.it> <4f61f9bf$0$1381$4fafbaef@reader2.news.tin.it> Message-ID: In article , Chris Angelico wrote: > I use gcc/g++ with most of the new features enabled. There's some > pretty handy features in it. Frankly, though, if I'd known about > Cython when I started the current project, I would have argued to > write it all in Python and Cify (is that a word?) the most > performance-critical sections afterwards, instead of writing it in > C++. +1. With the exception of the client-side javascript, virtually 100% of the application code behind songza.com is python. We use django, tornado, and gunicorn (all pure python). The ORM layer (mongoengine) is pure python. Of course, there's plenty of C/C++ code in the database (MongoDB), HTTP proxies (nginx and haproxy), and search engine (Xapian), but the core application code is all python. About 80,000 lines worth. Every time we look at performance, we discover the same thing. The time spent running python code is insignificant. It's all about network I/O and database queries. The only time we ever see any significant time running python code is when we do something stupid and write some O(n^2) code that can be replaced by a more appropriate algorithm. While it's nice to know that we've got the ability to write extensions in C, not once have we ever felt the need. I suppose if you're running a CPU-bound application, that might not be the case, but surprisingly few applications really are compute bound these days. I had an interesting experience the other day. We had a job applicant implement one of our coding tests in Java. It's a data mining exercise where you need to generate some summary statistics from a 700,000 line log file we give you. My Python version takes under a second. His Java version came up with the right numbers but took 2 minutes. I looked at his code and didn't any any obvious problem. It turned out he used a regex that started with '.*', and apparently the Java regex library implements that badly. Eliminating the leading '.*' got his Java running in the same time as my Python. From rosuav at gmail.com Thu Mar 15 11:14:54 2012 From: rosuav at gmail.com (Chris Angelico) Date: Fri, 16 Mar 2012 02:14:54 +1100 Subject: Python is readable In-Reply-To: <4f620557$0$1388$4fafbaef@reader2.news.tin.it> References: <4f612b19$0$1379$4fafbaef@reader2.news.tin.it> <8e72d74f-c844-4de3-8a37-f6b1fdc2291f@y27g2000yqy.googlegroups.com> <50e9ceec-40f1-4ead-b2b6-87328b30d084@ow8g2000pbc.googlegroups.com> <4f61c828$0$1390$4fafbaef@reader2.news.tin.it> <4f61d728$0$1375$4fafbaef@reader2.news.tin.it> <4f61fd0a$0$1389$4fafbaef@reader2.news.tin.it> <4f620557$0$1388$4fafbaef@reader2.news.tin.it> Message-ID: On Fri, Mar 16, 2012 at 2:05 AM, Kiuhnm wrote: > I had thought about the single-line case. What I hadn't thought about is > that Python strives to be as regular as possible, so having different cases > just for saving one keystroke isn't worth it. Yep. Have you read the Zen of Python? >>> import this (trimmed for brevity) Explicit is better than implicit. Readability counts. Special cases aren't special enough to break the rules. Although practicality beats purity. In the face of ambiguity, refuse the temptation to guess. Omitting the colon is definitely a not-special-enough case. ChrisA From kiuhnm03.4t.yahoo.it Thu Mar 15 11:18:14 2012 From: kiuhnm03.4t.yahoo.it (Kiuhnm) Date: Thu, 15 Mar 2012 16:18:14 +0100 Subject: Python is readable In-Reply-To: References: <4f612b19$0$1379$4fafbaef@reader2.news.tin.it> <8e72d74f-c844-4de3-8a37-f6b1fdc2291f@y27g2000yqy.googlegroups.com> <50e9ceec-40f1-4ead-b2b6-87328b30d084@ow8g2000pbc.googlegroups.com> <4f61c828$0$1390$4fafbaef@reader2.news.tin.it> <4f61d728$0$1375$4fafbaef@reader2.news.tin.it> <4f61fd0a$0$1389$4fafbaef@reader2.news.tin.it> Message-ID: <4f620837$0$1382$4fafbaef@reader2.news.tin.it> On 3/15/2012 15:43, Robert Kern wrote: > On 3/15/12 2:30 PM, Kiuhnm wrote: >> On 3/15/2012 15:23, Duncan Booth wrote: >>> Kiuhnm wrote: >>> >>>> BTW, aren't those ':' redundant? >>>> >>> >>> They are required by the grammar, but in a sense you are correct. You >>> could >>> modify Python's grammar to make the colons optional and still keep it >>> unambiguous but that would make it harder for other tools (such as text >>> editors or indeed humans) to understand. >> >> Sorry, but I can't see how it would make it harder for humans to >> understand. Are >> there particular situations you're referring to? > > There were usability studies done on one of Python's indentation-based > ancestors, ABC. Those studies found, empirically, that having the colons > helped people read and understand the code faster. Here's what Guido van Rossum writes about it: "Python?s use of indentation comes directly from ABC, but this idea didn?t originate with ABC--it had already been promoted by Donald Knuth and was a well-known concept of programming style. (The occam programming language also used it.) However, ABC?s authors did invent the use of the colon that separates the lead-in clause from the indented block. ----> After early user testing without the colon, it was discovered that the meaning of the indentation was unclear to beginners being taught the first steps of programming. <---- The addition of the colon clarified it significantly: the colon somehow draws attention to what follows and ties the phrases before and after it together in just the right way." If that passage is correct, those studies don't say that adding the colon increases the readability, but that it makes more sense to beginners who don't even know what indentation is. Kiuhnm From rosuav at gmail.com Thu Mar 15 11:27:31 2012 From: rosuav at gmail.com (Chris Angelico) Date: Fri, 16 Mar 2012 02:27:31 +1100 Subject: Python is readable In-Reply-To: References: <4f612b19$0$1379$4fafbaef@reader2.news.tin.it> <8e72d74f-c844-4de3-8a37-f6b1fdc2291f@y27g2000yqy.googlegroups.com> <50e9ceec-40f1-4ead-b2b6-87328b30d084@ow8g2000pbc.googlegroups.com> <4f61c828$0$1390$4fafbaef@reader2.news.tin.it> <4f61d221$0$1375$4fafbaef@reader2.news.tin.it> <4f61d9a2$0$1377$4fafbaef@reader2.news.tin.it> <4f61f9bf$0$1381$4fafbaef@reader2.news.tin.it> Message-ID: On Fri, Mar 16, 2012 at 2:14 AM, Roy Smith wrote: > While it's nice to know that we've got the ability to write extensions > in C, not once have we ever felt the need. ?I suppose if you're running > a CPU-bound application, that might not be the case, but surprisingly > few applications really are compute bound these days. My boss and I have these discussions now and then. A topic of performance comes up, and we debate whether or not, for instance, it's worth doing a separate check of an input file to see if it's properly-formed UTF-8 before parsing it (this is in PHP, or it'd be easy - just do a UTF-8 decode and work with Unicode). The debate ended, as they inevitably do, with "We're talking about a file that someone's uploaded to us, so it won't matter". Whatever processing we do is massively dwarfed by network time, and both scale linearly with the size of the file. ChrisA From nutznetz-0c1b6768-bfa9-48d5-a470-7603bd3aa915 at spamschutz.glglgl.de Thu Mar 15 11:41:36 2012 From: nutznetz-0c1b6768-bfa9-48d5-a470-7603bd3aa915 at spamschutz.glglgl.de (Thomas Rachel) Date: Thu, 15 Mar 2012 16:41:36 +0100 Subject: Python is readable In-Reply-To: <4f61d728$0$1375$4fafbaef@reader2.news.tin.it> References: <4f612b19$0$1379$4fafbaef@reader2.news.tin.it> <8e72d74f-c844-4de3-8a37-f6b1fdc2291f@y27g2000yqy.googlegroups.com> <50e9ceec-40f1-4ead-b2b6-87328b30d084@ow8g2000pbc.googlegroups.com> <4f61c828$0$1390$4fafbaef@reader2.news.tin.it> <4f61d728$0$1375$4fafbaef@reader2.news.tin.it> Message-ID: Am 15.03.2012 12:48 schrieb Kiuhnm: > On 3/15/2012 12:14, Thomas Rachel wrote: >> Am 15.03.2012 11:44 schrieb Kiuhnm: >> >>> Let's try that. >>> Show me an example of "list comprehensions" and "with" (whatever they >>> are). >> >> with open("filename", "w") as f: >> f.write(stuff) > > Here f is created before executing the block and destroyed right after > leaving the block. f's destructor will probably close the file handle. No, that is the point here: with calls __enter__ on entry and __exit__ on, well, exit. In the case of files, __enter__ doesn't probably do anything special, but returns the object again in order to be assigned to f. In __exit__, the file is closed. with open("/tmp/filename", "w") as f: print f print f So after the with clause, f is actually closed, but still present as object. >> with lock: >> do_something_exclusively() > It's clear what it does, but I don't know if that's special syntax. If you call "with" special syntax, it is. > Maybe objects can have two special methods that are called respect. on > entering and leaving the with-block. Exactly, see above. Here, on entry __enter__ is called which acquires the lock. __exit__ releases it again. > Or, more likely, lock creates an object which keeps the lock "acquired". > The lock is released when we leave the block. > So we could inspect the lock with > with lock as l: > inspect l... > do_some..... Or just inspect l - I don't know if a lock's __enter__ methos returns it again for assignment with "as"... Thomas From roy at panix.com Thu Mar 15 11:44:07 2012 From: roy at panix.com (Roy Smith) Date: Thu, 15 Mar 2012 11:44:07 -0400 Subject: Python is readable References: <4f612b19$0$1379$4fafbaef@reader2.news.tin.it> <8e72d74f-c844-4de3-8a37-f6b1fdc2291f@y27g2000yqy.googlegroups.com> <50e9ceec-40f1-4ead-b2b6-87328b30d084@ow8g2000pbc.googlegroups.com> <4f61c828$0$1390$4fafbaef@reader2.news.tin.it> <4f61d221$0$1375$4fafbaef@reader2.news.tin.it> <4f61d9a2$0$1377$4fafbaef@reader2.news.tin.it> <4f61f9bf$0$1381$4fafbaef@reader2.news.tin.it> Message-ID: In article , Chris Angelico wrote: > "We're talking about a file that someone's uploaded to us, so it > won't matter". Whatever processing we do is massively dwarfed by > network time, and both scale linearly with the size of the file. That last part (both scaling linearly) may not be true. There's an overhead of one RTT (Round Trip Time) to open a TCP connection. Add at least (handwave) one more RTT if you're negotiating encryption (i.e. https). If you're sending lots of small files, this can easily swamp the data transfer time. The single biggest optimization we've made recently was using a persistent https connection to an external data provider. Fortunately, the truly awesome requests library (http://docs.python-requests.org/) made that trivial to implement. From alec.taylor6 at gmail.com Thu Mar 15 12:01:42 2012 From: alec.taylor6 at gmail.com (Alec Taylor) Date: Fri, 16 Mar 2012 03:01:42 +1100 Subject: Python is readable In-Reply-To: <4f61f9bf$0$1381$4fafbaef@reader2.news.tin.it> References: <4f612b19$0$1379$4fafbaef@reader2.news.tin.it> <8e72d74f-c844-4de3-8a37-f6b1fdc2291f@y27g2000yqy.googlegroups.com> <50e9ceec-40f1-4ead-b2b6-87328b30d084@ow8g2000pbc.googlegroups.com> <4f61c828$0$1390$4fafbaef@reader2.news.tin.it> <4f61d221$0$1375$4fafbaef@reader2.news.tin.it> <4f61d9a2$0$1377$4fafbaef@reader2.news.tin.it> <4f61f9bf$0$1381$4fafbaef@reader2.news.tin.it> Message-ID: On Fri, Mar 16, 2012 at 1:16 AM, Kiuhnm wrote: > On 3/15/2012 13:21, Chris Angelico wrote: >> >> On Thu, Mar 15, 2012 at 10:59 PM, Kiuhnm >> ?wrote: >>> >>> On 3/15/2012 12:47, Chris Angelico wrote: >>>> >>>> It's a little odd, perhaps, if seen in a vacuum. But everything counts >>>> from zero - list indices, etc - so it makes sense for range(len(lst)) >>>> to return indices valid for lst. >>> >>> >>> Maybe range uses [...) intervals? So range(a,b) is a,a+1,a+2,...,b-1 and >>> range(b) is just short-hand for range(0,b)? >> >> >> Yup. It's amazing how accurate your conjectures are - it's almost like >> you've been reading the docs! :D > > > Come on... that was easy! :) > > >> But yeah, that's pretty logical IMHO; >> and having gotten used to [) intervals in many areas of computing, >> I've come to find [] intervals disconcerting. Bible passages are >> described as, for instance, John 14:5-7, which is a three-verse >> passage (5, 6, 7), even though 7-5=2. > > > Common people use mainly inclusive intervals as far as I can tell. > For instance, "from" and "to" are inclusive. > They could tell you they don't like your intervals because 8-5+1 = 4 instead > of 3. > > >> However, inclusive-inclusive intervals have the benefit that they >> don't require the element "beyond the last" to be indexable. This is >> important if you're working with something that takes up all of >> addressable memory - going back to the IBM PCs on which I learned to >> code, you could use one 64KB segment for an array, but then there's no >> way for a 16-bit integer to indicate "past the end". > > > But you lose the empty interval (a,a). You're forced to use (a,a-1) or > something similar. There's always a drawback. > >>>> List comps are pretty readable if you know how programming languages >>>> work. Python need not be readable by everyone and his grandmother, and >>>> it does a fairly good job of being grokkable to someone who has a few >>>> ranks in Coding. (Yeah, I'm a D&D nerd. ) >>> >>> >>> I like what I've seen so far. >> >> >> Python has its problems, but it's a good language. I personally prefer >> to delimit blocks of code with braces than with indentation, > > > I, on the other hand, prefer indentation. I find braces redundant (in fact, > I never use them in pseudo-code). > > >> and I >> also prefer explicit declaration of variables (yes, it's extra work, >> but you can have infinitely nested scopes and easily-caught syntax >> errors when you misspell one), but they're relatively minor. > > > I usually declare my variables but close to where I need them. > > >> One of my >> favorite aspects of Python is that *everything* is an object. There's >> no magic syntax that gives you a piece of an object, or something >> special about variables that contain this, that, or the other. A >> literal list [like, this, one] can be used in exactly the same ways as >> the name of a variable containing a list or a function call returning >> a list - there is no difference. Oh how I yearn for that when working >> in C++ or PHP! > > > Don't worry. Soon you'll be using C++0x :))) > > Kiuhnm > -- > http://mail.python.org/mailman/listinfo/python-list C++0x? You mean C++11? :P On that note, is Python upgrading to use C11? :V From d at davea.name Thu Mar 15 12:04:06 2012 From: d at davea.name (Dave Angel) Date: Thu, 15 Mar 2012 12:04:06 -0400 Subject: Is it technically possible to give Python option of naming process of running script? In-Reply-To: <22071354.8904.1331796412001.JavaMail.geo-discussion-forums@vbkc1> References: <19118128.4791.1331736187952.JavaMail.geo-discussion-forums@vbai14> <22071354.8904.1331796412001.JavaMail.geo-discussion-forums@vbkc1> Message-ID: <4F6212F6.5080202@davea.name> On 03/15/2012 03:26 AM, xliiv wrote: >>>> Like the topic.. . >>>> I use Python a lot, both Windows and Linux, and it's little weird to have many python process without fast distinction which is what. >> > > I did google, I've played with Exemaker (it works perfect, but not py3) and i've seen questions on Stackoverflow. > The thing I mean is a build feature of python to give such a name. Not 3rd part or etc. like Grant Edwards said. Is it possible? How about simply using cp to copy the python executable, run chmod +x on it, and run that one? Then ps would list it as the new name, not as python. i tried it on /usr/bin/python2.7 but I see no reason the same approach won't work on 3.x Note, I copied it to a new name in the same directory, which may be important. or not. -- DaveA From llanitedave at veawb.coop Thu Mar 15 12:59:54 2012 From: llanitedave at veawb.coop (llanitedave) Date: Thu, 15 Mar 2012 09:59:54 -0700 (PDT) Subject: Pragmas, foreign keys in sqlite3? Message-ID: <41621d5f-072f-41e5-a880-57d78a298250@j5g2000yqm.googlegroups.com> Several questions here, but they're related. I'm trying to incorporate an sqlite3 database that was created using Sqliteman1.2.2. I don't know what version of sqlite3 that one uses, but it seems to have ignored any attempts to create foreign keys for its tables. I'm using Python 2.7.2, and I know that the sqlite3 version that it contains is 3.7.7. Therefore, it should be able to handle foreign keys. Where I'm clueless is about how to get that information out of it, and how to implement or add foreign keys to existing tables. Is there some way to use the sqlite PRAGMA command from within python? I tried connecting to the database and got >>> cr.execute('''PRAGMA foreign_keys;''') using "inspect.getmembers()" I got a huge list of everything; it lets me see that there's no foreign key created, but I can't get that particular tuple separated out, and I have no idea how to add them. Do I need to recreate the entire database structure from scratch? From joncle at googlemail.com Thu Mar 15 13:13:41 2012 From: joncle at googlemail.com (Jon Clements) Date: Thu, 15 Mar 2012 10:13:41 -0700 (PDT) Subject: Style question (Poll) In-Reply-To: References: Message-ID: <24625945.5378.1331831621256.JavaMail.geo-discussion-forums@vblb5> On Wednesday, 14 March 2012 21:16:05 UTC, Terry Reedy wrote: > On 3/14/2012 4:49 PM, Arnaud Delobelle wrote: > > On 14 March 2012 20:37, Croepha wrote: > >> Which is preferred: > >> > >> for value in list: > >> if not value is another_value: > >> value.do_something() > >> break > > Do you really mean 'is' or '=='? > > If you mean x is not y, write it that way. > 'not x is y' can be misread and misunderstood, depending on whether > the 'is' is true or not. > > >>> not 1 is 1 > False > >>> not (1 is 1) > False > >>> (not 1) is 1 > False > > Does not matter how read. > > >>> not (1 is 0) > True > >>> (not 1) is 0 > False > >>> not 1 is 0 > True > > Does matter how read. > > >> if list and not list[0] is another_value: > >> list[0].do_something() > > Or > try: > value = mylist[0] > if value is not another_value: value.dosomething > except IndexError: > pass > > I would not do this in this case of index 0, but if the index were a > complicated expression or expensive function call, making 'if list' an > inadequate test, I might. > > > Hard to say, since they don't do the same thing :) > > > > I suspect you meant: > > > > for value in list: > > if not value is another_value: > > value.do_something() > > break > > > > I always feel uncomfortable with this because it's misleading: a loop > > that never loops. > > I agree. Please do not do this in public ;-). > > -- > Terry Jan Reedy I'm not sure it's efficient or even if I like it, but it avoids try/except and the use of a for loop. if next( iter(mylist), object() ) is not another_value: # ... Just my 2p, Jon. From joncle at googlemail.com Thu Mar 15 13:13:41 2012 From: joncle at googlemail.com (Jon Clements) Date: Thu, 15 Mar 2012 10:13:41 -0700 (PDT) Subject: Style question (Poll) In-Reply-To: References: Message-ID: <24625945.5378.1331831621256.JavaMail.geo-discussion-forums@vblb5> On Wednesday, 14 March 2012 21:16:05 UTC, Terry Reedy wrote: > On 3/14/2012 4:49 PM, Arnaud Delobelle wrote: > > On 14 March 2012 20:37, Croepha wrote: > >> Which is preferred: > >> > >> for value in list: > >> if not value is another_value: > >> value.do_something() > >> break > > Do you really mean 'is' or '=='? > > If you mean x is not y, write it that way. > 'not x is y' can be misread and misunderstood, depending on whether > the 'is' is true or not. > > >>> not 1 is 1 > False > >>> not (1 is 1) > False > >>> (not 1) is 1 > False > > Does not matter how read. > > >>> not (1 is 0) > True > >>> (not 1) is 0 > False > >>> not 1 is 0 > True > > Does matter how read. > > >> if list and not list[0] is another_value: > >> list[0].do_something() > > Or > try: > value = mylist[0] > if value is not another_value: value.dosomething > except IndexError: > pass > > I would not do this in this case of index 0, but if the index were a > complicated expression or expensive function call, making 'if list' an > inadequate test, I might. > > > Hard to say, since they don't do the same thing :) > > > > I suspect you meant: > > > > for value in list: > > if not value is another_value: > > value.do_something() > > break > > > > I always feel uncomfortable with this because it's misleading: a loop > > that never loops. > > I agree. Please do not do this in public ;-). > > -- > Terry Jan Reedy I'm not sure it's efficient or even if I like it, but it avoids try/except and the use of a for loop. if next( iter(mylist), object() ) is not another_value: # ... Just my 2p, Jon. From steveo at syslang.net Thu Mar 15 13:32:14 2012 From: steveo at syslang.net (Steven W. Orr) Date: Thu, 15 Mar 2012 13:32:14 -0400 Subject: Questions about the use of descriptors. Message-ID: <4F62279E.9050102@syslang.net> Question 1: I have a class A with one attribute and I define __get__ and __set__ for that class. Then I create another class B that uses it. Why does B require that the instance of A be a class variable in B and not created as an instance variable in __init__? E.g., # This works fine. class Truth(object): def __init__(self): self.is_slave = False def __get__(self, obj, objtype): return self.is_slave def __set__(self, obj, val): if not self.is_slave and val: self.is_slave = val class TruthHolder(object): IsSlave = Truth() def set_truth(self): self.IsSlave = True tt = TruthHolder() print tt.IsSlave tt.IsSlave = True print tt.IsSlave tt.IsSlave = False print tt.IsSlave But if I change TruthHolder to not start as a class variable class TruthHolder(object): def __init__(self): self.IsSlave = Truth() def set_truth(self): self.IsSlave = True it doesn't seem to use descriptor methods of Truth. It's just using the default setter and getter of TruthHolder. Question2: Is it the case that people only use descriptors for classes with single attributes? Or is it more frequent that descriptors are used with classes that have multiple attributes? I feel like this is powerful juju, but I'm not getting when I should be using property and when I should be using descriptors. General note: I see really simple examples in my searches, but I'd like to see a good practical example that has just a bit more meat on it. -- Time flies like the wind. Fruit flies like a banana. Stranger things have .0. happened but none stranger than this. Does your driver's license say Organ ..0 Donor?Black holes are where God divided by zero. Listen to me! We are all- 000 individuals! What if this weren't a hypothetical question? steveo at syslang.net From ramit.prasad at jpmorgan.com Thu Mar 15 13:34:44 2012 From: ramit.prasad at jpmorgan.com (Prasad, Ramit) Date: Thu, 15 Mar 2012 17:34:44 +0000 Subject: Context Manager getting str instead of AttributeError instance Message-ID: <5B80DD153D7D744689F57F4FB69AF474026B9264@SCACMX008.exchad.jpmchase.net> So I have a context manager used to catch errors def __exit__( self, exceptionClass, exception, tracebackObject ): if isinstance( exception, self.exceptionClasses ): #do something here Normally exception would be the exception instance, but for AttributeError it seems to be a string instead. 1) Why is AttributeError different than the other built-ins in this respect? 2) Are there other standard errors like this (I know that SystemExit is different as well)? 3) Taking into account that I want to include subclasses of classes listed in self.exceptionClasses, Is there a better check I can use? Ramit Ramit Prasad | JPMorgan Chase Investment Bank | Currencies Technology 712 Main Street | Houston, TX 77002 work phone: 713 - 216 - 5423 -- This email is confidential and subject to important disclaimers and conditions including on offers for the purchase or sale of securities, accuracy and completeness of information, viruses, confidentiality, legal privilege, and legal entity disclaimers, available at http://www.jpmorgan.com/pages/disclosures/email. From breamoreboy at yahoo.co.uk Thu Mar 15 13:41:12 2012 From: breamoreboy at yahoo.co.uk (Mark Lawrence) Date: Thu, 15 Mar 2012 17:41:12 +0000 Subject: Python is readable In-Reply-To: References: <4f612b19$0$1379$4fafbaef@reader2.news.tin.it> <8e72d74f-c844-4de3-8a37-f6b1fdc2291f@y27g2000yqy.googlegroups.com> <50e9ceec-40f1-4ead-b2b6-87328b30d084@ow8g2000pbc.googlegroups.com> <4f61c828$0$1390$4fafbaef@reader2.news.tin.it> <4f61d221$0$1375$4fafbaef@reader2.news.tin.it> <4f61d9a2$0$1377$4fafbaef@reader2.news.tin.it> <4f61f9bf$0$1381$4fafbaef@reader2.news.tin.it> Message-ID: On 15/03/2012 16:01, Alec Taylor wrote: > > C++0x? You mean C++11? :P > > On that note, is Python upgrading to use C11? :V Not for Windows given http://mail.python.org/pipermail/python-dev/2012-February/116258.html. I've no idea regarding *nix, os x or whatever. -- Cheers. Mark Lawrence. From ramit.prasad at jpmorgan.com Thu Mar 15 13:43:29 2012 From: ramit.prasad at jpmorgan.com (Prasad, Ramit) Date: Thu, 15 Mar 2012 17:43:29 +0000 Subject: Python is readable In-Reply-To: <87bonyotx2.fsf@benfinney.id.au> References: <4f612b19$0$1379$4fafbaef@reader2.news.tin.it> <8e72d74f-c844-4de3-8a37-f6b1fdc2291f@y27g2000yqy.googlegroups.com> <50e9ceec-40f1-4ead-b2b6-87328b30d084@ow8g2000pbc.googlegroups.com> <4f61c828$0$1390$4fafbaef@reader2.news.tin.it> <4f61d221$0$1375$4fafbaef@reader2.news.tin.it> <4f61d9a2$0$1377$4fafbaef@reader2.news.tin.it> <87k42moxkq.fsf@benfinney.id.au> <87fwdaovgz.fsf@benfinney.id.au> <87bonyotx2.fsf@benfinney.id.au> Message-ID: <5B80DD153D7D744689F57F4FB69AF474026B92B4@SCACMX008.exchad.jpmchase.net> > > > Hopefully, the fact that your quoting of my text munged the > > > characters down to ASCII is also pure coincidence, and is soon to be > > > corrected at your end? Or has your client program not joined the > > > rest of us in the third millennium with Unicode? Outlook showed the EN DASH but your MINUS SIGN and hyphen were the same for me. (UTF-8) Ramit Ramit Prasad | JPMorgan Chase Investment Bank | Currencies Technology 712 Main Street | Houston, TX 77002 work phone: 713 - 216 - 5423 -- This email is confidential and subject to important disclaimers and conditions including on offers for the purchase or sale of securities, accuracy and completeness of information, viruses, confidentiality, legal privilege, and legal entity disclaimers, available at http://www.jpmorgan.com/pages/disclosures/email. From jeanpierreda at gmail.com Thu Mar 15 13:51:05 2012 From: jeanpierreda at gmail.com (Devin Jeanpierre) Date: Thu, 15 Mar 2012 13:51:05 -0400 Subject: Python is readable In-Reply-To: References: <4f612b19$0$1379$4fafbaef@reader2.news.tin.it> Message-ID: On Wed, Mar 14, 2012 at 8:27 PM, Chris Angelico wrote: > On Thu, Mar 15, 2012 at 10:54 AM, Arnaud Delobelle wrote: >> I don't know this book and there may be a pedagogical reason for the >> implementation you quote, but pairwise_sum is probably better >> implemented in Python 3.X as: >> >> def pairwise_sum(list1, list2): >> ? ?return [x1 + x2 for x1, x2 in zip(list1, list2)] > > Okay, here's something for debate. > > Should the readability of a language be gauged on the basis of its > standard library, or should you be comparing actual code? "Actual code" often uses the standard library. > For instance, a quine in C can be fairly complex and messy, and it can > be unobvious what it's doing - but in HQ9+ it's easy. Is it fair to > compare on that basis, or should you actually implement the same / > equivalent code in each before judging? It's fair. But it's also fair to note that the comparison is silly, because the easiness of writing quines doesn't correspond with the easiness of doing productive things. -- Devin From k.sahithi2862 at gmail.com Thu Mar 15 13:55:43 2012 From: k.sahithi2862 at gmail.com (SAHITHI) Date: Thu, 15 Mar 2012 10:55:43 -0700 (PDT) Subject: HOT ACTRESS PHOTOS & VIDEOS Message-ID: TOP DATING TIPS TO ENCOURAGE WOMEN FOR DATING http://datingsitesdatingtips.blogspot.in/ FOR ONLY HOT GUYS SEE THIS SIDDI MAMRE HOT ROMANTIC STILLS http://hotactress-kalyani.blogspot.in/2012/02/siddhi-mamre-hot.html SHEENA SHAHABADI LATEST HOT PHOTOS http://hotactress-kalyani.blogspot.com/2012/02/sheena-shahabadi-hot.html LATEST HOT KATRINA KAIF PHOTOS http://hotactress-kalyani.blogspot.in/2011/08/katrina-kaif-hot.html ANUSHKA LATEST HOT PHOTOS http://hotactress-kalyani.blogspot.in/2011/08/anushka-hot.html KAJAL AGARWAL HOT SAREE STILLS http://hotactress-kalyani.blogspot.in/2011/11/kajal-agarwal-hot-in-saree.html PRIYAMANI HOT PHOTOS http://hotactress-kalyani.blogspot.in/2011/09/priyamani-hot.html KAJAL AGARWAL LATEST HOT WITHOUT TOP http://hotactress-kalyani.blogspot.in/2011/08/kajal-agarwal-hot-photos.html NEERU BAJWA LATEST SPICY STILLS http://hotactress-kalyani.blogspot.in/2011/12/neeru-bajwa-hot.html PRIYANKA TIWARI HOT PHOTOS http://hotactress-kalyani.blogspot.in/2011/12/priyanka-tiwari-hot.html SAMANTHA LATEST HOT STILLS http://hotactress-kalyani.blogspot.in/2011/09/samantha-hot.html DEEKSHASETH LATEST ROMANTIC STILLS http://hotactress-kalyani.blogspot.in/2011/09/deeksha-seth-hot.html PAYAL GHOSH HOT PHOTOS http://hotactress-kalyani.blogspot.in/2011/11/payal-ghosh-hot.html RAGINI DWIVEDI HOT PHOTOS http://hotactress-kalyani.blogspot.in/2011/12/ragini-dwivedi.html PARVATHI MELTON LATEST HOT PHOTOS http://hotactress-kalyani.blogspot.in/2011/11/parvathi-melton-hot.html SARAH JANE DIAS HOT PHOTOS http://hotactress-kalyani.blogspot.in/2011/11/sarah-jane-dias-hot.html TAMANNA LATEST HOT PHOTOS http://hotactress-kalyani.blogspot.in/2011/08/tamanna-hot.html PARUL HOT PHOTO STILLS http://hotactress-kalyani.blogspot.in/2011/12/parul-hot.html ADITI AGARWAL NEW ROMANTIC STILLS http://hotactress-kalyani.blogspot.in/2011/12/aditi-agarwal-hot.html POONAM KAUR HOT ROMANTIC STILLS http://hotactress-kalyani.blogspot.in/2011/11/poonam-kaur-hot.html AMISHA PATEL LATEST HOT BIKINI STILLS http://hotactress-kalyani.blogspot.in/2011/08/amisha-patel-hot.html { ALL LATEST MOVIE STILLS} KAJAL BUSINESSMAN MOVIE STILLS http://actressgallery-kalyani.blogspot.in/2012/01/kajal-agarwal-in-business-man.html SONAM KAPOOR LATEST HOT STILLS http://actressgallery-kalyani.blogspot.in/2012/01/sonam-kapoor-maxim-photoshoot-stills.html RITU KAUR LATEST PHOTO STILLS http://actressgallery-kalyani.blogspot.in/2012/01/ritu-kaur-stills.html SWAPNA SUNDARI MOVIE STILLS http://actressgallery-kalyani.blogspot.in/2012/01/swapna-sundari-movie-stills.html SEVAKUDU MOVIE STILLS http://actressgallery-kalyani.blogspot.in/2012/01/sevakudu-movie-stills.html. SRIKANTH DEVARA MOVIE GALLERY http://actressgallery-kalyani.blogspot.in/2011/12/devaraya-movie-stills.html KULLUMANALI MOVIE STILLS http://actressgallery-kalyani.blogspot.in/2011/12/kullu-manali-movie-stills.html BUSINESSMAN MOVIE STILLS http://actressgallery-kalyani.blogspot.in/2011/12/businessman-movie-stills.html HOT ACTRESS BIKINI STILLS IN 2012 CALENDAR http://actressgallery-kalyani.blogspot.in/2011/12/2012-actress-calendar-wallpapers.html KSHETHRAM MOVIE STILLS http://actressgallery-kalyani.blogspot.in/2011/12/kshethram-movie-stills.html SAMANTHA SOUTHSCOPE HOT PHOTOS http://actressgallery-kalyani.blogspot.in/2011/12/samantha-at-south-scope-magazine.html BODYGAURD LATEST MOVIE STILLS http://actressgallery-kalyani.blogspot.in/2011/12/bodyguard-telugu-movie-stills_14.html DEEPIKA PADUKONE SPICY WALLPAPERS http://actressgallery-kalyani.blogspot.in/2011/12/deepika-padukone.html KATRINA KAIF LATEST HOT WALLPAPERS http://actressgallery-kalyani.blogspot.in/2011/12/katrina-kaif-wallpapers.html NIPPU MOVIE STILLS http://actressgallery-kalyani.blogspot.in/2011/11/nippu-movie-stills.html LOVE FAILURE MOVIE STILLS http://actressgallery-kalyani.blogspot.in/2011/12/love-failure-movie-stills.html VIKRAM VEEDINTHE MOVIE STILLS http://actressgallery-kalyani.blogspot.in/2011/12/veedinthe-movie-stills.html 4FRIENDS MOVIE STILLS http://actressgallery-kalyani.blogspot.in/2011/12/4-friends-movie-stills.html NANDEESWARUDU MOVIE STILLS http://actressgallery-kalyani.blogspot.in/2011/12/nandeeswarudu-movie-stills.html HARI PRIYA HOT PHOTO STILLS http://actressgallery-kalyani.blogspot.in/2011/12/haripariya-actress.html SHRUTI HASSAN HOT IN 3 MOVIE http://actressgallery-kalyani.blogspot.in/2011/11/shruti-hassan-in-3-movie.html PANJA MOVIE LATEST STILLS http://actressgallery-kalyani.blogspot.in/2011/11/panja-movie-stills.html URIMI LATEST MOVIE STILLS http://actressgallery-kalyani.blogspot.in/2011/11/urimi-movie-stills.html ROUDRAM MOVIE STILLS http://actressgallery-kalyani.blogspot.in/2011/11/roudram-movie-stills.html SIMHAPUTHRUDU MOVIE STILLS http://actressgallery-kalyani.blogspot.in/2011/11/simhaputhrudu-movie-stills.html SOLO MOVIE STILLS http://actressgallery-kalyani.blogspot.in/2011/11/solo-movie-stills.html BEZAWADA MOVIE STILLS http://actressgallery-kalyani.blogspot.in/2011/11/bezawada-movie-stills.html RAJANNA MOVIE STILLS http://actressgallery-kalyani.blogspot.in/2011/11/rajanna-movie-stills.html\ POOLARANGADU MOVIE STILLS http://actressgallery-kalyani.blogspot.in/2011/11/poolarangadu-movie-stills.html PRIYUDU HOT ROMANTIC STILLS http://actressgallery-kalyani.blogspot.in/2011/11/priyudu-movie-stills.html ADHINAYAKUDU LATEST MOVIE STILLS http://actressgallery-kalyani.blogspot.in/2011/11/adhinayakudu-movie-stills.html HOT KATRINA KAIF PHOTOS http://actressgallery-kalyani.blogspot.in/2011/09/katrina-kaif.html AISHWARYA RAI HOT HQ PHOTO STILLS http://actressgallery-kalyani.blogspot.in/2011/09/aishwarya-rai.html ASIN HOT PHOTO GALLERY http://actressgallery-kalyani.blogspot.in/2011/09/asin.html HANSIKA MATOWNI LATEST HOT STILLS http://actressgallery-kalyani.blogspot.in/2011/09/hansika-motwani.html KAJAL AGARWAL HOT PHOTOS http://actressgallery-kalyani.blogspot.in/2011/09/kajal-agarwal.html SNEHA HOT GOA MOVIE STILLS http://actressgallery-kalyani.blogspot.in/2011/09/goa-movie-stills.html FOR FAST UPDATES IN FILM INDUSTRY KATRINA KAIF RARE PHOTOS http://allyouwants.blogspot.in/2011/12/katrina-kaif.html From ian.g.kelly at gmail.com Thu Mar 15 14:22:38 2012 From: ian.g.kelly at gmail.com (Ian Kelly) Date: Thu, 15 Mar 2012 12:22:38 -0600 Subject: Questions about the use of descriptors. In-Reply-To: <4F62279E.9050102@syslang.net> References: <4F62279E.9050102@syslang.net> Message-ID: On Thu, Mar 15, 2012 at 11:32 AM, Steven W. Orr wrote: > Question 1: > > I have a class A with one attribute and I define __get__ and __set__ for > that class. Then I create another class B that uses it. > > Why does B require that the instance of A be a class variable in B and not > created as an instance variable in __init__? Because that's the way descriptors work -- you put them on a class, and they modify the behavior of instances of that class w.r.t. the attribute they're stored in. If you store an object that implements the descriptor protocol in an instance attribute, then it is treated as ordinary data, not as a descriptor (which would often be undesirable). For example, this behavior is the reason that you can store functions in instance attributes without having them automagically turn into methods of the instance: def make_color(name): if name == 'red': return (255, 0, 0) elif name == 'green': return (0, 255, 0) elif name == 'blue': return (0, 0, 255) else: raise ValueError('Unsupported color %r' % name) class FactoryUser(object): def __init__(self, factory): self.factory = factory def show_blue(self): color = self.factory('blue') print(color) FactoryUser(make_color).show_blue() Here, if "self.factory" were treated as a descriptor, then it would become a method of the FactoryUser instance instead of just an arbitrary function, and the call "self.factory('blue')" would fail, because it would try to pass "self" in as the first argument to "make_color", which it is not expecting since it is not a member of FactoryUser. > Question2: > > Is it the case that people only use descriptors for classes with single > attributes? Or is it more frequent that descriptors are used with classes > that have multiple attributes? property is a convenient shorthand for a one-off descriptor. I use descriptor classes instead when I have a generic behavior that I want to use across multiple attributes, either on a single class or in multiple classes. As a simple, real example, I have a wxPython app with some classes for dialog windows, each of which contain one or more text controls, and I want to be able to access the contents of those text controls as attributes. I could create a whole bunch of properties, each of which does basically the same thing, or I could just use this descriptor class: class TextDescriptor(object): def __init__(self, control_name): self._control_name = control_name def __get__(self, instance, owner): if instance is not None: return getattr(instance, self._control_name).GetValue() def __set__(self, instance, value): getattr(instance, self._control_name).ChangeValue(value) Then to create the individual properties, all I have to do is this: class MyDialog(wx.Dialog): name = TextDescriptor('_name') description = TextDescriptor('_description') address = TextDescriptor('_address') def __init__(self, ...): # Build the dialog along with the _name, _description, and _address controls... Cheers, Ian From invalid at invalid.invalid Thu Mar 15 14:39:11 2012 From: invalid at invalid.invalid (Grant Edwards) Date: Thu, 15 Mar 2012 18:39:11 +0000 (UTC) Subject: Is it technically possible to give Python option of naming process of running script? References: <19118128.4791.1331736187952.JavaMail.geo-discussion-forums@vbai14> <22071354.8904.1331796412001.JavaMail.geo-discussion-forums@vbkc1> Message-ID: On 2012-03-15, Dave Angel wrote: > On 03/15/2012 03:26 AM, xliiv wrote: >>>>> Like the topic.. . >>>>> I use Python a lot, both Windows and Linux, and it's little weird to have many python process without fast distinction which is what. >>> >> >> I did google, I've played with Exemaker (it works perfect, but not py3) and i've seen questions on Stackoverflow. >> The thing I mean is a build feature of python to give such a name. Not 3rd part or etc. like Grant Edwards said. Is it possible? > > How about simply using cp to copy the python executable, run chmod +x on > it, and run that one? Then ps would list it as the new name, not as python. That's rather a waste of memory. Better to use a link. That way the executable can still be shared by multiple programs and won't be duplicated in memory. > i tried it on /usr/bin/python2.7 but I see no reason the same > approach won't work on 3.x Note, I copied it to a new name in the same > directory, which may be important. or not. Seems like an awfully obtuse way of doing things -- I don't really want to have 15 different copies of Python (or even links), and it requires root privleges every time you want to run a Python program with the "correct" name. -- Grant Edwards grant.b.edwards Yow! Can I have an IMPULSE at ITEM instead? gmail.com From __peter__ at web.de Thu Mar 15 15:01:38 2012 From: __peter__ at web.de (Peter Otten) Date: Thu, 15 Mar 2012 20:01:38 +0100 Subject: Context Manager getting str instead of AttributeError instance References: <5B80DD153D7D744689F57F4FB69AF474026B9264@SCACMX008.exchad.jpmchase.net> Message-ID: Prasad, Ramit wrote: > So I have a context manager used to catch errors > > def __exit__( self, exceptionClass, exception, tracebackObject ): > if isinstance( exception, self.exceptionClasses ): > #do something here > > Normally exception would be the exception instance, but for > AttributeError it seems to be a string instead. I don't think so: >>> class A(object): ... def __enter__(self): return self ... def __exit__(self, *args): print args ... >>> with A() as a: ... a.x ... (, AttributeError("'A' object has no attribute 'x'",), ) Traceback (most recent call last): File "", line 2, in AttributeError: 'A' object has no attribute 'x' > 1) Why is AttributeError different than the other built-ins > in this respect? > 2) Are there other standard errors like this (I know > that SystemExit is different as well)? > 3) Taking into account that I want to include subclasses of > classes listed in self.exceptionClasses, Is there a better check I can > use? From ramit.prasad at jpmorgan.com Thu Mar 15 15:10:59 2012 From: ramit.prasad at jpmorgan.com (Prasad, Ramit) Date: Thu, 15 Mar 2012 19:10:59 +0000 Subject: Context Manager getting str instead of AttributeError instance In-Reply-To: References: <5B80DD153D7D744689F57F4FB69AF474026B9264@SCACMX008.exchad.jpmchase.net> Message-ID: <5B80DD153D7D744689F57F4FB69AF474026B9625@SCACMX008.exchad.jpmchase.net> > Prasad, Ramit wrote: > > > So I have a context manager used to catch errors > > > > def __exit__( self, exceptionClass, exception, tracebackObject ): > > if isinstance( exception, self.exceptionClasses ): > > #do something here > > > > Normally exception would be the exception instance, but for > > AttributeError it seems to be a string instead. > > I don't think so: > > >>> class A(object): > ... def __enter__(self): return self > ... def __exit__(self, *args): print args > ... > >>> with A() as a: > ... a.x > ... > (, AttributeError("'A' object has no > attribute 'x'",), ) > Traceback (most recent call last): > File "", line 2, in > AttributeError: 'A' object has no attribute 'x' > > > 1) Why is AttributeError different than the other built-ins > > in this respect? > > 2) Are there other standard errors like this (I know > > that SystemExit is different as well)? > > 3) Taking into account that I want to include subclasses of > > classes listed in self.exceptionClasses, Is there a better check I can > > use? Not sure why mine behaves differently: Python 2.6.6 (r266:84292, Dec 17 2010, 12:36:53) [MSC v.1500 32 bit (Intel)] on win32 >>> >>> class A(object): ... def __enter__(self): return self ... def __exit__(self, *args): print args ... >>> with A() as a: ... a.x ... (, "'A' object has no attribute 'x'", ) AttributeError: 'A' object has no attribute 'x' As you can see, I am getting a string while you are not. Ramit Ramit Prasad | JPMorgan Chase Investment Bank | Currencies Technology 712 Main Street | Houston, TX 77002 work phone: 713 - 216 - 5423 -- This email is confidential and subject to important disclaimers and conditions including on offers for the purchase or sale of securities, accuracy and completeness of information, viruses, confidentiality, legal privilege, and legal entity disclaimers, available at http://www.jpmorgan.com/pages/disclosures/email. From kiuhnm03.4t.yahoo.it Thu Mar 15 15:40:52 2012 From: kiuhnm03.4t.yahoo.it (Kiuhnm) Date: Thu, 15 Mar 2012 20:40:52 +0100 Subject: Python is readable In-Reply-To: References: <4f612b19$0$1379$4fafbaef@reader2.news.tin.it> <8e72d74f-c844-4de3-8a37-f6b1fdc2291f@y27g2000yqy.googlegroups.com> <50e9ceec-40f1-4ead-b2b6-87328b30d084@ow8g2000pbc.googlegroups.com> <4f61c828$0$1390$4fafbaef@reader2.news.tin.it> <4f61d728$0$1375$4fafbaef@reader2.news.tin.it> <4f61fa8a$0$1381$4fafbaef@reader2.news.tin.it> <4f6202cb$0$1377$4fafbaef@reader2.news.tin.it> Message-ID: <4f6245c5$0$1384$4fafbaef@reader2.news.tin.it> On 3/15/2012 16:08, Chris Angelico wrote: > On Fri, Mar 16, 2012 at 1:55 AM, Kiuhnm > wrote: >> By the way, the more elaborate parsing consists of looking for an >> END_OF_LINE followed by one or more spaces. It doesn't sound that >> complicated. > > Only in the trivial case. What if you want to break your condition > over multiple lines? (Although you have to parenthesize or backslash, > so that's still unambig.) It's helpful to be explicit. You said it yourself. Just look out for parentheses or backslashes. C and C++ editors do that all the time with single-statement control-flow constructs. >> And what about an editor which indent when you press the spacebar or tab? > > Sure, but a good editor helps out by noticing that you did something > that begs for indentation. If I put an open brace, SciTE will indent - > very simple rule. What about braces in strings? There's always some parsing going on and since you probably want syntax highlighting and maybe code autocompletion, what's the problem with missing colons? Moreover, I think that if (............ ............ ............): ............ ............ ............ is not very readable anyway. Kiuhnm From storchaka at gmail.com Thu Mar 15 15:43:46 2012 From: storchaka at gmail.com (Serhiy Storchaka) Date: Thu, 15 Mar 2012 21:43:46 +0200 Subject: Python is readable In-Reply-To: <4f61fa8a$0$1381$4fafbaef@reader2.news.tin.it> References: <4f612b19$0$1379$4fafbaef@reader2.news.tin.it> <8e72d74f-c844-4de3-8a37-f6b1fdc2291f@y27g2000yqy.googlegroups.com> <50e9ceec-40f1-4ead-b2b6-87328b30d084@ow8g2000pbc.googlegroups.com> <4f61c828$0$1390$4fafbaef@reader2.news.tin.it> <4f61d728$0$1375$4fafbaef@reader2.news.tin.it> <4f61fa8a$0$1381$4fafbaef@reader2.news.tin.it> Message-ID: 15.03.12 16:19, Kiuhnm ???????(??): > Ok, so they're mandatory, but I was mainly talking of design. Why are they needed? http://python-history.blogspot.com/2011/07/karin-dewar-indentation-and-colon.html From ian.g.kelly at gmail.com Thu Mar 15 15:49:02 2012 From: ian.g.kelly at gmail.com (Ian Kelly) Date: Thu, 15 Mar 2012 13:49:02 -0600 Subject: Context Manager getting str instead of AttributeError instance In-Reply-To: <5B80DD153D7D744689F57F4FB69AF474026B9625@SCACMX008.exchad.jpmchase.net> References: <5B80DD153D7D744689F57F4FB69AF474026B9264@SCACMX008.exchad.jpmchase.net> <5B80DD153D7D744689F57F4FB69AF474026B9625@SCACMX008.exchad.jpmchase.net> Message-ID: On Thu, Mar 15, 2012 at 1:10 PM, Prasad, Ramit wrote: >> Prasad, Ramit wrote: >> >> > So I have a context manager used to catch errors >> > >> > def __exit__( self, exceptionClass, exception, tracebackObject ): >> > ? ? if isinstance( exception, self.exceptionClasses ): >> > ? ? ? ? ?#do something here >> > >> > Normally exception would be the exception instance, but for >> > AttributeError it seems to be a string instead. >> >> I don't think so: >> >> >>> class A(object): >> ... ? ? def __enter__(self): return self >> ... ? ? def __exit__(self, *args): print args >> ... >> >>> with A() as a: >> ... ? ? a.x >> ... >> (, AttributeError("'A' object has no >> attribute 'x'",), ) >> Traceback (most recent call last): >> ? File "", line 2, in >> AttributeError: 'A' object has no attribute 'x' >> >> > 1) Why is AttributeError different than the other built-ins >> > in this respect? >> > 2) Are there other standard errors like this (I know >> > that SystemExit is different as well)? >> > 3) Taking into account that I want to include subclasses of >> > classes listed in self.exceptionClasses, Is there a better check I can >> > use? > > Not sure why mine behaves differently: > Python 2.6.6 (r266:84292, Dec 17 2010, 12:36:53) [MSC v.1500 32 bit (Intel)] on win32 >>>> >>>> class A(object): > ... ? ? def __enter__(self): return self > ... ? ? def __exit__(self, *args): print args > ... >>>> with A() as a: > ... ? ? a.x > ... > (, "'A' object has no attribute 'x'", ) > AttributeError: 'A' object has no attribute 'x' > > As you can see, I am getting a string while you are not. Looks like a version difference. I don't have Python 2.6 handy to test on, but I get a str in Python 2.5 and an AttributeError instance in Python 2.7. From ramit.prasad at jpmorgan.com Thu Mar 15 16:25:46 2012 From: ramit.prasad at jpmorgan.com (Prasad, Ramit) Date: Thu, 15 Mar 2012 20:25:46 +0000 Subject: Context Manager getting str instead of AttributeError instance In-Reply-To: References: <5B80DD153D7D744689F57F4FB69AF474026B9264@SCACMX008.exchad.jpmchase.net> <5B80DD153D7D744689F57F4FB69AF474026B9625@SCACMX008.exchad.jpmchase.net> Message-ID: <5B80DD153D7D744689F57F4FB69AF474026B9706@SCACMX008.exchad.jpmchase.net> > > ... > > (, "'A' object has no attribute 'x'", > ) > > AttributeError: 'A' object has no attribute 'x' > > > > As you can see, I am getting a string while you are not. > >Ian Kelly said: > Looks like a version difference. I don't have Python 2.6 handy to > test on, but I get a str in Python 2.5 and an AttributeError instance > in Python 2.7. Thanks Ian, that was the key! I guess I will just have to work around it. Any suggestions? I am thinking about just creating a blank instance of the error class since that the class gets passed successfully. Ramit Ramit Prasad | JPMorgan Chase Investment Bank | Currencies Technology 712 Main Street | Houston, TX 77002 work phone: 713 - 216 - 5423 -- This email is confidential and subject to important disclaimers and conditions including on offers for the purchase or sale of securities, accuracy and completeness of information, viruses, confidentiality, legal privilege, and legal entity disclaimers, available at http://www.jpmorgan.com/pages/disclosures/email. From ian.g.kelly at gmail.com Thu Mar 15 16:33:46 2012 From: ian.g.kelly at gmail.com (Ian Kelly) Date: Thu, 15 Mar 2012 14:33:46 -0600 Subject: Context Manager getting str instead of AttributeError instance In-Reply-To: <5B80DD153D7D744689F57F4FB69AF474026B9706@SCACMX008.exchad.jpmchase.net> References: <5B80DD153D7D744689F57F4FB69AF474026B9264@SCACMX008.exchad.jpmchase.net> <5B80DD153D7D744689F57F4FB69AF474026B9625@SCACMX008.exchad.jpmchase.net> <5B80DD153D7D744689F57F4FB69AF474026B9706@SCACMX008.exchad.jpmchase.net> Message-ID: On Thu, Mar 15, 2012 at 2:25 PM, Prasad, Ramit wrote: >> > ... >> > (, "'A' object has no attribute 'x'", >> ) >> > AttributeError: 'A' object has no attribute 'x' >> > >> > As you can see, I am getting a string while you are not. >> >>Ian Kelly said: >> Looks like a version difference. ?I don't have Python 2.6 handy to >> test on, but I get a str in Python 2.5 and an AttributeError instance >> in Python 2.7. > > Thanks Ian, that was the key! I guess I will just have to work around it. > Any suggestions? I am thinking about just creating a blank instance of > the error class since that the class gets passed successfully. Well, for what you want to do, I don't think you need an instance at all -- just use issubclass instead of isinstance: def __exit__( self, exceptionClass, exception, tracebackObject ): if issubclass( exceptionClass, self.exceptionClasses ): #do something here Cheers, Ian From __peter__ at web.de Thu Mar 15 16:38:22 2012 From: __peter__ at web.de (Peter Otten) Date: Thu, 15 Mar 2012 21:38:22 +0100 Subject: Context Manager getting str instead of AttributeError instance References: <5B80DD153D7D744689F57F4FB69AF474026B9264@SCACMX008.exchad.jpmchase.net> <5B80DD153D7D744689F57F4FB69AF474026B9625@SCACMX008.exchad.jpmchase.net> Message-ID: Prasad, Ramit wrote: >> Prasad, Ramit wrote: >> >> > So I have a context manager used to catch errors >> > >> > def __exit__( self, exceptionClass, exception, tracebackObject ): >> > if isinstance( exception, self.exceptionClasses ): >> > #do something here >> > >> > Normally exception would be the exception instance, but for >> > AttributeError it seems to be a string instead. >> >> I don't think so: >> >> >>> class A(object): >> ... def __enter__(self): return self >> ... def __exit__(self, *args): print args >> ... >> >>> with A() as a: >> ... a.x >> ... >> (, AttributeError("'A' object has no >> attribute 'x'",), ) >> Traceback (most recent call last): >> File "", line 2, in >> AttributeError: 'A' object has no attribute 'x' >> >> > 1) Why is AttributeError different than the other built-ins >> > in this respect? >> > 2) Are there other standard errors like this (I know >> > that SystemExit is different as well)? >> > 3) Taking into account that I want to include subclasses of >> > classes listed in self.exceptionClasses, Is there a better check I can >> > use? > > Not sure why mine behaves differently: > Python 2.6.6 (r266:84292, Dec 17 2010, 12:36:53) [MSC v.1500 32 bit > (Intel)] on win32 >>>> >>>> class A(object): > ... def __enter__(self): return self > ... def __exit__(self, *args): print args > ... >>>> with A() as a: > ... a.x > ... > (, "'A' object has no attribute 'x'", > ) AttributeError: 'A' object has no > attribute 'x' > > As you can see, I am getting a string while you are not. Ah, it's a bug: http://bugs.python.org/issue7853 Unfortunately it is to severe to fix in a bugfix release. You could work around it with an issubclass() test on the first argument. From arnodel at gmail.com Thu Mar 15 16:54:30 2012 From: arnodel at gmail.com (Arnaud Delobelle) Date: Thu, 15 Mar 2012 20:54:30 +0000 Subject: Python is readable In-Reply-To: References: <4f612b19$0$1379$4fafbaef@reader2.news.tin.it> Message-ID: On 15 March 2012 00:27, Chris Angelico wrote: > On Thu, Mar 15, 2012 at 10:54 AM, Arnaud Delobelle wrote: >> I don't know this book and there may be a pedagogical reason for the >> implementation you quote, but pairwise_sum is probably better >> implemented in Python 3.X as: >> >> def pairwise_sum(list1, list2): >> ? ?return [x1 + x2 for x1, x2 in zip(list1, list2)] > > Okay, here's something for debate. > > Should the readability of a language be gauged on the basis of its > standard library, or should you be comparing actual code? But here's the code posted by the OP: --- Python --- def pairwise_sum(list1, list2): result = [] for i in range(len(list1)): result.append(list1[i] + list2[i]) return result --- --- The code I posted uses one builtin function (zip), the code posted by the OP uses two (range and len). Neither uses the standard library. -- Arnaud From cs at zip.com.au Thu Mar 15 17:18:57 2012 From: cs at zip.com.au (Cameron Simpson) Date: Fri, 16 Mar 2012 08:18:57 +1100 Subject: Enchancement suggestion for argparse: intuit type from default In-Reply-To: References: Message-ID: <20120315211857.GA31617@cskk.homeip.net> On 15Mar2012 09:28, Roy Smith wrote: | In article , | Robert Kern wrote: | > Yes. Not all type(default) types can be called with a string to produce a | > valid | > value. Note that "type=" is really a misnomer. argparse doesn't really want a | > type object there; it wants a converter function that takes a string to an | > object. | | Orthogonal to my original suggestion, I agree that this is misnamed. | I'm +1 on the idea of renaming it to conversion= or something like that | (we'd need to keep type= around as a deprecated synonym for backwards | compatability). It's really hard to get your head around "type=open". "factory"? Anyway, far too late to change this now! -- Cameron Simpson DoD#743 http://www.cskk.ezoshosting.com/cs/ all coders are created equal; that they are endowed with certain unalienable rights, of these are beer, net connectivity, and the pursuit of bugfixes... - Gregory R Block From cs at zip.com.au Thu Mar 15 17:42:24 2012 From: cs at zip.com.au (Cameron Simpson) Date: Fri, 16 Mar 2012 08:42:24 +1100 Subject: Is there a ConfigParser which keeps comments In-Reply-To: <4F60DFB8.8080703@tim.thechases.com> References: <4F60DFB8.8080703@tim.thechases.com> Message-ID: <20120315214224.GA3390@cskk.homeip.net> On 14Mar2012 13:13, Tim Chase wrote: | On 03/14/12 12:06, Terry Reedy wrote: | > On 3/14/2012 6:07 AM, Gelonida N wrote: | >> Now I'm looking for a library, which behaves like config parser, but | >> with one minor difference. | >> | >> The write() mehtod should keep existing comments. | > | > Assuming that you have not overlooked anything, I would just subclass | > ConfigParser with an altered write method. | | It would require a lot more than that. It would entail changing | the reading as well so that it preserved the comments as well as | the order of sections & keys, and a way of storing those | associated comments in sequence. I looked into it a fair while | back and it was a LOT more work than I cared to do for minimal | gain. I wimped out and just documented it with "If you use the | ability to (re)write a configuration file, it will not keep any | comments or ordering from any original sources." A low cost approach might be to patch the file instead of transcribing the in-memory state. Not the same semantics, but it would not be too hard to add a patch_config(filename, section, setting, value) that read the old file and wrote a new one with an adjusted section, ignoring the in-memory state (indeed, on that basis the siganture isn't a method but a standalone function). The logic is easy enough that I even wrote a shell script in 2004 to do essentially this: https://bitbucket.org/cameron_simpson/css/src/ef42896872b5/bin/winclauseappend One could imagine an efficient python implementation and a ConfigParser subclass that patched the file if a setting got changed, or had a .patch method to apply particular setting changes as desired. Cheers, -- Cameron Simpson DoD#743 http://www.cskk.ezoshosting.com/cs/ From sci.physics: tron at mailzone.com: The only problem is, how do you send a message from Earth to Mars instantly? Does anyone have any ideas about where we can start? John Baez References: <4F615880.6080005@syslang.net> Message-ID: <4F626405.7040609@gmail.com> Le 15/03/2012 03:48, Steven W. Orr a ?crit : > On 3/14/2012 6:07 AM, Gelonida N wrote: >> Hi, >> >> >> At the moment I use ConfigParser >> http://docs.python.org/library/configparser.html >> for one of my applications. >> >> >> Now I'm looking for a library, which behaves like config parser, but >> with one minor difference. >> >> The write() mehtod should keep existing comments. >> >> Does anybody know or implement something like this or is there as >> switrch, that I overlooked in hte documentaiton. >> >> > > I use ConfigObj. > Sure configObj is a must...I use it too. http://www.voidspace.org.uk/python/configobj.html Cheers Karim From torriem at gmail.com Thu Mar 15 18:12:28 2012 From: torriem at gmail.com (Michael Torrie) Date: Thu, 15 Mar 2012 16:12:28 -0600 Subject: Python is readable In-Reply-To: <4f6245c5$0$1384$4fafbaef@reader2.news.tin.it> References: <4f612b19$0$1379$4fafbaef@reader2.news.tin.it> <8e72d74f-c844-4de3-8a37-f6b1fdc2291f@y27g2000yqy.googlegroups.com> <50e9ceec-40f1-4ead-b2b6-87328b30d084@ow8g2000pbc.googlegroups.com> <4f61c828$0$1390$4fafbaef@reader2.news.tin.it> <4f61d728$0$1375$4fafbaef@reader2.news.tin.it> <4f61fa8a$0$1381$4fafbaef@reader2.news.tin.it> <4f6202cb$0$1377$4fafbaef@reader2.news.tin.it> <4f6245c5$0$1384$4fafbaef@reader2.news.tin.it> Message-ID: <4F62694C.30007@gmail.com> On 03/15/2012 01:40 PM, Kiuhnm wrote: > Moreover, I think that > if (............ > ............ > ............): > ............ > ............ > ............ > is not very readable anyway. Sure but neither is if (............ \ ............ \ ............) ............ ............ ............ In other words, with or without the : if you format your if statements in an unreadable way, it will be unreadable. Nothing to do with python's syntax at all. Now, if ............ ............ ............: ............ ............ ............ isn't too bad for readability. In other words the C-ism of putting the IF predicate in parenthesis normally doesn't belong in python, though there are cases when you need to enforce a certain operator precedence, granted. From torriem at gmail.com Thu Mar 15 18:17:36 2012 From: torriem at gmail.com (Michael Torrie) Date: Thu, 15 Mar 2012 16:17:36 -0600 Subject: Python is readable In-Reply-To: <4f620837$0$1382$4fafbaef@reader2.news.tin.it> References: <4f612b19$0$1379$4fafbaef@reader2.news.tin.it> <8e72d74f-c844-4de3-8a37-f6b1fdc2291f@y27g2000yqy.googlegroups.com> <50e9ceec-40f1-4ead-b2b6-87328b30d084@ow8g2000pbc.googlegroups.com> <4f61c828$0$1390$4fafbaef@reader2.news.tin.it> <4f61d728$0$1375$4fafbaef@reader2.news.tin.it> <4f61fd0a$0$1389$4fafbaef@reader2.news.tin.it> <4f620837$0$1382$4fafbaef@reader2.news.tin.it> Message-ID: <4F626A80.7080607@gmail.com> On 03/15/2012 09:18 AM, Kiuhnm wrote: > ----> After early user testing without the colon, it was discovered that > the meaning of the indentation was unclear to beginners being taught the > first steps of programming. <---- > > The addition of the colon clarified it significantly: the colon somehow > draws attention to what follows and ties the phrases before and after it > together in just the right way." > > If that passage is correct, those studies don't say that adding the > colon increases the readability, but that it makes more sense to > beginners who don't even know what indentation is. Seems to me that helping code to make more sense to a beginner is, by definition, increasing readability. From ben+python at benfinney.id.au Thu Mar 15 18:35:53 2012 From: ben+python at benfinney.id.au (Ben Finney) Date: Fri, 16 Mar 2012 09:35:53 +1100 Subject: Python is readable References: <4f612b19$0$1379$4fafbaef@reader2.news.tin.it> <8e72d74f-c844-4de3-8a37-f6b1fdc2291f@y27g2000yqy.googlegroups.com> <50e9ceec-40f1-4ead-b2b6-87328b30d084@ow8g2000pbc.googlegroups.com> <4f61c828$0$1390$4fafbaef@reader2.news.tin.it> <4f61d728$0$1375$4fafbaef@reader2.news.tin.it> <4f61fa8a$0$1381$4fafbaef@reader2.news.tin.it> <4f6202cb$0$1377$4fafbaef@reader2.news.tin.it> <4f6245c5$0$1384$4fafbaef@reader2.news.tin.it> Message-ID: <873999pk52.fsf@benfinney.id.au> Kiuhnm writes: > Moreover, I think that > if (............ > ............ > ............): > ............ > ............ > ............ > is not very readable anyway. I agree, and am glad PEP 8 has been updated to recommend an extra level of indentation for continuation, to distinguish from the new block that follows . -- \ ?From the moment I picked your book up until I laid it down I | `\ was convulsed with laughter. Someday I intend reading it.? | _o__) ?Groucho Marx | Ben Finney From arnodel at gmail.com Thu Mar 15 19:00:23 2012 From: arnodel at gmail.com (Arnaud Delobelle) Date: Thu, 15 Mar 2012 23:00:23 +0000 Subject: Python is readable In-Reply-To: <873999pk52.fsf@benfinney.id.au> References: <4f612b19$0$1379$4fafbaef@reader2.news.tin.it> <8e72d74f-c844-4de3-8a37-f6b1fdc2291f@y27g2000yqy.googlegroups.com> <50e9ceec-40f1-4ead-b2b6-87328b30d084@ow8g2000pbc.googlegroups.com> <4f61c828$0$1390$4fafbaef@reader2.news.tin.it> <4f61d728$0$1375$4fafbaef@reader2.news.tin.it> <4f61fa8a$0$1381$4fafbaef@reader2.news.tin.it> <4f6202cb$0$1377$4fafbaef@reader2.news.tin.it> <4f6245c5$0$1384$4fafbaef@reader2.news.tin.it> <873999pk52.fsf@benfinney.id.au> Message-ID: On 15 March 2012 22:35, Ben Finney wrote: > Kiuhnm writes: > >> Moreover, I think that >> ? if (............ >> ? ? ? ............ >> ? ? ? ............): >> ? ? ? ............ >> ? ? ? ............ >> ? ? ? ............ >> is not very readable anyway. > > I agree, and am glad PEP 8 has been updated to recommend an extra level > of indentation for continuation, to distinguish from the new block that > follows . Personally I solve this by never writing if conditions that span more than one line. If the worst comes to the worst, I would write: aptly_named_condition = ( very long condition that goes over plenty of lines ) if aptly_named_condition: do stuff -- Arnaud From kiuhnm03.4t.yahoo.it Thu Mar 15 19:32:52 2012 From: kiuhnm03.4t.yahoo.it (Kiuhnm) Date: Fri, 16 Mar 2012 00:32:52 +0100 Subject: Python is readable In-Reply-To: References: <4f612b19$0$1379$4fafbaef@reader2.news.tin.it> <8e72d74f-c844-4de3-8a37-f6b1fdc2291f@y27g2000yqy.googlegroups.com> <50e9ceec-40f1-4ead-b2b6-87328b30d084@ow8g2000pbc.googlegroups.com> <4f61c828$0$1390$4fafbaef@reader2.news.tin.it> <4f61d728$0$1375$4fafbaef@reader2.news.tin.it> <4f61fd0a$0$1389$4fafbaef@reader2.news.tin.it> <4f620837$0$1382$4fafbaef@reader2.news.tin.it> Message-ID: <4f627c25$0$1381$4fafbaef@reader2.news.tin.it> On 3/15/2012 23:17, Michael Torrie wrote: > On 03/15/2012 09:18 AM, Kiuhnm wrote: >> ----> After early user testing without the colon, it was discovered that >> the meaning of the indentation was unclear to beginners being taught the >> first steps of programming.<---- >> >> The addition of the colon clarified it significantly: the colon somehow >> draws attention to what follows and ties the phrases before and after it >> together in just the right way." >> >> If that passage is correct, those studies don't say that adding the >> colon increases the readability, but that it makes more sense to >> beginners who don't even know what indentation is. > > Seems to me that helping code to make more sense to a beginner is, by > definition, increasing readability. Pick up two math books about the same topic but on two different levels (e.g. under-graduated and graduated). If you compare the proofs you'll see that those in the higher-level book are almost always sketched. Why is that? Because they're more readable for a mature reader. But they're almost incomprehensible to a beginner. As another example, why do people use jargon? Because that makes communication more efficient. And yet that frustrate beginners. So, no, I can't agree with you. There are too many situations where a steep learning curve pays off in the long run. Making that curve too shallow may help beginners but damage experienced users. Is functional programming code more readable than imperative code? Ask a beginner and you'll receive a resounding "no". Ask an experienced coder and he will probably say "it depends". If he says "yes, always" he is a just a lisp fanatic :) Kiuhnm From kiuhnm03.4t.yahoo.it Thu Mar 15 19:46:35 2012 From: kiuhnm03.4t.yahoo.it (Kiuhnm) Date: Fri, 16 Mar 2012 00:46:35 +0100 Subject: Python is readable In-Reply-To: References: <4f612b19$0$1379$4fafbaef@reader2.news.tin.it> <8e72d74f-c844-4de3-8a37-f6b1fdc2291f@y27g2000yqy.googlegroups.com> <50e9ceec-40f1-4ead-b2b6-87328b30d084@ow8g2000pbc.googlegroups.com> <4f61c828$0$1390$4fafbaef@reader2.news.tin.it> <4f61d728$0$1375$4fafbaef@reader2.news.tin.it> <4f61fa8a$0$1381$4fafbaef@reader2.news.tin.it> <4f6202cb$0$1377$4fafbaef@reader2.news.tin.it> <4f6245c5$0$1384$4fafbaef@reader2.news.tin.it> <873999pk52.fsf@benfinney.id.au> Message-ID: <4f627f5c$0$1389$4fafbaef@reader2.news.tin.it> On 3/16/2012 0:00, Arnaud Delobelle wrote: > On 15 March 2012 22:35, Ben Finney wrote: >> Kiuhnm writes: >> >>> Moreover, I think that >>> if (............ >>> ............ >>> ............): >>> ............ >>> ............ >>> ............ >>> is not very readable anyway. >> >> I agree, and am glad PEP 8 has been updated to recommend an extra level >> of indentation for continuation, to distinguish from the new block that >> follows. > > Personally I solve this by never writing if conditions that span more > than one line. If the worst comes to the worst, I would write: > > aptly_named_condition = ( > very long condition > that goes over > plenty of lines > ) > if aptly_named_condition: > do stuff Will I be able to use extra indentation in Python code? For instance, res = and(or(cond1, cond2), cond3, or(and(cond4, cond5, cond6), and(cond7, cond8))) I like it because it reads like a tree. Kiuhnm From steve+comp.lang.python at pearwood.info Thu Mar 15 19:52:01 2012 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 15 Mar 2012 23:52:01 GMT Subject: Python is readable References: <4f612b19$0$1379$4fafbaef@reader2.news.tin.it> <8e72d74f-c844-4de3-8a37-f6b1fdc2291f@y27g2000yqy.googlegroups.com> <50e9ceec-40f1-4ead-b2b6-87328b30d084@ow8g2000pbc.googlegroups.com> <4f61c828$0$1390$4fafbaef@reader2.news.tin.it> <4f61d728$0$1375$4fafbaef@reader2.news.tin.it> <4f61fd0a$0$1389$4fafbaef@reader2.news.tin.it> Message-ID: <4f6280a0$0$29981$c3e8da3$5496439d@news.astraweb.com> On Fri, 16 Mar 2012 01:48:09 +1100, Chris Angelico wrote: > On Fri, Mar 16, 2012 at 1:30 AM, Kiuhnm > wrote: >> Sorry, but I can't see how it would make it harder for humans to >> understand. Are there particular situations you're referring to? > > In a trivial example, it's mostly just noise: > > if a == b # who needs the colon? > print(c) The reader, for the same reason that above you wrote: "In a trivial example, it's mostly just noise COLON" and indeed I too used a colon for the same reason. It ties the lead sentence to the following block without ending the sentence, but still introducing a new grouping or clause. It is *remarkable* how people take the colon for granted. It is so simple and so obvious that they use it in their own writing often without thinking about it, but because it is not strictly necessary to avoid ambiguity in the grammar, they fool themselves into thinking that it is "just noise" or "pointless". It is not noise, it is a hint to the reader. Again, applying to both computer languages and natural languages, leaving out punctuation (either in the grammar, or just out of laziness) is doing a great disservice to the reader. The time the writer saves by not inserting punctuation is lost a million times for the reader (we read text and code thousands of times more than we write it, and there are thousands more readers than writers). Leaving out punctuation is a real pessimation: an example of being "penny wise and pound foolish". -- Steven From ben+python at benfinney.id.au Thu Mar 15 19:57:33 2012 From: ben+python at benfinney.id.au (Ben Finney) Date: Fri, 16 Mar 2012 10:57:33 +1100 Subject: Python is readable References: <4f612b19$0$1379$4fafbaef@reader2.news.tin.it> <8e72d74f-c844-4de3-8a37-f6b1fdc2291f@y27g2000yqy.googlegroups.com> <50e9ceec-40f1-4ead-b2b6-87328b30d084@ow8g2000pbc.googlegroups.com> <4f61c828$0$1390$4fafbaef@reader2.news.tin.it> <4f61d728$0$1375$4fafbaef@reader2.news.tin.it> <4f61fa8a$0$1381$4fafbaef@reader2.news.tin.it> <4f6202cb$0$1377$4fafbaef@reader2.news.tin.it> <4f6245c5$0$1384$4fafbaef@reader2.news.tin.it> <873999pk52.fsf@benfinney.id.au> Message-ID: <87mx7ho1si.fsf@benfinney.id.au> Arnaud Delobelle writes: > On 15 March 2012 22:35, Ben Finney wrote: > > I agree, and am glad PEP 8 has been updated to recommend an extra > > level of indentation for continuation, to distinguish from the new > > block that follows > > . > > Personally I solve this by never writing if conditions that span more > than one line. The admonition applies not only to ?if? conditions, but also to ?while?, ?with?, ?for?, etc.; and also to bracketing constructs like function calls, literal lists/dicts/sets, etc. In a single statement, the indentation for continuation lines should be indented two levels, so that they don't look so much like a new block of statements. -- \ ?If you do not trust the source do not use this program.? | `\ ?Microsoft Vista security dialogue | _o__) | Ben Finney From breamoreboy at yahoo.co.uk Thu Mar 15 19:58:08 2012 From: breamoreboy at yahoo.co.uk (Mark Lawrence) Date: Thu, 15 Mar 2012 23:58:08 +0000 Subject: Python is readable In-Reply-To: <4f627f5c$0$1389$4fafbaef@reader2.news.tin.it> References: <4f612b19$0$1379$4fafbaef@reader2.news.tin.it> <8e72d74f-c844-4de3-8a37-f6b1fdc2291f@y27g2000yqy.googlegroups.com> <50e9ceec-40f1-4ead-b2b6-87328b30d084@ow8g2000pbc.googlegroups.com> <4f61c828$0$1390$4fafbaef@reader2.news.tin.it> <4f61d728$0$1375$4fafbaef@reader2.news.tin.it> <4f61fa8a$0$1381$4fafbaef@reader2.news.tin.it> <4f6202cb$0$1377$4fafbaef@reader2.news.tin.it> <4f6245c5$0$1384$4fafbaef@reader2.news.tin.it> <873999pk52.fsf@benfinney.id.au> <4f627f5c$0$1389$4fafbaef@reader2.news.tin.it> Message-ID: On 15/03/2012 23:46, Kiuhnm wrote: > On 3/16/2012 0:00, Arnaud Delobelle wrote: >> On 15 March 2012 22:35, Ben Finney wrote: >>> Kiuhnm writes: >>> >>>> Moreover, I think that >>>> if (............ >>>> ............ >>>> ............): >>>> ............ >>>> ............ >>>> ............ >>>> is not very readable anyway. >>> >>> I agree, and am glad PEP 8 has been updated to recommend an extra level >>> of indentation for continuation, to distinguish from the new block that >>> follows. >> >> Personally I solve this by never writing if conditions that span more >> than one line. If the worst comes to the worst, I would write: >> >> aptly_named_condition = ( >> very long condition >> that goes over >> plenty of lines >> ) >> if aptly_named_condition: >> do stuff > > Will I be able to use extra indentation in Python code? > For instance, > > res = and(or(cond1, > cond2), > cond3, > or(and(cond4, > cond5, > cond6), > and(cond7, > cond8))) > > I like it because it reads like a tree. > > Kiuhnm Why not find out for yourself by slapping the code into an interactive Python interpreter and seeing what the result is? -- Cheers. Mark Lawrence. From steve+comp.lang.python at pearwood.info Thu Mar 15 20:15:14 2012 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 16 Mar 2012 00:15:14 GMT Subject: Python is readable References: <4f612b19$0$1379$4fafbaef@reader2.news.tin.it> <8e72d74f-c844-4de3-8a37-f6b1fdc2291f@y27g2000yqy.googlegroups.com> <50e9ceec-40f1-4ead-b2b6-87328b30d084@ow8g2000pbc.googlegroups.com> <4f61c828$0$1390$4fafbaef@reader2.news.tin.it> <4f61d728$0$1375$4fafbaef@reader2.news.tin.it> <4f61fa8a$0$1381$4fafbaef@reader2.news.tin.it> <4f6202cb$0$1377$4fafbaef@reader2.news.tin.it> <4f6245c5$0$1384$4fafbaef@reader2.news.tin.it> <873999pk52.fsf@benfinney.id.au> <4f627f5c$0$1389$4fafbaef@reader2.news.tin.it> Message-ID: <4f628611$0$29981$c3e8da3$5496439d@news.astraweb.com> On Fri, 16 Mar 2012 00:46:35 +0100, Kiuhnm wrote: > On 3/16/2012 0:00, Arnaud Delobelle wrote: >> On 15 March 2012 22:35, Ben Finney wrote: >>> Kiuhnm writes: >>> >>>> Moreover, I think that >>>> if (............ >>>> ............ >>>> ............): >>>> ............ >>>> ............ >>>> ............ >>>> is not very readable anyway. >>> >>> I agree, and am glad PEP 8 has been updated to recommend an extra >>> level of indentation for continuation, to distinguish from the new >>> block that >>> follows. >> >> Personally I solve this by never writing if conditions that span more >> than one line. If the worst comes to the worst, I would write: >> >> aptly_named_condition = ( >> very long condition >> that goes over >> plenty of lines >> ) >> if aptly_named_condition: >> do stuff > > Will I be able to use extra indentation in Python code? For instance, > > res = and(or(cond1, > cond2), > cond3, > or(and(cond4, > cond5, > cond6), > and(cond7, > cond8))) Not that exact example, because `and` and `or` are operators, not functions and you will get a syntax error. Python uses infix notation, not prefix or postfix: x and y # yes and(x, y) # no x y and # no But in general, yes, you can use whatever indentation you like inside a line-continuation bracket: py> x = [ ... 1, 2, 3, ... 4, 5, 6, ... 7, 8, 9, ... 10, 11, 12, ... 13, 14, 15 ... ] py> x [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15] Indentation is only syntactically significant in blocks and statements. > I like it because it reads like a tree. Funny. I dislike it because it is a tree on its side. -- Steven From gelonida at gmail.com Thu Mar 15 20:34:44 2012 From: gelonida at gmail.com (Gelonida N) Date: Fri, 16 Mar 2012 01:34:44 +0100 Subject: Is there a ConfigParser which keeps comments In-Reply-To: <20120315214224.GA3390@cskk.homeip.net> References: <4F60DFB8.8080703@tim.thechases.com> <20120315214224.GA3390@cskk.homeip.net> Message-ID: On 03/15/2012 10:42 PM, Cameron Simpson wrote: > On 14Mar2012 13:13, Tim Chase wrote: > | On 03/14/12 12:06, Terry Reedy wrote: > | > On 3/14/2012 6:07 AM, Gelonida N wrote: > | >> Now I'm looking for a library, which behaves like config parser, but > | >> with one minor difference. > | >> > | >> The write() mehtod should keep existing comments. > | > > | > Assuming that you have not overlooked anything, I would just subclass > | > ConfigParser with an altered write method. > | > | It would require a lot more than that. It would entail changing > | the reading as well so that it preserved the comments as well as > | the order of sections & keys, and a way of storing those > | associated comments in sequence. I looked into it a fair while > | back and it was a LOT more work than I cared to do for minimal > | gain. I wimped out and just documented it with "If you use the > | ability to (re)write a configuration file, it will not keep any > | comments or ordering from any original sources." > > A low cost approach might be to patch the file instead of transcribing > the in-memory state. Not the same semantics, but it would not be too > hard to add a patch_config(filename, section, setting, value) that read > the old file and wrote a new one with an adjusted section, ignoring the > in-memory state (indeed, on that basis the siganture isn't a method but > a standalone function). > > The logic is easy enough that I even wrote a shell script in 2004 to do > essentially this: > > https://bitbucket.org/cameron_simpson/css/src/ef42896872b5/bin/winclauseappend > > One could imagine an efficient python implementation and a ConfigParser > subclass that patched the file if a setting got changed, or had a .patch > method to apply particular setting changes as desired. > Agreed, patching is simpler than parsing the file and keeping all the comment info in the config object. I will also look at ConfigObj as suggested by Steven and Karim If this does what I want, then it's probably less effort to use this library than patching Configparser. From steve+comp.lang.python at pearwood.info Thu Mar 15 21:53:44 2012 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 16 Mar 2012 01:53:44 GMT Subject: Python is readable References: <4f612b19$0$1379$4fafbaef@reader2.news.tin.it> Message-ID: <4f629d27$0$29981$c3e8da3$5496439d@news.astraweb.com> On Thu, 15 Mar 2012 00:34:47 +0100, Kiuhnm wrote: > I've just started to read > The Quick Python Book (2nd ed.) Is this the one? http://manning.com/ceder/ > The author claims that Python code is more readable than Perl code and > provides this example: > > --- Perl --- > sub pairwise_sum { > my($arg1, $arg2) = @_; > my(@result) = (); > @list1 = @$arg1; > @list2 = @$arg2; I don't understand the reason for $arg1 and $arg2. Is there some reason why the code couldn't do this instead? my(@list1, @list2) = @_; > for($i=0; $i < length(@list1); $i++) { > push(@result, $list1[$i] + $list2[$i]); > } > return(\@result); > } > > --- Python --- > def pairwise_sum(list1, list2): > result = [] > for i in range(len(list1)): > result.append(list1[i] + list2[i]) > return result > --- --- > > It's quite clear that he knows little about Perl. On the contrary -- it is quite clear that you are missing the point of the comparison, which is not to compare the most idiomatic Perl with the most idiomatic Python, but to make a direct comparison of syntax for the purpose of teaching beginners. The problem with idiomatic comparisons is that they often don't give you a feel for the overall language syntax. Instead they end up comparing built-ins. For example, here is how I would write the above pairwise addition using idiomatic RPL, the Forth-like programming language used on some Hewlett-Packard scientific calculators: ADD That's it. One word. Would you conclude from this that RPL is easier to read and write than Python? I can tell you that it is not, and I *like* stack-based languages that use reverse Polish Notation. > Here's what I would've written: > > sub pairwise_sum { > my ($list1, $list2) = @_; > my @result; > push @result, $list1->[$_] + $list2->[$_] for (0..@$list1-1); > \@result; > } > > Having said that, the Python code is still more readable, so there's no > need to misrepresent Perl that way. Speaking as somebody who doesn't know Perl, I think that your version would do a great disservice to Perl. Your version is shorter, but conciseness is often in opposition to readability. Without the author's version above, and the function name, I would have literally NO IDEA what your version does. It is virtually pure line-noise. I know enough Perl to guess that @result might be an array, and so guess that push pushes a value onto the array, but the rest might as well be written in Martian. Or APL. The author's version above, which you denigrate, is *much* more understandable than your more idiomatic Perl, especially since I can compare it feature to feature with the Python code. Far from misrepresenting Perl, he has gone out of his way to show Perl in the best possible light. Idiomatic Perl code, written by experts, is even more incomprehensible and unreadable to non-Perl hackers than his example. > Now I'm wondering whether the author will show me "good" or "bad" Python > code throughout the book. Should I keep reading? >From what you have show, and the sample chapters on the link above, I am impressed. The author is aiming to teach basic concepts and impart *understanding* rather than just force-feed the reader idioms which would be incomprehensible to them. Vern Cedar (the author) is an actual professional teacher, and from the samples I have seen, he knows what he is doing. -- Steven From d at davea.name Thu Mar 15 22:00:43 2012 From: d at davea.name (Dave Angel) Date: Thu, 15 Mar 2012 22:00:43 -0400 Subject: Is it technically possible to give Python option of naming process of running script? In-Reply-To: References: <19118128.4791.1331736187952.JavaMail.geo-discussion-forums@vbai14> <22071354.8904.1331796412001.JavaMail.geo-discussion-forums@vbkc1> Message-ID: <4F629ECB.3090104@davea.name> On 03/15/2012 02:39 PM, Grant Edwards wrote: > On 2012-03-15, Dave Angel wrote: >> On 03/15/2012 03:26 AM, xliiv wrote: >>>>>> Like the topic.. . >>>>>> I use Python a lot, both Windows and Linux, and it's little weird to have many python process without fast distinction which is what. >>> I did google, I've played with Exemaker (it works perfect, but not py3) and i've seen questions on Stackoverflow. >>> The thing I mean is a build feature of python to give such a name. Not 3rd part or etc. like Grant Edwards said. Is it possible? >> How about simply using cp to copy the python executable, run chmod +x on >> it, and run that one? Then ps would list it as the new name, not as python. > That's rather a waste of memory. Better to use a link. That way the > executable can still be shared by multiple programs and won't be > duplicated in memory. > >> i tried it on /usr/bin/python2.7 but I see no reason the same >> approach won't work on 3.x Note, I copied it to a new name in the same >> directory, which may be important. or not. > Seems like an awfully obtuse way of doing things -- I don't really > want to have 15 different copies of Python (or even links), and it > requires root privleges every time you want to run a Python program > with the "correct" name. > Good point about using a link. I was trying to make something that would probably also work in Windows. As for the needing of root privileges, that's only for those programs you need to be able to identify with ps, and only one time for each. Anyway, it's a response to a specific need, which I don't share, and it was my second suggestion, not first. -- DaveA From steve+comp.lang.python at pearwood.info Thu Mar 15 22:03:59 2012 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 16 Mar 2012 02:03:59 GMT Subject: Python is readable References: <4f612b19$0$1379$4fafbaef@reader2.news.tin.it> Message-ID: <4f629f8e$0$29981$c3e8da3$5496439d@news.astraweb.com> On Thu, 15 Mar 2012 20:54:30 +0000, Arnaud Delobelle wrote: > On 15 March 2012 00:27, Chris Angelico wrote: >> On Thu, Mar 15, 2012 at 10:54 AM, Arnaud Delobelle >> wrote: >>> I don't know this book and there may be a pedagogical reason for the >>> implementation you quote, but pairwise_sum is probably better >>> implemented in Python 3.X as: >>> >>> def pairwise_sum(list1, list2): >>> ? ?return [x1 + x2 for x1, x2 in zip(list1, list2)] >> >> Okay, here's something for debate. >> >> Should the readability of a language be gauged on the basis of its >> standard library, or should you be comparing actual code? > > But here's the code posted by the OP: > > --- Python --- > def pairwise_sum(list1, list2): > result = [] > for i in range(len(list1)): > result.append(list1[i] + list2[i]) > return result > --- --- > > The code I posted uses one builtin function (zip), the code posted by > the OP uses two (range and len). Neither uses the standard library. For beginners, code using range and len is MUCH easier to understand than code using zip. len is obviously short for length, and range (at least in the one-argument version) is simple to explain. But zip? To understand zip, you need to have a good concept of iteration in your head. When writing for beginners, you can't assume that. For beginners, the most idiomatic code is not necessarily the simplest code. I would never start beginners with a list comprehension: result = [a+b for a,b in zip(list1, list2)] which is likely to be just incomprehensible jargon. You need to understand the syntax, which may not be obvious even to people with a mathematics background. (List comps are copied from Haskell, where they derive their syntax from mathematicians' set notation.) You need to understand zip, which requires having a good mental model of element-wise iteration. Although it is longer and less idiomatic, the Python1.5-ish result = [] for i in range(len(list1)): result.append(list1[i] + list2[i]) is likely to be simpler to understand. The downside is that experienced programmers may roll their eyes at how you are dumbing down the code, or worse, accusing you of deliberately misrepresenting the language. -- Steven From breamoreboy at yahoo.co.uk Thu Mar 15 22:16:34 2012 From: breamoreboy at yahoo.co.uk (Mark Lawrence) Date: Fri, 16 Mar 2012 02:16:34 +0000 Subject: Python is readable In-Reply-To: <4f629d27$0$29981$c3e8da3$5496439d@news.astraweb.com> References: <4f612b19$0$1379$4fafbaef@reader2.news.tin.it> <4f629d27$0$29981$c3e8da3$5496439d@news.astraweb.com> Message-ID: On 16/03/2012 01:53, Steven D'Aprano wrote: > On Thu, 15 Mar 2012 00:34:47 +0100, Kiuhnm wrote: > >> I've just started to read >> The Quick Python Book (2nd ed.) > > Is this the one? > > http://manning.com/ceder/ > > >> The author claims that Python code is more readable than Perl code and >> provides this example: >> >> --- Perl --- >> sub pairwise_sum { >> my($arg1, $arg2) = @_; >> my(@result) = (); >> @list1 = @$arg1; >> @list2 = @$arg2; > > I don't understand the reason for $arg1 and $arg2. Is there some reason > why the code couldn't do this instead? > > my(@list1, @list2) = @_; > > >> for($i=0; $i< length(@list1); $i++) { >> push(@result, $list1[$i] + $list2[$i]); >> } >> return(\@result); >> } >> >> --- Python --- >> def pairwise_sum(list1, list2): >> result = [] >> for i in range(len(list1)): >> result.append(list1[i] + list2[i]) >> return result >> --- --- >> >> It's quite clear that he knows little about Perl. > > On the contrary -- it is quite clear that you are missing the point of > the comparison, which is not to compare the most idiomatic Perl with the > most idiomatic Python, but to make a direct comparison of syntax for the > purpose of teaching beginners. > > The problem with idiomatic comparisons is that they often don't give you > a feel for the overall language syntax. Instead they end up comparing > built-ins. For example, here is how I would write the above pairwise > addition using idiomatic RPL, the Forth-like programming language used on > some Hewlett-Packard scientific calculators: > > ADD > > That's it. One word. Would you conclude from this that RPL is easier to > read and write than Python? I can tell you that it is not, and I *like* > stack-based languages that use reverse Polish Notation. > > >> Here's what I would've written: >> >> sub pairwise_sum { >> my ($list1, $list2) = @_; >> my @result; >> push @result, $list1->[$_] + $list2->[$_] for (0..@$list1-1); >> \@result; >> } >> >> Having said that, the Python code is still more readable, so there's no >> need to misrepresent Perl that way. > > Speaking as somebody who doesn't know Perl, I think that your version > would do a great disservice to Perl. Your version is shorter, but > conciseness is often in opposition to readability. Without the author's > version above, and the function name, I would have literally NO IDEA what > your version does. It is virtually pure line-noise. I know enough Perl to > guess that @result might be an array, and so guess that push pushes a > value onto the array, but the rest might as well be written in Martian. > Or APL. > > The author's version above, which you denigrate, is *much* more > understandable than your more idiomatic Perl, especially since I can > compare it feature to feature with the Python code. > > Far from misrepresenting Perl, he has gone out of his way to show Perl in > the best possible light. Idiomatic Perl code, written by experts, is even > more incomprehensible and unreadable to non-Perl hackers than his example. > > >> Now I'm wondering whether the author will show me "good" or "bad" Python >> code throughout the book. Should I keep reading? > >> From what you have show, and the sample chapters on the link above, I am > impressed. The author is aiming to teach basic concepts and impart > *understanding* rather than just force-feed the reader idioms which would > be incomprehensible to them. Vern Cedar (the author) is an actual > professional teacher, and from the samples I have seen, he knows what he > is doing. > > Well put Sir. And (seriously) when making your comments you show the killer instincts of a great bowler in an Ashes Test Match, now could there be anything more important in life or showing greater esteem than that? -- Cheers. Mark Lawrence. From rex.0510 at gmail.com Thu Mar 15 22:23:41 2012 From: rex.0510 at gmail.com (choi2k) Date: Thu, 15 Mar 2012 19:23:41 -0700 (PDT) Subject: Python simulate browser activity Message-ID: <214c4c0c-f8ec-4030-946b-8becc8e1aa9c@ur9g2000pbc.googlegroups.com> Hi, everyone I am trying to write a small application using python but I am not sure whether it is possible to do so.. The application aims to simulate user activity including visit a website and perform some interactive actions (click on the menu, submit a form, redirect to another pages...etc) I have found some libraries / plugins which aims to simulate browser activity but ... none of them support AJAX request and/or running javascript. Here is one of the simple tasks which I would like to do using the application: 1. simulate the user activity, visit the website ("https:// www.abc.com") 2. find out the target element by id ("submitBtn") and simulate mouse click on the item. 3. perform some javascript functions which invoked by click event from step 2. ( the function is bind to the item by jquery) 4. post ajax request using javascript and if the page has been redirected, load the new page content Is it possible to do so? Thank you in advance. From clp2 at rebertia.com Thu Mar 15 22:54:03 2012 From: clp2 at rebertia.com (Chris Rebert) Date: Thu, 15 Mar 2012 19:54:03 -0700 Subject: Python simulate browser activity In-Reply-To: <214c4c0c-f8ec-4030-946b-8becc8e1aa9c@ur9g2000pbc.googlegroups.com> References: <214c4c0c-f8ec-4030-946b-8becc8e1aa9c@ur9g2000pbc.googlegroups.com> Message-ID: On Thu, Mar 15, 2012 at 7:23 PM, choi2k wrote: > Hi, everyone > > I am trying to write a small application using python but I am not > sure whether it is possible to do so.. > The application aims to simulate user activity including visit a > website and perform some interactive actions (click on the menu, > submit a form, redirect to another pages...etc) > I have found some libraries / plugins which aims to simulate browser > activity but ... none of them support AJAX request and/or running > javascript. Did you look at Selenium? http://seleniumhq.org/ Cheers, Chris From rosuav at gmail.com Thu Mar 15 23:12:44 2012 From: rosuav at gmail.com (Chris Angelico) Date: Fri, 16 Mar 2012 14:12:44 +1100 Subject: Python is readable In-Reply-To: <4f6280a0$0$29981$c3e8da3$5496439d@news.astraweb.com> References: <4f612b19$0$1379$4fafbaef@reader2.news.tin.it> <8e72d74f-c844-4de3-8a37-f6b1fdc2291f@y27g2000yqy.googlegroups.com> <50e9ceec-40f1-4ead-b2b6-87328b30d084@ow8g2000pbc.googlegroups.com> <4f61c828$0$1390$4fafbaef@reader2.news.tin.it> <4f61d728$0$1375$4fafbaef@reader2.news.tin.it> <4f61fd0a$0$1389$4fafbaef@reader2.news.tin.it> <4f6280a0$0$29981$c3e8da3$5496439d@news.astraweb.com> Message-ID: On Fri, Mar 16, 2012 at 10:52 AM, Steven D'Aprano wrote: > On Fri, 16 Mar 2012 01:48:09 +1100, Chris Angelico wrote: > >> In a trivial example, it's mostly just noise: >> >> if a == b ? ?# who needs the colon? >> ? ? print(c) > > The reader, for the same reason that above you wrote: > > "In a trivial example, it's mostly just noise COLON" > > and indeed I too used a colon for the same reason. It ties the lead > sentence to the following block without ending the sentence, but still > introducing a new grouping or clause. Yep. As everyone who communicates on the internet knows, punctuation can often be omitted without introducing ambiguity. That doesn't mean it *should* be omitted. NOT TELEGRAMS TODAY STOP ChrisA From rosuav at gmail.com Thu Mar 15 23:14:03 2012 From: rosuav at gmail.com (Chris Angelico) Date: Fri, 16 Mar 2012 14:14:03 +1100 Subject: Is it technically possible to give Python option of naming process of running script? In-Reply-To: References: <19118128.4791.1331736187952.JavaMail.geo-discussion-forums@vbai14> <22071354.8904.1331796412001.JavaMail.geo-discussion-forums@vbkc1> Message-ID: On Fri, Mar 16, 2012 at 5:39 AM, Grant Edwards wrote: > Seems like an awfully obtuse way of doing things -- I don't really > want to have 15 different copies of Python (or even links), and it > requires root privleges every time you want to run a Python program > with the "correct" name. Why do you need root? Can't you copy / link into your own home directory? I may have misunderstood something here. ChrisA From malaclypse2 at gmail.com Thu Mar 15 23:44:29 2012 From: malaclypse2 at gmail.com (Jerry Hill) Date: Thu, 15 Mar 2012 23:44:29 -0400 Subject: Python simulate browser activity In-Reply-To: References: <214c4c0c-f8ec-4030-946b-8becc8e1aa9c@ur9g2000pbc.googlegroups.com> Message-ID: On Thu, Mar 15, 2012 at 10:54 PM, Chris Rebert wrote: > On Thu, Mar 15, 2012 at 7:23 PM, choi2k wrote: >> The application aims to simulate user activity including visit a >> website and perform some interactive actions (click on the menu, >> submit a form, redirect to another pages...etc) > > Did you look at Selenium? > http://seleniumhq.org/ You might also be interested in Sikuli (http://sikuli.org/), which uses Jython to write scripts to automate other programs using screenshots. It's pretty neat if you need to automate a GUI that is otherwise difficult to deal with. -- Jerry From steve+comp.lang.python at pearwood.info Thu Mar 15 23:55:43 2012 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 16 Mar 2012 03:55:43 GMT Subject: Python is readable References: <4f612b19$0$1379$4fafbaef@reader2.news.tin.it> <8e72d74f-c844-4de3-8a37-f6b1fdc2291f@y27g2000yqy.googlegroups.com> <50e9ceec-40f1-4ead-b2b6-87328b30d084@ow8g2000pbc.googlegroups.com> <4f61c828$0$1390$4fafbaef@reader2.news.tin.it> <4f61d728$0$1375$4fafbaef@reader2.news.tin.it> <4f61fd0a$0$1389$4fafbaef@reader2.news.tin.it> <4f620837$0$1382$4fafbaef@reader2.news.tin.it> <4f627c25$0$1381$4fafbaef@reader2.news.tin.it> Message-ID: <4f62b9be$0$29981$c3e8da3$5496439d@news.astraweb.com> On Fri, 16 Mar 2012 00:32:52 +0100, Kiuhnm wrote: > Pick up two math books about the same topic but on two different levels > (e.g. under-graduated and graduated). If you compare the proofs you'll > see that those in the higher-level book are almost always sketched. Why > is that? Because they're more readable for a mature reader. No. They're not more readable. They simply have less to read (per proof), or another way of putting it, you can fit more of the good stuff that the experienced reader wants ("yes yes, I know about the associative law, get to the part where you prove the Goldbach conjecture...") in the same amount of space. The text is compressed by leaving out the parts that an experienced reader can infer from her knowledge of the domain. Since an expert can infer meaning more quickly than they can read the actual words, this is a big win for efficiency. But the text is not more readable, there's just less to read for a given result. The same amount, or even more, brain processing occurs. It just happens in a different part of the brain. In Python terms, it's analogous to moving something out of a pure-Python O(log n) binary tree into a fast O(n) linear array written in C. Until the concepts get complex enough, it is faster for the expert to infer meaning than to read explicitly, even though technically more work is probably being done. Experts often find pedagogical texts harder to read because it seems dumbed down. It's as if they are reading text like this: The cat, which is a small animal with fur known for being aloof and yet attractive to many people, sat on the mat, which is like a rug or blanket except thicker, while Jack, a small male child, and Jill, a young female child, ran, that is to say travelled quickly by lifting their feet and moving forward in such a fashion that sometimes both feet are in the air simultaneously, up the hill, a moderately- sized elevation of land smaller than a mountain. It gets painful after a while because, as an expert, you can interpret the subtext quicker than you can read the actual words. But when teaching non-experts, you can't expect the reader to interpret the subtext quickly or at all. Which is more readable, that is to say, more comprehensible? The wix sat on the zaj, while Megf and Parz vev up the leff. Lacking any domain knowledge, the above carries virtually no information at all. We know that wixes can sit on things, and that's about it. Contrast this: The wix, which is a small animal with fur known for being aloof and yet attractive to many people, sat on the zaj, which is like a rug or blanket except thicker, while Megf, a small male child, and Parz, a young female child, vev, that is to say travelled quickly by lifting their feet and moving forward in such a fashion that sometimes both feet are in the air simultaneously, up the leff, a moderately- sized elevation of land smaller than a mountain. Despite having about 8 times as much content, and being one long run-on sentence, this version is far more comprehensible. (In practice, I wouldn't define terms in the sentence I was using them in this fashion. Or at least not more than one per sentence. Very long sentences have their own readability costs.) When people talk about readability, they normally mean to ask how much mental effort is needed to interpret the meaning of the text, not how much time does it take to pass your eyes over the characters. In other words they are actually talking about comprehensibility. Well obviously that depends on who is doing the reading. To somebody in the know, meaning can be incredibly compressed. You can crack up Monty Python fans with just two words: "Norwegian Blue". To those not in the know, that's incomprehensible. When speaking about programming languages, the reader who is judging readability is assumed to be: - somebody with a good grasp of natural language, normally English, and capable of understanding sentences containing loops and conditionals such as "soak and rinse the beans three times" "scrub the potatoes until the dirt is gone" "if the tap is dripping, replace the washer" - possessing an intuitive understanding of such concepts as "is-a" and "has-a" (Fido is a dog, Fido has a tail); - possessing a simple knowledge of basic arithmetic and logic; - able to intuit the meaning of programming concepts if they match simple natural language concepts (e.g. print, delete, but not necessarily import, delegate, and certainly not currying, closures, monads); - but not familiar with the programming language, its data model, or the details of its functions and commands; - and of average intelligence, neither a dummy nor a genius. (Despite the proliferation of books with titles like "Programming For Utter Morans", they aren't actually written for dummies.) To judge the readability of a language, we have to put ourselves into the position of such a beginner: ignorant but not stupid. To judge the expressibility and power of a language, we have to put ourselves into the position of an expert who knows all the idioms. The trick is to increase power without hurting readability. For example, in the late 80s or early 90s, Apple introduced the forerunner to Applescript, Hypertalk. Hypertalk is *extremely* readable: put the result into x add 15 to x go to the second card of background "Data" put x after word 7 of field "Age" get field "Name" put it into field "Alias" Aside: there's a non-GUI version of Hypertalk-on-steroids available from here: http://code.google.com/p/openxion/ Very readable indeed. You can possibly even infer part of the data model from the code (everything is text; text is stored in fields, which exist on cards collected into groupings called backgrounds). But, frankly, it's not too expressible. It's too verbose for experts. The data model is too simple. (Modern versions like OpenXion have a richer data model not as strongly tied to the original Hypercard GUI.) I think Python is pretty close to the top of the readability versus expressiveness curve. That's not to say that Python is the optimal combination, or can't be improved, or even that every language should compromise expressiveness for comprehensibility (or vice versa). -- Steven From aasayanisen at gmail.com Fri Mar 16 00:45:06 2012 From: aasayanisen at gmail.com (Sayani Sen) Date: Thu, 15 Mar 2012 21:45:06 -0700 (PDT) Subject: easy earn at home 50000 per month Message-ID: <30257078.288.1331873106000.JavaMail.geo-discussion-forums@pbcwe9> http://unlimitedmoney.yolasite.com From slo at hep.caltech.edu Fri Mar 16 02:47:36 2012 From: slo at hep.caltech.edu (Steven Lo) Date: Thu, 15 Mar 2012 23:47:36 -0700 Subject: cannot open shared object file Message-ID: <4F62E208.70005@hep.caltech.edu> Hi, We are getting the following error during a 'make' process on a CentOS release 5.4 system: Running mkfontdir... Creating SELinux policy... /usr/bin/python: error while loading shared libraries: libpython2.4.so.1.0: cannot open shared object file: No such file or directory However, we are able to execute 'python' without any problem # which python /usr/bin/python # python Python 2.4.3 (#1, Sep 3 2009, 15:37:37) [GCC 4.1.2 20080704 (Red Hat 4.1.2-46)] on linux2 Type "help", "copyright", "credits" or "license" for more information. >>> # ldd /usr/bin/python libpython2.4.so.1.0 => /usr/lib64/libpython2.4.so.1.0 (0x0000003fb7600000) libpthread.so.0 => /lib64/libpthread.so.0 (0x0000003b59600000) libdl.so.2 => /lib64/libdl.so.2 (0x0000003b59200000) libutil.so.1 => /lib64/libutil.so.1 (0x0000003b64000000) libm.so.6 => /lib64/libm.so.6 (0x0000003b58e00000) libc.so.6 => /lib64/libc.so.6 (0x0000003b58a00000) /lib64/ld-linux-x86-64.so.2 (0x0000003b58600000) # ls -lad /usr/lib64/*python* lrwxrwxrwx 1 root root 19 Feb 27 21:15 /usr/lib64/libpython2.4.so -> libpython2.4.so.1.0 -r-xr-xr-x 1 root root 1236344 Sep 3 2009 /usr/lib64/libpython2.4.so.1.0 drwxr-xr-x 18 root root 20480 Feb 27 21:15 /usr/lib64/python2.4 In this 'make' process, we are suppose to execute the applicate-specific python (/opt/rocks/bin/python) which has static link (not dynamic link) # ldd /opt/rocks/bin/python libpthread.so.0 => /lib64/libpthread.so.0 (0x0000003b59600000) libdl.so.2 => /lib64/libdl.so.2 (0x0000003b59200000) libutil.so.1 => /lib64/libutil.so.1 (0x0000003b64000000) libstdc++.so.6 => /usr/lib64/libstdc++.so.6 (0x0000003b6b400000) libm.so.6 => /lib64/libm.so.6 (0x0000003b58e00000) libgcc_s.so.1 => /lib64/libgcc_s.so.1 (0x0000003b67c00000) libc.so.6 => /lib64/libc.so.6 (0x0000003b58a00000) /lib64/ld-linux-x86-64.so.2 (0x0000003b58600000) Basically, we try to understand: * why /opt/rocks/bin/python not being used ? * why /usr/bin/python can not find the dynamic library Please let us know if you have any suggestion on how to troubleshoot this problem. If this is not the list to ask this type of question, please point us to the appropriate list. Thanks. S. -------------- next part -------------- An HTML attachment was scrubbed... URL: From tymoteusz.jankowski at gmail.com Fri Mar 16 04:19:38 2012 From: tymoteusz.jankowski at gmail.com (xliiv) Date: Fri, 16 Mar 2012 01:19:38 -0700 (PDT) Subject: Is it technically possible to give Python option of naming process of running script? In-Reply-To: References: <19118128.4791.1331736187952.JavaMail.geo-discussion-forums@vbai14> <22071354.8904.1331796412001.JavaMail.geo-discussion-forums@vbkc1> Message-ID: <19653171.562.1331885978787.JavaMail.geo-discussion-forums@vbbfw10> > > Seems like an awfully obtuse way of doing things -- I don't really > > want to have 15 different copies of Python (or even links), and it > > requires root privleges every time you want to run a Python program > > with the "correct" name. > > Why do you need root? Can't you copy / link into your own home directory? > > I may have misunderstood something here. > > ChrisA It's nice walkaround for now and for linux. But how about my question and future? :) From tymoteusz.jankowski at gmail.com Fri Mar 16 04:19:38 2012 From: tymoteusz.jankowski at gmail.com (xliiv) Date: Fri, 16 Mar 2012 01:19:38 -0700 (PDT) Subject: Is it technically possible to give Python option of naming process of running script? In-Reply-To: References: <19118128.4791.1331736187952.JavaMail.geo-discussion-forums@vbai14> <22071354.8904.1331796412001.JavaMail.geo-discussion-forums@vbkc1> Message-ID: <19653171.562.1331885978787.JavaMail.geo-discussion-forums@vbbfw10> > > Seems like an awfully obtuse way of doing things -- I don't really > > want to have 15 different copies of Python (or even links), and it > > requires root privleges every time you want to run a Python program > > with the "correct" name. > > Why do you need root? Can't you copy / link into your own home directory? > > I may have misunderstood something here. > > ChrisA It's nice walkaround for now and for linux. But how about my question and future? :) From Peter.Condon at airwavesolutions.co.uk Fri Mar 16 05:20:50 2012 From: Peter.Condon at airwavesolutions.co.uk (Peter Condon) Date: Fri, 16 Mar 2012 09:20:50 +0000 Subject: Android Message-ID: <8AF12430BDA2C6479273908A1873E24516BE65C6@AMRGBEX01.airmis.airwave.pri> Dear Sirs, I am a new student learning this and am getting an Android tablet for my birthday will python be able to run on android? Kindest regards Peter This email and any attachments to it may contain information which is confidential, legally privileged, subject to the Official Secrets Act, or otherwise not disclosable by law, and is protected by copyright. It is intended only for the addressee named above. If you are not the intended recipient you must delete this email immediately and not use, distribute, copy, disclose or take any action in reliance on this email or its contents. If you have received this email in error please notify us by return email immediately. Airwave Solutions Limited is a company registered in England and Wales having company number 03985643. Registered Office: Airwave Solutions Ltd, Charter Court, 50 Windsor Road, Slough, Berkshire, SL1 2EJ. -------------- next part -------------- An HTML attachment was scrubbed... URL: From duncan.booth at invalid.invalid Fri Mar 16 05:30:17 2012 From: duncan.booth at invalid.invalid (Duncan Booth) Date: 16 Mar 2012 09:30:17 GMT Subject: Python is readable References: <4f612b19$0$1379$4fafbaef@reader2.news.tin.it> <8e72d74f-c844-4de3-8a37-f6b1fdc2291f@y27g2000yqy.googlegroups.com> <50e9ceec-40f1-4ead-b2b6-87328b30d084@ow8g2000pbc.googlegroups.com> <4f61c828$0$1390$4fafbaef@reader2.news.tin.it> <4f61d728$0$1375$4fafbaef@reader2.news.tin.it> Message-ID: Thomas Rachel wrote: >> Or, more likely, lock creates an object which keeps the lock "acquired". >> The lock is released when we leave the block. >> So we could inspect the lock with >> with lock as l: >> inspect l... >> do_some..... > > Or just inspect l - I don't know if a lock's __enter__ methos returns it > again for assignment with "as"... > No, if you do `with lock as l:` then l will get the boolean True. The lock's __enter__ method is the same as lock.acquire(). That method takes an optional argument which can be used to conditionally acquire the lock and return a boolean indicating success or failure. When used inside a `with` statement you can't pass in the optional argument so it acquires it unconditionally but still returns the success status which is either True or it never returns. -- Duncan Booth http://kupuguy.blogspot.com From patrick.szabo at lexisnexis.at Fri Mar 16 07:38:55 2012 From: patrick.szabo at lexisnexis.at (Szabo, Patrick (LNG-VIE)) Date: Fri, 16 Mar 2012 12:38:55 +0100 Subject: AW: Android In-Reply-To: <8AF12430BDA2C6479273908A1873E24516BE65C6@AMRGBEX01.airmis.airwave.pri> References: <8AF12430BDA2C6479273908A1873E24516BE65C6@AMRGBEX01.airmis.airwave.pri> Message-ID: You might be interested in this: http://www.linuxjournal.com/article/10940 I had this installed on my Desire and it ran pretty nicely. regards Von: python-list-bounces+patrick.szabo=lexisnexis.at at python.org [mailto:python-list-bounces+patrick.szabo=lexisnexis.at at python.org] Im Auftrag von Peter Condon Gesendet: Freitag, 16. M?rz 2012 10:21 An: python-list at python.org Betreff: Android Dear Sirs, I am a new student learning this and am getting an Android tablet for my birthday will python be able to run on android? Kindest regards Peter This email and any attachments to it may contain information which is confidential, legally privileged, subject to the Official Secrets Act, or otherwise not disclosable by law, and is protected by copyright. It is intended only for the addressee named above. If you are not the intended recipient you must delete this email immediately and not use, distribute, copy, disclose or take any action in reliance on this email or its contents. If you have received this email in error please notify us by return email immediately. Airwave Solutions Limited a company registered in England and Wales having company number 03985643. Registered Office: Airwave Solutions Ltd, Charter Court, 50 Windsor Road, Slough, Berkshire, SL1 2EJ. . . . . . . . . . . . . . . . . . . . . . . . . . . Ing. Patrick Szabo XSLT Developer LexisNexis A-1030 Wien, Marxergasse 25 mailto:patrick.szabo at lexisnexis.at Tel.: +43 1 53452 1573 Fax: +43 1 534 52 146 -------------- next part -------------- An HTML attachment was scrubbed... URL: From kiuhnm03.4t.yahoo.it Fri Mar 16 07:41:49 2012 From: kiuhnm03.4t.yahoo.it (Kiuhnm) Date: Fri, 16 Mar 2012 12:41:49 +0100 Subject: Python is readable In-Reply-To: References: <4f612b19$0$1379$4fafbaef@reader2.news.tin.it> <8e72d74f-c844-4de3-8a37-f6b1fdc2291f@y27g2000yqy.googlegroups.com> <50e9ceec-40f1-4ead-b2b6-87328b30d084@ow8g2000pbc.googlegroups.com> <4f61c828$0$1390$4fafbaef@reader2.news.tin.it> <4f61d728$0$1375$4fafbaef@reader2.news.tin.it> <4f61fa8a$0$1381$4fafbaef@reader2.news.tin.it> <4f6202cb$0$1377$4fafbaef@reader2.news.tin.it> <4f6245c5$0$1384$4fafbaef@reader2.news.tin.it> <873999pk52.fsf@benfinney.id.au> <4f627f5c$0$1389$4fafbaef@reader2.news.tin.it> Message-ID: <4f6326fe$0$1381$4fafbaef@reader1.news.tin.it> On 3/16/2012 0:58, Mark Lawrence wrote: > On 15/03/2012 23:46, Kiuhnm wrote: >> On 3/16/2012 0:00, Arnaud Delobelle wrote: >>> On 15 March 2012 22:35, Ben Finney wrote: >>>> Kiuhnm writes: >>>> >>>>> Moreover, I think that >>>>> if (............ >>>>> ............ >>>>> ............): >>>>> ............ >>>>> ............ >>>>> ............ >>>>> is not very readable anyway. >>>> >>>> I agree, and am glad PEP 8 has been updated to recommend an extra level >>>> of indentation for continuation, to distinguish from the new block that >>>> follows. >>> >>> Personally I solve this by never writing if conditions that span more >>> than one line. If the worst comes to the worst, I would write: >>> >>> aptly_named_condition = ( >>> very long condition >>> that goes over >>> plenty of lines >>> ) >>> if aptly_named_condition: >>> do stuff >> >> Will I be able to use extra indentation in Python code? >> For instance, >> >> res = and(or(cond1, >> cond2), >> cond3, >> or(and(cond4, >> cond5, >> cond6), >> and(cond7, >> cond8))) >> >> I like it because it reads like a tree. >> >> Kiuhnm > > Why not find out for yourself by slapping the code into an interactive > Python interpreter and seeing what the result is? Ok, it works. I had to use different names though. Kiuhnm From kiuhnm03.4t.yahoo.it Fri Mar 16 08:10:12 2012 From: kiuhnm03.4t.yahoo.it (Kiuhnm) Date: Fri, 16 Mar 2012 13:10:12 +0100 Subject: Python is readable In-Reply-To: <4f62b9be$0$29981$c3e8da3$5496439d@news.astraweb.com> References: <4f612b19$0$1379$4fafbaef@reader2.news.tin.it> <8e72d74f-c844-4de3-8a37-f6b1fdc2291f@y27g2000yqy.googlegroups.com> <50e9ceec-40f1-4ead-b2b6-87328b30d084@ow8g2000pbc.googlegroups.com> <4f61c828$0$1390$4fafbaef@reader2.news.tin.it> <4f61d728$0$1375$4fafbaef@reader2.news.tin.it> <4f61fd0a$0$1389$4fafbaef@reader2.news.tin.it> <4f620837$0$1382$4fafbaef@reader2.news.tin.it> <4f627c25$0$1381$4fafbaef@reader2.news.tin.it> <4f62b9be$0$29981$c3e8da3$5496439d@news.astraweb.com> Message-ID: <4f632da5$0$1375$4fafbaef@reader1.news.tin.it> On 3/16/2012 4:55, Steven D'Aprano wrote: > On Fri, 16 Mar 2012 00:32:52 +0100, Kiuhnm wrote: > >> Pick up two math books about the same topic but on two different levels >> (e.g. under-graduated and graduated). If you compare the proofs you'll >> see that those in the higher-level book are almost always sketched. Why >> is that? Because they're more readable for a mature reader. > > No. They're not more readable. They simply have less to read (per proof), > or another way of putting it, you can fit more of the good stuff that the > experienced reader wants ("yes yes, I know about the associative law, get > to the part where you prove the Goldbach conjecture...") in the same > amount of space. The text is compressed by leaving out the parts that an > experienced reader can infer from her knowledge of the domain. > > Since an expert can infer meaning more quickly than they can read the > actual words, this is a big win for efficiency. But the text is not more > readable, there's just less to read for a given result. The same amount, > or even more, brain processing occurs. It just happens in a different > part of the brain. Maybe we should define *exactly* what readability is (in less then 500 lines, if possible). According to your view, ASM code is more readable than Python code. It's just that there's more to read in ASM. Kiuhnm From kiuhnm03.4t.yahoo.it Fri Mar 16 08:36:25 2012 From: kiuhnm03.4t.yahoo.it (Kiuhnm) Date: Fri, 16 Mar 2012 13:36:25 +0100 Subject: Python is readable In-Reply-To: <4f6280a0$0$29981$c3e8da3$5496439d@news.astraweb.com> References: <4f612b19$0$1379$4fafbaef@reader2.news.tin.it> <8e72d74f-c844-4de3-8a37-f6b1fdc2291f@y27g2000yqy.googlegroups.com> <50e9ceec-40f1-4ead-b2b6-87328b30d084@ow8g2000pbc.googlegroups.com> <4f61c828$0$1390$4fafbaef@reader2.news.tin.it> <4f61d728$0$1375$4fafbaef@reader2.news.tin.it> <4f61fd0a$0$1389$4fafbaef@reader2.news.tin.it> <4f6280a0$0$29981$c3e8da3$5496439d@news.astraweb.com> Message-ID: <4f6333ca$0$1392$4fafbaef@reader1.news.tin.it> On 3/16/2012 0:52, Steven D'Aprano wrote: >> On Fri, Mar 16, 2012 at 1:30 AM, Kiuhnm >> wrote: >>> Sorry, but I can't see how it would make it harder for humans to >>> understand. Are there particular situations you're referring to? >> >> In a trivial example, it's mostly just noise: >> >> if a == b # who needs the colon? >> print(c) > > The reader, for the same reason that above you wrote: > > "In a trivial example, it's mostly just noise COLON" > > and indeed I too used a colon for the same reason. It ties the lead > sentence to the following block without ending the sentence, but still > introducing a new grouping or clause. > > It is *remarkable* how people take the colon for granted. It is so simple > and so obvious that they use it in their own writing often without > thinking about it, but because it is not strictly necessary to avoid > ambiguity in the grammar, they fool themselves into thinking that it is > "just noise" or "pointless". It is not noise, it is a hint to the reader. IMHO, Python misuses colons. No grammarian would ever write "If you can: take the bus." Natural languages are irregular while Python strives to be as regular as possible. BTW, I prefer The matrix [....] can be ..... and it gives [....] which ..... to The matrix: [....] can be ..... and it gives: [....] which .... Colons should introduce more specific information, not all the information. For instance, "I like many things in life: " is way better than "I like: ". As you can see, I'm not an English native speaker, but I think I know a few things about punctuation. We second language learners remember all the wrong things :( Kiuhnm From emacsray at gmail.com Fri Mar 16 08:45:15 2012 From: emacsray at gmail.com (Ray Song) Date: Fri, 16 Mar 2012 20:45:15 +0800 Subject: Why not use juxtaposition to indicate function application Message-ID: <20120316124515.GA2529@lap.tuna.tsinghua.edu.cn> I confess i've indulged in Haskell and found f a more readable than f(a) And why aren't functions curried (partially applied function is another function which takes the rest arguments) by default? Thanks in advance for any suggestions. -- Ray From neilc at norwich.edu Fri Mar 16 08:50:33 2012 From: neilc at norwich.edu (Neil Cerutti) Date: 16 Mar 2012 12:50:33 GMT Subject: Python is readable References: <4f612b19$0$1379$4fafbaef@reader2.news.tin.it> <8e72d74f-c844-4de3-8a37-f6b1fdc2291f@y27g2000yqy.googlegroups.com> <50e9ceec-40f1-4ead-b2b6-87328b30d084@ow8g2000pbc.googlegroups.com> <4f61c828$0$1390$4fafbaef@reader2.news.tin.it> <4f61d728$0$1375$4fafbaef@reader2.news.tin.it> <4f61fd0a$0$1389$4fafbaef@reader2.news.tin.it> <4f6280a0$0$29981$c3e8da3$5496439d@news.astraweb.com> <4f6333ca$0$1392$4fafbaef@reader1.news.tin.it> Message-ID: <9sgr8oF2opU9@mid.individual.net> On 2012-03-16, Kiuhnm wrote: > As you can see, I'm not an English native speaker, but I think > I know a few things about punctuation. We second language > learners remember all the wrong things :( English's punctuation rules have to be a lot easier to remember than the seemingly random way in which we apply articles to our nouns. -- Neil Cerutti From kiuhnm03.4t.yahoo.it Fri Mar 16 08:55:06 2012 From: kiuhnm03.4t.yahoo.it (Kiuhnm) Date: Fri, 16 Mar 2012 13:55:06 +0100 Subject: Python is readable In-Reply-To: <4f629d27$0$29981$c3e8da3$5496439d@news.astraweb.com> References: <4f612b19$0$1379$4fafbaef@reader2.news.tin.it> <4f629d27$0$29981$c3e8da3$5496439d@news.astraweb.com> Message-ID: <4f63382b$0$1375$4fafbaef@reader1.news.tin.it> On 3/16/2012 2:53, Steven D'Aprano wrote: > On Thu, 15 Mar 2012 00:34:47 +0100, Kiuhnm wrote: > >> I've just started to read >> The Quick Python Book (2nd ed.) > > Is this the one? > > http://manning.com/ceder/ > > >> The author claims that Python code is more readable than Perl code and >> provides this example: >> >> --- Perl --- >> sub pairwise_sum { >> my($arg1, $arg2) = @_; >> my(@result) = (); >> @list1 = @$arg1; >> @list2 = @$arg2; > > I don't understand the reason for $arg1 and $arg2. Is there some reason > why the code couldn't do this instead? > > my(@list1, @list2) = @_; @_ contains references to arrays. You can't pass two arrays to a function. Kiuhnm From roy at panix.com Fri Mar 16 08:57:30 2012 From: roy at panix.com (Roy Smith) Date: Fri, 16 Mar 2012 08:57:30 -0400 Subject: Python simulate browser activity References: <214c4c0c-f8ec-4030-946b-8becc8e1aa9c@ur9g2000pbc.googlegroups.com> Message-ID: In article <214c4c0c-f8ec-4030-946b-8becc8e1aa9c at ur9g2000pbc.googlegroups.com>, choi2k wrote: > Hi, everyone > > I am trying to write a small application using python but I am not > sure whether it is possible to do so.. > The application aims to simulate user activity including visit a > website and perform some interactive actions (click on the menu, > submit a form, redirect to another pages...etc) > I have found some libraries / plugins which aims to simulate browser > activity but ... none of them support AJAX request and/or running > javascript. > > Here is one of the simple tasks which I would like to do using the > application: > 1. simulate the user activity, visit the website ("https:// > www.abc.com") > 2. find out the target element by id ("submitBtn") and simulate mouse > click on the item. > 3. perform some javascript functions which invoked by click event from > step 2. ( the function is bind to the item by jquery) > 4. post ajax request using javascript and if the page has been > redirected, load the new page content > > Is it possible to do so? > > Thank you in advance. Depending on exactly what you're trying to test, this may or may not be possible. #1 is easy. Just get the URL with urllib (or, even better, Kenneth Reitz's very cool requests library (http://docs.python-requests.org/). #2 gets a little more interesting, but still not that big a deal. Parse the HTML you get back with something like lxml (http://lxml.de/). Navigate the DOM with a CSSSelector to find the element you're looking for. Use urllib/requests again to get the href. #3 is where things get fun. What, exactly, are you trying to test? Are you trying to test that the js works, or are you really trying to test your server and you're just using the embedded js as a means to generate the next HTTP request? If the former, then you really want to be exploring something like selenium (http://seleniumhq.org/). If the latter, then skip all the js crap and just go a GET or POST (back to urllib/requests) on the appropriate url. #4 falls into the same bucket as #3. Once you have figured all this out, you will get a greater appreciation for the need to cleanly separate your presentation (HTML, CSS, Javascript) from your business logic and data layers. If there is a clean interface between them, it becomes easy to test one in isolation from the other. If not, then you end up playing games with screen scraping via lxml and selenium just to test your database queries. Which will quickly lead to you running screaming into the night. From steve+comp.lang.python at pearwood.info Fri Mar 16 09:03:22 2012 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 16 Mar 2012 13:03:22 GMT Subject: Python is readable References: <4f612b19$0$1379$4fafbaef@reader2.news.tin.it> <8e72d74f-c844-4de3-8a37-f6b1fdc2291f@y27g2000yqy.googlegroups.com> <50e9ceec-40f1-4ead-b2b6-87328b30d084@ow8g2000pbc.googlegroups.com> <4f61c828$0$1390$4fafbaef@reader2.news.tin.it> <4f61d728$0$1375$4fafbaef@reader2.news.tin.it> <4f61fd0a$0$1389$4fafbaef@reader2.news.tin.it> <4f6280a0$0$29981$c3e8da3$5496439d@news.astraweb.com> <4f6333ca$0$1392$4fafbaef@reader1.news.tin.it> Message-ID: <4f633a1a$0$29981$c3e8da3$5496439d@news.astraweb.com> On Fri, 16 Mar 2012 13:36:25 +0100, Kiuhnm wrote: > On 3/16/2012 0:52, Steven D'Aprano wrote: >> It is *remarkable* how people take the colon for granted. It is so >> simple and so obvious that they use it in their own writing often >> without thinking about it, but because it is not strictly necessary to >> avoid ambiguity in the grammar, they fool themselves into thinking that >> it is "just noise" or "pointless". It is not noise, it is a hint to the >> reader. > > IMHO, Python misuses colons. According to the rules of which language? Latin? Cantonese? Russian? Or perhaps Perl? Javascript? Forth? > No grammarian would ever write > "If you can: take the bus." A grammarian might very well write: Your assignment, if you choose to accept it, is to: 1. Take the bus to Swansea. 2. Go across the road to the little shop on the corner. 3. Ask for Dave. 4. Tell him George sent you. 5. He will give you a package. Take it to the park down the street. 6. You will see a man making balloon animals. Give him the package. 7. He will give you a balloon giraffe. Take it to the pub. 8. Put the giraffe on the piano in the public bar, and leave. In English, one typical use for colons is to introduce a list or sequence of items, including instructions. A sequence of instructions is an algorithm, program or routine. You may have heard of them :) A one line routine is still a routine. There is nothing ungrammatical about "If you can: take the bus.", although it is non-idiomatic English. > Natural languages are irregular while Python strives to be as regular as > possible. So what? -- Steven From neilc at norwich.edu Fri Mar 16 09:08:49 2012 From: neilc at norwich.edu (Neil Cerutti) Date: 16 Mar 2012 13:08:49 GMT Subject: Python is readable References: <4f612b19$0$1379$4fafbaef@reader2.news.tin.it> <8e72d74f-c844-4de3-8a37-f6b1fdc2291f@y27g2000yqy.googlegroups.com> <50e9ceec-40f1-4ead-b2b6-87328b30d084@ow8g2000pbc.googlegroups.com> <4f61c828$0$1390$4fafbaef@reader2.news.tin.it> <4f61d728$0$1375$4fafbaef@reader2.news.tin.it> <4f61fd0a$0$1389$4fafbaef@reader2.news.tin.it> <4f6280a0$0$29981$c3e8da3$5496439d@news.astraweb.com> <4f6333ca$0$1392$4fafbaef@reader1.news.tin.it> <4f633a1a$0$29981$c3e8da3$5496439d@news.astraweb.com> Message-ID: <9sgsb1FsbpU1@mid.individual.net> On 2012-03-16, Steven D'Aprano wrote: > A grammarian might very well write: > > Your assignment, if you choose to accept it, is to: > > 1. Take the bus to Swansea. > ... > > In English, one typical use for colons is to introduce a list > or sequence of items, including instructions. A sequence of > instructions is an algorithm, program or routine. You may have > heard of them :) A grammarian always uses complete sentence before a colon, even when introducing a list. -- Neil Cerutti From bruno.desthuilliers at gmail.com Fri Mar 16 09:14:59 2012 From: bruno.desthuilliers at gmail.com (bruno.desthuilliers at gmail.com) Date: Fri, 16 Mar 2012 06:14:59 -0700 (PDT) Subject: Why not use juxtaposition to indicate function application References: Message-ID: <42cac695-761e-4cdb-aa3b-7c82789b76f9@h20g2000yqd.googlegroups.com> On Mar 16, 1:45?pm, Ray Song wrote: > I confess i've indulged in Haskell and found > ? ? f a > more readable than > ? ? f(a) Hmmm... What about: f a b versus f(a(b)) or was it supposed to be read as f(a)(b) or as f(a, b) ?-) > And why aren't functions curried (partially applied function is another function which takes the rest arguments) by default? If you're asking "why isn't Python like Haskell", the obvious answer is, well, "because Python is not Haskell" ;) Remember that Pythons is first and foremost an object-oriented language, where most of the support for functional idioms comes from the underlying object model. functions are central to fp, objects are central to OOP, so better to use objects than functions (hint: there's a builtin "partial" type). From invalid at invalid.invalid Fri Mar 16 09:27:34 2012 From: invalid at invalid.invalid (Grant Edwards) Date: Fri, 16 Mar 2012 13:27:34 +0000 (UTC) Subject: Is it technically possible to give Python option of naming process of running script? References: <19118128.4791.1331736187952.JavaMail.geo-discussion-forums@vbai14> <22071354.8904.1331796412001.JavaMail.geo-discussion-forums@vbkc1> Message-ID: On 2012-03-16, Chris Angelico wrote: > On Fri, Mar 16, 2012 at 5:39 AM, Grant Edwards wrote: >> Seems like an awfully obtuse way of doing things -- I don't really >> want to have 15 different copies of Python (or even links), and it >> requires root privleges every time you want to run a Python program >> with the "correct" name. > > Why do you need root? Can't you copy / link into your own home directory? I was thinging about daemons and system-type stuff. One possible problem with linking from one's home directory is that home directories are often on different filesystems than /usr/bin (or wherever python is). Using a symlink doesn't work, the process name still ends up as python2.6 (or whatever the real binary is called). -- Grant Edwards grant.b.edwards Yow! Where do your SOCKS at go when you lose them in gmail.com th' WASHER? From cjw at ncf.ca Fri Mar 16 11:06:12 2012 From: cjw at ncf.ca (Colin J. Williams) Date: Fri, 16 Mar 2012 11:06:12 -0400 Subject: Why not use juxtaposition to indicate function application In-Reply-To: References: Message-ID: On 16/03/2012 8:45 AM, Ray Song wrote: > I confess i've indulged in Haskell and found > f a > more readable than > f(a) > > And why aren't functions curried (partially applied function is another function which takes the rest arguments) by default? > > > Thanks in advance for any suggestions. > > -- > Ray +1 Colin W. From kiuhnm03.4t.yahoo.it Fri Mar 16 12:00:16 2012 From: kiuhnm03.4t.yahoo.it (Kiuhnm) Date: Fri, 16 Mar 2012 17:00:16 +0100 Subject: Why not use juxtaposition to indicate function application In-Reply-To: <42cac695-761e-4cdb-aa3b-7c82789b76f9@h20g2000yqd.googlegroups.com> References: <42cac695-761e-4cdb-aa3b-7c82789b76f9@h20g2000yqd.googlegroups.com> Message-ID: <4f636391$0$1382$4fafbaef@reader1.news.tin.it> On 3/16/2012 14:14, bruno.desthuilliers at gmail.com wrote: > On Mar 16, 1:45 pm, Ray Song wrote: >> I confess i've indulged in Haskell and found >> f a >> more readable than >> f(a) > > Hmmm... What about: > > f a b > > versus > > f(a(b)) > > or was it supposed to be read as > > f(a)(b) > > > or as > > f(a, b) > > ?-) That would be f (a b) # Haskell f(a(b)) # Python Kiuhnm From ramit.prasad at jpmorgan.com Fri Mar 16 12:13:38 2012 From: ramit.prasad at jpmorgan.com (Prasad, Ramit) Date: Fri, 16 Mar 2012 16:13:38 +0000 Subject: Why not use juxtaposition to indicate function application In-Reply-To: <4f636391$0$1382$4fafbaef@reader1.news.tin.it> References: <42cac695-761e-4cdb-aa3b-7c82789b76f9@h20g2000yqd.googlegroups.com> <4f636391$0$1382$4fafbaef@reader1.news.tin.it> Message-ID: <5B80DD153D7D744689F57F4FB69AF474026BB729@SCACMX008.exchad.jpmchase.net> > >> I confess i've indulged in Haskell and found > >> f a > >> more readable than > >> f(a) > > > > Hmmm... What about: > > > > f a b > > > > versus > > > > f(a(b)) > > > > or was it supposed to be read as > > > > f(a)(b) > > > > > > or as > > > > f(a, b) > > > > ?-) > > That would be > f (a b) # Haskell > f(a(b)) # Python I have not used Haskell so far, but in this case I think I prefer the 'Explicit is better than implicit.' I would probably always forget if it should be f a b or f ( a b ) Not to mention the first line look like text rather than a function call because my mind tends to filter out whitespaces like that when reading. I blame variable width fonts (and the mind being a strange thing). Ramit Ramit Prasad | JPMorgan Chase Investment Bank | Currencies Technology 712 Main Street | Houston, TX 77002 work phone: 713 - 216 - 5423 -- This email is confidential and subject to important disclaimers and conditions including on offers for the purchase or sale of securities, accuracy and completeness of information, viruses, confidentiality, legal privilege, and legal entity disclaimers, available at http://www.jpmorgan.com/pages/disclosures/email. From robert.kern at gmail.com Fri Mar 16 12:18:57 2012 From: robert.kern at gmail.com (Robert Kern) Date: Fri, 16 Mar 2012 16:18:57 +0000 Subject: Why not use juxtaposition to indicate function application In-Reply-To: <20120316124515.GA2529@lap.tuna.tsinghua.edu.cn> References: <20120316124515.GA2529@lap.tuna.tsinghua.edu.cn> Message-ID: On 3/16/12 12:45 PM, Ray Song wrote: > I confess i've indulged in Haskell and found > f a > more readable than > f(a) > > And why aren't functions curried (partially applied function is another function which takes the rest arguments) by default? Python isn't a strongly functional language. We just don't do partial function application all that frequently to make it a language feature. Leaving out an argument is a common enough mistake, though, and using curry-by-default would postpone the error and make for even more inscrutable error messages. -- Robert Kern "I have come to believe that the whole world is an enigma, a harmless enigma that is made terrible by our own mad attempt to interpret it as though it had an underlying truth." -- Umberto Eco From steve+comp.lang.python at pearwood.info Fri Mar 16 12:25:32 2012 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 16 Mar 2012 16:25:32 GMT Subject: Python is readable References: <4f612b19$0$1379$4fafbaef@reader2.news.tin.it> <4f629d27$0$29981$c3e8da3$5496439d@news.astraweb.com> <4f63382b$0$1375$4fafbaef@reader1.news.tin.it> Message-ID: <4f63697c$0$29981$c3e8da3$5496439d@news.astraweb.com> On Fri, 16 Mar 2012 13:55:06 +0100, Kiuhnm wrote: >> I don't understand the reason for $arg1 and $arg2. Is there some reason >> why the code couldn't do this instead? >> >> my(@list1, @list2) = @_; > > @_ contains references to arrays. You can't pass two arrays to a > function. Why ever not? That seems like basic functionality to me. I can't imagine any modern language that lacks such a simple feature. Even Pascal allows you to pass arrays as arguments to functions. Is there some design principle that I'm missing that explains why Perl lacks this feature? -- Steven From steve+comp.lang.python at pearwood.info Fri Mar 16 12:28:41 2012 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 16 Mar 2012 16:28:41 GMT Subject: Python is readable References: <4f612b19$0$1379$4fafbaef@reader2.news.tin.it> <8e72d74f-c844-4de3-8a37-f6b1fdc2291f@y27g2000yqy.googlegroups.com> <50e9ceec-40f1-4ead-b2b6-87328b30d084@ow8g2000pbc.googlegroups.com> <4f61c828$0$1390$4fafbaef@reader2.news.tin.it> <4f61d728$0$1375$4fafbaef@reader2.news.tin.it> <4f61fd0a$0$1389$4fafbaef@reader2.news.tin.it> <4f6280a0$0$29981$c3e8da3$5496439d@news.astraweb.com> <4f6333ca$0$1392$4fafbaef@reader1.news.tin.it> <4f633a1a$0$29981$c3e8da3$5496439d@news.astraweb.com> <9sgsb1FsbpU1@mid.individual.net> Message-ID: <4f636a38$0$29981$c3e8da3$5496439d@news.astraweb.com> On Fri, 16 Mar 2012 13:08:49 +0000, Neil Cerutti wrote: > On 2012-03-16, Steven D'Aprano > wrote: >> A grammarian might very well write: >> >> Your assignment, if you choose to accept it, is to: >> >> 1. Take the bus to Swansea. >> ... >> >> In English, one typical use for colons is to introduce a list or >> sequence of items, including instructions. A sequence of instructions >> is an algorithm, program or routine. You may have heard of them :) > > A grammarian always uses complete sentence before a colon, even when > introducing a list. Ah, perhaps you're talking about *prescriptivist* grammarians, who insist on applying grammatical rules that exist only in their own fevered imagination. Sorry, I was talking about the other sort, the ones who apply the grammatical rules used by people in real life. You know the ones: linguists. My mistake. Colons don't end sentences, therefore there is no need to use a complete sentence before a colon. -- Steven From kiuhnm03.4t.yahoo.it Fri Mar 16 12:31:06 2012 From: kiuhnm03.4t.yahoo.it (Kiuhnm) Date: Fri, 16 Mar 2012 17:31:06 +0100 Subject: Why not use juxtaposition to indicate function application In-Reply-To: References: <42cac695-761e-4cdb-aa3b-7c82789b76f9@h20g2000yqd.googlegroups.com> <4f636391$0$1382$4fafbaef@reader1.news.tin.it> Message-ID: <4f636acb$0$1381$4fafbaef@reader1.news.tin.it> On 3/16/2012 17:13, Prasad, Ramit wrote: >>>> I confess i've indulged in Haskell and found >>>> f a >>>> more readable than >>>> f(a) >>> >>> Hmmm... What about: >>> >>> f a b >>> >>> versus >>> >>> f(a(b)) >>> >>> or was it supposed to be read as >>> >>> f(a)(b) >>> >>> >>> or as >>> >>> f(a, b) >>> >>> ?-) >> >> That would be >> f (a b) # Haskell >> f(a(b)) # Python > > I have not used Haskell so far, but in this case I think I prefer the > 'Explicit is better than implicit.' Are you sure that "call the function f with the params a and b" is better than f a b or f(a,b) ? > I would probably always forget if it should be > > f a b > > or > > f ( a b ) You wouldn't, because Haskel's way is more regular and makes a lot of sense: parentheses are for grouping and that's it. Kiuhnm From steve+comp.lang.python at pearwood.info Fri Mar 16 12:45:55 2012 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 16 Mar 2012 16:45:55 GMT Subject: Why not use juxtaposition to indicate function application References: <42cac695-761e-4cdb-aa3b-7c82789b76f9@h20g2000yqd.googlegroups.com> <4f636391$0$1382$4fafbaef@reader1.news.tin.it> <4f636acb$0$1381$4fafbaef@reader1.news.tin.it> Message-ID: <4f636e43$0$29981$c3e8da3$5496439d@news.astraweb.com> On Fri, 16 Mar 2012 17:31:06 +0100, Kiuhnm wrote: > You wouldn't, because Haskel's way is more regular and makes a lot of > sense: parentheses are for grouping and that's it. If f is a function which normally takes (for the sake of the argument) one argument, then f would call the function with no arguments (which may return a curried function, or may apply default arguments, or perhaps raise an exception). So how would you refer to the function itself without calling it? -- Steven From steve+comp.lang.python at pearwood.info Fri Mar 16 12:48:21 2012 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 16 Mar 2012 16:48:21 GMT Subject: Python is readable References: <4f612b19$0$1379$4fafbaef@reader2.news.tin.it> <8e72d74f-c844-4de3-8a37-f6b1fdc2291f@y27g2000yqy.googlegroups.com> <50e9ceec-40f1-4ead-b2b6-87328b30d084@ow8g2000pbc.googlegroups.com> <4f61c828$0$1390$4fafbaef@reader2.news.tin.it> <4f61d728$0$1375$4fafbaef@reader2.news.tin.it> <4f61fd0a$0$1389$4fafbaef@reader2.news.tin.it> <4f620837$0$1382$4fafbaef@reader2.news.tin.it> <4f627c25$0$1381$4fafbaef@reader2.news.tin.it> <4f62b9be$0$29981$c3e8da3$5496439d@news.astraweb.com> <4f632da5$0$1375$4fafbaef@reader1.news.tin.it> Message-ID: <4f636ed5$0$29981$c3e8da3$5496439d@news.astraweb.com> On Fri, 16 Mar 2012 13:10:12 +0100, Kiuhnm wrote: > Maybe we should define *exactly* what readability is (in less then 500 > lines, if possible). If you can't be bothered to read my post before replying, save yourself some more time and don't bother to reply at all. I quote from the part of the my post you deleted: When people talk about readability, they normally mean to ask how much mental effort is needed to interpret the meaning of the text, not how much time does it take to pass your eyes over the characters. In other words they are actually talking about comprehensibility. Unless I've made a mistake counting, that's less than 500 lines. > According to your view, ASM code is more readable than Python code. It's > just that there's more to read in ASM. What a ridiculous misrepresentation of my position. Readability is not proportional to length. -- Steven From andrea.crotti.0 at gmail.com Fri Mar 16 12:49:17 2012 From: andrea.crotti.0 at gmail.com (Andrea Crotti) Date: Fri, 16 Mar 2012 16:49:17 +0000 Subject: avoid import short-circuiting Message-ID: <4F636F0D.3060006@gmail.com> I started the following small project: https://github.com/AndreaCrotti/import-tree because I would like to find out what exactly depends on what at run-time, using an import hook. It works quite well for small examples but the main problem is that once a module is imported it's added to sys.modules and then it doesn't go through the import hook anymore. I tried to mess around with sys.modules but it might not be a good idea, and it leads to easy infinite loops. Is there a good way to achieve this? I guess I could do the loop detection myself, but that should not be too hard.. Thanks, Andrea From kiuhnm03.4t.yahoo.it Fri Mar 16 12:58:36 2012 From: kiuhnm03.4t.yahoo.it (Kiuhnm) Date: Fri, 16 Mar 2012 17:58:36 +0100 Subject: Python is readable In-Reply-To: <4f63697c$0$29981$c3e8da3$5496439d@news.astraweb.com> References: <4f612b19$0$1379$4fafbaef@reader2.news.tin.it> <4f629d27$0$29981$c3e8da3$5496439d@news.astraweb.com> <4f63382b$0$1375$4fafbaef@reader1.news.tin.it> <4f63697c$0$29981$c3e8da3$5496439d@news.astraweb.com> Message-ID: <4f63713d$0$1374$4fafbaef@reader1.news.tin.it> On 3/16/2012 17:25, Steven D'Aprano wrote: > On Fri, 16 Mar 2012 13:55:06 +0100, Kiuhnm wrote: > > >>> I don't understand the reason for $arg1 and $arg2. Is there some reason >>> why the code couldn't do this instead? >>> >>> my(@list1, @list2) = @_; >> >> @_ contains references to arrays. You can't pass two arrays to a >> function. > > > Why ever not? That seems like basic functionality to me. I can't imagine > any modern language that lacks such a simple feature. Even Pascal allows > you to pass arrays as arguments to functions. > > Is there some design principle that I'm missing that explains why Perl > lacks this feature? Perl uses references only when explicitly told so. For instance, my @a = (1,2,3); my @b = @a; creates two distinct arrays and you can modify @b without touching @a at all. Another odd thing is that Perl "flattens" lists or arrays. If you write my @a = (1,2,3); my @b = (0, at a,4); you'll end up with @b = (0,1,2,3,4). If you want nested data structures, you'll need to use explicit references: my @b = (0,\@a,4); # '\' = take the ref of Now you can write $b[1][0] but that's short-hand for $b[1]->[0] # deref. $b[1] and get the first elem which is short-hand for ${$b[1]}[0] Square brackets build an array and return a reference to it: my $ref = [0,1,2]; (Notice that, in Perl, '$' means one ($ref is one reference), while '@' means many.) Now you can write my @a = (1,[2,3,4],5) because you're putting a reference into $a[1]! So, let's go back to this code: sub pairwise_sum { my($arg1, $arg2) = @_; my(@result) = (); @list1 = @$arg1; @list2 = @$arg2; for($i=0; $i < length(@list1); $i++) { push(@result, $list1[$i] + $list2[$i]); } return(\@result); } Here @list1 and @list2 are copies. No careful Perl programmer would do such extra copies. And no Perl programmer would use a C-style for loop. Kiuhnm From ramit.prasad at jpmorgan.com Fri Mar 16 13:01:28 2012 From: ramit.prasad at jpmorgan.com (Prasad, Ramit) Date: Fri, 16 Mar 2012 17:01:28 +0000 Subject: Python is readable In-Reply-To: <4f63697c$0$29981$c3e8da3$5496439d@news.astraweb.com> References: <4f612b19$0$1379$4fafbaef@reader2.news.tin.it> <4f629d27$0$29981$c3e8da3$5496439d@news.astraweb.com> <4f63382b$0$1375$4fafbaef@reader1.news.tin.it> <4f63697c$0$29981$c3e8da3$5496439d@news.astraweb.com> Message-ID: <5B80DD153D7D744689F57F4FB69AF474026BB7D3@SCACMX008.exchad.jpmchase.net> > >> I don't understand the reason for $arg1 and $arg2. Is there some reason > >> why the code couldn't do this instead? > >> > >> my(@list1, @list2) = @_; > > > > @_ contains references to arrays. You can't pass two arrays to a > > function. > > > Why ever not? That seems like basic functionality to me. I can't imagine > any modern language that lacks such a simple feature. Even Pascal allows > you to pass arrays as arguments to functions. > > Is there some design principle that I'm missing that explains why Perl > lacks this feature? My understanding is that it assigns each scalar argument until it finds a list to assign and then it assigns everything remaining to the list. my @arr = ( 'test', 'blah', '1234', 'boop', 'foo', 'bar' ); my @arr2 = ( 'adsf', 'qwerty' ); print "@arr\n"; my @arr3 = (@arr, @arr2); print "arr3:@arr3\n"; my ($arg1, $arg2, @arg3) = @arr3; print "arg3:@arg3\n"; bash-3.2$ perl temp.pl testblah1234boopfoobar arr3:test blah 1234 boop foo bar adsf qwerty arg3:1234 boop foo bar adsf qwerty I assume this is because it combines both elements of the list into one giant list and then if you try and assign two lists it does not know where to split it. Now if you pass a reference to the two arrays instead of the values it should work as expected, but now you are dealing with pointers / references. bash-3.2$ cat temp.pl my @arr = ( 'test', 'blah', '1234', 'boop', 'foo', 'bar' ); my @arr2 = ( 'adsf', 'qwerty' ); print "@arr\n"; my @arr3 = (\@arr, \@arr2); print "arr3:@arr3\n"; my ($arg1, $arg2, @arg3) = @arr3; print "arg1:@$arg1\narg2:@$arg2\narg3:@arg3\n"; bash-3.2$ perl temp.pl test blah 1234 boop foo bar arr3:ARRAY(0xb2f0f90) ARRAY(0xb2f1020) arg1:test blah 1234 boop foo bar arg2:adsf qwerty arg3: Ramit Ramit Prasad | JPMorgan Chase Investment Bank | Currencies Technology 712 Main Street | Houston, TX 77002 work phone: 713 - 216 - 5423 -- This email is confidential and subject to important disclaimers and conditions including on offers for the purchase or sale of securities, accuracy and completeness of information, viruses, confidentiality, legal privilege, and legal entity disclaimers, available at http://www.jpmorgan.com/pages/disclosures/email. From ethan at stoneleaf.us Fri Mar 16 13:06:31 2012 From: ethan at stoneleaf.us (Ethan Furman) Date: Fri, 16 Mar 2012 10:06:31 -0700 Subject: avoid import short-circuiting In-Reply-To: <4F636F0D.3060006@gmail.com> References: <4F636F0D.3060006@gmail.com> Message-ID: <4F637317.6010403@stoneleaf.us> Andrea Crotti wrote: > I started the following small project: > > https://github.com/AndreaCrotti/import-tree > > because I would like to find out what exactly depends on what at > run-time, using an import hook. > > It works quite well for small examples but the main problem is that once > a module is imported > it's added to sys.modules and then it doesn't go through the import hook > anymore. > > I tried to mess around with sys.modules but it might not be a good idea, > and it leads to easy > infinite loops. > Is there a good way to achieve this? > I guess I could do the loop detection myself, but that should not be too > hard.. I believe sys.modules is a dictionary; you might try replacing it with your own custom dictionary that does whatever when the keys are accessed. ~Ethan~ From kiuhnm03.4t.yahoo.it Fri Mar 16 13:18:21 2012 From: kiuhnm03.4t.yahoo.it (Kiuhnm) Date: Fri, 16 Mar 2012 18:18:21 +0100 Subject: Why not use juxtaposition to indicate function application In-Reply-To: <4f636e43$0$29981$c3e8da3$5496439d@news.astraweb.com> References: <42cac695-761e-4cdb-aa3b-7c82789b76f9@h20g2000yqd.googlegroups.com> <4f636391$0$1382$4fafbaef@reader1.news.tin.it> <4f636acb$0$1381$4fafbaef@reader1.news.tin.it> <4f636e43$0$29981$c3e8da3$5496439d@news.astraweb.com> Message-ID: <4f6375de$0$1382$4fafbaef@reader1.news.tin.it> On 3/16/2012 17:45, Steven D'Aprano wrote: > On Fri, 16 Mar 2012 17:31:06 +0100, Kiuhnm wrote: > >> You wouldn't, because Haskel's way is more regular and makes a lot of >> sense: parentheses are for grouping and that's it. > > If f is a function which normally takes (for the sake of the argument) > one argument, then f would call the function with no arguments (which may > return a curried function, or may apply default arguments, or perhaps > raise an exception). So how would you refer to the function itself > without calling it? Thanks to Referential Transparency, a function with no params is a constant. But that's a good observation. It would cause some problems in Python. ML languages use the empty tuple: f(). Kiuhnm From robert.kern at gmail.com Fri Mar 16 13:19:47 2012 From: robert.kern at gmail.com (Robert Kern) Date: Fri, 16 Mar 2012 17:19:47 +0000 Subject: avoid import short-circuiting In-Reply-To: <4F636F0D.3060006@gmail.com> References: <4F636F0D.3060006@gmail.com> Message-ID: On 3/16/12 4:49 PM, Andrea Crotti wrote: > I started the following small project: > > https://github.com/AndreaCrotti/import-tree > > because I would like to find out what exactly depends on what at run-time, using > an import hook. > > It works quite well for small examples but the main problem is that once a > module is imported > it's added to sys.modules and then it doesn't go through the import hook anymore. > > I tried to mess around with sys.modules but it might not be a good idea, and it > leads to easy > infinite loops. > Is there a good way to achieve this? > I guess I could do the loop detection myself, but that should not be too hard.. You want to monkeypatch __builtin__.__import__() instead. It always gets called. -- Robert Kern "I have come to believe that the whole world is an enigma, a harmless enigma that is made terrible by our own mad attempt to interpret it as though it had an underlying truth." -- Umberto Eco From neilc at norwich.edu Fri Mar 16 13:53:24 2012 From: neilc at norwich.edu (Neil Cerutti) Date: 16 Mar 2012 17:53:24 GMT Subject: Python is readable References: <4f612b19$0$1379$4fafbaef@reader2.news.tin.it> <8e72d74f-c844-4de3-8a37-f6b1fdc2291f@y27g2000yqy.googlegroups.com> <50e9ceec-40f1-4ead-b2b6-87328b30d084@ow8g2000pbc.googlegroups.com> <4f61c828$0$1390$4fafbaef@reader2.news.tin.it> <4f61d728$0$1375$4fafbaef@reader2.news.tin.it> <4f61fd0a$0$1389$4fafbaef@reader2.news.tin.it> <4f6280a0$0$29981$c3e8da3$5496439d@news.astraweb.com> <4f6333ca$0$1392$4fafbaef@reader1.news.tin.it> <4f633a1a$0$29981$c3e8da3$5496439d@news.astraweb.com> <9sgsb1FsbpU1@mid.individual.net> <4f636a38$0$29981$c3e8da3$5496439d@news.astraweb.com> Message-ID: <9shd0kFvgbU1@mid.individual.net> On 2012-03-16, Steven D'Aprano wrote: > Ah, perhaps you're talking about *prescriptivist* grammarians, > who insist on applying grammatical rules that exist only in > their own fevered imagination. Sorry, I was talking about the > other sort, the ones who apply the grammatical rules used by > people in real life. You know the ones: linguists. My mistake. I am not pedantic. You are wrong. -- Neil Cerutti From ian.g.kelly at gmail.com Fri Mar 16 13:59:51 2012 From: ian.g.kelly at gmail.com (Ian Kelly) Date: Fri, 16 Mar 2012 11:59:51 -0600 Subject: Why not use juxtaposition to indicate function application In-Reply-To: <4f636e43$0$29981$c3e8da3$5496439d@news.astraweb.com> References: <42cac695-761e-4cdb-aa3b-7c82789b76f9@h20g2000yqd.googlegroups.com> <4f636391$0$1382$4fafbaef@reader1.news.tin.it> <4f636acb$0$1381$4fafbaef@reader1.news.tin.it> <4f636e43$0$29981$c3e8da3$5496439d@news.astraweb.com> Message-ID: On Fri, Mar 16, 2012 at 10:45 AM, Steven D'Aprano wrote: > On Fri, 16 Mar 2012 17:31:06 +0100, Kiuhnm wrote: > >> You wouldn't, because Haskel's way is more regular and makes a lot of >> sense: parentheses are for grouping and that's it. > > If f is a function which normally takes (for the sake of the argument) > one argument, then f would call the function with no arguments (which may > return a curried function, or may apply default arguments, or perhaps > raise an exception). So how would you refer to the function itself > without calling it? A partial application of f with no arguments is still just f. From steve+comp.lang.python at pearwood.info Fri Mar 16 14:50:31 2012 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 16 Mar 2012 18:50:31 GMT Subject: Python is readable References: <4f612b19$0$1379$4fafbaef@reader2.news.tin.it> <8e72d74f-c844-4de3-8a37-f6b1fdc2291f@y27g2000yqy.googlegroups.com> <50e9ceec-40f1-4ead-b2b6-87328b30d084@ow8g2000pbc.googlegroups.com> <4f61c828$0$1390$4fafbaef@reader2.news.tin.it> <4f61d728$0$1375$4fafbaef@reader2.news.tin.it> <4f61fd0a$0$1389$4fafbaef@reader2.news.tin.it> <4f6280a0$0$29981$c3e8da3$5496439d@news.astraweb.com> <4f6333ca$0$1392$4fafbaef@reader1.news.tin.it> <4f633a1a$0$29981$c3e8da3$5496439d@news.astraweb.com> <9sgsb1FsbpU1@mid.individual.net> <4f636a38$0$29981$c3e8da3$5496439d@news.astraweb.com> <9shd0kFvgbU1@mid.individual.net> Message-ID: <4f638b76$0$29981$c3e8da3$5496439d@news.astraweb.com> On Fri, 16 Mar 2012 17:53:24 +0000, Neil Cerutti wrote: > On 2012-03-16, Steven D'Aprano > wrote: >> Ah, perhaps you're talking about *prescriptivist* grammarians, who >> insist on applying grammatical rules that exist only in their own >> fevered imagination. Sorry, I was talking about the other sort, the >> ones who apply the grammatical rules used by people in real life. You >> know the ones: linguists. My mistake. > > I am not pedantic. You are wrong. Whether you like it or not, it simply is a fact that in English (I won't speak for other languages) people use colons without the first clause *necessarily* being a complete sentence. They write things like this: Star Wars Episode IV: A New Hope Also like these: Example: this is an example of a colon following a sentence fragment. Last update: Oct 4, 2007. Shopping list: - eggs - milk - cheese They even use the reverse construction: Lists, quotations, explanations, examples: some of the things which follow after a colon. Check the use of colons here: http://articles.baltimoresun.com/2012-03-15/features/bal-the-raven-reviews-20120313_1_edgar-allan-poe-john-cusack-mystery-writer I count at least ten colons on the page (including the title) and *not one of them* uses a complete sentence before the colon. While it is common for the clause preceding the colon to be an independent clause (i.e. it would stand alone as a complete sentence) it is not required that it be so. I think I'll end this with a quote from Gore Vidal: "The four most beautiful words in our common language: I told you so." http://grammar.about.com/od/c/g/colon.htm -- Steven From rosuav at gmail.com Fri Mar 16 15:20:17 2012 From: rosuav at gmail.com (Chris Angelico) Date: Sat, 17 Mar 2012 06:20:17 +1100 Subject: Python simulate browser activity In-Reply-To: <214c4c0c-f8ec-4030-946b-8becc8e1aa9c@ur9g2000pbc.googlegroups.com> References: <214c4c0c-f8ec-4030-946b-8becc8e1aa9c@ur9g2000pbc.googlegroups.com> Message-ID: On Fri, Mar 16, 2012 at 1:23 PM, choi2k wrote: > The application aims to simulate user activity including visit a > website and perform some interactive actions (click on the menu, > submit a form, redirect to another pages...etc) > I have found some libraries / plugins which aims to simulate browser > activity but ... none of them support AJAX request and/or running > javascript. > > Here is one of the simple tasks which I would like to do using the > application: > 4. post ajax request using javascript and if the page has been > redirected, load the new page content To the web server, everything is a request. Don't think in terms of Javascript; there is no Javascript, there is no AJAX, there is not even a web browser. There's just a TCP socket connection and an HTTP request. That's all you have. On that basis, your Python script most definitely can simulate the request. It needs simply to make the same HTTP query that the Javascript would have made. The only tricky part is figuring out what that request would be. If you can use a non-SSL connection, that'll make your job easier - just get a proxy or packet sniffer to monitor an actual web browser, then save the request headers and body. You can then replay that using Python; it's not difficult to handle cookies and such, too. Hope that helps! ChrisA From neilc at norwich.edu Fri Mar 16 15:35:34 2012 From: neilc at norwich.edu (Neil Cerutti) Date: 16 Mar 2012 19:35:34 GMT Subject: Python is readable References: <4f612b19$0$1379$4fafbaef@reader2.news.tin.it> <8e72d74f-c844-4de3-8a37-f6b1fdc2291f@y27g2000yqy.googlegroups.com> <50e9ceec-40f1-4ead-b2b6-87328b30d084@ow8g2000pbc.googlegroups.com> <4f61c828$0$1390$4fafbaef@reader2.news.tin.it> <4f61d728$0$1375$4fafbaef@reader2.news.tin.it> <4f61fd0a$0$1389$4fafbaef@reader2.news.tin.it> <4f6280a0$0$29981$c3e8da3$5496439d@news.astraweb.com> <4f6333ca$0$1392$4fafbaef@reader1.news.tin.it> <4f633a1a$0$29981$c3e8da3$5496439d@news.astraweb.com> <9sgsb1FsbpU1@mid.individual.net> <4f636a38$0$29981$c3e8da3$5496439d@news.astraweb.com> <9shd0kFvgbU1@mid.individual.net> <4f638b76$0$29981$c3e8da3$5496439d@news.astraweb.com> Message-ID: <9shj05FabeU1@mid.individual.net> On 2012-03-16, Steven D'Aprano wrote: > On Fri, 16 Mar 2012 17:53:24 +0000, Neil Cerutti wrote: > >> On 2012-03-16, Steven D'Aprano >> wrote: >>> Ah, perhaps you're talking about *prescriptivist* grammarians, who >>> insist on applying grammatical rules that exist only in their own >>> fevered imagination. Sorry, I was talking about the other sort, the >>> ones who apply the grammatical rules used by people in real life. You >>> know the ones: linguists. My mistake. >> >> I am not pedantic. You are wrong. > > Whether you like it or not, it simply is a fact that in English > (I won't speak for other languages) people use colons without > the first clause *necessarily* being a complete sentence. They > write things like this: People spell your name Stephen, sometimes too. Thinking of changing it? Gore Vidal's quote has panache, a valid compensation for breaking the usual rule. How many other uses on that page are similar? -- Neil Cerutti From mwilson at the-wire.com Fri Mar 16 16:01:13 2012 From: mwilson at the-wire.com (Mel Wilson) Date: Fri, 16 Mar 2012 16:01:13 -0400 Subject: Python is readable References: <4f612b19$0$1379$4fafbaef@reader2.news.tin.it> <8e72d74f-c844-4de3-8a37-f6b1fdc2291f@y27g2000yqy.googlegroups.com> <50e9ceec-40f1-4ead-b2b6-87328b30d084@ow8g2000pbc.googlegroups.com> <4f61c828$0$1390$4fafbaef@reader2.news.tin.it> <4f61d728$0$1375$4fafbaef@reader2.news.tin.it> <4f61fd0a$0$1389$4fafbaef@reader2.news.tin.it> <4f6280a0$0$29981$c3e8da3$5496439d@news.astraweb.com> <4f6333ca$0$1392$4fafbaef@reader1.news.tin.it> <4f633a1a$0$29981$c3e8da3$5496439d@news.astraweb.com> <9sgsb1FsbpU1@mid.individual.net> <4f636a38$0$29981$c3e8da3$5496439d@news.astraweb.com> <9shd0kFvgbU1@mid.individual.net> <4f638b76$0$29981$c3e8da3$5496439d@news.astraweb.com> Message-ID: Steven D'Aprano wrote: > On Fri, 16 Mar 2012 17:53:24 +0000, Neil Cerutti wrote: > >> On 2012-03-16, Steven D'Aprano >> wrote: >>> Ah, perhaps you're talking about *prescriptivist* grammarians, who >>> insist on applying grammatical rules that exist only in their own >>> fevered imagination. Sorry, I was talking about the other sort, the >>> ones who apply the grammatical rules used by people in real life. You >>> know the ones: linguists. My mistake. >> >> I am not pedantic. You are wrong. > > > Whether you like it or not, it simply is a fact that in English (I won't > speak for other languages) people use colons without the first clause > *necessarily* being a complete sentence. They write things like this: > > Star Wars Episode IV: A New Hope Come to think of it, just about every "serious" book title works this way. Mel. From ramit.prasad at jpmorgan.com Fri Mar 16 16:04:57 2012 From: ramit.prasad at jpmorgan.com (Prasad, Ramit) Date: Fri, 16 Mar 2012 20:04:57 +0000 Subject: Python is readable In-Reply-To: <9shj05FabeU1@mid.individual.net> References: <4f612b19$0$1379$4fafbaef@reader2.news.tin.it> <8e72d74f-c844-4de3-8a37-f6b1fdc2291f@y27g2000yqy.googlegroups.com> <50e9ceec-40f1-4ead-b2b6-87328b30d084@ow8g2000pbc.googlegroups.com> <4f61c828$0$1390$4fafbaef@reader2.news.tin.it> <4f61d728$0$1375$4fafbaef@reader2.news.tin.it> <4f61fd0a$0$1389$4fafbaef@reader2.news.tin.it> <4f6280a0$0$29981$c3e8da3$5496439d@news.astraweb.com> <4f6333ca$0$1392$4fafbaef@reader1.news.tin.it> <4f633a1a$0$29981$c3e8da3$5496439d@news.astraweb.com> <9sgsb1FsbpU1@mid.individual.net> <4f636a38$0$29981$c3e8da3$5496439d@news.astraweb.com> <9shd0kFvgbU1@mid.individual.net> <4f638b76$0$29981$c3e8da3$5496439d@news.astraweb.com> <9shj05FabeU1@mid.individual.net> Message-ID: <5B80DD153D7D744689F57F4FB69AF474026BBCD8@SCACMX008.exchad.jpmchase.net> > People spell your name Stephen, sometimes too. Thinking of changing it? > Gore Vidal's quote has panache, a valid compensation for breaking the usual rule. How many other uses on that page are similar? He provided common examples and reference links. Seems like a pretty reasonable way of trying to prove a point. If you don't like reference links, what would convince you that the point was correct? I have not seen any counter examples or counter references on your behalf... Ramit Ramit Prasad | JPMorgan Chase Investment Bank | Currencies Technology 712 Main Street | Houston, TX 77002 work phone: 713 - 216 - 5423 -- This email is confidential and subject to important disclaimers and conditions including on offers for the purchase or sale of securities, accuracy and completeness of information, viruses, confidentiality, legal privilege, and legal entity disclaimers, available at http://www.jpmorgan.com/pages/disclosures/email. From ramit.prasad at jpmorgan.com Fri Mar 16 16:14:16 2012 From: ramit.prasad at jpmorgan.com (Prasad, Ramit) Date: Fri, 16 Mar 2012 20:14:16 +0000 Subject: Is it technically possible to give Python option of naming process of running script? In-Reply-To: References: <19118128.4791.1331736187952.JavaMail.geo-discussion-forums@vbai14> <22071354.8904.1331796412001.JavaMail.geo-discussion-forums@vbkc1> Message-ID: <5B80DD153D7D744689F57F4FB69AF474026BBD75@SCACMX008.exchad.jpmchase.net> > I was thinging about daemons and system-type stuff. > > One possible problem with linking from one's home directory is that > home directories are often on different filesystems than /usr/bin (or > wherever python is). Using a symlink doesn't work, the process name > still ends up as python2.6 (or whatever the real binary is called). Try a hardlink instead of symlink? It seems to work for me. Ramit Ramit Prasad | JPMorgan Chase Investment Bank | Currencies Technology 712 Main Street | Houston, TX 77002 work phone: 713 - 216 - 5423 -- This email is confidential and subject to important disclaimers and conditions including on offers for the purchase or sale of securities, accuracy and completeness of information, viruses, confidentiality, legal privilege, and legal entity disclaimers, available at http://www.jpmorgan.com/pages/disclosures/email. From ethan at stoneleaf.us Fri Mar 16 16:30:15 2012 From: ethan at stoneleaf.us (Ethan Furman) Date: Fri, 16 Mar 2012 13:30:15 -0700 Subject: Python is readable In-Reply-To: <9shd0kFvgbU1@mid.individual.net> References: <4f612b19$0$1379$4fafbaef@reader2.news.tin.it> <8e72d74f-c844-4de3-8a37-f6b1fdc2291f@y27g2000yqy.googlegroups.com> <50e9ceec-40f1-4ead-b2b6-87328b30d084@ow8g2000pbc.googlegroups.com> <4f61c828$0$1390$4fafbaef@reader2.news.tin.it> <4f61d728$0$1375$4fafbaef@reader2.news.tin.it> <4f61fd0a$0$1389$4fafbaef@reader2.news.tin.it> <4f6280a0$0$29981$c3e8da3$5496439d@news.astraweb.com> <4f6333ca$0$1392$4fafbaef@reader1.news.tin.it> <4f633a1a$0$29981$c3e8da3$5496439d@news.astraweb.com> <9sgsb1FsbpU1@mid.individual.net> <4f636a38$0$29981$c3e8da3$5496439d@news.astraweb.com> <9shd0kFvgbU1@mid.individual.net> Message-ID: <4F63A2D7.7040309@stoneleaf.us> Neil Cerutti wrote: > On 2012-03-16, Steven D'Aprano wrote: >> Ah, perhaps you're talking about *prescriptivist* grammarians, >> who insist on applying grammatical rules that exist only in >> their own fevered imagination. Sorry, I was talking about the >> other sort, the ones who apply the grammatical rules used by >> people in real life. You know the ones: linguists. My mistake. > > I am not pedantic. You are wrong. > When saying somebody is wrong, you really should back it up with references (wiki, dictionary, etc.). At this point, if I had to decide between Steven and you, I'd go with Steven. Of course, it doesn't hurt that everything he has said matches with my experience on the topic. ~Ethan~ From drsalists at gmail.com Fri Mar 16 16:31:13 2012 From: drsalists at gmail.com (Dan Stromberg) Date: Fri, 16 Mar 2012 13:31:13 -0700 Subject: cannot open shared object file In-Reply-To: <4F62E208.70005@hep.caltech.edu> References: <4F62E208.70005@hep.caltech.edu> Message-ID: A suggestion: 1) strace it. http://stromberg.dnsalias.org/~strombrg/debugging-with-syscall-tracers.html 2) Show the output to a C programmer, or take some educated guesses yourself. On Thu, Mar 15, 2012 at 11:47 PM, Steven Lo wrote: > ** > > Hi, > > We are getting the following error during a 'make' process on a CentOS > release 5.4 system: > > Running mkfontdir... > Creating SELinux policy... > /usr/bin/python: error while loading shared libraries: > libpython2.4.so.1.0: cannot open shared object file: No such file or > directory > > > However, we are able to execute 'python' without any problem > > # which python > /usr/bin/python > > # python > Python 2.4.3 (#1, Sep 3 2009, 15:37:37) > [GCC 4.1.2 20080704 (Red Hat 4.1.2-46)] on linux2 > Type "help", "copyright", "credits" or "license" for more information. > >>> > > > # ldd /usr/bin/python > libpython2.4.so.1.0 => /usr/lib64/libpython2.4.so.1.0 > (0x0000003fb7600000) > libpthread.so.0 => /lib64/libpthread.so.0 (0x0000003b59600000) > libdl.so.2 => /lib64/libdl.so.2 (0x0000003b59200000) > libutil.so.1 => /lib64/libutil.so.1 (0x0000003b64000000) > libm.so.6 => /lib64/libm.so.6 (0x0000003b58e00000) > libc.so.6 => /lib64/libc.so.6 (0x0000003b58a00000) > /lib64/ld-linux-x86-64.so.2 (0x0000003b58600000) > > > # ls -lad /usr/lib64/*python* > lrwxrwxrwx 1 root root 19 Feb 27 21:15 /usr/lib64/libpython2.4.so-> libpython2.4.so.1.0 > -r-xr-xr-x 1 root root 1236344 Sep 3 2009 /usr/lib64/libpython2.4.so.1.0 > drwxr-xr-x 18 root root 20480 Feb 27 21:15 /usr/lib64/python2.4 > > > > In this 'make' process, we are suppose to execute the applicate-specific > python > (/opt/rocks/bin/python) which has static link (not dynamic link) > > # ldd /opt/rocks/bin/python > libpthread.so.0 => /lib64/libpthread.so.0 (0x0000003b59600000) > libdl.so.2 => /lib64/libdl.so.2 (0x0000003b59200000) > libutil.so.1 => /lib64/libutil.so.1 (0x0000003b64000000) > libstdc++.so.6 => /usr/lib64/libstdc++.so.6 (0x0000003b6b400000) > libm.so.6 => /lib64/libm.so.6 (0x0000003b58e00000) > libgcc_s.so.1 => /lib64/libgcc_s.so.1 (0x0000003b67c00000) > libc.so.6 => /lib64/libc.so.6 (0x0000003b58a00000) > /lib64/ld-linux-x86-64.so.2 (0x0000003b58600000) > > > > Basically, we try to understand: > * why /opt/rocks/bin/python not being used ? > * why /usr/bin/python can not find the dynamic library > > > Please let us know if you have any suggestion on how to troubleshoot this > problem. > > If this is not the list to ask this type of question, please point us to > the appropriate > list. > > > Thanks. > > S. > > > -- > http://mail.python.org/mailman/listinfo/python-list > > -------------- next part -------------- An HTML attachment was scrubbed... URL: From invalid at invalid.invalid Fri Mar 16 16:54:16 2012 From: invalid at invalid.invalid (Grant Edwards) Date: Fri, 16 Mar 2012 20:54:16 +0000 (UTC) Subject: Is it technically possible to give Python option of naming process of running script? References: <19118128.4791.1331736187952.JavaMail.geo-discussion-forums@vbai14> <22071354.8904.1331796412001.JavaMail.geo-discussion-forums@vbkc1> Message-ID: On 2012-03-16, Prasad, Ramit wrote: > >> One possible problem with linking from one's home directory is that >> home directories are often on different filesystems than /usr/bin (or >> wherever python is). Using a symlink doesn't work, the process name >> still ends up as python2.6 (or whatever the real binary is called). > > Try a hardlink instead of symlink? It seems to work for me. Not across different filesystems -- which was what I was talking about. -- Grant Edwards grant.b.edwards Yow! As President I have at to go vacuum my coin gmail.com collection! From storchaka at gmail.com Fri Mar 16 16:57:04 2012 From: storchaka at gmail.com (Serhiy Storchaka) Date: Fri, 16 Mar 2012 22:57:04 +0200 Subject: Why not use juxtaposition to indicate function application In-Reply-To: <4f636e43$0$29981$c3e8da3$5496439d@news.astraweb.com> References: <42cac695-761e-4cdb-aa3b-7c82789b76f9@h20g2000yqd.googlegroups.com> <4f636391$0$1382$4fafbaef@reader1.news.tin.it> <4f636acb$0$1381$4fafbaef@reader1.news.tin.it> <4f636e43$0$29981$c3e8da3$5496439d@news.astraweb.com> Message-ID: 16.03.12 18:45, Steven D'Aprano ???????(??): > If f is a function which normally takes (for the sake of the argument) > one argument, then f would call the function with no arguments (which may > return a curried function, or may apply default arguments, or perhaps > raise an exception). So how would you refer to the function itself > without calling it? lambda:f From rosuav at gmail.com Fri Mar 16 16:59:18 2012 From: rosuav at gmail.com (Chris Angelico) Date: Sat, 17 Mar 2012 07:59:18 +1100 Subject: Python is readable In-Reply-To: <4F63A2D7.7040309@stoneleaf.us> References: <4f612b19$0$1379$4fafbaef@reader2.news.tin.it> <8e72d74f-c844-4de3-8a37-f6b1fdc2291f@y27g2000yqy.googlegroups.com> <50e9ceec-40f1-4ead-b2b6-87328b30d084@ow8g2000pbc.googlegroups.com> <4f61c828$0$1390$4fafbaef@reader2.news.tin.it> <4f61d728$0$1375$4fafbaef@reader2.news.tin.it> <4f61fd0a$0$1389$4fafbaef@reader2.news.tin.it> <4f6280a0$0$29981$c3e8da3$5496439d@news.astraweb.com> <4f6333ca$0$1392$4fafbaef@reader1.news.tin.it> <4f633a1a$0$29981$c3e8da3$5496439d@news.astraweb.com> <9sgsb1FsbpU1@mid.individual.net> <4f636a38$0$29981$c3e8da3$5496439d@news.astraweb.com> <9shd0kFvgbU1@mid.individual.net> <4F63A2D7.7040309@stoneleaf.us> Message-ID: On Sat, Mar 17, 2012 at 7:30 AM, Ethan Furman wrote: > Neil Cerutti wrote: >> >> I am not pedantic. You are wrong. >> > > When saying somebody is wrong, you really should back it up with references > (wiki, dictionary, etc.). I interpret this simply as a witty statement, one that can be thrown into any argument that has descended into pure pedantry. As such, it needs no backing, and is completely on topic for this thread (if not for python-list itself). Personally, I find it amusing. ChrisA From clp2 at rebertia.com Fri Mar 16 17:02:51 2012 From: clp2 at rebertia.com (Chris Rebert) Date: Fri, 16 Mar 2012 14:02:51 -0700 Subject: Why not use juxtaposition to indicate function application In-Reply-To: References: <42cac695-761e-4cdb-aa3b-7c82789b76f9@h20g2000yqd.googlegroups.com> <4f636391$0$1382$4fafbaef@reader1.news.tin.it> <4f636acb$0$1381$4fafbaef@reader1.news.tin.it> <4f636e43$0$29981$c3e8da3$5496439d@news.astraweb.com> Message-ID: On Fri, Mar 16, 2012 at 1:57 PM, Serhiy Storchaka wrote: > 16.03.12 18:45, Steven D'Aprano ???????(??): >> If f is a function which normally takes (for the sake of the argument) >> one argument, then f would call the function with no arguments (which may >> return a curried function, or may apply default arguments, or perhaps >> raise an exception). So how would you refer to the function itself >> without calling it? > > lambda:f Doesn't help; wouldn't the lambda be implicitly called? Cheers, Chris From andrea.crotti.0 at gmail.com Fri Mar 16 18:04:04 2012 From: andrea.crotti.0 at gmail.com (Andrea Crotti) Date: Fri, 16 Mar 2012 22:04:04 +0000 Subject: avoid import short-circuiting In-Reply-To: References: <4F636F0D.3060006@gmail.com> Message-ID: <4F63B8D4.8010103@gmail.com> On 03/16/2012 05:19 PM, Robert Kern wrote: > On 3/16/12 4:49 PM, Andrea Crotti wrote: >> I started the following small project: >> >> https://github.com/AndreaCrotti/import-tree >> >> because I would like to find out what exactly depends on what at >> run-time, using >> an import hook. >> >> It works quite well for small examples but the main problem is that >> once a >> module is imported >> it's added to sys.modules and then it doesn't go through the import >> hook anymore. >> >> I tried to mess around with sys.modules but it might not be a good >> idea, and it >> leads to easy >> infinite loops. >> Is there a good way to achieve this? >> I guess I could do the loop detection myself, but that should not be >> too hard.. > > You want to monkeypatch __builtin__.__import__() instead. It always > gets called. > Seems like a good idea :) My first attempt failes though def full(module): from __builtin__ import __import__ ls = [] orig = __import__ def my_import(name): ls.append(name) orig(name) __import__ = my_import __import__(module) __import__ = orig return ls it imports only the first element and doesn't import the dependencies.. Any hints? From storchaka at gmail.com Fri Mar 16 18:14:19 2012 From: storchaka at gmail.com (Serhiy Storchaka) Date: Sat, 17 Mar 2012 00:14:19 +0200 Subject: Why not use juxtaposition to indicate function application In-Reply-To: References: <42cac695-761e-4cdb-aa3b-7c82789b76f9@h20g2000yqd.googlegroups.com> <4f636391$0$1382$4fafbaef@reader1.news.tin.it> <4f636acb$0$1381$4fafbaef@reader1.news.tin.it> <4f636e43$0$29981$c3e8da3$5496439d@news.astraweb.com> Message-ID: 16.03.12 23:02, Chris Rebert ???????(??): > On Fri, Mar 16, 2012 at 1:57 PM, Serhiy Storchaka wrote: >> lambda:f > > Doesn't help; wouldn't the lambda be implicitly called? No, the lambda is only for declaration. I prefer to use braces for lambda syntax, it will be fine with 'if' and 'while' functions. But all this for some other, fictitious, language, not for Python. From ian.g.kelly at gmail.com Fri Mar 16 18:18:07 2012 From: ian.g.kelly at gmail.com (Ian Kelly) Date: Fri, 16 Mar 2012 16:18:07 -0600 Subject: avoid import short-circuiting In-Reply-To: <4F63B8D4.8010103@gmail.com> References: <4F636F0D.3060006@gmail.com> <4F63B8D4.8010103@gmail.com> Message-ID: On Fri, Mar 16, 2012 at 4:04 PM, Andrea Crotti wrote: >> You want to monkeypatch __builtin__.__import__() instead. It always gets >> called. >> > > Seems like a good idea :) > > My first attempt failes though > > > def full(module): > ? ?from __builtin__ import __import__ > ? ?ls = [] > ? ?orig = __import__ > > ? ?def my_import(name): > ? ? ? ?ls.append(name) > ? ? ? ?orig(name) > > ? ?__import__ = my_import > ? ?__import__(module) > ? ?__import__ = orig > ? ?return ls > > > it imports only the first element and doesn't import the dependencies.. > Any hints? You didn't actually monkey-patch it. You just created a local called __import__ that stores a wrapped version of the function. You need to actually replace it in the __builtin__ module: import __builtin__ __builtin__.__import__ = my_import Cheers, Ian From robert.kern at gmail.com Fri Mar 16 18:20:15 2012 From: robert.kern at gmail.com (Robert Kern) Date: Fri, 16 Mar 2012 22:20:15 +0000 Subject: avoid import short-circuiting In-Reply-To: <4F63B8D4.8010103@gmail.com> References: <4F636F0D.3060006@gmail.com> <4F63B8D4.8010103@gmail.com> Message-ID: On 3/16/12 10:04 PM, Andrea Crotti wrote: > On 03/16/2012 05:19 PM, Robert Kern wrote: >> On 3/16/12 4:49 PM, Andrea Crotti wrote: >>> I started the following small project: >>> >>> https://github.com/AndreaCrotti/import-tree >>> >>> because I would like to find out what exactly depends on what at run-time, using >>> an import hook. >>> >>> It works quite well for small examples but the main problem is that once a >>> module is imported >>> it's added to sys.modules and then it doesn't go through the import hook >>> anymore. >>> >>> I tried to mess around with sys.modules but it might not be a good idea, and it >>> leads to easy >>> infinite loops. >>> Is there a good way to achieve this? >>> I guess I could do the loop detection myself, but that should not be too hard.. >> >> You want to monkeypatch __builtin__.__import__() instead. It always gets called. >> > > Seems like a good idea :) > > My first attempt failes though > > > def full(module): > from __builtin__ import __import__ > ls = [] > orig = __import__ > > def my_import(name): > ls.append(name) > orig(name) > > __import__ = my_import > __import__(module) > __import__ = orig > return ls > > > it imports only the first element and doesn't import the dependencies.. > Any hints? You need to replace it in __builtin__. Don't forget to handle all of the arguments. import __builtin__ orig_import = __builtin__.__import__ all_imports = [] def my_import(*args, **kwds): module = orig_import(*args, **kwds) # Get the fully-qualified module name from the module object itself # instead of trying to compute it yourself. all_imports.append(module.__name__) return module __builtin__.__import__ = my_import For extra points, make a context manager that hooks and then unhooks your custom importer. You may also want to take a look at an import profiler that I once made: http://www.enthought.com/~rkern/cgi-bin/hgwebdir.cgi/import_profiler/file/tip/import_profiler.py#l23 -- Robert Kern "I have come to believe that the whole world is an enigma, a harmless enigma that is made terrible by our own mad attempt to interpret it as though it had an underlying truth." -- Umberto Eco From andrea.crotti.0 at gmail.com Fri Mar 16 19:14:16 2012 From: andrea.crotti.0 at gmail.com (Andrea Crotti) Date: Fri, 16 Mar 2012 23:14:16 +0000 Subject: avoid import short-circuiting In-Reply-To: References: <4F636F0D.3060006@gmail.com> <4F63B8D4.8010103@gmail.com> Message-ID: <4F63C948.8020700@gmail.com> On 03/16/2012 10:20 PM, Robert Kern wrote: > On 3/16/12 10:04 PM, Andrea Crotti wrote: >> On 03/16/2012 05:19 PM, Robert Kern wrote: >>> On 3/16/12 4:49 PM, Andrea Crotti wrote: >>>> I started the following small project: >>>> >>>> https://github.com/AndreaCrotti/import-tree >>>> >>>> because I would like to find out what exactly depends on what at >>>> run-time, using >>>> an import hook. >>>> >>>> It works quite well for small examples but the main problem is that >>>> once a >>>> module is imported >>>> it's added to sys.modules and then it doesn't go through the import >>>> hook >>>> anymore. >>>> >>>> I tried to mess around with sys.modules but it might not be a good >>>> idea, and it >>>> leads to easy >>>> infinite loops. >>>> Is there a good way to achieve this? >>>> I guess I could do the loop detection myself, but that should not >>>> be too hard.. >>> >>> You want to monkeypatch __builtin__.__import__() instead. It always >>> gets called. >>> >> >> Seems like a good idea :) >> >> My first attempt failes though >> >> >> def full(module): >> from __builtin__ import __import__ >> ls = [] >> orig = __import__ >> >> def my_import(name): >> ls.append(name) >> orig(name) >> >> __import__ = my_import >> __import__(module) >> __import__ = orig >> return ls >> >> >> it imports only the first element and doesn't import the dependencies.. >> Any hints? > > You need to replace it in __builtin__. Don't forget to handle all of > the arguments. > > > import __builtin__ > > orig_import = __builtin__.__import__ > > all_imports = [] > > def my_import(*args, **kwds): > module = orig_import(*args, **kwds) > # Get the fully-qualified module name from the module object itself > # instead of trying to compute it yourself. > all_imports.append(module.__name__) > return module > > __builtin__.__import__ = my_import > > > For extra points, make a context manager that hooks and then unhooks your > custom importer. > > You may also want to take a look at an import profiler that I once made: > > http://www.enthought.com/~rkern/cgi-bin/hgwebdir.cgi/import_profiler/file/tip/import_profiler.py#l23 > > Very nice thanks, here it is class ImportMock: def _my_import(self, *args, **kwargs): self.ls.append(args[0]) self.orig(*args, **kwargs) def __enter__(self): self.orig = __builtin__.__import__ self.ls = [] __builtin__.__import__ = self._my_import return self def __exit__(self, type, value, traceback): __builtin__.__import__ = self.orig now I only need to make it create also the graph and then I should be done :) From torriem at gmail.com Fri Mar 16 19:39:21 2012 From: torriem at gmail.com (Michael Torrie) Date: Fri, 16 Mar 2012 17:39:21 -0600 Subject: Python is readable In-Reply-To: <4f636ed5$0$29981$c3e8da3$5496439d@news.astraweb.com> References: <4f612b19$0$1379$4fafbaef@reader2.news.tin.it> <8e72d74f-c844-4de3-8a37-f6b1fdc2291f@y27g2000yqy.googlegroups.com> <50e9ceec-40f1-4ead-b2b6-87328b30d084@ow8g2000pbc.googlegroups.com> <4f61c828$0$1390$4fafbaef@reader2.news.tin.it> <4f61d728$0$1375$4fafbaef@reader2.news.tin.it> <4f61fd0a$0$1389$4fafbaef@reader2.news.tin.it> <4f620837$0$1382$4fafbaef@reader2.news.tin.it> <4f627c25$0$1381$4fafbaef@reader2.news.tin.it> <4f62b9be$0$29981$c3e8da3$5496439d@news.astraweb.com> <4f632da5$0$1375$4fafbaef@reader1.news.tin.it> <4f636ed5$0$29981$c3e8da3$5496439d@news.astraweb.com> Message-ID: <4F63CF29.7010906@gmail.com> On 03/16/2012 10:48 AM, Steven D'Aprano wrote: > On Fri, 16 Mar 2012 13:10:12 +0100, Kiuhnm wrote: > >> Maybe we should define *exactly* what readability is (in less then 500 >> lines, if possible). > > If you can't be bothered to read my post before replying, save yourself > some more time and don't bother to reply at all. > > I quote from the part of the my post you deleted: > > When people talk about readability, they normally mean to > ask how much mental effort is needed to interpret the > meaning of the text, not how much time does it take to > pass your eyes over the characters. In other words they > are actually talking about comprehensibility. > > > Unless I've made a mistake counting, that's less than 500 lines. > > >> According to your view, ASM code is more readable than Python code. It's >> just that there's more to read in ASM. > > What a ridiculous misrepresentation of my position. Readability is not > proportional to length. For someone who claims he's merely examining the language and seeking to learn about it, Kiuhnm is jumping awfully quickly into the realm of trolling. From kiuhnm03.4t.yahoo.it Fri Mar 16 21:21:32 2012 From: kiuhnm03.4t.yahoo.it (Kiuhnm) Date: Sat, 17 Mar 2012 02:21:32 +0100 Subject: Currying in Python Message-ID: <4f63e724$0$1386$4fafbaef@reader1.news.tin.it> Here we go. ---> def genCur(f, unique = True, minArgs = -1): """ Generates a 'curried' version of a function. """ def geng(curArgs, curKwargs): def g(*args, **kwargs): nonlocal f, curArgs, curKwargs, minArgs; # our STATIC data if len(args) or len(kwargs): # Allocates data for the next 'g'. We don't want to modify our # static data. newArgs = curArgs[:]; newKwargs = dict.copy(curKwargs); # Adds positional arguments. newArgs += args; # Adds/updates keyword arguments. if unique: # We don't want repeated keyword arguments. for k in kwargs.keys(): if k in newKwargs: raise(Exception("Repeated kw arg while unique = True")); newKwargs.update(kwargs); # Checks whether it's time to evaluate f. if minArgs >= 0 and minArgs <= len(newArgs) + len(newKwargs): return f(*newArgs, **newKwargs); # f has enough args else: return geng(newArgs, newKwargs); # f needs some more args else: return f(*curArgs, **curKwargs); # the caller forced the evaluation return g; return geng([], {}); def cur(f, minArgs = -1): return genCur(f, True, minArgs); def curr(f, minArgs = -1): return genCur(f, False, minArgs); # Simple Function. def f(a, b, c, d, e, f, g = 100): print(a, b, c, d, e, f, g); # NOTE: '<====' means "this line prints to the screen". # Example 1. c1 = cur(f)(1); c2 = c1(2, d = 4); # Note that c is still unbound c3 = c2(3)(f = 6)(e = 5); # now c = 3 c3(); # () forces the evaluation <==== c4 = c2(30)(f = 60)(e = 50); # now c = 30 c4(); # () forces the evaluation <==== print("\n------\n"); # Example 2. c1 = curr(f)(1, 2)(3, 4); # curr = cur with possibly repeated # keyword args c2 = c1(e = 5)(f = 6)(e = 10)(); # ops... we repeated 'e' because we <==== # changed our mind about it! # again, () forces the evaluation print("\n------\n"); # Example 3. c1 = cur(f, 6); # forces the evaluation after 6 arguments c2 = c1(1, 2, 3); # num args = 3 c3 = c2(4, f = 6); # num args = 5 c4 = c3(5); # num args = 6 ==> evalution <==== c5 = c3(5, g = -1); # num args = 7 ==> evaluation <==== # we can specify more than 6 arguments, but # 6 are enough to force the evaluation print("\n------\n"); # Example 4. def printTree(func, level = -1): if level == -1: printTree(cur(func), level + 1); elif level == 6: func(g = '')(); # or just func('')() else: printTree(func(0), level + 1); printTree(func(1), level + 1); printTree(f); print("\n------\n"); def f2(*args): print(", ".join(["%3d"%(x) for x in args])); def stress(f, n): if n: stress(f(n), n - 1) else: f(); # enough is enough stress(cur(f2), 100); <--- Kiuhnm From robert.kern at gmail.com Fri Mar 16 21:22:05 2012 From: robert.kern at gmail.com (Robert Kern) Date: Sat, 17 Mar 2012 01:22:05 +0000 Subject: avoid import short-circuiting In-Reply-To: <4F63C948.8020700@gmail.com> References: <4F636F0D.3060006@gmail.com> <4F63B8D4.8010103@gmail.com> <4F63C948.8020700@gmail.com> Message-ID: On 3/16/12 11:14 PM, Andrea Crotti wrote: > Very nice thanks, here it is > class ImportMock: > > def _my_import(self, *args, **kwargs): > self.ls.append(args[0]) > self.orig(*args, **kwargs) There's a bug here. You need to return the module object you got from calling self.orig(). By the way, you really should follow my example of getting the .__name__ from the module object instead of the argument in order to properly account for relative imports inside packages. __import__() will be passed the relative name, not the fully-qualified name. -- Robert Kern "I have come to believe that the whole world is an enigma, a harmless enigma that is made terrible by our own mad attempt to interpret it as though it had an underlying truth." -- Umberto Eco From nagle at animats.com Fri Mar 16 21:44:41 2012 From: nagle at animats.com (John Nagle) Date: Fri, 16 Mar 2012 18:44:41 -0700 Subject: Does anyone actually use PyPy in production? Message-ID: <4f63ec8b$0$11975$742ec2ed@news.sonic.net> Does anyone run PyPy in production? John Nagle From steve+comp.lang.python at pearwood.info Fri Mar 16 21:46:59 2012 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 17 Mar 2012 01:46:59 GMT Subject: Currying in Python References: <4f63e724$0$1386$4fafbaef@reader1.news.tin.it> Message-ID: <4f63ed13$0$29981$c3e8da3$5496439d@news.astraweb.com> On Sat, 17 Mar 2012 02:21:32 +0100, Kiuhnm wrote: > Here we go. [snip code] Have you looked at functools.partial? import functools new_func = functools.partial(func, ham, spam=23) (I am aware that, technically, currying and partial function application are not quite the same thing, but it seems to me on a superficial reading that your function performs partial function application rather than actually currying. But I haven't read it in enough detail to be sure.) -- Steven From NA Fri Mar 16 21:51:49 2012 From: NA (NA) Date: Fri, 16 Mar 2012 21:51:49 -0400 Subject: Python simulate browser activity References: <214c4c0c-f8ec-4030-946b-8becc8e1aa9c@ur9g2000pbc.googlegroups.com> Message-ID: <2012031621514936408-NA@news.giganews.com> selenium is the best bet. http://github.com/antlong/selenium From dcday137 at gmail.com Fri Mar 16 21:56:41 2012 From: dcday137 at gmail.com (Collin Day) Date: Fri, 16 Mar 2012 19:56:41 -0600 Subject: PIL for py3k not picking up external libraries Message-ID: <4F63EF59.6010605@gmail.com> Hi all, I am using python 3.2 on an amd64 Gentoo system. I was trying to compile an unofficial version of PIL to work in 3.2 that I found here: http://www.lfd.uci.edu/~gohlke/pythonlibs Anyway, when I run the setup.py to compile the source, it doesn't pick up tkinter, zlib, or freetype. When I use pdb to step through the code where it is looking for libraries (for example zlib here), I make it all the way into unixcompiler.py: > /usr/lib64/python3.2/distutils/unixccompiler.py(318)find_library_file() -> shared_f = self.library_filename(lib, lib_type='shared') which returns 'libz.cpython-32.so' or 'libtcl8.5.cpython-32.py', depending on what it is looking for. If I step in further to ccompiler.py "") 881 fmt = getattr(self, lib_type + "_lib_format") 882 ext = getattr(self, lib_type + "_lib_extension") 883 884 -> dir, base = os.path.split(libname) 885 filename = fmt % (base, ext) The extension returns .cpython-32.so I have a lot of these extensions for site packages, but how do I generate libraries compatible with this for say tkinter, zlib, etc. For example, I see libtcl8.5.so, but no libtcl8.5.cpython-32.so. Can someone tell me what I am missing? Thanks! From java at leeclemens.net Fri Mar 16 22:12:14 2012 From: java at leeclemens.net (Lee Clemens) Date: Fri, 16 Mar 2012 22:12:14 -0400 Subject: Daemonization / Popen / pipe issue Message-ID: <4F63F2FE.1030409@leeclemens.net> Hello, I am new to the list, have many years of Java experience but an fairly new to Python. I am hoping this is an issue caused by my misuse of Python in a multi-threaded way, but so far no one has identified such to me. I have a multi-threaded application, each thread has an instance of a class which calls Popen. The command(s) being executed (shell=True) include pipes. The errors I have seen involve "broken pipe" and unexepected output (as demonstrated in the test case). This issues only seem to occur when the application is "daemonized", using a double-fork and os.dup2, as shown here: http://www.jejik.com/articles/2007/02/a_simple_unix_linux_daemon_in_python/ I have provided a test-case here: https://gist.github.com/2054194 Please test how flipping DAEMONIZE between True and False yield different results. I have used this on Red Hat/CentOS/Fedora using Python 2.6.x (latest) and 2.7.1 and on Solaris with 2.6.4. I know it's a bit long, but I have added comments to explain where the oddities appear and how it is called (fairly straight-forward multi-threaded). Please keep in mind this is a test-case based on a much larger application - I understand a lot of pieces included here are not necessary in this case. Any assistance/advice would be greatly appreciated. Thanks, Lee From steve+comp.lang.python at pearwood.info Fri Mar 16 22:14:54 2012 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 17 Mar 2012 02:14:54 GMT Subject: Currying in Python References: <4f63e724$0$1386$4fafbaef@reader1.news.tin.it> <4f63ed13$0$29981$c3e8da3$5496439d@news.astraweb.com> Message-ID: <4f63f39e$0$29981$c3e8da3$5496439d@news.astraweb.com> On Sat, 17 Mar 2012 01:46:59 +0000, Steven D'Aprano wrote: > On Sat, 17 Mar 2012 02:21:32 +0100, Kiuhnm wrote: > >> Here we go. > [snip code] > > > Have you looked at functools.partial? > > > import functools > new_func = functools.partial(func, ham, spam=23) > > > (I am aware that, technically, currying and partial function application > are not quite the same thing, but it seems to me on a superficial > reading that your function performs partial function application rather > than actually currying. But I haven't read it in enough detail to be > sure.) Okay, that was an incredibly superficial reading, because on a second reading, I can see it's nothing like partial function application. Sorry for the noise. -- Steven From research at johnohagan.com Fri Mar 16 23:37:26 2012 From: research at johnohagan.com (John O'Hagan) Date: Sat, 17 Mar 2012 14:37:26 +1100 Subject: Daemonization / Popen / pipe issue In-Reply-To: <4F63F2FE.1030409@leeclemens.net> References: <4F63F2FE.1030409@leeclemens.net> Message-ID: <20120317143726.7134d2b04d56d1759d8eeeb6@johnohagan.com> On Fri, 16 Mar 2012 22:12:14 -0400 Lee Clemens wrote: > > I have a multi-threaded application, each thread has an instance of a class > which calls Popen. The command(s) being executed (shell=True) include pipes. > The errors I have seen involve "broken pipe" and unexepected output (as > demonstrated in the test case). > > This issues only seem to occur when the application is "daemonized", using a > double-fork and os.dup2, as shown here: > http://www.jejik.com/articles/2007/02/a_simple_unix_linux_daemon_in_python/ > > I have provided a test-case here: https://gist.github.com/2054194 > > Please test how flipping DAEMONIZE between True and False yield different > results. I haven't looked at your test case yet, but a possible cause is the fact that the main application (or main thread) exits if it has finished executing and only daemon threads remain. This can abruptly terminate threads which may be busy, for example, communicating via a pipe. The best solution IMO is not to use daemon threads, but to give all threads a way to terminate cleanly before the main thread does, even if this means using a flag or the like. HTH, John From tjreedy at udel.edu Sat Mar 17 00:38:27 2012 From: tjreedy at udel.edu (Terry Reedy) Date: Sat, 17 Mar 2012 00:38:27 -0400 Subject: Why not use juxtaposition to indicate function application In-Reply-To: <42cac695-761e-4cdb-aa3b-7c82789b76f9@h20g2000yqd.googlegroups.com> References: <42cac695-761e-4cdb-aa3b-7c82789b76f9@h20g2000yqd.googlegroups.com> Message-ID: On 3/16/2012 9:14 AM, bruno.desthuilliers at gmail.com wrote: > On Mar 16, 1:45 pm, Ray Song wrote: >> I confess i've indulged in Haskell and found >> f a >> more readable than >> f(a) > > Hmmm... What about: > > f a b > > versus > > f(a(b)) > > or was it supposed to be read as > > f(a)(b) > > > or as > > f(a, b) > > ?-) One also has to consider Python calls with *args, **kwds, and arg=obj. These are all compile-time SyntaxErrors unless inside parens that follow a expression. Also, function calls, especially in a functional language without side-effects, do not usually occur in isolation. 'f(a) + 3' would have to be written as '(f a) + 3', so saving of parens anyway. Also, is 'f a - 2' f(a -2) or f(a, -2)? A new precedence rule is needed to disambiguage. -- Terry Jan Reedy From tjreedy at udel.edu Sat Mar 17 01:09:04 2012 From: tjreedy at udel.edu (Terry Reedy) Date: Sat, 17 Mar 2012 01:09:04 -0400 Subject: Python is readable In-Reply-To: <9sgsb1FsbpU1@mid.individual.net> References: <4f612b19$0$1379$4fafbaef@reader2.news.tin.it> <8e72d74f-c844-4de3-8a37-f6b1fdc2291f@y27g2000yqy.googlegroups.com> <50e9ceec-40f1-4ead-b2b6-87328b30d084@ow8g2000pbc.googlegroups.com> <4f61c828$0$1390$4fafbaef@reader2.news.tin.it> <4f61d728$0$1375$4fafbaef@reader2.news.tin.it> <4f61fd0a$0$1389$4fafbaef@reader2.news.tin.it> <4f6280a0$0$29981$c3e8da3$5496439d@news.astraweb.com> <4f6333ca$0$1392$4fafbaef@reader1.news.tin.it> <4f633a1a$0$29981$c3e8da3$5496439d@news.astraweb.com> <9sgsb1FsbpU1@mid.individual.net> Message-ID: On 3/16/2012 9:08 AM, Neil Cerutti wrote: > A grammarian always uses complete sentence before a colon, even > when introducing a list. The Chicago Manual of Style*, 13th edition, says "The colon is used to mark a discontinuity of grammatical construction greater than that indicated by the semicolon and less than that indicated by the period." While most of the examples in that section have what would be a complete sentence before the colon, not all do. Not in that section is this, from the Table of Contents: "Documentation: References, Notes, and Bibliographies". Here are a couple more from their Library of Congress Cataloging in Publication data: "Rev. ed. of: A manual of style." and "Bibliography: p.". And in letters: "To:", "From:", and "Date:" *A major style guide for general American writing and publication: used by some as the 'Bible'. -- Terry Jan Reedy From tjreedy at udel.edu Sat Mar 17 01:20:15 2012 From: tjreedy at udel.edu (Terry Reedy) Date: Sat, 17 Mar 2012 01:20:15 -0400 Subject: Does anyone actually use PyPy in production? In-Reply-To: <4f63ec8b$0$11975$742ec2ed@news.sonic.net> References: <4f63ec8b$0$11975$742ec2ed@news.sonic.net> Message-ID: On 3/16/2012 9:44 PM, John Nagle wrote: > Does anyone run PyPy in production? The pypy list, accessible via gmane, might be a better place to ask. But my impression is yes, and that they are getting commercial $$$ support. -- Terry Jan Reedy From rustompmody at gmail.com Sat Mar 17 01:26:28 2012 From: rustompmody at gmail.com (rusi) Date: Fri, 16 Mar 2012 22:26:28 -0700 (PDT) Subject: Haskellizing python (was Why not use juxtaposition to indicate function application) References: Message-ID: On Mar 16, 5:45?pm, Ray Song wrote: > I confess i've indulged in Haskell and found > ? ? f a > more readable than > ? ? f(a) > > And why aren't functions curried (partially applied function is another function which takes the rest arguments) by default? > > Thanks in advance for any suggestions. > > -- > Ray In Haskell a b c d is short for (((a b) c) d) This works nicely when the latter is commonly required, as for example happens in a language where what one may call 'the currying convention' is the default. It fails when one wants the opposite convention -- a (b (c (d))) -- which may be called the 'function-composition convention.' The fact that the default convention in haskell is not always a good idea is seen in the existence of a special application operator $ with low precedence which allows a (b (c (d))) to be written as a $ b $ c $ d It is another matter: as someone pointed out that () is overloaded in python to denote: - function application - tupling - grouping Comes from the hegemony of ASCII. A from-first-principles unicode language would use more of these: http://xahlee.org/comp/unicode_matching_brackets.html From cosmius at gmail.com Sat Mar 17 01:30:34 2012 From: cosmius at gmail.com (Cosmia Luna) Date: Fri, 16 Mar 2012 22:30:34 -0700 (PDT) Subject: How to get a reference of the 'owner' class to which a method belongs in Python 3.X? Message-ID: <20411334.2044.1331962234309.JavaMail.geo-discussion-forums@yncd8> I'm porting my existing work to Python 3.X, but... class Foo: def bar(self): pass mthd = Foo.bar assert mthd.im_class is Foo # this does not work in py3k So, how can I get a reference to Foo? This is important when writing decorators, the only way I can think out is: class Foo: def bar(self): 'Foo' # manually declare the owner class pass mthd = Foo.bar assert mthd.__globals__[mthd.__doc__] is Foo # this works class Child(Foo): def bar(self): 'Child' # I have to override all method defined by bar but do nothing pass child_mthd = Child.bar assert child_mthd.__globals__[child_mthd.__doc__] is Child # this works But the code above is quite ugly and abuses the __doc__. Is there any equivalent in py3k of im_class? Thanks, Cosmia From clp2 at rebertia.com Sat Mar 17 01:51:05 2012 From: clp2 at rebertia.com (Chris Rebert) Date: Fri, 16 Mar 2012 22:51:05 -0700 Subject: How to get a reference of the 'owner' class to which a method belongs in Python 3.X? In-Reply-To: <20411334.2044.1331962234309.JavaMail.geo-discussion-forums@yncd8> References: <20411334.2044.1331962234309.JavaMail.geo-discussion-forums@yncd8> Message-ID: On Fri, Mar 16, 2012 at 10:30 PM, Cosmia Luna wrote: > I'm porting my existing work to Python 3.X, but... > > class Foo: > ? ?def bar(self): > ? ? ? ?pass > > mthd = Foo.bar > > assert mthd.im_class is Foo # this does not work in py3k > > So, how can I get a reference to Foo? This is important when writing > decorators, Could you give an example of such a decorator? Cheers, Chris From dcday137 at gmail.com Sat Mar 17 02:05:29 2012 From: dcday137 at gmail.com (Collin Day) Date: Sat, 17 Mar 2012 00:05:29 -0600 Subject: Question about python 3.2 distutils Message-ID: <4F6429A9.1010008@gmail.com> Hi all, I have a question about python 3.2 distutils on a Gentoo amd64 system. When I open an ipython session and import distutils.unixcompiler and then check the shared library extension with UnixCCompiler.shared)lib_extension, it returns '.so', as I would expect. When I run a setup.py in an unofficial PIL source that should work with python 3.2 and step into it, I hit the line: find_library_file(self, "tcl" + version): feature.tcl = "tcl"+TCL_VERSION self is: <__main__.pil_build_ext object at 0xf44510> find_library_file is: def find_library_file(self, library): return self.compiler.find_library_file(self.compiler.library_dirs, library) self.compiler is library is: 'tcl8.5' when I check the shared_lib_extension it returns '.cpython-32.so' - not '.so' This is causing a problem because, for example, I have libtcl8.5.so, but it is looking for libtcl8.5.cpython-32.so. Where is this shared lib extension being determined? After all, in an interactive session, it is just looking for .so, but in the script, it is looking for .cpython-32.so. I tried grep -R cpython-32 * in the top level directory of ther PIL source I am using, thinking it may be ovridden or set somewhere, but it turns up empty. Can anyone tell me what the difference is? I posted earlier, but I just noticed this difference between interactive session and script. Thanks! From orgnut at yahoo.com Sat Mar 17 02:39:28 2012 From: orgnut at yahoo.com (Larry Hudson) Date: Fri, 16 Mar 2012 23:39:28 -0700 Subject: Why not use juxtaposition to indicate function application In-Reply-To: References: Message-ID: On 03/16/2012 05:45 AM, Ray Song wrote: > I confess i've indulged in Haskell and found > f a > more readable than > f(a) > > And why aren't functions curried (partially applied function is another function which takes the rest arguments) by default? > > > Thanks in advance for any suggestions. > > -- > Ray My suggestion is that your question is irrelevant -- Python and Haskell are two different languages each with different syntax rules and coming from different backgrounds. I would say that trying to make any language look like some other is, at best, misguided. Simply learn, and get used to, the language you're using AS IT IS DEFINED, not as you think it should be. If you want to combine the features of two different languages, write a new one -- don't expect that existing languages are going to change due to someone's whim. To expect otherwise is simply a waste of time. As to readability, I would suggest that that's more a function of what you're used to than any inherent language syntax rules. If my comments seem harsh -- sorry 'bout that. I'm old, and sometimes tend to be a curmugeon. And as a completely irrelevant aside concerning readability: Is anyone familiar with the IOCCC (International Obfuscated C Coding Contest)? The object is to write the most obscure, but functional, C code possible. I haven't looked at any of this for many years myself, but I just Googled it to see that this contest is still going on. Anyone familiar with C might find it amusing to take a look... -=- Larry -=- From chardster at gmail.com Sat Mar 17 03:34:57 2012 From: chardster at gmail.com (Richard Thomas) Date: Sat, 17 Mar 2012 00:34:57 -0700 (PDT) Subject: How to get a reference of the 'owner' class to which a method belongs in Python 3.X? In-Reply-To: <20411334.2044.1331962234309.JavaMail.geo-discussion-forums@yncd8> References: <20411334.2044.1331962234309.JavaMail.geo-discussion-forums@yncd8> Message-ID: <32504391.2142.1331969697343.JavaMail.geo-discussion-forums@ynil17> On Saturday, 17 March 2012 05:30:34 UTC, Cosmia Luna wrote: > I'm porting my existing work to Python 3.X, but... > > class Foo: > def bar(self): > pass > > mthd = Foo.bar > > assert mthd.im_class is Foo # this does not work in py3k mthd.im_class is the class of mthd.im_self not the class that defined the method. > > So, how can I get a reference to Foo? This is important when writing > decorators, the only way I can think out is: Not sure what sort of decorators you're writing. Examples? You can achieve this with metaclasses but if you're using classes from someone else's code this doesn't necessarily work. Something in inspect module can probably do the trick, check the docs. Frankly though it sounds messy no matter what. It might be better to find an alternative to knowing the class. > class Foo: > def bar(self): > 'Foo' # manually declare the owner class > pass > > mthd = Foo.bar > > assert mthd.__globals__[mthd.__doc__] is Foo # this works > > class Child(Foo): > def bar(self): > 'Child' # I have to override all method defined by bar but do nothing > pass > > child_mthd = Child.bar > > assert child_mthd.__globals__[child_mthd.__doc__] is Child # this works > > But the code above is quite ugly and abuses the __doc__. Is there any > equivalent in py3k of im_class? > > Thanks, > Cosmia From cosmius at gmail.com Sat Mar 17 04:11:17 2012 From: cosmius at gmail.com (Cosmia Luna) Date: Sat, 17 Mar 2012 01:11:17 -0700 (PDT) Subject: How to get a reference of the 'owner' class to which a method belongs in Python 3.X? In-Reply-To: <32504391.2142.1331969697343.JavaMail.geo-discussion-forums@ynil17> References: <20411334.2044.1331962234309.JavaMail.geo-discussion-forums@yncd8> <32504391.2142.1331969697343.JavaMail.geo-discussion-forums@ynil17> Message-ID: <2929404.2007.1331971877783.JavaMail.geo-discussion-forums@ynbo9> On Saturday, March 17, 2012 3:34:57 PM UTC+8, Richard Thomas wrote: > On Saturday, 17 March 2012 05:30:34 UTC, Cosmia Luna wrote: > > I'm porting my existing work to Python 3.X, but... > > > > class Foo: > > def bar(self): > > pass > > > > mthd = Foo.bar > > > > assert mthd.im_class is Foo # this does not work in py3k > > mthd.im_class is the class of mthd.im_self not the class that defined the method. > > > > > So, how can I get a reference to Foo? This is important when writing > > decorators, the only way I can think out is: > > Not sure what sort of decorators you're writing. Examples? A decorator is not necessary but a similar function accept a method. I don't like any of existing web frameworks and try to write one via werkzeug from pocoo. from myapp.controllers import RootController from werkzeug.routing import Map, Rule from werkzeug.exceptions import HTTPException from werkzeug.wrappers import Request url_map = Map([ Rule('/', endpoint=RootController.index), Rule('/about', endpoint=RootController.about), Rule('/contact', endpoint=RootController.contact), Rule('//', endpoint=RootController.otheraction) ]) def application(environ, start_response): #this is a WSGI 1.0 app bound_url_map = url_map.bind_to_environ(environ) try: endpoint, args = bound_url_map.match() except HTTPException, e: return e(environ, start_response) Controller = endpoint.im_class controller = Controller(Request(environ)) if hasattr(controller, '__before__'): controller.__before__() endpoint(controller) if hasattr(controller, '__after__'): controller.__after__() response = controller.__get_response__(): return response(environ, start_response) This is a Pylons-style application, but I don't like others in Pylons. > > You can achieve this with metaclasses but if you're using classes from someone else's code this doesn't necessarily work. Something in inspect module can probably do the trick, check the docs. Frankly though it sounds messy no matter what. It might be better to find an alternative to knowing the class. > > > class Foo: > > def bar(self): > > 'Foo' # manually declare the owner class > > pass > > > > mthd = Foo.bar > > > > assert mthd.__globals__[mthd.__doc__] is Foo # this works > > > > class Child(Foo): > > def bar(self): > > 'Child' # I have to override all method defined by bar but do nothing > > pass > > > > child_mthd = Child.bar > > > > assert child_mthd.__globals__[child_mthd.__doc__] is Child # this works > > > > But the code above is quite ugly and abuses the __doc__. Is there any > > equivalent in py3k of im_class? > > > > Thanks, > > Cosmia From __peter__ at web.de Sat Mar 17 05:25:06 2012 From: __peter__ at web.de (Peter Otten) Date: Sat, 17 Mar 2012 10:25:06 +0100 Subject: How to get a reference of the 'owner' class to which a method belongs in Python 3.X? References: <20411334.2044.1331962234309.JavaMail.geo-discussion-forums@yncd8> Message-ID: Cosmia Luna wrote: > I'm porting my existing work to Python 3.X, but... > > class Foo: > def bar(self): > pass > > mthd = Foo.bar > > assert mthd.im_class is Foo # this does not work in py3k > > So, how can I get a reference to Foo? This is important when writing > decorators, the only way I can think out is: > > class Foo: > def bar(self): > 'Foo' # manually declare the owner class > pass > > mthd = Foo.bar > > assert mthd.__globals__[mthd.__doc__] is Foo # this works > > class Child(Foo): > def bar(self): > 'Child' # I have to override all method defined by bar but do > nothing pass > > child_mthd = Child.bar > > assert child_mthd.__globals__[child_mthd.__doc__] is Child # this works > > But the code above is quite ugly and abuses the __doc__. Is there any > equivalent in py3k of im_class? class set_class: def __init__(self, method): self.method = method def __get__(self, instance, class_): if instance is None: method = self.method def f(*args, **kw): return method(*args, **kw) f.im_class = class_ f.__name__ = method.__name__ return f return self.method.__get__(instance, class_) class Foo: def __init__(self, name): self.name = name @set_class def bar(self): print("%s says hello from bar()" % self) def __str__(self): return self.name class Bar(Foo): pass assert Foo.bar.im_class is Foo assert Bar.bar.im_class is Bar Foo("Fred").bar() Foo.bar(Foo("Fred")) Bar("Fred").bar() Bar.bar(Bar("Fred")) The cleaner approach is probably: Rule('//', endpoint=(RootController, RootController.otheraction)) ... Controller, method = endpoint controller = Controller(Request(environ)) ... method(controller) From steve+comp.lang.python at pearwood.info Sat Mar 17 06:01:37 2012 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 17 Mar 2012 10:01:37 GMT Subject: How to get a reference of the 'owner' class to which a method belongs in Python 3.X? References: <20411334.2044.1331962234309.JavaMail.geo-discussion-forums@yncd8> Message-ID: <4f646101$0$29981$c3e8da3$5496439d@news.astraweb.com> On Fri, 16 Mar 2012 22:30:34 -0700, Cosmia Luna wrote: > I'm porting my existing work to Python 3.X, but... > > class Foo: > def bar(self): > pass > > mthd = Foo.bar > > assert mthd.im_class is Foo # this does not work in py3k > > So, how can I get a reference to Foo? This is important when writing > decorators, the only way I can think out is: I don't believe you can get a reference to Foo just by inspecting the function object Foo.bar. (In Python 2.x, Foo.bar would be an unbound method, but they no longer exist in Python 3.x.) > class Foo: > def bar(self): > 'Foo' # manually declare the owner class > pass A better approach might be to inject a reference to the class after the event, using a class decorator: function = type(lambda: None) def inject_class(cls): for name, obj in vars(cls).items(): if type(obj) is function: obj.owner_class = cls return cls And in use: py> @inject_class ... class Test: ... a = 1 ... b = 2 ... def method(self, x): ... return (x, self) ... py> Test.a 1 py> Test.method py> Test.method.owner_class is Test True Does this help? -- Steven From cosmius at gmail.com Sat Mar 17 06:04:58 2012 From: cosmius at gmail.com (Cosmia Luna) Date: Sat, 17 Mar 2012 03:04:58 -0700 (PDT) Subject: How to get a reference of the 'owner' class to which a method belongs in Python 3.X? In-Reply-To: References: <20411334.2044.1331962234309.JavaMail.geo-discussion-forums@yncd8> Message-ID: <31776112.2291.1331978698664.JavaMail.geo-discussion-forums@ynne2> On Saturday, March 17, 2012 5:25:06 PM UTC+8, Peter Otten wrote: > Cosmia Luna wrote: > > > I'm porting my existing work to Python 3.X, but... > > > > class Foo: > > def bar(self): > > pass > > > > mthd = Foo.bar > > > > assert mthd.im_class is Foo # this does not work in py3k > > > > So, how can I get a reference to Foo? This is important when writing > > decorators, the only way I can think out is: > > > > class Foo: > > def bar(self): > > 'Foo' # manually declare the owner class > > pass > > > > mthd = Foo.bar > > > > assert mthd.__globals__[mthd.__doc__] is Foo # this works > > > > class Child(Foo): > > def bar(self): > > 'Child' # I have to override all method defined by bar but do > > nothing pass > > > > child_mthd = Child.bar > > > > assert child_mthd.__globals__[child_mthd.__doc__] is Child # this works > > > > But the code above is quite ugly and abuses the __doc__. Is there any > > equivalent in py3k of im_class? > > class set_class: > def __init__(self, method): > self.method = method > def __get__(self, instance, class_): > if instance is None: > method = self.method > def f(*args, **kw): > return method(*args, **kw) > f.im_class = class_ > f.__name__ = method.__name__ > return f > return self.method.__get__(instance, class_) > > class Foo: > def __init__(self, name): > self.name = name > @set_class > def bar(self): > print("%s says hello from bar()" % self) > def __str__(self): > return self.name > > class Bar(Foo): > pass > > assert Foo.bar.im_class is Foo > assert Bar.bar.im_class is Bar > > Foo("Fred").bar() > Foo.bar(Foo("Fred")) > > Bar("Fred").bar() > Bar.bar(Bar("Fred")) > > The cleaner approach is probably: > > Rule('//', endpoint=(RootController, RootController.otheraction)) > ... > Controller, method = endpoint > controller = Controller(Request(environ)) > ... > method(controller) That's exactly what I want, and I think you're right, the approach below is cleaner. Rule('//', endpoint=(RootController, RootController.otheraction)). Thanks a lot. Cosmia From cosmius at gmail.com Sat Mar 17 06:04:58 2012 From: cosmius at gmail.com (Cosmia Luna) Date: Sat, 17 Mar 2012 03:04:58 -0700 (PDT) Subject: How to get a reference of the 'owner' class to which a method belongs in Python 3.X? In-Reply-To: References: <20411334.2044.1331962234309.JavaMail.geo-discussion-forums@yncd8> Message-ID: <31776112.2291.1331978698664.JavaMail.geo-discussion-forums@ynne2> On Saturday, March 17, 2012 5:25:06 PM UTC+8, Peter Otten wrote: > Cosmia Luna wrote: > > > I'm porting my existing work to Python 3.X, but... > > > > class Foo: > > def bar(self): > > pass > > > > mthd = Foo.bar > > > > assert mthd.im_class is Foo # this does not work in py3k > > > > So, how can I get a reference to Foo? This is important when writing > > decorators, the only way I can think out is: > > > > class Foo: > > def bar(self): > > 'Foo' # manually declare the owner class > > pass > > > > mthd = Foo.bar > > > > assert mthd.__globals__[mthd.__doc__] is Foo # this works > > > > class Child(Foo): > > def bar(self): > > 'Child' # I have to override all method defined by bar but do > > nothing pass > > > > child_mthd = Child.bar > > > > assert child_mthd.__globals__[child_mthd.__doc__] is Child # this works > > > > But the code above is quite ugly and abuses the __doc__. Is there any > > equivalent in py3k of im_class? > > class set_class: > def __init__(self, method): > self.method = method > def __get__(self, instance, class_): > if instance is None: > method = self.method > def f(*args, **kw): > return method(*args, **kw) > f.im_class = class_ > f.__name__ = method.__name__ > return f > return self.method.__get__(instance, class_) > > class Foo: > def __init__(self, name): > self.name = name > @set_class > def bar(self): > print("%s says hello from bar()" % self) > def __str__(self): > return self.name > > class Bar(Foo): > pass > > assert Foo.bar.im_class is Foo > assert Bar.bar.im_class is Bar > > Foo("Fred").bar() > Foo.bar(Foo("Fred")) > > Bar("Fred").bar() > Bar.bar(Bar("Fred")) > > The cleaner approach is probably: > > Rule('//', endpoint=(RootController, RootController.otheraction)) > ... > Controller, method = endpoint > controller = Controller(Request(environ)) > ... > method(controller) That's exactly what I want, and I think you're right, the approach below is cleaner. Rule('//', endpoint=(RootController, RootController.otheraction)). Thanks a lot. Cosmia From steve+comp.lang.python at pearwood.info Sat Mar 17 07:18:47 2012 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 17 Mar 2012 11:18:47 GMT Subject: Using non-dict namespaces in functions Message-ID: <4f647317$0$29981$c3e8da3$5496439d@news.astraweb.com> Inspired by the new collections.ChainMap in Python 3.3 http://docs.python.org/dev/library/collections.html#collections.ChainMap I would like to experiment with similar non-dictionary namespaces in Python 3.2. My starting point is these two recipes, adapted for Python 3.2: http://code.activestate.com/recipes/305268/ http://code.activestate.com/recipes/577434/ Or for simplicity, here's a mock version: from collections import Mapping class MockChainMap(Mapping): def __getitem__(self, key): if key == 'a': return 1 elif key == 'b': return 2 raise KeyError(key) def __len__(self): return 2 def __iter__(self): yield 'a' yield 'b' Note that it is important for my purposes that MockChainMap does not inherit from dict. Now I try to create a function that uses a MockChainMap instead of a dict for its globals: function = type(lambda: None) f = lambda x: (a+b+x) g = function(f.__code__, MockChainMap(), 'g') And that's where I get into trouble: Traceback (most recent call last): File "", line 1, in TypeError: function() argument 2 must be dict, not MockChainMap How do I build a function with globals set to a non-dict mapping? If this can't be done, any suggestions for how I might proceed? -- Steven From cosmius at gmail.com Sat Mar 17 08:21:02 2012 From: cosmius at gmail.com (Cosmia Luna) Date: Sat, 17 Mar 2012 05:21:02 -0700 (PDT) Subject: How to get a reference of the 'owner' class to which a method belongs in Python 3.X? In-Reply-To: References: <20411334.2044.1331962234309.JavaMail.geo-discussion-forums@yncd8> Message-ID: <23527589.2560.1331986862750.JavaMail.geo-discussion-forums@ynmb12> On Saturday, March 17, 2012 6:04:58 PM UTC+8, Cosmia Luna wrote: > On Saturday, March 17, 2012 5:25:06 PM UTC+8, Peter Otten wrote: > > Cosmia Luna wrote: > > > > > I'm porting my existing work to Python 3.X, but... > > > > > > class Foo: > > > def bar(self): > > > pass > > > > > > mthd = Foo.bar > > > > > > assert mthd.im_class is Foo # this does not work in py3k > > > > > > So, how can I get a reference to Foo? This is important when writing > > > decorators, the only way I can think out is: > > > > > > class Foo: > > > def bar(self): > > > 'Foo' # manually declare the owner class > > > pass > > > > > > mthd = Foo.bar > > > > > > assert mthd.__globals__[mthd.__doc__] is Foo # this works > > > > > > class Child(Foo): > > > def bar(self): > > > 'Child' # I have to override all method defined by bar but do > > > nothing pass > > > > > > child_mthd = Child.bar > > > > > > assert child_mthd.__globals__[child_mthd.__doc__] is Child # this works > > > > > > But the code above is quite ugly and abuses the __doc__. Is there any > > > equivalent in py3k of im_class? > > > > class set_class: > > def __init__(self, method): > > self.method = method > > def __get__(self, instance, class_): > > if instance is None: > > method = self.method > > def f(*args, **kw): > > return method(*args, **kw) > > f.im_class = class_ > > f.__name__ = method.__name__ > > return f > > return self.method.__get__(instance, class_) > > > > class Foo: > > def __init__(self, name): > > self.name = name > > @set_class > > def bar(self): > > print("%s says hello from bar()" % self) > > def __str__(self): > > return self.name > > > > class Bar(Foo): > > pass > > > > assert Foo.bar.im_class is Foo > > assert Bar.bar.im_class is Bar > > > > Foo("Fred").bar() > > Foo.bar(Foo("Fred")) > > > > Bar("Fred").bar() > > Bar.bar(Bar("Fred")) > > > > The cleaner approach is probably: > > > > Rule('//', endpoint=(RootController, RootController.otheraction)) > > ... > > Controller, method = endpoint > > controller = Controller(Request(environ)) > > ... > > method(controller) > > > That's exactly what I want, and I think you're right, the approach below is cleaner. > Rule('//', endpoint=(RootController, RootController.otheraction)). > > Thanks a lot. > Cosmia Oh I'm wrong. If I use a decorator, the decorator will NEVER get the owner class even in Python 2.X. The function is just plain function instead of unbound method before the code of a class is fully evaluated. So the decorator ALWAYS receives a plain function. I'll look into the module inspect and try to get the frame of calling... Cosmia From cosmius at gmail.com Sat Mar 17 08:21:02 2012 From: cosmius at gmail.com (Cosmia Luna) Date: Sat, 17 Mar 2012 05:21:02 -0700 (PDT) Subject: How to get a reference of the 'owner' class to which a method belongs in Python 3.X? In-Reply-To: References: <20411334.2044.1331962234309.JavaMail.geo-discussion-forums@yncd8> Message-ID: <23527589.2560.1331986862750.JavaMail.geo-discussion-forums@ynmb12> On Saturday, March 17, 2012 6:04:58 PM UTC+8, Cosmia Luna wrote: > On Saturday, March 17, 2012 5:25:06 PM UTC+8, Peter Otten wrote: > > Cosmia Luna wrote: > > > > > I'm porting my existing work to Python 3.X, but... > > > > > > class Foo: > > > def bar(self): > > > pass > > > > > > mthd = Foo.bar > > > > > > assert mthd.im_class is Foo # this does not work in py3k > > > > > > So, how can I get a reference to Foo? This is important when writing > > > decorators, the only way I can think out is: > > > > > > class Foo: > > > def bar(self): > > > 'Foo' # manually declare the owner class > > > pass > > > > > > mthd = Foo.bar > > > > > > assert mthd.__globals__[mthd.__doc__] is Foo # this works > > > > > > class Child(Foo): > > > def bar(self): > > > 'Child' # I have to override all method defined by bar but do > > > nothing pass > > > > > > child_mthd = Child.bar > > > > > > assert child_mthd.__globals__[child_mthd.__doc__] is Child # this works > > > > > > But the code above is quite ugly and abuses the __doc__. Is there any > > > equivalent in py3k of im_class? > > > > class set_class: > > def __init__(self, method): > > self.method = method > > def __get__(self, instance, class_): > > if instance is None: > > method = self.method > > def f(*args, **kw): > > return method(*args, **kw) > > f.im_class = class_ > > f.__name__ = method.__name__ > > return f > > return self.method.__get__(instance, class_) > > > > class Foo: > > def __init__(self, name): > > self.name = name > > @set_class > > def bar(self): > > print("%s says hello from bar()" % self) > > def __str__(self): > > return self.name > > > > class Bar(Foo): > > pass > > > > assert Foo.bar.im_class is Foo > > assert Bar.bar.im_class is Bar > > > > Foo("Fred").bar() > > Foo.bar(Foo("Fred")) > > > > Bar("Fred").bar() > > Bar.bar(Bar("Fred")) > > > > The cleaner approach is probably: > > > > Rule('//', endpoint=(RootController, RootController.otheraction)) > > ... > > Controller, method = endpoint > > controller = Controller(Request(environ)) > > ... > > method(controller) > > > That's exactly what I want, and I think you're right, the approach below is cleaner. > Rule('//', endpoint=(RootController, RootController.otheraction)). > > Thanks a lot. > Cosmia Oh I'm wrong. If I use a decorator, the decorator will NEVER get the owner class even in Python 2.X. The function is just plain function instead of unbound method before the code of a class is fully evaluated. So the decorator ALWAYS receives a plain function. I'll look into the module inspect and try to get the frame of calling... Cosmia From antti.ylikoski at tkk.fi Sat Mar 17 10:03:52 2012 From: antti.ylikoski at tkk.fi (Antti J Ylikoski) Date: Sat, 17 Mar 2012 16:03:52 +0200 Subject: Programming D. E. Knuth in Python with the Deterministic Finite Automaton construct Message-ID: In his legendary book series The Art of Computer Programming, Professor Donald E. Knuth presents many of his algorithms in the form that they have been divided in several individual phases, with instructions to GOTO to another phase interspersed in the text of the individual phases. I. e. they look like the following, purely invented, example: (Knuth is being clearer than me below.....) A1. (Do the work of Phase A1.) If then go to Phase A5, otherwise continue. A2. (Do some work.) If go to Phase A4. A3. (Some more work.) A4. (Do something.) If go to Phase A1. A5. (Something more). If then go to Phase A2, otherwise end. I came across the problem, which would be the clearest way to program such algorithms with a programming language such as Python, which has no GOTO statement. It struck me that the above construction actually is a modified Deterministic Finite Automaton with states A1 -- A5 + [END], transferring to different states, not on read input, but according to conditions in the running program. So one very clear way to program Knuth with Python is the following kind of a construct. continueLoop = 1 nextState = "A1" while continueLoop: if nextState == "A1": # (Do the work of Phase A1.) if : nextState = "A5" elif nextState == "A2": # (Do some work.) if zorp: nextState = "A4" else: nextState = "A3" elif nextState == "A3": # (Some more work.) nextState = "A4" elif nextState == "A4": # (Do something.) if ZZZ: nextState = "A1" else: nextState = "A5" elif nextState == "A5": # (Something more). if foobar: nextState = "A2" else: continueLoop = 0 else: error("Impossible -- I quit!\n") Following is a working Python function which iteratively calculates the lexicographically ordered permutations of integers [1, 2, 3, 4, ..., n], where n is an arbitary integer. The function was written after D. E. Knuth with the abovementioned DFA construct. def iterAllPerm(n): # iteratively generate all permutations of n integers 1-n # After Donald Knuth, The Art of Computer Programming, Vol4, # Fascicle 2, # ISBN 0-201-85393-0. See pp. 39--40. listofPerm = [] # list of lists to collect permutations continueLoop = 1 # indicates whether to continue the iteration nextStat = "L1" # next phase in Knuth's text a = list(range(0, n+1)) # [0, 1, 2, 3, 4, ..., n] -- see Knuth while continueLoop: if nextStat == "L1": app = listofPerm.append(a[1:n+1]) nextStat = "L2" continueLoop = 1 elif nextStat == "L2": j = n - 1 while a[j] >= a[j+1]: j -= 1 if j == 0: continueLoop = 0 nextStat = "Finis Algorithm" else: continueLoop = 1 nextStat = "L3" elif nextStat == "L3": l = n while a[j] >= a[l]: l -= 1 temp = a[j] a[j] = a[l] a[l] = temp nextStat = "L4" continueLoop = 1 elif nextStat == "L4": k = j + 1 l = n while k < l: temp = a[k] a[k] = a[l] a[l] = temp k += 1 l -= 1 nextStat = "L1" continueLoop = 1 else: continueLoop = 0 error("Impossible -- I quit!\n") return(listofPerm) kind regards, Antti J Ylikoski Helsinki, Finland, the EU From gandalf at shopzeus.com Sat Mar 17 10:13:16 2012 From: gandalf at shopzeus.com (Laszlo Nagy) Date: Sat, 17 Mar 2012 15:13:16 +0100 Subject: urllib.urlretrieve never returns??? Message-ID: <4F649BFC.1080601@shopzeus.com> See attached example code. I have a program that calls exactly the same code, and here is the strange thing about it: * Program is started as "start.py", e.g. with an open console. In this case, the program works! * Program is started as "start.pyw", e.g. with no open console under Windows 7 64bit - the program does not work! In the later case, "log.txt" only contains "#1" and nothing else. If I look at pythonw.exe from task manager, then its shows +1 thread every time I click the button, and "#1" is appended to the file. Seems like urllib.urlretrieve() does not return at all! Using wx.PySimpleApp(redirect=True) does not help either - nothing is printed on the redirected console. Unfortunately, I cannot send the whole program, because it is too big and also because it is confidental. Question is: how is it possible that urllib.urlretrieve() does not return? It is part of a system library. What I could have possibly done to screw it up? And moreover, how is it possible that it does not return ONLY when the program is started with pythonw.exe? Thanks, Laszlo -------------- next part -------------- An HTML attachment was scrubbed... URL: -------------- next part -------------- An embedded and charset-unspecified text was scrubbed... Name: test.py URL: From mwilson at the-wire.com Sat Mar 17 10:39:38 2012 From: mwilson at the-wire.com (Mel Wilson) Date: Sat, 17 Mar 2012 10:39:38 -0400 Subject: Programming D. E. Knuth in Python with the Deterministic Finite Automaton construct References: Message-ID: Antti J Ylikoski wrote: > > In his legendary book series The Art of Computer Programming, > Professor Donald E. Knuth presents many of his algorithms in the form > that they have been divided in several individual phases, with > instructions to GOTO to another phase interspersed in the text of the > individual phases. > > > > I. e. they look like the following, purely invented, example: (Knuth is > being clearer than me below.....) > > > > A1. (Do the work of Phase A1.) If then go to Phase A5, > otherwise continue. > > A2. (Do some work.) If go to Phase A4. > > A3. (Some more work.) > > A4. (Do something.) If go to Phase A1. > > A5. (Something more). If then go to Phase A2, otherwise > end. > > > > I came across the problem, which would be the clearest way to program > such algorithms with a programming language such as Python, which has > no GOTO statement. It struck me that the above construction actually > is a modified Deterministic Finite Automaton with states A1 -- A5 + > [END], transferring to different states, not on read input, but > according to conditions in the running program. > > So one very clear way to program Knuth with Python is the following > kind of a construct. Yeah. This is an idea that came up during the '70s after Dijkstra published his "GOTO Considered Harmful". Model the execution pointer as a state, and then explicit changes to the execution pointer (prohibited in GOTO-less languages) get replaced by assignments to the state. It preserves the objectionable part of GOTO: that there's no easy way to predict the conditions that any statement might execute under. You can't understand any of the program until you understand all of the program. I think Knuth kept the assembly-language model for his algorithms because it promotes his real goal, which is mathematical analysis of the performance of the algorithms. It helps that his algorithms are very short. As "the quickest way to get a Knuth algorithm running in Python", this is a pretty good idea. My own preference is to get the algo "really" coded in Python, but that usually takes a fair bit of time and effort. Mel. From kiuhnm03.4t.yahoo.it Sat Mar 17 10:45:45 2012 From: kiuhnm03.4t.yahoo.it (Kiuhnm) Date: Sat, 17 Mar 2012 15:45:45 +0100 Subject: Programming D. E. Knuth in Python with the Deterministic Finite Automaton construct In-Reply-To: References: Message-ID: <4f64a3a0$0$1386$4fafbaef@reader2.news.tin.it> On 3/17/2012 15:03, Antti J Ylikoski wrote: > In his legendary book series The Art of Computer Programming, > Professor Donald E. Knuth presents many of his algorithms in the form > that they have been divided in several individual phases, with > instructions to GOTO to another phase interspersed in the text of the > individual phases. > > > > I. e. they look like the following, purely invented, example: (Knuth is > being clearer than me below.....) > > > > A1. (Do the work of Phase A1.) If then go to Phase A5, > otherwise continue. > > A2. (Do some work.) If go to Phase A4. > > A3. (Some more work.) > > A4. (Do something.) If go to Phase A1. > > A5. (Something more). If then go to Phase A2, otherwise > end. > > > > I came across the problem, which would be the clearest way to program > such algorithms with a programming language such as Python, which has > no GOTO statement. It struck me that the above construction actually > is a modified Deterministic Finite Automaton with states A1 -- A5 + > [END], transferring to different states, not on read input, but > according to conditions in the running program. A1 and A5 are NOT states: they're labels. There is no garanteed bijection from labels to states. > So one very clear way to program Knuth with Python is the following > kind of a construct. [...] Your way is easy, but the result is poor. Your should try to rewrite it. Decompilers do exactly that. Kiuhnm From torriem at gmail.com Sat Mar 17 11:01:59 2012 From: torriem at gmail.com (Michael Torrie) Date: Sat, 17 Mar 2012 09:01:59 -0600 Subject: Programming D. E. Knuth in Python with the Deterministic Finite Automaton construct In-Reply-To: <4f64a3a0$0$1386$4fafbaef@reader2.news.tin.it> References: <4f64a3a0$0$1386$4fafbaef@reader2.news.tin.it> Message-ID: <4F64A767.4060505@gmail.com> On 03/17/2012 08:45 AM, Kiuhnm wrote: > Your way is easy, but the result is poor. In what way? What is your recommended way? > Your should try to rewrite it. > Decompilers do exactly that. Decompilers rewrite code for people? That's really neat. From kiuhnm03.4t.yahoo.it Sat Mar 17 11:12:29 2012 From: kiuhnm03.4t.yahoo.it (Kiuhnm) Date: Sat, 17 Mar 2012 16:12:29 +0100 Subject: Programming D. E. Knuth in Python with the Deterministic Finite Automaton construct In-Reply-To: References: <4f64a3a0$0$1386$4fafbaef@reader2.news.tin.it> Message-ID: <4f64a9e5$0$1385$4fafbaef@reader2.news.tin.it> On 3/17/2012 16:01, Michael Torrie wrote: > On 03/17/2012 08:45 AM, Kiuhnm wrote: >> Your way is easy, but the result is poor. > > In what way? The resulting code is inefficient, difficult to comprehend and to mantain. > What is your recommended way? One should rewrite the code. There is a reason why Python doesn't have gotos. >> Your should try to rewrite it. >> Decompilers do exactly that. > > Decompilers rewrite code for people? That's really neat. No, they try to rewrite code that contains jmps in order to remove them. If one jmp is too difficult to remove, one should use a flag or something similar. Kiuhnm From roy at panix.com Sat Mar 17 11:47:55 2012 From: roy at panix.com (Roy Smith) Date: Sat, 17 Mar 2012 11:47:55 -0400 Subject: Programming D. E. Knuth in Python with the Deterministic Finite Automaton construct References: Message-ID: In article , Antti J Ylikoski wrote: > I came across the problem, which would be the clearest way to program > such algorithms with a programming language such as Python, which has > no GOTO statement. It struck me that the above construction actually > is a modified Deterministic Finite Automaton with states A1 -- A5 + > [END], transferring to different states, not on read input, but > according to conditions in the running program. > > So one very clear way to program Knuth with Python is the following > kind of a construct. > > > > continueLoop = 1 > nextState = "A1" > > while continueLoop: > if nextState == "A1": > # (Do the work of Phase A1.) > if : > nextState = "A5" > elif nextState == "A2": > # (Do some work.) > if zorp: > nextState = "A4" > else: > nextState = "A3" > elif nextState == "A3": > # (Some more work.) > nextState = "A4" > elif nextState == "A4": > # (Do something.) > if ZZZ: > nextState = "A1" > else: > nextState = "A5" > elif nextState == "A5": > # (Something more). > if foobar: > nextState = "A2" > else: > continueLoop = 0 > else: > error("Impossible -- I quit!\n") Oh, my, I can't even begin to get my head around all the nested conditionals. And that for a nearly trivial machine with only 5 states. Down this path lies madness. Keep in mind that Knuth wrote The Art of Computer Programming in the 1960s. The algorithms may still be valid, but we've learned a lot about how to write readable programs since then. Most people today are walking around with phones that have far more compute power than the biggest supercomputers of Knuth's day. We're no longer worried about bumming every cycle by writing in assembler. When I've done FSMs in Python, I've found the cleanest way is to make each state a function. Do something like: def a1(input): # (Do the work of Phase A1.) if : return a5 # goto state a5 else: return a1 # stay in the same state # and so on for the other states. next_state = a1 for input in whatever(): next_state = next_state(input) if next_state is None: break You can adjust that for your needs. Sometimes I have the states return a (next_state, output) tuple. You could use a distinguished done() state, or just use None for that. I wrote the example above as global functions, but more commonly these would be methods of some StateMachine class. From torriem at gmail.com Sat Mar 17 11:53:23 2012 From: torriem at gmail.com (Michael Torrie) Date: Sat, 17 Mar 2012 09:53:23 -0600 Subject: Programming D. E. Knuth in Python with the Deterministic Finite Automaton construct In-Reply-To: <4f64a9e5$0$1385$4fafbaef@reader2.news.tin.it> References: <4f64a3a0$0$1386$4fafbaef@reader2.news.tin.it> <4f64a9e5$0$1385$4fafbaef@reader2.news.tin.it> Message-ID: <4F64B373.204@gmail.com> On 03/17/2012 09:12 AM, Kiuhnm wrote: > On 3/17/2012 16:01, Michael Torrie wrote: >> On 03/17/2012 08:45 AM, Kiuhnm wrote: >>> Your way is easy, but the result is poor. >> >> In what way? > > The resulting code is inefficient, difficult to comprehend and to mantain. > >> What is your recommended way? > > One should rewrite the code. There is a reason why Python doesn't have > gotos. We appear to have a language barrier here. How should one rewrite the code? Everyone knows python doesn't have gotos and state machines have to be created using other mechanisms like loops, state variables, and such. Your suggestion to "rewrite the code" is unhelpful to the OP if you're not willing to suggest the best method for doing so. Saying, "be like a decompiler" doesn't say anything. From antti.ylikoski at tkk.fi Sat Mar 17 12:31:02 2012 From: antti.ylikoski at tkk.fi (Antti J Ylikoski) Date: Sat, 17 Mar 2012 18:31:02 +0200 Subject: Programming D. E. Knuth in Python with the Deterministic Finite Automaton construct In-Reply-To: References: Message-ID: On 17.3.2012 17:47, Roy Smith wrote: > In article, > Antti J Ylikoski wrote: > >> I came across the problem, which would be the clearest way to program >> such algorithms with a programming language such as Python, which has >> no GOTO statement. It struck me that the above construction actually >> is a modified Deterministic Finite Automaton with states A1 -- A5 + >> [END], transferring to different states, not on read input, but >> according to conditions in the running program. >> >> So one very clear way to program Knuth with Python is the following >> kind of a construct. >> >> >> >> continueLoop = 1 >> nextState = "A1" >> >> while continueLoop: >> if nextState == "A1": >> # (Do the work of Phase A1.) >> if: >> nextState = "A5" >> elif nextState == "A2": >> # (Do some work.) >> if zorp: >> nextState = "A4" >> else: >> nextState = "A3" >> elif nextState == "A3": >> # (Some more work.) >> nextState = "A4" >> elif nextState == "A4": >> # (Do something.) >> if ZZZ: >> nextState = "A1" >> else: >> nextState = "A5" >> elif nextState == "A5": >> # (Something more). >> if foobar: >> nextState = "A2" >> else: >> continueLoop = 0 >> else: >> error("Impossible -- I quit!\n") > > Oh, my, I can't even begin to get my head around all the nested > conditionals. And that for a nearly trivial machine with only 5 states. > Down this path lies madness. Keep in mind that Knuth wrote The Art of > Computer Programming in the 1960s. The algorithms may still be valid, > but we've learned a lot about how to write readable programs since then. > Most people today are walking around with phones that have far more > compute power than the biggest supercomputers of Knuth's day. We're no > longer worried about bumming every cycle by writing in assembler. > > When I've done FSMs in Python, I've found the cleanest way is to make > each state a function. Do something like: > > def a1(input): > # (Do the work of Phase A1.) > if: > return a5 # goto state a5 > else: > return a1 # stay in the same state > > # and so on for the other states. > > next_state = a1 > for input in whatever(): > next_state = next_state(input) > if next_state is None: > break > > You can adjust that for your needs. Sometimes I have the states return > a (next_state, output) tuple. You could use a distinguished done() > state, or just use None for that. I wrote the example above as global > functions, but more commonly these would be methods of some StateMachine > class. Thank you, that is a very good idea to my opinion. Antti "Andy" From rosuav at gmail.com Sat Mar 17 12:34:05 2012 From: rosuav at gmail.com (Chris Angelico) Date: Sun, 18 Mar 2012 03:34:05 +1100 Subject: urllib.urlretrieve never returns??? In-Reply-To: <4F649BFC.1080601@shopzeus.com> References: <4F649BFC.1080601@shopzeus.com> Message-ID: 2012/3/18 Laszlo Nagy : > In the later case, "log.txt" only contains "#1" and nothing else. If I look > at pythonw.exe from task manager, then its shows +1 thread every time I > click the button, and "#1" is appended to the file. try: fpath = urllib.urlretrieve(imgurl)[0] except: self.Log(traceback.format_exc()) return Just a stab in the dark, but I'm wondering if something's throwing an exception when it's running without a GUI? Your except clause references 'traceback' which I don't see anywhere else - or is that part of the code you can't share? Anyway, my guess is that something perhaps tries to write to the console and can't, and it gets stuck inside format_exc(). Is that testable? For instance, replace the "fpath=" line with "fpath = 1/0" to raise WhatKindOfIdiotAreYouError (it's spelled differently, but that's what the computer thinks of people who ask it to divide by zero) - see what that does. Or maybe add self.log("#1.5") at the beginning of the except: clause. Without all your code, I can't actually run it to test, so it's entirely possible that I'm completely wrong here. ChrisA From miki.tebeka at gmail.com Sat Mar 17 13:12:59 2012 From: miki.tebeka at gmail.com (Miki Tebeka) Date: Sat, 17 Mar 2012 10:12:59 -0700 (PDT) Subject: elasticsearch client Message-ID: <16392875.280.1332004379343.JavaMail.geo-discussion-forums@ynjx8> Greetings, I see several elasticsearch clients on PyPI, any recommendations? Thanks, -- Miki From gandalf at shopzeus.com Sat Mar 17 13:31:33 2012 From: gandalf at shopzeus.com (Laszlo Nagy) Date: Sat, 17 Mar 2012 18:31:33 +0100 Subject: urllib.urlretrieve never returns??? In-Reply-To: References: <4F649BFC.1080601@shopzeus.com> Message-ID: <4F64CA75.1060108@shopzeus.com> 2012.03.17. 17:34 keltez?ssel, Chris Angelico wrote > 2012/3/18 Laszlo Nagy: >> In the later case, "log.txt" only contains "#1" and nothing else. If I look >> at pythonw.exe from task manager, then its shows +1 thread every time I >> click the button, and "#1" is appended to the file. > try: > fpath = urllib.urlretrieve(imgurl)[0] > except: > self.Log(traceback.format_exc()) > return > > > Just a stab in the dark, but I'm wondering if something's throwing an > exception when it's running without a GUI? Your except clause > references 'traceback' which I don't see anywhere else - or is that > part of the code you can't share? Anyway, my guess is that something > perhaps tries to write to the console and can't, and it gets stuck > inside format_exc(). Is that testable? You are right, I should have added "import traceback". However, I tried this: try: fpath = urllib.urlretrieve(imgurl)[0] except: self.Log("Exception") return and still nothing was logged. Another proof is that the number of threads is increased every time I press the button. So I'm 100% sure that urlretrieve does not return from the call. From rosuav at gmail.com Sat Mar 17 13:53:24 2012 From: rosuav at gmail.com (Chris Angelico) Date: Sun, 18 Mar 2012 04:53:24 +1100 Subject: urllib.urlretrieve never returns??? In-Reply-To: <4F64CA75.1060108@shopzeus.com> References: <4F649BFC.1080601@shopzeus.com> <4F64CA75.1060108@shopzeus.com> Message-ID: On Sun, Mar 18, 2012 at 4:31 AM, Laszlo Nagy wrote: > You are right, I should have added "import traceback". However, I tried > this: > > ? ? ? ?except: > ? ? ? ? ? ?self.Log("Exception") > > and still nothing was logged. Another proof is that the number of threads is > increased every time I press the button. So I'm 100% sure that urlretrieve > does not return from the call. Okay, was worth a shot! Hopefully someone else can help more. ChrisA From kiuhnm03.4t.yahoo.it Sat Mar 17 13:55:14 2012 From: kiuhnm03.4t.yahoo.it (Kiuhnm) Date: Sat, 17 Mar 2012 18:55:14 +0100 Subject: Programming D. E. Knuth in Python with the Deterministic Finite Automaton construct In-Reply-To: References: <4f64a3a0$0$1386$4fafbaef@reader2.news.tin.it> <4f64a9e5$0$1385$4fafbaef@reader2.news.tin.it> Message-ID: <4f64d00a$0$1390$4fafbaef@reader1.news.tin.it> On 3/17/2012 16:53, Michael Torrie wrote: > On 03/17/2012 09:12 AM, Kiuhnm wrote: >> On 3/17/2012 16:01, Michael Torrie wrote: >>> On 03/17/2012 08:45 AM, Kiuhnm wrote: >>>> Your way is easy, but the result is poor. >>> >>> In what way? >> >> The resulting code is inefficient, difficult to comprehend and to mantain. >> >>> What is your recommended way? >> >> One should rewrite the code. There is a reason why Python doesn't have >> gotos. > > We appear to have a language barrier here. How should one rewrite the > code? Everyone knows python doesn't have gotos and state machines have > to be created using other mechanisms like loops, state variables, and > such. Your suggestion to "rewrite the code" is unhelpful to the OP if > you're not willing to suggest the best method for doing so. Why should I write a treatise on decompilation techniques on this ng? > Saying, "be > like a decompiler" doesn't say anything. That looks like a glaring contradiction to me... I'm sure the interested reader will think of some ways of getting additional information on the subject. Here's an example of rewriting: A1. (Do the work of Phase A1.) If then go to Phase A5, otherwise continue. A2. (Do some work.) If go to Phase A4. A3. (Some more work.) A4. (Do something.) If go to Phase A1. A5. (Something more). If then go to Phase A2, otherwise end. ==> A1. (Do the work of Phase A1.) If not : A2. (Do some work.) If go to Phase A4. A3. (Some more work.) A4. (Do something.) If go to Phase A1. A5. (Something more). If then go to Phase A2, otherwise end. ==> A1. (Do the work of Phase A1.) If not : A2. (Do some work.) If not : A3. (Some more work.) A4. (Do something.) If go to Phase A1. A5. (Something more). If then go to Phase A2, otherwise end. ==> while (True): A1. (Do the work of Phase A1.) If not : A2. (Do some work.) If not : A3. (Some more work.) A4. (Do something.) If not : break A5. (Something more). If then go to Phase A2 ==> while (True): A1. (Do the work of Phase A1.) If not : A2. (Do some work.) If not : A3. (Some more work.) A4. (Do something.) If not : A5. (Something more). If then go to Phase A2 break ==> again = TRUE while (again): A1. (Do the work of Phase A1.) If not : while (True): A2. (Do some work.) If not : A3. (Some more work.) A4. (Do something.) If not : A5. (Something more). If : continue again = FALSE; break ==> def f: while (True): A1. (Do the work of Phase A1.) If not : while (True): A2. (Do some work.) If not : A3. (Some more work.) A4. (Do something.) If not : A5. (Something more). If : continue return ==> def f: while (True): A1. (Do the work of Phase A1.) If : continue while (True): A2. (Do some work.) If not : A3. (Some more work.) A4. (Do something.) If not : A5. (Something more). If : continue return ==> def f: while (True): A1. (Do the work of Phase A1.) If : continue while (True): A2. (Do some work.) If not : A3. (Some more work.) A4. (Do something.) If : continue A5. (Something more). If : continue return ==> def f: while (True): A1. (Do the work of Phase A1.) If : continue while (True): A2. (Do some work.) If not : A3. (Some more work.) A4. (Do something.) If : continue A5. (Something more). If not : return Etc... until you're satisfied with the result. If the code is more complex, divide et impera. Kiuhnm From lists at cheimes.de Sat Mar 17 14:18:25 2012 From: lists at cheimes.de (Christian Heimes) Date: Sat, 17 Mar 2012 19:18:25 +0100 Subject: urllib.urlretrieve never returns??? In-Reply-To: <4F649BFC.1080601@shopzeus.com> References: <4F649BFC.1080601@shopzeus.com> Message-ID: Am 17.03.2012 15:13, schrieb Laszlo Nagy: > See attached example code. I have a program that calls exactly the same > code, and here is the strange thing about it: > > * Program is started as "start.py", e.g. with an open console. In this > case, the program works! > * Program is started as "start.pyw", e.g. with no open console under > Windows 7 64bit - the program does not work! The pythonw.exe may not have the rights to access network resources. Have you set a default timeout for sockets? import socket socket.setdefaulttimeout(10) # 10 seconds A pyw Python doesn't have stdout, stderr or stdin. Any attempt to write to them (e.g. print statement, default exception logger) can cause an exception. Christian From ericsnowcurrently at gmail.com Sat Mar 17 14:42:49 2012 From: ericsnowcurrently at gmail.com (Eric Snow) Date: Sat, 17 Mar 2012 11:42:49 -0700 Subject: Using non-dict namespaces in functions In-Reply-To: <4f647317$0$29981$c3e8da3$5496439d@news.astraweb.com> References: <4f647317$0$29981$c3e8da3$5496439d@news.astraweb.com> Message-ID: On Sat, Mar 17, 2012 at 4:18 AM, Steven D'Aprano wrote: > Note that it is important for my purposes that MockChainMap does not > inherit from dict. Care to elaborate? > Now I try to create a function that uses a MockChainMap instead of a dict > for its globals: > > function = type(lambda: None) > f = lambda x: (a+b+x) > g = function(f.__code__, MockChainMap(), 'g') > > And that's where I get into trouble: > > Traceback (most recent call last): > ?File "", line 1, in > TypeError: function() argument 2 must be dict, not MockChainMap > > > How do I build a function with globals set to a non-dict mapping? > > If this can't be done, any suggestions for how I might proceed? This looks like one of those cases where there is strict type checking (of a Python object) at the C level. You may consider bringing this up in a tracker ticket. Unless there are performance implications, it's likely a case of no one having bothered to change this spot to be more duck-type friendly. There are quite a few of those in CPython and I've seen at least a couple updated when someone brought it up. Regardless, you could also implement __call__() on a function look-alike class to get what you're after. It may not be as performant though. -eric From nagle at animats.com Sat Mar 17 14:44:32 2012 From: nagle at animats.com (John Nagle) Date: Sat, 17 Mar 2012 11:44:32 -0700 Subject: Programming D. E. Knuth in Python with the Deterministic Finite Automaton construct In-Reply-To: References: Message-ID: <4f64db92$0$12041$742ec2ed@news.sonic.net> On 3/17/2012 9:31 AM, Antti J Ylikoski wrote: > On 17.3.2012 17:47, Roy Smith wrote: >> In article, >> Antti J Ylikoski wrote: >> >>> I came across the problem, which would be the clearest way to program >>> such algorithms with a programming language such as Python, which has >>> no GOTO statement. >> Oh, my, I can't even begin to get my head around all the nested >> conditionals. And that for a nearly trivial machine with only 5 states. >> Down this path lies madness. Right. Few programs should be written as state machines. As a means of rewriting Knuth's algorithms, it's inappropriate. Some should. LALR(1) parsers, such as what YACC and Bison generate, are state machines. They're huge collections of nested switch statements. Python doesn't have a "switch" or "case" statement. Which is surprising, for a language that loves dictionary lookups. You can create a dict full of function names and lambdas, but it's clunky looking. John Nagle From kiuhnm03.4t.yahoo.it Sat Mar 17 15:59:34 2012 From: kiuhnm03.4t.yahoo.it (Kiuhnm) Date: Sat, 17 Mar 2012 20:59:34 +0100 Subject: Python is readable In-Reply-To: <4f636ed5$0$29981$c3e8da3$5496439d@news.astraweb.com> References: <4f612b19$0$1379$4fafbaef@reader2.news.tin.it> <8e72d74f-c844-4de3-8a37-f6b1fdc2291f@y27g2000yqy.googlegroups.com> <50e9ceec-40f1-4ead-b2b6-87328b30d084@ow8g2000pbc.googlegroups.com> <4f61c828$0$1390$4fafbaef@reader2.news.tin.it> <4f61d728$0$1375$4fafbaef@reader2.news.tin.it> <4f61fd0a$0$1389$4fafbaef@reader2.news.tin.it> <4f620837$0$1382$4fafbaef@reader2.news.tin.it> <4f627c25$0$1381$4fafbaef@reader2.news.tin.it> <4f62b9be$0$29981$c3e8da3$5496439d@news.astraweb.com> <4f632da5$0$1375$4fafbaef@reader1.news.tin.it> <4f636ed5$0$29981$c3e8da3$5496439d@news.astraweb.com> Message-ID: <4f64ed2e$0$1389$4fafbaef@reader1.news.tin.it> On 3/16/2012 17:48, Steven D'Aprano wrote: > On Fri, 16 Mar 2012 13:10:12 +0100, Kiuhnm wrote: > >> Maybe we should define *exactly* what readability is (in less then 500 >> lines, if possible). > > If you can't be bothered to read my post before replying, save yourself > some more time and don't bother to reply at all. > > I quote from the part of the my post you deleted: > > When people talk about readability, they normally mean to > ask how much mental effort is needed to interpret the > meaning of the text, not how much time does it take to > pass your eyes over the characters. In other words they > are actually talking about comprehensibility. > > > Unless I've made a mistake counting, that's less than 500 lines. > > >> According to your view, ASM code is more readable than Python code. It's >> just that there's more to read in ASM. > > What a ridiculous misrepresentation of my position. Readability is not > proportional to length. Ok, so length and readability are orthogonal properties. Could you please explain to me in which way mov eax, 3 should be less readable than for i in x: print(i) ? From kiuhnm03.4t.yahoo.it Sat Mar 17 16:23:45 2012 From: kiuhnm03.4t.yahoo.it (Kiuhnm) Date: Sat, 17 Mar 2012 21:23:45 +0100 Subject: Python is readable In-Reply-To: <4f633a1a$0$29981$c3e8da3$5496439d@news.astraweb.com> References: <4f612b19$0$1379$4fafbaef@reader2.news.tin.it> <8e72d74f-c844-4de3-8a37-f6b1fdc2291f@y27g2000yqy.googlegroups.com> <50e9ceec-40f1-4ead-b2b6-87328b30d084@ow8g2000pbc.googlegroups.com> <4f61c828$0$1390$4fafbaef@reader2.news.tin.it> <4f61d728$0$1375$4fafbaef@reader2.news.tin.it> <4f61fd0a$0$1389$4fafbaef@reader2.news.tin.it> <4f6280a0$0$29981$c3e8da3$5496439d@news.astraweb.com> <4f6333ca$0$1392$4fafbaef@reader1.news.tin.it> <4f633a1a$0$29981$c3e8da3$5496439d@news.astraweb.com> Message-ID: <4f64f2d8$0$1393$4fafbaef@reader1.news.tin.it> On 3/16/2012 14:03, Steven D'Aprano wrote: > A one line routine is still a routine. There is nothing ungrammatical > about "If you can: take the bus.", although it is non-idiomatic English. In another post you wrote "Sorry, I was talking about the other sort, the ones who apply the grammatical rules used by people in real life. You know the ones: linguists." Then how do you know that there's nothing ungrammatical about "If you can: take the bus" if people don't use it? Kiuhnm From kiuhnm03.4t.yahoo.it Sat Mar 17 16:54:40 2012 From: kiuhnm03.4t.yahoo.it (Kiuhnm) Date: Sat, 17 Mar 2012 21:54:40 +0100 Subject: Python is readable In-Reply-To: References: <4f612b19$0$1379$4fafbaef@reader2.news.tin.it> <8e72d74f-c844-4de3-8a37-f6b1fdc2291f@y27g2000yqy.googlegroups.com> <50e9ceec-40f1-4ead-b2b6-87328b30d084@ow8g2000pbc.googlegroups.com> <4f61c828$0$1390$4fafbaef@reader2.news.tin.it> <4f61d728$0$1375$4fafbaef@reader2.news.tin.it> <4f61fd0a$0$1389$4fafbaef@reader2.news.tin.it> <4f6280a0$0$29981$c3e8da3$5496439d@news.astraweb.com> <4f6333ca$0$1392$4fafbaef@reader1.news.tin.it> <4f633a1a$0$29981$c3e8da3$5496439d@news.astraweb.com> <9sgsb1FsbpU1@mid.individual.net> <4f636a38$0$29981$c3e8da3$5496439d@news.astraweb.com> <9shd0kFvgbU1@mid.individual.net> <4f638b76$0$29981$c3e8da3$5496439d@news.astraweb.com> <9shj05FabeU1@mid.individual.net> Message-ID: <4f64fa18$0$1392$4fafbaef@reader1.news.tin.it> On 3/16/2012 21:04, Prasad, Ramit wrote: >> People spell your name Stephen, sometimes too. Thinking of changing it? >> Gore Vidal's quote has panache, a valid compensation for breaking > the usual rule. How many other uses on that page are similar? > > > He provided common examples and reference links. Seems like a pretty > reasonable way of trying to prove a point. If you don't like reference > links, what would convince you that the point was correct? I have > not seen any counter examples or counter references on your behalf... He's referring to this "rule": "A colon should not precede a list unless it follows a complete sentence; however, the colon is a style choice that some publications allow." http://www.grammarbook.com/punctuation/colons.asp Kiuhnm From rosuav at gmail.com Sat Mar 17 17:20:14 2012 From: rosuav at gmail.com (Chris Angelico) Date: Sun, 18 Mar 2012 08:20:14 +1100 Subject: Python is readable In-Reply-To: <4f64ed2e$0$1389$4fafbaef@reader1.news.tin.it> References: <4f612b19$0$1379$4fafbaef@reader2.news.tin.it> <8e72d74f-c844-4de3-8a37-f6b1fdc2291f@y27g2000yqy.googlegroups.com> <50e9ceec-40f1-4ead-b2b6-87328b30d084@ow8g2000pbc.googlegroups.com> <4f61c828$0$1390$4fafbaef@reader2.news.tin.it> <4f61d728$0$1375$4fafbaef@reader2.news.tin.it> <4f61fd0a$0$1389$4fafbaef@reader2.news.tin.it> <4f620837$0$1382$4fafbaef@reader2.news.tin.it> <4f627c25$0$1381$4fafbaef@reader2.news.tin.it> <4f62b9be$0$29981$c3e8da3$5496439d@news.astraweb.com> <4f632da5$0$1375$4fafbaef@reader1.news.tin.it> <4f636ed5$0$29981$c3e8da3$5496439d@news.astraweb.com> <4f64ed2e$0$1389$4fafbaef@reader1.news.tin.it> Message-ID: On Sun, Mar 18, 2012 at 6:59 AM, Kiuhnm wrote: > Could you please explain to me in which way > ? ?mov eax, 3 > should be less readable than > ? ?for i in x: print(i) > ? They are equally readable. The first one sets EAX to 3; the second displays all elements of x on the console. Assembly is readable on a very low level, but it's by nature verbose at a high level, and thus less readable (you can't eyeball a function and know exactly what it does, especially if that function spans more than a screenful of code). ChrisA From kiuhnm03.4t.yahoo.it Sat Mar 17 17:22:12 2012 From: kiuhnm03.4t.yahoo.it (Kiuhnm) Date: Sat, 17 Mar 2012 22:22:12 +0100 Subject: Python is readable In-Reply-To: References: <4f612b19$0$1379$4fafbaef@reader2.news.tin.it> <8e72d74f-c844-4de3-8a37-f6b1fdc2291f@y27g2000yqy.googlegroups.com> <50e9ceec-40f1-4ead-b2b6-87328b30d084@ow8g2000pbc.googlegroups.com> <4f61c828$0$1390$4fafbaef@reader2.news.tin.it> <4f61d728$0$1375$4fafbaef@reader2.news.tin.it> <4f61fd0a$0$1389$4fafbaef@reader2.news.tin.it> <4f620837$0$1382$4fafbaef@reader2.news.tin.it> <4f627c25$0$1381$4fafbaef@reader2.news.tin.it> <4f62b9be$0$29981$c3e8da3$5496439d@news.astraweb.com> <4f632da5$0$1375$4fafbaef@reader1.news.tin.it> <4f636ed5$0$29981$c3e8da3$5496439d@news.astraweb.com> Message-ID: <4f65008c$0$1375$4fafbaef@reader1.news.tin.it> On 3/17/2012 0:39, Michael Torrie wrote: > For someone who claims he's merely examining the language and seeking to > learn about it, Kiuhnm is jumping awfully quickly into the realm of > trolling. I'm speechless... thanks, man! Kiuhnm From kiuhnm03.4t.yahoo.it Sat Mar 17 17:28:44 2012 From: kiuhnm03.4t.yahoo.it (Kiuhnm) Date: Sat, 17 Mar 2012 22:28:44 +0100 Subject: Python is readable In-Reply-To: References: <4f612b19$0$1379$4fafbaef@reader2.news.tin.it> <8e72d74f-c844-4de3-8a37-f6b1fdc2291f@y27g2000yqy.googlegroups.com> <50e9ceec-40f1-4ead-b2b6-87328b30d084@ow8g2000pbc.googlegroups.com> <4f61c828$0$1390$4fafbaef@reader2.news.tin.it> <4f61d728$0$1375$4fafbaef@reader2.news.tin.it> <4f61fd0a$0$1389$4fafbaef@reader2.news.tin.it> <4f620837$0$1382$4fafbaef@reader2.news.tin.it> <4f627c25$0$1381$4fafbaef@reader2.news.tin.it> <4f62b9be$0$29981$c3e8da3$5496439d@news.astraweb.com> <4f632da5$0$1375$4fafbaef@reader1.news.tin.it> <4f636ed5$0$29981$c3e8da3$5496439d@news.astraweb.com> <4f64ed2e$0$1389$4fafbaef@reader1.news.tin.it> Message-ID: <4f650213$0$1375$4fafbaef@reader1.news.tin.it> On 3/17/2012 22:20, Chris Angelico wrote: > On Sun, Mar 18, 2012 at 6:59 AM, Kiuhnm > wrote: >> Could you please explain to me in which way >> mov eax, 3 >> should be less readable than >> for i in x: print(i) >> ? > > They are equally readable. The first one sets EAX to 3; the second > displays all elements of x on the console. Assembly is readable on a > very low level, but it's by nature verbose at a high level, and thus > less readable (you can't eyeball a function and know exactly what it > does, especially if that function spans more than a screenful of > code). Welcome in the realm of trolling. Kiuhnm From java at leeclemens.net Sat Mar 17 18:17:10 2012 From: java at leeclemens.net (Lee Clemens) Date: Sat, 17 Mar 2012 18:17:10 -0400 Subject: Daemonization / Popen / pipe issue In-Reply-To: <20120317143726.7134d2b04d56d1759d8eeeb6@johnohagan.com> References: <4F63F2FE.1030409@leeclemens.net> <20120317143726.7134d2b04d56d1759d8eeeb6@johnohagan.com> Message-ID: <4F650D66.4040209@leeclemens.net> On 03/16/2012 11:37 PM, John O'Hagan wrote: > On Fri, 16 Mar 2012 22:12:14 -0400 > Lee Clemens wrote: > >> I have a multi-threaded application >> >> I have provided a test-case here: https://gist.github.com/2054194 > I haven't looked at your test case yet, but a possible cause is the fact that > the main application (or main thread) exits if it has finished executing and > only daemon threads remain. This can abruptly terminate threads which may be > busy, for example, communicating via a pipe. The best solution IMO is not to > use daemon threads, but to give all threads a way to terminate cleanly before > the main thread does, even if this means using a flag or the like. > > HTH, > > John > I call .join() on each spawned thread, whether it is daemonized or not. The code is available here: https://gist.github.com/2054194 Is it generally not recommended to daemonize Python applications using this method? Do you have any references or data to support your opinion? Do you have any references which specifically state - "Daemonizing Python applications cause Python to work in unexpected ways."? As that is what seems to be happening - data corrupting pipe redirection at an underlying level.... From torriem at gmail.com Sat Mar 17 19:04:14 2012 From: torriem at gmail.com (Michael Torrie) Date: Sat, 17 Mar 2012 17:04:14 -0600 Subject: Python is readable In-Reply-To: <4f650213$0$1375$4fafbaef@reader1.news.tin.it> References: <4f612b19$0$1379$4fafbaef@reader2.news.tin.it> <8e72d74f-c844-4de3-8a37-f6b1fdc2291f@y27g2000yqy.googlegroups.com> <50e9ceec-40f1-4ead-b2b6-87328b30d084@ow8g2000pbc.googlegroups.com> <4f61c828$0$1390$4fafbaef@reader2.news.tin.it> <4f61d728$0$1375$4fafbaef@reader2.news.tin.it> <4f61fd0a$0$1389$4fafbaef@reader2.news.tin.it> <4f620837$0$1382$4fafbaef@reader2.news.tin.it> <4f627c25$0$1381$4fafbaef@reader2.news.tin.it> <4f62b9be$0$29981$c3e8da3$5496439d@news.astraweb.com> <4f632da5$0$1375$4fafbaef@reader1.news.tin.it> <4f636ed5$0$29981$c3e8da3$5496439d@news.astraweb.com> <4f64ed2e$0$1389$4fafbaef@reader1.news.tin.it> <4f650213$0$1375$4fafbaef@reader1.news.tin.it> Message-ID: <4F65186E.8010901@gmail.com> On 03/17/2012 03:28 PM, Kiuhnm wrote: >> They are equally readable. The first one sets EAX to 3; the second >> displays all elements of x on the console. Assembly is readable on a >> very low level, but it's by nature verbose at a high level, and thus >> less readable (you can't eyeball a function and know exactly what it >> does, especially if that function spans more than a screenful of >> code). > > Welcome in the realm of trolling. Seems like you're the one trolling. From torriem at gmail.com Sat Mar 17 19:28:38 2012 From: torriem at gmail.com (Michael Torrie) Date: Sat, 17 Mar 2012 17:28:38 -0600 Subject: Programming D. E. Knuth in Python with the Deterministic Finite Automaton construct In-Reply-To: <4f64d00a$0$1390$4fafbaef@reader1.news.tin.it> References: <4f64a3a0$0$1386$4fafbaef@reader2.news.tin.it> <4f64a9e5$0$1385$4fafbaef@reader2.news.tin.it> <4f64d00a$0$1390$4fafbaef@reader1.news.tin.it> Message-ID: <4F651E26.7010705@gmail.com> On 03/17/2012 11:55 AM, Kiuhnm wrote: > Why should I write a treatise on decompilation techniques on this ng? You were the one that said simply, you're doing it wrong followed by a terse statement, do it like a decompiler. I am familiar with how one might implement a decompiler, as well as a compiler (having written a simple one in the past), but even now I don't see a connection between a decompiler and the process of converting a knuth algorithm into a python python implementation. I was hoping you would shed some light on that. But alas, I'm not really as much of an "interested reader" as you would like me to be. >> Saying, "be like a decompiler" doesn't say anything. > That looks like a glaring contradiction to me... True, if you wish to be pedantic. I should have said, "meaningless," or at least, "not a useful response." > Here's an example of rewriting: > Thank you. Your example makes more clear your assertion about "labels" and how really A1 and A5 were the only real labels in the example. Though I still do not really see why "states" is not a good equivalence for labels in this case. As well, Roy's idea for doing the state machines, which works equally well as the nested if statements, is more pythonic, which is generally preferred in Python. From ben+python at benfinney.id.au Sat Mar 17 20:42:49 2012 From: ben+python at benfinney.id.au (Ben Finney) Date: Sun, 18 Mar 2012 11:42:49 +1100 Subject: Python is readable References: <4f612b19$0$1379$4fafbaef@reader2.news.tin.it> <8e72d74f-c844-4de3-8a37-f6b1fdc2291f@y27g2000yqy.googlegroups.com> <50e9ceec-40f1-4ead-b2b6-87328b30d084@ow8g2000pbc.googlegroups.com> <4f61c828$0$1390$4fafbaef@reader2.news.tin.it> <4f61d728$0$1375$4fafbaef@reader2.news.tin.it> <4f61fd0a$0$1389$4fafbaef@reader2.news.tin.it> <4f620837$0$1382$4fafbaef@reader2.news.tin.it> <4f627c25$0$1381$4fafbaef@reader2.news.tin.it> <4f62b9be$0$29981$c3e8da3$5496439d@news.astraweb.com> <4f632da5$0$1375$4fafbaef@reader1.news.tin.it> <4f636ed5$0$29981$c3e8da3$5496439d@news.astraweb.com> <4f64ed2e$0$1389$4fafbaef@reader1.news.tin.it> <4f650213$0$1375$4fafbaef@reader1.news.tin.it> Message-ID: <877gyioi2e.fsf@benfinney.id.au> Kiuhnm writes: > Welcome in the realm of trolling. Thank you for stating clearly what you're doing. Welcome to yet another kill-file. *plonk* -- \ ?I am too firm in my consciousness of the marvelous to be ever | `\ fascinated by the mere supernatural ?? ?Joseph Conrad, _The | _o__) Shadow-Line_ | Ben Finney From drsalists at gmail.com Sat Mar 17 20:44:07 2012 From: drsalists at gmail.com (Dan Stromberg) Date: Sat, 17 Mar 2012 17:44:07 -0700 Subject: Does anyone actually use PyPy in production? In-Reply-To: <4f63ec8b$0$11975$742ec2ed@news.sonic.net> References: <4f63ec8b$0$11975$742ec2ed@news.sonic.net> Message-ID: I personally feel that python-list should be restricted to discussing Python the language, not just CPython the implementation. Anyway, there are many kinds of production, no? But I use Pypy for my backups frequently, which is a form of production use. Pypy+backshift pass my automated tests as well as CPython+backshift and Jython+backshift, so why not? On Fri, Mar 16, 2012 at 6:44 PM, John Nagle wrote: > Does anyone run PyPy in production? > > John Nagle > -- > http://mail.python.org/**mailman/listinfo/python-list > -------------- next part -------------- An HTML attachment was scrubbed... URL: From steve+comp.lang.python at pearwood.info Sat Mar 17 20:57:11 2012 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 18 Mar 2012 00:57:11 GMT Subject: Python is readable References: <4f612b19$0$1379$4fafbaef@reader2.news.tin.it> <8e72d74f-c844-4de3-8a37-f6b1fdc2291f@y27g2000yqy.googlegroups.com> <50e9ceec-40f1-4ead-b2b6-87328b30d084@ow8g2000pbc.googlegroups.com> <4f61c828$0$1390$4fafbaef@reader2.news.tin.it> <4f61d728$0$1375$4fafbaef@reader2.news.tin.it> <4f61fd0a$0$1389$4fafbaef@reader2.news.tin.it> <4f6280a0$0$29981$c3e8da3$5496439d@news.astraweb.com> <4f6333ca$0$1392$4fafbaef@reader1.news.tin.it> <4f633a1a$0$29981$c3e8da3$5496439d@news.astraweb.com> <9sgsb1FsbpU1@mid.individual.net> <4f636a38$0$29981$c3e8da3$5496439d@news.astraweb.com> <9shd0kFvgbU1@mid.individual.net> <4f638b76$0$29981$c3e8da3$5496439d@news.astraweb.com> <9shj05FabeU1@mid.individual.net> <4f64fa18$0$1392$4fafbaef@reader1.news.tin.it> Message-ID: <4f6532e7$0$29981$c3e8da3$5496439d@news.astraweb.com> On Sat, 17 Mar 2012 21:54:40 +0100, Kiuhnm wrote: > On 3/16/2012 21:04, Prasad, Ramit wrote: >>> People spell your name Stephen, sometimes too. Thinking of changing >>> it? Gore Vidal's quote has panache, a valid compensation for breaking >> the usual rule. How many other uses on that page are similar? >> >> >> He provided common examples and reference links. Seems like a pretty >> reasonable way of trying to prove a point. If you don't like reference >> links, what would convince you that the point was correct? I have not >> seen any counter examples or counter references on your behalf... > > He's referring to this "rule": > "A colon should not precede a list unless it follows a complete > sentence; however, the colon is a style choice that some publications > allow." > http://www.grammarbook.com/punctuation/colons.asp That is an invented prescriptivist rule and not based on English grammar as it actually is used by native English speakers. It is *bullshit*. Even the author of that page breaks it. Immediately following the above prohibition, she follows it with the sentence fragment: "Examples:" and then a list -- exactly what she says you may not do. People *do* precede lists by a colon following a sentence fragment. This is unremarkable English grammar, with only a tiny number of arse-plugged prescriptivists finding anything to complain about it, and even they break their own bullshit made-up so-called rule. The vast majority of English speakers write things like: TO DO: - mow the lawn - wash the car - take kids to the zoo - write book on grammar and there is nothing wrong with doing so. -- Steven From rosuav at gmail.com Sat Mar 17 21:07:36 2012 From: rosuav at gmail.com (Chris Angelico) Date: Sun, 18 Mar 2012 12:07:36 +1100 Subject: Python is readable In-Reply-To: <4f6532e7$0$29981$c3e8da3$5496439d@news.astraweb.com> References: <4f612b19$0$1379$4fafbaef@reader2.news.tin.it> <8e72d74f-c844-4de3-8a37-f6b1fdc2291f@y27g2000yqy.googlegroups.com> <50e9ceec-40f1-4ead-b2b6-87328b30d084@ow8g2000pbc.googlegroups.com> <4f61c828$0$1390$4fafbaef@reader2.news.tin.it> <4f61d728$0$1375$4fafbaef@reader2.news.tin.it> <4f61fd0a$0$1389$4fafbaef@reader2.news.tin.it> <4f6280a0$0$29981$c3e8da3$5496439d@news.astraweb.com> <4f6333ca$0$1392$4fafbaef@reader1.news.tin.it> <4f633a1a$0$29981$c3e8da3$5496439d@news.astraweb.com> <9sgsb1FsbpU1@mid.individual.net> <4f636a38$0$29981$c3e8da3$5496439d@news.astraweb.com> <9shd0kFvgbU1@mid.individual.net> <4f638b76$0$29981$c3e8da3$5496439d@news.astraweb.com> <9shj05FabeU1@mid.individual.net> <4f64fa18$0$1392$4fafbaef@reader1.news.tin.it> <4f6532e7$0$29981$c3e8da3$5496439d@news.astraweb.com> Message-ID: On Sun, Mar 18, 2012 at 11:57 AM, Steven D'Aprano wrote: > The vast majority of English speakers write things like: > > ? ?TO DO: And the vast majority of programmers leave out the space, even in non-code. ChrisA From research at johnohagan.com Sat Mar 17 21:35:16 2012 From: research at johnohagan.com (John O'Hagan) Date: Sun, 18 Mar 2012 12:35:16 +1100 Subject: Daemonization / Popen / pipe issue In-Reply-To: <4F650D66.4040209@leeclemens.net> References: <4F63F2FE.1030409@leeclemens.net> <20120317143726.7134d2b04d56d1759d8eeeb6@johnohagan.com> <4F650D66.4040209@leeclemens.net> Message-ID: <20120318123516.0c13a6345c333a040568b95a@johnohagan.com> On Sat, 17 Mar 2012 18:17:10 -0400 Lee Clemens wrote: > On 03/16/2012 11:37 PM, John O'Hagan wrote: > > On Fri, 16 Mar 2012 22:12:14 -0400 > > Lee Clemens wrote: > > > >> I have a multi-threaded application > >> > >> I have provided a test-case here: https://gist.github.com/2054194 > > I haven't looked at your test case yet, but a possible cause is the fact > > that the main application (or main thread) exits if it has finished > > executing and only daemon threads remain. This can abruptly terminate > > threads which may be busy, for example, communicating via a pipe. The best > > solution IMO is not to use daemon threads, but to give all threads a way to > > terminate cleanly before the main thread does, even if this means using a > > flag or the like. > > > > HTH, > > > > John > > > I call .join() on each spawned thread, whether it is daemonized or not. > The code is available here: > > https://gist.github.com/2054194 I've tried running your code (which at a glance looks very well-written) but I get the broken pipe errors whether the DAEMONIZE flag is True or False (Python 2.7, Debian testing). I don't have time to dig much deeper. > Is it generally not recommended to daemonize Python applications using > this method? I'm no guru, but not that I know of. I haven't seen the os.fork method you use before; out of interest, why not use Thread.setDaemon? > Do you have any references or data to support your opinion? > Do you have any references which specifically state - "Daemonizing > Python applications cause Python to work in unexpected ways."? Not particularly, although there are a few oldish references to "Python daemon threads considered harmful" out there. You probably know that daemonising can cover a multitude of sins, and it's always a good idea to ensure clean termination and not just assume that what happens in a daemon thread on program exit is moot. I'm not saying you haven't done that, in fact your errors seem to occur during execution, not termination. I replied to your post because I've had broken pipe errors before with daemon threads communicating on sockets which sounded similar to your issue. I solved them by rewriting so that the main thread told the threads to terminate, and waited till they had. This made daemonising unnecessary in that case. [...] Regards, John From steve+comp.lang.python at pearwood.info Sat Mar 17 21:36:30 2012 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 18 Mar 2012 01:36:30 GMT Subject: Python is readable References: <4f612b19$0$1379$4fafbaef@reader2.news.tin.it> <8e72d74f-c844-4de3-8a37-f6b1fdc2291f@y27g2000yqy.googlegroups.com> <50e9ceec-40f1-4ead-b2b6-87328b30d084@ow8g2000pbc.googlegroups.com> <4f61c828$0$1390$4fafbaef@reader2.news.tin.it> <4f61d728$0$1375$4fafbaef@reader2.news.tin.it> <4f61fd0a$0$1389$4fafbaef@reader2.news.tin.it> <4f620837$0$1382$4fafbaef@reader2.news.tin.it> <4f627c25$0$1381$4fafbaef@reader2.news.tin.it> <4f62b9be$0$29981$c3e8da3$5496439d@news.astraweb.com> <4f632da5$0$1375$4fafbaef@reader1.news.tin.it> <4f636ed5$0$29981$c3e8da3$5496439d@news.astraweb.com> <4f64ed2e$0$1389$4fafbaef@reader1.news.tin.it> Message-ID: <4f653c1e$0$29981$c3e8da3$5496439d@news.astraweb.com> On Sat, 17 Mar 2012 20:59:34 +0100, Kiuhnm wrote: > Ok, so length and readability are orthogonal properties. Could you > please explain to me in which way > mov eax, 3 > should be less readable than > for i in x: print(i) > ? "mov eax, 3" requires more domain-specific knowledge. It operates at a very low level, that of memory locations and bytes, rather than at a level which most people can reason about efficiently. English speakers would probably guess that "mov" was an abbreviation of "move", but what is being moved, and from where to where, for what purpose? They're also likely to flounder on the analogy of "moving" bytes. When you move a book from here to there, you leave a space in the row of books where there is no longer a book. (You might choose to move a second book into that gap, but first there is a gap.) But when you move bytes, you don't leave a gap. There are always bytes at every valid address. The average non-programmer is likely to have the wrong data model to understand what "mov eax, 3" does. In the second example, most English speakers would intuit that "print(i)" prints i, whatever i is. "for i in x" is more cryptic, but if it were written with less jargon-like names, such as "for item in list" or "for person in family" or similar, they would likely guess that it means to repeat the following instructions for each item in the set: "For each person at the table, place a plate, knife and fork." And even if the reader can't guess the meaning of the for-loop, it is a concept easy enough for most people to grasp given some explanations and examples. It's neither too low level (assembly language), nor too high level (monads, functors) but is at just the right level of abstraction versus concreteness for the average person to follow. -- Steven From steve+comp.lang.python at pearwood.info Sat Mar 17 21:46:04 2012 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 18 Mar 2012 01:46:04 GMT Subject: Python is readable References: <4f612b19$0$1379$4fafbaef@reader2.news.tin.it> <8e72d74f-c844-4de3-8a37-f6b1fdc2291f@y27g2000yqy.googlegroups.com> <50e9ceec-40f1-4ead-b2b6-87328b30d084@ow8g2000pbc.googlegroups.com> <4f61c828$0$1390$4fafbaef@reader2.news.tin.it> <4f61d728$0$1375$4fafbaef@reader2.news.tin.it> <4f61fd0a$0$1389$4fafbaef@reader2.news.tin.it> <4f6280a0$0$29981$c3e8da3$5496439d@news.astraweb.com> <4f6333ca$0$1392$4fafbaef@reader1.news.tin.it> <4f633a1a$0$29981$c3e8da3$5496439d@news.astraweb.com> <4f64f2d8$0$1393$4fafbaef@reader1.news.tin.it> Message-ID: <4f653e5c$0$29981$c3e8da3$5496439d@news.astraweb.com> On Sat, 17 Mar 2012 21:23:45 +0100, Kiuhnm wrote: > On 3/16/2012 14:03, Steven D'Aprano wrote: >> A one line routine is still a routine. There is nothing ungrammatical >> about "If you can: take the bus.", although it is non-idiomatic >> English. > > In another post you wrote > "Sorry, I was talking about the other sort, the ones who apply the > grammatical rules used by people in real life. You know the ones: > linguists." > > Then how do you know that there's nothing ungrammatical about "If you > can: take the bus" if people don't use it? Who says it is ungrammatical? If the list (a list of one item, but still a list) was labelled as a list like this: If you can: (1) take the bus. or if the items were offset like this: If you can: - take the bus. (or similar) I wouldn't hesitate to say it was following the same form as this: Your mission, should you choose to accept it, is to: - take the bus ... - do this - do that - etc. even though in English we don't usually treat a list of one item as a list. That would make it unidiomatic but grammatically valid. But written in line, as you do, I'm not entirely sure. It is more of a grey area. It is not explicitly written as a list of items, so a colon seems a bit too "heavy" and I would prefer to write: If you can, take the bus. That flows better and is more idiomatic. On balance, I think it *is* grammatical but only on a technicality (a little like the (in)famous "Buffalo buffalo buffalo buffalo" sentence), but poorly written and not idiomatic. Natural languages frequently have many sentences which obey the grammatical rules and yet nobody uses that *specific* sentence, either because they feel clumsy, or because they are semantically meaningless, e.g. "hairless fears deconstruct lustily". But the problem with "If you can: take the bus" is not the colon or the initial sentence fragment. It is the fact that it introduces a list of a single item in a form that doesn't look like a list of items. This, for example, reads much more naturally: "If you can: take the bus to work every day; work hard for an unappreciative boss; give up 40% of your pay in taxes for a war you disagree with; use the rest to support a family that despises you; remind yourself that you're still happier than 90% of the people who have every lived." -- Steven From steve+comp.lang.python at pearwood.info Sat Mar 17 21:52:25 2012 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 18 Mar 2012 01:52:25 GMT Subject: Using non-dict namespaces in functions References: <4f647317$0$29981$c3e8da3$5496439d@news.astraweb.com> Message-ID: <4f653fd9$0$29981$c3e8da3$5496439d@news.astraweb.com> On Sat, 17 Mar 2012 11:42:49 -0700, Eric Snow wrote: > On Sat, Mar 17, 2012 at 4:18 AM, Steven D'Aprano > wrote: >> Note that it is important for my purposes that MockChainMap does not >> inherit from dict. > > Care to elaborate? I want to use collections.ChainMap, or something very like it, and I don't want to be forced into an unnatural is-a relationship with dict if I don't have to. [...] > Regardless, you could also implement __call__() on a function look-alike > class to get what you're after. It may not be as performant though. I don't think that can work, because __call__ itself is a function, and I would need to change *its* globals. Which brings me back exactly where I started, trying to change globals in a function to a non-dict. -- Steven From steve+comp.lang.python at pearwood.info Sat Mar 17 21:54:10 2012 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 18 Mar 2012 01:54:10 GMT Subject: Programming D. E. Knuth in Python with the Deterministic Finite Automaton construct References: <4f64a3a0$0$1386$4fafbaef@reader2.news.tin.it> <4f64a9e5$0$1385$4fafbaef@reader2.news.tin.it> <4f64d00a$0$1390$4fafbaef@reader1.news.tin.it> Message-ID: <4f654042$0$29981$c3e8da3$5496439d@news.astraweb.com> On Sat, 17 Mar 2012 17:28:38 -0600, Michael Torrie wrote: > Thank you. Your example makes more clear your assertion about "labels" > and how really A1 and A5 were the only real labels in the example. > Though I still do not really see why "states" is not a good equivalence > for labels in this case. Program labels are states. You can treat every line of code as being invisibly labelled with the line number. (Or visibly, if you are using BASIC back in 1975.) Clearly "the interpreter is executing at line 42" is a state distinct from "the interpreter is executing line 23", but that state *alone* is not sufficient to know the overall state of the program. Adding an explicit GOTO label does not change this. But this refers to the state of the interpreter, not the state of the program being executed, and either way, is not a state in the sense of a finite state machine. -- Steven From steve+usenet at pearwood.info Sat Mar 17 22:05:38 2012 From: steve+usenet at pearwood.info (Steven D'Aprano) Date: 18 Mar 2012 02:05:38 GMT Subject: Python is readable References: <4f612b19$0$1379$4fafbaef@reader2.news.tin.it> <50e9ceec-40f1-4ead-b2b6-87328b30d084@ow8g2000pbc.googlegroups.com> <4f61c828$0$1390$4fafbaef@reader2.news.tin.it> <4f61d728$0$1375$4fafbaef@reader2.news.tin.it> <4f61fd0a$0$1389$4fafbaef@reader2.news.tin.it> <4f6280a0$0$29981$c3e8da3$5496439d@news.astraweb.com> <4f6333ca$0$1392$4fafbaef@reader1.news.tin.it> <4f633a1a$0$29981$c3e8da3$5496439d@news.astraweb.com> <9sgsb1FsbpU1@mid.individual.net> <4f636a38$0$29981$c3e8da3$5496439d@news.astraweb.com> <9shd0kFvgbU1@mid.individual.net> <4f638b76$0$29981$c3e8da3$5496439d@news.astraweb.com> <9shj05FabeU1@mid.individual.net> <4f64fa18$0$1392$4fafbaef@reader1.news.tin.it> <4f6532e7$0$29981$c3e8da3$5496439d@news.astraweb.com> Message-ID: <4f6542f1$0$29981$c3e8da3$5496439d@news.astraweb.com> On Sun, 18 Mar 2012 12:07:36 +1100, Chris Angelico wrote: > On Sun, Mar 18, 2012 at 11:57 AM, Steven D'Aprano > wrote: >> The vast majority of English speakers write things like: >> >> ? ?TO DO: > > And the vast majority of programmers leave out the space, even in > non-code. I'm not sure if you're making a point there, or just a witty observation, but for the record I would accept dictionaries adding "todo" as a jargon entry. I don't think it is widespread enough to count as a regular word, but if we can have "another", "anywhere", "nowhere" and "pocketbook", I don't see why we might not someday have "todo". -- Steven From rosuav at gmail.com Sat Mar 17 22:15:08 2012 From: rosuav at gmail.com (Chris Angelico) Date: Sun, 18 Mar 2012 13:15:08 +1100 Subject: Python is readable In-Reply-To: <4f6542f1$0$29981$c3e8da3$5496439d@news.astraweb.com> References: <4f612b19$0$1379$4fafbaef@reader2.news.tin.it> <50e9ceec-40f1-4ead-b2b6-87328b30d084@ow8g2000pbc.googlegroups.com> <4f61c828$0$1390$4fafbaef@reader2.news.tin.it> <4f61d728$0$1375$4fafbaef@reader2.news.tin.it> <4f61fd0a$0$1389$4fafbaef@reader2.news.tin.it> <4f6280a0$0$29981$c3e8da3$5496439d@news.astraweb.com> <4f6333ca$0$1392$4fafbaef@reader1.news.tin.it> <4f633a1a$0$29981$c3e8da3$5496439d@news.astraweb.com> <9sgsb1FsbpU1@mid.individual.net> <4f636a38$0$29981$c3e8da3$5496439d@news.astraweb.com> <9shd0kFvgbU1@mid.individual.net> <4f638b76$0$29981$c3e8da3$5496439d@news.astraweb.com> <9shj05FabeU1@mid.individual.net> <4f64fa18$0$1392$4fafbaef@reader1.news.tin.it> <4f6532e7$0$29981$c3e8da3$5496439d@news.astraweb.com> <4f6542f1$0$29981$c3e8da3$5496439d@news.astraweb.com> Message-ID: On Sun, Mar 18, 2012 at 1:05 PM, Steven D'Aprano wrote: > I'm not sure if you're making a point there, or just a witty observation, > but for the record I would accept dictionaries adding "todo" as a jargon > entry. I don't think it is widespread enough to count as a regular word, > but if we can have "another", "anywhere", "nowhere" and "pocketbook", I > don't see why we might not someday have "todo". A bit of both. My point is: The jargon that is developed in specific domains (such as TODO, and the P-convention among Lispers, and so on) often ends up used outside it. Once people not associated with the original domain are using that jargon, it can be safely declared to be part of the language. TODO mightn't be there quite yet, but I agree, it's highly likely to be dictionarified (is THAT a word?) before long. ChrisA From driscoll at cs.wisc.edu Sat Mar 17 22:59:31 2012 From: driscoll at cs.wisc.edu (Evan Driscoll) Date: Sat, 17 Mar 2012 21:59:31 -0500 Subject: Programming D. E. Knuth in Python with the Deterministic Finite Automaton construct In-Reply-To: References: Message-ID: <4F654F93.4080309@cs.wisc.edu> On 3/17/2012 9:03, Antti J Ylikoski wrote: > > In his legendary book series The Art of Computer Programming, > Professor Donald E. Knuth presents many of his algorithms in the form > that they have been divided in several individual phases, with > instructions to GOTO to another phase interspersed in the text of the > individual phases. > > > A1. (Do the work of Phase A1.) If then go to Phase A5, > otherwise continue. > > A2. (Do some work.) If go to Phase A4. > > A3. (Some more work.) > > A4. (Do something.) If go to Phase A1. > > A5. (Something more). If then go to Phase A2, otherwise > end. Clearly you just need the goto module (http://entrian.com/goto/): from goto import goto, label label .A1 # do work of phase A1 if : goto .A5 label .A2 # do some work if : goto .A4 # do some more work label .A4 # do something if : goto .A1 label .A5 # something more if : goto .A2 Clearly the best solution of all. (Note: do not actually do this.) Evan -------------- next part -------------- A non-text attachment was scrubbed... Name: signature.asc Type: application/pgp-signature Size: 552 bytes Desc: OpenPGP digital signature URL: From cs at zip.com.au Sun Mar 18 00:15:48 2012 From: cs at zip.com.au (Cameron Simpson) Date: Sun, 18 Mar 2012 15:15:48 +1100 Subject: Daemonization / Popen / pipe issue In-Reply-To: <20120318123516.0c13a6345c333a040568b95a@johnohagan.com> References: <20120318123516.0c13a6345c333a040568b95a@johnohagan.com> Message-ID: <20120318041548.GA15675@cskk.homeip.net> On 18Mar2012 12:35, John O'Hagan wrote: | On Sat, 17 Mar 2012 18:17:10 -0400 | Lee Clemens wrote: | > Is it generally not recommended to daemonize Python applications using | > this method? | | I'm no guru, but not that I know of. I haven't seen the os.fork method you use | before; out of interest, why not use Thread.setDaemon? They are two entirely different practices. Thread.setDaemon is a flag for a particular thread telling the python system to not bother waiting for it at exit time. The daemonize stuff Lee is using is "daemon" in the UNIX sense: forking the main process (the whole python instance) into an unassociated process not subject to job control etc. I glanced at Lee's code and have seen found anything obviously wrong yet. Maybe if I get a bit more time later. It seems that in daemon mode the code forks first, exactly once, before firing off any subprocesses or threads. Is this correct? If the daemonising happened per thread that would be very bad. BTW, Lee, there is an external module for daemonising things in the UNIX sense: http://pypi.python.org/pypi/python-daemon I recommend you use it. Cheers, -- Cameron Simpson DoD#743 http://www.cskk.ezoshosting.com/cs/ The First Law of Internet Communications: Be liberal in what you accept, and conservative in what you send. - Jon Postel From van.lindberg at gmail.com Sun Mar 18 00:51:49 2012 From: van.lindberg at gmail.com (VanL) Date: Sat, 17 Mar 2012 23:51:49 -0500 Subject: Comments wanted: Proposed change to install layout Message-ID: There is a proposal on Python-dev right now (championed by me) to harmonize the install layout for Python between platforms. This change would be most noticeable on Windows. Specifically, using Python 3.3 or above: 1) the 'Scripts' directory would change to 'bin'; 2) python.exe would move to the 'bin' directory; and 3) the installer for Windows would get the optional ability to add this directory to the PATH. Please reply if this would help you or harm you, and how. Thanks, Van -------------- next part -------------- An HTML attachment was scrubbed... URL: From __peter__ at web.de Sun Mar 18 03:50:46 2012 From: __peter__ at web.de (Peter Otten) Date: Sun, 18 Mar 2012 08:50:46 +0100 Subject: Using non-dict namespaces in functions References: <4f647317$0$29981$c3e8da3$5496439d@news.astraweb.com> <4f653fd9$0$29981$c3e8da3$5496439d@news.astraweb.com> Message-ID: Steven D'Aprano wrote: > On Sat, 17 Mar 2012 11:42:49 -0700, Eric Snow wrote: > >> On Sat, Mar 17, 2012 at 4:18 AM, Steven D'Aprano >> wrote: >>> Note that it is important for my purposes that MockChainMap does not >>> inherit from dict. >> >> Care to elaborate? > > I want to use collections.ChainMap, or something very like it, and I > don't want to be forced into an unnatural is-a relationship with dict if > I don't have to. > > > [...] >> Regardless, you could also implement __call__() on a function look-alike >> class to get what you're after. It may not be as performant though. > > I don't think that can work, because __call__ itself is a function, and I > would need to change *its* globals. Which brings me back exactly where I > started, trying to change globals in a function to a non-dict. The key lookup code in ceval.c is inlined, so even subclassing dict and overriding __getitem__() won't help. Instead of def f(a): return a + b # b taken from some custom namespace you have to resort to the conventional approach def f(a, ns=magic()): return a + ns["b"] or def f(self, a): return a + self.b From cosmius at gmail.com Sun Mar 18 05:42:20 2012 From: cosmius at gmail.com (Cosmia Luna) Date: Sun, 18 Mar 2012 02:42:20 -0700 (PDT) Subject: How to get a reference of the 'owner' class to which a method belongs in Python 3.X? In-Reply-To: References: <20411334.2044.1331962234309.JavaMail.geo-discussion-forums@yncd8> Message-ID: <14929632.47.1332063740635.JavaMail.geo-discussion-forums@ynbq18> I think I got the way to handle it but with small problem and probably at unnecessary performance cost. If you're going to use it, be sure rewrite the code and remove the lines which you don't need. Annnnd, test them, the code below is only tested on py3.2, and may contains a lot of bugs even in py3.2. You don't need it in py2.X, really. ----------------------------------BEGIN PYTHON---------------------------------- from functools import wraps from types import FunctionType CLASS_REF = 'im_class' class Py2Type(type): def __init__(cls, name, bases, dict_): for k, v in dict_.items(): #ref3 if isinstance(v, FunctionType): setattr(v, CLASS_REF, cls) for base in bases: for k, v in base.__dict__.items(): if isinstance(v, FunctionType) and k not in dict_: @wraps(v) def wrapper(*args, **kwargs): return v(*args, **kwargs) setattr(wrapper, CLASS_REF, cls) dict_[k] = wrapper setattr(cls, k, wrapper) #ref1 type.__init__(cls, name, bases, dict_) #ref2 Py2TypeBase = Py2Type('Py2TypeBase', (object, ), {}) -----------------------------------END PYTHON----------------------------------- And any class inherit(directly or indirectly) from Py2TypeBase can have them unbound method has a 'im_class' attribute reference to the owner class. Usage: Just subclass Py2TypeBase and write anything you want. ----------------------------------BEGIN PYTHON---------------------------------- class Foo(Py2TypeBase): def get(self): pass def set(self): pass class Bar(Foo): def get(self): pass assert Foo.get.im_class is Foo assert Foo.set.im_class is Foo assert Bar.get.im_class is Bar assert Bar.set.im_class is Bar # the code above works, but only the explicitly defined will has the # im_class attribute, so assert Foo.__init__.im_class is Foo # this doesn't work. -----------------------------------END PYTHON----------------------------------- But it seems that the last line(#ref2) in the Py2Type.__init__ does not work at all. It seems really weird, 'type' is an instance of 'type' itself, I'm not sure if I'm calling the unbound method __init__ or bound method __init__. And the original code does not have the line(#ref1), but because line(#ref2) does not work, I added them. It seems type.__new__ calls type.__init__ before it calls Py2Type.__init__, because dict_ is already copied to cls.__dict__ at line(#ref3). But 'type' is written in C or some other, it's beyond my ability to read the code. Can anyone tell me what python does when a class block is fully evaluated kindly? Regards, Cosmia From cosmius at gmail.com Sun Mar 18 05:42:20 2012 From: cosmius at gmail.com (Cosmia Luna) Date: Sun, 18 Mar 2012 02:42:20 -0700 (PDT) Subject: How to get a reference of the 'owner' class to which a method belongs in Python 3.X? In-Reply-To: References: <20411334.2044.1331962234309.JavaMail.geo-discussion-forums@yncd8> Message-ID: <14929632.47.1332063740635.JavaMail.geo-discussion-forums@ynbq18> I think I got the way to handle it but with small problem and probably at unnecessary performance cost. If you're going to use it, be sure rewrite the code and remove the lines which you don't need. Annnnd, test them, the code below is only tested on py3.2, and may contains a lot of bugs even in py3.2. You don't need it in py2.X, really. ----------------------------------BEGIN PYTHON---------------------------------- from functools import wraps from types import FunctionType CLASS_REF = 'im_class' class Py2Type(type): def __init__(cls, name, bases, dict_): for k, v in dict_.items(): #ref3 if isinstance(v, FunctionType): setattr(v, CLASS_REF, cls) for base in bases: for k, v in base.__dict__.items(): if isinstance(v, FunctionType) and k not in dict_: @wraps(v) def wrapper(*args, **kwargs): return v(*args, **kwargs) setattr(wrapper, CLASS_REF, cls) dict_[k] = wrapper setattr(cls, k, wrapper) #ref1 type.__init__(cls, name, bases, dict_) #ref2 Py2TypeBase = Py2Type('Py2TypeBase', (object, ), {}) -----------------------------------END PYTHON----------------------------------- And any class inherit(directly or indirectly) from Py2TypeBase can have them unbound method has a 'im_class' attribute reference to the owner class. Usage: Just subclass Py2TypeBase and write anything you want. ----------------------------------BEGIN PYTHON---------------------------------- class Foo(Py2TypeBase): def get(self): pass def set(self): pass class Bar(Foo): def get(self): pass assert Foo.get.im_class is Foo assert Foo.set.im_class is Foo assert Bar.get.im_class is Bar assert Bar.set.im_class is Bar # the code above works, but only the explicitly defined will has the # im_class attribute, so assert Foo.__init__.im_class is Foo # this doesn't work. -----------------------------------END PYTHON----------------------------------- But it seems that the last line(#ref2) in the Py2Type.__init__ does not work at all. It seems really weird, 'type' is an instance of 'type' itself, I'm not sure if I'm calling the unbound method __init__ or bound method __init__. And the original code does not have the line(#ref1), but because line(#ref2) does not work, I added them. It seems type.__new__ calls type.__init__ before it calls Py2Type.__init__, because dict_ is already copied to cls.__dict__ at line(#ref3). But 'type' is written in C or some other, it's beyond my ability to read the code. Can anyone tell me what python does when a class block is fully evaluated kindly? Regards, Cosmia From albert at spenarnc.xs4all.nl Sun Mar 18 07:03:43 2012 From: albert at spenarnc.xs4all.nl (Albert van der Horst) Date: 18 Mar 2012 11:03:43 GMT Subject: Programming D. E. Knuth in Python with the Deterministic Finite Automaton construct References: <4f64d00a$0$1390$4fafbaef@reader1.news.tin.it> <4f654042$0$29981$c3e8da3$5496439d@news.astraweb.com> Message-ID: In article <4f654042$0$29981$c3e8da3$5496439d at news.astraweb.com>, Steven D'Aprano wrote: >On Sat, 17 Mar 2012 17:28:38 -0600, Michael Torrie wrote: > >> Thank you. Your example makes more clear your assertion about "labels" >> and how really A1 and A5 were the only real labels in the example. >> Though I still do not really see why "states" is not a good equivalence >> for labels in this case. > >Program labels are states. > >You can treat every line of code as being invisibly labelled with the >line number. (Or visibly, if you are using BASIC back in 1975.) Clearly >"the interpreter is executing at line 42" is a state distinct from "the >interpreter is executing line 23", but that state *alone* is not >sufficient to know the overall state of the program. This is the idea of the original (not universal, hard coded) Turing machine with cards. Of course you then still need the infinite tape to store calculation input and output. > >Adding an explicit GOTO label does not change this. > >But this refers to the state of the interpreter, not the state of the >program being executed, and either way, is not a state in the sense of a >finite state machine. I hope the reference to the Turing machine makes this clearer. Turing Machines and Finite State Machines are different constructions in automaton theory. Remember those definitions are like A Turing machine is a set S the set of symbols T a mapping of S onto IZ (natural numbers) ... F is a mapping from SxT into G .. Some such. (A FSM is just different with different mappings ) The memory of the Turing machine is T , the tape, time dependant. The program of the Turing is e.g. F, to be thought of as hard wiring. A Turing machine is *not* a stored program computer! The universal Turing machine is, it contains a hardwired program to execute a stored program on the tape. > >-- >Steven Groetjes Albert -- -- Albert van der Horst, UTRECHT,THE NETHERLANDS Economic growth -- being exponential -- ultimately falters. albert at spe&ar&c.xs4all.nl &=n http://home.hccnet.nl/a.w.m.van.der.horst From albert at spenarnc.xs4all.nl Sun Mar 18 07:08:59 2012 From: albert at spenarnc.xs4all.nl (Albert van der Horst) Date: 18 Mar 2012 11:08:59 GMT Subject: Programming D. E. Knuth in Python with the Deterministic Finite Automaton construct References: Message-ID: In article , Antti J Ylikoski wrote: > >In his legendary book series The Art of Computer Programming, >Professor Donald E. Knuth presents many of his algorithms in the form >that they have been divided in several individual phases, with >instructions to GOTO to another phase interspersed in the text of the >individual phases. > > > >I. e. they look like the following, purely invented, example: (Knuth is >being clearer than me below.....) > > > >A1. (Do the work of Phase A1.) If then go to Phase A5, >otherwise continue. > >A2. (Do some work.) If go to Phase A4. > >A3. (Some more work.) > >A4. (Do something.) If go to Phase A1. > >A5. (Something more). If then go to Phase A2, otherwise >end. I can rewrite this into Python in my sleep, without resorting to formal techniques. Instead try one of the harder algorithms like T (Toom Cook) that must be translated to recursive functions that pass data down. That took me quite a wile. The correct answer is, it is just labour. Deal with it. Note that if you want to translate it to assembler, it is relatively easy. > >kind regards, Antti J Ylikoski >Helsinki, Finland, the EU Groetjes Albert -- -- Albert van der Horst, UTRECHT,THE NETHERLANDS Economic growth -- being exponential -- ultimately falters. albert at spe&ar&c.xs4all.nl &=n http://home.hccnet.nl/a.w.m.van.der.horst From adminlewis at gmail.com Sun Mar 18 08:03:47 2012 From: adminlewis at gmail.com (admin lewis) Date: Sun, 18 Mar 2012 13:03:47 +0100 Subject: dpkg status Message-ID: Hi, anyone know what library i have to use to manage /var/lib/dpkg/status file to get url of packages ? thanks lewis -- Linux Server, Microsoft Windows 2003/2008 Server, Exchange 2007 http://predellino.blogspot.com/ From andrea.crotti.0 at gmail.com Sun Mar 18 09:31:50 2012 From: andrea.crotti.0 at gmail.com (Andrea Crotti) Date: Sun, 18 Mar 2012 13:31:50 +0000 Subject: Unittest2 on python 2.6 Message-ID: <4F65E3C6.2020405@gmail.com> Suppose we want to use the unittest from Python 2.7, but also want to support Python 2.6, what is the best way to do it? The solution used now is to have in setup.py if sys.version < '2.7': tests_require.append('unittest2') and then in every test file try: import unittest2 as unittest except ImportError: import unittest and it should work just fine, but it's a bit verbose to have this try/except dance everywhere.. Any ideas? From vincent.vandevyvre at swing.be Sun Mar 18 10:00:06 2012 From: vincent.vandevyvre at swing.be (Vincent Vande Vyvre) Date: Sun, 18 Mar 2012 15:00:06 +0100 Subject: dpkg status In-Reply-To: References: Message-ID: <4F65EA66.8000509@swing.be> An HTML attachment was scrubbed... URL: From adminlewis at gmail.com Sun Mar 18 10:54:41 2012 From: adminlewis at gmail.com (admin lewis) Date: Sun, 18 Mar 2012 15:54:41 +0100 Subject: dpkg status In-Reply-To: <4F65EA66.8000509@swing.be> References: <4F65EA66.8000509@swing.be> Message-ID: 2012/3/18 Vincent Vande Vyvre : > Le 18/03/12 13:03, admin lewis a ?crit?: > > Hi, > > What url ?, Sources, maintainer? > No, I need of to open /var/lib/dpkg/status and extract the packages and its url to download it... I know that there is python-apt http://apt.alioth.debian.org/python-apt-doc/library/index.html but I dont understand how it works.. -- Linux Server, Microsoft Windows 2003/2008 Server, Exchange 2007 http://predellino.blogspot.com/ From vincent.vandevyvre at swing.be Sun Mar 18 11:17:57 2012 From: vincent.vandevyvre at swing.be (Vincent Vande Vyvre) Date: Sun, 18 Mar 2012 16:17:57 +0100 Subject: dpkg status In-Reply-To: References: <4F65EA66.8000509@swing.be> Message-ID: <4F65FCA5.8090504@swing.be> An HTML attachment was scrubbed... URL: From tjreedy at udel.edu Sun Mar 18 11:46:39 2012 From: tjreedy at udel.edu (Terry Reedy) Date: Sun, 18 Mar 2012 11:46:39 -0400 Subject: Unittest2 on python 2.6 In-Reply-To: <4F65E3C6.2020405@gmail.com> References: <4F65E3C6.2020405@gmail.com> Message-ID: On 3/18/2012 9:31 AM, Andrea Crotti wrote: > Suppose we want to use the unittest from Python 2.7, but also want to > support Python 2.6, > what is the best way to do it? > > The solution used now is to have in setup.py > > if sys.version < '2.7': > tests_require.append('unittest2') > > and then in every test file > > try: > import unittest2 as unittest > except ImportError: > import unittest > > and it should work just fine, but it's a bit verbose to have this > try/except dance everywhere.. > Any ideas? 1. If the difference between unittest and unittest2 is strictly a matter of deletions and addition, replace unittest with the union of the two. 2. Put the try/except dance in a compat file. Then everywhere else 'from compat import unittest'. This idea is one of those used to write code that will run on both 2.x and 3.x -- Terry Jan Reedy From ian.g.kelly at gmail.com Sun Mar 18 12:14:12 2012 From: ian.g.kelly at gmail.com (Ian Kelly) Date: Sun, 18 Mar 2012 10:14:12 -0600 Subject: How to get a reference of the 'owner' class to which a method belongs in Python 3.X? In-Reply-To: <14929632.47.1332063740635.JavaMail.geo-discussion-forums@ynbq18> References: <20411334.2044.1331962234309.JavaMail.geo-discussion-forums@yncd8> <14929632.47.1332063740635.JavaMail.geo-discussion-forums@ynbq18> Message-ID: On Sun, Mar 18, 2012 at 3:42 AM, Cosmia Luna wrote: > But it seems that the last line(#ref2) in the Py2Type.__init__ does not work at > all. I'm not sure what you're expecting it to do, but type.__init__ does not actually do anything > It seems really weird, 'type' is an instance of 'type' itself, I'm not sure > if I'm calling the unbound method __init__ or bound method __init__. type.__init__ is never bound. > It seems type.__new__ calls type.__init__ before it calls Py2Type.__init__, > because dict_ is already copied to cls.__dict__ at line(#ref3). No, type.__new__ does not call type.__init__ at all. Rather, it is type.__new__ that is responsible for copying the dict, not type.__init__. For this reason you should override type.__new__ in your metaclass, not type.__init__. Cheers, Ian From adminlewis at gmail.com Sun Mar 18 12:43:51 2012 From: adminlewis at gmail.com (admin lewis) Date: Sun, 18 Mar 2012 17:43:51 +0100 Subject: dpkg status In-Reply-To: <4F65FCA5.8090504@swing.be> References: <4F65EA66.8000509@swing.be> <4F65FCA5.8090504@swing.be> Message-ID: 2012/3/18 Vincent Vande Vyvre : > > > OK, you know apt, I see (your blog). > > But packages have no url, just repositery. > > I see your link python-apt, this doc is very minimalistic, maybe you can > find repositeries infos of packages with aptsources.distinfo, but methods > are not documented. > > http://apt.alioth.debian.org/python-apt-doc/library/aptsources.distinfo.html#module-aptsources.distinfo > Well no, I need something like the following: import apt_pkg tagf = apt_pkg.TagFile(open('/home/lightbox/status')) for section in tagf: indirizzo="http://it.archive.ubuntu.com/ubuntu/pool/main/"+section['Package'][0]+'/'+section['Package']+'/'+section['Package']+'_'+section['Version']+'_'+section['Architecture']+'.deb'+'\n' print indirizzo with the following output: http://it.archive.ubuntu.com/ubuntu/pool/main/t/texlive-lang-all/texlive-lang-all_2009-3_all.deb http://it.archive.ubuntu.com/ubuntu/pool/main/x/xserver-xorg-input-vmmouse/xserver-xorg-input-vmmouse_1:12.7.0-2_i386.deb http://it.archive.ubuntu.com/ubuntu/pool/main/l/libmono-system-data4.0-cil/libmono-system-data4.0-cil_2.10.5-1_all.deb but the best sould be that the script make the download of deb automatically.. infact if u see the output u will see that is not correct.. because the section texlive-lang-all doesn't exist and the correct one is texlive-lang I dont know if i have to connect to the cache of apt or simply i need of source.list.. thanks for any help luigi P.S. the /home/lightbox/status is a partial file of /var/lib/dpkg/status -- Linux Server, Microsoft Windows 2003/2008 Server, Exchange 2007 http://predellino.blogspot.com/ From alister.ware at ntlworld.com Sun Mar 18 14:19:23 2012 From: alister.ware at ntlworld.com (alister) Date: Sun, 18 Mar 2012 18:19:23 GMT Subject: Python is readable References: <4f612b19$0$1379$4fafbaef@reader2.news.tin.it> Message-ID: On Thu, 15 Mar 2012 00:34:47 +0100, Kiuhnm wrote: > I've just started to read > The Quick Python Book (2nd ed.) > The author claims that Python code is more readable than Perl code and > provides this example: > > --- Perl --- > sub pairwise_sum { > my($arg1, $arg2) = @_; > my(@result) = (); > @list1 = @$arg1; > @list2 = @$arg2; > for($i=0; $i < length(@list1); $i++) { > push(@result, $list1[$i] + $list2[$i]); > } > return(\@result); > } > > --- Python --- > def pairwise_sum(list1, list2): > result = [] > for i in range(len(list1)): > result.append(list1[i] + list2[i]) > return result > --- --- > > It's quite clear that he knows little about Perl. > Here's what I would've written: > > sub pairwise_sum { > my ($list1, $list2) = @_; > my @result; > push @result, $list1->[$_] + $list2->[$_] for (0..@$list1-1); > \@result; > } > > Having said that, the Python code is still more readable, so there's no > need to misrepresent Perl that way. > Now I'm wondering whether the author will show me "good" or "bad" Python > code throughout the book. Should I keep reading? > > Kiuhnm I have a simple experience which to me demonstrates python must be fairly readable. I gave a copy of a small utility to a friend of mine, whilst running it he found an obscure case that would cause a crash, he has only limited programming experience of any sort but from the python trace-back he was able to read my code & made a suggestion of what he thought would fix the issue, this suggestion was spot on. -- Necessity is a mother. From alex at moreati.org.uk Sun Mar 18 16:13:32 2012 From: alex at moreati.org.uk (Alex Willmer) Date: Sun, 18 Mar 2012 13:13:32 -0700 (PDT) Subject: Benchmarking stripping of Unicode characters which are invalid XML Message-ID: <11575952.4030.1332101612105.JavaMail.geo-discussion-forums@vbai14> Last week I was surprised to discover that there are Unicode characters that aren't valid in an XML document. That is regardless of escaping (e.g. �) and unicode encoding (e.g. UTF-8) - not every Unicode string can be stored in XML. The valid characters are (as of XML 1.0) #x9 | #xA | #xD | [#x20-#xD7FF] | [#xE000-#xFFFD] | [#x10000-#x10FFFF]. Others such as #x13 must be stripped, replaced or placed inside a wrapper such as base64. I didn't find an existing function to strip these so I wrote some and benchmarked them. I'd be interested for thoughts, suggestions and improvements. regsub_p2 was the fastest on a string containing mostly printable-ascii. regsub_p1 0.422097921371 True regsub_p2 0.353546857834 True regsub_p3 0.697242021561 True regsub_p4 0.677567005157 True genexp_p1 6.43633103371 True genexp_p2 6.43329787254 True genexp_p3 6.80837488174 True genexp_p4 6.81470417976 True filter_p1 7.21444416046 True filter_p2 7.46805095673 True filter_p3 7.37018704414 True filter_p4 7.03261303902 True genexp_f1 12.8470640182 True genexp_f2 5.43630099297 True genexp_f3 4.9708840847 True genexp_f4 12.2384109497 True genexp_f5 6.95861411095 True genexp_f6 4.7168610096 True genexp_f7 20.2065701485 True genexp_f8 21.1112251282 True Regards, Alex #!/usr/bin/python # Valid XML 1.0 characters are # #x9 | #xA | #xD | [#x20-#xD7FF] | [#xE000-#xFFFD] | [#x10000-#x10FFFF] # http://www.w3.org/TR/2008/PER-xml-20080205/#charsets # # Before passing an arbitrary unicode string to an XML encoder invalid characters # must be stripped or replaced. Escaping them doesn't help - they're simply not # allowed in a well formed XML 1.0 document. # The following script banchmarks several functions that strip them import re import string import timeit p1 = re.compile(u'[^\x09\x0A\x0D\u0020-\uD7FF' u'\uE000-\uFFFD\U00010000-\U0010FFFF]', re.U) p2 = re.compile(u'[^\u0020-\uD7FF\x09\x0A\x0D' u'\uE000-\uFFFD\U00010000-\U0010FFFF]', re.U) p3 = re.compile(p1.pattern + u'+', re.U) p4 = re.compile(p2.pattern + u'+', re.U) def regsub_p1(s): return p1.sub(u'', s) def regsub_p2(s): return p2.sub(u'', s) def regsub_p3(s): return p3.sub(u'', s) def regsub_p4(s): return p4.sub(u'', s) def genexp_p1(s): return u''.join(c for c in s if not p1.match(c)) def genexp_p2(s): return u''.join(c for c in s if not p2.match(c)) def genexp_p3(s): return u''.join(c for c in s if not p3.match(c)) def genexp_p4(s): return u''.join(c for c in s if not p4.match(c)) def filter_p1(s): return u''.join(filter(lambda c: not p1.match(c), s)) def filter_p2(s): return u''.join(filter(lambda c: not p2.match(c), s)) def filter_p3(s): return u''.join(filter(lambda c: not p3.match(c), s)) def filter_p4(s): return u''.join(filter(lambda c: not p4.match(c), s)) def f1(c): i = ord(c) return (i in set([0x09, 0x0A, 0x0D]) or 0x0020 <= i <= 0xD7FF or 0xE000 <= i <= 0xFFFD or 0x00010000 <= i <= 0x0010FFFF) def f2(c): i = ord(c) return (0x0020 <= i <= 0xD7FF or i in set([0x09, 0x0A, 0x0D]) or 0xE000 <= i <= 0xFFFD or 0x00010000 <= i <= 0x0010FFFF) def f3(c): return (u'\u0020' <= c <= u'\uD7FF' or c in set([u'\x09', u'\x0A', u'\x0D']) or u'\uE000' <= c <= u'\uFFFD' or u'\U00010000' <= c <= u'\U0010FFFF') def f4(c): return (c in set([u'\x09', u'\x0A', u'\x0D']) or u'\u0020' <= c <= u'\uD7FF' or u'\uE000' <= c <= u'\uFFFD' or u'\U00010000' <= c <= u'\U0010FFFF') def f5(c): return (c == u'\x09' or c == u'\x0A' or c == u'\x0D' or u'\u0020' <= c <= u'\uD7FF' or u'\uE000' <= c <= u'\uFFFD' or u'\U00010000' <= c <= u'\U0010FFFF') def f6(c): return (u'\u0020' <= c <= u'\uD7FF' or c == u'\x09' or c == u'\x0A' or c == u'\x0D' or u'\uE000' <= c <= u'\uFFFD' or u'\U00010000' <= c <= u'\U0010FFFF') every_8bit = u''.join(unichr(i) for i in range(256)) valid_8bit = u''.join(c for c in every_8bit if f1(c)) invalid_8bit = u''.join(c for c in every_8bit if not f1(c)) invalid_8bit_iso88591 = invalid_8bit.encode('iso-8859-1') translator = string.maketrans(invalid_8bit_iso88591, '\x00' * len(invalid_8bit_iso88591)) def f7(c): return ((c <= u'\xff' and ord(string.translate(c.encode('iso-8859-1'), translator))) or u'\uE000' <= c <= u'\uFFFD' or u'\U00010000' <= c <= u'\U0010FFFF') def f8(c): return ((c <= u'\xff' and string.translate(c.encode('iso-8859-1'), None, invalid_8bit_iso88591)) or u'\uE000' <= c <= u'\uFFFD' or u'\U00010000' <= c <= u'\U0010FFFF') def genexp_f1(s): return u''.join(c for c in s if f1(c)) def genexp_f2(s): return u''.join(c for c in s if f2(c)) def genexp_f3(s): return u''.join(c for c in s if f3(c)) def genexp_f4(s): return u''.join(c for c in s if f4(c)) def genexp_f5(s): return u''.join(c for c in s if f5(c)) def genexp_f6(s): return u''.join(c for c in s if f6(c)) def genexp_f7(s): return u''.join(c for c in s if f7(c)) def genexp_f8(s): return u''.join(c for c in s if f8(c)) if __name__ == '__main__': sample_in = u'''Lorem ipsum dolor sit amet\x00, consectetur adipisicing elit, \tsed \rdo eiusmod tempor incididunt \x13ut labore et dolore magna \xf7aliqua.\ufffe''' expected_out = u'''Lorem ipsum dolor sit amet, consectetur adipisicing elit, \tsed \rdo eiusmod tempor incididunt ut labore et dolore magna \xf7aliqua.''' for func, inner_fun in [(regsub_p1, p1), (regsub_p2, p2), (regsub_p3, p3), (regsub_p4, p4), (genexp_p1, p1), (genexp_p2, p2), (genexp_p3, p3), (genexp_p4, p4), (filter_p1, p1), (filter_p2, p2), (filter_p3, p3), (filter_p4, p4), (genexp_f1, f1), (genexp_f2, f2), (genexp_f3, f3), (genexp_f4, f4), (genexp_f5, f5), (genexp_f6, f6), (genexp_f7, f7), (genexp_f8, f8), ]: t = timeit.Timer(r'%s(%s)' % (func.__name__, repr(sample_in)), 'from __main__ import %s' % (func.__name__,)) print func.__name__, print min(t.repeat(3, 100000)), print func(sample_in) == expected_out, print From andrea.crotti.0 at gmail.com Sun Mar 18 16:55:04 2012 From: andrea.crotti.0 at gmail.com (Andrea Crotti) Date: Sun, 18 Mar 2012 20:55:04 +0000 Subject: Unittest2 on python 2.6 In-Reply-To: References: <4F65E3C6.2020405@gmail.com> Message-ID: <4F664BA8.8090800@gmail.com> On 03/18/2012 03:46 PM, Terry Reedy wrote: > 1. If the difference between unittest and unittest2 is strictly a > matter of deletions and addition, replace unittest with the union of > the two. > > 2. Put the try/except dance in a compat file. Then everywhere else > 'from compat import unittest'. This idea is one of those used to write > code that will run on both 2.x and 3.x > 1. I think that unittest2 is a simple superset of unittest, but unittest2 is a backport of unittest module in Python 2.7, that's the point, so I don't see how I should replace it with the union.. 2. good idea thanks From ladasky at my-deja.com Sun Mar 18 17:30:15 2012 From: ladasky at my-deja.com (John Ladasky) Date: Sun, 18 Mar 2012 14:30:15 -0700 (PDT) Subject: Python is readable References: <4f612b19$0$1379$4fafbaef@reader2.news.tin.it> <8e72d74f-c844-4de3-8a37-f6b1fdc2291f@y27g2000yqy.googlegroups.com> <50e9ceec-40f1-4ead-b2b6-87328b30d084@ow8g2000pbc.googlegroups.com> Message-ID: On Mar 14, 11:23?pm, alex23 wrote: > The idea that Python code has to be obvious to non-programmers is an > incorrect and dangerous one. Incorrect? Probably. Dangerous? You'll have to explain what you mean. What I would say is that, when PROGRAMMERS look at Python code for the first time, they will understand what it does more readily than they would understand other unfamiliar programming languages. That has value. From tjreedy at udel.edu Sun Mar 18 17:58:55 2012 From: tjreedy at udel.edu (Terry Reedy) Date: Sun, 18 Mar 2012 17:58:55 -0400 Subject: Unittest2 on python 2.6 In-Reply-To: <4F664BA8.8090800@gmail.com> References: <4F65E3C6.2020405@gmail.com> <4F664BA8.8090800@gmail.com> Message-ID: On 3/18/2012 4:55 PM, Andrea Crotti wrote: > On 03/18/2012 03:46 PM, Terry Reedy wrote: >> 1. If the difference between unittest and unittest2 is strictly a >> matter of deletions and addition, replace unittest with the union of >> the two. >> >> 2. Put the try/except dance in a compat file. Then everywhere else >> 'from compat import unittest'. This idea is one of those used to write >> code that will run on both 2.x and 3.x >> > > 1. I think that unittest2 is a simple superset of unittest, but > unittest2 is a backport of unittest module in Python 2.7, that's the point, > so I don't see how I should replace it with the union. If set A contains set B, then A is the union of the two. The danger of replacing unittest with unittest2 in a 2.6 installation is that 2.6 code that used the new features will not run in a 'normal' 2.6 installation. Whether that is a potential problem depends on whether you ever expect the code to escape from the altered environment. I said 'union' because I was not familiar with its details. I was allowing for the possibility that features were both deleted and added, in which case the union would include all features and work with multiple versions. That is moot for this case but not some others. > 2. good idea thanks The advantage of even one explicit unittest2 import, even if hidden away, is that you get a proper error message if you run the code where unittest2 is not present. -- Terry Jan Reedy From rosuav at gmail.com Sun Mar 18 18:02:06 2012 From: rosuav at gmail.com (Chris Angelico) Date: Mon, 19 Mar 2012 09:02:06 +1100 Subject: Python is readable In-Reply-To: References: <4f612b19$0$1379$4fafbaef@reader2.news.tin.it> <8e72d74f-c844-4de3-8a37-f6b1fdc2291f@y27g2000yqy.googlegroups.com> <50e9ceec-40f1-4ead-b2b6-87328b30d084@ow8g2000pbc.googlegroups.com> Message-ID: On Mon, Mar 19, 2012 at 8:30 AM, John Ladasky wrote: > What I would say is that, when PROGRAMMERS look at Python code for the > first time, they will understand what it does more readily than they > would understand other unfamiliar programming languages. ?That has > value. This is something that's never truly defined. Everyone talks of how this language or that language is readable, but if you mean that you can look at a line of code and know what *that line* does, then Python suffers badly and assembly language wins out; but if you mean that you should be able to glance over an entire function and comprehend its algorithm, then I have yet to see any language in which it's not plainly easy to write bad code. Even with good code, anything more than trivial can't be eyeballed in that way - if you could, what would docstrings be for? Really, the metric MUST be Python programmers. Intuitiveness is of value, but readability among experienced programmers is far more useful. If I write a whole lot of code today, and next year I'm dead and someone else has replaced me, I frankly don't mind if he has to learn the language before he can grok my code. I _do_ mind if, even after he's learned the language, he can't figure out what my code's doing; and that's where Python's placed itself at about the right level - not so high that it's all in airy-fairy conceptual work, but not so low that it gets bogged down. There's a handful of other languages that are similarly placed, and they're the languages that I would call "readable". Here's an analogy: One statement (aka line of code, etc) corresponds to one sentence in English. Massive one-liners are like some of the sentences in Paul's epistles; assembly language is like "The cat sat on the mat". Both are valid; both are hard to read. There, have fun tearing thaat to shreds :) ChrisA From bernhard.heijstek at yahoo.com Sun Mar 18 18:27:09 2012 From: bernhard.heijstek at yahoo.com (Bernhard Heijstek) Date: Mon, 19 Mar 2012 03:57:09 +0530 (IST) Subject: Problem with special characters in the password field (urllib) Message-ID: <1332109629.87336.YahooMailNeo@web137616.mail.in.yahoo.com> Hi, I'm having problems getting a script that I wrote to check the unread Gmail feed work (http://pastebin.com/FAGyedH0). The script fetches the unread mail feed (https://mail.google.com/mail/feed/atom/) and then parses it using python-feedparser. The script seems to work fine if I'm not using any special characters like !@#$%^&*() in the password. I tried some pretty basic debugging and saw that the execution stops beyond line 35 which is where the authentication happens. So I figured that this has got to do something with urrllib and special characters in the password field. I've also tried prefixing the string with 'r' without any success. Any help is appreciated. Cheers! Bernhard. From kiuhnm03.4t.yahoo.it Sun Mar 18 19:49:59 2012 From: kiuhnm03.4t.yahoo.it (Kiuhnm) Date: Mon, 19 Mar 2012 00:49:59 +0100 Subject: Currying in Python In-Reply-To: <4f63e724$0$1386$4fafbaef@reader1.news.tin.it> References: <4f63e724$0$1386$4fafbaef@reader1.news.tin.it> Message-ID: <4f6674aa$0$1385$4fafbaef@reader2.news.tin.it> On 3/17/2012 2:21, Kiuhnm wrote: > Here we go. I wrote an article about my approach to currying: http://mtomassoli.wordpress.com/2012/03/18/currying-in-python/ Beginners should be able to understand it as well. Experienced programmers will probably want to skip some sections. Kiuhnm From kiuhnm03.4t.yahoo.it Sun Mar 18 21:02:23 2012 From: kiuhnm03.4t.yahoo.it (Kiuhnm) Date: Mon, 19 Mar 2012 02:02:23 +0100 Subject: Programming D. E. Knuth in Python with the Deterministic Finite Automaton construct In-Reply-To: References: <4f64a3a0$0$1386$4fafbaef@reader2.news.tin.it> <4f64a9e5$0$1385$4fafbaef@reader2.news.tin.it> <4f64d00a$0$1390$4fafbaef@reader1.news.tin.it> Message-ID: <4f6685a2$0$1389$4fafbaef@reader2.news.tin.it> On 3/18/2012 0:28, Michael Torrie wrote: > I am familiar with how one > might implement a decompiler, as well as a compiler (having written a > simple one in the past), but even now I don't see a connection between a > decompiler and the process of converting a knuth algorithm into a python > python implementation. I was hoping you would shed some light on that. > But alas, I'm not really as much of an "interested reader" as you would > like me to be. Many ASM languages don't have structured control flow statements but only jmps, which are roughly equivalent to gotos. A good decompiler will need to analize the net of jmps and try to rewrite the code using structured control flow statements. The idea is to maximize readability, of course. >> Here's an example of rewriting: >> > > Thank you. Your example makes more clear your assertion about "labels" > and how really A1 and A5 were the only real labels in the example. > Though I still do not really see why "states" is not a good equivalence > for labels in this case. As well, Roy's idea for doing the state > machines, which works equally well as the nested if statements, is more > pythonic, which is generally preferred in Python. What I don't like about the entire issue is that (pseudo-)code shouldn't be cut and pasted or blindly ported to another language. Python is a very expressive language. I don't think you like it when someone writes C code in Python. Now we're writing ASM code in Python! If you want to emulate a DFA, do it, but if you want to implement an algorithm whose pseudo-code happens to use labels and gotos, please use higher-level control flow statements (unless you're pressed on time and you need it done yesterday, of course). Regarding labels and state, I simply meant that they're completely different things, in fact this program has two labels but infinitely many states: A1: cur = cur + 1 A2: goto A1 I was being pedantic, to say it your way ;) Kiuhnm From steve+comp.lang.python at pearwood.info Sun Mar 18 21:23:42 2012 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 19 Mar 2012 01:23:42 GMT Subject: Python is readable References: <4f612b19$0$1379$4fafbaef@reader2.news.tin.it> <8e72d74f-c844-4de3-8a37-f6b1fdc2291f@y27g2000yqy.googlegroups.com> <50e9ceec-40f1-4ead-b2b6-87328b30d084@ow8g2000pbc.googlegroups.com> Message-ID: <4f668a9d$0$29981$c3e8da3$5496439d@news.astraweb.com> On Mon, 19 Mar 2012 09:02:06 +1100, Chris Angelico wrote: > On Mon, Mar 19, 2012 at 8:30 AM, John Ladasky > wrote: >> What I would say is that, when PROGRAMMERS look at Python code for the >> first time, they will understand what it does more readily than they >> would understand other unfamiliar programming languages. ?That has >> value. > > This is something that's never truly defined. I'm sorry, I don't understand what part of John's sentence you mean by "this". "Programmers"? "Value"? "Understand"? > Everyone talks of how this > language or that language is readable, but if you mean that you can look > at a line of code and know what *that line* does then Python suffers > badly and assembly language wins out; This is at least the second time you've alleged that assembly language is more readable than Python. I think you're a raving nutter, no offence Chris :-) Assignment (name binding) is close to the absolute simplest thing you can do in a programming language. In Python, the syntax is intuitive to anyone who has gone through high school, or possibly even primary school, and been introduced to the equals sign. x = 1234 y = "Hello" In assembly language, not so much. I wouldn't even have begun to guess how to assign variables in assembly, or even whether such a thing is possible, but a few minutes of googling gave me this: # 8086 assembly x dw 1234 y db 'Hello', 0 # MIPS assembly x: .word 1234 y: .asciiz "Hello" I don't know about anyone else, but I wouldn't have guessed that the way to get x=1234 was with "x dw 1234". What's more, with Python, one example hints on how to do other examples. Having seen x=1234, most people would guess that x=1.234 would also work. I'm pretty sure that "x dw 1.234" will do something surprising, although I don't know what, but it certainly won't be to assign the float 1.234 to a variable x. So there we have another measure of "readability" -- discoverability. Having seen one example, how easy is it to predict slightly modified examples? In assembly's case, not very predictable. What's the difference between these two lines? a db 127 b db 327 For that matter, what will the second line actually do? The thing is, these aren't "advanced features" of assembly language. It's not like trying to understand metaclasses in Python. These are the basic foundations. You can read vast swathes of simple Python code without needing to learn the gory details of Python's data model (name binding of objects, everything is an object), but you can't even *begin* reading assembly language without a good grasp of the data model and jargon. Assembly has a very steep learning curve. Python has a shallow curve. Here's another indication of readability. There have been occasional suggestions on Wikipedia that they standardize on Python as "executable pseudo-code" for code samples. Now replace "Python" with assembly language. Unless you're Donald Knuth, the idea is ridiculous. Another factor related to readability is the primitiveness of the toolset. Assembly has a very low-level, primitive toolset. How would you write this in assembly? print(sorted(somelist)) If all you have is a hammer, the instructions you get are easy to understand because there's not much you can do with it. How complicated can "hit the nail with the hammer" get? But the right measure is not the simplicity of the tasks you *can* do, but the comprehensibility of the tasks you *want* to do. "How do I build a tree house using nothing but a hammer?" I'm sure that, given sufficient ingenuity, you could build a tree house with nothing but a hammer, lumber and nails, but the detailed instructions would be complicated and difficult. How much simpler it becomes with a more powerful set of tools. Assembly is simple, like a hammer. (Well, perhaps not *quite* as simple as a hammer.) > but if you mean that you should be > able to glance over an entire function and comprehend its algorithm, > then I have yet to see any language in which it's not plainly easy to > write bad code. Even with good code, anything more than trivial can't be > eyeballed in that way - if you could, what would docstrings be for? The measure of the readability of a language should not be obfuscated or badly written code, but good, idiomatic code written by an experienced practitioner in the art. Note that there is a deliberate asymmetry there: when judging "readability" (comprehensibility), we take idiomatic code written by somebody who knows the language well, and give it to a novice to interpret it. On this measure, Python has actually become *less* readable in recent years, with the addition of powerful new idioms such as generators, list comprehensions, with statement, etc. They are very expressive, and Python is much better off with them, but they are less readable in the sense I am talking about: readable to somebody who is not an expert in the language. For this reason, when dealing with beginners, or writing code intended as "executable pseudo-code", I try to stick with features that worked in Python 1.5 where possible. E.g. for-loops rather than list comprehensions. > Really, the metric MUST be Python programmers. Intuitiveness is of > value, but readability among experienced programmers is far more useful. But by that metric, Brainf*** is readable, since an experienced expert in the art of writing BF code will be able to recognise BF idioms and interpret them correctly. No, I'm sorry, I disagree that the standard of readability should be the experienced programmer. By that standard, "readability" is a no-op. All languages are, more or less, equally readable, to those who can read them well. I don't think it is useful to judge the readability of Forth on the ability of Charles Moore to read it. How does that help me decide whether to use Forth for my next project? > If I write a whole lot of code today, and next year I'm dead and someone > else has replaced me, I frankly don't mind if he has to learn the > language before he can grok my code. I _do_ mind if, even after he's > learned the language, he can't figure out what my code's doing; Then he hasn't learned the language *sufficiently well*. Either that, or your code is obfuscated, unidiomatic crap. Perhaps you're trying to write BF in Python :) -- Steven From benjamin at python.org Sun Mar 18 21:43:56 2012 From: benjamin at python.org (Benjamin Peterson) Date: Sun, 18 Mar 2012 20:43:56 -0500 Subject: [RELEASED] Second release candidates for Python 2.6.8, 2.7.3, 3.1.5, and 3.2.3 Message-ID: We're chuffed to announce the immediate availability of the second release candidates for Python 2.6.8, 2.7.3, 3.1.5, and 3.2.3. The only change from the first release candidates is the patching of an additional security hole. The security issue fixed in the second release candidates is in the expat XML parsing library. expat had the same hash security issue detailed below as Python's core types. The hashing algorithm used in the expat library is now randomized. A more thorough explanation of the "hash attack" security hole follows. The main impetus for these releases is fixing a security issue in Python's hash based types, dict and set, as described below. Python 2.7.3 and 3.2.3 include the security patch and the normal set of bug fixes. Since Python 2.6 and 3.1 are maintained only for security issues, 2.6.8 and 3.1.5 contain only various security patches. The security issue exploits Python's dict and set implementations. Carefully crafted input can lead to extremely long computation times and denials of service. [1] Python dict and set types use hash tables to provide amortized constant time operations. Hash tables require a well-distributed hash function to spread data evenly across the hash table. The security issue is that an attacker could compute thousands of keys with colliding hashes; this causes quadratic algorithmic complexity when the hash table is constructed. To alleviate the problem, the new releases add randomization to the hashing of Python's string types (bytes/str in Python 3 and str/unicode in Python 2), datetime.date, and datetime.datetime. This prevents an attacker from computing colliding keys of these types without access to the Python process. Hash randomization causes the iteration order of dicts and sets to be unpredictable and differ across Python runs. Python has never guaranteed iteration order of keys in a dict or set, and applications are advised to never rely on it. Historically, dict iteration order has not changed very often across releases and has always remained consistent between successive executions of Python. Thus, some existing applications may be relying on dict or set ordering. Because of this and the fact that many Python applications which don't accept untrusted input are not vulnerable to this attack, in all stable Python releases mentioned here, HASH RANDOMIZATION IS DISABLED BY DEFAULT. There are two ways to enable it. The -R commandline option can be passed to the python executable. It can also be enabled by setting an environmental variable PYTHONHASHSEED to "random". (Other values are accepted, too; pass -h to python for complete description.) More details about the issue and the patch can be found in the oCERT advisory [1] and the Python bug tracker [2]. These releases are releases candidates and thus not recommended for production use. Please test your applications and libraries with them, and report any bugs you encounter. We are especially interested in any buggy behavior observed using hash randomization. Excepting major calamity, final versions should appear after several weeks. Downloads are at http://python.org/download/releases/2.6.8/ http://python.org/download/releases/2.7.3/ http://python.org/download/releases/3.1.5/ http://python.org/download/releases/3.2.3/ Please test these candidates and report bugs to http://bugs.python.org/ With regards, The Python release team Barry Warsaw (2.6), Georg Brandl (3.2), Benjamin Peterson (2.7 and 3.1) [1] http://www.ocert.org/advisories/ocert-2011-003.html [2] http://bugs.python.org/issue13703 From wuwei23 at gmail.com Sun Mar 18 23:15:56 2012 From: wuwei23 at gmail.com (alex23) Date: Sun, 18 Mar 2012 20:15:56 -0700 (PDT) Subject: Python is readable References: <4f612b19$0$1379$4fafbaef@reader2.news.tin.it> <8e72d74f-c844-4de3-8a37-f6b1fdc2291f@y27g2000yqy.googlegroups.com> <50e9ceec-40f1-4ead-b2b6-87328b30d084@ow8g2000pbc.googlegroups.com> Message-ID: <3904be71-335e-43a9-9e82-024abb1729b5@ni10g2000pbc.googlegroups.com> John Ladasky wrote: > > The idea that Python code has to be obvious to non-programmers is an > > incorrect and dangerous one. > > Incorrect? ?Probably. ?Dangerous? ?You'll have to explain what you > mean. The classic "obvious" behaviour to new Python programmers that causes problems would be mutable default arguments. At this point you have two options: improve the "readability" to new users so their expectations are met, or ask them to modify those expectations and understand what's really happening under the surface. As it stands, you tend to hit this problem pretty early on, learn about it, and walk away with a deeper knowledge of Python's mechanics. The danger, I feel, is that changing it to better fit the mind-set that non-Python programmers bring with them could mask that necessary understanding for longer. From clp2 at rebertia.com Mon Mar 19 00:14:27 2012 From: clp2 at rebertia.com (Chris Rebert) Date: Sun, 18 Mar 2012 21:14:27 -0700 Subject: Python is readable In-Reply-To: <3904be71-335e-43a9-9e82-024abb1729b5@ni10g2000pbc.googlegroups.com> References: <4f612b19$0$1379$4fafbaef@reader2.news.tin.it> <8e72d74f-c844-4de3-8a37-f6b1fdc2291f@y27g2000yqy.googlegroups.com> <50e9ceec-40f1-4ead-b2b6-87328b30d084@ow8g2000pbc.googlegroups.com> <3904be71-335e-43a9-9e82-024abb1729b5@ni10g2000pbc.googlegroups.com> Message-ID: On Sun, Mar 18, 2012 at 8:15 PM, alex23 wrote: > John Ladasky wrote: >> > The idea that Python code has to be obvious to non-programmers is an >> > incorrect and dangerous one. >> >> Incorrect? ?Probably. ?Dangerous? ?You'll have to explain what you >> mean. > > The classic "obvious" behaviour to new Python programmers that causes > problems would be mutable default arguments. At this point you have > two options: improve the "readability" to new users so their > expectations are met, or ask them to modify those expectations and > understand what's really happening under the surface. As it stands, > you tend to hit this problem pretty early on, learn about it, and walk > away with a deeper knowledge of Python's mechanics. The mechanics of default arguments maybe, but that's tautological. If you mean call-by-object, any time you pass both mutable and immutable things around, you will learn the same lesson. If you mean the more general principle that "Python doesn't ever copy things unless you explicitly ask", working with lists (and particularly their multiplication operator) again tends to also teach that lesson. > The danger, I > feel, is that changing it to better fit the mind-set that non-Python > programmers bring with them could mask that necessary understanding > for longer. I disagree. Just add a keyword for each default argument evaluation behavior (evaluate-once-at-definition-time [e.g. "once", "static"] and evaluate-at-call-time [e.g. "fresh"]) and don't have there be a default behavior; make the choice explicit. They'll be confronted with the issue as soon as they're shown default arguments, and keywords are easy to look up the meaning of. And as I said previously, there are other common ways to learn any of the "lessons" that default arguments might "teach". If-I-had-my-druthers-ly yours, Chris (R.) From rosuav at gmail.com Mon Mar 19 00:33:51 2012 From: rosuav at gmail.com (Chris Angelico) Date: Mon, 19 Mar 2012 15:33:51 +1100 Subject: Python is readable In-Reply-To: <4f668a9d$0$29981$c3e8da3$5496439d@news.astraweb.com> References: <4f612b19$0$1379$4fafbaef@reader2.news.tin.it> <8e72d74f-c844-4de3-8a37-f6b1fdc2291f@y27g2000yqy.googlegroups.com> <50e9ceec-40f1-4ead-b2b6-87328b30d084@ow8g2000pbc.googlegroups.com> <4f668a9d$0$29981$c3e8da3$5496439d@news.astraweb.com> Message-ID: On Mon, Mar 19, 2012 at 12:23 PM, Steven D'Aprano wrote: > On Mon, 19 Mar 2012 09:02:06 +1100, Chris Angelico wrote: > >> On Mon, Mar 19, 2012 at 8:30 AM, John Ladasky >> wrote: >>> What I would say is that, when PROGRAMMERS look at Python code for the >>> first time, they will understand what it does more readily than they >>> would understand other unfamiliar programming languages. ?That has >>> value. >> >> This is something that's never truly defined. > > I'm sorry, I don't understand what part of John's sentence you mean by > "this". "Programmers"? "Value"? "Understand"? I should have rewritten that into the next paragraph. Anyhow. Further explanation below. >> Everyone talks of how this >> language or that language is readable, but if you mean that you can look >> at a line of code and know what *that line* does then Python suffers >> badly and assembly language wins out; > > This is at least the second time you've alleged that assembly language is > more readable than Python. I think you're a raving nutter, no offence > Chris :-) None taken; guilty as charged. And unashamedly so. With that dealt with, though: My calling assembly "readable" is a form of argument by drawing to logical, but absurd, conclusion - by the given definition of readability, assembly is readable, ergo the definition sucks. (That's a term all logicians use, you know. Proper and formal jargon.) > Assignment (name binding) is close to the absolute simplest thing you can > do in a programming language. In Python, the syntax is intuitive to > anyone who has gone through high school, or possibly even primary school, > and been introduced to the equals sign. > > x = 1234 > y = "Hello" Not quite. In mathematics, "x = 1234" is either a declaration of fact, or a statement that can be either true or false. In mathematics, "x = x + 1" is absurd and/or simply false. That's why Pascal has its := operator, supposed to be read as "becomes" and not "equals". IMHO this is simply proof of one of the differences between programming and mathematics. > I don't know about anyone else, but I wouldn't have guessed that the way > to get x=1234 was with "x dw 1234". Except that it's not quite the same thing. That 8086 Assembly statement is more like the C statement: int x=1234; The nearest equivalent of assignment is: mov x,1234 although that differs slightly from assembler to assembler (NASM, if I recall correctly, calls for "mov [x],1234"). You're right, though, that it's nothing like as clear. > What's more, with Python, one example hints on how to do other examples. > Having seen x=1234, most people would guess that x=1.234 would also work. Yes, which brings up the old favorite arguments about whether computers work with integers, floats, rationals, Real Numbers, or Numbers. But, that aside... > I'm pretty sure that "x dw 1.234" will do something surprising, although > I don't know what, but it certainly won't be to assign the float 1.234 to > a variable x. Perhaps not usefully, but "x dd 1.234" ought to work. You just can't fit a float into a dw. (NASM does support "half precision", but most operations want a doubleword for a float.) Assembly language requires variable sizes to be declared. Of course, what it *really* does is declare a doubleword-sized patch of memory, initializes it to the IEEE representation of the nearest possible float to the real number 1.234, and assigns the label 'x' to point to the lowest memory address used by that doubleword... but mostly you don't need to care about that. > So there we have another measure of "readability" -- discoverability. > Having seen one example, how easy is it to predict slightly modified > examples? > > In assembly's case, not very predictable. What's the difference between > these two lines? > > a db 127 > b db 327 > > For that matter, what will the second line actually do? I'm not 100% sure, but since assembly is much stricter than most HLLs with data sizes, it's a concern that you don't have with Python's long ints. But the same thing can come up in a HLL - struct.pack("i") can't handle a long int, because, like an assembler, it's concerned about exact byte sizes. > Assembly has a very steep learning curve. Python has a shallow curve. Of course. But computer programming generally has a fairly stiff learning curve; you have to get your head around all sorts of concepts that simply do not exist anywhere else. > Here's another indication of readability. There have been occasional > suggestions on Wikipedia that they standardize on Python as "executable > pseudo-code" for code samples. Now replace "Python" with assembly > language. Unless you're Donald Knuth, the idea is ridiculous. I am not, and it is. But I could make you a set of NASM macros that allow you to write assembly code that looks like pseudo-code. Does that make assembly code readable? Maybe. Does it make it worth using as a HLL? No. > If all you have is a hammer, the instructions you get are easy to > understand because there's not much you can do with it. How complicated > can "hit the nail with the hammer" get? But the right measure is not the > simplicity of the tasks you *can* do, but the comprehensibility of the > tasks you *want* to do. Right, which is why NO language can be described as "readable" or "easy to work with" unless you define a problem domain. SQL is an excellent language... as long as you want to query a relational database. > The measure of the readability of a language should not be obfuscated or > badly written code, but good, idiomatic code written by an experienced > practitioner in the art. Note that there is a deliberate asymmetry there: > when judging "readability" (comprehensibility), we take idiomatic code > written by somebody who knows the language well, and give it to a novice > to interpret it. Sure. You can write bad code in any language, and that doesn't mean anything. But still, if you're writing for a novice, you write quite different code from what you'd write normally. Language tutorials are written by experts for novices; language tutorials do not look like the language's own standard library (assuming it has one written in itself). >> Really, the metric MUST be Python programmers. Intuitiveness is of >> value, but readability among experienced programmers is far more useful. > > But by that metric, Brainf*** is readable, since an experienced expert in > the art of writing BF code will be able to recognise BF idioms and > interpret them correctly. Not really. The BF code to do one simple high level operation could easily span several pages. You can't "recognize" those. Now, BF with macros/subroutines might be more plausible - if you could define a new opcode that represents some huge slab of BF code and use that - but in its native form, I don't think anyone could recognize what BF is doing. > No, I'm sorry, I disagree that the standard of readability should be the > experienced programmer. By that standard, "readability" is a no-op. All > languages are, more or less, equally readable, to those who can read them > well. I don't think it is useful to judge the readability of Forth on the > ability of Charles Moore to read it. How does that help me decide whether > to use Forth for my next project? > >> If I write a whole lot of code today, and next year I'm dead and someone >> else has replaced me, I frankly don't mind if he has to learn the >> language before he can grok my code. I _do_ mind if, even after he's >> learned the language, he can't figure out what my code's doing; > > Then he hasn't learned the language *sufficiently well*. Either that, or > your code is obfuscated, unidiomatic crap. Perhaps you're trying to write > BF in Python :) And that's where the nub of the question is. How well is sufficiently well? Clearly you do not require your code to be comprehensible to a non-programmer, or you would not write code at all. If you don't demand that the reader learn basic keywords of the language, then it's equally impossible to expect them to comprehend your code. If you're writing production code, I see no reason to avoid language features like Python's list comps, Pike's %{ %} sprintf codes, or C's pointer arithmetic, just because they can confuse people. Learn the language, THEN start hacking on the code. ChrisA From anntzer.lee at gmail.com Mon Mar 19 01:11:13 2012 From: anntzer.lee at gmail.com (anntzer.lee at gmail.com) Date: Sun, 18 Mar 2012 22:11:13 -0700 (PDT) Subject: ANN: cmd2, an extenstion of cmd that parses its argument line Message-ID: <20285780.118.1332133873462.JavaMail.geo-discussion-forums@pbcwe9> Dear all, I would like to announce the first public release of cmd2, an extension of the standard library's cmd with argument parsing, here: https://github.com/anntzer/cmd2. Cmd2 is an extension built around the excellent cmd module of the standard library. Cmd allows one to build simple custom shells using ``do_*`` methods, taking care in particular of the REPL loop and the interactive help. However, no facility is given for parsing the argument line (do_* methods are passed the rest of the line as a single string argument). With Cmd2, ``do_*`` methods are type-annotated, either using Python 3's function annotation syntax, or with an ad-hoc ``annotate`` decorator, allowing the dispatcher to parse the argument list for them. Antony Lee From xianming.yan at gmail.com Mon Mar 19 02:30:09 2012 From: xianming.yan at gmail.com (yan xianming) Date: Sun, 18 Mar 2012 23:30:09 -0700 (PDT) Subject: New learner of Python--any suggestion on studying it? Message-ID: Hello all, I'm a new learning of Python. Can someone give me some suggestion about it? thanks xianming From clp2 at rebertia.com Mon Mar 19 02:58:38 2012 From: clp2 at rebertia.com (Chris Rebert) Date: Sun, 18 Mar 2012 23:58:38 -0700 Subject: New learner of Python--any suggestion on studying it? In-Reply-To: References: Message-ID: On Sun, Mar 18, 2012 at 11:30 PM, yan xianming wrote: > Hello all, > > I'm a new learning of Python. > > Can someone give me some suggestion about it? http://docs.python.org/tutorial/index.html http://wiki.python.org/moin/BeginnersGuide/NonProgrammers http://wiki.python.org/moin/BeginnersGuide/Programmers http://www.quora.com/How-can-I-learn-to-program-in-Python Cheers, Chris From mining.facts at googlemail.com Mon Mar 19 03:26:25 2012 From: mining.facts at googlemail.com (Christian) Date: Mon, 19 Mar 2012 00:26:25 -0700 (PDT) Subject: filter max from iterable for grouped element Message-ID: <0184870c-e30a-4865-aa24-c6cb9a661aed@gr6g2000vbb.googlegroups.com> Hi, as beginner in python , I struggle somewhat to filter out only the maximum in the values for and get hmax. Maybe it easier when i change the structure of h? Many thanks in advance Christian h = {'abvjv': ('asyak', 0.9014230420411024), 'afqes': ('jarbm', 0.9327883839839753), 'aikdj': ('jarbm', 0.9503941616408824), 'ajbhn': ('jarbm', 0.9323583083061541), 'ajrje': ('jbhdj', 0.9825125732711598), 'anbrw': ('jarbm', 0.950801828672098)} hmax = {'abvjv': ('asyak', 0.9014230420411024), 'ajrje': ('jbhdj', 0.9825125732711598), 'anbrw': ('jarbm', 0.950801828672098)} From antti.ylikoski at tkk.fi Mon Mar 19 03:46:22 2012 From: antti.ylikoski at tkk.fi (Antti J Ylikoski) Date: Mon, 19 Mar 2012 09:46:22 +0200 Subject: New learner of Python--any suggestion on studying it? In-Reply-To: References: Message-ID: On 19.3.2012 8:30, yan xianming wrote: > Hello all, > > I'm a new learning of Python. > > > > Can someone give me some suggestion about it? > > thanks > xianming The best textbooks on Python that I have come across are: Learning Python by Mark Lutz, O'Reilly, http://oreilly.com, ISBN 978-0-596-15806-4 Programming Python by Mark Lutz, O'Reilly, http://oreilly.com, ISBN 978-0-596-15810-1 regards, Antti "Andy" Ylikoski Helsinki, Finland, the EU From gandalf at shopzeus.com Mon Mar 19 03:55:51 2012 From: gandalf at shopzeus.com (Laszlo Nagy) Date: Mon, 19 Mar 2012 08:55:51 +0100 Subject: urllib.urlretrieve never returns??? In-Reply-To: References: <4F649BFC.1080601@shopzeus.com> Message-ID: <4F66E687.2050008@shopzeus.com> On 2012-03-17 19:18, Christian Heimes wrote: > Am 17.03.2012 15:13, schrieb Laszlo Nagy: >> See attached example code. I have a program that calls exactly the same >> code, and here is the strange thing about it: >> >> * Program is started as "start.py", e.g. with an open console. In this >> case, the program works! >> * Program is started as "start.pyw", e.g. with no open console under >> Windows 7 64bit - the program does not work! > The pythonw.exe may not have the rights to access network resources. > Have you set a default timeout for sockets? > > import socket > socket.setdefaulttimeout(10) # 10 seconds > > A pyw Python doesn't have stdout, stderr or stdin. Any attempt to write > to them (e.g. print statement, default exception logger) can cause an > exception. Yes, that is why I started the app with wx.PySimpleApp(redirect=True) so stdout is redirected into a window. Unfortunately, nothing is logged. I'm going to turn off the firewall and start as admin today. That might be the solution. Thanks! From jeanpierreda at gmail.com Mon Mar 19 04:00:06 2012 From: jeanpierreda at gmail.com (Devin Jeanpierre) Date: Mon, 19 Mar 2012 04:00:06 -0400 Subject: ANN: cmd2, an extenstion of cmd that parses its argument line In-Reply-To: <20285780.118.1332133873462.JavaMail.geo-discussion-forums@pbcwe9> References: <20285780.118.1332133873462.JavaMail.geo-discussion-forums@pbcwe9> Message-ID: There already is a module named cmd2: http://pypi.python.org/pypi/cmd2 -- Devin On Mon, Mar 19, 2012 at 1:11 AM, wrote: > Dear all, > > I would like to announce the first public release of cmd2, an extension of > the standard library's cmd with argument parsing, here: > https://github.com/anntzer/cmd2. > > Cmd2 is an extension built around the excellent cmd module of the standard > library. Cmd allows one to build simple custom shells using ``do_*`` > methods, > taking care in particular of the REPL loop and the interactive help. > However, > no facility is given for parsing the argument line (do_* methods are > passed the > rest of the line as a single string argument). > > With Cmd2, ``do_*`` methods are type-annotated, either using Python 3's > function annotation syntax, or with an ad-hoc ``annotate`` decorator, > allowing > the dispatcher to parse the argument list for them. > > Antony Lee > -- > http://mail.python.org/mailman/listinfo/python-list > -------------- next part -------------- An HTML attachment was scrubbed... URL: From __peter__ at web.de Mon Mar 19 04:45:54 2012 From: __peter__ at web.de (Peter Otten) Date: Mon, 19 Mar 2012 09:45:54 +0100 Subject: filter max from iterable for grouped element References: <0184870c-e30a-4865-aa24-c6cb9a661aed@gr6g2000vbb.googlegroups.com> Message-ID: Christian wrote: > as beginner in python , I struggle somewhat to filter out only the > maximum in the values for and get hmax. > h = {'abvjv': ('asyak', 0.9014230420411024), > 'afqes': ('jarbm', 0.9327883839839753), > 'aikdj': ('jarbm', 0.9503941616408824), > 'ajbhn': ('jarbm', 0.9323583083061541), > 'ajrje': ('jbhdj', 0.9825125732711598), > 'anbrw': ('jarbm', 0.950801828672098)} > > > hmax = {'abvjv': ('asyak', 0.9014230420411024), > 'ajrje': ('jbhdj', 0.9825125732711598), > 'anbrw': ('jarbm', 0.950801828672098)} You can create an intermediate dict: >>> d = {} >>> for k, (k2, v) in h.items(): ... d.setdefault(k2, []).append((v, k)) ... >>> import pprint >>> pprint.pprint(d) {'asyak': [(0.9014230420411024, 'abvjv')], 'jarbm': [(0.9323583083061541, 'ajbhn'), (0.950801828672098, 'anbrw'), (0.9327883839839753, 'afqes'), (0.9503941616408824, 'aikdj')], 'jbhdj': [(0.9825125732711598, 'ajrje')]} Now find the maximum values: >>> for k, pairs in d.items(): ... v, k2 = max(pairs) ... assert k2 not in hmax ... hmax[k2] = k, v ... >>> pprint.pprint(hmax) {'abvjv': ('asyak', 0.9014230420411024), 'ajrje': ('jbhdj', 0.9825125732711598), 'anbrw': ('jarbm', 0.950801828672098)} > Maybe it easier when i change the structure of h? Maybe. Here's one option: >>> pprint.pprint(data) [('jarbm', 0.9323583083061541, 'ajbhn'), ('jarbm', 0.950801828672098, 'anbrw'), ('jarbm', 0.9327883839839753, 'afqes'), ('asyak', 0.9014230420411024, 'abvjv'), ('jbhdj', 0.9825125732711598, 'ajrje'), ('jarbm', 0.9503941616408824, 'aikdj')] >>> data.sort() >>> from itertools import groupby >>> def last(items): ... for item in items: pass ... return item ... >>> dmax = [last(group) for key, group in groupby(data, key=lambda item: item[0])] >>> pprint.pprint(dmax) [('asyak', 0.9014230420411024, 'abvjv'), ('jarbm', 0.950801828672098, 'anbrw'), ('jbhdj', 0.9825125732711598, 'ajrje')] From mining.facts at googlemail.com Mon Mar 19 05:29:57 2012 From: mining.facts at googlemail.com (Christian) Date: Mon, 19 Mar 2012 02:29:57 -0700 (PDT) Subject: filter max from iterable for grouped element References: <0184870c-e30a-4865-aa24-c6cb9a661aed@gr6g2000vbb.googlegroups.com> Message-ID: <08542ab5-feb5-476c-827b-f7eb73cef4e9@v22g2000vby.googlegroups.com> On 19 Mrz., 09:45, Peter Otten <__pete... at web.de> wrote: > Christian wrote: > > as beginner in python , I struggle ?somewhat to filter out only the > > maximum in the values for ?and get hmax. > > h = {'abvjv': ('asyak', 0.9014230420411024), > > ?'afqes': ('jarbm', 0.9327883839839753), > > ?'aikdj': ('jarbm', 0.9503941616408824), > > ?'ajbhn': ('jarbm', 0.9323583083061541), > > ?'ajrje': ('jbhdj', 0.9825125732711598), > > ?'anbrw': ('jarbm', 0.950801828672098)} > > > hmax = {'abvjv': ('asyak', 0.9014230420411024), > > ?'ajrje': ('jbhdj', 0.9825125732711598), > > ?'anbrw': ('jarbm', 0.950801828672098)} > > You can create an intermediate dict: > > >>> d = {} > >>> for k, (k2, v) in h.items(): > > ... ? ? d.setdefault(k2, []).append((v, k)) > ...>>> import pprint > >>> pprint.pprint(d) > > {'asyak': [(0.9014230420411024, 'abvjv')], > ?'jarbm': [(0.9323583083061541, 'ajbhn'), > ? ? ? ? ? ?(0.950801828672098, 'anbrw'), > ? ? ? ? ? ?(0.9327883839839753, 'afqes'), > ? ? ? ? ? ?(0.9503941616408824, 'aikdj')], > ?'jbhdj': [(0.9825125732711598, 'ajrje')]} > > Now find the maximum values: > > >>> for k, pairs in d.items(): > > ... ? ? v, k2 = max(pairs) > ... ? ? assert k2 not in hmax > ... ? ? hmax[k2] = k, v > ...>>> pprint.pprint(hmax) > > {'abvjv': ('asyak', 0.9014230420411024), > ?'ajrje': ('jbhdj', 0.9825125732711598), > ?'anbrw': ('jarbm', 0.950801828672098)} > > > Maybe it easier when i change the structure of h? > > Maybe. Here's one option: > > >>> pprint.pprint(data) > > [('jarbm', 0.9323583083061541, 'ajbhn'), > ?('jarbm', 0.950801828672098, 'anbrw'), > ?('jarbm', 0.9327883839839753, 'afqes'), > ?('asyak', 0.9014230420411024, 'abvjv'), > ?('jbhdj', 0.9825125732711598, 'ajrje'), > ?('jarbm', 0.9503941616408824, 'aikdj')]>>> data.sort() > >>> from itertools import groupby > >>> def last(items): > > ... ? ? for item in items: pass > ... ? ? return item > ...>>> dmax = [last(group) for key, group in groupby(data, key=lambda item: > item[0])] > >>> pprint.pprint(dmax) > > [('asyak', 0.9014230420411024, 'abvjv'), > ?('jarbm', 0.950801828672098, 'anbrw'), > ?('jbhdj', 0.9825125732711598, 'ajrje')] Thanks a lot. From kiuhnm03.4t.yahoo.it Mon Mar 19 06:24:40 2012 From: kiuhnm03.4t.yahoo.it (Kiuhnm) Date: Mon, 19 Mar 2012 11:24:40 +0100 Subject: Programming D. E. Knuth in Python with the Deterministic Finite Automaton construct In-Reply-To: References: <4f64a3a0$0$1386$4fafbaef@reader2.news.tin.it> <4f64a9e5$0$1385$4fafbaef@reader2.news.tin.it> <4f64d00a$0$1390$4fafbaef@reader1.news.tin.it> <4f6685a2$0$1389$4fafbaef@reader2.news.tin.it> Message-ID: <4f670968$0$1379$4fafbaef@reader2.news.tin.it> On 3/19/2012 6:02, Dennis Lee Bieber wrote: > On Mon, 19 Mar 2012 02:02:23 +0100, Kiuhnm > declaimed the following in > gmane.comp.python.general: > >> >> Many ASM languages don't have structured control flow statements but >> only jmps, which are roughly equivalent to gotos. A good decompiler will >> need to analize the net of jmps and try to rewrite the code using >> structured control flow statements. >> The idea is to maximize readability, of course. >> > Never met Sigma's Meta-Symbol > > Okay, the machine level code was limited to basic condition/jump... > But a master of Meta-Symbol (I wasn't such -- not in a trimester college > course) could create macros that would make it structured. You can do that in MASM (and others) as well. Kiuhnm From kiuhnm03.4t.yahoo.it Mon Mar 19 07:15:07 2012 From: kiuhnm03.4t.yahoo.it (Kiuhnm) Date: Mon, 19 Mar 2012 12:15:07 +0100 Subject: Python is readable In-Reply-To: References: <4f612b19$0$1379$4fafbaef@reader2.news.tin.it> <8e72d74f-c844-4de3-8a37-f6b1fdc2291f@y27g2000yqy.googlegroups.com> <50e9ceec-40f1-4ead-b2b6-87328b30d084@ow8g2000pbc.googlegroups.com> <4f61c828$0$1390$4fafbaef@reader2.news.tin.it> <4f61d728$0$1375$4fafbaef@reader2.news.tin.it> <4f61fd0a$0$1389$4fafbaef@reader2.news.tin.it> <4f620837$0$1382$4fafbaef@reader2.news.tin.it> <4f627c25$0$1381$4fafbaef@reader2.news.tin.it> <4f62b9be$0$29981$c3e8da3$5496439d@news.astraweb.com> <4f632da5$0$1375$4fafbaef@reader1.news.tin.it> <4f636ed5$0$29981$c3e8da3$5496439d@news.astraweb.com> <4f64ed2e$0$1389$4fafbaef@reader1.news.tin.it> <4f650213$0$1375$4fafbaef@reader1.news.tin.it> Message-ID: <4f67153b$0$1383$4fafbaef@reader2.news.tin.it> On 3/18/2012 0:04, Michael Torrie wrote: > On 03/17/2012 03:28 PM, Kiuhnm wrote: >>> They are equally readable. The first one sets EAX to 3; the second >>> displays all elements of x on the console. Assembly is readable on a >>> very low level, but it's by nature verbose at a high level, and thus >>> less readable (you can't eyeball a function and know exactly what it >>> does, especially if that function spans more than a screenful of >>> code). >> >> Welcome in the realm of trolling. > > Seems like you're the one trolling. At least I hope that ChrisA understood what I meant. I'll spell it out for you trollmonger (is that even a word?): 1) I read Steve's posts but I found his answers inconsistent. 2) He accused me of misrepresenting his view and you called me a troll. 3) I suspect that you didn't follow the entire discussion or you'd have noticed the inconsistencies yourself... but I understand that calling someone you don't agree with a troll is easier. 4) ChrisA gave the right answer which was the point I was trying to make all along. 5) I could have said "I second that" or "I agree with you", but I thought that "Welcome to the realm of trolling" was more amusing. I thought that people who agree with me were supposed to be troll as well. But I should've consulted with you about that. Sorry. Kiuhnm From neilc at norwich.edu Mon Mar 19 07:26:10 2012 From: neilc at norwich.edu (Neil Cerutti) Date: 19 Mar 2012 11:26:10 GMT Subject: Python is readable References: <4f612b19$0$1379$4fafbaef@reader2.news.tin.it> <8e72d74f-c844-4de3-8a37-f6b1fdc2291f@y27g2000yqy.googlegroups.com> <50e9ceec-40f1-4ead-b2b6-87328b30d084@ow8g2000pbc.googlegroups.com> <4f61c828$0$1390$4fafbaef@reader2.news.tin.it> <4f61d728$0$1375$4fafbaef@reader2.news.tin.it> <4f61fd0a$0$1389$4fafbaef@reader2.news.tin.it> <4f6280a0$0$29981$c3e8da3$5496439d@news.astraweb.com> <4f6333ca$0$1392$4fafbaef@reader1.news.tin.it> <4f633a1a$0$29981$c3e8da3$5496439d@news.astraweb.com> <9sgsb1FsbpU1@mid.individual.net> Message-ID: <9sojehFi09U2@mid.individual.net> On 2012-03-17, Terry Reedy wrote: > On 3/16/2012 9:08 AM, Neil Cerutti wrote: > >> A grammarian always uses complete sentence before a colon, even >> when introducing a list. > > The Chicago Manual of Style*, 13th edition, says "The colon is > used to mark a discontinuity of grammatical construction > greater than that indicated by the semicolon and less than that > indicated by the period." > > While most of the examples in that section have what would be a > complete sentence before the colon, not all do. Not in that > section is this, from the Table of Contents: "Documentation: > References, Notes, and Bibliographies". Here are a couple more > from their Library of Congress Cataloging in Publication data: > "Rev. ed. of: A manual of style." and "Bibliography: p.". And > in letters: "To:", "From:", and "Date:" > > *A major style guide for general American writing and > publication: used by some as the 'Bible'. Thanks for the discussion and corrections. My apologies to Steven for pushing my apparnetly overly narrow view. There are plenty of valid use cases for a colon without an independent clause. -- Neil Cerutti From kiuhnm03.4t.yahoo.it Mon Mar 19 07:34:58 2012 From: kiuhnm03.4t.yahoo.it (Kiuhnm) Date: Mon, 19 Mar 2012 12:34:58 +0100 Subject: Python is readable In-Reply-To: <4f653c1e$0$29981$c3e8da3$5496439d@news.astraweb.com> References: <4f612b19$0$1379$4fafbaef@reader2.news.tin.it> <8e72d74f-c844-4de3-8a37-f6b1fdc2291f@y27g2000yqy.googlegroups.com> <50e9ceec-40f1-4ead-b2b6-87328b30d084@ow8g2000pbc.googlegroups.com> <4f61c828$0$1390$4fafbaef@reader2.news.tin.it> <4f61d728$0$1375$4fafbaef@reader2.news.tin.it> <4f61fd0a$0$1389$4fafbaef@reader2.news.tin.it> <4f620837$0$1382$4fafbaef@reader2.news.tin.it> <4f627c25$0$1381$4fafbaef@reader2.news.tin.it> <4f62b9be$0$29981$c3e8da3$5496439d@news.astraweb.com> <4f632da5$0$1375$4fafbaef@reader1.news.tin.it> <4f636ed5$0$29981$c3e8da3$5496439d@news.astraweb.com> <4f64ed2e$0$1389$4fafbaef@reader1.news.tin.it> <4f653c1e$0$29981$c3e8da3$5496439d@news.astraweb.com> Message-ID: <4f6719e2$0$1384$4fafbaef@reader2.news.tin.it> On 3/18/2012 2:36, Steven D'Aprano wrote: > On Sat, 17 Mar 2012 20:59:34 +0100, Kiuhnm wrote: > >> Ok, so length and readability are orthogonal properties. Could you >> please explain to me in which way >> mov eax, 3 >> should be less readable than >> for i in x: print(i) >> ? > > "mov eax, 3" requires more domain-specific knowledge. It operates at a > very low level, that of memory locations and bytes, rather than at a > level which most people can reason about efficiently. > > English speakers would probably guess that "mov" was an abbreviation of > "move", but what is being moved, and from where to where, for what > purpose? > > They're also likely to flounder on the analogy of "moving" bytes. When > you move a book from here to there, you leave a space in the row of books > where there is no longer a book. (You might choose to move a second book > into that gap, but first there is a gap.) But when you move bytes, you > don't leave a gap. There are always bytes at every valid address. The > average non-programmer is likely to have the wrong data model to > understand what "mov eax, 3" does. > > In the second example, most English speakers would intuit that "print(i)" > prints i, whatever i is. "for i in x" is more cryptic, but if it were > written with less jargon-like names, such as "for item in list" or "for > person in family" or similar, they would likely guess that it means to > repeat the following instructions for each item in the set: > > "For each person at the table, place a plate, knife and fork." > > And even if the reader can't guess the meaning of the for-loop, it is a > concept easy enough for most people to grasp given some explanations and > examples. It's neither too low level (assembly language), nor too high > level (monads, functors) but is at just the right level of abstraction > versus concreteness for the average person to follow. Would you be so kind to give me your final definition of readability and /stick/ to it? You keep changing it every time I point out a flaw in it. Kiuhnm From ovidiudeac at gmail.com Mon Mar 19 07:41:20 2012 From: ovidiudeac at gmail.com (Ovidiu Deac) Date: Mon, 19 Mar 2012 13:41:20 +0200 Subject: debugging ssl handshake failure Message-ID: I have an HTTPS server written in python, based on ssl package. This application is running on 3 virtual machines which were created by clonning. The application works perfectly on 2 machines but on the third it doesn't. Instead of the normal "Server Hello" message it gives me an Alert Level: Fatal, Description: "Handshake failure" Anybody here has any idea what the problem could be? My main problem here is that I don't have any means to debug the problem. My next option is to look into ssl sources which I'm not really happy to do. Also anybody has any suggestion for debugging? Thanks, Ovidiu From kiuhnm03.4t.yahoo.it Mon Mar 19 07:44:53 2012 From: kiuhnm03.4t.yahoo.it (Kiuhnm) Date: Mon, 19 Mar 2012 12:44:53 +0100 Subject: Python is readable In-Reply-To: <4f653e5c$0$29981$c3e8da3$5496439d@news.astraweb.com> References: <4f612b19$0$1379$4fafbaef@reader2.news.tin.it> <8e72d74f-c844-4de3-8a37-f6b1fdc2291f@y27g2000yqy.googlegroups.com> <50e9ceec-40f1-4ead-b2b6-87328b30d084@ow8g2000pbc.googlegroups.com> <4f61c828$0$1390$4fafbaef@reader2.news.tin.it> <4f61d728$0$1375$4fafbaef@reader2.news.tin.it> <4f61fd0a$0$1389$4fafbaef@reader2.news.tin.it> <4f6280a0$0$29981$c3e8da3$5496439d@news.astraweb.com> <4f6333ca$0$1392$4fafbaef@reader1.news.tin.it> <4f633a1a$0$29981$c3e8da3$5496439d@news.astraweb.com> <4f64f2d8$0$1393$4fafbaef@reader1.news.tin.it> <4f653e5c$0$29981$c3e8da3$5496439d@news.astraweb.com> Message-ID: <4f671c36$0$1386$4fafbaef@reader2.news.tin.it> On 3/18/2012 2:46, Steven D'Aprano wrote: > On Sat, 17 Mar 2012 21:23:45 +0100, Kiuhnm wrote: > >> On 3/16/2012 14:03, Steven D'Aprano wrote: >>> A one line routine is still a routine. There is nothing ungrammatical >>> about "If you can: take the bus.", although it is non-idiomatic >>> English. >> >> In another post you wrote >> "Sorry, I was talking about the other sort, the ones who apply the >> grammatical rules used by people in real life. You know the ones: >> linguists." >> >> Then how do you know that there's nothing ungrammatical about "If you >> can: take the bus" if people don't use it? > > Who says it is ungrammatical? You did. You're not a prescriptivist, thus you're probably a descriptivist. Beeing a descriptivist, you must agree on the fact that "If ...: do this" is ungrammatical, because nobody says that. On the other hand, a prescriptivist might accept that. BTW, I asked a few teachers of English whether "If ...: do this" is correct or not and they, surprisingly, said "no". Kiuhnm From steve+comp.lang.python at pearwood.info Mon Mar 19 07:51:14 2012 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 19 Mar 2012 11:51:14 GMT Subject: Python is readable References: <4f612b19$0$1379$4fafbaef@reader2.news.tin.it> <8e72d74f-c844-4de3-8a37-f6b1fdc2291f@y27g2000yqy.googlegroups.com> <50e9ceec-40f1-4ead-b2b6-87328b30d084@ow8g2000pbc.googlegroups.com> <4f61c828$0$1390$4fafbaef@reader2.news.tin.it> <4f61d728$0$1375$4fafbaef@reader2.news.tin.it> <4f61fd0a$0$1389$4fafbaef@reader2.news.tin.it> <4f6280a0$0$29981$c3e8da3$5496439d@news.astraweb.com> <4f6333ca$0$1392$4fafbaef@reader1.news.tin.it> <4f633a1a$0$29981$c3e8da3$5496439d@news.astraweb.com> <9sgsb1FsbpU1@mid.individual.net> <9sojehFi09U2@mid.individual.net> Message-ID: <4f671db2$0$29981$c3e8da3$5496439d@news.astraweb.com> On Mon, 19 Mar 2012 11:26:10 +0000, Neil Cerutti wrote: [...] >> *A major style guide for general American writing and publication: used >> by some as the 'Bible'. > > Thanks for the discussion and corrections. My apologies to Steven for > pushing my apparnetly overly narrow view. There are plenty of valid use > cases for a colon without an independent clause. No apology necessary, I like a good argument :) http://www.mindspring.com/~mfpatton/sketch.htm One observation that amuses me though... it seems to me that the widespread practice of people writing colons following sentence fragments isn't sufficient to convince you that this is grammatical, but a self- declared authority prescribing it as allowed is. That makes you a grammar prescriptivist :) We're-all-a-little-bit-prescriptivists-when-it-comes-to-grammar-ly y'rs, -- Steven From steve+comp.lang.python at pearwood.info Mon Mar 19 07:57:09 2012 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 19 Mar 2012 11:57:09 GMT Subject: Python is readable References: <4f612b19$0$1379$4fafbaef@reader2.news.tin.it> <50e9ceec-40f1-4ead-b2b6-87328b30d084@ow8g2000pbc.googlegroups.com> <4f61c828$0$1390$4fafbaef@reader2.news.tin.it> <4f61d728$0$1375$4fafbaef@reader2.news.tin.it> <4f61fd0a$0$1389$4fafbaef@reader2.news.tin.it> <4f620837$0$1382$4fafbaef@reader2.news.tin.it> <4f627c25$0$1381$4fafbaef@reader2.news.tin.it> <4f62b9be$0$29981$c3e8da3$5496439d@news.astraweb.com> <4f632da5$0$1375$4fafbaef@reader1.news.tin.it> <4f636ed5$0$29981$c3e8da3$5496439d@news.astraweb.com> <4f64ed2e$0$1389$4fafbaef@reader1.news.tin.it> <4f650213$0$1375$4fafbaef@reader1.news.tin.it> <4f67153b$0$1383$4fafbaef@reader2.news.tin.it> Message-ID: <4f671f15$0$29981$c3e8da3$5496439d@news.astraweb.com> On Mon, 19 Mar 2012 12:15:07 +0100, Kiuhnm wrote: > On 3/18/2012 0:04, Michael Torrie wrote: >> On 03/17/2012 03:28 PM, Kiuhnm wrote: >>>> They are equally readable. The first one sets EAX to 3; the second >>>> displays all elements of x on the console. Assembly is readable on a >>>> very low level, but it's by nature verbose at a high level, and thus >>>> less readable (you can't eyeball a function and know exactly what it >>>> does, especially if that function spans more than a screenful of >>>> code). >>> >>> Welcome in the realm of trolling. >> >> Seems like you're the one trolling. > > At least I hope that ChrisA understood what I meant. I'll spell it out > for you trollmonger (is that even a word?): Sure, why not? A trollmonger would be someone who deals in the buying and selling of trolls. Presumably this would be meant figuratively, like an argument-monger (someone who starts and gets involved in arguments). > 1) I read Steve's posts but I found his answers inconsistent. I don't think they are, but I'm happy to either clarify or concede any points that are contradictory or inconsistent, if you tell me what they are. -- Steven From jmwebaze at gmail.com Mon Mar 19 08:38:27 2012 From: jmwebaze at gmail.com (J. Mwebaze) Date: Mon, 19 Mar 2012 13:38:27 +0100 Subject: Message passing between python objects Message-ID: I am trying to learn about the interaction between python objects. One thing i have often read is that objects interact by sending messages to other objects to invoke corresponding methods. I am specifically interested in tracing these messages and also probably log the messages for further scrutiny. I would like to build a provenance kind of system. Regards -- *Mob UG: +256 (0) 70 1735800 | NL +31 (0) 6 852 841 38 | Gtalk: jmwebaze | skype: mwebazej | URL: www.astro.rug.nl/~jmwebaze /* Life runs on code */* -------------- next part -------------- An HTML attachment was scrubbed... URL: From neilc at norwich.edu Mon Mar 19 08:53:23 2012 From: neilc at norwich.edu (Neil Cerutti) Date: 19 Mar 2012 12:53:23 GMT Subject: Python is readable References: <4f612b19$0$1379$4fafbaef@reader2.news.tin.it> <8e72d74f-c844-4de3-8a37-f6b1fdc2291f@y27g2000yqy.googlegroups.com> <50e9ceec-40f1-4ead-b2b6-87328b30d084@ow8g2000pbc.googlegroups.com> <4f61c828$0$1390$4fafbaef@reader2.news.tin.it> <4f61d728$0$1375$4fafbaef@reader2.news.tin.it> <4f61fd0a$0$1389$4fafbaef@reader2.news.tin.it> <4f6280a0$0$29981$c3e8da3$5496439d@news.astraweb.com> <4f6333ca$0$1392$4fafbaef@reader1.news.tin.it> <4f633a1a$0$29981$c3e8da3$5496439d@news.astraweb.com> <9sgsb1FsbpU1@mid.individual.net> <9sojehFi09U2@mid.individual.net> <4f671db2$0$29981$c3e8da3$5496439d@news.astraweb.com> Message-ID: <9sooi3F682U1@mid.individual.net> On 2012-03-19, Steven D'Aprano wrote: > On Mon, 19 Mar 2012 11:26:10 +0000, Neil Cerutti wrote: > [...] >>> *A major style guide for general American writing and >>> publication: used by some as the 'Bible'. >> >> Thanks for the discussion and corrections. My apologies to >> Steven for pushing my apparnetly overly narrow view. There are >> plenty of valid use cases for a colon without an independent >> clause. > > No apology necessary, I like a good argument :) > > http://www.mindspring.com/~mfpatton/sketch.htm > > One observation that amuses me though... it seems to me that > the widespread practice of people writing colons following > sentence fragments isn't sufficient to convince you that this > is grammatical, but a self- declared authority prescribing it > as allowed is. That makes you a grammar prescriptivist :) There are certain uses of colon that are worse than others, in my mind. It's a matter of taste, and that's going to be impossible to find references for. My birthday cake had three kinds of frosting: chocolate, vanilla and raspberry. I checked only one reference before diving in (www.wsu.edu/~brians/errors/), but it's a guide that concentrates on presenting yourself well through widely acceptable grammar. It's not an exhaustive taxonomy of all valid usages. So I looked in the wrong place. I still think sentence fragments before a colon introducing a list often looks bad, and may be taken for an error. But it doesn't always look bad, and I didn't think about it enough. > We're-all-a-little-bit-prescriptivists-when-it-comes-to-grammar-ly y'rs, Yep: my clever usage is another's abomination. -- Neil Cerutti From andrea.crotti.0 at gmail.com Mon Mar 19 08:59:43 2012 From: andrea.crotti.0 at gmail.com (Andrea Crotti) Date: Mon, 19 Mar 2012 12:59:43 +0000 Subject: configobj validation Message-ID: <4F672DBF.5060506@gmail.com> I seemed to remember that type validation and type conversion worked out of the box, but now I can't get it working anymore. Shouldn't this simple example actually fail the parsing (instead it parses perfectly port to a string)? sample.py: from configobj import ConfigObj conf = ConfigObj('sample.conf', configspec='sample.spec') sample.conf: port = some_string sample.spec: port = integer(0, 10) PS. using configobj 4.7.2 From thudfoo at gmail.com Mon Mar 19 09:14:44 2012 From: thudfoo at gmail.com (xDog Walker) Date: Mon, 19 Mar 2012 06:14:44 -0700 Subject: ANN: cmd2, an extenstion of cmd that parses its argument line In-Reply-To: <20285780.118.1332133873462.JavaMail.geo-discussion-forums@pbcwe9> References: <20285780.118.1332133873462.JavaMail.geo-discussion-forums@pbcwe9> Message-ID: <201203190614.44110.thudfoo@gmail.com> On Sunday 2012 March 18 22:11, anntzer.lee at gmail.com wrote: > I would like to announce the first public release of cmd2, an extension of > the standard library's cmd with argument parsing, here: > https://github.com/anntzer/cmd2. There already is a cmd2 package at PyPI and has been for a long time. http://packages.python.org/cmd2/ -- I have seen the future and I am not in it. From brian.wilkinson at ssfs.org Mon Mar 19 09:20:06 2012 From: brian.wilkinson at ssfs.org (Brian Wilkinson) Date: Mon, 19 Mar 2012 06:20:06 -0700 (PDT) Subject: New learner of Python--any suggestion on studying it? References: Message-ID: <5cf01d60-c5d9-4a38-84c4-aac517bfc2af@i18g2000vbx.googlegroups.com> On Mar 19, 2:30?am, yan xianming wrote: > Hello all, > > I'm a new learning of Python. > > Can someone give me some suggestion about it? > > thanks > xianming Once you have a few of the basics down (using the resources others have suggested), a good way to practice those skills is to visit Project Euler (http://projecteuler.net/) or The Python Challenge (http://www.pythonchallenge.com/). Project Euler is a site with math problems that can be best solved using basic programming skills. The first problem asks for the sum of all the multiples of 3 or 5 below 1000. The problems build in difficulty and in the programming skills you need. The Python Challenge (best completed using version 2.7 of Python) is hard to explain, but a lot of fun to do. Good luck! Brian From __peter__ at web.de Mon Mar 19 09:27:11 2012 From: __peter__ at web.de (Peter Otten) Date: Mon, 19 Mar 2012 14:27:11 +0100 Subject: Message passing between python objects References: Message-ID: J. Mwebaze wrote: > I am trying to learn about the interaction between python objects. One > thing i have often read is that objects interact by sending messages to > other objects to invoke corresponding methods. I am specifically > interested in tracing these messages and also probably log the messages > for further scrutiny. I would like to build a provenance kind of system. The term "message" occurs in various contexts in computing. You have probably encountered these http://en.wikipedia.org/wiki/Smalltalk#Messages http://en.wikipedia.org/wiki/Message_loop_in_Microsoft_Windows and are mixing the two meanings. However, methods in Python are ordinary functions that know about "their" instance. Given a = A() a.method(1, 2) and A.method(a, 1, 2) are equivalent, no animals are hurt and no messages passed. From steve+comp.lang.python at pearwood.info Mon Mar 19 09:37:05 2012 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 19 Mar 2012 13:37:05 GMT Subject: Python is readable References: <4f612b19$0$1379$4fafbaef@reader2.news.tin.it> <8e72d74f-c844-4de3-8a37-f6b1fdc2291f@y27g2000yqy.googlegroups.com> <50e9ceec-40f1-4ead-b2b6-87328b30d084@ow8g2000pbc.googlegroups.com> <4f668a9d$0$29981$c3e8da3$5496439d@news.astraweb.com> Message-ID: <4f673680$0$29981$c3e8da3$5496439d@news.astraweb.com> On Mon, 19 Mar 2012 15:33:51 +1100, Chris Angelico wrote: >> This is at least the second time you've alleged that assembly language >> is more readable than Python. I think you're a raving nutter, no >> offence Chris :-) > > None taken; guilty as charged. And unashamedly so. With that dealt with, > though: My calling assembly "readable" is a form of argument by drawing > to logical, but absurd, conclusion - by the given definition of > readability, assembly is readable, ergo the definition sucks. (That's a > term all logicians use, you know. Proper and formal jargon.) Which definition of readability are you using? Because I have given, if not a formal definition, at least a good explanation of what I consider to be the usual meaning of "readability" in the context of programming languages. I haven't seen anyone propose an alternative. Readability, as I see it, is a misnomer. What people actually mean by "Ruby is more readable than Forth" (say) is that Ruby is more comprehensible to some idealised non-expert reader. I also gave a list of characteristics of this idealised reader -- check the archives. I don't see how "assembly is readable" is the logical conclusion of my definition. It certainly is the logical conclusion if you make expert practitioners in the language as the judge of readability, but that's not my argument, that's yours. >> Assignment (name binding) is close to the absolute simplest thing you >> can do in a programming language. In Python, the syntax is intuitive to >> anyone who has gone through high school, or possibly even primary >> school, and been introduced to the equals sign. >> >> x = 1234 >> y = "Hello" > > Not quite. In mathematics, "x = 1234" is either a declaration of fact, > or a statement that can be either true or false. [snip differences between assignment and equality] Granted there are differences. Nevertheless, even mathematicians have a form of assignment, using almost the same notation many programming languages use: let c = 42 Sometimes the "let" is left out. The point is not that programming assignment and mathematical equality are identical, but that most people have been exposed to maths = in school and so can intuit the meaning of programming = . Admittedly not always *correctly* :) [...] >> Assembly has a very steep learning curve. Python has a shallow curve. > > Of course. But computer programming generally has a fairly stiff > learning curve; you have to get your head around all sorts of concepts > that simply do not exist anywhere else. Sure. That brings us to the perennial conflict between power/ expressibility versus readability/comprehensibility. Except for languages aimed purely as a teaching language for beginners, or perhaps an application scripting language, readability should not be the *only* aim in a language. The trick is to add as much power as you need without losing too much readability. The more powerful an abstraction or programming construct, the less non- experts will be able to intuit what it does. Or for that matter, the less likely they will be able to understand it even after explanations. I still have no idea what Haskell monads are. Contrariwise, the simpler and more comprehensible a tool is for non- experts, the less likely it will be interesting to experts. Either there will be too much syntactic sugar (e.g. "add 3 to x" instead of x += 3) or it simply won't do much ("x + 3" is understandable but not very interesting, and it doesn't help you talk to a database). Somewhere between those extremes of Forth and Hypertalk is a happy medium. It is my position that Python is somewhat closer to that peak than close neighbours like Ruby and Javascript, but I'm willing to accept that a certain amount of that is mere personal taste. Of course my personal taste is right and theirs is wrong. *wink* >> If all you have is a hammer, the instructions you get are easy to >> understand because there's not much you can do with it. How complicated >> can "hit the nail with the hammer" get? But the right measure is not >> the simplicity of the tasks you *can* do, but the comprehensibility of >> the tasks you *want* to do. > > Right, which is why NO language can be described as "readable" or "easy > to work with" unless you define a problem domain. SQL is an excellent > language... as long as you want to query a relational database. And so long as you stick to simple examples, it is relatively comprehensible: SELECT COLUMN2 FROM TABLE WHERE COLUMN1 = 42; But then you have stuff like this: SELECT * FROM ( SELECT RANK() OVER (ORDER BY age ASC) AS ranking, person_id, person_name, age FROM person ) foo WHERE ranking <= 10 Try asking your dear ol' granny to explain what that does. >> The measure of the readability of a language should not be obfuscated >> or badly written code, but good, idiomatic code written by an >> experienced practitioner in the art. Note that there is a deliberate >> asymmetry there: when judging "readability" (comprehensibility), we >> take idiomatic code written by somebody who knows the language well, >> and give it to a novice to interpret it. > > Sure. You can write bad code in any language, and that doesn't mean > anything. But still, if you're writing for a novice, you write quite > different code from what you'd write normally. Language tutorials are > written by experts for novices; language tutorials do not look like the > language's own standard library (assuming it has one written in itself). Absolutely. One of my pet peeves is the number of people who give answers to questions *far* over the experience level of the person asking the question. Like if Joe Noob asked how to read a number from three files and calculate the sum, and I gave an answer involving spawning a bunch of threads to read the files. If your aim is to *teach*, then "that's how I would do it" is not necessarily a good answer is the person you are trying to teach knows less than you. >>> Really, the metric MUST be Python programmers. Intuitiveness is of >>> value, but readability among experienced programmers is far more >>> useful. >> >> But by that metric, Brainf*** is readable, since an experienced expert >> in the art of writing BF code will be able to recognise BF idioms and >> interpret them correctly. > > Not really. The BF code to do one simple high level operation could > easily span several pages. You can't "recognize" those. Now, BF with > macros/subroutines might be more plausible - if you could define a new > opcode that represents some huge slab of BF code and use that - but in > its native form, I don't think anyone could recognize what BF is doing. Dude, there are people who can recite pi to ten thousand digits, or tell you the 23rd phone number on page 348 of the White Pages from memory. Somewhere out there is a guy who can glance at eight pages of BF code and tell you what it does and where the bugs are. >> No, I'm sorry, I disagree that the standard of readability should be >> the experienced programmer. By that standard, "readability" is a no-op. >> All languages are, more or less, equally readable, to those who can >> read them well. I don't think it is useful to judge the readability of >> Forth on the ability of Charles Moore to read it. How does that help me >> decide whether to use Forth for my next project? >> >>> If I write a whole lot of code today, and next year I'm dead and >>> someone else has replaced me, I frankly don't mind if he has to learn >>> the language before he can grok my code. I _do_ mind if, even after >>> he's learned the language, he can't figure out what my code's doing; >> >> Then he hasn't learned the language *sufficiently well*. Either that, >> or your code is obfuscated, unidiomatic crap. Perhaps you're trying to >> write BF in Python :) > > And that's where the nub of the question is. How well is sufficiently > well? Clearly you do not require your code to be comprehensible to a > non-programmer, or you would not write code at all. If you don't demand > that the reader learn basic keywords of the language, then it's equally > impossible to expect them to comprehend your code. If you're writing > production code, I see no reason to avoid language features like > Python's list comps, Pike's %{ %} sprintf codes, or C's pointer > arithmetic, just because they can confuse people. Learn the language, > THEN start hacking on the code. Certainly. I don't mean to imply that code should always be written for beginners. Code is primarily written for other programmers, and only secondly for the compiler, so you must choose your audience. Every piece of code needs to weigh up many different characteristics, some of which are in conflict: * fast to run * fast to write * efficient use of memory or other resources * easy to add functionality * easy to debug * understandable to non-experts * useful * correct The last two are especially interesting. Some problems can't be solved correctly in any reasonable timeframe, but heuristics can give an answer which may not be strictly correct but still useful. Many optimization problems are like that. Sometimes a close answer is better than no answer at all. -- Steven From neilc at norwich.edu Mon Mar 19 10:33:25 2012 From: neilc at norwich.edu (Neil Cerutti) Date: 19 Mar 2012 14:33:25 GMT Subject: A debugging story. Message-ID: <9soudlFimvU1@mid.individual.net> I just spent two hours debugging a crucial, though fairly simple, program. As part of the processing of an admissions report, I use difflib to compare two csv files. I compare the current file with one from the immediate past. The file changes over time as new students are accepted, and current students change major and so forth. I next comb through the generated diff to find the actually changed fields, keeping a log of critical changes. I found I had not accounted for field names changing between runs of the admissions report, as recently happened when something had to be added to the report. I finally got it working and tested, and then was horrified when a slip of my finger caused me to have to revert to a previous version of the file from rcs. Two hours of work, down the bit-bucket! My horror abated when I found I was able to make the necessary changes again in roughly 30 seconds. This message brought to you by the Debugging is Mostly Comprehending Old Code and Testing Council. -- Neil Cerutti From robert.kern at gmail.com Mon Mar 19 10:38:33 2012 From: robert.kern at gmail.com (Robert Kern) Date: Mon, 19 Mar 2012 14:38:33 +0000 Subject: Python is readable In-Reply-To: <9sooi3F682U1@mid.individual.net> References: <4f612b19$0$1379$4fafbaef@reader2.news.tin.it> <8e72d74f-c844-4de3-8a37-f6b1fdc2291f@y27g2000yqy.googlegroups.com> <50e9ceec-40f1-4ead-b2b6-87328b30d084@ow8g2000pbc.googlegroups.com> <4f61c828$0$1390$4fafbaef@reader2.news.tin.it> <4f61d728$0$1375$4fafbaef@reader2.news.tin.it> <4f61fd0a$0$1389$4fafbaef@reader2.news.tin.it> <4f6280a0$0$29981$c3e8da3$5496439d@news.astraweb.com> <4f6333ca$0$1392$4fafbaef@reader1.news.tin.it> <4f633a1a$0$29981$c3e8da3$5496439d@news.astraweb.com> <9sgsb1FsbpU1@mid.individual.net> <9sojehFi09U2@mid.individual.net> <4f671db2$0$29981$c3e8da3$5496439d@news.astraweb.com> <9sooi3F682U1@mid.individual.net> Message-ID: On 3/19/12 12:53 PM, Neil Cerutti wrote: > I still think sentence fragments before a colon introducing a > list often looks bad, and may be taken for an error. But it > doesn't always look bad, and I didn't think about it enough. One of my English teachers suggested a rule that seems to accord (descriptively) with the uses the "look good" and "look bad" to me: don't use a colon to separate a transitive verb from its objects. -- Robert Kern "I have come to believe that the whole world is an enigma, a harmless enigma that is made terrible by our own mad attempt to interpret it as though it had an underlying truth." -- Umberto Eco From andrea.crotti.0 at gmail.com Mon Mar 19 10:44:21 2012 From: andrea.crotti.0 at gmail.com (Andrea Crotti) Date: Mon, 19 Mar 2012 14:44:21 +0000 Subject: configobj validation In-Reply-To: <4F672DBF.5060506@gmail.com> References: <4F672DBF.5060506@gmail.com> Message-ID: <4F674645.4070600@gmail.com> On 03/19/2012 12:59 PM, Andrea Crotti wrote: > I seemed to remember that type validation and type conversion worked > out of the box, but now > I can't get it working anymore. > > Shouldn't this simple example actually fail the parsing (instead it > parses perfectly port to a string)? > > sample.py: > from configobj import ConfigObj > > conf = ConfigObj('sample.conf', configspec='sample.spec') > > sample.conf: > port = some_string > > sample.spec: > port = integer(0, 10) > > PS. using configobj 4.7.2 I now checked the repo and configobj seems also quite dead (2 years ago last version), it's a pity because it's a really nice library. Any other alternatives for validation/configuration systems otherwise? From steve+comp.lang.python at pearwood.info Mon Mar 19 11:27:39 2012 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 19 Mar 2012 15:27:39 GMT Subject: Python is readable References: <4f612b19$0$1379$4fafbaef@reader2.news.tin.it> <8e72d74f-c844-4de3-8a37-f6b1fdc2291f@y27g2000yqy.googlegroups.com> <50e9ceec-40f1-4ead-b2b6-87328b30d084@ow8g2000pbc.googlegroups.com> <4f61c828$0$1390$4fafbaef@reader2.news.tin.it> <4f61d728$0$1375$4fafbaef@reader2.news.tin.it> <4f61fd0a$0$1389$4fafbaef@reader2.news.tin.it> <4f6280a0$0$29981$c3e8da3$5496439d@news.astraweb.com> <4f6333ca$0$1392$4fafbaef@reader1.news.tin.it> <4f633a1a$0$29981$c3e8da3$5496439d@news.astraweb.com> <4f64f2d8$0$1393$4fafbaef@reader1.news.tin.it> <4f653e5c$0$29981$c3e8da3$5496439d@news.astraweb.com> <4f671c36$0$1386$4fafbaef@reader2.news.tin.it> Message-ID: <4f67506b$0$29981$c3e8da3$5496439d@news.astraweb.com> On Mon, 19 Mar 2012 12:44:53 +0100, Kiuhnm wrote: > On 3/18/2012 2:46, Steven D'Aprano wrote: >> On Sat, 17 Mar 2012 21:23:45 +0100, Kiuhnm wrote: >> >>> On 3/16/2012 14:03, Steven D'Aprano wrote: >>>> A one line routine is still a routine. There is nothing ungrammatical >>>> about "If you can: take the bus.", although it is non-idiomatic >>>> English. >>> >>> In another post you wrote >>> "Sorry, I was talking about the other sort, the ones who apply the >>> grammatical rules used by people in real life. You know the ones: >>> linguists." >>> >>> Then how do you know that there's nothing ungrammatical about "If you >>> can: take the bus" if people don't use it? >> >> Who says it is ungrammatical? > > You did. > You're not a prescriptivist, thus you're probably a descriptivist. > Beeing a descriptivist, you must agree on the fact that > "If ...: do this" > is ungrammatical, because nobody says that. I believe that you are misunderstanding the descriptivist position. There are many sentences which are never said, or perhaps only said once. Most non-trivial spoken or written sentences are unique. That doesn't make them wrong or erroneous because "nobody says them". Nobody says "hesitant teapots sleep artistically". It's a meaningless sentence, but it is grammatically correct: it obeys the same grammatical rule as "hungry dogs howl pitifully" or "devote saints suffer silently": ADJECTIVE NOUN VERB ADVERB. This pattern is common in English: nearly everyone uses it, and therefore any sentence matching the pattern is *grammatically* correct for English even if it is semantically meaningless. On the other hand, "pitifully dogs hungry howl" is incorrect because virtually no English speaker writes sentences using the rule ADVERB NOUN ADJECTIVE VERB, and on such rare times that somebody does, people will notice and declare that it is "wrong" or "doesn't make sense", or otherwise correct it. In my opinion, "If ...: do this" matches a grammatical pattern which I see very frequently. I've already given my reasons for this. > On the other hand, a > prescriptivist might accept that. BTW, I asked a few teachers of English > whether "If ...: do this" is correct or not and they, surprisingly, said > "no". What matters is not the authorities who say something is right or wrong, but their reasons for doing so. -- Steven From waitmeforever at hotmail.com Mon Mar 19 12:04:24 2012 From: waitmeforever at hotmail.com (Yang Chun-Kai) Date: Tue, 20 Mar 2012 00:04:24 +0800 Subject: Please recommend a open source for Python ACLs function Message-ID: Hello Dear All: I would like to write some simple python test code with ACL(Access Control List) functions. Now simply I aim to use MAC address as ACL parameters, is there any good ACL open source recommended for using? Simple one is better. Any tips or suggestions welcomed and appreciated. Thank you. Kay -------------- next part -------------- An HTML attachment was scrubbed... URL: From andrea.crotti.0 at gmail.com Mon Mar 19 12:54:03 2012 From: andrea.crotti.0 at gmail.com (Andrea Crotti) Date: Mon, 19 Mar 2012 16:54:03 +0000 Subject: pypi and dependencies Message-ID: <4F6764AB.7060008@gmail.com> When I publish something on Pypi, is there a way to make it fetch the list of dependencies needed by my project automatically? It would be nice to have it in the Pypi page, without having to look at the actual code.. Any other possible solution? From ichels.moabit at gmail.com Mon Mar 19 13:59:21 2012 From: ichels.moabit at gmail.com (Wim M) Date: 19 Mar 2012 17:59:21 GMT Subject: New learner of Python--any suggestion on studying it? References: Message-ID: <4f6773f9$0$7628$9b4e6d93@newsspool1.arcor-online.net> Hi, this might be of interest to you: http://www.udacity.com/overview/Course/cs101 All the best Wimm On 2012-03-19, yan xianming wrote: > Hello all, > > I'm a new learning of Python. > > > > Can someone give me some suggestion about it? > > thanks > xianming -- Wim. From gandalf at shopzeus.com Mon Mar 19 15:32:03 2012 From: gandalf at shopzeus.com (Laszlo Nagy) Date: Mon, 19 Mar 2012 20:32:03 +0100 Subject: urllib.urlretrieve never returns??? In-Reply-To: <4F66E687.2050008@shopzeus.com> References: <4F649BFC.1080601@shopzeus.com> <4F66E687.2050008@shopzeus.com> Message-ID: <4F6789B3.30907@shopzeus.com> The pythonw.exe may not have the rights to access network resources. >> Have you set a default timeout for sockets? >> >> import socket >> socket.setdefaulttimeout(10) # 10 seconds I have added pythonw.exe to allowed exceptions. Disabled firewall completely. Set socket timeout to 10 seconds. Still nothing. urllib.urlretrieve does not return from call.... any other ideas? From joncle at googlemail.com Mon Mar 19 19:04:54 2012 From: joncle at googlemail.com (Jon Clements) Date: Mon, 19 Mar 2012 16:04:54 -0700 (PDT) Subject: urllib.urlretrieve never returns??? In-Reply-To: References: <4F649BFC.1080601@shopzeus.com> <4F66E687.2050008@shopzeus.com> Message-ID: <11279707.1159.1332198294121.JavaMail.geo-discussion-forums@vbfl9> On Monday, 19 March 2012 19:32:03 UTC, Laszlo Nagy wrote: > The pythonw.exe may not have the rights to access network resources. > >> Have you set a default timeout for sockets? > >> > >> import socket > >> socket.setdefaulttimeout(10) # 10 seconds > I have added pythonw.exe to allowed exceptions. Disabled firewall > completely. Set socket timeout to 10 seconds. Still nothing. > > urllib.urlretrieve does not return from call.... > > any other ideas? Maybe try using the reporthook option for urlretrieve, just to see if that does anything... If it constantly calls the hook or never calls it, that's one thing. Alternately, tcpdump/wireshark whatever, to see what the heck is going on with traffic - if any. hth Jon From joncle at googlemail.com Mon Mar 19 19:04:54 2012 From: joncle at googlemail.com (Jon Clements) Date: Mon, 19 Mar 2012 16:04:54 -0700 (PDT) Subject: urllib.urlretrieve never returns??? In-Reply-To: References: <4F649BFC.1080601@shopzeus.com> <4F66E687.2050008@shopzeus.com> Message-ID: <11279707.1159.1332198294121.JavaMail.geo-discussion-forums@vbfl9> On Monday, 19 March 2012 19:32:03 UTC, Laszlo Nagy wrote: > The pythonw.exe may not have the rights to access network resources. > >> Have you set a default timeout for sockets? > >> > >> import socket > >> socket.setdefaulttimeout(10) # 10 seconds > I have added pythonw.exe to allowed exceptions. Disabled firewall > completely. Set socket timeout to 10 seconds. Still nothing. > > urllib.urlretrieve does not return from call.... > > any other ideas? Maybe try using the reporthook option for urlretrieve, just to see if that does anything... If it constantly calls the hook or never calls it, that's one thing. Alternately, tcpdump/wireshark whatever, to see what the heck is going on with traffic - if any. hth Jon From ian.g.kelly at gmail.com Mon Mar 19 19:20:43 2012 From: ian.g.kelly at gmail.com (Ian Kelly) Date: Mon, 19 Mar 2012 17:20:43 -0600 Subject: Currying in Python In-Reply-To: <4f63e724$0$1386$4fafbaef@reader1.news.tin.it> References: <4f63e724$0$1386$4fafbaef@reader1.news.tin.it> Message-ID: I hope you don't mind if I critique your code a bit! On Fri, Mar 16, 2012 at 7:21 PM, Kiuhnm wrote: > Here we go. > > ---> > def genCur(f, unique = True, minArgs = -1): It is customary in Python for unsupplied arguments with no default to use the value None, not -1. That's what it exists for. > ? ?""" Generates a 'curried' version of a function. """ > ? ?def geng(curArgs, curKwargs): > ? ? ? ?def g(*args, **kwargs): > ? ? ? ? ? ?nonlocal f, curArgs, curKwargs, minArgs; ? ?# our STATIC data > > ? ? ? ? ? ?if len(args) or len(kwargs): Collections evaluate as true if they are not empty, so this could just be: if args or kwargs: > ? ? ? ? ? ? ? ?# Allocates data for the next 'g'. We don't want to modify our > ? ? ? ? ? ? ? ?# static data. > ? ? ? ? ? ? ? ?newArgs = curArgs[:]; > ? ? ? ? ? ? ? ?newKwargs = dict.copy(curKwargs); > > ? ? ? ? ? ? ? ?# Adds positional arguments. > ? ? ? ? ? ? ? ?newArgs += args; > > ? ? ? ? ? ? ? ?# Adds/updates keyword arguments. > ? ? ? ? ? ? ? ?if unique: > ? ? ? ? ? ? ? ? ? ?# We don't want repeated keyword arguments. > ? ? ? ? ? ? ? ? ? ?for k in kwargs.keys(): > ? ? ? ? ? ? ? ? ? ? ? ?if k in newKwargs: > ? ? ? ? ? ? ? ? ? ? ? ? ? ?raise(Exception("Repeated kw arg while unique = True")); > ? ? ? ? ? ? ? ?newKwargs.update(kwargs); Since you're writing this for Python 3 (as evidenced by the use of the nonlocal keyword), you could take advantage here of the fact that Python 3 dictionary views behave like sets. Also, you should use a more specific exception type: if unique and not kwargs.keys().isdisjoint(newKwargs): raise ValueError("A repeated keyword argument was supplied") > ? ? ? ? ? ? ? ?# Checks whether it's time to evaluate f. > ? ? ? ? ? ? ? ?if minArgs >= 0 and minArgs <= len(newArgs) + len(newKwargs): With minArgs defaulting to None, that would be: if minArgs is not None and minArgs <= len(newArgs) + len(newKwargs): > ? ? ? ? ? ? ? ? ? ?return f(*newArgs, **newKwargs); ? ?# f has enough args > ? ? ? ? ? ? ? ?else: > ? ? ? ? ? ? ? ? ? ?return geng(newArgs, newKwargs); ? ?# f needs some more args > ? ? ? ? ? ?else: > ? ? ? ? ? ? ? ?return f(*curArgs, **curKwargs); ? ?# the caller forced the evaluation > ? ? ? ?return g; > ? ?return geng([], {}); > > def cur(f, minArgs = -1): > ? ?return genCur(f, True, minArgs); > > def curr(f, minArgs = -1): > ? ?return genCur(f, False, minArgs); The names "cur" and "curr" are terrible. Good names should describe what the function does without being too onerous to type, and the addition of the duplicate "r" is not an obvious mnemonic for remembering that the first one prohibits duplicate keyword arguments and the second one allows them. Why not more descriptive names like "curry" and "curry_unique"? That's all I've got. All in all, it's pretty decent for a Python newbie. Cheers, Ian From steve+comp.lang.python at pearwood.info Mon Mar 19 19:26:20 2012 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 19 Mar 2012 23:26:20 GMT Subject: urllib.urlretrieve never returns??? References: <4F649BFC.1080601@shopzeus.com> <4F66E687.2050008@shopzeus.com> Message-ID: <4f67c09b$0$29981$c3e8da3$5496439d@news.astraweb.com> On Mon, 19 Mar 2012 20:32:03 +0100, Laszlo Nagy wrote: > The pythonw.exe may not have the rights to access network resources. >>> Have you set a default timeout for sockets? >>> >>> import socket >>> socket.setdefaulttimeout(10) # 10 seconds > I have added pythonw.exe to allowed exceptions. Disabled firewall > completely. Set socket timeout to 10 seconds. Still nothing. > > urllib.urlretrieve does not return from call.... > > any other ideas? I'm sorry if I have missed something, or making suggestions you have already tried, but your original post describing the problem is missing from my news server. I gather you are running urlretrieve in a separate thread, inside a GUI? I have learned that whenever I have inexplicable behaviour in a function, I should check my assumptions. In this case, (1) are you sure you have the right urlretrieve, and (2) are you sure that your self.Log() method is working correctly? Just before the problematic call, do this: # was: fpath = urllib.urlretrieve(imgurl)[0] # becomes: print(urllib.__file__, urlretrieve) self.Log(urllib.__file__, urlretrieve) fpath = urllib.urlretrieve(imgurl)[0] and ensure that you haven't accidentally shadowed them with something unexpected. Does the output printed to the console match the output logged? What happens if you take the call to urlretrieve out of the thread and call it by hand? Run urllib.urlretrieve(imgurl) directly in the interactive interpreter. Does it still hang forever? When you say it "never" returns, do you mean *never* or do you mean "I gave up waiting after five minutes"? What happens if you leave it to run all day? Perhaps it returns after e.g. seven hours, which would be a mystery in itself, but at least you have perturbed the problem and have another data point. Maybe it isn't dead, just really slow. How big are the files you are trying to retrieve? Try retrieving a really small file. Then try retrieving a non-existent file. What happens if you call urlretrieve with a reporthook argument? Does it print anything? What happens if you try to browse to imgurl in your web browser? Are you sure the problem is with urlretrieve and not the source? -- Steven From kiuhnm03.4t.yahoo.it Mon Mar 19 20:24:22 2012 From: kiuhnm03.4t.yahoo.it (Kiuhnm) Date: Tue, 20 Mar 2012 01:24:22 +0100 Subject: Currying in Python In-Reply-To: References: <4f63e724$0$1386$4fafbaef@reader1.news.tin.it> Message-ID: <4f67ce36$0$1377$4fafbaef@reader2.news.tin.it> On 3/20/2012 0:20, Ian Kelly wrote: > I hope you don't mind if I critique your code a bit! Not at all. Thank you for your time. > On Fri, Mar 16, 2012 at 7:21 PM, Kiuhnm > wrote: >> Here we go. >> >> ---> >> def genCur(f, unique = True, minArgs = -1): [...] I'll update my code following your corrections, but will keep "curr" :) Kiuhnm From kiuhnm03.4t.yahoo.it Mon Mar 19 21:13:55 2012 From: kiuhnm03.4t.yahoo.it (Kiuhnm) Date: Tue, 20 Mar 2012 02:13:55 +0100 Subject: Currying in Python In-Reply-To: References: <4f63e724$0$1386$4fafbaef@reader1.news.tin.it> Message-ID: <4f67d9d3$0$1386$4fafbaef@reader2.news.tin.it> On 3/20/2012 0:20, Ian Kelly wrote: > I hope you don't mind if I critique your code a bit! And I hope you don't mind that I included your name in my code. Let me know if I should remove it. Kiuhnm From _spice at mail.ru Mon Mar 19 23:19:40 2012 From: _spice at mail.ru (=?UTF-8?B?0JDRgNGC0ZHQvCDQndCw0LfQsNGA0L7Qsg==?=) Date: Tue, 20 Mar 2012 07:19:40 +0400 Subject: =?UTF-8?B?c19wdXNoIHBhcnNlciBzdGFjayBvdmVyZmxvdw==?= Message-ID: Hi. Sorry of my english :-) code: print (((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((0)))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))" message from python is: s_push parser stack overflow Can i configure phyton to solve this problem without change MAXSTACK in " parser.c" and re-build the python? From python at mrabarnett.plus.com Tue Mar 20 00:30:51 2012 From: python at mrabarnett.plus.com (MRAB) Date: Tue, 20 Mar 2012 04:30:51 +0000 Subject: s_push parser stack overflow In-Reply-To: References: Message-ID: <4F6807FB.8010604@mrabarnett.plus.com> On 20/03/2012 03:19, ????? ??????? wrote: > Hi. > Sorry of my english :-) > > code: > print (((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((0)))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))" > > message from python is: s_push parser stack overflow > > Can i configure phyton to solve this problem without change MAXSTACK in " parser.c" and re-build the python? A quick look at parser.h tells me that it's a hard-coded limit: typedef struct { stackentry *s_top; /* Top entry */ stackentry s_base[MAXSTACK];/* Array of stack entries */ /* NB The stack grows down */ } stack; From prince.ram85 at gmail.com Tue Mar 20 00:31:39 2012 From: prince.ram85 at gmail.com (prince.pangeni) Date: Mon, 19 Mar 2012 21:31:39 -0700 (PDT) Subject: Distribution Message-ID: <33044d51-c481-4796-a722-406f412cf994@x7g2000pbi.googlegroups.com> Hi all, I am doing a simulation project using Python. In my project, I want to use some short of distribution to generate requests to a server. The request should have two distributions. One for request arrival rate (should be poisson) and another for request mix (i.e. out of the total requests defined in request arrival rate, how many requests are of which type). Example: Suppose the request rate is - 90 req/sec (generated using poisson distribution) at time t and we have 3 types of requests (i.e. r1, r2, r2). The request mix distribution output should be similar to: {r1 : 50 , r2 : 30 , r3 : 10} (i.e. out of 90 requests - 50 are of r1 type, 30 are of r2 type and 10 are of r3 type). As I an new to python distribution module, I am not getting how to code this situation. Please help me out for the same. Thanks in advance Prince From gojosupra at gmail.com Tue Mar 20 01:46:07 2012 From: gojosupra at gmail.com (jothi) Date: Mon, 19 Mar 2012 22:46:07 -0700 (PDT) Subject: with out invesment Message-ID: http://123maza.com/46/golden756/ From medina.rc at gmail.com Tue Mar 20 02:00:50 2012 From: medina.rc at gmail.com (Richard Medina Calderon) Date: Mon, 19 Mar 2012 23:00:50 -0700 (PDT) Subject: Eclipse, C, and Python Message-ID: <6023956.2302.1332223250728.JavaMail.geo-discussion-forums@ynlp3> Hello Forum. I have installed Python comnpiler in Eclipse Classic for Windows. After a while I have installed the C compiler. However, somehow now when I try to run my code in Python it shows me for default Ant Run -->Ant Build I switched my workspace but still. Do you know how to solve this?.. Thanks From gandalf at shopzeus.com Tue Mar 20 03:08:12 2012 From: gandalf at shopzeus.com (Laszlo Nagy) Date: Tue, 20 Mar 2012 08:08:12 +0100 Subject: urllib.urlretrieve never returns??? In-Reply-To: <4f67c09b$0$29981$c3e8da3$5496439d@news.astraweb.com> References: <4F649BFC.1080601@shopzeus.com> <4F66E687.2050008@shopzeus.com> <4f67c09b$0$29981$c3e8da3$5496439d@news.astraweb.com> Message-ID: <4F682CDC.5000703@shopzeus.com> Here you can find the example program and the original post. http://code.activestate.com/lists/python-list/617894/ > > I gather you are running urlretrieve in a separate thread, inside a GUI? Yes. > > I have learned that whenever I have inexplicable behaviour in a function, > I should check my assumptions. In this case, (1) are you sure you have > the right urlretrieve, and (2) are you sure that your self.Log() method > is working correctly? Just before the problematic call, do this: > > # was: > fpath = urllib.urlretrieve(imgurl)[0] > > # becomes: > print(urllib.__file__, urlretrieve) > self.Log(urllib.__file__, urlretrieve) > fpath = urllib.urlretrieve(imgurl)[0] I called self.Log() after each line, and also from a general "except:" clause. Definitely, the line after urlretrieve is not executed, and no exception is raised. Number of threads goes up (visible from task manager). It is true that the program uses another module that uses the socket module and multiple threads. (These are written in pure python.) If I remove the other module, then there is no error, however it renders the application useless. If I start the program with a console (e.g. with python.exe instead of pythonw.exe) then it works. Looks like opening a console solves the problem, although nothing is ever printed on the console. > and ensure that you haven't accidentally shadowed them with something > unexpected. Does the output printed to the console match the output > logged? Well, this cannot be tested. If there is a console, then there is no problem. > > What happens if you take the call to urlretrieve out of the thread and > call it by hand? Then it works. > Run urllib.urlretrieve(imgurl) directly in the > interactive interpreter. Does it still hang forever? Then it works perfectly. > > When you say it "never" returns, do you mean *never* or do you mean "I > gave up waiting after five minutes"? What happens if you leave it to run > all day? I did not try that. But I have already set socket timeout to 10 seconds, and definitely it is not waiting for a response from the server. > > How big are the files you are trying to retrieve? 34 KB > Try retrieving a really small file. Then try retrieving a non-existent file. Good point. I'll try to retrieve a nonexistent file when I get home. :) > > What happens if you call urlretrieve with a reporthook argument? Does it > print anything? I'll try this too. I'll also try using pycurl or the low level socket module instead. > > What happens if you try to browse to imgurl in your web browser? Are you > sure the problem is with urlretrieve and not the source? Yes. From arnodel at gmail.com Tue Mar 20 03:11:59 2012 From: arnodel at gmail.com (Arnaud Delobelle) Date: Tue, 20 Mar 2012 07:11:59 +0000 Subject: Currying in Python In-Reply-To: References: <4f63e724$0$1386$4fafbaef@reader1.news.tin.it> Message-ID: On 19 March 2012 23:20, Ian Kelly wrote: > I hope you don't mind if I critique your code a bit! > > On Fri, Mar 16, 2012 at 7:21 PM, Kiuhnm > wrote: >> Here we go. >> >> ---> >> def genCur(f, unique = True, minArgs = -1): > > It is customary in Python for unsupplied arguments with no default to > use the value None, not -1. ?That's what it exists for. > >> ? ?""" Generates a 'curried' version of a function. """ >> ? ?def geng(curArgs, curKwargs): >> ? ? ? ?def g(*args, **kwargs): >> ? ? ? ? ? ?nonlocal f, curArgs, curKwargs, minArgs; ? ?# our STATIC data I don't know if all the rest of the code is below, but this line above would only be necessary if you want to rebind f, curArgs, minArgs. You don't seem to do it, so I think this line is unnecessary. Also, your naming of variables disagrees with PEP 8 :) >> ? ? ? ? ? ?if len(args) or len(kwargs): > > Collections evaluate as true if they are not empty, so this could just be: > > ? ? ? ? ? ?if args or kwargs: > >> ? ? ? ? ? ? ? ?# Allocates data for the next 'g'. We don't want to modify our >> ? ? ? ? ? ? ? ?# static data. >> ? ? ? ? ? ? ? ?newArgs = curArgs[:]; Semicolon to end a statement? >> ? ? ? ? ? ? ? ?newKwargs = dict.copy(curKwargs); >> >> ? ? ? ? ? ? ? ?# Adds positional arguments. >> ? ? ? ? ? ? ? ?newArgs += args; >> >> ? ? ? ? ? ? ? ?# Adds/updates keyword arguments. >> ? ? ? ? ? ? ? ?if unique: >> ? ? ? ? ? ? ? ? ? ?# We don't want repeated keyword arguments. >> ? ? ? ? ? ? ? ? ? ?for k in kwargs.keys(): >> ? ? ? ? ? ? ? ? ? ? ? ?if k in newKwargs: >> ? ? ? ? ? ? ? ? ? ? ? ? ? ?raise(Exception("Repeated kw arg while unique = True")); >> ? ? ? ? ? ? ? ?newKwargs.update(kwargs); > > Since you're writing this for Python 3 (as evidenced by the use of the > nonlocal keyword), you could take advantage here of the fact that > Python 3 dictionary views behave like sets. ?Also, you should use a > more specific exception type: > > ? ? ? ? ? ? ? ?if unique and not kwargs.keys().isdisjoint(newKwargs): > ? ? ? ? ? ? ? ? ? ?raise ValueError("A repeated keyword argument was supplied") > >> ? ? ? ? ? ? ? ?# Checks whether it's time to evaluate f. >> ? ? ? ? ? ? ? ?if minArgs >= 0 and minArgs <= len(newArgs) + len(newKwargs): > > With minArgs defaulting to None, that would be: > > ? ? ? ? ? ? ? ?if minArgs is not None and minArgs <= len(newArgs) + > len(newKwargs): > >> ? ? ? ? ? ? ? ? ? ?return f(*newArgs, **newKwargs); ? ?# f has enough args >> ? ? ? ? ? ? ? ?else: >> ? ? ? ? ? ? ? ? ? ?return geng(newArgs, newKwargs); ? ?# f needs some more args >> ? ? ? ? ? ?else: >> ? ? ? ? ? ? ? ?return f(*curArgs, **curKwargs); ? ?# the caller forced the evaluation >> ? ? ? ?return g; >> ? ?return geng([], {}); >> >> def cur(f, minArgs = -1): >> ? ?return genCur(f, True, minArgs); >> >> def curr(f, minArgs = -1): >> ? ?return genCur(f, False, minArgs); > > The names "cur" and "curr" are terrible. ?Good names should describe > what the function does without being too onerous to type, and the > addition of the duplicate "r" is not an obvious mnemonic for > remembering that the first one prohibits duplicate keyword arguments > and the second one allows them. ?Why not more descriptive names like > "curry" and "curry_unique"? > > That's all I've got. ?All in all, it's pretty decent for a Python newbie. > > Cheers, > Ian > -- > http://mail.python.org/mailman/listinfo/python-list From __peter__ at web.de Tue Mar 20 05:15:01 2012 From: __peter__ at web.de (Peter Otten) Date: Tue, 20 Mar 2012 10:15:01 +0100 Subject: Distribution References: <33044d51-c481-4796-a722-406f412cf994@x7g2000pbi.googlegroups.com> Message-ID: prince.pangeni wrote: > Hi all, > I am doing a simulation project using Python. In my project, I want > to use some short of distribution to generate requests to a server. > The request should have two distributions. One for request arrival > rate (should be poisson) and another for request mix (i.e. out of the > total requests defined in request arrival rate, how many requests are > of which type). > Example: Suppose the request rate is - 90 req/sec (generated using > poisson distribution) at time t and we have 3 types of requests (i.e. > r1, r2, r2). The request mix distribution output should be similar to: > {r1 : 50 , r2 : 30 , r3 : 10} (i.e. out of 90 requests - 50 are of r1 > type, 30 are of r2 type and 10 are of r3 type). > As I an new to python distribution module, I am not getting how to > code this situation. Please help me out for the same. You don't say what distribution module you're talking of, and I guess I'm not the only one who'd need to know that detail. However, with sufficient resolution and duration the naive approach sketched below might be good enough. # untested DURATION = 3600 # run for one hour RATE = 90 # requests/sec RESOLUTION = 1000 # one msec requests = ([r1]*50 + [r2]*30 + [r3]*10) time_slots = [0]*(RESOLUTION*DURATION) times = range(RESOLUTION*DURATION) for _ in range(DURATION*RATE): time_slots[random.choice(times)] += 1 for time, count in enumerate(time_slots): for _ in range(count): issue_request_at(random.choice(requests), time) From kiuhnm03.4t.yahoo.it Tue Mar 20 06:06:42 2012 From: kiuhnm03.4t.yahoo.it (Kiuhnm) Date: Tue, 20 Mar 2012 11:06:42 +0100 Subject: Currying in Python In-Reply-To: References: <4f63e724$0$1386$4fafbaef@reader1.news.tin.it> Message-ID: <4f6856b2$0$1392$4fafbaef@reader1.news.tin.it> On 3/20/2012 0:20, Ian Kelly wrote: > Since you're writing this for Python 3 (as evidenced by the use of the > nonlocal keyword), you could take advantage here of the fact that > Python 3 dictionary views behave like sets. Also, you should use a > more specific exception type: As a side note, "nonlocal" isn't needed in my code, in fact I removed it right after my first post. Kiuhnm From kiuhnm03.4t.yahoo.it Tue Mar 20 06:13:23 2012 From: kiuhnm03.4t.yahoo.it (Kiuhnm) Date: Tue, 20 Mar 2012 11:13:23 +0100 Subject: Currying in Python In-Reply-To: References: <4f63e724$0$1386$4fafbaef@reader1.news.tin.it> Message-ID: <4f685843$0$1374$4fafbaef@reader1.news.tin.it> On 3/20/2012 8:11, Arnaud Delobelle wrote: > On 19 March 2012 23:20, Ian Kelly wrote: >> I hope you don't mind if I critique your code a bit! >> >> On Fri, Mar 16, 2012 at 7:21 PM, Kiuhnm >> wrote: >>> Here we go. >>> >>> ---> >>> def genCur(f, unique = True, minArgs = -1): >> >> It is customary in Python for unsupplied arguments with no default to >> use the value None, not -1. That's what it exists for. >> >>> """ Generates a 'curried' version of a function. """ >>> def geng(curArgs, curKwargs): >>> def g(*args, **kwargs): >>> nonlocal f, curArgs, curKwargs, minArgs; # our STATIC data > > I don't know if all the rest of the code is below, but this line above > would only be necessary if you want to rebind f, curArgs, minArgs. > You don't seem to do it, so I think this line is unnecessary. What a coincidence. I was just telling that to Ian Kelly. I removed it from the code in my article a few days ago but forgot to update my post on this ng. > Also, your naming of variables disagrees with PEP 8 :) > >>> if len(args) or len(kwargs): >> >> Collections evaluate as true if they are not empty, so this could just be: >> >> if args or kwargs: >> >>> # Allocates data for the next 'g'. We don't want to modify our >>> # static data. >>> newArgs = curArgs[:]; > > Semicolon to end a statement? As above. Too many years of C++. Kiuhnm From martin.hellwig at gmail.com Tue Mar 20 06:19:31 2012 From: martin.hellwig at gmail.com (Martin P. Hellwig) Date: Tue, 20 Mar 2012 10:19:31 +0000 Subject: Eclipse, C, and Python In-Reply-To: <6023956.2302.1332223250728.JavaMail.geo-discussion-forums@ynlp3> References: <6023956.2302.1332223250728.JavaMail.geo-discussion-forums@ynlp3> Message-ID: On 20/03/2012 06:00, Richard Medina Calderon wrote: > Hello Forum. I have installed Python comnpiler in Eclipse Classic for Windows. > After a while I have installed the C compiler. However, somehow now when I try to run my code in Python it shows me for default Ant > > Run -->Ant Build > > I switched my workspace but still. Do you know how to solve this?.. > > Thanks You might want to install the PyDev plugin and switch to that perspective (after configuring it). Cheers, MArtin From ben+python at benfinney.id.au Tue Mar 20 07:18:39 2012 From: ben+python at benfinney.id.au (Ben Finney) Date: Tue, 20 Mar 2012 22:18:39 +1100 Subject: pypi and dependencies References: Message-ID: <87bonrmsfk.fsf@benfinney.id.au> Andrea Crotti writes: > When I publish something on Pypi, is there a way to make it fetch the list > of dependencies needed by my project automatically? > > It would be nice to have it in the Pypi page, without having to look at the > actual code.. Sadly, no. The metadata available for packages on PyPI does not include information about the dependencies. (I'd love to be wrong about that, but I'm pretty certain that for most, if not all, packages that's the case.) > Any other possible solution? All the solutions I've seen involve fetching the full package in order to unpack it and *then* parse it for dependencies. This is very sub-optimal, and I believe people are working on it; but fixing it will at least require adjustment to all existing packages that don't have dependencies in their metadata. -- \ ?Some people have a problem, and they think ?I know, I'll use | `\ Perl!?. Now they have some number of problems but they're not | _o__) sure whether it's a string or an integer.? ?Benno Rice, 2011 | Ben Finney From ben+python at benfinney.id.au Tue Mar 20 07:21:02 2012 From: ben+python at benfinney.id.au (Ben Finney) Date: Tue, 20 Mar 2012 22:21:02 +1100 Subject: Distribution References: <33044d51-c481-4796-a722-406f412cf994@x7g2000pbi.googlegroups.com> Message-ID: <877gyfmsbl.fsf@benfinney.id.au> "prince.pangeni" writes: > I am doing a simulation project using Python. In my project, I want > to use some short of distribution to generate requests to a server. What is a distribution? That term already means something in Python jargon, and it doesn't match the rest of your use case. So what do you mean by ?distribution?? Maybe we can find a less confusing term. -- \ ?I used to think that the brain was the most wonderful organ in | `\ my body. Then I realized who was telling me this.? ?Emo Philips | _o__) | Ben Finney From robert.kern at gmail.com Tue Mar 20 08:00:50 2012 From: robert.kern at gmail.com (Robert Kern) Date: Tue, 20 Mar 2012 12:00:50 +0000 Subject: Distribution In-Reply-To: <877gyfmsbl.fsf@benfinney.id.au> References: <33044d51-c481-4796-a722-406f412cf994@x7g2000pbi.googlegroups.com> <877gyfmsbl.fsf@benfinney.id.au> Message-ID: On 3/20/12 11:21 AM, Ben Finney wrote: > "prince.pangeni" writes: > >> I am doing a simulation project using Python. In my project, I want >> to use some short of distribution to generate requests to a server. > > What is a distribution? That term already means something in Python > jargon, and it doesn't match the rest of your use case. > > So what do you mean by ?distribution?? Maybe we can find a less > confusing term. Judging from the context, he means a probability distribution. -- Robert Kern "I have come to believe that the whole world is an enigma, a harmless enigma that is made terrible by our own mad attempt to interpret it as though it had an underlying truth." -- Umberto Eco From andrea.crotti.0 at gmail.com Tue Mar 20 08:01:47 2012 From: andrea.crotti.0 at gmail.com (Andrea Crotti) Date: Tue, 20 Mar 2012 12:01:47 +0000 Subject: pypi and dependencies In-Reply-To: <87bonrmsfk.fsf@benfinney.id.au> References: <87bonrmsfk.fsf@benfinney.id.au> Message-ID: <4F6871AB.6030401@gmail.com> On 03/20/2012 11:18 AM, Ben Finney wrote: > Andrea Crotti writes: > >> When I publish something on Pypi, is there a way to make it fetch the list >> of dependencies needed by my project automatically? >> >> It would be nice to have it in the Pypi page, without having to look at the >> actual code.. > Sadly, no. The metadata available for packages on PyPI does not include > information about the dependencies. > > (I'd love to be wrong about that, but I'm pretty certain that for most, > if not all, packages that's the case.) > >> Any other possible solution? > All the solutions I've seen involve fetching the full package in order > to unpack it and *then* parse it for dependencies. > > This is very sub-optimal, and I believe people are working on it; but > fixing it will at least require adjustment to all existing packages that > don't have dependencies in their metadata. > Yes that's not so nice, many projects write clearly the dependencies in the README file, but that's annoying because it might get outdated. And it's also sad that it's not automatically fetched from setuptools, because it's just python setup.py egg-info && cat package.egg-info/requirements.txt to actually extract them. Should I file a bug maybe or is completely not feasible? From donald.stufft at gmail.com Tue Mar 20 08:13:36 2012 From: donald.stufft at gmail.com (Donald Stufft) Date: Tue, 20 Mar 2012 08:13:36 -0400 Subject: pypi and dependencies In-Reply-To: <4F6871AB.6030401@gmail.com> References: <87bonrmsfk.fsf@benfinney.id.au> <4F6871AB.6030401@gmail.com> Message-ID: <899C4AC6C8EB4E3FA0393A24FA96E690@gmail.com> packaging (in 3.3) and distutils2 (2.x-3.2) is a new metadata format for python packages. It gets rid of setup.py and it includes a way to specify the requirements that your package needs. This will show up on PyPI/Crate. On Tuesday, March 20, 2012 at 8:01 AM, Andrea Crotti wrote: > On 03/20/2012 11:18 AM, Ben Finney wrote: > > Andrea Crotti writes: > > > > > When I publish something on Pypi, is there a way to make it fetch the list > > > of dependencies needed by my project automatically? > > > > > > It would be nice to have it in the Pypi page, without having to look at the > > > actual code.. > > > > > > > Sadly, no. The metadata available for packages on PyPI does not include > > information about the dependencies. > > > > (I'd love to be wrong about that, but I'm pretty certain that for most, > > if not all, packages that's the case.) > > > > > Any other possible solution? > > All the solutions I've seen involve fetching the full package in order > > to unpack it and *then* parse it for dependencies. > > > > This is very sub-optimal, and I believe people are working on it; but > > fixing it will at least require adjustment to all existing packages that > > don't have dependencies in their metadata. > > > > > Yes that's not so nice, many projects write clearly the dependencies in > the README file, > but that's annoying because it might get outdated. > > And it's also sad that it's not automatically fetched from setuptools, > because it's just > > python setup.py egg-info && cat package.egg-info/requirements.txt > > to actually extract them. > Should I file a bug maybe or is completely not feasible? > -- > http://mail.python.org/mailman/listinfo/python-list > > -------------- next part -------------- An HTML attachment was scrubbed... URL: From albert at spenarnc.xs4all.nl Tue Mar 20 08:20:02 2012 From: albert at spenarnc.xs4all.nl (Albert van der Horst) Date: 20 Mar 2012 12:20:02 GMT Subject: Python is readable References: <4f612b19$0$1379$4fafbaef@reader2.news.tin.it> <4f668a9d$0$29981$c3e8da3$5496439d@news.astraweb.com> Message-ID: In article , Chris Angelico wrote: >On Mon, Mar 19, 2012 at 12:23 PM, Steven D'Aprano > wrote: >> On Mon, 19 Mar 2012 09:02:06 +1100, Chris Angelico wrote: >> >>> On Mon, Mar 19, 2012 at 8:30 AM, John Ladasky >>> wrote: >>>> What I would say is that, when PROGRAMMERS look at Python code for the >>>> first time, they will understand what it does more readily than they >>>> would understand other unfamiliar programming languages. =A0That has >>>> value. >>> >>> This is something that's never truly defined. >> >> I'm sorry, I don't understand what part of John's sentence you mean by >> "this". "Programmers"? "Value"? "Understand"? > >I should have rewritten that into the next paragraph. Anyhow. Further >explanation below. > >>> Everyone talks of how this >>> language or that language is readable, but if you mean that you can look >>> at a line of code and know what *that line* does then Python suffers >>> badly and assembly language wins out; >> >> This is at least the second time you've alleged that assembly language is >> more readable than Python. I think you're a raving nutter, no offence >> Chris :-) > >None taken; guilty as charged. And unashamedly so. With that dealt >with, though: My calling assembly "readable" is a form of argument by >drawing to logical, but absurd, conclusion - by the given definition >of readability, assembly is readable, ergo the definition sucks. >(That's a term all logicians use, you know. Proper and formal jargon.) > >> Assignment (name binding) is close to the absolute simplest thing you can >> do in a programming language. In Python, the syntax is intuitive to >> anyone who has gone through high school, or possibly even primary school, >> and been introduced to the equals sign. >> >> x =3D 1234 >> y =3D "Hello" > >Not quite. In mathematics, "x =3D 1234" is either a declaration of fact, >or a statement that can be either true or false. In mathematics, "x =3D >x + 1" is absurd and/or simply false. That's why Pascal has its :=3D >operator, supposed to be read as "becomes" and not "equals". IMHO this >is simply proof of one of the differences between programming and >mathematics. > >> I don't know about anyone else, but I wouldn't have guessed that the way >> to get x=3D1234 was with "x dw 1234". > >Except that it's not quite the same thing. That 8086 Assembly >statement is more like the C statement: >int x=3D1234; >The nearest equivalent of assignment is: >mov x,1234 I tried to mentally translate that to my ciasdis assembler syntax and discovered that there is no instruction in the 8086 for that. It would require using a scratch register like AX. In my very precise ciasdis assembler syntax it would be 1] XXXXXX: DL 0 MOVI, X| R| AX| 1234 IL, MOV, X| F| R| [AX] XXXXXX L, If you were restricted to the 8086, (not 80386 or better) you could not have chosen AX, and you would have used BX instead. [ The first MOVI, could be replaced by a LEA, instruction LEA, AX'| MEM| XXXXXX L, (Go figure!) ] So a realistic fragment could have been PUSH|X BX, MOVI, X| R| BX| 1234 IL,, MOV, X| F| R| [BX] XXXXXX L, POP|X BX, The real unreadability comes from the fact that the novice would ask herself why on earth the BX register was freed while the AX register was free to use. And she is lucky, because no flags were harmed in this sequence, another pitfall. You can't blame me for the unreadibility of the ciasdis-syntax. It merely reflects the abomination that the 8086/80386/Pentium is. Bottom line. A comparison between a HLL where the goal is abstraction and assembly where the goal is precision and control, is unproductive. And if you insist to do it, you better be a real expert. > >And that's where the nub of the question is. How well is sufficiently >well? Clearly you do not require your code to be comprehensible to a >non-programmer, or you would not write code at all. If you don't >demand that the reader learn basic keywords of the language, then it's >equally impossible to expect them to comprehend your code. If you're >writing production code, I see no reason to avoid language features >like Python's list comps, Pike's %{ %} sprintf codes, or C's pointer >arithmetic, just because they can confuse people. Learn the language, >THEN start hacking on the code. Can we just agree, that it is a compromise? > >ChrisA 1] ciasdis.html on the site in my sig. Groetjes Albert -- -- Albert van der Horst, UTRECHT,THE NETHERLANDS Economic growth -- being exponential -- ultimately falters. albert at spe&ar&c.xs4all.nl &=n http://home.hccnet.nl/a.w.m.van.der.horst From robert.kern at gmail.com Tue Mar 20 08:52:46 2012 From: robert.kern at gmail.com (Robert Kern) Date: Tue, 20 Mar 2012 12:52:46 +0000 Subject: Distribution In-Reply-To: <33044d51-c481-4796-a722-406f412cf994@x7g2000pbi.googlegroups.com> References: <33044d51-c481-4796-a722-406f412cf994@x7g2000pbi.googlegroups.com> Message-ID: On 3/20/12 4:31 AM, prince.pangeni wrote: > Hi all, > I am doing a simulation project using Python. In my project, I want > to use some short of distribution to generate requests to a server. > The request should have two distributions. One for request arrival > rate (should be poisson) and another for request mix (i.e. out of the > total requests defined in request arrival rate, how many requests are > of which type). > Example: Suppose the request rate is - 90 req/sec (generated using > poisson distribution) Just a note on terminology to be sure we're clear: a Poisson *distribution* models the number of arrivals in a given time period if the events are from a Poisson *process* with a given mean rate. To model the inter-event arrival times, you use an exponential distribution. If you want to handle events individually in your simulation, you will need to use the exponential distribution to figure out the exact times for each. If you are handling all of the events in each second "in bulk" without regard to the exact times or ordering within that second, then you can use a Poisson distribution. > at time t and we have 3 types of requests (i.e. > r1, r2, r2). The request mix distribution output should be similar to: > {r1 : 50 , r2 : 30 , r3 : 10} (i.e. out of 90 requests - 50 are of r1 > type, 30 are of r2 type and 10 are of r3 type). > As I an new to python distribution module, I am not getting how to > code this situation. Please help me out for the same. I am going to assume that you want to handle each event independently. A basic strategy is to keep a time variable starting at 0 and use a while loop until the time reaches the end of the simulation time. Increment it using a draw from the exponential distribution each loop. Each iteration of the loop is an event. To determine the kind of event, you will need to draw from a weighted discrete distribution. What you want to do here is to do a cumulative sum of the weights, draw a uniform number from 0 to the total sum, then use bisect to find the item that matches. import bisect import random # Use a seeded PRNG for repeatability. Use the methods on the Random # object rather than the functions in the random module. prng = random.Random(1234567890) avg_rate = 90.0 # reqs/sec kind_weights = [50.0, 30.0, 10.0] kind_cumsum = [sum(kind_weights[:i+1]) for i in range(len(kind_weights))] kind_max = kind_cumsum[-1] max_time = 10.0 # sec t = 0.0 # sec events = [] # (t, kind) while t < max_time: dt = prng.expovariate(avg_rate) u = prng.uniform(0.0, kind_max) kind = bisect.bisect_left(kind_cumsum, u) events.append((t, kind)) t += dt -- Robert Kern "I have come to believe that the whole world is an enigma, a harmless enigma that is made terrible by our own mad attempt to interpret it as though it had an underlying truth." -- Umberto Eco From steve+comp.lang.python at pearwood.info Tue Mar 20 09:54:45 2012 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 20 Mar 2012 13:54:45 GMT Subject: Eclipse, C, and Python References: <6023956.2302.1332223250728.JavaMail.geo-discussion-forums@ynlp3> Message-ID: <4f688c25$0$29981$c3e8da3$5496439d@news.astraweb.com> On Mon, 19 Mar 2012 23:00:50 -0700, Richard Medina Calderon wrote: > Hello Forum. I have installed Python comnpiler in Eclipse Classic for > Windows. After a while I have installed the C compiler. However, somehow > now when I try to run my code in Python it shows me for default Ant > > Run -->Ant Build > > I switched my workspace but still. Do you know how to solve this?.. This is an Eclipse problem, not a Python problem. Most people here don't use Eclipse. You might have better luck asking on a forum for Eclipse. -- Steven From alister.ware at ntlworld.com Tue Mar 20 10:39:22 2012 From: alister.ware at ntlworld.com (alister ware) Date: Tue, 20 Mar 2012 14:39:22 GMT Subject: s_push parser stack overflow References: Message-ID: On Tue, 20 Mar 2012 04:30:51 +0000, MRAB wrote: > On 20/03/2012 03:19, ????? ??????? wrote: >> Hi. >> Sorry of my english :-) >> >> code: >> print >> (((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((0)))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))" >> >> message from python is: s_push parser stack overflow >> >> Can i configure phyton to solve this problem without change MAXSTACK in >> " parser.c" and re-build the python? > > A quick look at parser.h tells me that it's a hard-coded limit: > > typedef struct { > stackentry *s_top; /* Top entry */ > stackentry s_base[MAXSTACK];/* Array of stack entries */ > /* NB The stack grows down */ > } stack; But why such an obscure print statement anyway? is it purely to show the issue or is there some actual reason behind it? -- divorce, n: A change of wife. From marksmensocom at yahoo.com Tue Mar 20 10:59:05 2012 From: marksmensocom at yahoo.com (Joi Mond) Date: Tue, 20 Mar 2012 07:59:05 -0700 (PDT) Subject: code for computing and printing list of combinations Message-ID: <1332255545.34960.YahooMailClassic@web126001.mail.ne1.yahoo.com> To All, Can someone help me with the proper code to compute combinations for n=7, r=5 for the following list of numbers: 7, 8, 10, 29, 41, 48, 55. There should be 21 combination. Also once there list is made can a code be written to add (sum) each of the set of five number in the the list. For example list: 8, 10, 29, 48, 55, = 150. Thanks -------------- next part -------------- An HTML attachment was scrubbed... URL: From __peter__ at web.de Tue Mar 20 11:20:32 2012 From: __peter__ at web.de (Peter Otten) Date: Tue, 20 Mar 2012 16:20:32 +0100 Subject: code for computing and printing list of combinations References: <1332255545.34960.YahooMailClassic@web126001.mail.ne1.yahoo.com> Message-ID: Joi Mond wrote: > Can someone help me with the proper code to compute combinations for n=7, > r=5 for the following list of numbers: 7, 8, 10, 29, 41, 48, 55. There > should be 21 combination. Also once there list is made can a code be > written to add (sum) each of the set of five number in the the list. For > example list: 8, 10, 29, 48, 55, = 150. Thanks >>> [sum(x) for x in itertools.combinations([7,8,10,29,41,48,55], 5)] [95, 102, 109, 114, 121, 128, 133, 140, 147, 159, 135, 142, 149, 161, 180, 136, 143, 150, 162, 181, 183] Best wishes to your teacher... From python.list at tim.thechases.com Tue Mar 20 11:33:10 2012 From: python.list at tim.thechases.com (Tim Chase) Date: Tue, 20 Mar 2012 10:33:10 -0500 Subject: code for computing and printing list of combinations In-Reply-To: <1332255545.34960.YahooMailClassic@web126001.mail.ne1.yahoo.com> References: <1332255545.34960.YahooMailClassic@web126001.mail.ne1.yahoo.com> Message-ID: <4F68A336.4060406@tim.thechases.com> On 03/20/12 09:59, Joi Mond wrote: > To All, Can someone help me with the proper code to compute > combinations for n=7, r=5 for the following list of numbers: > 7, 8, 10, 29, 41, 48, 55. There should be 21 combination. Also > once there list is made can a code be written to add (sum) > each of the set of five number in the the list. For example > list: 8, 10, 29, 48, 55, = 150. Thanks Sounds like you want to read up on itertools.combinations() and the sum() function. http://docs.python.org/library/itertools.html#itertools.combinations or >>> import itertools >>> help(itertools.combinations) This sounds like a homework problem, so I won't hand you the answer, but you pass your list to combinations() with the grouping-size (r). You then iterate over the results of that, and use sum() on the results. -tkc From technovegas at gmail.com Tue Mar 20 12:51:09 2012 From: technovegas at gmail.com (Fabric Paul) Date: Tue, 20 Mar 2012 09:51:09 -0700 (PDT) Subject: Fabric Engine v1.0 released under AGPL Message-ID: <549b3a51-5bd9-4ea1-aae0-8f7b09206046@tx8g2000pbc.googlegroups.com> Hi everyone - just letting you know that we released v1.0 of Fabric Engine today. We've open-sourced the core under AGPL, so I hope that gives you an incentive to get started with high-performance for Python :) http://fabricengine.com/technology/benchmarks/ - to give you an idea of the kind of performance possible. Most of these are with node, but the core engine is the same - we just bound it to Python. For those of you using Python on the desktop (particularly if you're working with 3D), we've started a closed beta on a PyQt framework - you can see more here: http://fabricengine.com/2012/03/pyqt-framework-for-fabric-engine/ - email beta at fabricengine.com if you'd like to take part in the testing program. Thanks for your time, Paul From nathan.alexander.rice at gmail.com Tue Mar 20 12:55:07 2012 From: nathan.alexander.rice at gmail.com (Nathan Rice) Date: Tue, 20 Mar 2012 12:55:07 -0400 Subject: Python is readable In-Reply-To: References: <4f612b19$0$1379$4fafbaef@reader2.news.tin.it> <8e72d74f-c844-4de3-8a37-f6b1fdc2291f@y27g2000yqy.googlegroups.com> <50e9ceec-40f1-4ead-b2b6-87328b30d084@ow8g2000pbc.googlegroups.com> Message-ID: Just to troll the discussion a little bit more... On Sun, Mar 18, 2012 at 6:02 PM, Chris Angelico wrote: > On Mon, Mar 19, 2012 at 8:30 AM, John Ladasky wrote: >> What I would say is that, when PROGRAMMERS look at Python code for the >> first time, they will understand what it does more readily than they >> would understand other unfamiliar programming languages. ?That has >> value. > > This is something that's never truly defined. Everyone talks of how > this language or that language is readable, but if you mean that you > can look at a line of code and know what *that line* does, then Python > suffers badly and assembly language wins out; but if you mean that you > should be able to glance over an entire function and comprehend its > algorithm, then I have yet to see any language in which it's not > plainly easy to write bad code. Even with good code, anything more > than trivial can't be eyeballed in that way - if you could, what would > docstrings be for? I agree, docstrings/code comments are a pretty obvious indication that code (as it exists currently) fails as a human communication medium. I suppose that I could make an exception for elaboration on statement with subtle implications. This seems like something people should think more about fixing. > Really, the metric MUST be Python programmers. Intuitiveness is of > value, but readability among experienced programmers is far more > useful. If I write a whole lot of code today, and next year I'm dead > and someone else has replaced me, I frankly don't mind if he has to > learn the language before he can grok my code. I _do_ mind if, even > after he's learned the language, he can't figure out what my code's > doing; and that's where Python's placed itself at about the right > level - not so high that it's all in airy-fairy conceptual work, but > not so low that it gets bogged down. There's a handful of other > languages that are similarly placed, and they're the languages that I > would call "readable". In mathematics, when you perform global optimization you must be willing to make moves in the solution space that may result in a temporary reduction of your optimality condition. If you just perform naive gradient decent, only looking to the change that will induce the greatest immediate improvement in optimality, you will usually end up orbiting around a solution which is not globally optimal. I mention this because any readability or usability information gained using trained programmers is simultaneously measuring the readability or usability and its conformance to the programmer's cognitive model of programming. The result is local optimization around the current-paradigm minimum. This is why we have so many nearly identical curly brace C-like languages. In my opinion, language readability and usability should be determined based on the following tests: - Given users with no programming experience: -- What is the probability that they can correctly guess the result of a program, and how long does it take? -- What is the probability that they can take a program and correctly modify it to change its output to another specified output, or modify it to support another input representation, and how long does it take? - Given users with no programming experience who are provided with a controlled training period: -- What is the probability that they can produce a program that correctly implements a simple, completely described algorithm for solving a puzzle or winning a game, and how long does it take? - Given users with previous (but not extensive) programming experience who are provided with a controlled training period: -- What is the probability that they can produce a program that correctly implements a simple, partially described algorithm for solving a puzzle or winning a game, and how long does it take? -- What is the probability that they can produce a program that correctly implements a complex, completely described algorithm for solving a puzzle or winning a game, and how long does it take? It would probably also be worth examining user behavior relating to code organization and composition under a variety of circumstances. It seems likely that if proper organization and composition are intuitive, productivity would scale well with program size. > Here's an analogy: One statement (aka line of code, etc) corresponds > to one sentence in English. Massive one-liners are like some of the > sentences in Paul's epistles; assembly language is like "The cat sat > on the mat". Both are valid; both are hard to read. This is one of my gripes with the dogmatic application of the "break it into multiple statements" mantra of Python. Not only are you forced to use generators to maintain semantic equivalence in many cases, in some cases a partial statement fragment doesn't have any intuitive meaning. The result is that readers are forced to hold the value of intermediate_variable in their head while reading another statement, then translate the statement to the conceptually complete form. A statement should be an encoding from a conceptual space to a operation space, and ideally the two should be as similar as possible. If a concept is atomic, it should not be comprised of multiple statements. From moky.math at gmail.com Tue Mar 20 13:00:25 2012 From: moky.math at gmail.com (Laurent Claessens) Date: Tue, 20 Mar 2012 18:00:25 +0100 Subject: Distribution In-Reply-To: <877gyfmsbl.fsf@benfinney.id.au> References: <33044d51-c481-4796-a722-406f412cf994@x7g2000pbi.googlegroups.com> <877gyfmsbl.fsf@benfinney.id.au> Message-ID: Il 20/03/2012 12:21, Ben Finney ha scritto: > "prince.pangeni" writes: > >> I am doing a simulation project using Python. In my project, I want >> to use some short of distribution to generate requests to a server. I guess scipy is also available in plain python (didn't check), but the following works with Sage : ---------------------------------------------------------------------- | Sage Version 4.8, Release Date: 2012-01-20 | | Type notebook() for the GUI, and license() for information. | ---------------------------------------------------------------------- sage: from scipy import stats sage: X=stats.poisson.rvs sage: X(4) 5 sage: X(4) 2 sage: X(4) 3 Hope it helps Laurent From steve+comp.lang.python at pearwood.info Tue Mar 20 13:48:11 2012 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 20 Mar 2012 17:48:11 GMT Subject: Python is readable References: <4f612b19$0$1379$4fafbaef@reader2.news.tin.it> <8e72d74f-c844-4de3-8a37-f6b1fdc2291f@y27g2000yqy.googlegroups.com> <50e9ceec-40f1-4ead-b2b6-87328b30d084@ow8g2000pbc.googlegroups.com> Message-ID: <4f68c2db$0$29981$c3e8da3$5496439d@news.astraweb.com> On Tue, 20 Mar 2012 12:55:07 -0400, Nathan Rice wrote: > This is one of my gripes with the dogmatic application of the "break it > into multiple statements" mantra of Python. I must admit I don't recognise that one, unless you're talking about "not everything needs to be a one liner". > Not only are you forced to > use generators to maintain semantic equivalence in many cases, in some > cases a partial statement fragment doesn't have any intuitive meaning. > The result is that readers are forced to hold the value of > intermediate_variable in their head while reading another statement, > then translate the statement to the conceptually complete form. A > statement should be an encoding from a conceptual space to a operation > space, and ideally the two should be as similar as possible. > If a concept is atomic, it should not be comprised of multiple > statements. Perhaps you could give some examples (actual or contrived) of stuff where "breaking it into multiple statements" is a bad thing? -- Steven From tjreedy at udel.edu Tue Mar 20 14:09:11 2012 From: tjreedy at udel.edu (Terry Reedy) Date: Tue, 20 Mar 2012 14:09:11 -0400 Subject: Python is readable In-Reply-To: References: <4f612b19$0$1379$4fafbaef@reader2.news.tin.it> <8e72d74f-c844-4de3-8a37-f6b1fdc2291f@y27g2000yqy.googlegroups.com> <50e9ceec-40f1-4ead-b2b6-87328b30d084@ow8g2000pbc.googlegroups.com> Message-ID: On 3/20/2012 12:55 PM, Nathan Rice wrote: > I agree, docstrings/code comments are a pretty obvious indication that > code (as it exists currently) fails as a human communication medium. The fact that scientific journal articles start with a documentation string called an abstract does not indicate that scientific English fails as a human communication medium. Function docstrings say what the function does and how to use it without reading the code. They can be pulled out and displayed elsewhere. They also guide the reading of the code. Abstracts serve the same functions. -- Terry Jan Reedy From michael at stroeder.com Tue Mar 20 14:49:55 2012 From: michael at stroeder.com (=?UTF-8?B?TWljaGFlbCBTdHLDtmRlcg==?=) Date: Tue, 20 Mar 2012 19:49:55 +0100 Subject: Enforcing hash randomization (was: [RELEASED] Second release candidates for Python 2.6.8, 2.7.3, 3.1.5, and 3.2.3) In-Reply-To: References: Message-ID: Benjamin Peterson wrote: > Hash randomization causes the iteration order of dicts and sets to be > unpredictable and differ across Python runs. Python has never guaranteed > iteration order of keys in a dict or set, and applications are advised to never > rely on it. Historically, dict iteration order has not changed very often across > releases and has always remained consistent between successive executions of > Python. Thus, some existing applications may be relying on dict or set ordering. > Because of this and the fact that many Python applications which don't accept > untrusted input are not vulnerable to this attack, in all stable Python releases > mentioned here, HASH RANDOMIZATION IS DISABLED BY DEFAULT. There are two ways to > enable it. The -R commandline option can be passed to the python executable. It > can also be enabled by setting an environmental variable PYTHONHASHSEED to > "random". (Other values are accepted, too; pass -h to python for complete > description.) I wonder how I could enforce hash randomization from within a Python app without too much hassle. I'd like to avoid having to rely on sys-admins doing the right thing when installing my web2ldap. I guess os.environ['PYTHONHASHSEED'] = 'random' before forking a process would be a solution. But is there another way? Ciao, Michael. From nathan.alexander.rice at gmail.com Tue Mar 20 15:28:25 2012 From: nathan.alexander.rice at gmail.com (Nathan Rice) Date: Tue, 20 Mar 2012 15:28:25 -0400 Subject: Python is readable In-Reply-To: References: <4f612b19$0$1379$4fafbaef@reader2.news.tin.it> <8e72d74f-c844-4de3-8a37-f6b1fdc2291f@y27g2000yqy.googlegroups.com> <50e9ceec-40f1-4ead-b2b6-87328b30d084@ow8g2000pbc.googlegroups.com> Message-ID: >> This is one of my gripes with the dogmatic application of the "break it >> into multiple statements" mantra of Python. > > I must admit I don't recognise that one, unless you're talking about "not > everything needs to be a one liner". > ... > Perhaps you could give some examples (actual or contrived) of stuff where > "breaking it into multiple statements" is a bad thing? One example is performing a series of transformations on a collection of data, with the intent of finding an element of that collection that satisfies a particular criterion. If you separate out the individual transformations, you need to understand generators or you will waste space and perform many unnecessary calculations. If you only ever do a single transformation with a clear conceptual meaning, you could create a "master transformation function," but what if you have a large number of potential permutations of that function? What if you are composing three or four functions, each of which is conditional on the data? If you extract things from a statement and assign them somewhat arbitrary names, you've just traded horizontal bloat for vertical bloat (with a net increase in volume), while forcing a reader to scan back and forth to different statements to understand what is happening. To steal a line from Einstein, "Make things as simple as possible, but not simpler" >> I agree, docstrings/code comments are a pretty obvious indication that >> code (as it exists currently) fails as a human communication medium. > > > The fact that scientific journal articles start with a documentation string > called an abstract does not indicate that scientific English fails as a > human communication medium. Function docstrings say what the function does > and how to use it without reading the code. They can be pulled out and > displayed elsewhere. They also guide the reading of the code. Abstracts > serve the same functions. A paper, with topic introduction, methods exposition, data/results description and discussion is a poor analog to a function. I would compare the abstract of a scientific paper to the overview section of a program's documentation. The great majority of the docstrings I see are basically signature rehashes with added type information and assertions, followed by a single sentence English gloss-over. If the code were sufficiently intuitive and expressive, that would be redundant. Of course, there will always be morbidly obese functions and coders that like to wax philosophical or give history lessons in comments. Also, because of Sphinx, it is very common in the Python community weave documents and code together in a way that is convenient for authors but irritating for readers. I personally would prefer not to have to scroll past 100 lines of a tutorial with examples, tests and what not in order to go from one function to another. It would be really awesome if everyone used links to that material in docstrings, and the default sphinx theme created an inline collapsible iframe that included that material for the HTML version. Don't get me wrong, I adore Sphinx, the problem here is people who are lazy or don't know the right way to structure docs. From tjreedy at udel.edu Tue Mar 20 16:01:08 2012 From: tjreedy at udel.edu (Terry Reedy) Date: Tue, 20 Mar 2012 16:01:08 -0400 Subject: Python is readable In-Reply-To: References: <4f612b19$0$1379$4fafbaef@reader2.news.tin.it> <8e72d74f-c844-4de3-8a37-f6b1fdc2291f@y27g2000yqy.googlegroups.com> <50e9ceec-40f1-4ead-b2b6-87328b30d084@ow8g2000pbc.googlegroups.com> Message-ID: On 3/20/2012 3:28 PM, Nathan Rice wrote: >>> This is one of my gripes with the dogmatic application of the "break it >>> into multiple statements" mantra of Python. >> >> I must admit I don't recognise that one, unless you're talking about "not >> everything needs to be a one liner". >> ... >> Perhaps you could give some examples (actual or contrived) of stuff where >> "breaking it into multiple statements" is a bad thing? > > One example is performing a series of transformations on a collection > of data, with the intent of finding an element of that collection that > satisfies a particular criterion. If you separate out the individual > transformations, you need to understand generators or you will waste > space and perform many unnecessary calculations. If you only ever do > a single transformation with a clear conceptual meaning, you could > create a "master transformation function," but what if you have a > large number of potential permutations of that function? What if you > are composing three or four functions, each of which is conditional on > the data? If you extract things from a statement and assign them > somewhat arbitrary names, you've just traded horizontal bloat for > vertical bloat (with a net increase in volume), while forcing a reader > to scan back and forth to different statements to understand what is > happening. > > To steal a line from Einstein, "Make things as simple as possible, but > not simpler" > >>> I agree, docstrings/code comments are a pretty obvious indication that >>> code (as it exists currently) fails as a human communication medium. >> >> >> The fact that scientific journal articles start with a documentation string >> called an abstract does not indicate that scientific English fails as a >> human communication medium. Function docstrings say what the function does >> and how to use it without reading the code. They can be pulled out and >> displayed elsewhere. They also guide the reading of the code. Abstracts >> serve the same functions. > > A paper, with topic introduction, methods exposition, data/results > description and discussion is a poor analog to a function. I would > compare the abstract of a scientific paper to the overview section of > a program's documentation. The great majority of the docstrings I see > are basically signature rehashes with added type information and > assertions, followed by a single sentence English gloss-over. If the > code were sufficiently intuitive and expressive, that would be > redundant. Of course, there will always be morbidly obese functions > and coders that like to wax philosophical or give history lessons in > comments. Both abstracts and doc strings are designed to be and are read independently of the stuff they summarize. Perhaps you do not use help(obj) as often as some other people do. > Also, because of Sphinx, it is very common in the Python community > weave documents and code together in a way that is convenient for > authors but irritating for readers. I personally would prefer not to > have to scroll past 100 lines of a tutorial with examples, tests and > what not in order to go from one function to another. If I understand you, some devs agree. Hence the increasing use of How-to docs with tutorial and example material for a module separate from the reference entries in its section of the Library Reference. -- Terry Jan Reedy From gandalf at shopzeus.com Tue Mar 20 16:12:12 2012 From: gandalf at shopzeus.com (Laszlo Nagy) Date: Tue, 20 Mar 2012 21:12:12 +0100 Subject: urllib.urlretrieve never returns??? In-Reply-To: <4F682CDC.5000703@shopzeus.com> References: <4F649BFC.1080601@shopzeus.com> <4F66E687.2050008@shopzeus.com> <4f67c09b$0$29981$c3e8da3$5496439d@news.astraweb.com> <4F682CDC.5000703@shopzeus.com> Message-ID: <4F68E49C.2060000@shopzeus.com> 2012.03.20. 8:08 keltez?ssel, Laszlo Nagy ?rta: > Here you can find the example program and the original post. > > http://code.activestate.com/lists/python-list/617894/ >> >> I gather you are running urlretrieve in a separate thread, inside a GUI? > Yes. >> >> I have learned that whenever I have inexplicable behaviour in a >> function, >> I should check my assumptions. In this case, (1) are you sure you have >> the right urlretrieve, and (2) are you sure that your self.Log() method >> is working correctly? Just before the problematic call, do this: >> >> # was: >> fpath = urllib.urlretrieve(imgurl)[0] >> >> # becomes: >> print(urllib.__file__, urlretrieve) >> self.Log(urllib.__file__, urlretrieve) >> fpath = urllib.urlretrieve(imgurl)[0] > I called self.Log() after each line, and also from a general "except:" > clause. Definitely, the line after urlretrieve is not executed, and no > exception is raised. Number of threads goes up (visible from task > manager). > > It is true that the program uses another module that uses the socket > module and multiple threads. (These are written in pure python.) > > If I remove the other module, then there is no error, however it > renders the application useless. If I start the program with a console > (e.g. with python.exe instead of pythonw.exe) then it works. Looks > like opening a console solves the problem, although nothing is ever > printed on the console. >> and ensure that you haven't accidentally shadowed them with something >> unexpected. Does the output printed to the console match the output >> logged? > Well, this cannot be tested. If there is a console, then there is no > problem. >> >> What happens if you take the call to urlretrieve out of the thread and >> call it by hand? > Then it works. >> Run urllib.urlretrieve(imgurl) directly in the >> interactive interpreter. Does it still hang forever? > Then it works perfectly. >> >> When you say it "never" returns, do you mean *never* or do you mean "I >> gave up waiting after five minutes"? What happens if you leave it to run >> all day? > I did not try that. But I have already set socket timeout to 10 > seconds, and definitely it is not waiting for a response from the server. >> >> How big are the files you are trying to retrieve? > 34 KB >> Try retrieving a really small file. Then try retrieving a >> non-existent file. > Good point. I'll try to retrieve a nonexistent file when I get home. :) Today I got a different error message printed on console (program started with python.exe) Unhandled exception in thread started by >>Unhandled exception in thread started by >>Unhandled exception in thread started by >>Unhandled exception in thread started by Traceback (most recent call last): Traceback (most recent call last): Traceback (most recent call last): >> File "C:\Python\Projects\Warehouserclient_v3\locedit.py", line 917, in GetThumbnail File "C:\Python\Projects\Warehouserclient_v3\locedit.py", line 917, in GetThumbnail File "C:\Python\Projects\Warehouserclient_v3\locedit.py", line 917, in GetThumbnail sys.excepthook is missing Traceback (most recent call last): I have never seen a traceback like this before. I didn't install any excepthook myself. Program is using wxPython, socket, threads, threading, PIL. Here is something even more strange. If I click on the button three times, then absolutely nothing gets printed on stdout. However, if I close the program with file/exit (actually, calling wx.PySimpleApp.ExitMainLoop) then suddenly three stack traces are printed on stdout, all lines mixed up: Unhandled exception in thread started by >>Unhandled exception in thread started by Unhandled exception in thread started by >>Unhandled exception in thread started by Unhandled exception in thread started by >>Traceback (most recent call last): >>Traceback (most recent call last): >>Traceback (most recent call last): File "C:\Python\Projects\Warehouserclient_v3\locedit.py", line 917, in GetThumbnail Traceback (most recent call last): File "C:\Python\Projects\Warehouserclient_v3\locedit.py", line 917, in GetThumbnail Traceback (most recent call last): File "C:\Python\Projects\Warehouserclient_v3\locedit.py", line 917, in GetThumbnail File "C:\Python\Projects\Warehouserclient_v3\locedit.py", line 917, in GetThumbnail File "C:\Python\Projects\Warehouserclient_v3\locedit.py", line 917, in GetThumbnail self.Log(traceback.format_exc()) self.Log(traceback.format_exc()) self.Log(traceback.format_exc()) AttributeErrorself.Log(traceback.format_exc()) AttributeErrorself.Log(traceback.format_exc()) AttributeError: AttributeError: AttributeError: C:\Python\Projects\Warehouserclient_v3> And the last attributerror doesn't tell what attribute is missing. Probably I'll have to use a different library (pycurl, for example). But the error itself is getting more interesting. Also tried to use an invalid file (that should return with HTTP 404 not found) but the effect is exactly the same. Nothing is printed on stdout until I try to close the program (stop wxPython's mainloop). Then all previously threads throw an AttributeError and all of them print a stack trace (at the same time, lines mixed up). I'll be experimenting with pyCurl now. Thanks, Laszlo From nagle at animats.com Tue Mar 20 16:18:24 2012 From: nagle at animats.com (John Nagle) Date: Tue, 20 Mar 2012 13:18:24 -0700 Subject: urllib.urlretrieve never returns??? In-Reply-To: References: <4F649BFC.1080601@shopzeus.com> Message-ID: <4f68e60f$0$11987$742ec2ed@news.sonic.net> On 3/17/2012 9:34 AM, Chris Angelico wrote: > 2012/3/18 Laszlo Nagy: >> In the later case, "log.txt" only contains "#1" and nothing else. If I look >> at pythonw.exe from task manager, then its shows +1 thread every time I >> click the button, and "#1" is appended to the file. Does it fail to retrieve on all URLs, or only on some of them? Running a web crawler, I've seen some pathological cases. There are a very few sites that emit data very, very slowly, but don't time out because they are making progress. There are also some sites where attempting to negotiate a SSL connection results in the SSL protocol reaching a point where the host end is supposed to finish the handshake, but it doesn't. The odds are against this being the problem. I see problems like that in maybe 1 in 100,000 URLs. John Nagle From buzzard at urubu.freeserve.co.uk Tue Mar 20 16:19:28 2012 From: buzzard at urubu.freeserve.co.uk (duncan smith) Date: Tue, 20 Mar 2012 20:19:28 +0000 Subject: Distribution In-Reply-To: <33044d51-c481-4796-a722-406f412cf994@x7g2000pbi.googlegroups.com> References: <33044d51-c481-4796-a722-406f412cf994@x7g2000pbi.googlegroups.com> Message-ID: On 20/03/12 04:31, prince.pangeni wrote: > Hi all, > I am doing a simulation project using Python. In my project, I want > to use some short of distribution to generate requests to a server. > The request should have two distributions. One for request arrival > rate (should be poisson) and another for request mix (i.e. out of the > total requests defined in request arrival rate, how many requests are > of which type). > Example: Suppose the request rate is - 90 req/sec (generated using > poisson distribution) at time t and we have 3 types of requests (i.e. > r1, r2, r2). The request mix distribution output should be similar to: > {r1 : 50 , r2 : 30 , r3 : 10} (i.e. out of 90 requests - 50 are of r1 > type, 30 are of r2 type and 10 are of r3 type). > As I an new to python distribution module, I am not getting how to > code this situation. Please help me out for the same. > > Thanks in advance > > Prince Robert has given you a very good answer. The easiest way is to generate interarrival times using an exponential distribution, then for each event select the type from a categorical probability mass function. Perhaps the easiest and most efficient approach for the latter using your 'mix distribution' above is to create a list containing 5 instances of r1, 3 of r2 and 1 of r3. Then select the type by generating a random index into the list. It is not an ideal solution generally, but good when the parameters do not change and the required list is small. Duncan From jcd at sdf.lonestar.org Tue Mar 20 16:23:22 2012 From: jcd at sdf.lonestar.org (J. Cliff Dyer) Date: Tue, 20 Mar 2012 16:23:22 -0400 Subject: List comprehension/genexp inconsistency. Message-ID: <1332275002.10958.7.camel@jcdyer-laptop> One of my coworkers just stumbled across an interesting issue. I'm hoping someone here can explain why it's happening. When trying to create a class with a dual-loop generator expression in a class definition, there is a strange scoping issue where the inner variable is not found, (but the outer loop variable is found), while a list comprehension has no problem finding both variables. Demonstration: >>> class Spam: ... foo, bar = 4, 4 ... baz = dict(((x, y), x+y) for x in range(foo) for y in range(bar)) ... Traceback (most recent call last): File "", line 1, in File "", line 3, in Spam File "", line 3, in NameError: global name 'bar' is not defined >>> class Eggs(object): ... foo, bar = 4, 4 ... baz = dict([((x, y), x+y) for x in range(foo) for y in range(bar)]) ... >>> This was discovered in python 2.6. In python 3.2, both versions fail with the same NameError. Obviously, this is easy enough to work around. I'm curious though: What's going on under the hood to cause the nested generator expression to fail while the list comprehension succeeds? Cheers, Cliff From cjw at ncf.ca Tue Mar 20 16:28:33 2012 From: cjw at ncf.ca (Colin J. Williams) Date: Tue, 20 Mar 2012 16:28:33 -0400 Subject: Fabric Engine v1.0 released under AGPL In-Reply-To: <549b3a51-5bd9-4ea1-aae0-8f7b09206046@tx8g2000pbc.googlegroups.com> References: <549b3a51-5bd9-4ea1-aae0-8f7b09206046@tx8g2000pbc.googlegroups.com> Message-ID: On 20/03/2012 12:51 PM, Fabric Paul wrote: > Hi everyone - just letting you know that we released v1.0 of Fabric > Engine today. We've open-sourced the core under AGPL, so I hope that > gives you an incentive to get started with high-performance for > Python :) > > http://fabricengine.com/technology/benchmarks/ - to give you an idea > of the kind of performance possible. Most of these are with node, but > the core engine is the same - we just bound it to Python. > > For those of you using Python on the desktop (particularly if you're > working with 3D), we've started a closed beta on a PyQt framework - > you can see more here: http://fabricengine.com/2012/03/pyqt-framework-for-fabric-engine/ > - email beta at fabricengine.com if you'd like to take part in the > testing program. > > Thanks for your time, > > Paul It seems that sing;e dimension arrays are used in KL. How does this compare with Numpy? Colin W. From nathan.alexander.rice at gmail.com Tue Mar 20 16:34:21 2012 From: nathan.alexander.rice at gmail.com (Nathan Rice) Date: Tue, 20 Mar 2012 16:34:21 -0400 Subject: Python is readable In-Reply-To: References: <4f612b19$0$1379$4fafbaef@reader2.news.tin.it> <8e72d74f-c844-4de3-8a37-f6b1fdc2291f@y27g2000yqy.googlegroups.com> <50e9ceec-40f1-4ead-b2b6-87328b30d084@ow8g2000pbc.googlegroups.com> Message-ID: >>> The fact that scientific journal articles start with a documentation >>> string >>> called an abstract does not indicate that scientific English fails as a >>> human communication medium. Function docstrings say what the function >>> does >>> and how to use it without reading the code. They can be pulled out and >>> displayed elsewhere. They also guide the reading of the code. Abstracts >>> serve the same functions. >> >> >> A paper, with topic introduction, methods exposition, data/results >> description and discussion is a poor analog to a function. ?I would >> compare the abstract of a scientific paper to the overview section of >> a program's documentation. ?The great majority of the docstrings I see >> are basically signature rehashes with added type information and >> assertions, followed by a single sentence English gloss-over. ?If the >> code were sufficiently intuitive and expressive, that would be >> redundant. ?Of course, there will always be morbidly obese functions >> and coders that like to wax philosophical or give history lessons in >> comments. > > > Both abstracts and doc strings are designed to be and are read independently > of the stuff they summarize. Perhaps you do not use help(obj) as often as > some other people do. I find help() to be mostly useless because of the clutter induced by double under methods. I use IPython, and I typically will either use tab name completion with the "?" feature or %edit if I really need to dig around. I teach Python to groups from time to time as part of my job, and I usually only mention help() as something of an afterthought, since typically people react to the output like a deer in headlights. Some sort of semantic function and class search from the interpreter would probably win a lot of fans, but I don't know that it is possible without a standard annotation format and the addition of a namespace cache to pyc files. From roy at panix.com Tue Mar 20 16:38:19 2012 From: roy at panix.com (Roy Smith) Date: Tue, 20 Mar 2012 13:38:19 -0700 (PDT) Subject: Released: stackprint -- analyze python stack dumps in server logs Message-ID: <42e5d5ea-ff53-49e8-935e-184e9430327a@b18g2000vbz.googlegroups.com> Stackprint is a little tool for finding, formatting, and categorizing python stack dumps in server log files. We've found it useful for monitoring the health of our django applications. https://bitbucket.org/roysmith/python-tools. BSD license. From gandalf at shopzeus.com Tue Mar 20 16:42:28 2012 From: gandalf at shopzeus.com (Laszlo Nagy) Date: Tue, 20 Mar 2012 21:42:28 +0100 Subject: urllib.urlretrieve never returns??? [SOLVED] - workaround In-Reply-To: <4F68E49C.2060000@shopzeus.com> References: <4F649BFC.1080601@shopzeus.com> <4F66E687.2050008@shopzeus.com> <4f67c09b$0$29981$c3e8da3$5496439d@news.astraweb.com> <4F682CDC.5000703@shopzeus.com> <4F68E49C.2060000@shopzeus.com> Message-ID: <4F68EBB4.6060606@shopzeus.com> > I'll be experimenting with pyCurl now. By replacing the GetThumbnail method with this brainless example, taken from the pyCurl demo: def GetThumbnail(self,imgurl): class Test: def __init__(self): self.contents = '' def body_callback(self, buf): self.contents = self.contents + buf self.Log("#1: "+repr(imgurl)) try: t = Test() c = pycurl.Curl() c.setopt(c.URL, imgurl) c.setopt(c.WRITEFUNCTION, t.body_callback) self.Log("#2") c.perform() self.Log("#3") c.close() self.Log("#4") fpath = os.path.join(os.environ["TEMP"],"thumbnail.jpg") fout = open(fpath,"wb+") self.Log("#5: "+repr(fpath)) try: fout.write(t.contents) finally: fout.close() self.Log("#6") except: self.Log(traceback.format_exc()) return self.Log("#7") wx.CallAfter(self.imgProduct.SetPage,""""""%fpath) self.Log("#8") Everything works perfectly, in all modes: console, no console, started directly and started in separate thread. So the problem with urllib must be. Maybe wxPython installs some except hooks, or who knows? If somebody feels up to it, I can start narrowing down the problem to the smallest possible application. But only if someone knows how to debug core code because I don't. Otherwise I'll just use pyCURL. Thank you for your help! Laszlo From ramit.prasad at jpmorgan.com Tue Mar 20 16:52:00 2012 From: ramit.prasad at jpmorgan.com (Prasad, Ramit) Date: Tue, 20 Mar 2012 20:52:00 +0000 Subject: urllib.urlretrieve never returns??? In-Reply-To: <4F68E49C.2060000@shopzeus.com> References: <4F649BFC.1080601@shopzeus.com> <4F66E687.2050008@shopzeus.com> <4f67c09b$0$29981$c3e8da3$5496439d@news.astraweb.com> <4F682CDC.5000703@shopzeus.com> <4F68E49C.2060000@shopzeus.com> Message-ID: <5B80DD153D7D744689F57F4FB69AF474026C4BD8@SCACMX008.exchad.jpmchase.net> > Today I got a different error message printed on console (program > started with python.exe) > > > > Unhandled exception in thread started by FrameLocEdit.GetThumbnail of Object of type 'wxPanel *' at 0x4f85300> > >>Unhandled exception in thread started by FrameLocEdit.GetThumbnail of Object of type 'wxPanel *' at 0x4f85300> > >>Unhandled exception in thread started by FrameLocEdit.GetThumbnail of Object of type 'wxPanel *' at 0x4f85300> > >>Unhandled exception in thread started by > Traceback (most recent call last): > > Traceback (most recent call last): > > Traceback (most recent call last): > of > >> File "C:\Python\Projects\Warehouserclient_v3\locedit.py", line 917, > in GetThumbnail > File "C:\Python\Projects\Warehouserclient_v3\locedit.py", line 917, > in GetThumbnail > File "C:\Python\Projects\Warehouserclient_v3\locedit.py", line 917, > in GetThumbnail > > sys.excepthook is missing > Traceback (most recent call last): > > I have never seen a traceback like this before. I didn't install any > excepthook myself. > > Program is using wxPython, socket, threads, threading, PIL. > > Here is something even more strange. If I click on the button three > times, then absolutely nothing gets printed on stdout. However, if I > close the program with file/exit (actually, calling > wx.PySimpleApp.ExitMainLoop) then suddenly three stack traces are > printed on stdout, all lines mixed up: > Maybe in self.Log you should add a sys.stdout.flush and sys.stderr.flush(). I am not very familiar with stdin/out but maybe it will help. > Unhandled exception in thread started by FrameLocEdit.GetThumbnail of Object of type 'wxPanel *' at 0x4fb530 > 0> > >>Unhandled exception in thread started by Unhandled exception in > thread started by 0x4fb5300> > >>Unhandled exception in thread started by Unhandled exception in > thread started by 0x4fb5300> > >>Traceback (most recent call last): FrameLocEdit.GetThumbnail of Object of type 'wxPanel *' at 0x4fb5300> > >>Traceback (most recent call last): FrameLocEdit.GetThumbnail of Object of type 'wxPanel *' at 0x4fb5300> > >>Traceback (most recent call last): File > "C:\Python\Projects\Warehouserclient_v3\locedit.py", line 917, in > GetThumbnail > > > Traceback (most recent call last): > > File "C:\Python\Projects\Warehouserclient_v3\locedit.py", line 917, > in GetThumbnail > Traceback (most recent call last): > File "C:\Python\Projects\Warehouserclient_v3\locedit.py", line 917, > in GetThumbnail > File "C:\Python\Projects\Warehouserclient_v3\locedit.py", line > 917, in GetThumbnail > File "C:\Python\Projects\Warehouserclient_v3\locedit.py", line > 917, in GetThumbnail > self.Log(traceback.format_exc()) > self.Log(traceback.format_exc()) > self.Log(traceback.format_exc()) > AttributeErrorself.Log(traceback.format_exc()) > AttributeErrorself.Log(traceback.format_exc()) > AttributeError: AttributeError: AttributeError: > C:\Python\Projects\Warehouserclient_v3> > > > And the last attributerror doesn't tell what attribute is missing. > Probably I'll have to use a different library (pycurl, for example). But > the error itself is getting more interesting. This makes me think self does not have a .Log() or the traceback import is being overridden by something else that does not have .format_exc(). Or possibly this is in a function that does not have a self (maybe a typo in the function def?). > > Also tried to use an invalid file (that should return with HTTP 404 not > found) but the effect is exactly the same. Nothing is printed on stdout > until I try to close the program (stop wxPython's mainloop). Then all > previously threads throw an AttributeError and all of them print a stack > trace (at the same time, lines mixed up). > > I'll be experimenting with pyCurl now. Ramit Ramit Prasad | JPMorgan Chase Investment Bank | Currencies Technology 712 Main Street | Houston, TX 77002 work phone: 713 - 216 - 5423 -- This email is confidential and subject to important disclaimers and conditions including on offers for the purchase or sale of securities, accuracy and completeness of information, viruses, confidentiality, legal privilege, and legal entity disclaimers, available at http://www.jpmorgan.com/pages/disclosures/email. From ramit.prasad at jpmorgan.com Tue Mar 20 17:01:58 2012 From: ramit.prasad at jpmorgan.com (Prasad, Ramit) Date: Tue, 20 Mar 2012 21:01:58 +0000 Subject: urllib.urlretrieve never returns??? [SOLVED] - workaround In-Reply-To: <4F68EBB4.6060606@shopzeus.com> References: <4F649BFC.1080601@shopzeus.com> <4F66E687.2050008@shopzeus.com> <4f67c09b$0$29981$c3e8da3$5496439d@news.astraweb.com> <4F682CDC.5000703@shopzeus.com> <4F68E49C.2060000@shopzeus.com> <4F68EBB4.6060606@shopzeus.com> Message-ID: <5B80DD153D7D744689F57F4FB69AF474026C4BF3@SCACMX008.exchad.jpmchase.net> > Everything works perfectly, in all modes: console, no console, started > directly and started in separate thread. > > So the problem with urllib must be. Maybe wxPython installs some except > hooks, or who knows? If somebody feels up to it, I can start narrowing > down the problem to the smallest possible application. But only if > someone knows how to debug core code because I don't. Otherwise I'll > just use pyCURL. Have you tried urllib2? Have you tried a small program without using wx? To be honest, I doubt the problem is wx or urllib as they are both fairly broadly used. Try to come up with an example that is as minimal as possible. >>> imgurl = "http://www.shopzeus.hu/thumbnail.php?width=200&image=pyramid/PP0830.jpg" >>> urllib.urlretrieve( imgurl ) ('c:\\[...]\\tmpkhixgt.php', ) And I have Windows 7 64 with Python 2.6.6 (32 bit) and wx installed. Ramit Ramit Prasad | JPMorgan Chase Investment Bank | Currencies Technology 712 Main Street | Houston, TX 77002 work phone: 713 - 216 - 5423 -- This email is confidential and subject to important disclaimers and conditions including on offers for the purchase or sale of securities, accuracy and completeness of information, viruses, confidentiality, legal privilege, and legal entity disclaimers, available at http://www.jpmorgan.com/pages/disclosures/email. From ramit.prasad at jpmorgan.com Tue Mar 20 17:25:07 2012 From: ramit.prasad at jpmorgan.com (Prasad, Ramit) Date: Tue, 20 Mar 2012 21:25:07 +0000 Subject: urllib.urlretrieve never returns??? [SOLVED] - workaround References: <4F649BFC.1080601@shopzeus.com> <4F66E687.2050008@shopzeus.com> <4f67c09b$0$29981$c3e8da3$5496439d@news.astraweb.com> <4F682CDC.5000703@shopzeus.com> <4F68E49C.2060000@shopzeus.com> <4F68EBB4.6060606@shopzeus.com> Message-ID: <5B80DD153D7D744689F57F4FB69AF474026C4C73@SCACMX008.exchad.jpmchase.net> > > Everything works perfectly, in all modes: console, no console, started > > directly and started in separate thread. > > > > So the problem with urllib must be. Maybe wxPython installs some except > > hooks, or who knows? If somebody feels up to it, I can start narrowing > > down the problem to the smallest possible application. But only if > > someone knows how to debug core code because I don't. Otherwise I'll > > just use pyCURL. > > Have you tried urllib2? Have you tried a small program without using wx? > > To be honest, I doubt the problem is wx or urllib as they are both fairly > broadly used. Try to come up with an example that is as minimal as > possible. > > >>> imgurl = > "http://www.shopzeus.hu/thumbnail.php?width=200&image=pyramid/PP0830.jpg" > >>> urllib.urlretrieve( imgurl ) > ('c:\\[...]\\tmpkhixgt.php', ) > > And I have Windows 7 64 with Python 2.6.6 (32 bit) and wx installed. > Your program on ActiveState worked for me which tells me that it might be a network or machine specific problem. You are missing an import which I mentioned in another post. Fixing that should tell what the error you are getting is; you would not be getting the AttributeError without some other error first. Ramit Ramit Prasad | JPMorgan Chase Investment Bank | Currencies Technology 712 Main Street | Houston, TX 77002 work phone: 713 - 216 - 5423 -- This email is confidential and subject to important disclaimers and conditions including on offers for the purchase or sale of securities, accuracy and completeness of information, viruses, confidentiality, legal privilege, and legal entity disclaimers, available at http://www.jpmorgan.com/pages/disclosures/email. From ramit.prasad at jpmorgan.com Tue Mar 20 17:26:51 2012 From: ramit.prasad at jpmorgan.com (Prasad, Ramit) Date: Tue, 20 Mar 2012 21:26:51 +0000 Subject: urllib.urlretrieve never returns??? In-Reply-To: <5B80DD153D7D744689F57F4FB69AF474026C4BD8@SCACMX008.exchad.jpmchase.net> References: <4F649BFC.1080601@shopzeus.com> <4F66E687.2050008@shopzeus.com> <4f67c09b$0$29981$c3e8da3$5496439d@news.astraweb.com> <4F682CDC.5000703@shopzeus.com> <4F68E49C.2060000@shopzeus.com> <5B80DD153D7D744689F57F4FB69AF474026C4BD8@SCACMX008.exchad.jpmchase.net> Message-ID: <5B80DD153D7D744689F57F4FB69AF474026C4C97@SCACMX008.exchad.jpmchase.net> > > Traceback (most recent call last): > > > > File "C:\Python\Projects\Warehouserclient_v3\locedit.py", line 917, > > in GetThumbnail > > Traceback (most recent call last): > > File "C:\Python\Projects\Warehouserclient_v3\locedit.py", line 917, > > in GetThumbnail > > File "C:\Python\Projects\Warehouserclient_v3\locedit.py", line > > 917, in GetThumbnail > > File "C:\Python\Projects\Warehouserclient_v3\locedit.py", line > > 917, in GetThumbnail > > self.Log(traceback.format_exc()) > > self.Log(traceback.format_exc()) > > self.Log(traceback.format_exc()) > > AttributeErrorself.Log(traceback.format_exc()) > > AttributeErrorself.Log(traceback.format_exc()) > > AttributeError: AttributeError: AttributeError: > > C:\Python\Projects\Warehouserclient_v3> > > > > > > And the last attributerror doesn't tell what attribute is missing. > > Probably I'll have to use a different library (pycurl, for example). But > > the error itself is getting more interesting. > > This makes me think self does not have a .Log() or the traceback > import is being overridden by something else that does not have > .format_exc(). Or possibly this is in a function that does not have a > self (maybe a typo in the function def?). > Here you can find the example program and the original post. > > http://code.activestate.com/lists/python-list/617894/ I just looked at your source file on ActiveState and noticed that you do not import traceback. That is why you are getting the AttributeError. Now you should be getting a much better error once you import it :) Ramit Ramit Prasad | JPMorgan Chase Investment Bank | Currencies Technology 712 Main Street | Houston, TX 77002 work phone: 713 - 216 - 5423 -- > -----Original Message----- > From: python-list-bounces+ramit.prasad=jpmorgan.com at python.org > [mailto:python-list-bounces+ramit.prasad=jpmorgan.com at python.org] On Behalf > Of Prasad, Ramit > Sent: Tuesday, March 20, 2012 3:52 PM > To: python-list at python.org > Subject: RE: urllib.urlretrieve never returns??? > > > Today I got a different error message printed on console (program > > started with python.exe) > > > > > > > > Unhandled exception in thread started by > FrameLocEdit.GetThumbnail of > Object of type 'wxPanel *' at 0x4f85300> > > >>Unhandled exception in thread started by > FrameLocEdit.GetThumbnail of > Object of type 'wxPanel *' at 0x4f85300> > > >>Unhandled exception in thread started by > FrameLocEdit.GetThumbnail of > Object of type 'wxPanel *' at 0x4f85300> > > >>Unhandled exception in thread started by > > Traceback (most recent call last): > > > > Traceback (most recent call last): > > > > Traceback (most recent call last): > > > of > > >> File "C:\Python\Projects\Warehouserclient_v3\locedit.py", line 917, > > in GetThumbnail > > File "C:\Python\Projects\Warehouserclient_v3\locedit.py", line 917, > > in GetThumbnail > > File "C:\Python\Projects\Warehouserclient_v3\locedit.py", line 917, > > in GetThumbnail > > > > sys.excepthook is missing > > Traceback (most recent call last): > > > > I have never seen a traceback like this before. I didn't install any > > excepthook myself. > > > > Program is using wxPython, socket, threads, threading, PIL. > > > > Here is something even more strange. If I click on the button three > > times, then absolutely nothing gets printed on stdout. However, if I > > close the program with file/exit (actually, calling > > wx.PySimpleApp.ExitMainLoop) then suddenly three stack traces are > > printed on stdout, all lines mixed up: > > > > Maybe in self.Log you should add a sys.stdout.flush and > sys.stderr.flush(). I am not very familiar with stdin/out but > maybe it will help. > > > Unhandled exception in thread started by > FrameLocEdit.GetThumbnail of > Object of type 'wxPanel *' at 0x4fb530 > > 0> > > >>Unhandled exception in thread started by Unhandled exception in > > thread started by > > 0x4fb5300> > > >>Unhandled exception in thread started by Unhandled exception in > > thread started by > > 0x4fb5300> > > >>Traceback (most recent call last): > FrameLocEdit.GetThumbnail of > Object of type 'wxPanel *' at 0x4fb5300> > > >>Traceback (most recent call last): > FrameLocEdit.GetThumbnail of > Object of type 'wxPanel *' at 0x4fb5300> > > >>Traceback (most recent call last): File > > "C:\Python\Projects\Warehouserclient_v3\locedit.py", line 917, in > > GetThumbnail > > > > > > > > > Also tried to use an invalid file (that should return with HTTP 404 not > > found) but the effect is exactly the same. Nothing is printed on stdout > > until I try to close the program (stop wxPython's mainloop). Then all > > previously threads throw an AttributeError and all of them print a stack > > trace (at the same time, lines mixed up). > > > > I'll be experimenting with pyCurl now. > > > Ramit > > > Ramit Prasad | JPMorgan Chase Investment Bank | Currencies Technology > 712 Main Street | Houston, TX 77002 > work phone: 713 - 216 - 5423 > > -- > > This email is confidential and subject to important disclaimers and > conditions including on offers for the purchase or sale of > securities, accuracy and completeness of information, viruses, > confidentiality, legal privilege, and legal entity disclaimers, > available at http://www.jpmorgan.com/pages/disclosures/email. > -- > http://mail.python.org/mailman/listinfo/python-list From paul at fabric-engine.com Tue Mar 20 18:24:28 2012 From: paul at fabric-engine.com (Paul Doyle) Date: Tue, 20 Mar 2012 15:24:28 -0700 (PDT) Subject: Fabric Engine v1.0 released under AGPL References: <549b3a51-5bd9-4ea1-aae0-8f7b09206046@tx8g2000pbc.googlegroups.com> Message-ID: <0c86f051-e519-4638-9914-110ea02a75a8@db5g2000vbb.googlegroups.com> Hi Colin, Fabric supports multi-dimensional arrays, and also provides support for dictionaries. You can read more here: http://documentation.fabric-engine.com/latest/FabricEngine-KLProgrammingGuide.html In terms of comparison to Numpy - I'm not familiar with that product, but some surface level similarities/differences: - we don't provide high-level functions for scientific computing. This is something we're looking at now. - both products provide methods for including existing libraries (http://documentation.fabric-engine.com/latest/FabricEngine- ExtensionsReference.html) - Fabric is a high-performance framework - http://documentation.fabric-engine.com/latest/FabricEngine-Overview.html - we haven't benchmarked against R, MatLab etc but we run at the same speed as multi-threaded compiled code (since that's essentially what we're doing). Hope that helps, Paul > > It seems that sing;e dimension arrays are used in KL. ?How does this > compare with Numpy? > > Colin W. From ian.g.kelly at gmail.com Tue Mar 20 18:50:03 2012 From: ian.g.kelly at gmail.com (Ian Kelly) Date: Tue, 20 Mar 2012 16:50:03 -0600 Subject: List comprehension/genexp inconsistency. In-Reply-To: References: <1332275002.10958.7.camel@jcdyer-laptop> Message-ID: On Tue, Mar 20, 2012 at 3:16 PM, Dennis Lee Bieber wrote: > On Tue, 20 Mar 2012 16:23:22 -0400, "J. Cliff Dyer" > declaimed the following in > gmane.comp.python.general: > >> >> When trying to create a class with a dual-loop generator expression in a >> class definition, there is a strange scoping issue where the inner >> variable is not found, (but the outer loop variable is found), while a >> list comprehension has no problem finding both variables. >> > ? ? ? ?Read http://www.python.org/dev/peps/pep-0289/ -- in particular, look > for the word "leak" No, this has nothing to do with the loop variable leaking. It appears to have to do with the fact that the variables and the generator expression are inside a class block. I think that it's related to the reason that this doesn't work: class Foo(object): x = 42 def foo(): print(x) foo() In this case, x is not a local variable of foo, nor is it a global. In order for foo to access x, it would have to be a closure -- but Python can't make it a closure in this case, because the variable it accesses is (or rather, will become) a class attribute, not a local variable of a function that can be stored in a cell. Instead, the compiler just makes it a global reference in the hope that such a global will actually be defined when the code is run. For that reason, what surprises me about Cliff's example is that a generator expression works at all in that context. It seems to work as long as it contains only one loop, but not if it contains two. To find out why, I tried disassembling one: >>> class Foo(object): ... x = 42 ... y = 12 ... g = (a+b for a in range(x) for b in range(y)) ... >>> dis.dis(Foo.g.gi_code) 4 0 LOAD_FAST 0 (.0) >> 3 FOR_ITER 34 (to 40) 6 STORE_FAST 1 (a) 9 LOAD_GLOBAL 0 (range) 12 LOAD_GLOBAL 1 (y) 15 CALL_FUNCTION 1 18 GET_ITER >> 19 FOR_ITER 15 (to 37) 22 STORE_FAST 2 (b) 25 LOAD_FAST 1 (a) 28 LOAD_FAST 2 (b) 31 BINARY_ADD 32 YIELD_VALUE 33 POP_TOP 34 JUMP_ABSOLUTE 19 >> 37 JUMP_ABSOLUTE 3 >> 40 LOAD_CONST 0 (None) 43 RETURN_VALUE So that explains it. Notice that "x" is never actually accessed in that disassembly; only "y" is. It turns out that the first iterator [range(x)] is actually created before the generator ever starts executing, and is stored as an anonymous local variable on the generator's stack frame -- so it's created in the class scope, not in the generator scope. The second iterator, however, is recreated on every iteration of the first iterator, so it can't be pre-built in that manner. It does get created in the generator scope, and when that happens it blows up because it can't find the variable, just like the function example above. Cheers, Ian From kiuhnm03.4t.yahoo.it Tue Mar 20 19:27:26 2012 From: kiuhnm03.4t.yahoo.it (Kiuhnm) Date: Wed, 21 Mar 2012 00:27:26 +0100 Subject: Python is readable In-Reply-To: <4f67506b$0$29981$c3e8da3$5496439d@news.astraweb.com> References: <4f612b19$0$1379$4fafbaef@reader2.news.tin.it> <8e72d74f-c844-4de3-8a37-f6b1fdc2291f@y27g2000yqy.googlegroups.com> <50e9ceec-40f1-4ead-b2b6-87328b30d084@ow8g2000pbc.googlegroups.com> <4f61c828$0$1390$4fafbaef@reader2.news.tin.it> <4f61d728$0$1375$4fafbaef@reader2.news.tin.it> <4f61fd0a$0$1389$4fafbaef@reader2.news.tin.it> <4f6280a0$0$29981$c3e8da3$5496439d@news.astraweb.com> <4f6333ca$0$1392$4fafbaef@reader1.news.tin.it> <4f633a1a$0$29981$c3e8da3$5496439d@news.astraweb.com> <4f64f2d8$0$1393$4fafbaef@reader1.news.tin.it> <4f653e5c$0$29981$c3e8da3$5496439d@news.astraweb.com> <4f671c36$0$1386$4fafbaef@reader2.news.tin.it> <4f67506b$0$29981$c3e8da3$5496439d@news.astraweb.com> Message-ID: <4f69125e$0$1380$4fafbaef@reader2.news.tin.it> On 3/19/2012 16:27, Steven D'Aprano wrote: > I believe that you are misunderstanding the descriptivist position. There > are many sentences which are never said, or perhaps only said once. Most > non-trivial spoken or written sentences are unique. That doesn't make > them wrong or erroneous because "nobody says them". > > Nobody says "hesitant teapots sleep artistically". Let's not mix syntax with semantics. "If I'm ok: I'll go." represents all the possible sentences where the if-clause and the then-clause are separated by a colon. I believe that none of those are grammatically correct. Kiuhnm From kiuhnm03.4t.yahoo.it Tue Mar 20 19:57:17 2012 From: kiuhnm03.4t.yahoo.it (Kiuhnm) Date: Wed, 21 Mar 2012 00:57:17 +0100 Subject: Python is readable In-Reply-To: <4f6532e7$0$29981$c3e8da3$5496439d@news.astraweb.com> References: <4f612b19$0$1379$4fafbaef@reader2.news.tin.it> <8e72d74f-c844-4de3-8a37-f6b1fdc2291f@y27g2000yqy.googlegroups.com> <50e9ceec-40f1-4ead-b2b6-87328b30d084@ow8g2000pbc.googlegroups.com> <4f61c828$0$1390$4fafbaef@reader2.news.tin.it> <4f61d728$0$1375$4fafbaef@reader2.news.tin.it> <4f61fd0a$0$1389$4fafbaef@reader2.news.tin.it> <4f6280a0$0$29981$c3e8da3$5496439d@news.astraweb.com> <4f6333ca$0$1392$4fafbaef@reader1.news.tin.it> <4f633a1a$0$29981$c3e8da3$5496439d@news.astraweb.com> <9sgsb1FsbpU1@mid.individual.net> <4f636a38$0$29981$c3e8da3$5496439d@news.astraweb.com> <9shd0kFvgbU1@mid.individual.net> <4f638b76$0$29981$c3e8da3$5496439d@news.astraweb.com> <9shj05FabeU1@mid.individual.net> <4f64fa18$0$1392$4fafbaef@reader1.news.tin.it> <4f6532e7$0$29981$c3e8da3$5496439d@news.astraweb.com> Message-ID: <4f69195d$0$1388$4fafbaef@reader2.news.tin.it> On 3/18/2012 1:57, Steven D'Aprano wrote: >> On 3/16/2012 21:04, Prasad, Ramit wrote: >>>> People spell your name Stephen, sometimes too. Thinking of changing >>>> it? Gore Vidal's quote has panache, a valid compensation for breaking >>> the usual rule. How many other uses on that page are similar? >>> >>> >>> He provided common examples and reference links. Seems like a pretty >>> reasonable way of trying to prove a point. If you don't like reference >>> links, what would convince you that the point was correct? I have not >>> seen any counter examples or counter references on your behalf... >> >> He's referring to this "rule": >> "A colon should not precede a list unless it follows a complete >> sentence; however, the colon is a style choice that some publications >> allow." >> http://www.grammarbook.com/punctuation/colons.asp > > > That is an invented prescriptivist rule and not based on English grammar > as it actually is used by native English speakers. It is *bullshit*. Even > the author of that page breaks it. Immediately following the above > prohibition, she follows it with the sentence fragment: > > "Examples:" > > and then a list -- exactly what she says you may not do. I never said that rule is acceptable. I agree with you on that. > People *do* precede lists by a colon following a sentence fragment. This > is unremarkable English grammar, with only a tiny number of arse-plugged > prescriptivists finding anything to complain about it, and even they > break their own bullshit made-up so-called rule. > > The vast majority of English speakers write things like: > > TO DO: > - mow the lawn > - wash the car > - take kids to the zoo > - write book on grammar > > and there is nothing wrong with doing so. That's perfectly acceptable. Robert Kern put it very well in his post: "don't use a colon to separate a transitive verb from its objects". You can't say TO DO - mow the lawn - ... because "TO DO mow the lawn" doesn't "flow". But why should we break a sentence when there's no need to do so? Why should you write The matrix: .... is equal to.... Why the colon? Why break the flow of a sentence without reason? I would generalize Robert Kern's rule a little: "don't put a colon into a sentence which is fine already". Example: You should - mow the lawn - do the dishes - walk the dog That's perfectly fine. Commas are conveniently omitted. As a side note, titles of movies, newspapers etc... don't follow common rules. Articles may be omitted, verbs may be missing, etc... They're just titles. Kiuhnm From steve+comp.lang.python at pearwood.info Tue Mar 20 20:01:25 2012 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 21 Mar 2012 00:01:25 GMT Subject: Python is readable References: <4f612b19$0$1379$4fafbaef@reader2.news.tin.it> <8e72d74f-c844-4de3-8a37-f6b1fdc2291f@y27g2000yqy.googlegroups.com> <50e9ceec-40f1-4ead-b2b6-87328b30d084@ow8g2000pbc.googlegroups.com> Message-ID: <4f691a55$0$29981$c3e8da3$5496439d@news.astraweb.com> On Tue, 20 Mar 2012 16:34:21 -0400, Nathan Rice wrote: > I find help() to be mostly useless because of the clutter induced by > double under methods. I feel your pain, but perhaps I've just learned how to skim the output without being bogged down in reading every line, or perhaps because I mostly call it on methods rather than on the class itself, I find help() is absolutely invaluable and would be lost without it. -- Steven From steve+comp.lang.python at pearwood.info Tue Mar 20 20:22:22 2012 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 21 Mar 2012 00:22:22 GMT Subject: Python is readable References: <4f612b19$0$1379$4fafbaef@reader2.news.tin.it> <8e72d74f-c844-4de3-8a37-f6b1fdc2291f@y27g2000yqy.googlegroups.com> <50e9ceec-40f1-4ead-b2b6-87328b30d084@ow8g2000pbc.googlegroups.com> Message-ID: <4f691f3d$0$29981$c3e8da3$5496439d@news.astraweb.com> On Tue, 20 Mar 2012 15:28:25 -0400, Nathan Rice wrote: >>> This is one of my gripes with the dogmatic application of the "break >>> it into multiple statements" mantra of Python. >> >> I must admit I don't recognise that one, unless you're talking about >> "not everything needs to be a one liner". >> ... >> Perhaps you could give some examples (actual or contrived) of stuff >> where "breaking it into multiple statements" is a bad thing? > > One example is performing a series of transformations on a collection of > data, with the intent of finding an element of that collection that > satisfies a particular criterion. If you separate out the individual > transformations, you need to understand generators or you will waste > space and perform many unnecessary calculations. If you only ever do a > single transformation with a clear conceptual meaning, you could create > a "master transformation function," but what if you have a large number > of potential permutations of that function? I'm sorry, that is far too abstract for me. Do you have a *concrete* example, even an trivial one? > What if you are composing > three or four functions, each of which is conditional on the data? If > you extract things from a statement and assign them somewhat arbitrary > names, you've just traded horizontal bloat for vertical bloat (with a > net increase in volume), while forcing a reader to scan back and forth > to different statements to understand what is happening. First off, vertical bloat is easier to cope with than horizontal bloat, at least for people used to reading left-to-right rather than vertically. There are few anti-patterns worse that horizontal scrolling, especially for text. Secondly, the human brain can only deal with a limited number of tokens at any one time. It's easier to remember large numbers when they are broken up into chunks: 824-791-259-401 versus 824791259401 (three tokens, versus twelve) Likewise for reading code. Chunking code into multiple lines instead of one long expression, and temporary variables, make things easier to understand, not harder. http://en.wikipedia.org/wiki/The_Magical_Number_Seven,_Plus_or_Minus_Two And thirdly, you're not "forcing" the reader to scan back and forth -- or at least if you are, then you've chosen your functions badly. Functions should have descriptive names and should perform a meaningful task, not just an arbitrary collection of code. When you read: x = range(3, len(sequence), 5) you're not forced to scan back and forth between that line and the code for range and len to understand it, because range and len are good abstractions that make sensible functions. There is a lot of badly written code in existence. Don't blame poor execution of design principles on the design principle itself. [...] > Also, because of Sphinx, it is very common in the Python community weave > documents and code together in a way that is convenient for authors but > irritating for readers. I don't know about "very common". I suspect, given the general paucity of documentation in the average software package, it is more like "very rare, but memorable when it does happen". > I personally would prefer not to have to scroll > past 100 lines of a tutorial with examples, tests and what not in order > to go from one function to another. Agreed. Docstrings should use a minimal number of examples and tests. Tutorials and extensive tests should be extracted into external documents. > It would be really awesome if > everyone used links to that material in docstrings, and the default > sphinx theme created an inline collapsible iframe that included that > material for the HTML version. Don't get me wrong, I adore Sphinx, the > problem here is people who are lazy or don't know the right way to > structure docs. +1000 -- Steven From showell30 at yahoo.com Tue Mar 20 21:28:25 2012 From: showell30 at yahoo.com (Steve Howell) Date: Tue, 20 Mar 2012 18:28:25 -0700 (PDT) Subject: Python is readable References: <4f612b19$0$1379$4fafbaef@reader2.news.tin.it> <8e72d74f-c844-4de3-8a37-f6b1fdc2291f@y27g2000yqy.googlegroups.com> <50e9ceec-40f1-4ead-b2b6-87328b30d084@ow8g2000pbc.googlegroups.com> <4f691f3d$0$29981$c3e8da3$5496439d@news.astraweb.com> Message-ID: On Mar 20, 5:22?pm, Steven D'Aprano wrote: > On Tue, 20 Mar 2012 15:28:25 -0400, Nathan Rice wrote: > > > What if you are composing > > three or four functions, each of which is conditional on the data? ?If > > you extract things from a statement and assign them somewhat arbitrary > > names, you've just traded horizontal bloat for vertical bloat (with a > > net increase in volume), while forcing a reader to scan back and forth > > to different statements to understand what is happening. > > First off, vertical bloat is easier to cope with than horizontal bloat, > at least for people used to reading left-to-right rather than vertically. > There are few anti-patterns worse that horizontal scrolling, especially > for text. > I agree with Steven that horizontal bloat hurts readability more than vertical bloat. Of course, it's a subjective thing, and I get the fact that the remedy to horizontal bloat often means more volume of code overalls (i.e. introducing locals). My main problem with horizontal bloat is that you often have to read inside-outside or right to left: verb3(verb2(verb1(noun))) verb2(verb1(noun, adverb1), adverb2) The vertical versions tend to be more verbose, but entirely sequential: noun1 = verb1(noun) noun2 = verb2(noun1) verb3(noun2) and noun1 = verb1(noun, adverb1) verb2(noun1, adverb2) There is a bit of an inflection point when the number of lines in the "local" code exceeds the vertical real estate of your monitor. I feel like vertical real estate is still mostly constrained by the way we build our monitors and our editors, and it's not so much a "human brain" limitation. With horizontally stretched code, I always feel like my brain is the bottleneck. The one place where I don't mind the horizontal approach is when code is truly laid out in the order of execution: noun.verb1(adverb1).verb2(adverb2).verb3(adverb3).verb4(adverb4) Even then, I'd prefer it to read vertically. Also, while the above idiom puts the verbs in the right order, it is still backward to me to say "noun.verb." You don't noun a verb. You verb a noun. From ben+python at benfinney.id.au Tue Mar 20 22:28:53 2012 From: ben+python at benfinney.id.au (Ben Finney) Date: Wed, 21 Mar 2012 13:28:53 +1100 Subject: Python is readable References: <4f612b19$0$1379$4fafbaef@reader2.news.tin.it> <8e72d74f-c844-4de3-8a37-f6b1fdc2291f@y27g2000yqy.googlegroups.com> <50e9ceec-40f1-4ead-b2b6-87328b30d084@ow8g2000pbc.googlegroups.com> <4f691f3d$0$29981$c3e8da3$5496439d@news.astraweb.com> Message-ID: <87d386lmai.fsf@benfinney.id.au> Steve Howell writes: > Also, while the above idiom puts the verbs in the right order, it is > still backward to me to say "noun.verb." You don't noun a verb. You > verb a noun. When calling a method, the program object is the grammatical subject. You don't verb the noun, and you don't noun a verb. The noun verbs. -- \ ?Last year I went fishing with Salvador Dali. He was using a | `\ dotted line. He caught every other fish.? ?Steven Wright | _o__) | Ben Finney From showell30 at yahoo.com Tue Mar 20 22:44:38 2012 From: showell30 at yahoo.com (Steve Howell) Date: Tue, 20 Mar 2012 19:44:38 -0700 (PDT) Subject: Python is readable References: <4f612b19$0$1379$4fafbaef@reader2.news.tin.it> <8e72d74f-c844-4de3-8a37-f6b1fdc2291f@y27g2000yqy.googlegroups.com> <50e9ceec-40f1-4ead-b2b6-87328b30d084@ow8g2000pbc.googlegroups.com> <4f691f3d$0$29981$c3e8da3$5496439d@news.astraweb.com> <87d386lmai.fsf@benfinney.id.au> Message-ID: <8a77bf8d-b12f-442b-a1a3-479b5d66d366@tx8g2000pbc.googlegroups.com> On Mar 20, 7:28?pm, Ben Finney wrote: > Steve Howell writes: > > Also, while the above idiom puts the verbs in the right order, it is > > still backward to me to say "noun.verb." You don't noun a verb. You > > verb a noun. > > When calling a method, the program object is the grammatical subject. > You don't verb the noun, and you don't noun a verb. The noun verbs. > I think it's a matter of perspective, so there's no right answer, but I always think of the program object as also being the grammatical object, with the implied subject/actor being Python itself. For example, consider this code: stack.push(item) It's not the stack that's pushing. It's the stack being pushed on to. So "stack" is the direct object, and "item" is the indirect object. When you say "stack.push(item)", I think of it as being that Python pushes an item on to the stack. I suppose you would argue that the stack pushes item on to itself? And even then, isn't it still the grammatical object in the "itself" case? Also, don't they call those thingies "object" for a reason? ;) From showell30 at yahoo.com Tue Mar 20 23:07:52 2012 From: showell30 at yahoo.com (Steve Howell) Date: Tue, 20 Mar 2012 20:07:52 -0700 (PDT) Subject: List comprehension/genexp inconsistency. References: <1332275002.10958.7.camel@jcdyer-laptop> Message-ID: <0d1d9544-fc2b-4938-b341-eb912882c13b@ur9g2000pbc.googlegroups.com> On Mar 20, 3:50?pm, Ian Kelly wrote: > On Tue, Mar 20, 2012 at 3:16 PM, Dennis Lee Bieber > > wrote: > > On Tue, 20 Mar 2012 16:23:22 -0400, "J. Cliff Dyer" > > declaimed the following in > > gmane.comp.python.general: > > >> When trying to create a class with a dual-loop generator expression in a > >> class definition, there is a strange scoping issue where the inner > >> variable is not found, (but the outer loop variable is found), while a > >> list comprehension has no problem finding both variables. > > > ? ? ? ?Readhttp://www.python.org/dev/peps/pep-0289/-- in particular, look > > for the word "leak" > > No, this has nothing to do with the loop variable leaking. ?It appears > to have to do with the fact that the variables and the generator > expression are inside a class block. Interesting. Just for completeness, the code does seem to work fine when you take it out of the class: Python 2.6.1 (r261:67515, Jun 24 2010, 21:47:49) [GCC 4.2.1 (Apple Inc. build 5646)] on darwin Type "help", "copyright", "credits" or "license" for more information. >>> foo, bar = 4, 4 >>> g = (((x, y), x+y) for x in range(foo) for y in range(bar)) >>> dict(g) {(0, 1): 1, (1, 2): 3, (3, 2): 5, (0, 0): 0, (3, 3): 6, (3, 0): 3, (3, 1): 4, (2, 1): 3, (0, 2): 2, (2, 0): 2, (1, 3): 4, (2, 3): 5, (2, 2): 4, (1, 0): 1, (0, 3): 3, (1, 1): 2} >>> import dis >>> dis.dis(g.gi_code) 1 0 SETUP_LOOP 57 (to 60) 3 LOAD_FAST 0 (.0) >> 6 FOR_ITER 50 (to 59) 9 STORE_FAST 1 (x) 12 SETUP_LOOP 41 (to 56) 15 LOAD_GLOBAL 0 (range) 18 LOAD_GLOBAL 1 (bar) 21 CALL_FUNCTION 1 24 GET_ITER >> 25 FOR_ITER 27 (to 55) 28 STORE_FAST 2 (y) 31 LOAD_FAST 1 (x) 34 LOAD_FAST 2 (y) 37 BUILD_TUPLE 2 40 LOAD_FAST 1 (x) 43 LOAD_FAST 2 (y) 46 BINARY_ADD 47 BUILD_TUPLE 2 50 YIELD_VALUE 51 POP_TOP 52 JUMP_ABSOLUTE 25 >> 55 POP_BLOCK >> 56 JUMP_ABSOLUTE 6 >> 59 POP_BLOCK >> 60 LOAD_CONST 0 (None) 63 RETURN_VALUE From p_s_d_a_s_i_l_v_a at netcabo.pt Wed Mar 21 00:09:14 2012 From: p_s_d_a_s_i_l_v_a at netcabo.pt (Paulo da Silva) Date: Wed, 21 Mar 2012 04:09:14 +0000 Subject: setup.py for an extension Message-ID: Hi all. I have a python extension (bindings for a C lib - no swig) and I would like to write a setup.py to build a source distribution pack. The extension consists of 3 files: foo.h foo.c foo.py that are placed in a eclipse directory /home//ECLIPSE/workspace/ext/src foo.h+foo.c are to be compiled into _foo.so shared lib. _foo.so is itself a module only called from foo.py. The dir I wrote the setup.py is any arbitrary dir. I don't want to put packaging stuff into the eclipse source. I read the docs but have no idea on how to do this. Some tentatives I did completely failed. Any help? Thanks in advance. From rosuav at gmail.com Wed Mar 21 00:16:36 2012 From: rosuav at gmail.com (Chris Angelico) Date: Wed, 21 Mar 2012 15:16:36 +1100 Subject: Python is readable In-Reply-To: <8a77bf8d-b12f-442b-a1a3-479b5d66d366@tx8g2000pbc.googlegroups.com> References: <4f612b19$0$1379$4fafbaef@reader2.news.tin.it> <8e72d74f-c844-4de3-8a37-f6b1fdc2291f@y27g2000yqy.googlegroups.com> <50e9ceec-40f1-4ead-b2b6-87328b30d084@ow8g2000pbc.googlegroups.com> <4f691f3d$0$29981$c3e8da3$5496439d@news.astraweb.com> <87d386lmai.fsf@benfinney.id.au> <8a77bf8d-b12f-442b-a1a3-479b5d66d366@tx8g2000pbc.googlegroups.com> Message-ID: On Wed, Mar 21, 2012 at 1:44 PM, Steve Howell wrote: > I think it's a matter of perspective, so there's no right answer, but > I always think of the program object as also being the grammatical > object, with the implied subject/actor being Python itself. ?For > example, consider this code: > > ?stack.push(item) > > It's not the stack that's pushing. ?It's the stack being pushed on > to. In code, though, the push() method is defined in and on the stack object (or more likely, on the class that instantiated it, but near enough). So the stack is being asked to push something onto itself. It is still viably the subject. Yes, the implied subject could be the language interpreter; but it could just as easily be the CPU, or those friendly nanobots, or that guy moving the rocks in XKCD 505. But in the abstraction of the line of code, you don't care how CPython goes about loading globals, calling bound methods, and incrementing object reference counts - you just care that the stack is pushing this item onto itself. Some method names are definitely written as though their primary argument is the object, not the subject. Either option works. Do you think about code as the subject+verb and a data structure as the object, or the object as the subject and the method as the verb? Fundamentally no difference. ChrisA From nathan.alexander.rice at gmail.com Wed Mar 21 00:55:51 2012 From: nathan.alexander.rice at gmail.com (Nathan Rice) Date: Wed, 21 Mar 2012 00:55:51 -0400 Subject: Python is readable In-Reply-To: <4f691f3d$0$29981$c3e8da3$5496439d@news.astraweb.com> References: <4f612b19$0$1379$4fafbaef@reader2.news.tin.it> <8e72d74f-c844-4de3-8a37-f6b1fdc2291f@y27g2000yqy.googlegroups.com> <50e9ceec-40f1-4ead-b2b6-87328b30d084@ow8g2000pbc.googlegroups.com> <4f691f3d$0$29981$c3e8da3$5496439d@news.astraweb.com> Message-ID: >> One example is performing a series of transformations on a collection of >> data, with the intent of finding an element of that collection that >> satisfies a particular criterion. ?If you separate out the individual >> transformations, you need to understand generators or you will waste >> space and perform many unnecessary calculations. ?If you only ever do a >> single transformation with a clear conceptual meaning, you could create >> a "master transformation function," but what if you have a large number >> of potential permutations of that function? > > I'm sorry, that is far too abstract for me. Do you have a *concrete* > example, even an trivial one? How about a hypothetical log analyzer that parses a log file that is aggregated from multiple event sources with disparate record structures. You will need to perform a series of transformations on the data to convert record elements from text to specific formats, and your function for identifying "alarm" records is also dependent on record structure (and possibly system state, imagining an intrusion detection system). Of course you could go through a lot of trouble to dispatch and detect alarms over 6-7 statements, however given the description "for each log record you receive, convert text elements to native data types based on the value of the first three fields of the record, then trigger an alert if that record meets defined requirements" and assuming you have maps from record values to conversion functions for record elements, and a map from record types to alert criteria functions for record types already constructed, it seems like a one liner to me. >> What if you are composing >> three or four functions, each of which is conditional on the data? ?If >> you extract things from a statement and assign them somewhat arbitrary >> names, you've just traded horizontal bloat for vertical bloat (with a >> net increase in volume), while forcing a reader to scan back and forth >> to different statements to understand what is happening. > > First off, vertical bloat is easier to cope with than horizontal bloat, > at least for people used to reading left-to-right rather than vertically. > There are few anti-patterns worse that horizontal scrolling, especially > for text. I agree that if a line goes into horizontal scroll buffer, you have a problem. Of course, I often rail on parenthesized function-taking-arguments expression structure for the fact that it forces you to read inside out and right to left, and I'd prefer not to conflate the two issues here. My assertion is that given an expression structure that reads naturally regardless, horizontal bloat is better than larger vertical bloat, in particular when the vertical bloat does not fall along clean semantic boundaries. > Secondly, the human brain can only deal with a limited number of tokens > at any one time. It's easier to remember large numbers when they are > broken up into chunks: > > 824-791-259-401 versus 824791259401 > > (three tokens, versus twelve) > > Likewise for reading code. Chunking code into multiple lines instead of > one long expression, and temporary variables, make things easier to > understand, not harder. This is true, when the tokens are an abstraction. I read some of the research on chunking, basically it came down to people being able to remember multiple numbers efficiently in an auditory fashion using phonemes. Words versus random letter combinations have the same effect, only with visual images (which is why I think Paul Graham is full of shit with regards to his "shorter is better than descriptive" mantra in old essays). This doesn't really apply if storing the elements in batches doesn't provide a more efficient representation. Of course, if you can get your statements to read like sensible English sentences, there is definitely a reduction in cognitive load. > And thirdly, you're not "forcing" the reader to scan back and forth -- or > at least if you are, then you've chosen your functions badly. Functions > should have descriptive names and should perform a meaningful task, not > just an arbitrary collection of code. This is why I quoted Einstein. I support breaking compound logical statements down to simple statements, then combining those simple statements. The problem arises when your compound statement still looks like "A B C D E F G H I J K L M N", and portions of that compound statement don't have a lot of meaning outside the larger statement. You could say X = A B C D E, Y = F G H I J, Z = K L M N, then say X Y Z, but now you've created bloat and forced the reader to backtrack. > > When you read: > > x = range(3, len(sequence), 5) > > you're not forced to scan back and forth between that line and the code > for range and len to understand it, because range and len are good > abstractions that make sensible functions. > > There is a lot of badly written code in existence. Don't blame poor > execution of design principles on the design principle itself. I like to be fair and even handed, and I recognize that tool and language creators don't control users. At the same time, it is a fundamental truth that people are much more inclined to laziness and ignorance than their complements. Any exceptional design will recognize this and make doing the right thing the intuitive, expedient choice. From this perspective I feel morally obligated to lay some blame at the feet of language or tool creator when a person misuses their creation in a way easily predicted given his or her nature. > [...] >> Also, because of Sphinx, it is very common in the Python community weave >> documents and code together in a way that is convenient for authors but >> irritating for readers. > > I don't know about "very common". I suspect, given the general paucity of > documentation in the average software package, it is more like "very > rare, but memorable when it does happen". Well, as a textbook example, the Pocoo projects tend to this. FormAlchemy is another offender. This is just off the top of my head. >> I personally would prefer not to have to scroll >> past 100 lines of a tutorial with examples, tests and what not in order >> to go from one function to another. > > Agreed. Docstrings should use a minimal number of examples and tests. > Tutorials and extensive tests should be extracted into external documents. I don't even mind having tutorials and doctests in the same file, I just don't like them to be interleaved. I really like module level docstrings, and class docstrings are sometimes useful; it is function docstrings that I usually find irritating. From showell30 at yahoo.com Wed Mar 21 00:58:14 2012 From: showell30 at yahoo.com (Steve Howell) Date: Tue, 20 Mar 2012 21:58:14 -0700 (PDT) Subject: Python is readable References: <4f612b19$0$1379$4fafbaef@reader2.news.tin.it> <8e72d74f-c844-4de3-8a37-f6b1fdc2291f@y27g2000yqy.googlegroups.com> <50e9ceec-40f1-4ead-b2b6-87328b30d084@ow8g2000pbc.googlegroups.com> <4f691f3d$0$29981$c3e8da3$5496439d@news.astraweb.com> <87d386lmai.fsf@benfinney.id.au> <8a77bf8d-b12f-442b-a1a3-479b5d66d366@tx8g2000pbc.googlegroups.com> Message-ID: On Mar 20, 9:16?pm, Chris Angelico wrote: > On Wed, Mar 21, 2012 at 1:44 PM, Steve Howell wrote: > > I think it's a matter of perspective, so there's no right answer, but > > I always think of the program object as also being the grammatical > > object, with the implied subject/actor being Python itself. ?For > > example, consider this code: > > > ?stack.push(item) > > > It's not the stack that's pushing. ?It's the stack being pushed on > > to. > > In code, though, the push() method is defined in and on the stack > object (or more likely, on the class that instantiated it, but near > enough). [...] The interpretation that the "subject" is the Stack class itself leads to this coding style: Stack.push(stack, item) The above code takes duck-typing to an extreme--you don't have to assume that "stack" was instantiated from "Stack" in order to apply "Stack.push" to "stack" (where "Stack" acts a the subject and "stack" acts as a grammatical direct object). Of course, 99% of the time, we want some sugar that makes Stack be the implicit subject (given that "stack" was instantiated from "Stack"): stack.push(item) # push comes from Stack via stack > Yes, the implied subject could be the > language interpreter; but it could just as easily be the CPU, or those > friendly nanobots, or that guy moving the rocks in XKCD 505. But in > the abstraction of the line of code, you don't care how CPython goes > about loading globals, calling bound methods, and incrementing object > reference counts - you just care that the stack is pushing this item > onto itself. Sure, that's all good, but, colloquially, I bet you've probably said at one time in your life, "And, here, we are pushing the item on to the stack." The subject is vague ("we"), but there is no assumption of friendly nanobots (or vigorous hamsters, or CPUs, or any specific mechanisms), just the idea that the stack is the object, not the subject. > Some method names are definitely written as though their primary > argument is the object, not the subject. Either option works. Do you > think about code as the subject+verb and a data structure as the > object, or the object as the subject and the method as the verb? > Fundamentally no difference. At a certain fundamental level, sure, of course it's all just data structure and code, so we shouldn't be quibbling about syntax or grammar, and we certainly shouldn't be throwing around strained analogies to natural languages. But in this context, we are musing about grammar, so I would propose this question: What's more important, the object or the method? IMHO the method is usually more interesting than the object itself. Of course, the "stack" itself is important, but on any given line of code, the action is more interesting, so I'd want to lead with "push" or "pop." Verb-first gets a bad rap, because people tend to associate verb-first syntax with early, primitive imperative/functional languages that had no OO syntax. Assembly tends to be very imperative: MOV AX, BX So saying "push(stack, item)" or "push(item, stack)" seems very unsophisticated, almost assembly-like in syntax, albeit at a higher level conceptually than assembly. From rosuav at gmail.com Wed Mar 21 01:40:18 2012 From: rosuav at gmail.com (Chris Angelico) Date: Wed, 21 Mar 2012 16:40:18 +1100 Subject: Python is readable In-Reply-To: References: <4f612b19$0$1379$4fafbaef@reader2.news.tin.it> <8e72d74f-c844-4de3-8a37-f6b1fdc2291f@y27g2000yqy.googlegroups.com> <50e9ceec-40f1-4ead-b2b6-87328b30d084@ow8g2000pbc.googlegroups.com> <4f691f3d$0$29981$c3e8da3$5496439d@news.astraweb.com> <87d386lmai.fsf@benfinney.id.au> <8a77bf8d-b12f-442b-a1a3-479b5d66d366@tx8g2000pbc.googlegroups.com> Message-ID: On Wed, Mar 21, 2012 at 3:58 PM, Steve Howell wrote: > So saying "push(stack, item)" or "push(item, stack)" seems very > unsophisticated, almost assembly-like in syntax, albeit at a higher > level conceptually than assembly. Perhaps it does, but "push(stack, item)" and "stack.push(item)" are so close to identical as makes no odds (in a number of languages, the latter is just syntactic sugar for something like the former) - yet they "read" quite differently, one with verb first, one with noun first. Code doesn't follow the same grammar as English prose, and forcing it to usually makes it sound odd. Reader.can_comprehend(code) is True. ChrisA From showell30 at yahoo.com Wed Mar 21 02:52:47 2012 From: showell30 at yahoo.com (Steve Howell) Date: Tue, 20 Mar 2012 23:52:47 -0700 (PDT) Subject: Python is readable References: <4f612b19$0$1379$4fafbaef@reader2.news.tin.it> <50e9ceec-40f1-4ead-b2b6-87328b30d084@ow8g2000pbc.googlegroups.com> <4f691f3d$0$29981$c3e8da3$5496439d@news.astraweb.com> <87d386lmai.fsf@benfinney.id.au> <8a77bf8d-b12f-442b-a1a3-479b5d66d366@tx8g2000pbc.googlegroups.com> Message-ID: <6af70db0-dc4a-48ee-9ee2-1a934846d5f2@r2g2000pbs.googlegroups.com> On Mar 20, 10:40?pm, Chris Angelico wrote: > On Wed, Mar 21, 2012 at 3:58 PM, Steve Howell wrote: > > So saying "push(stack, item)" or "push(item, stack)" seems very > > unsophisticated, almost assembly-like in syntax, albeit at a higher > > level conceptually than assembly. > > Perhaps it does, but "push(stack, item)" and "stack.push(item)" are so > close to identical as makes no odds (in a number of languages, the > latter is just syntactic sugar for something like the former) - yet > they "read" quite differently, one with verb first, one with noun > first. > On the one hand, you say that "push(stack, item)" reads quite differently from "stack.push(item)". On the other hand, you say they are "so close to identical as makes no odds." I'm trying to make sense of that. Are you saying that the way the two idioms read makes no odds, despite reading quite differently? > Code doesn't follow the same grammar as English prose, and forcing it > to usually makes it sound odd. Reader.can_comprehend(code) is True. > Code shouldn't necessarily follow the example of English prose, but it seems that English has had some influence: 1 push(stack, item) # Push on the stack the item 2 push(item, stack) # Push the item on the stack 3 stack.push(item) # On the stack, push the item 4 stack item push # On the stack, take the item and push it 5 item stack push # Take the item and on the stack, push the former. 6 item push stack # Take the item; push it on the stack. The first three ways are the most common ways of arranging the grammar in mainstream programming languages, and they are also the three most natural ways in English (no pronouns required). #1/2 are imperative. #3 is OO. #4 and #5 are sort of Forth-like, maybe? #6 is just downright strange. From rosuav at gmail.com Wed Mar 21 02:59:23 2012 From: rosuav at gmail.com (Chris Angelico) Date: Wed, 21 Mar 2012 17:59:23 +1100 Subject: Python is readable In-Reply-To: <6af70db0-dc4a-48ee-9ee2-1a934846d5f2@r2g2000pbs.googlegroups.com> References: <4f612b19$0$1379$4fafbaef@reader2.news.tin.it> <50e9ceec-40f1-4ead-b2b6-87328b30d084@ow8g2000pbc.googlegroups.com> <4f691f3d$0$29981$c3e8da3$5496439d@news.astraweb.com> <87d386lmai.fsf@benfinney.id.au> <8a77bf8d-b12f-442b-a1a3-479b5d66d366@tx8g2000pbc.googlegroups.com> <6af70db0-dc4a-48ee-9ee2-1a934846d5f2@r2g2000pbs.googlegroups.com> Message-ID: On Wed, Mar 21, 2012 at 5:52 PM, Steve Howell wrote: > On the one hand, you say that "push(stack, item)" reads quite > differently from "stack.push(item)". > > On the other hand, you say they are "so close to identical as makes no > odds." > > I'm trying to make sense of that. ?Are you saying that the way the two > idioms read makes no odds, despite reading quite differently? If you're designing a language (or, often, a library/module), you can choose either option without greatly annoying your users. As a programmer, I use both types of API all the time. Yes, they read differently, but neither is confusing, and you can easily grok that they do the same thing. ChrisA From clp2 at rebertia.com Wed Mar 21 03:16:49 2012 From: clp2 at rebertia.com (Chris Rebert) Date: Wed, 21 Mar 2012 00:16:49 -0700 Subject: Python is readable In-Reply-To: <6af70db0-dc4a-48ee-9ee2-1a934846d5f2@r2g2000pbs.googlegroups.com> References: <4f612b19$0$1379$4fafbaef@reader2.news.tin.it> <50e9ceec-40f1-4ead-b2b6-87328b30d084@ow8g2000pbc.googlegroups.com> <4f691f3d$0$29981$c3e8da3$5496439d@news.astraweb.com> <87d386lmai.fsf@benfinney.id.au> <8a77bf8d-b12f-442b-a1a3-479b5d66d366@tx8g2000pbc.googlegroups.com> <6af70db0-dc4a-48ee-9ee2-1a934846d5f2@r2g2000pbs.googlegroups.com> Message-ID: On Tue, Mar 20, 2012 at 11:52 PM, Steve Howell wrote: > On Mar 20, 10:40?pm, Chris Angelico wrote: >> On Wed, Mar 21, 2012 at 3:58 PM, Steve Howell wrote: >> > So saying "push(stack, item)" or "push(item, stack)" seems very >> > unsophisticated, almost assembly-like in syntax, albeit at a higher >> > level conceptually than assembly. >> >> Perhaps it does, but "push(stack, item)" and "stack.push(item)" are so >> close to identical as makes no odds (in a number of languages, the >> latter is just syntactic sugar for something like the former) - yet >> they "read" quite differently, one with verb first, one with noun >> first. > > On the one hand, you say that "push(stack, item)" reads quite > differently from "stack.push(item)". > > On the other hand, you say they are "so close to identical as makes no > odds." > > I'm trying to make sense of that. ?Are you saying that the way the two > idioms read makes no odds, despite reading quite differently? > >> Code doesn't follow the same grammar as English prose, and forcing it >> to usually makes it sound odd. Reader.can_comprehend(code) is True. > > Code shouldn't necessarily follow the example of English prose, but it > seems that English has had some influence: > > ?1 ?push(stack, item) # Push on the stack the item > ?2 ?push(item, stack) # Push the item on the stack > 3 stack.push(item) # On the stack, push the item > ?6 ?item push stack ? # Take the item; push it on the stack. > #4 and #5 are sort of Forth-like, maybe? ?#6 is just downright > strange. #6 is just an infix binary operator (likewise with its cousin #3, just remove the punctuation). If you change the name slightly, it becomes more sensical. One could easily write in Haskell: item `pushOnto` stack which would just be syntactic sugar for #2. Not that I endorse #6, merely saying it's less weird than you think. Cheers, Chris From chardster at gmail.com Wed Mar 21 03:42:19 2012 From: chardster at gmail.com (Richard Thomas) Date: Wed, 21 Mar 2012 00:42:19 -0700 (PDT) Subject: setup.py for an extension In-Reply-To: References: Message-ID: <13339221.934.1332315740021.JavaMail.geo-discussion-forums@ynim7> Assuming you have: lib/__init__.py lib/foo.py lib/foo.c Then: from distutils.core import setup, Extension setup(name="lib", packages=["lib"], ext_modules=[Extension("lib._foo", ["lib/foo.c"])]) From showell30 at yahoo.com Wed Mar 21 03:57:36 2012 From: showell30 at yahoo.com (Steve Howell) Date: Wed, 21 Mar 2012 00:57:36 -0700 (PDT) Subject: Python is readable References: <4f612b19$0$1379$4fafbaef@reader2.news.tin.it> <4f691f3d$0$29981$c3e8da3$5496439d@news.astraweb.com> <87d386lmai.fsf@benfinney.id.au> <8a77bf8d-b12f-442b-a1a3-479b5d66d366@tx8g2000pbc.googlegroups.com> <6af70db0-dc4a-48ee-9ee2-1a934846d5f2@r2g2000pbs.googlegroups.com> Message-ID: <6a4c821e-3672-401a-9a35-e0950734c22f@ms3g2000pbb.googlegroups.com> On Mar 21, 12:16?am, Chris Rebert wrote: > On Tue, Mar 20, 2012 at 11:52 PM, Steve Howell wrote: > > On Mar 20, 10:40?pm, Chris Angelico wrote: > >> On Wed, Mar 21, 2012 at 3:58 PM, Steve Howell wrote: > >> > So saying "push(stack, item)" or "push(item, stack)" seems very > >> > unsophisticated, almost assembly-like in syntax, albeit at a higher > >> > level conceptually than assembly. > > >> Perhaps it does, but "push(stack, item)" and "stack.push(item)" are so > >> close to identical as makes no odds (in a number of languages, the > >> latter is just syntactic sugar for something like the former) - yet > >> they "read" quite differently, one with verb first, one with noun > >> first. > > > On the one hand, you say that "push(stack, item)" reads quite > > differently from "stack.push(item)". > > > On the other hand, you say they are "so close to identical as makes no > > odds." > > > I'm trying to make sense of that. ?Are you saying that the way the two > > idioms read makes no odds, despite reading quite differently? > > >> Code doesn't follow the same grammar as English prose, and forcing it > >> to usually makes it sound odd. Reader.can_comprehend(code) is True. > > > Code shouldn't necessarily follow the example of English prose, but it > > seems that English has had some influence: > > > ?1 ?push(stack, item) # Push on the stack the item > > ?2 ?push(item, stack) # Push the item on the stack > > ?3 ?stack.push(item) ?# On the stack, push the item > > > ?6 ?item push stack ? # Take the item; push it on the stack. > > > #4 and #5 are sort of Forth-like, maybe? ?#6 is just downright > > strange. > > #6 is just an infix binary operator (likewise with its cousin #3, just > remove the punctuation). If you change the name slightly, it becomes > more sensical. One could easily write in Haskell: > ? ? item `pushOnto` stack > which would just be syntactic sugar for #2. Not that I endorse #6, > merely saying it's less weird than you think. > Ha, you're right, verb-in-the-middle is just infix. So, if you don't care about the order of the nouns, you have three forms: verb first: English-imperative ("boil water", "add noodles/salt", "serve in dish") or math-functional, e.g. sum(a,b,c) verb middle: infix, arithmetic-like ("5 plus 4", "10 divided by 2") or English-descriptive ("Dog bites man") verb last: Forth-like, maps well to simple underlying implementation I guess the OO syntax is really verb-first when you think of "stack.push" as the verb. From rosuav at gmail.com Wed Mar 21 04:15:22 2012 From: rosuav at gmail.com (Chris Angelico) Date: Wed, 21 Mar 2012 19:15:22 +1100 Subject: Python is readable In-Reply-To: <6a4c821e-3672-401a-9a35-e0950734c22f@ms3g2000pbb.googlegroups.com> References: <4f612b19$0$1379$4fafbaef@reader2.news.tin.it> <4f691f3d$0$29981$c3e8da3$5496439d@news.astraweb.com> <87d386lmai.fsf@benfinney.id.au> <8a77bf8d-b12f-442b-a1a3-479b5d66d366@tx8g2000pbc.googlegroups.com> <6af70db0-dc4a-48ee-9ee2-1a934846d5f2@r2g2000pbs.googlegroups.com> <6a4c821e-3672-401a-9a35-e0950734c22f@ms3g2000pbb.googlegroups.com> Message-ID: On Wed, Mar 21, 2012 at 6:57 PM, Steve Howell wrote: > ?verb first: English-imperative ("boil water", "add noodles/salt", > "serve in dish") or math-functional, e.g. sum(a,b,c) > ?verb middle: infix, arithmetic-like ("5 plus 4", "10 divided by 2") > or English-descriptive ("Dog bites man") In English, verb-first imperative is just verb-middle descriptive with an implied "You" as the subject. Its nearest equivalent in code, then, is the common idiom of omitting the 'this' argument (eg in C++), which Python doesn't support. ChrisA From deets at web.de Wed Mar 21 07:38:03 2012 From: deets at web.de (Diez B. Roggisch) Date: Wed, 21 Mar 2012 12:38:03 +0100 Subject: pypi and dependencies References: Message-ID: Andrea Crotti writes: > When I publish something on Pypi, is there a way to make it fetch the > list of dependencies needed by my project automatically? > > It would be nice to have it in the Pypi page, without having to look > at the actual code.. > Any other possible solution? I don't understand this - if you declare the dependencies of your published package in the requires-section of the setup()-call, easy_install (and I guess pip as well, no experience with it) will automatically fetch these. Is that what you wanted to know? Diez From deets at web.de Wed Mar 21 07:40:56 2012 From: deets at web.de (Diez B. Roggisch) Date: Wed, 21 Mar 2012 12:40:56 +0100 Subject: configobj validation References: <4F672DBF.5060506@gmail.com> Message-ID: Andrea Crotti writes: > On 03/19/2012 12:59 PM, Andrea Crotti wrote: >> I seemed to remember that type validation and type conversion worked >> out of the box, but now >> I can't get it working anymore. >> >> Shouldn't this simple example actually fail the parsing (instead it >> parses perfectly port to a string)? >> >> sample.py: >> from configobj import ConfigObj >> >> conf = ConfigObj('sample.conf', configspec='sample.spec') >> >> sample.conf: >> port = some_string >> >> sample.spec: >> port = integer(0, 10) >> >> PS. using configobj 4.7.2 > > I now checked the repo and configobj seems also quite dead (2 years > ago last version), it's a pity because it's a really nice library. > Any other alternatives for validation/configuration systems otherwise? It works - so why do you bother? And I'm not sure about the above code - AFAIK, validation is a two-step thing: http://www.voidspace.org.uk/python/articles/configobj.shtml#validation Diez From gandalf at shopzeus.com Wed Mar 21 08:38:10 2012 From: gandalf at shopzeus.com (Laszlo Nagy) Date: Wed, 21 Mar 2012 13:38:10 +0100 Subject: urllib.urlretrieve never returns??? In-Reply-To: <5B80DD153D7D744689F57F4FB69AF474026C4C97@SCACMX008.exchad.jpmchase.net> References: <4F649BFC.1080601@shopzeus.com> <4F66E687.2050008@shopzeus.com> <4f67c09b$0$29981$c3e8da3$5496439d@news.astraweb.com> <4F682CDC.5000703@shopzeus.com> <4F68E49C.2060000@shopzeus.com> <5B80DD153D7D744689F57F4FB69AF474026C4BD8@SCACMX008.exchad.jpmchase.net> <5B80DD153D7D744689F57F4FB69AF474026C4C97@SCACMX008.exchad.jpmchase.net> Message-ID: <4F69CBB2.6060801@shopzeus.com> On 2012-03-20 22:26, Prasad, Ramit wrote: > I just looked at your source file on ActiveState and noticed that > you do not import traceback. That is why you are getting the > AttributeError. Now you should be getting a much better error > once you import it:) Nope. That would result in a NameError. After adding "import traceback", I still get several AttributeError messages. The traceback should contain the exact line number, and a description about what object is missing what attribute anyway. My code is pure Python, and under no circumstances should it be able to start a blocked call for a system library function. From andrea.crotti.0 at gmail.com Wed Mar 21 09:03:44 2012 From: andrea.crotti.0 at gmail.com (Andrea Crotti) Date: Wed, 21 Mar 2012 13:03:44 +0000 Subject: pypi and dependencies In-Reply-To: References: Message-ID: <4F69D1B0.9030102@gmail.com> On 03/21/2012 11:38 AM, Diez B. Roggisch wrote: > Andrea Crotti writes: > >> When I publish something on Pypi, is there a way to make it fetch the >> list of dependencies needed by my project automatically? >> >> It would be nice to have it in the Pypi page, without having to look >> at the actual code.. >> Any other possible solution? > I don't understand this - if you declare the dependencies of your > published package in the requires-section of the setup()-call, > easy_install (and I guess pip as well, no experience with it) will > automatically fetch these. > > Is that what you wanted to know? > > Diez It would be nice to know the dependencies *before* you actually try to install it ;) From andrea.crotti.0 at gmail.com Wed Mar 21 09:06:06 2012 From: andrea.crotti.0 at gmail.com (Andrea Crotti) Date: Wed, 21 Mar 2012 13:06:06 +0000 Subject: configobj validation In-Reply-To: References: <4F672DBF.5060506@gmail.com> Message-ID: <4F69D23E.8020905@gmail.com> On 03/21/2012 11:40 AM, Diez B. Roggisch wrote: > Andrea Crotti writes: > > It works - so why do you bother? And I'm not sure about the above code - > AFAIK, validation is a two-step thing: > > http://www.voidspace.org.uk/python/articles/configobj.shtml#validation > > Diez I don't agree, if you write code that is supposed to work with Python3, using a library which is not developed and will probably never support Python3 is quite a stupid idea ;) Any other validation mechanism that can be plugged in ConfigParser for example? From what I've understood from the doc and what I remembered I thought that validation is automatically done when passing the configspec, but I'll check if the two steps work.. From jcd at sdf.lonestar.org Wed Mar 21 09:50:54 2012 From: jcd at sdf.lonestar.org (J. Cliff Dyer) Date: Wed, 21 Mar 2012 09:50:54 -0400 Subject: List comprehension/genexp inconsistency. In-Reply-To: References: <1332275002.10958.7.camel@jcdyer-laptop> Message-ID: <1332337854.2737.4.camel@jcdyer-laptop> Thanks, Ian. That does seem to explain it. The inner loop doesn't have access to the class's name space, and of course you can't fix it by referencing Foo.y explicitly, because the class isn't fully defined yet. Ultimately, we realized that the dict should be created in the __init__ method, so that it gets the appropriate values of the foo and bar attributes if the class is subclassed, which obviates the problem, but it's a fascinating peek into python internals. It looks like this is explained in the section of the pep entitled "Early Binding versus Late Binding" http://www.python.org/dev/peps/pep-0289/#early-binding-versus-late-binding Cheers, Cliff On Tue, 2012-03-20 at 16:50 -0600, Ian Kelly wrote: > On Tue, Mar 20, 2012 at 3:16 PM, Dennis Lee Bieber > wrote: > > On Tue, 20 Mar 2012 16:23:22 -0400, "J. Cliff Dyer" > > declaimed the following in > > gmane.comp.python.general: > > > >> > >> When trying to create a class with a dual-loop generator expression in a > >> class definition, there is a strange scoping issue where the inner > >> variable is not found, (but the outer loop variable is found), while a > >> list comprehension has no problem finding both variables. > >> > > Read http://www.python.org/dev/peps/pep-0289/ -- in particular, look > > for the word "leak" > > No, this has nothing to do with the loop variable leaking. It appears > to have to do with the fact that the variables and the generator > expression are inside a class block. I think that it's related to the > reason that this doesn't work: > > class Foo(object): > x = 42 > def foo(): > print(x) > foo() > > In this case, x is not a local variable of foo, nor is it a global. > In order for foo to access x, it would have to be a closure -- but > Python can't make it a closure in this case, because the variable it > accesses is (or rather, will become) a class attribute, not a local > variable of a function that can be stored in a cell. Instead, the > compiler just makes it a global reference in the hope that such a > global will actually be defined when the code is run. > > For that reason, what surprises me about Cliff's example is that a > generator expression works at all in that context. It seems to work > as long as it contains only one loop, but not if it contains two. To > find out why, I tried disassembling one: > > >>> class Foo(object): > ... x = 42 > ... y = 12 > ... g = (a+b for a in range(x) for b in range(y)) > ... > >>> dis.dis(Foo.g.gi_code) > 4 0 LOAD_FAST 0 (.0) > >> 3 FOR_ITER 34 (to 40) > 6 STORE_FAST 1 (a) > 9 LOAD_GLOBAL 0 (range) > 12 LOAD_GLOBAL 1 (y) > 15 CALL_FUNCTION 1 > 18 GET_ITER > >> 19 FOR_ITER 15 (to 37) > 22 STORE_FAST 2 (b) > 25 LOAD_FAST 1 (a) > 28 LOAD_FAST 2 (b) > 31 BINARY_ADD > 32 YIELD_VALUE > 33 POP_TOP > 34 JUMP_ABSOLUTE 19 > >> 37 JUMP_ABSOLUTE 3 > >> 40 LOAD_CONST 0 (None) > 43 RETURN_VALUE > > So that explains it. Notice that "x" is never actually accessed in > that disassembly; only "y" is. It turns out that the first iterator > [range(x)] is actually created before the generator ever starts > executing, and is stored as an anonymous local variable on the > generator's stack frame -- so it's created in the class scope, not in > the generator scope. The second iterator, however, is recreated on > every iteration of the first iterator, so it can't be pre-built in > that manner. It does get created in the generator scope, and when > that happens it blows up because it can't find the variable, just like > the function example above. > > Cheers, > Ian From ralph.heinkel at web.de Wed Mar 21 11:06:47 2012 From: ralph.heinkel at web.de (Ralph Heinkel) Date: Wed, 21 Mar 2012 08:06:47 -0700 (PDT) Subject: Compiling Python (modules) on 64bit Windows - which compiler suite? Message-ID: <808abad4-3ab3-4336-8a31-2f88eb28be01@v22g2000vby.googlegroups.com> Hi, when processing our mass spectrometry data we are running against the 2GB memory limit on our 32 bit machines. So we are planning to move to 64bit. Downloading and installing the 64bit version of Python for Windows is trivial, but how do we compile our own C extension? Visual C ++ 2008 express comes for free, but only compiles for 32 bit. What has been used to compile the downloadable Python Win64 bit version? Visual Studio professional? The problem with the professional edition is that it is hard to obtain and it is sort of out-of-date - nowadays everyone uses Visual Studio 2010 (or even 2011 coming soon). So if Visual Studio 2008 professional is required for compiling 64bit modules, we would have to spend $1200 for a license which is actually rather out of date. Any hints or suggestions are very welcome. Thanks, Ralph From esyrkina at gmail.com Wed Mar 21 11:15:52 2012 From: esyrkina at gmail.com (Katya) Date: Wed, 21 Mar 2012 08:15:52 -0700 (PDT) Subject: ReportLab alternative for Python3 Message-ID: <24078051.142.1332342952564.JavaMail.geo-discussion-forums@vbat19> I have a Python3 GUI, where user selects certain values to be statistically evaluated and/or plotted (matplotlib hist). Out of this GUI on user's request I want to create a report, prefferebly in DOC or/and ODT or/and PDF or/and HTML formats. The layout of the report is pretty much fixed, what will change is: the names of the selected measures and the corresponding values (there are always three measures to display - user selects which), matplotlib histogram (only image will change depending on the selected settings, but not its size/location), user name, date etc. ReportLab which seems to be suitable is not ready for Python3. I also found a reference to pod package (http://appyframework.org/pod.html) which looks very close to my needs. But pod does NOT support Python3, also after 2to3 convertion and couple of small fixes. Any suggestions are greatly appreciated since the rest of the project is nearly done and this is the last big unsolved problem! Thanks, Katya From rodperson at rodperson.com Wed Mar 21 11:25:03 2012 From: rodperson at rodperson.com (Rod Person) Date: Wed, 21 Mar 2012 11:25:03 -0400 Subject: class checking its own module for an attribute Message-ID: <20120321112503.00006eb5@unknown> We have a module called constants.py, which contains related to server names, databases, service account users and there passwords. In order to be able to use constants as command line parameters for calling from our batch files I created the class below that checks to make sure the parameter value is a valid constant and if so return it's value. class ConstantParameterCheck(Action): def __call__(self, parser, namespace, value, option_string=None): if value: if not hasattr(CCBH.constants, value): message = ("Invalid parameter value: {0!r}. Value must be a value constant in CCBH.constants.".format(value)) raise ArgumentError(self, message) setattr(namespace, self.dest, getattr(CCBH.constants, value)) This works great, but it has to be placed in every script, so I decided why not place this in the constants.py module so it can just be imported. So I did that and got it to work like this: class ConstantParameterCheck(Action): def __call__(self, parser, namespace, value, option_string=None): from CCBH import constants if value: if not hasattr(constants, value): message = ("Invalid parameter value: {0!r}. Value must be a value constant in CCBH.constants.".format(value)) raise ArgumentError(self, message) setattr(namespace, self.dest, getattr(CCBH.constants, value)) The question is there a way I can do this with out having to import constants when what it's doing is importing itself. It would seem to me that there should be a way for a module to reference itself. In that thinking I have tried if not(hasattr(__file__, value): if not(hasattr(__name__, value): and even: this = sys.argv[0] if not(hasattr(this, value): None of which works. -- Rod Person http://www.rodperson.com rodperson at rodperson.com 'Silence is a fence around wisdom' From driscoll at cs.wisc.edu Wed Mar 21 12:22:01 2012 From: driscoll at cs.wisc.edu (Evan Driscoll) Date: Wed, 21 Mar 2012 11:22:01 -0500 Subject: Python is readable In-Reply-To: <6af70db0-dc4a-48ee-9ee2-1a934846d5f2@r2g2000pbs.googlegroups.com> References: <4f612b19$0$1379$4fafbaef@reader2.news.tin.it> <50e9ceec-40f1-4ead-b2b6-87328b30d084@ow8g2000pbc.googlegroups.com> <4f691f3d$0$29981$c3e8da3$5496439d@news.astraweb.com> <87d386lmai.fsf@benfinney.id.au> <8a77bf8d-b12f-442b-a1a3-479b5d66d366@tx8g2000pbc.googlegroups.com> <6af70db0-dc4a-48ee-9ee2-1a934846d5f2@r2g2000pbs.googlegroups.com> Message-ID: <4F6A0029.6090702@cs.wisc.edu> On 01/-10/-28163 01:59 PM, Steve Howell wrote: > Code shouldn't necessarily follow the example of English prose, but it > seems that English has had some influence: > > 1 push(stack, item) # Push on the stack the item > 2 push(item, stack) # Push the item on the stack > 3 stack.push(item) # On the stack, push the item > 4 stack item push # On the stack, take the item and push it > 5 item stack push # Take the item and on the stack, push the > former. > 6 item push stack # Take the item; push it on the stack. > > The first three ways are the most common ways of arranging the grammar > in mainstream programming languages, and they are also the three most > natural ways in English (no pronouns required). > > #1/2 are imperative. #3 is OO. In my opinion, people who make statements such as "#1/2 are imperative, #3 is OO" are missing pretty much the entire point of what OO is. OO is much more about semantics and the way code is structured. The difference between #1/2 (especially #1, of course) and #3 is surface-level syntax only. About the strongest statement you can make along those lines is that #3 will allow you to do dynamic dispatch on the type of 'stack' while #1/2 won't, but even that isn't true of course. For instance, CLOS will let you write '(push stack item)' (which is the direct analogy in that language to #1) and do even more powerful dynamic dispatch than what a language like C++, Java, or Python will let you do. Evan From showell30 at yahoo.com Wed Mar 21 12:30:07 2012 From: showell30 at yahoo.com (Steve Howell) Date: Wed, 21 Mar 2012 09:30:07 -0700 (PDT) Subject: Python is readable References: <4f612b19$0$1379$4fafbaef@reader2.news.tin.it> <4f691f3d$0$29981$c3e8da3$5496439d@news.astraweb.com> <87d386lmai.fsf@benfinney.id.au> <8a77bf8d-b12f-442b-a1a3-479b5d66d366@tx8g2000pbc.googlegroups.com> <6af70db0-dc4a-48ee-9ee2-1a934846d5f2@r2g2000pbs.googlegroups.com> Message-ID: On Mar 21, 9:22?am, Evan Driscoll wrote: > On 01/-10/-28163 01:59 PM, Steve Howell wrote: > > > > > > > > > > > Code shouldn't necessarily follow the example of English prose, but it > > seems that English has had some influence: > > > ? 1 ?push(stack, item) # Push on the stack the item > > ? 2 ?push(item, stack) # Push the item on the stack > > ? 3 ?stack.push(item) ?# On the stack, push the item > > ? 4 ?stack item push ? # On the stack, take the item and push it > > ? 5 ?item stack push ? # Take the item and on the stack, push the > > former. > > ? 6 ?item push stack ? # Take the item; push it on the stack. > > > The first three ways are the most common ways of arranging the grammar > > in mainstream programming languages, and they are also the three most > > natural ways in English (no pronouns required). > > > #1/2 are imperative. ?#3 is OO. > > In my opinion, people who make statements such as "#1/2 are imperative, > #3 is OO" are missing pretty much the entire point of what OO is. > > OO is much more about semantics and the way code is structured. The > difference between #1/2 (especially #1, of course) and #3 is > surface-level syntax only. > > About the strongest statement you can make along those lines is that #3 > will allow you to do dynamic dispatch on the type of 'stack' while #1/2 > won't, but even that isn't true of course. For instance, CLOS will let > you write '(push stack item)' (which is the direct analogy in that > language to #1) and do even more powerful dynamic dispatch than what a > language like C++, Java, or Python will let you do. > In the grand scheme of things, of course code structure and semantics are more important the surface-level syntax. If you take it as a given that structure/semantics are sound (big assumption, I know), then the next issue with regards to "readability" is the syntax itself. From stefan_ml at behnel.de Wed Mar 21 12:32:33 2012 From: stefan_ml at behnel.de (Stefan Behnel) Date: Wed, 21 Mar 2012 17:32:33 +0100 Subject: Fast file data retrieval? In-Reply-To: References: <4F5E50F6.9070309@it.uu.se> Message-ID: Jorgen Grahn, 13.03.2012 21:44: > On Mon, 2012-03-12, MRAB wrote: >> Probably the best solution is to put it into a database. Have a look at >> the sqlite3 module. > > Some people like to use databases for everything, others never use > them. I'm in the latter crowd, so to me this sounds as overkill Well, there's databases and databases. I agree that the complexity of a SQL database is likely unnecessary here since a key-value database (any of the dbm modules) appears to be sufficient from what the OP wrote. Stefan From clp2 at rebertia.com Wed Mar 21 12:56:57 2012 From: clp2 at rebertia.com (Chris Rebert) Date: Wed, 21 Mar 2012 09:56:57 -0700 Subject: class checking its own module for an attribute In-Reply-To: <20120321112503.00006eb5@unknown> References: <20120321112503.00006eb5@unknown> Message-ID: On Wed, Mar 21, 2012 at 8:25 AM, Rod Person wrote: > The question is there a way I can do this with out having to import > constants when what it's doing is importing itself. It would seem to me > that there should be a way for a module to reference itself. In that > thinking I have tried > > ?if not(hasattr(__file__, value): > ?if not(hasattr(__name__, value): > > and even: > > ?this = sys.argv[0] > ?if not(hasattr(this, value): > > None of which works. http://stackoverflow.com/questions/2933470/how-do-i-call-setattr-on-the-current-module Cheers, Chris From __peter__ at web.de Wed Mar 21 12:59:56 2012 From: __peter__ at web.de (Peter Otten) Date: Wed, 21 Mar 2012 17:59:56 +0100 Subject: class checking its own module for an attribute References: <20120321112503.00006eb5@unknown> Message-ID: Rod Person wrote: > We have a module called constants.py, which contains [whatever] related to > server names, databases, service account users and their passwords. Passwords? > In order to be able to use constants as command line parameters for > calling from our batch files I created the class below that checks to > make sure the parameter value is a valid constant and if so return its > value. Instead of > from CCBH import constants ... > if not hasattr(constants, value): ... You can look up the name in the global namespace: if value not in globals(): ... From rodperson at rodperson.com Wed Mar 21 13:06:55 2012 From: rodperson at rodperson.com (Rod Person) Date: Wed, 21 Mar 2012 13:06:55 -0400 Subject: class checking its own module for an attribute In-Reply-To: References: <20120321112503.00006eb5@unknown> Message-ID: <20120321130655.000040a2@unknown> On Wed, 21 Mar 2012 09:56:57 -0700 Chris Rebert wrote: > On Wed, Mar 21, 2012 at 8:25 AM, Rod Person > wrote: > > The question is there a way I can do this with out having to import > > constants when what it's doing is importing itself. It would seem > > to me that there should be a way for a module to reference itself. > > In that thinking I have tried > > > > ?if not(hasattr(__file__, value): > > ?if not(hasattr(__name__, value): > > > > and even: > > > > ?this = sys.argv[0] > > ?if not(hasattr(this, value): > > > > None of which works. > > http://stackoverflow.com/questions/2933470/how-do-i-call-setattr-on-the-current-module > > Cheers, > Chris Thank you! -- Rod Person http://www.rodperson.com rodperson at rodperson.com 'Silence is a fence around wisdom' From rodperson at rodperson.com Wed Mar 21 13:10:41 2012 From: rodperson at rodperson.com (Rod Person) Date: Wed, 21 Mar 2012 13:10:41 -0400 Subject: class checking its own module for an attribute In-Reply-To: References: <20120321112503.00006eb5@unknown> Message-ID: <20120321131041.00001dde@unknown> On Wed, 21 Mar 2012 17:59:56 +0100 Peter Otten <__peter__ at web.de> wrote: > Rod Person wrote: > > > We have a module called constants.py, which contains [whatever] > > related to server names, databases, service account users and their > > passwords. > > Passwords? > Yes, not the best thing, but they are only service account that run nightly batch jobs. Everyone in our IT department knows these password and users. I only deploy the .pyo or .pyc files for this module, although I'm looking into a better way than that. -- Rod Person http://www.rodperson.com rodperson at rodperson.com 'Silence is a fence around wisdom' From tjreedy at udel.edu Wed Mar 21 13:56:20 2012 From: tjreedy at udel.edu (Terry Reedy) Date: Wed, 21 Mar 2012 13:56:20 -0400 Subject: Compiling Python (modules) on 64bit Windows - which compiler suite? In-Reply-To: <808abad4-3ab3-4336-8a31-2f88eb28be01@v22g2000vby.googlegroups.com> References: <808abad4-3ab3-4336-8a31-2f88eb28be01@v22g2000vby.googlegroups.com> Message-ID: On 3/21/2012 11:06 AM, Ralph Heinkel wrote: > when processing our mass spectrometry data we are running against the > 2GB memory limit on our 32 bit machines. So we are planning to move to > 64bit. Downloading and installing the 64bit version of Python for > Windows is trivial, but how do we compile our own C extension? Visual C > ++ 2008 express comes for free, but only compiles for 32 bit. > > What has been used to compile the downloadable Python Win64 bit > version? Visual Studio professional? Yes. Python Windows devs get it for free from MS. > The problem with the professional edition is that it is hard to obtain > and it is sort of out-of-date - nowadays everyone uses Visual Studio > 2010 (or even 2011 coming soon). So if Visual Studio 2008 professional > is required for compiling 64bit modules, we would have to spend $1200 > for a license which is actually rather out of date. > > Any hints or suggestions are very welcome. I believe the intention is to release 3.3 compiled with VS 2010. Brian Curtin and Martin Loewis are working on that. I believe people have successfully built at least the basics with VS2010. You could also dual boot to Linux and get 64 bit gcc for free. -- Terry Jan Reedy From nathan.alexander.rice at gmail.com Wed Mar 21 14:06:50 2012 From: nathan.alexander.rice at gmail.com (Nathan Rice) Date: Wed, 21 Mar 2012 14:06:50 -0400 Subject: Python is readable In-Reply-To: References: <4f612b19$0$1379$4fafbaef@reader2.news.tin.it> <4f691f3d$0$29981$c3e8da3$5496439d@news.astraweb.com> <87d386lmai.fsf@benfinney.id.au> <8a77bf8d-b12f-442b-a1a3-479b5d66d366@tx8g2000pbc.googlegroups.com> <6af70db0-dc4a-48ee-9ee2-1a934846d5f2@r2g2000pbs.googlegroups.com> Message-ID: MOAR TROLLING... >> In my opinion, people who make statements such as "#1/2 are imperative, >> #3 is OO" are missing pretty much the entire point of what OO is. >> >> OO is much more about semantics and the way code is structured. The >> difference between #1/2 (especially #1, of course) and #3 is >> surface-level syntax only. The idea of actions as concrete attributes of entities is probably the worst bit of object oriented programming, except perhaps inheritance. Events occur in the context of multiple entities, but they are conceptually distinct and should not be subordinated. Furthermore, if you have an explicit self or this context, your ability to override elements of an event is limited to things which are directly encapsulated in that context. Additionally, dynamic dispatch induces overhead and the possibility of action at a distance. Reflective template meta-programming and explicit attribute delegation are VASTLY superior. To rant about inheritance, outside of mathematics platonic ideals are bullshit. Natural kinds are the closest we might actually be able to come to ideals, and philosophers still debate whether atomic elements and subatomic particles should have this designation. On the macro scale, classes or types are dynamic, fuzzy unions of structure, context and intent. Making any sort of invariant categorical statement about real things is just begging to be proven wrong. Programmers would be much better off if we made assertions about relationships and structure with an explicit, contextual reference. I think this would simplify code reuse, since you would be able to compare contexts to know if program elements were compatible and programs could be assembled by the union or intersection of sets of assertions. >> About the strongest statement you can make along those lines is that #3 >> will allow you to do dynamic dispatch on the type of 'stack' while #1/2 >> won't, but even that isn't true of course. For instance, CLOS will let >> you write '(push stack item)' (which is the direct analogy in that >> language to #1) and do even more powerful dynamic dispatch than what a >> language like C++, Java, or Python will let you do. >> > > In the grand scheme of things, of course code structure and semantics > are more important the surface-level syntax. > > If you take it as a given that structure/semantics are sound (big > assumption, I know), then the next issue with regards to "readability" > is the syntax itself. Sadly, defining sound (i.e. valid) language semantics is not terribly difficult; Turing complete systems occur spontaneously with surprising frequency in nature. The problem is that fundamentally, languages model the conceptual space at large, but language designers choose a semantic vocabulary that models their minuscule subset of that space. This semantic vocabulary is by its nature static, while the conceptual space is dynamic. We aren't going to get semantics really right until we model the dynamical meta structure of the concept space, and put abstract structure, context and intent at the fore. As for syntax, we have a lot of "real" domain specific languages, such as English, math and logic. They are vetted, understood and useful outside the context of programming. We should approach the discussion of language syntax from the perspective of trying to define a unified syntactical structure for real these DSLs. Ideally it would allow representation of things in a familiar way where possible, while providing an elegant mechanism for descriptions that cut across domains and eliminating redundancy/ambiguity. This is clearly possible, though a truly successful attempt would probably be a work of art for the ages. From emile at fenx.com Wed Mar 21 14:50:56 2012 From: emile at fenx.com (Emile van Sebille) Date: Wed, 21 Mar 2012 11:50:56 -0700 Subject: ReportLab alternative for Python3 In-Reply-To: <24078051.142.1332342952564.JavaMail.geo-discussion-forums@vbat19> References: <24078051.142.1332342952564.JavaMail.geo-discussion-forums@vbat19> Message-ID: On 3/21/2012 8:15 AM Katya said... > Out of this GUI on user's request I want to create a report, > prefferebly in DOC or/and ODT or/and PDF or/and HTML formats. > ReportLab which seems to be suitable is not ready for Python3. So, any reason why not to just run that part under python2 -- they typically live side-by-side without issues. Emile From thbach at students.uni-mainz.de Wed Mar 21 15:03:01 2012 From: thbach at students.uni-mainz.de (Thomas Bach) Date: Wed, 21 Mar 2012 20:03:01 +0100 Subject: Compiling Python (modules) on 64bit Windows - which compiler suite? In-Reply-To: <808abad4-3ab3-4336-8a31-2f88eb28be01@v22g2000vby.googlegroups.com> (Ralph Heinkel's message of "Wed, 21 Mar 2012 08:06:47 -0700") References: <808abad4-3ab3-4336-8a31-2f88eb28be01@v22g2000vby.googlegroups.com> Message-ID: <874nthu68q.fsf@jubold.box> Hi, Ralph Heinkel writes: > Hi, > > when processing our mass spectrometry data we are running against the > 2GB memory limit on our 32 bit machines. So we are planning to move to > 64bit. Downloading and installing the 64bit version of Python for > Windows is trivial, but how do we compile our own C extension? What about installing Cygwin and using the shipped GCC? Regards, Thomas Bach. From gordon at panix.com Wed Mar 21 15:30:16 2012 From: gordon at panix.com (John Gordon) Date: Wed, 21 Mar 2012 19:30:16 +0000 (UTC) Subject: Best way to disconnect from ldap? Message-ID: I'm writing an application that interacts with ldap, and I'm looking for advice on how to handle the connection. Specifically, how to close the ldap connection when the application is done. I wrote a class to wrap an LDAP connection, similar to this: import ldap import ConfigParser class MyLDAPWrapper(object): def __init__(self): config = ConfigParser.SafeConfigParser() config.read('sample.conf') uri = config.get('LDAP', 'uri') user = config.get('LDAP', 'user') password = config.get('LDAP', 'password') self.ldapClient = ldap.initialize(uri) self.ldapClient.simple_bind_s(user, password) My question is this: what is the best way to ensure the ldap connection gets closed when it should? I could write an explicit close() method, but that seems a bit messy; there would end up being lots of calls to close() scattered around in my code (primarily inside exception handlers.) Or I could write a __del__ method: def __del__(self): self.ldapClient.unbind_s() This seems like a much cleaner solution, as I don't ever have to worry about closing the connection; it gets done automatically. I haven't ever used __del__ before. Are there any 'gotchas' I need to worry about? Thanks! -- 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 jcd at sdf.lonestar.org Wed Mar 21 16:21:52 2012 From: jcd at sdf.lonestar.org (J. Cliff Dyer) Date: Wed, 21 Mar 2012 16:21:52 -0400 Subject: Best way to disconnect from ldap? In-Reply-To: References: Message-ID: <1332361312.7320.2.camel@jcdyer-laptop> Write a context manager. Then you just do with MyLDAPWrapper() as ldap ldap.this() ldap.that() and when you leave the scope of the with statement, your ldap __exit__ method will get called regardless of how you left. Cheers, Cliff On Wed, 2012-03-21 at 19:30 +0000, John Gordon wrote: > I'm writing an application that interacts with ldap, and I'm looking > for advice on how to handle the connection. Specifically, how to > close the ldap connection when the application is done. > > I wrote a class to wrap an LDAP connection, similar to this:LDAP > > import ldap > import ConfigParser > > class MyLDAPWrapper(object): > > def __init__(self): > > config = ConfigParser.SafeConfigParser() > config.read('sample.conf') > > uri = config.get('LDAP', 'uri') > user = config.get('LDAP', 'user') > password = config.get('LDAP', 'password') > > self.ldapClient = ldap.initialize(uri) > self.ldapClient.simple_bind_s(user, password) > > My question is this: what is the best way to ensure the ldap connection > gets closed when it should? I could write an explicit close() method, > but that seems a bit messy; there would end up being lots of calls to > close() scattered around in my code (primarily inside exception handlers.) > > Or I could write a __del__ method: > > def __del__(self): > self.ldapClient.unbind_s() > > This seems like a much cleaner solution, as I don't ever have to worry > about closing the connection; it gets done automatically. > > I haven't ever used __del__ before. Are there any 'gotchas' I need to > worry about? > > Thanks! > > -- > 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 clp2 at rebertia.com Wed Mar 21 16:34:29 2012 From: clp2 at rebertia.com (Chris Rebert) Date: Wed, 21 Mar 2012 13:34:29 -0700 Subject: Best way to disconnect from ldap? In-Reply-To: References: Message-ID: On Wed, Mar 21, 2012 at 12:30 PM, John Gordon wrote: > I'm writing an application that interacts with ldap, and I'm looking > for advice on how to handle the connection. ?Specifically, how to > close the ldap connection when the application is done. > > I wrote a class to wrap an LDAP connection, similar to this: > > ? ?import ldap > ? ?import ConfigParser > > ? ?class MyLDAPWrapper(object): > > ? ? ? ?def __init__(self): > > ? ? ? ? ? ?config = ConfigParser.SafeConfigParser() > ? ? ? ? ? ?config.read('sample.conf') > > ? ? ? ? ? ?uri = config.get('LDAP', 'uri') > ? ? ? ? ? ?user = config.get('LDAP', 'user') > ? ? ? ? ? ?password = config.get('LDAP', 'password') > > ? ? ? ? ? ?self.ldapClient = ldap.initialize(uri) > ? ? ? ? ? ?self.ldapClient.simple_bind_s(user, password) > > My question is this: what is the best way to ensure the ldap connection > gets closed when it should? ?I could write an explicit close() method, > but that seems a bit messy; there would end up being lots of calls to > close() scattered around in my code (primarily inside exception handlers.) > > Or I could write a __del__ method: > > ? ? ? ?def __del__(self): > ? ? ? ? ? ?self.ldapClient.unbind_s() > > This seems like a much cleaner solution, as I don't ever have to worry > about closing the connection; it gets done automatically. Yes, but not necessarily in a timely manner. Since its uses reference counting, CPython /just so happens/ to finalize non-cyclically-referenced objects promptly when they go out of scope, but Python-the-language makes no such guarantee, and indeed some of the other Python implementations explicitly disclaim that there may be a significant delay before finalization is performed. > I haven't ever used __del__ before. ?Are there any 'gotchas' I need to > worry about? In addition to the aforementioned problem regarding portability to other Python implementations, see also the Warning box under: http://docs.python.org/reference/datamodel.html#object.__del__ I concur with J.'s context manager suggestion. Cheers, Chris From ckaynor at zindagigames.com Wed Mar 21 16:54:13 2012 From: ckaynor at zindagigames.com (Chris Kaynor) Date: Wed, 21 Mar 2012 13:54:13 -0700 Subject: Best way to disconnect from ldap? In-Reply-To: References: Message-ID: On Wed, Mar 21, 2012 at 1:34 PM, Chris Rebert wrote: > > On Wed, Mar 21, 2012 at 12:30 PM, John Gordon wrote: > > I'm writing an application that interacts with ldap, and I'm looking > > for advice on how to handle the connection. ?Specifically, how to > > close the ldap connection when the application is done. > > > > I wrote a class to wrap an LDAP connection, similar to this: > > > > ? ?import ldap > > ? ?import ConfigParser > > > > ? ?class MyLDAPWrapper(object): > > > > ? ? ? ?def __init__(self): > > > > ? ? ? ? ? ?config = ConfigParser.SafeConfigParser() > > ? ? ? ? ? ?config.read('sample.conf') > > > > ? ? ? ? ? ?uri = config.get('LDAP', 'uri') > > ? ? ? ? ? ?user = config.get('LDAP', 'user') > > ? ? ? ? ? ?password = config.get('LDAP', 'password') > > > > ? ? ? ? ? ?self.ldapClient = ldap.initialize(uri) > > ? ? ? ? ? ?self.ldapClient.simple_bind_s(user, password) > > > > My question is this: what is the best way to ensure the ldap connection > > gets closed when it should? ?I could write an explicit close() method, > > but that seems a bit messy; there would end up being lots of calls to > > close() scattered around in my code (primarily inside exception handlers.) > > > > Or I could write a __del__ method: > > > > ? ? ? ?def __del__(self): > > ? ? ? ? ? ?self.ldapClient.unbind_s() > > > > This seems like a much cleaner solution, as I don't ever have to worry > > about closing the connection; it gets done automatically. > > Yes, but not necessarily in a timely manner. Since its uses reference > counting, CPython /just so happens/ to finalize > non-cyclically-referenced objects promptly when they go out of scope, > but Python-the-language makes no such guarantee, and indeed some of > the other Python implementations explicitly disclaim that there may be > a significant delay before finalization is performed. > > > I haven't ever used __del__ before. ?Are there any 'gotchas' I need to > > worry about? > > In addition to the aforementioned problem regarding portability to > other Python implementations, see also the Warning box under: > http://docs.python.org/reference/datamodel.html#object.__del__ > > I concur with J.'s context manager suggestion. Personally, I would combine both methods (and maybe throw in a close option as well). The standard interface would be to use the with context, however in cases where that is not possible, an explicit close is useful, and just in-case that is forgotten or missed, the __del__ is there as a final backup. The main case that context managers fail is when you need to break the creation and teardown into separate methods, such as when writing a more complex context manager. As Chris Rebert pointed out, there is no guarantee as to when the __del__ method is called. CPython will generally call it immediately, however if there are reference cycles it may never call it: class O(object): def __del__(self): print 'del' a = O() b = O() a.obj = b b.obj = a del a del b # After this, all references should be gone. Netiher a nor b are accessable anymore, right? # Yet del was never printed. Maybe a full garbage collection will help? import gc gc.collect() # Nope... Also, if the object exists and an exception is thrown, the object may be held onto for extended periods of time, or may never get cleaned up. A quick example of this issue: >>> class O(object): ... def __del__(self): ... print 'del' ... >>> def F(): ... o = O() ... raise RuntimeError() ... >>> F() # o is not garbage collected as sys.exc_info holds a reference to it still in the traceback object. RuntimeError Traceback (most recent call last): File "", line 1, in File "", line 3, in F RuntimeError >>> raise ValueError() # When another exception got thrown, it will get cleaned up.... del ValueError Traceback (most recent call last): File "", line 1, in ValueError In any case, it still makes a decent fall-back in case the user of your code fails to properly clean-up. It will cover many of the common cases, though you do need to be careful to never get into a reference cycle if you have __del__ methods, or you get memory leaks. > > > Cheers, > Chris > -- > http://mail.python.org/mailman/listinfo/python-list From python.list at tim.thechases.com Wed Mar 21 17:49:54 2012 From: python.list at tim.thechases.com (Tim Chase) Date: Wed, 21 Mar 2012 16:49:54 -0500 Subject: Best way to disconnect from ldap? In-Reply-To: References: Message-ID: <4F6A4D02.6020403@tim.thechases.com> On 03/21/12 15:54, Chris Kaynor wrote: > As Chris Rebert pointed out, there is no guarantee as to when the > __del__ method is called. CPython will generally call it immediately, > however if there are reference cycles it may never call it And more maddeningly, modules/objects used/called from within the __del__ may have already gone out of scope, producing head-scratching errors. I've been bitten by this enough times that I just stopped using __del__ completely. -tkc From steve+comp.lang.python at pearwood.info Wed Mar 21 19:34:28 2012 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 21 Mar 2012 23:34:28 GMT Subject: Python is readable References: <4f612b19$0$1379$4fafbaef@reader2.news.tin.it> <50e9ceec-40f1-4ead-b2b6-87328b30d084@ow8g2000pbc.googlegroups.com> <4f691f3d$0$29981$c3e8da3$5496439d@news.astraweb.com> <87d386lmai.fsf@benfinney.id.au> <8a77bf8d-b12f-442b-a1a3-479b5d66d366@tx8g2000pbc.googlegroups.com> <6af70db0-dc4a-48ee-9ee2-1a934846d5f2@r2g2000pbs.googlegroups.com> Message-ID: <4f6a6584$0$29981$c3e8da3$5496439d@news.astraweb.com> On Wed, 21 Mar 2012 11:22:01 -0500, Evan Driscoll wrote: > On 01/-10/-28163 01:59 PM, Steve Howell wrote: >> Code shouldn't necessarily follow the example of English prose, but it >> seems that English has had some influence: >> >> 1 push(stack, item) # Push on the stack the item >> 2 push(item, stack) # Push the item on the stack >> 3 stack.push(item) # On the stack, push the item >> 4 stack item push # On the stack, take the item and push it >> 5 item stack push # Take the item and on the stack, push the >> former. >> 6 item push stack # Take the item; push it on the stack. >> >> The first three ways are the most common ways of arranging the grammar >> in mainstream programming languages, and they are also the three most >> natural ways in English (no pronouns required). >> >> #1/2 are imperative. #3 is OO. > > In my opinion, people who make statements such as "#1/2 are imperative, > #3 is OO" are missing pretty much the entire point of what OO is. > > OO is much more about semantics and the way code is structured. The > difference between #1/2 (especially #1, of course) and #3 is > surface-level syntax only. +1000 I like to talk about "object oriented SYNTAX" (emphasis added) to distinguish the typical OO dotted syntax obj.attr (or obj->attr) from other syntax varieties. But this must be understood as mere convention. One could invent an OO language which used syntax "push(stack, item)" or even something exotic like "item!push~stack" and it would remain OO, only with unusual syntax. Contrariwise, a purely functional language might use declarative or OO- like syntax. Syntax is orthogonal to the data model, although some data models naturally suggest some syntaxes over others. (Syntaxes? Syntaxen? Syntacies?) The first OO language I ever used was Hypertalk, which used a message- passing model: send mouseUp to button OK of card Prefs and an optional function-call syntax like this: put the average of field Values into field Average which I guess makes Hypertalk a message-passing OO language with imperative syntax. > About the strongest statement you can make along those lines is that #3 > will allow you to do dynamic dispatch on the type of 'stack' while #1/2 > won't, but even that isn't true of course. Of course. At runtime, the interpreter is able to dispatch to the correct method of 'stack' regardless of where the tokens are in the source code. -- Steven From cjgohlke at gmail.com Wed Mar 21 20:06:18 2012 From: cjgohlke at gmail.com (cjgohlke at gmail.com) Date: Wed, 21 Mar 2012 17:06:18 -0700 (PDT) Subject: Compiling Python (modules) on 64bit Windows - which compiler suite? In-Reply-To: <808abad4-3ab3-4336-8a31-2f88eb28be01@v22g2000vby.googlegroups.com> References: <808abad4-3ab3-4336-8a31-2f88eb28be01@v22g2000vby.googlegroups.com> Message-ID: <13033772.7.1332374778471.JavaMail.geo-discussion-forums@ynjk1> On Wednesday, March 21, 2012 8:06:47 AM UTC-7, Ralph Heinkel wrote: > Hi, > > when processing our mass spectrometry data we are running against the > 2GB memory limit on our 32 bit machines. So we are planning to move to > 64bit. Downloading and installing the 64bit version of Python for > Windows is trivial, but how do we compile our own C extension? Visual C > ++ 2008 express comes for free, but only compiles for 32 bit. > > What has been used to compile the downloadable Python Win64 bit > version? Visual Studio professional? > The problem with the professional edition is that it is hard to obtain > and it is sort of out-of-date - nowadays everyone uses Visual Studio > 2010 (or even 2011 coming soon). So if Visual Studio 2008 professional > is required for compiling 64bit modules, we would have to spend $1200 > for a license which is actually rather out of date. > > Any hints or suggestions are very welcome. > > Thanks, > > Ralph See "Compiling 64-bit extension modules on Windows" at . It applies to non-Cython extensions as well. MinGW-w64 also works, but you'll have to generate and use libpythonXX.a and libmsvcr90.a link libraries. Christoph From showell30 at yahoo.com Wed Mar 21 20:54:14 2012 From: showell30 at yahoo.com (Steve Howell) Date: Wed, 21 Mar 2012 17:54:14 -0700 (PDT) Subject: Python is readable References: <4f612b19$0$1379$4fafbaef@reader2.news.tin.it> <4f691f3d$0$29981$c3e8da3$5496439d@news.astraweb.com> <87d386lmai.fsf@benfinney.id.au> <8a77bf8d-b12f-442b-a1a3-479b5d66d366@tx8g2000pbc.googlegroups.com> <6af70db0-dc4a-48ee-9ee2-1a934846d5f2@r2g2000pbs.googlegroups.com> <4f6a6584$0$29981$c3e8da3$5496439d@news.astraweb.com> Message-ID: On Mar 21, 4:34?pm, Steven D'Aprano wrote: > On Wed, 21 Mar 2012 11:22:01 -0500, Evan Driscoll wrote: > > On 01/-10/-28163 01:59 PM, Steve Howell wrote: > >> Code shouldn't necessarily follow the example of English prose, but it > >> seems that English has had some influence: > > >> ? 1 ?push(stack, item) # Push on the stack the item > >> ? 2 ?push(item, stack) # Push the item on the stack > >> ? 3 ?stack.push(item) ?# On the stack, push the item > >> ? 4 ?stack item push ? # On the stack, take the item and push it > >> ? 5 ?item stack push ? # Take the item and on the stack, push the > >> ? ? ?former. > >> ? 6 ?item push stack ? # Take the item; push it on the stack. > > >> The first three ways are the most common ways of arranging the grammar > >> in mainstream programming languages, and they are also the three most > >> natural ways in English (no pronouns required). > > >> #1/2 are imperative. ?#3 is OO. > > > In my opinion, people who make statements such as "#1/2 are imperative, > > #3 is OO" are missing pretty much the entire point of what OO is. > > > OO is much more about semantics and the way code is structured. The > > difference between #1/2 (especially #1, of course) and #3 is > > surface-level syntax only. > > +1000 > > I like to talk about "object oriented SYNTAX" (emphasis added) to > distinguish the typical OO dotted syntax obj.attr (or obj->attr) from > other syntax varieties. But this must be understood as mere convention. > One could invent an OO language which used syntax "push(stack, item)" or > even something exotic like "item!push~stack" and it would remain OO, only > with unusual syntax. > Sorry if I caused confusion here. When I labelled certain syntaxes as "imperative" and certain syntaxes as "object-oriented," I never meant to imply anything about the semantic layer. (I think Evan misread my post a bit, and then went a little overboard with his comment that people like me "are missing the entire point of OO.") Clearly, I get the fact that there can be multiple valid syntaxes to express the same underlying operation, as evidenced by my presenting six permutations of stack/push/item. The discussion that I thought would be interesting is this--given six seemingly arbitrary ways of expressing the same idea, how do you decide? My hypothesis is that we all have prior conditioning such that the arrangement of words actually *does* matter. And the conditioning comes from multiple realms--we speak natural languages, we have familiarity with arithmetic notation, and we have traditions from programming itself. The place where token arrangement resonates best with me is arithmetic. I can deal with all of the expressions on a semantic level: 5 + 3 5 3 + + 5 3 On a purely theoretical level, the choice of syntax doesn't really matter (it's just a convention), but the convention is so strong, it matters on a readability level. Even though I can grok prefix/ postfix, I feel uncomfortable in programming languages that don't have "infix" sugar. Imagine if Python didn't support infix sugar. No semantic change, right? But it would still matter for some... From showell30 at yahoo.com Wed Mar 21 21:35:16 2012 From: showell30 at yahoo.com (Steve Howell) Date: Wed, 21 Mar 2012 18:35:16 -0700 (PDT) Subject: Python is readable References: <4f612b19$0$1379$4fafbaef@reader2.news.tin.it> <4f691f3d$0$29981$c3e8da3$5496439d@news.astraweb.com> <87d386lmai.fsf@benfinney.id.au> <8a77bf8d-b12f-442b-a1a3-479b5d66d366@tx8g2000pbc.googlegroups.com> <6af70db0-dc4a-48ee-9ee2-1a934846d5f2@r2g2000pbs.googlegroups.com> Message-ID: <32b8c4ae-2509-43df-abf0-0fb308be398f@oq7g2000pbb.googlegroups.com> On Mar 21, 11:06?am, Nathan Rice wrote: > As for syntax, we have a lot of "real" domain specific languages, such > as English, math and logic. They are vetted, understood and useful > outside the context of programming. ?We should approach the discussion > of language syntax from the perspective of trying to define a unified > syntactical structure for real these DSLs. ? ?Ideally it would allow > representation of things in a familiar way where possible, while > providing an elegant mechanism for descriptions that cut across > domains and eliminating redundancy/ambiguity. ?This is clearly > possible, though a truly successful attempt would probably be a work > of art for the ages. If I'm reading you correctly, you're expressing frustration with the state of language syntax unification in 2012. You mention language in a broad sense (not just programming languages, but also English, math, logic, etc.), but even in the narrow context of programming languages, the current state of the world is pretty chaotic. My position is that mankind is stuck in a painful, but inevitable, part of the evolutionary process of building programming languages. If there are quantum leaps of expressiveness/elegance/familiarity around the corner, I haven't seen them. My take is that the landscape in 2032 won't be vastly different than 2012. Languages will be better incrementally, but Python 4 or Python 5, or whatever eclipses Python in two decades, won't look vastly different than the Python we have now. If you look back to 1992, things weren't vastly different than now. In 1992 you already had Perl, C/C++, Python, Haskell, LISP, etc. Some of the languages we have in 2012 were still a glimmer in the eye back then (notably Java and Ruby), and some were quite young (notably Python), but most of them can at least trace their roots to earlier days. The optimistic view is that there will be some kind of inflection point around 2020 or so. I could imagine a perfect storm of good things happening, like convergence on a single browser platform, nearly complete migration to Python 3, further maturity of JVM-based languages, etc., where the bar gets a little higher from what people expect from languages. Instead of fighting semicolons and braces, we start thinking bigger. It could also be some sort of hardware advance, like screen resolutions that are so amazing they let us completely rethink our views on terseness, punctuation, code organization, etc. From java at leeclemens.net Wed Mar 21 21:37:25 2012 From: java at leeclemens.net (Lee Clemens) Date: Wed, 21 Mar 2012 21:37:25 -0400 Subject: Daemonization / Popen / pipe issue In-Reply-To: <20120318041548.GA15675@cskk.homeip.net> References: <20120318123516.0c13a6345c333a040568b95a@johnohagan.com> <20120318041548.GA15675@cskk.homeip.net> Message-ID: <4F6A8255.1090607@leeclemens.net> On 03/18/2012 12:15 AM, Cameron Simpson wrote: > BTW, Lee, there is an external module for daemonising things in the UNIX > sense: > http://pypi.python.org/pypi/python-daemon > I recommend you use it. > > Cheers, I haven't updated the gist yet, but I did try it with the code below - but I get the same results (inconsistent termination, logs still match up as though everything worked fine. If I'm not in DAEMONIZE mode and hold down enter, I can get stdout from the Popen process too - which I have seen with and without the DaemonContext package. There seems to be something odd going on with the way pipes are handled... Added after if __name__ == "__main__": if DAEMONIZE: import daemon myDaemon = daemon.DaemonContext() myDaemon.open() ... From stefan_ml at behnel.de Thu Mar 22 03:06:17 2012 From: stefan_ml at behnel.de (Stefan Behnel) Date: Thu, 22 Mar 2012 08:06:17 +0100 Subject: Compiling Python (modules) on 64bit Windows - which compiler suite? In-Reply-To: <874nthu68q.fsf@jubold.box> References: <808abad4-3ab3-4336-8a31-2f88eb28be01@v22g2000vby.googlegroups.com> <874nthu68q.fsf@jubold.box> Message-ID: Thomas Bach, 21.03.2012 20:03: > Ralph Heinkel writes: >> when processing our mass spectrometry data we are running against the >> 2GB memory limit on our 32 bit machines. So we are planning to move to >> 64bit. Downloading and installing the 64bit version of Python for >> Windows is trivial, but how do we compile our own C extension? > > What about installing Cygwin and using the shipped GCC? I'm pretty sure it doesn't cross compile to native Windows. It certainly won't build against a native Windows Python installation, and given the overhead that cygwin induces into a lot of common OS operations (such as fork(), I/O operations or file system access), a native Windows Python installation has serious advantages in most cases. If the choice is GCC, then MinGW is the right tool. Stefan From steve+comp.lang.python at pearwood.info Thu Mar 22 04:56:17 2012 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 22 Mar 2012 08:56:17 GMT Subject: Python is readable References: <4f612b19$0$1379$4fafbaef@reader2.news.tin.it> <4f691f3d$0$29981$c3e8da3$5496439d@news.astraweb.com> <87d386lmai.fsf@benfinney.id.au> <8a77bf8d-b12f-442b-a1a3-479b5d66d366@tx8g2000pbc.googlegroups.com> <6af70db0-dc4a-48ee-9ee2-1a934846d5f2@r2g2000pbs.googlegroups.com> <32b8c4ae-2509-43df-abf0-0fb308be398f@oq7g2000pbb.googlegroups.com> Message-ID: <4f6ae931$0$29883$c3e8da3$5496439d@news.astraweb.com> On Wed, 21 Mar 2012 18:35:16 -0700, Steve Howell wrote: > On Mar 21, 11:06?am, Nathan Rice > wrote: >> As for syntax, we have a lot of "real" domain specific languages, such >> as English, math and logic. They are vetted, understood and useful >> outside the context of programming. ?We should approach the discussion >> of language syntax from the perspective of trying to define a unified >> syntactical structure for real these DSLs. ? ?Ideally it would allow >> representation of things in a familiar way where possible, while >> providing an elegant mechanism for descriptions that cut across domains >> and eliminating redundancy/ambiguity. ?This is clearly possible, though >> a truly successful attempt would probably be a work of art for the >> ages. > > If I'm reading you correctly, you're expressing frustration with the > state of language syntax unification in 2012. You mention language in a > broad sense (not just programming languages, but also English, math, > logic, etc.), but even in the narrow context of programming languages, > the current state of the world is pretty chaotic. And this is a good thing. Programming languages are chaotic because the universe of programming problems is chaotic, and the strategies available to solve those problems are many and varied. Different programming languages are good for different things because they have been designed to work in different problem/solution spaces. Although I dislike C with a passion, I do recognise that it is good for when the programmer needs fine control over the smallest details. It is, after all, a high-level assembler. Likewise for Forth, which lets you modify the compiler and language as you go. Some languages are optimized for the compiler, some for the writer, and some for the reader. So are optimized for numeric work, others for database access. Some are Jack-Of-All-Trades. Each language encourages its own idioms and ways of thinking about programming. When it comes to programming, I say, let a thousand voices shout out. Instead of imagining a single language so wonderful that every other language is overshadowed and forgotten, imagine that the single language is the next Java, or C, or even for that matter Python, but whatever it is, it's not ideal for the problems you care about, or the way you think about them. Not so attractive now, is it? > The optimistic view is that there will be some kind of inflection point > around 2020 or so. I could imagine a perfect storm of good things > happening, like convergence on a single browser platform, You call that a perfect storm of good things. I call that sort of intellectual and software monoculture a nightmare. I want a dozen browsers, not one of which is so common that web designers can design for it and ignore the rest, not one browser so common that nobody dares try anything new. > nearly > complete migration to Python 3, further maturity of JVM-based languages, > etc., where the bar gets a little higher from what people expect from > languages. Instead of fighting semicolons and braces, we start thinking > bigger. It could also be some sort of hardware advance, like screen > resolutions that are so amazing they let us completely rethink our views > on terseness, punctuation, code organization, etc. And what of those with poor eyesight, or the blind? Are they to be excluded from your "bigger" brave new world? -- Steven From slehar at gmail.com Thu Mar 22 06:51:05 2012 From: slehar at gmail.com (Steven Lehar) Date: Thu, 22 Mar 2012 06:51:05 -0400 Subject: Python classes: Simplify? Message-ID: It seems to me that the Python class system is needlessly confusing. Am I missing something? For example in the class Complex given in the documentation *class Complex:* * def __init__(self, realpart, imagpart):* * self.r = realpart* * self.i = imagpart* * * *x = Complex(3.0, -4.5)* I initially found it profoundly confusing that __init__( ) calls for 3 arguments, but you call Complex( ) with 2. Furthermore, why not call the initialization function after the class name as is done in other languages? Isn't that the simplest conceptually? Demonstrating with the above example: *class Complex:* * def Complex(realpart, imagpart):* * Complex.r = realpart* * Complex.i = imagpart* * * *x = Complex(3.0, -4.5)* * * Is there a good reason why classes cannot be defined that way? (Besides the problem of backward-compatibility) -------------- next part -------------- An HTML attachment was scrubbed... URL: From rosuav at gmail.com Thu Mar 22 07:10:53 2012 From: rosuav at gmail.com (Chris Angelico) Date: Thu, 22 Mar 2012 22:10:53 +1100 Subject: Python classes: Simplify? In-Reply-To: References: Message-ID: On Thu, Mar 22, 2012 at 9:51 PM, Steven Lehar wrote: > It seems to me that the Python class system is needlessly confusing. Am I > missing something? > > For example in the class Complex given in the documentation > > class Complex: > ? ? def __init__(self, realpart, imagpart): > ? ? ? ? self.r = realpart > ? ? ? ? self.i = imagpart > > x = Complex(3.0, -4.5) > > I initially found it profoundly confusing that __init__( ) calls for 3 > arguments, but you call Complex( ) with 2. Furthermore, why not call the > initialization function after the class name as is done in other languages? > Isn't that the simplest conceptually? Demonstrating with the above example: Why doesn't Python do things the way Java does? Because Python isn't Java. Different language, different choices. :) Methods are called with an explicit first argument (the object being acted upon). Constructors need that argument too, even though it's not given in the invocation. With your example alternate syntax: > class Complex: > ? ? def Complex(realpart, imagpart): > ? ? ? ? Complex.r = realpart > ? ? ? ? Complex.i = imagpart there's no way to distinguish between assigning to the newly-created object's attributes and assigning to the class's own attributes. Especially since the latter is a truly viable option in Python, this can't be done; consequently, there needs to be either an explicit or an implicit "self" argument (C++ does this with an implicit 'this' pointer); the Python choice is to make it explicit. There's really no reason to have the name of the constructor change when the class is renamed. The way Python does things, you can rename a class by changing just one thing, the "class Foo:" line. In C++, you have to also rename all your constructors. And bear in mind, a class is an object, same as any other: >>> class Foo: def __init__(self,x): self.x=x def speak(self): print("x = "+self.x) >>> a=Foo("Hello") >>> a.speak() x = Hello >>> Bar=Foo >>> b=Bar("World") >>> b.speak() x = World If the constructor is named the same as the class, how would this sort of thing function? ChrisA From clp2 at rebertia.com Thu Mar 22 07:17:35 2012 From: clp2 at rebertia.com (Chris Rebert) Date: Thu, 22 Mar 2012 04:17:35 -0700 Subject: Python classes: Simplify? In-Reply-To: References: Message-ID: On Thu, Mar 22, 2012 at 3:51 AM, Steven Lehar wrote: > It seems to me that the Python class system is needlessly confusing. Am I > missing something? Explicit `self` is slightly annoying, but you'll get over it quickly (trust me). > For example in the class Complex given in the documentation > > class Complex: > ? ? def __init__(self, realpart, imagpart): > ? ? ? ? self.r = realpart > ? ? ? ? self.i = imagpart > > x = Complex(3.0, -4.5) > > I initially found it profoundly confusing that __init__( ) calls for 3 > arguments, but you call Complex( ) with 2. That's not at all unique to __init__(). > Furthermore, why not call the > initialization function after the class name as is done in other languages? Yech. That would add another step to renaming a class and make referring to the superclass initializer method rather difficult. It would also break the "all special methods have underscored names" rule. Perhaps you'll find the following instructive: Python 2.7.1 (r271:86832, Jul 31 2011, 19:30:53) >>> class Foo(object): ... def __init__(self): ... pass ... >>> Foo() <__main__.Foo object at 0x100fd5750> >>> Bar = Foo >>> Bar.__name__ = "Bar" >>> del Foo >>> # look Ma, I've renamed the class! >>> Bar() <__main__.Bar object at 0x100fd57d0> How would your scheme account for this possibility? > Isn't that the simplest conceptually? Demonstrating with the above example: > > class Complex: > ? ? def Complex(realpart, imagpart): > ? ? ? ? Complex.r = realpart > ? ? ? ? Complex.i = imagpart Your change of "self" to "Complex" in the method body here makes no sense to me. > x = Complex(3.0, -4.5) > > Is there a good reason why classes cannot be defined that way? (Besides the > problem of backward-compatibility) Mostly historical, IMO. But here are some justifications for explicit `self`: http://docs.python.org/faq/design.html#why-must-self-be-used-explicitly-in-method-definitions-and-calls http://neopythonic.blogspot.com/2008/10/why-explicit-self-has-to-stay.html Cheers, Chris R. -- http://blog.rebertia.com From joncle at googlemail.com Thu Mar 22 07:18:02 2012 From: joncle at googlemail.com (Jon Clements) Date: Thu, 22 Mar 2012 04:18:02 -0700 (PDT) Subject: Python is readable (OT) In-Reply-To: <4f6ae931$0$29883$c3e8da3$5496439d@news.astraweb.com> References: <4f612b19$0$1379$4fafbaef@reader2.news.tin.it> <4f691f3d$0$29981$c3e8da3$5496439d@news.astraweb.com> <87d386lmai.fsf@benfinney.id.au> <8a77bf8d-b12f-442b-a1a3-479b5d66d366@tx8g2000pbc.googlegroups.com> <6af70db0-dc4a-48ee-9ee2-1a934846d5f2@r2g2000pbs.googlegroups.com> <32b8c4ae-2509-43df-abf0-0fb308be398f@oq7g2000pbb.googlegroups.com> <4f6ae931$0$29883$c3e8da3$5496439d@news.astraweb.com> Message-ID: <33536194.2563.1332415082529.JavaMail.geo-discussion-forums@ynlt15> On Thursday, 22 March 2012 08:56:17 UTC, Steven D'Aprano wrote: > On Wed, 21 Mar 2012 18:35:16 -0700, Steve Howell wrote: > > > On Mar 21, 11:06?am, Nathan Rice > > wrote: [snip]. > > Different programming languages are good for different things because > they have been designed to work in different problem/solution spaces. > Although I dislike C with a passion, I do recognise that it is good for > when the programmer needs fine control over the smallest details. It is, > after all, a high-level assembler. Likewise for Forth, which lets you > modify the compiler and language as you go. > > Some languages are optimized for the compiler, some for the writer, and > some for the reader. So are optimized for numeric work, others for > database access. Some are Jack-Of-All-Trades. Each language encourages > its own idioms and ways of thinking about programming. > > When it comes to programming, I say, let a thousand voices shout out. > Instead of imagining a single language so wonderful that every other > language is overshadowed and forgotten, imagine that the single language > is the next Java, or C, or even for that matter Python, but whatever it > is, it's not ideal for the problems you care about, or the way you think > about them. Not so attractive now, is it? > > > > The optimistic view is that there will be some kind of inflection point > > around 2020 or so. I could imagine a perfect storm of good things > > happening, like convergence on a single browser platform, > > You call that a perfect storm of good things. I call that sort of > intellectual and software monoculture a nightmare. > > I want a dozen browsers, not one of which is so common that web designers > can design for it and ignore the rest, not one browser so common that > nobody dares try anything new. > > > > nearly > > complete migration to Python 3, further maturity of JVM-based languages, > > etc., where the bar gets a little higher from what people expect from > > languages. Instead of fighting semicolons and braces, we start thinking > > bigger. It could also be some sort of hardware advance, like screen > > resolutions that are so amazing they let us completely rethink our views > > on terseness, punctuation, code organization, etc. > > And what of those with poor eyesight, or the blind? Are they to be > excluded from your "bigger" brave new world? > > > > -- > Steven On Thursday, 22 March 2012 08:56:17 UTC, Steven D'Aprano wrote: > On Wed, 21 Mar 2012 18:35:16 -0700, Steve Howell wrote: > > > On Mar 21, 11:06?am, Nathan Rice > > wrote: > >> As for syntax, we have a lot of "real" domain specific languages, such > >> as English, math and logic. They are vetted, understood and useful > >> outside the context of programming. ?We should approach the discussion > >> of language syntax from the perspective of trying to define a unified > >> syntactical structure for real these DSLs. ? ?Ideally it would allow > >> representation of things in a familiar way where possible, while > >> providing an elegant mechanism for descriptions that cut across domains > >> and eliminating redundancy/ambiguity. ?This is clearly possible, though > >> a truly successful attempt would probably be a work of art for the > >> ages. > > > > If I'm reading you correctly, you're expressing frustration with the > > state of language syntax unification in 2012. You mention language in a > > broad sense (not just programming languages, but also English, math, > > logic, etc.), but even in the narrow context of programming languages, > > the current state of the world is pretty chaotic. > > And this is a good thing. Programming languages are chaotic because the > universe of programming problems is chaotic, and the strategies available > to solve those problems are many and varied. > > Different programming languages are good for different things because > they have been designed to work in different problem/solution spaces. > Although I dislike C with a passion, I do recognise that it is good for > when the programmer needs fine control over the smallest details. It is, > after all, a high-level assembler. Likewise for Forth, which lets you > modify the compiler and language as you go. > > Some languages are optimized for the compiler, some for the writer, and > some for the reader. So are optimized for numeric work, others for > database access. Some are Jack-Of-All-Trades. Each language encourages > its own idioms and ways of thinking about programming. > > When it comes to programming, I say, let a thousand voices shout out. > Instead of imagining a single language so wonderful that every other > language is overshadowed and forgotten, imagine that the single language > is the next Java, or C, or even for that matter Python, but whatever it > is, it's not ideal for the problems you care about, or the way you think > about them. Not so attractive now, is it? > > > > The optimistic view is that there will be some kind of inflection point > > around 2020 or so. I could imagine a perfect storm of good things > > happening, like convergence on a single browser platform, > > You call that a perfect storm of good things. I call that sort of > intellectual and software monoculture a nightmare. > > I want a dozen browsers, not one of which is so common that web designers > can design for it and ignore the rest, not one browser so common that > nobody dares try anything new. > > > > nearly > > complete migration to Python 3, further maturity of JVM-based languages, > > etc., where the bar gets a little higher from what people expect from > > languages. Instead of fighting semicolons and braces, we start thinking > > bigger. It could also be some sort of hardware advance, like screen > > resolutions that are so amazing they let us completely rethink our views > > on terseness, punctuation, code organization, etc. > > And what of those with poor eyesight, or the blind? Are they to be > excluded from your "bigger" brave new world? > > > > -- > Steven Completely not related to this discussion, but, I just have to say to Steven, I could not have expressed that better. +1 QOTW (albeit a long one) Jon. From mrsangeet at gmail.com Thu Mar 22 07:33:46 2012 From: mrsangeet at gmail.com (Sangeet) Date: Thu, 22 Mar 2012 04:33:46 -0700 (PDT) Subject: Accessing the files by last modified time Message-ID: <26215939.1574.1332416026298.JavaMail.geo-discussion-forums@ynlt17> Hi I am new to the python programming language. I've been trying to write a script that would access the last modified file in one of my directories. I'm using Win XP. I saw a similar topic, on the forum before, however the reply using (os.popen) didn't work out for me. I'm not sure whether it was due to syntax errors either. Thanks, Sangeet From clp2 at rebertia.com Thu Mar 22 07:49:23 2012 From: clp2 at rebertia.com (Chris Rebert) Date: Thu, 22 Mar 2012 04:49:23 -0700 Subject: Accessing the files by last modified time In-Reply-To: <26215939.1574.1332416026298.JavaMail.geo-discussion-forums@ynlt17> References: <26215939.1574.1332416026298.JavaMail.geo-discussion-forums@ynlt17> Message-ID: On Thu, Mar 22, 2012 at 4:33 AM, Sangeet wrote: > Hi > > I am new to the python programming language. > > I've been trying to write a script that would access the last modified file in one of my directories. I'm using Win XP. > > I saw a similar topic, on the forum before, however the reply using (os.popen) didn't work out for me. I'm not sure whether it was due to syntax errors either. Recursively or non-recursively? Live monitoring or just one-time? What was the forum post in question? In the simple case, you just need to stitch together these functions: http://docs.python.org/library/os.html#os.stat (note the .st_mtime attribute of the result) http://docs.python.org/library/os.path.html#os.path.join with one of these functions: http://docs.python.org/library/os.html#os.listdir http://docs.python.org/library/os.html#os.walk Cheers, Chris From tjandacw at cox.net Thu Mar 22 08:04:43 2012 From: tjandacw at cox.net (Tim Williams) Date: Thu, 22 Mar 2012 05:04:43 -0700 (PDT) Subject: Accessing the files by last modified time References: <26215939.1574.1332416026298.JavaMail.geo-discussion-forums@ynlt17> Message-ID: <8cbfb1b2-94ed-4830-90fa-976a831ebb97@l14g2000vbe.googlegroups.com> On Mar 22, 7:33?am, Sangeet wrote: > Hi > > I am new to the python programming language. > > I've been trying to write a script that would access the last modified file in one of my directories. I'm using Win XP. > > I saw a similar topic, on the forum before, however the reply using (os.popen) didn't work out for me. I'm not sure whether it was due to syntax errors either. > > Thanks, > Sangeet Check out os.stat() From __peter__ at web.de Thu Mar 22 08:38:00 2012 From: __peter__ at web.de (Peter Otten) Date: Thu, 22 Mar 2012 13:38 +0100 Subject: Accessing the files by last modified time References: <26215939.1574.1332416026298.JavaMail.geo-discussion-forums@ynlt17> Message-ID: Sangeet wrote: > I've been trying to write a script that would access the last modified > file in one of my directories. I'm using Win XP. import os import glob path = r"c:\one\of\my directories\*" youngest_file = max(glob.glob(path), key=os.path.getmtime) From nathan.alexander.rice at gmail.com Thu Mar 22 08:47:15 2012 From: nathan.alexander.rice at gmail.com (Nathan Rice) Date: Thu, 22 Mar 2012 08:47:15 -0400 Subject: Python is readable In-Reply-To: <4f6ae931$0$29883$c3e8da3$5496439d@news.astraweb.com> References: <4f612b19$0$1379$4fafbaef@reader2.news.tin.it> <4f691f3d$0$29981$c3e8da3$5496439d@news.astraweb.com> <87d386lmai.fsf@benfinney.id.au> <8a77bf8d-b12f-442b-a1a3-479b5d66d366@tx8g2000pbc.googlegroups.com> <6af70db0-dc4a-48ee-9ee2-1a934846d5f2@r2g2000pbs.googlegroups.com> <32b8c4ae-2509-43df-abf0-0fb308be398f@oq7g2000pbb.googlegroups.com> <4f6ae931$0$29883$c3e8da3$5496439d@news.astraweb.com> Message-ID: >> If I'm reading you correctly, you're expressing frustration with the >> state of language syntax unification in 2012. You mention language in a >> broad sense (not just programming languages, but also English, math, >> logic, etc.), but even in the narrow context of programming languages, >> the current state of the world is pretty chaotic. > > And this is a good thing. Programming languages are chaotic because the > universe of programming problems is chaotic, and the strategies available > to solve those problems are many and varied. > > Different programming languages are good for different things because > they have been designed to work in different problem/solution spaces. > Although I dislike C with a passion, I do recognise that it is good for > when the programmer needs fine control over the smallest details. It is, > after all, a high-level assembler. Likewise for Forth, which lets you > modify the compiler and language as you go. There is a concept in statistical/mathematical modeling called minimum message length (a close analog is minimum description length), which asserts that the optimum model for some set of information is the one that minimizes the sum of the length of the model and the length of the set described by that model. Clearly no model is going to be optimal for every set of information. What I was alluding to in the post that Steve Howell replied to was that we need to have a programming language that is a model of models, then include a second order model as part of the program. Having one core language with many DSLs that can interoperate is infinitely better than having many languages that cannot. A language designed in such a way would also prevent issues like the Python 2 -> 3 fiasco, because two versions of a DSL can be separate, and code can reference them independently while being able to interoperate. > Some languages are optimized for the compiler, some for the writer, and > some for the reader. So are optimized for numeric work, others for > database access. Some are Jack-Of-All-Trades. Each language encourages > its own idioms and ways of thinking about programming. The difference between compiler optimized and writer optimized languages is how many assertions they require about the thing being modeled to be a "valid" program, given its deductive rules. Ideally, the number of assertions should be flexible, and the interpreter/compiler should try and figure out the best way to implement it given the information it has. > When it comes to programming, I say, let a thousand voices shout out. > Instead of imagining a single language so wonderful that every other > language is overshadowed and forgotten, imagine that the single language > is the next Java, or C, or even for that matter Python, but whatever it > is, it's not ideal for the problems you care about, or the way you think > about them. Not so attractive now, is it? I agree about letting a thousand voices shout out, in the context of an embedding language that guarantees code interoperability. Additionally, the size of optimal DSLs for different areas is actually quite small, yet having separate languages for each DSL requires the user to re-learn common patterns such as collection manipulation, IO, etc. Pretty horrible all around. >> The optimistic view is that there will be some kind of inflection point >> around 2020 or so. I could imagine a perfect storm of good things >> happening, like convergence on a single browser platform, > > You call that a perfect storm of good things. I call that sort of > intellectual and software monoculture a nightmare. The cores of English and math are pretty much singularly represented. At more nuanced or abstract levels, there is divergence in order to simplify the process of describing complicated things. How would you like it if linear algebra or algebraic geometry re-invented addition, multiplication, etc with completely different syntax and semantics (I'm ignoring non-commutativity of vector space multiplication) > I want a dozen browsers, not one of which is so common that web designers > can design for it and ignore the rest, not one browser so common that > nobody dares try anything new. How about one browser that is infinitely configurable? That way if someone tries something new, you can try it as well without precluding anything else you already do. The CLI/JVM provide some flexibility, but they are not the correct path. They model the executable machine representations of language, rather than modeling the meta structure of language. This means that you still lack flexibility and dynamism. At least things are moving in the right direction. From neilc at norwich.edu Thu Mar 22 09:06:36 2012 From: neilc at norwich.edu (Neil Cerutti) Date: 22 Mar 2012 13:06:36 GMT Subject: Accessing the files by last modified time References: <26215939.1574.1332416026298.JavaMail.geo-discussion-forums@ynlt17> <8cbfb1b2-94ed-4830-90fa-976a831ebb97@l14g2000vbe.googlegroups.com> Message-ID: <9t0mesFnj3U1@mid.individual.net> On 2012-03-22, Tim Williams wrote: > On Mar 22, 7:33?am, Sangeet wrote: >> Hi >> >> I am new to the python programming language. >> >> I've been trying to write a script that would access the last >> modified file in one of my directories. I'm using Win XP. >> >> I saw a similar topic, on the forum before, however the reply >> using (os.popen) didn't work out for me. I'm not sure whether >> it was due to syntax errors either. >> >> Thanks, >> Sangeet > > Check out os.stat() I've been using os.path.getmtime, and converting that to a datetime object using datetime.datetime.fromtimestamp. Surprisingly, perhaps, this has been working. According to the docs, to avoid making any assumptiong, I might need to do: tm = os.path.getmtime(apath) lt = time.localtime(tm) datetime.datetime(lt.tm_year, lt.tm_mon, lt.tm_mday) Here's where I'm confused about the functioning of my original plan. The docs say: os.path.getmtime [...] The return value is a number giving the number of seconds since the epoch (see the time module). [...] classmethod datetime.fromtimestamp Return the local date and time corresponding to the POSIX timestamp, such as returned by time.time(). [...] time.time Return the time as a floating point number expressed as seconds since the epoch, in UTC. [...] I'm not completely sure the return type of getmtime and the argument type of fromtimestamp are really the same or not. I guess I came to that conclusion some time in the past, and it does seem to work. It may be a simple case of just different aspects the exact same type being being highlighted in each definition. -- Neil Cerutti From tycho at tycho.ws Thu Mar 22 09:14:47 2012 From: tycho at tycho.ws (Tycho Andersen) Date: Thu, 22 Mar 2012 08:14:47 -0500 Subject: Best way to disconnect from ldap? In-Reply-To: <4F6A4D02.6020403@tim.thechases.com> References: <4F6A4D02.6020403@tim.thechases.com> Message-ID: <20120322131447.GG19657@ccapuser-ubuntu.WICOURTS.GOV> On Wed, Mar 21, 2012 at 04:49:54PM -0500, Tim Chase wrote: > On 03/21/12 15:54, Chris Kaynor wrote: > >As Chris Rebert pointed out, there is no guarantee as to when the > >__del__ method is called. CPython will generally call it immediately, > >however if there are reference cycles it may never call it > > And more maddeningly, modules/objects used/called from within the > __del__ may have already gone out of scope, producing > head-scratching errors. I've been bitten by this enough times that > I just stopped using __del__ completely. I've had similar experiences. In fact, in light of all this - why does __del__ exist at all? Novice python users may (reasonably) assume it behaves similarly to a C++ destructor (even though the docs warn otherwise). Given that you can't trust __del__, is there a legitimate use case for it? \t From andrea.crotti.0 at gmail.com Thu Mar 22 09:15:03 2012 From: andrea.crotti.0 at gmail.com (Andrea Crotti) Date: Thu, 22 Mar 2012 13:15:03 +0000 Subject: Python classes: Simplify? In-Reply-To: References: Message-ID: <4F6B25D7.9020002@gmail.com> On 03/22/2012 10:51 AM, Steven Lehar wrote: > It seems to me that the Python class system is needlessly confusing. > Am I missing something? > > For example in the class Complex given in the documentation > > *class Complex:* > * def __init__(self, realpart, imagpart):* > * self.r = realpart* > * self.i = imagpart* > * > * > *x = Complex(3.0, -4.5)* > > I initially found it profoundly confusing that __init__( ) calls for 3 > arguments, but you call Complex( ) with 2. Furthermore, why not call > the initialization function after the class name as is done in other > languages? Isn't that the simplest conceptually? Demonstrating with > the above example: > > *class Complex:* > * def Complex(realpart, imagpart):* > * Complex.r = realpart* > * Complex.i = imagpart* > * > * > *x = Complex(3.0, -4.5)* > * > * > Is there a good reason why classes cannot be defined that way? > (Besides the problem of backward-compatibility) > Some time ago I saw some nasty hack that allowed you to drop the self in the method declaration, using some crazy metaclass trick, but that's really not a good idea ;) I agree that is counter-intuitive but just set your editor to do that for you and you will be fine.. in my emacs - s TAB -> self - . TAB -> self. - m TAB -> def ${1:method}(self$2): $0 so I never actually write the self.. -------------- next part -------------- An HTML attachment was scrubbed... URL: From rosuav at gmail.com Thu Mar 22 09:17:49 2012 From: rosuav at gmail.com (Chris Angelico) Date: Fri, 23 Mar 2012 00:17:49 +1100 Subject: Python is readable In-Reply-To: References: <4f612b19$0$1379$4fafbaef@reader2.news.tin.it> <4f691f3d$0$29981$c3e8da3$5496439d@news.astraweb.com> <87d386lmai.fsf@benfinney.id.au> <8a77bf8d-b12f-442b-a1a3-479b5d66d366@tx8g2000pbc.googlegroups.com> <6af70db0-dc4a-48ee-9ee2-1a934846d5f2@r2g2000pbs.googlegroups.com> <32b8c4ae-2509-43df-abf0-0fb308be398f@oq7g2000pbb.googlegroups.com> <4f6ae931$0$29883$c3e8da3$5496439d@news.astraweb.com> Message-ID: On Thu, Mar 22, 2012 at 11:47 PM, Nathan Rice wrote: > Having one core language with > many DSLs that can interoperate is infinitely better than having many > languages that cannot. ?A language designed in such a way would also > prevent issues like the Python 2 -> 3 fiasco, because two versions of > a DSL can be separate, and code can reference them independently while > being able to interoperate. This is either utterly impossible, or already available, depending on your point of view. To have an infinitely-configurable program, you must make its configuration equivalent to writing code. There is already an infinitely-configurable program in Unix: "gcc config.c; ./a.out" takes a simple-format text file called "config.c" and processes it. You want infinite DSLs? Behold! $ ./module1 | ./module2 | ./module3 | ./module4 Each one has a shebang that tells you what they are (Python 2, Python 3, something else entirely). There's a very strict interoperability protocol between the modules - they pass information around through stdout and stdin. You can write any module in any language, and you can rewrite module1 for Python 3 without affecting any other or the invocation sequence. Problems always come when you want to share data between dissimilar modules. There's no single perfect data-transfer protocol that works across all languages. What does it mean to "call a function"? If you truly want this level of flexibility, the best thing to do is to separate sections cleanly. In fact, the pipe system I show above could be used that way, although it's stupidly ugly. Everything going on stdout/stdin has a two-word dispatch envelope with a from and a to, and each module reads a line, and if it's not addressed to it, passes it on to stdout. Responses get sent out with their from and to reversed. All you need is for the last module's stdout to be linked back into the first module's stdin (not sure if you can do that or not - it has the feeling of plugging a power strip into itself), and it'll work perfectly. Add a bit of boilerplate so that the application developers don't see what's happening underneath, and you could pretend that dissimilar languages are able to call into each other. Doesn't mean it's efficient though! TLDR version: Infinite flexibility means you're doing nothing. ChrisA From clp2 at rebertia.com Thu Mar 22 09:27:45 2012 From: clp2 at rebertia.com (Chris Rebert) Date: Thu, 22 Mar 2012 06:27:45 -0700 Subject: Best way to disconnect from ldap? In-Reply-To: <20120322131447.GG19657@ccapuser-ubuntu.WICOURTS.GOV> References: <4F6A4D02.6020403@tim.thechases.com> <20120322131447.GG19657@ccapuser-ubuntu.WICOURTS.GOV> Message-ID: On Thu, Mar 22, 2012 at 6:14 AM, Tycho Andersen wrote: > On Wed, Mar 21, 2012 at 04:49:54PM -0500, Tim Chase wrote: >> On 03/21/12 15:54, Chris Kaynor wrote: >> >As Chris Rebert pointed out, there is no guarantee as to when the >> >__del__ method is called. CPython will generally call it immediately, >> >however if there are reference cycles it may never call it >> >> And more maddeningly, modules/objects used/called from within the >> __del__ may have already gone out of scope, producing >> head-scratching errors. ?I've been bitten by this enough times that >> I just stopped using __del__ completely. > > I've had similar experiences. In fact, in light of all this - why does > __del__ exist at all? Novice python users may (reasonably) assume it > behaves similarly to a C++ destructor (even though the docs warn > otherwise). > > Given that you can't trust __del__, is there a legitimate use case for > it? Writing resource classes (like `file`) in C? Their __del__()s typically involve little/less Python-level stuff and thus less paranoia need be exercised. There is somewhat of a perverse incentive in having such last-ditch clean-up mechanisms though. "This code seems to work fine without `with`, so why bother changing it?" Cheers, Chris From tycho at tycho.ws Thu Mar 22 10:00:50 2012 From: tycho at tycho.ws (Tycho Andersen) Date: Thu, 22 Mar 2012 09:00:50 -0500 Subject: Best way to disconnect from ldap? In-Reply-To: References: <4F6A4D02.6020403@tim.thechases.com> <20120322131447.GG19657@ccapuser-ubuntu.WICOURTS.GOV> Message-ID: <20120322140050.GI19657@ccapuser-ubuntu.WICOURTS.GOV> On Thu, Mar 22, 2012 at 06:27:45AM -0700, Chris Rebert wrote: > On Thu, Mar 22, 2012 at 6:14 AM, Tycho Andersen wrote: > > On Wed, Mar 21, 2012 at 04:49:54PM -0500, Tim Chase wrote: > >> On 03/21/12 15:54, Chris Kaynor wrote: > >> >As Chris Rebert pointed out, there is no guarantee as to when the > >> >__del__ method is called. CPython will generally call it immediately, > >> >however if there are reference cycles it may never call it > >> > >> And more maddeningly, modules/objects used/called from within the > >> __del__ may have already gone out of scope, producing > >> head-scratching errors. ?I've been bitten by this enough times that > >> I just stopped using __del__ completely. > > > > I've had similar experiences. In fact, in light of all this - why does > > __del__ exist at all? Novice python users may (reasonably) assume it > > behaves similarly to a C++ destructor (even though the docs warn > > otherwise). > > > > Given that you can't trust __del__, is there a legitimate use case for > > it? > > Writing resource classes (like `file`) in C? Their __del__()s > typically involve little/less Python-level stuff and thus less > paranoia need be exercised. Sure, but you still have no guarantee that __del__ will ever be called, so it's a bad idea to rely on it to clean up anything. > There is somewhat of a perverse incentive in having such last-ditch > clean-up mechanisms though. "This code seems to work fine without > `with`, so why bother changing it?" Yeah, I guess I can see doing something like: __del__ = __exit__ but anything beyond that seems risky... \t From nathan.alexander.rice at gmail.com Thu Mar 22 10:29:48 2012 From: nathan.alexander.rice at gmail.com (Nathan Rice) Date: Thu, 22 Mar 2012 10:29:48 -0400 Subject: Python is readable In-Reply-To: References: <4f612b19$0$1379$4fafbaef@reader2.news.tin.it> <4f691f3d$0$29981$c3e8da3$5496439d@news.astraweb.com> <87d386lmai.fsf@benfinney.id.au> <8a77bf8d-b12f-442b-a1a3-479b5d66d366@tx8g2000pbc.googlegroups.com> <6af70db0-dc4a-48ee-9ee2-1a934846d5f2@r2g2000pbs.googlegroups.com> <32b8c4ae-2509-43df-abf0-0fb308be398f@oq7g2000pbb.googlegroups.com> <4f6ae931$0$29883$c3e8da3$5496439d@news.astraweb.com> Message-ID: On Thu, Mar 22, 2012 at 9:17 AM, Chris Angelico wrote: > On Thu, Mar 22, 2012 at 11:47 PM, Nathan Rice > wrote: >> Having one core language with >> many DSLs that can interoperate is infinitely better than having many >> languages that cannot. ?A language designed in such a way would also >> prevent issues like the Python 2 -> 3 fiasco, because two versions of >> a DSL can be separate, and code can reference them independently while >> being able to interoperate. > > This is either utterly impossible, or already available, depending on > your point of view. Of course it is already available. It is called the laws of physics. Everything we know of inter-operates in the context of physical reality perfectly. > To have an infinitely-configurable program, you must make its > configuration equivalent to writing code. There is already an > infinitely-configurable program in Unix: "gcc config.c; ./a.out" takes > a simple-format text file called "config.c" and processes it. It is true that infinite configuration requires that the configuration be specified in the language of the program. What's the problem? > You want infinite DSLs? Behold! > > $ ./module1 | ./module2 | ./module3 | ./module4 > > Each one has a shebang that tells you what they are (Python 2, Python > 3, something else entirely). There's a very strict interoperability > protocol between the modules - they pass information around through > stdout and stdin. You can write any module in any language, and you > can rewrite module1 for Python 3 without affecting any other or the > invocation sequence. It has always been possible to get from one point in space to another point in space in finite time. Was the invention of the automobile was redundant and unimportant? Obviously not, the characteristics of the process matter. For example, your ability to reason about the behavior of the system you posited as a whole is limited. Are there parts of the different modules that can execute concurrently? Is the output of module1 guaranteed to be acceptable as the input for module2? Is part of module3 redundant (and thus avoidable) given some conditions in module1? If you make a change in module2 what effect does that have on module3 and module4? What if you need to go back and forth between module2 and module3 until some criterion is met before you transition to module4? What if you sometimes want to run module2b instead of module2? > Problems always come when you want to share data between dissimilar > modules. There's no single perfect data-transfer protocol that works > across all languages. What does it mean to "call a function"? If you > truly want this level of flexibility, the best thing to do is to > separate sections cleanly. In fact, the pipe system I show above could > be used that way, although it's stupidly ugly. Everything going on > stdout/stdin has a two-word dispatch envelope with a from and a to, > and each module reads a line, and if it's not addressed to it, passes > it on to stdout. Responses get sent out with their from and to > reversed. All you need is for the last module's stdout to be linked > back into the first module's stdin (not sure if you can do that or not > - it has the feeling of plugging a power strip into itself), and it'll > work perfectly. Add a bit of boilerplate so that the application > developers don't see what's happening underneath, and you could > pretend that dissimilar languages are able to call into each other. > Doesn't mean it's efficient though! What is a function? You could say that it is a sequence of logical statements that relates some assertion with another. You can make a big deal about call by name versus call by value, but it only really matters on a conceptual level when dealing with infinite objects that do not have an analytic closure. You can make a big deal about data format, but scientists have been communicating using different unit systems for hundreds of years, I don't see assertions of relationship between structures as different from unit conversions from imperial to metric; it's all data. There are of course a few snags such as cardinality of the set represented by the integer data type in one case versus another, but that is a low level detail that would be a problem if DSLs were embedded in an expressive modelling language. Data structures ultimately boil down to assertions, assertions about those assertions and relations between assertions. > TLDR version: Infinite flexibility means you're doing nothing. I could address that from a number of ways. First off, anything that is Turing complete is basically "infinitely flexible" but the difference in expressiveness (as measured by the combined length of the program and its input required to generate some output) varies over orders of magnitudes. So, we're actually discussing "infinitely expressive" though in fact we don't need to appeal to infinity here, so that is a strawman. The reason for that is the system in which concepts are generated (physical reality) is finite on some levels. Much like a fractal, though there is infinite "detail", it is the result of the recursive application and composition of a small set of motifs. This is why I keep harping on the importance of a meta-model. Given a description of the fractal system and starting state, I can predict the structure of any portion of the fractal at any time with complete accuracy (assuming it is not a stochastic system, in which case I can only predict the distribution of states). If you try to model a fractal system at a particular point by describing its geometry you will be busy for a VERY long time, and if I asked you anything about the state of the fractal at a different time you would be at a loss. All I'm trying to advocate is that people stop modelling the geometry of the system at time t and start modelling the dynamics of the system. Seems pretty reasonable to me. TL;DR there are a huge number of incompatible programming languages because people are modeling a permutation rather than the input to a permutation generating function. Nathan From anacrolix at gmail.com Thu Mar 22 10:53:51 2012 From: anacrolix at gmail.com (Matt Joiner) Date: Thu, 22 Mar 2012 22:53:51 +0800 Subject: Condition in C API Message-ID: Is there a Condition-like object exposed in the CPython C API? I've found PyThread_lock_type, but nothing condition-like. From ramit.prasad at jpmorgan.com Thu Mar 22 11:25:04 2012 From: ramit.prasad at jpmorgan.com (Prasad, Ramit) Date: Thu, 22 Mar 2012 15:25:04 +0000 Subject: urllib.urlretrieve never returns??? In-Reply-To: <4F69CBB2.6060801@shopzeus.com> References: <4F649BFC.1080601@shopzeus.com> <4F66E687.2050008@shopzeus.com> <4f67c09b$0$29981$c3e8da3$5496439d@news.astraweb.com> <4F682CDC.5000703@shopzeus.com> <4F68E49C.2060000@shopzeus.com> <5B80DD153D7D744689F57F4FB69AF474026C4BD8@SCACMX008.exchad.jpmchase.net> <5B80DD153D7D744689F57F4FB69AF474026C4C97@SCACMX008.exchad.jpmchase.net> <4F69CBB2.6060801@shopzeus.com> Message-ID: <5B80DD153D7D744689F57F4FB69AF474026C646B@SCACMX008.exchad.jpmchase.net> > > I just looked at your source file on ActiveState and noticed that > > you do not import traceback. That is why you are getting the > > AttributeError. Now you should be getting a much better error > > once you import it:) > Nope. That would result in a NameError. After adding "import traceback", > I still get several AttributeError messages. The traceback should > contain the exact line number, and a description about what object is > missing what attribute anyway. My code is pure Python, and under no > circumstances should it be able to start a blocked call for a system > library function. Your code works for me, so the problem should be your system and/or network. Try a different Python version? I tested using 2.6.6. Also, check your proxy or firewall. If you are using Python 2.x try using urllib2. Ramit Ramit Prasad | JPMorgan Chase Investment Bank | Currencies Technology 712 Main Street | Houston, TX 77002 work phone: 713 - 216 - 5423 This email is confidential and subject to important disclaimers and conditions including on offers for the purchase or sale of securities, accuracy and completeness of information, viruses, confidentiality, legal privilege, and legal entity disclaimers, available at http://www.jpmorgan.com/pages/disclosures/email. From showell30 at yahoo.com Thu Mar 22 11:33:34 2012 From: showell30 at yahoo.com (Steve Howell) Date: Thu, 22 Mar 2012 08:33:34 -0700 (PDT) Subject: Python is readable References: <4f612b19$0$1379$4fafbaef@reader2.news.tin.it> <4f691f3d$0$29981$c3e8da3$5496439d@news.astraweb.com> <87d386lmai.fsf@benfinney.id.au> <8a77bf8d-b12f-442b-a1a3-479b5d66d366@tx8g2000pbc.googlegroups.com> <6af70db0-dc4a-48ee-9ee2-1a934846d5f2@r2g2000pbs.googlegroups.com> <32b8c4ae-2509-43df-abf0-0fb308be398f@oq7g2000pbb.googlegroups.com> <4f6ae931$0$29883$c3e8da3$5496439d@news.astraweb.com> Message-ID: <3d27a54d-b790-4c73-8fd1-05fcbe9abf7e@r2g2000pbs.googlegroups.com> On Mar 22, 1:56?am, Steven D'Aprano wrote: > On Wed, 21 Mar 2012 18:35:16 -0700, Steve Howell wrote: > > On Mar 21, 11:06?am, Nathan Rice > > wrote: > >> As for syntax, we have a lot of "real" domain specific languages, such > >> as English, math and logic. They are vetted, understood and useful > >> outside the context of programming. ?We should approach the discussion > >> of language syntax from the perspective of trying to define a unified > >> syntactical structure for real these DSLs. ? ?Ideally it would allow > >> representation of things in a familiar way where possible, while > >> providing an elegant mechanism for descriptions that cut across domains > >> and eliminating redundancy/ambiguity. ?This is clearly possible, though > >> a truly successful attempt would probably be a work of art for the > >> ages. > > > If I'm reading you correctly, you're expressing frustration with the > > state of language syntax unification in 2012. ?You mention language in a > > broad sense (not just programming languages, but also English, math, > > logic, etc.), but even in the narrow context of programming languages, > > the current state of the world is pretty chaotic. > > And this is a good thing. Programming languages are chaotic because the > universe of programming problems is chaotic, and the strategies available > to solve those problems are many and varied. > > Different programming languages are good for different things because > they have been designed to work in different problem/solution spaces. > Although I dislike C with a passion, I do recognise that it is good for > when the programmer needs fine control over the smallest details. It is, > after all, a high-level assembler. Likewise for Forth, which lets you > modify the compiler and language as you go. > > Some languages are optimized for the compiler, some for the writer, and > some for the reader. So are optimized for numeric work, others for > database access. Some are Jack-Of-All-Trades. Each language encourages > its own idioms and ways of thinking about programming. > > When it comes to programming, I say, let a thousand voices shout out. > Instead of imagining a single language so wonderful that every other > language is overshadowed and forgotten, imagine that the single language > is the next Java, or C, or even for that matter Python, but whatever it > is, it's not ideal for the problems you care about, or the way you think > about them. Not so attractive now, is it? > I'm not imagining a world where a single, imperfect programming language crowds out other useful solutions. What I am hoping for is a more purposeful diversity. It would be great if the top 20 languages in the future had the same expressive power as say the top 200 do now. In other words, by the time you investigated the 21st best language for your needs, it would be something really interesting and cutting edge, instead of PHP. It's hard to imagine the *specific* form of progress we'll have in the future, but I'd imagine that some day we'll have something more interesting than a best-of-breed Algol derivative dominating the scene. > > The optimistic view is that there will be some kind of inflection point > > around 2020 or so. ?I could imagine a perfect storm of good things > > happening, like convergence on a single browser platform, > > You call that a perfect storm of good things. I call that sort of > intellectual and software monoculture a nightmare. > > I want a dozen browsers, not one of which is so common that web designers > can design for it and ignore the rest, not one browser so common that > nobody dares try anything new. > I don't want a monoculture any more than you do. When I talk about "convergence on a single browser platform", the thought was that web designers might not to have waste brain cycles on IE6 workarounds in 2020; instead, they could be working on actual, cutting edge design. By "convergence on a single browser platform", I was hoping for something like the Unix situation that we have now--there's still competition, there's still innovation around the edges, but you can generally rely on 90% of the platform to be predictable. > > nearly > > complete migration to Python 3, further maturity of JVM-based languages, > > etc., where the bar gets a little higher from what people expect from > > languages. ?Instead of fighting semicolons and braces, we start thinking > > bigger. ?It could also be some sort of hardware advance, like screen > > resolutions that are so amazing they let us completely rethink our views > > on terseness, punctuation, code organization, etc. > > And what of those with poor eyesight, or the blind? Are they to be > excluded from your "bigger" brave new world? I made my hypothetical advance ("screen resolutions") a little too narrow and hardware-focused. What I really meant to imagine is a world where eyesight and monitors stop being a bottleneck. Suppose people with normal eyesight had way, way better monitors, and suppose people with less than perfect eyesight had way more remedies available (laser surgery, brain implants, whatever). With those constraints removed, how would it change our view on what code should "look" like? Also, far more people are already held back by a lack of vision than a lack of eyesight. They can only imagine the worst scenarios with any suggestion of progress, they embrace the status quo despite its obvious shortcomings, etc. From showell30 at yahoo.com Thu Mar 22 12:12:59 2012 From: showell30 at yahoo.com (Steve Howell) Date: Thu, 22 Mar 2012 09:12:59 -0700 (PDT) Subject: Python is readable References: <4f612b19$0$1379$4fafbaef@reader2.news.tin.it> <8a77bf8d-b12f-442b-a1a3-479b5d66d366@tx8g2000pbc.googlegroups.com> <6af70db0-dc4a-48ee-9ee2-1a934846d5f2@r2g2000pbs.googlegroups.com> <32b8c4ae-2509-43df-abf0-0fb308be398f@oq7g2000pbb.googlegroups.com> <4f6ae931$0$29883$c3e8da3$5496439d@news.astraweb.com> Message-ID: <887ca72d-72f6-46f4-9af2-2cfd72d10212@t8g2000pbe.googlegroups.com> On Mar 22, 7:29?am, Nathan Rice wrote: > On Thu, Mar 22, 2012 at 9:17 AM, Chris Angelico wrote: > > On Thu, Mar 22, 2012 at 11:47 PM, Nathan Rice > > wrote: > >> Having one core language with > >> many DSLs that can interoperate is infinitely better than having many > >> languages that cannot. ?A language designed in such a way would also > >> prevent issues like the Python 2 -> 3 fiasco, because two versions of > >> a DSL can be separate, and code can reference them independently while > >> being able to interoperate. > > > This is either utterly impossible, or already available, depending on > > your point of view. > > Of course it is already available. ?It is called the laws of physics. > Everything we know of inter-operates in the context of physical > reality perfectly. > > > To have an infinitely-configurable program, you must make its > > configuration equivalent to writing code. There is already an > > infinitely-configurable program in Unix: "gcc config.c; ./a.out" takes > > a simple-format text file called "config.c" and processes it. > > It is true that infinite configuration requires that the configuration > be specified in the language of the program. ?What's the problem? > > > You want infinite DSLs? Behold! > > > $ ./module1 | ./module2 | ./module3 | ./module4 > > > Each one has a shebang that tells you what they are (Python 2, Python > > 3, something else entirely). There's a very strict interoperability > > protocol between the modules - they pass information around through > > stdout and stdin. You can write any module in any language, and you > > can rewrite module1 for Python 3 without affecting any other or the > > invocation sequence. > > It has always been possible to get from one point in space to another > point in space in finite time. ?Was the invention of the automobile > was redundant and unimportant? ?Obviously not, the characteristics of > the process matter. > The funny thing about the "automobile" is that, for all its impact, it's really just a better horse. Imagine in 1750 three futurists pondering how people in the future could solve the problem of physical separation: Futurist A: We'll breed a better horse. Futurist B: No, we should build a mechanical machine that's faster than a horse. Futurist C: What if we make it so that two people 10,000 miles away from each other can talk to each other like they're next door? The ironic thing is that telecommunication was more or less solved in the late 1800s or so, but in the 21 century, we still talk about "horsepower" for our people-moving machines. I think in 2012, when it comes to programming languages, we're still mostly breeding better horses. Nothing wrong with that, just an observation. From edreamleo at gmail.com Thu Mar 22 12:48:06 2012 From: edreamleo at gmail.com (Edward K. Ream) Date: Thu, 22 Mar 2012 09:48:06 -0700 (PDT) Subject: ANN: Leo 4.10 b1 released Message-ID: <568e1ced-1a06-439b-8c53-949c99d6aa97@n9g2000pbb.googlegroups.com> Leo 4.10 b1 is now available at: http://sourceforge.net/projects/leo/files/ Leo is a text editor, data organizer, project manager and much more. http://webpages.charter.net/edreamleo/intro.html Leo 4.10 contains 9 months of intense work on Leo. Several very important features are subtle; you could almost call them Easter Eggs, so please read the following notes carefully. The highlights of Leo 4.10: -------------------------- * Dozens of new and improved features and commands, including... - Tab completion now shows all @command & @button nodes. - Leo tabs may be detached from the main window. - The Open With menu now works. - The leoInspect module answers questions about Python code. - Leo can highlight the pane containing the focus. - The bigdash plugin searches across multiple files. - Improved abbreviation capabilities. - Improved handling of URL's. - Improved editing of non-Leo files. - Improvements create "weightless" unit testing. * Easier installation on MacOS. * Fixed almost 70 bugs. The Easter Eggs --------------- 1. Tab completion now shows all @command & @button nodes. Put all your common scripts in @command nodes in myLeoSettings.leo. Typing @c will remind you of the names of these scripts. You can execute the scripts by name without the "@command-" prefix. 2. Improved abbreviation capabilities. Virtually any kind of abbreviation is possible. For example, ~a to ?. 3. Improved handling of URL's. URL's can link to other Leo outlines. Ctrl-Click on nodes or URL's in body text to activate the URL. 4 Weightless unit testing. The mantra is edit, alt-4 (run-marked-unit-tests-externally), edit, alt-4,... Several seemingly innocuous changes made this work without an "friction". The result is a remarkable increase in productivity. Links: ------ Leo: http://webpages.charter.net/edreamleo/front.html Forum: http://groups.google.com/group/leo-editor Download: http://sourceforge.net/projects/leo/files/ Bzr: http://code.launchpad.net/leo-editor/ Quotes: http://webpages.charter.net/edreamleo/testimonials.html From steve+comp.lang.python at pearwood.info Thu Mar 22 13:18:17 2012 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 22 Mar 2012 17:18:17 GMT Subject: Python is readable References: <4f612b19$0$1379$4fafbaef@reader2.news.tin.it> <4f691f3d$0$29981$c3e8da3$5496439d@news.astraweb.com> <87d386lmai.fsf@benfinney.id.au> <8a77bf8d-b12f-442b-a1a3-479b5d66d366@tx8g2000pbc.googlegroups.com> <6af70db0-dc4a-48ee-9ee2-1a934846d5f2@r2g2000pbs.googlegroups.com> <32b8c4ae-2509-43df-abf0-0fb308be398f@oq7g2000pbb.googlegroups.com> <4f6ae931$0$29883$c3e8da3$5496439d@news.astraweb.com> Message-ID: <4f6b5ed9$0$29981$c3e8da3$5496439d@news.astraweb.com> On Thu, 22 Mar 2012 08:47:15 -0400, Nathan Rice wrote: > There is a concept in statistical/mathematical modeling called minimum > message length (a close analog is minimum description length), which > asserts that the optimum model for some set of information is the one > that minimizes the sum of the length of the model and the length of the > set described by that model. (1) Optimum in what sense? (2) What does this have to do with designing programming languages? This discussion sounds to me like the apocryphal story about the spherical cow. http://en.wikipedia.org/wiki/Spherical_cow > Clearly no model is going to be optimal > for every set of information. What I was alluding to in the post that > Steve Howell replied to was that we need to have a programming language > that is a model of models, then include a second order model as part of > the program. Having one core language with many DSLs that can > interoperate is infinitely better than having many languages that > cannot. Some people, when confronted with a problem, think "I know, I'll use a DSL." Now they have two problems. And some people think "I know, I'll use a meta-language with an infinite number of infinitely variable DSLs." Now they have an infinite number of problems. > A language designed in such a way would also prevent issues > like the Python 2 -> 3 fiasco, What fiasco? You've just lost an awful lot of credibility with me. -- Steven From steve+comp.lang.python at pearwood.info Thu Mar 22 13:26:11 2012 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 22 Mar 2012 17:26:11 GMT Subject: Best way to disconnect from ldap? References: <4F6A4D02.6020403@tim.thechases.com> Message-ID: <4f6b60b2$0$29981$c3e8da3$5496439d@news.astraweb.com> On Thu, 22 Mar 2012 08:14:47 -0500, Tycho Andersen wrote: > I've had similar experiences. In fact, in light of all this - why does > __del__ exist at all? Novice python users may (reasonably) assume it > behaves similarly to a C++ destructor (even though the docs warn > otherwise). What makes you think that novice Python users will be familiar with C++ destructors? Be careful about assuming that idioms in will be shared by all Python programmers, novice or expert. > Given that you can't trust __del__, is there a legitimate use case for > it? I've never found the need to write one. -- Steven From steve+comp.lang.python at pearwood.info Thu Mar 22 13:44:25 2012 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 22 Mar 2012 17:44:25 GMT Subject: Python is readable References: <4f612b19$0$1379$4fafbaef@reader2.news.tin.it> <87d386lmai.fsf@benfinney.id.au> <8a77bf8d-b12f-442b-a1a3-479b5d66d366@tx8g2000pbc.googlegroups.com> <6af70db0-dc4a-48ee-9ee2-1a934846d5f2@r2g2000pbs.googlegroups.com> <32b8c4ae-2509-43df-abf0-0fb308be398f@oq7g2000pbb.googlegroups.com> <4f6ae931$0$29883$c3e8da3$5496439d@news.astraweb.com> Message-ID: <4f6b64f9$0$29981$c3e8da3$5496439d@news.astraweb.com> On Thu, 22 Mar 2012 10:29:48 -0400, Nathan Rice wrote: [Snip a load of stuff about the laws of physics, infinity, and of course fractals.] I'm just surprised you didn't manage to fit quantum mechanics and "the interconnectedness of all things" into it :) > TL;DR there are a huge number of incompatible programming languages > because people are modeling a permutation rather than the input to a > permutation generating function. No offence Nathan, but I think you need to come back down to earth for air before you black out: http://www.joelonsoftware.com/articles/fog0000000018.html Or at least before *I* black out. Even if somebody manages to write your meta-language, you're going to run into the problem of who is going to be able to use it. The typical developer knows three, maybe four languages moderately well, if you include SQL and regexes as languages, and might have a nodding acquaintance with one or two more. With the radical changes you're suggesting, developers would need to be able to deal with some arbitrary number of different DSLs, and whatever meta-language is used to glue them together. There are a huge number of incompatible programming languages because language designers have different requirements, preferences, and styles; and because the state of the art of language design is very different in 2012 than it was in 1962. -- Steven From python.list at tim.thechases.com Thu Mar 22 13:54:29 2012 From: python.list at tim.thechases.com (Tim Chase) Date: Thu, 22 Mar 2012 12:54:29 -0500 Subject: Best way to disconnect from ldap? In-Reply-To: <4f6b60b2$0$29981$c3e8da3$5496439d@news.astraweb.com> References: <4F6A4D02.6020403@tim.thechases.com> <4f6b60b2$0$29981$c3e8da3$5496439d@news.astraweb.com> Message-ID: <4F6B6755.7000104@tim.thechases.com> On 03/22/12 12:26, Steven D'Aprano wrote: > On Thu, 22 Mar 2012 08:14:47 -0500, Tycho Andersen wrote: >> Given that you can't trust __del__, is there a legitimate >> use case for it? > > I've never found the need to write one. I've found the need to write them...then been frustrated by things falling out of namespace reach, and found that context managers do a much more reliable/understandable job, saving what little sanity I had left. ;-) So I'd say that __del__ was really only useful (for some sick, sick definition of "useful") in versions of Python before context-managers were readily available. -tkc From jcd at sdf.lonestar.org Thu Mar 22 14:12:32 2012 From: jcd at sdf.lonestar.org (J. Cliff Dyer) Date: Thu, 22 Mar 2012 14:12:32 -0400 Subject: Python classes: Simplify? In-Reply-To: <4F6B25D7.9020002@gmail.com> References: <4F6B25D7.9020002@gmail.com> Message-ID: <1332439952.4992.2.camel@jcdyer-laptop> The issue of explicitly naming a "self" parameter has been discussed in depth on a number of occasions. I recommend a google search for "python implicit self" for some of the reasons why it exists. Here's what Guido has to say about it: http://neopythonic.blogspot.com/2008/10/why-explicit-self-has-to-stay.html Cheers, Cliff On Thu, 2012-03-22 at 13:15 +0000, Andrea Crotti wrote: > On 03/22/2012 10:51 AM, Steven Lehar wrote: > > It seems to me that the Python class system is needlessly confusing. > > Am I missing something? > > > > > > For example in the class Complex given in the documentation > > > > > > class Complex: > > def __init__(self, realpart, imagpart): > > self.r = realpart > > self.i = imagpart > > > > > > x = Complex(3.0, -4.5) > > > > > > I initially found it profoundly confusing that __init__( ) calls for > > 3 arguments, but you call Complex( ) with 2. Furthermore, why not > > call the initialization function after the class name as is done in > > other languages? Isn't that the simplest conceptually? Demonstrating > > with the above example: > > > > > > class Complex: > > def Complex(realpart, imagpart): > > Complex.r = realpart > > Complex.i = imagpart > > > > > > x = Complex(3.0, -4.5) > > > > > > Is there a good reason why classes cannot be defined that way? > > (Besides the problem of backward-compatibility) > > > > > > Some time ago I saw some nasty hack that allowed you to drop the self > in the method declaration, > using some crazy metaclass trick, but that's really not a good idea ;) > > I agree that is counter-intuitive but just set your editor to do that > for you and you will be fine.. > > in my emacs > - s TAB -> self > - . TAB -> self. > - m TAB -> def ${1:method}(self$2): > $0 > > so I never actually write the self.. From nathan.alexander.rice at gmail.com Thu Mar 22 14:26:51 2012 From: nathan.alexander.rice at gmail.com (Nathan Rice) Date: Thu, 22 Mar 2012 14:26:51 -0400 Subject: Python is readable In-Reply-To: <4f6b5ed9$0$29981$c3e8da3$5496439d@news.astraweb.com> References: <4f612b19$0$1379$4fafbaef@reader2.news.tin.it> <4f691f3d$0$29981$c3e8da3$5496439d@news.astraweb.com> <87d386lmai.fsf@benfinney.id.au> <8a77bf8d-b12f-442b-a1a3-479b5d66d366@tx8g2000pbc.googlegroups.com> <6af70db0-dc4a-48ee-9ee2-1a934846d5f2@r2g2000pbs.googlegroups.com> <32b8c4ae-2509-43df-abf0-0fb308be398f@oq7g2000pbb.googlegroups.com> <4f6ae931$0$29883$c3e8da3$5496439d@news.astraweb.com> <4f6b5ed9$0$29981$c3e8da3$5496439d@news.astraweb.com> Message-ID: >> There is a concept in statistical/mathematical modeling called minimum >> message length (a close analog is minimum description length), which >> asserts that the optimum model for some set of information is the one >> that minimizes the sum of the length of the model and the length of the >> set described by that model. > > (1) Optimum in what sense? Oh, I don't know, the information theoretic one? Of course, if you're part of the department of redundancy department, that might seem to appear to look like a poor, weak, sub-optimal criterion for the purposes of evaluation of optimality, goodness and positive quality. If you're getting hung up on the fact that there are deep ties to data compression in this language, let me help you out. Imagine that instead of having a simple Boolean algebra of two values, the possible values ranged over a set of elementary concepts. You are then trying to come up with a set of compound concepts and a permutation of those concepts that can describe > (2) What does this have to do with designing programming languages? A program is a representation of knowledge (i.e. a model) which a machine has the ability to interpret. Let me know if you can't understand this, I'll break it down further for you. > This discussion sounds to me like the apocryphal story about the > spherical cow. > > http://en.wikipedia.org/wiki/Spherical_cow When you take the baton, you're supposed to keep running along the path in the same direction as the person who handed it to you. >> Clearly no model is going to be optimal >> for every set of information. ?What I was alluding to in the post that >> Steve Howell replied to was that we need to have a programming language >> that is a model of models, then include a second order model as part of >> the program. ?Having one core language with many DSLs that can >> interoperate is infinitely better than having many languages that >> cannot. > > Some people, when confronted with a problem, think "I know, I'll use a > DSL." Now they have two problems. Sure. When confronted with the problem of finding the area under a curve, using integral calculus is going to make things worse... I should just manually sum the infantesimals, from now until the end of time. > And some people think "I know, I'll use a meta-language with an infinite > number of infinitely variable DSLs." Now they have an infinite number of > problems. I'll agree with you, if we change that statement to say "an infinite number of possible problems, all isomorphic to each other." >> A language designed in such a way would also prevent issues >> like the Python 2 -> 3 fiasco, > > What fiasco? The extremely slow uptake? I don't really care one way or another but a lot of the devs have lamented the issue. > You've just lost an awful lot of credibility with me. I didn't lose anything, technically you lost some of your belief in my credibility. So, tautologically, you are the one that lost in this situation. > I'm just surprised you didn't manage to fit quantum mechanics and "the > interconnectedness of all things" into it :) Math/Logic are encompassing. I could draw analogies to quantum theory if you really wanted (category theory is great for this sort of thing). As for the interconnectedness of all things, that is quack language, I do science. >> TL;DR there are a huge number of incompatible programming languages >> because people are modeling a permutation rather than the input to a >> permutation generating function. > > No offence Nathan, but I think you need to come back down to earth for > air before you black out: > > http://www.joelonsoftware.com/articles/fog0000000018.html I read that article a long time ago, it was bullshit then, it is bullshit now. The only thing he gets right is that the Shannon information of a uniquely specified program is proportional to the code that would be required to generate it. Never mind that if a program meets a specification, you shouldn't care about any of the values used for unspecified parts of the program. If you care about the values, they should be specified. So, if Joel had said that the program was uniquely specified, or that none of the things that weren't specified require values in the programming language, he might have been kinda, sorta right. Of course, nobody cares enough to specify every last bit of minutiae in a program, and specifications change, so it is pretty much impossible to imagine either case ever actually occurring. > Or at least before *I* black out. Even if somebody manages to write your > meta-language, you're going to run into the problem of who is going to be > able to use it. The typical developer knows three, maybe four languages > moderately well, if you include SQL and regexes as languages, and might > have a nodding acquaintance with one or two more. Please don't black out Steven. I'm trying to encourage thought in interesting directions; you can't think when you're unconscious. Lets draw the analogy to mathematicians. If a mathematician wants to solve a problem, he can cruise along at a pretty good clip as long as he understands the theories of the problem domain. If he runs into a portion of the problem domain that requires theories he isn't familiar with, he must trot off to the library for a book, or read some journal articles. Once he's absorbed the theory, he can continue to work on solving the problem, and if he encounters other problems that require the theory, he is set. I can give you another analogy that is even clearer... What happens if there are several words in a paragraph you don't know? You go to the dictionary to look them up, you now know the words, they are part of your vocabulary, and life is good. Finally, what about when you want to use a library in a programming language you already know? That is a domain specific language that just so happens to have the syntax and semantics of the base language as a subset of its own syntax and semantics. Part of the problem here, I think, is that you imagine each DSL to have radically different syntax and semantics. That is unnecessary, and actually contrary to what I am proposing. > With the radical changes you're suggesting, developers would need to be > able to deal with some arbitrary number of different DSLs, and whatever > meta-language is used to glue them together. They already do that (replace DSL with library here, again). The problem is that the meta-language lacks expressiveness and flexibility because it is modeling the permutation rather than the permutation generator. > There are a huge number of incompatible programming languages because > language designers have different requirements, preferences, and styles; > and because the state of the art of language design is very different in > 2012 than it was in 1962. Every language goes to 1s and 0s in the end. Clearly 1s and 0s are capable of closing the space of requirements, preferences and styles. This is the case because programs are information (i.e. encoded knowledge). All I'm proposing is an intermediate representation language that describes the higher order structure and dynamics of knowledge in a clean, human readable format. Mathematicians realized this was a good idea and started down this path something like 140 years ago (minus the human readable ;). They aren't done yet, so clearly any meta language someone develops would similarly be a work in progress, but the nice thing is that backwards compatibility would never be broken; as deeper theorems are exposed, previous results can be recast as specific cases of them. From ralph.heinkel at web.de Thu Mar 22 14:34:58 2012 From: ralph.heinkel at web.de (Ralph Heinkel) Date: Thu, 22 Mar 2012 11:34:58 -0700 (PDT) Subject: Compiling Python (modules) on 64bit Windows - which compiler suite? In-Reply-To: <13033772.7.1332374778471.JavaMail.geo-discussion-forums@ynjk1> References: <808abad4-3ab3-4336-8a31-2f88eb28be01@v22g2000vby.googlegroups.com> <13033772.7.1332374778471.JavaMail.geo-discussion-forums@ynjk1> Message-ID: <11748169.44.1332441298178.JavaMail.geo-discussion-forums@vbbp15> > > See "Compiling 64-bit extension modules on Windows" at . It applies to non-Cython extensions as well. > > MinGW-w64 also works, but you'll have to generate and use libpythonXX.a and libmsvcr90.a link libraries. > > Christoph Thanks to everyone who has replied to my question. Especially for the link/hint to use the .NET SDK which indeed seems to provide the right tools for 64bit compilation. I'm going to try this and report back here. Cheers, Ralph From rosuav at gmail.com Thu Mar 22 15:08:28 2012 From: rosuav at gmail.com (Chris Angelico) Date: Fri, 23 Mar 2012 06:08:28 +1100 Subject: Python is readable In-Reply-To: References: <4f612b19$0$1379$4fafbaef@reader2.news.tin.it> <4f691f3d$0$29981$c3e8da3$5496439d@news.astraweb.com> <87d386lmai.fsf@benfinney.id.au> <8a77bf8d-b12f-442b-a1a3-479b5d66d366@tx8g2000pbc.googlegroups.com> <6af70db0-dc4a-48ee-9ee2-1a934846d5f2@r2g2000pbs.googlegroups.com> <32b8c4ae-2509-43df-abf0-0fb308be398f@oq7g2000pbb.googlegroups.com> <4f6ae931$0$29883$c3e8da3$5496439d@news.astraweb.com> <4f6b5ed9$0$29981$c3e8da3$5496439d@news.astraweb.com> Message-ID: On Fri, Mar 23, 2012 at 5:26 AM, Nathan Rice wrote: [regarding Python 2 -> 3] > The extremely slow uptake? ?I don't really care one way or another but > a lot of the devs have lamented the issue. By your plan, the slow uptake would be accepted, even encouraged. In fact, your plan is effectively equivalent to simply having both Python 2 and Python 3 installed on every computer, plus having some way for them to interact. ChrisA From rosuav at gmail.com Thu Mar 22 15:14:46 2012 From: rosuav at gmail.com (Chris Angelico) Date: Fri, 23 Mar 2012 06:14:46 +1100 Subject: Number of languages known [was Re: Python is readable] - somewhat OT Message-ID: On Fri, Mar 23, 2012 at 4:44 AM, Steven D'Aprano wrote: > The typical developer knows three, maybe four languages > moderately well, if you include SQL and regexes as languages, and might > have a nodding acquaintance with one or two more. I'm not entirely sure what you mean by "moderately well", nor "languages", but I'm of the opinion that a good developer should be able to learn a new language very efficiently. Do you count Python 2 and 3 as the same language? What about all the versions of the C standard? In any case, though, I agree that there's a lot of people professionally writing code who would know about the 3-4 that you say. I'm just not sure that they're any good at coding, even in those few languages. All the best people I've ever known have had experience with quite a lot of languages. ChrisA From rosuav at gmail.com Thu Mar 22 15:21:12 2012 From: rosuav at gmail.com (Chris Angelico) Date: Fri, 23 Mar 2012 06:21:12 +1100 Subject: Python is readable In-Reply-To: References: <4f612b19$0$1379$4fafbaef@reader2.news.tin.it> <4f691f3d$0$29981$c3e8da3$5496439d@news.astraweb.com> <87d386lmai.fsf@benfinney.id.au> <8a77bf8d-b12f-442b-a1a3-479b5d66d366@tx8g2000pbc.googlegroups.com> <6af70db0-dc4a-48ee-9ee2-1a934846d5f2@r2g2000pbs.googlegroups.com> <32b8c4ae-2509-43df-abf0-0fb308be398f@oq7g2000pbb.googlegroups.com> <4f6ae931$0$29883$c3e8da3$5496439d@news.astraweb.com> Message-ID: On Fri, Mar 23, 2012 at 1:29 AM, Nathan Rice wrote: > For example, your ability to reason about the behavior of the system > you posited as a whole is limited. ?Are there parts of the different > modules that can execute concurrently? ?Is the output of module1 > guaranteed to be acceptable as the input for module2? ?Is part of > module3 redundant (and thus avoidable) given some conditions in > module1? ?If you make a change in module2 what effect does that have > on module3 and module4? ?What if you need to go back and forth between > module2 and module3 until some criterion is met before you transition > to module4? ?What if you sometimes want to run module2b instead of > module2? Pipes allow different modules to execute concurrently (except on DOS and maybe Windows, haven't checked). Nothing in ANY language "guarantees" acceptable input, but protocolling would do that for you. If part of module3 is redundant, you don't call it. If you make a change to one that affects others, then you fix the others, same as in any other coding system (or non-coding system - if you upgrade your hardware from an 8086 with 1MB of memory to a modern box with >4GB, you'll have to rewrite your code to take advantage of it). The (somewhat stupid) protocol I suggested allows you to go between 2 and 3 before going to 4. If you want module2b, you add it to the chain and call on it. Yep, Unix solved all your problems back in the 1970s. ChrisA From tjreedy at udel.edu Thu Mar 22 15:27:37 2012 From: tjreedy at udel.edu (Terry Reedy) Date: Thu, 22 Mar 2012 15:27:37 -0400 Subject: Best way to disconnect from ldap? In-Reply-To: <4F6B6755.7000104@tim.thechases.com> References: <4F6A4D02.6020403@tim.thechases.com> <4f6b60b2$0$29981$c3e8da3$5496439d@news.astraweb.com> <4F6B6755.7000104@tim.thechases.com> Message-ID: On 3/22/2012 1:54 PM, Tim Chase wrote: > On 03/22/12 12:26, Steven D'Aprano wrote: >> On Thu, 22 Mar 2012 08:14:47 -0500, Tycho Andersen wrote: >>> Given that you can't trust __del__, is there a legitimate >>> use case for it? It is part of original or early Python and pretty well superceded by cyclic gc (which does not work for object with __del__ *because* of the unreliability), explicit close methods, and now context managers. >> >> I've never found the need to write one. > > I've found the need to write them...then been frustrated by things > falling out of namespace reach, and found that context managers do a > much more reliable/understandable job, saving what little sanity I had > left. ;-) Which is one reason they were added ;-). > So I'd say that __del__ was really only useful (for some sick, sick > definition of "useful") in versions of Python before context-managers > were readily available. And before cyclic gc, which does a better job of ordering deletions. -- Terry Jan Reedy From nathan.alexander.rice at gmail.com Thu Mar 22 15:33:28 2012 From: nathan.alexander.rice at gmail.com (Nathan Rice) Date: Thu, 22 Mar 2012 15:33:28 -0400 Subject: Python is readable In-Reply-To: References: <4f612b19$0$1379$4fafbaef@reader2.news.tin.it> <4f691f3d$0$29981$c3e8da3$5496439d@news.astraweb.com> <87d386lmai.fsf@benfinney.id.au> <8a77bf8d-b12f-442b-a1a3-479b5d66d366@tx8g2000pbc.googlegroups.com> <6af70db0-dc4a-48ee-9ee2-1a934846d5f2@r2g2000pbs.googlegroups.com> <32b8c4ae-2509-43df-abf0-0fb308be398f@oq7g2000pbb.googlegroups.com> <4f6ae931$0$29883$c3e8da3$5496439d@news.astraweb.com> Message-ID: >> For example, your ability to reason about the behavior of the system >> you posited as a whole is limited. ?Are there parts of the different >> modules that can execute concurrently? ?Is the output of module1 >> guaranteed to be acceptable as the input for module2? ?Is part of >> module3 redundant (and thus avoidable) given some conditions in >> module1? ?If you make a change in module2 what effect does that have >> on module3 and module4? ?What if you need to go back and forth between >> module2 and module3 until some criterion is met before you transition >> to module4? ?What if you sometimes want to run module2b instead of >> module2? > > Pipes allow different modules to execute concurrently (except on DOS > and maybe Windows, haven't checked). Nothing in ANY language > "guarantees" acceptable input, but protocolling would do that for you. > If part of module3 is redundant, you don't call it. If you make a > change to one that affects others, then you fix the others, same as in > any other coding system (or non-coding system - if you upgrade your > hardware from an 8086 with 1MB of memory to a modern box with >4GB, > you'll have to rewrite your code to take advantage of it). The > (somewhat stupid) protocol I suggested allows you to go between 2 and > 3 before going to 4. If you want module2b, you add it to the chain and > call on it. > > Yep, Unix solved all your problems back in the 1970s. Pipes do not provide any fine grained control over the concurrent behavior. If you want to change the order of calls, suddenly you have to write a bash script (with its own set of issues), etc. Unix solved these problems in much the same way that the evolution of appendages solved the problem of changing location from one point to another before the automobile. The process matters. From rosuav at gmail.com Thu Mar 22 15:48:01 2012 From: rosuav at gmail.com (Chris Angelico) Date: Fri, 23 Mar 2012 06:48:01 +1100 Subject: Python is readable In-Reply-To: References: <4f612b19$0$1379$4fafbaef@reader2.news.tin.it> <4f691f3d$0$29981$c3e8da3$5496439d@news.astraweb.com> <87d386lmai.fsf@benfinney.id.au> <8a77bf8d-b12f-442b-a1a3-479b5d66d366@tx8g2000pbc.googlegroups.com> <6af70db0-dc4a-48ee-9ee2-1a934846d5f2@r2g2000pbs.googlegroups.com> <32b8c4ae-2509-43df-abf0-0fb308be398f@oq7g2000pbb.googlegroups.com> <4f6ae931$0$29883$c3e8da3$5496439d@news.astraweb.com> Message-ID: On Fri, Mar 23, 2012 at 6:33 AM, Nathan Rice wrote: > Pipes do not provide any fine grained control over the concurrent > behavior. ?If you want to change the order of calls, suddenly you have > to write a bash script (with its own set of issues), etc. Go back to my original post. I posited a means of communication which allows one module to "call" a function in another module, purely by writing to stdout. All four (or however many) modules would run concurrently, and be waiting on stdin most of the time. Of course, the same technique could be used for true concurrency; with such a simple message-passing technique, there's no reason to wait for your response before continuing. ChrisA From rodrick.brown at gmail.com Thu Mar 22 15:48:44 2012 From: rodrick.brown at gmail.com (Rodrick Brown) Date: Thu, 22 Mar 2012 15:48:44 -0400 Subject: Odd strip behavior Message-ID: <5B2CBFB0-DC2D-47E1-978F-59E47EB3A757@gmail.com> #!/usr/bin/python def main(): str1='this is a test' str2='t' print "".join([ c for c in str1 if c not in str2 ]) print(str1.strip(str2)) if __name__ == '__main__': main() ./remove_str.py his is a es his is a tes Why wasnt the t removed ? Sent from my iPhone From rosuav at gmail.com Thu Mar 22 15:49:54 2012 From: rosuav at gmail.com (Chris Angelico) Date: Fri, 23 Mar 2012 06:49:54 +1100 Subject: Python is readable In-Reply-To: References: <4f612b19$0$1379$4fafbaef@reader2.news.tin.it> <4f691f3d$0$29981$c3e8da3$5496439d@news.astraweb.com> <87d386lmai.fsf@benfinney.id.au> <8a77bf8d-b12f-442b-a1a3-479b5d66d366@tx8g2000pbc.googlegroups.com> <6af70db0-dc4a-48ee-9ee2-1a934846d5f2@r2g2000pbs.googlegroups.com> <32b8c4ae-2509-43df-abf0-0fb308be398f@oq7g2000pbb.googlegroups.com> <4f6ae931$0$29883$c3e8da3$5496439d@news.astraweb.com> Message-ID: On Fri, Mar 23, 2012 at 6:33 AM, Nathan Rice wrote: > Pipes do not provide any fine grained control over the concurrent > behavior. ?If you want to change the order of calls... And to clarify: The "order of calls" in what I described is merely the order of initialization. It's like the order of your imports at the top of a Python script, and should have equally no significance. And a module can import other modules by dropping to another chain of pipes in exactly the same way. It'd work! I can't vouch for performance, of course... ChrisA From arnodel at gmail.com Thu Mar 22 15:53:13 2012 From: arnodel at gmail.com (Arnaud Delobelle) Date: Thu, 22 Mar 2012 19:53:13 +0000 Subject: Odd strip behavior In-Reply-To: <5B2CBFB0-DC2D-47E1-978F-59E47EB3A757@gmail.com> References: <5B2CBFB0-DC2D-47E1-978F-59E47EB3A757@gmail.com> Message-ID: On Mar 22, 2012 7:49 PM, "Rodrick Brown" wrote: > > #!/usr/bin/python > > def main(): > > str1='this is a test' > str2='t' > > print "".join([ c for c in str1 if c not in str2 ]) > print(str1.strip(str2)) > > if __name__ == '__main__': > main() > > ./remove_str.py > his is a es > his is a tes > > Why wasnt the t removed ? Try help(ste.strip) -- Arnaud -------------- next part -------------- An HTML attachment was scrubbed... URL: From ramit.prasad at jpmorgan.com Thu Mar 22 15:54:37 2012 From: ramit.prasad at jpmorgan.com (Prasad, Ramit) Date: Thu, 22 Mar 2012 19:54:37 +0000 Subject: Odd strip behavior In-Reply-To: <5B2CBFB0-DC2D-47E1-978F-59E47EB3A757@gmail.com> References: <5B2CBFB0-DC2D-47E1-978F-59E47EB3A757@gmail.com> Message-ID: <5B80DD153D7D744689F57F4FB69AF474026C6C6D@SCACMX008.exchad.jpmchase.net> > str1='this is a test' > str2='t' > > print "".join([ c for c in str1 if c not in str2 ]) > print(str1.strip(str2)) > > if __name__ == '__main__': > main() > > ./remove_str.py > his is a es > his is a tes > > Why wasnt the t removed ? This is not odd behavior, you just do not understand what strip does. :) The behavior is listed on the API. I highly recommend you take time to become familiar with it. http://docs.python.org/library/stdtypes.html#string-methods str.strip([chars]) Return a copy of the string with the leading and trailing characters removed. The chars argument is a string specifying the set of characters to be removed. If omitted or None, the chars argument defaults to removing whitespace. The chars argument is not a prefix or suffix; rather, all combinations of its values are stripped: >>> >>> ' spacious '.strip() 'spacious' >>> 'www.example.com'.strip('cmowz.') 'example' Changed in version 2.2.2: Support for the chars argument. Ramit Ramit Prasad | JPMorgan Chase Investment Bank | Currencies Technology 712 Main Street | Houston, TX 77002 work phone: 713 - 216 - 5423 -- > -----Original Message----- > From: python-list-bounces+ramit.prasad=jpmorgan.com at python.org > [mailto:python-list-bounces+ramit.prasad=jpmorgan.com at python.org] On Behalf > Of Rodrick Brown > Sent: Thursday, March 22, 2012 2:49 PM > To: python-list at python.org > Subject: Odd strip behavior > > #!/usr/bin/python > > def main(): > > Sent from my iPhone > -- > http://mail.python.org/mailman/listinfo/python-list This email is confidential and subject to important disclaimers and conditions including on offers for the purchase or sale of securities, accuracy and completeness of information, viruses, confidentiality, legal privilege, and legal entity disclaimers, available at http://www.jpmorgan.com/pages/disclosures/email. From kiuhnm03.4t.yahoo.it Thu Mar 22 15:56:19 2012 From: kiuhnm03.4t.yahoo.it (Kiuhnm) Date: Thu, 22 Mar 2012 20:56:19 +0100 Subject: Odd strip behavior In-Reply-To: References: Message-ID: <4f6b83e3$0$1389$4fafbaef@reader1.news.tin.it> On 3/22/2012 20:48, Rodrick Brown wrote: > #!/usr/bin/python > > def main(): > > str1='this is a test' > str2='t' > > print "".join([ c for c in str1 if c not in str2 ]) > print(str1.strip(str2)) > > if __name__ == '__main__': > main() > > ./remove_str.py > his is a es > his is a tes > > Why wasnt the t removed ? Because it's not a leading or trailing character. Kiuhnm From dstein64 at gmail.com Thu Mar 22 15:59:25 2012 From: dstein64 at gmail.com (Daniel Steinberg) Date: Thu, 22 Mar 2012 15:59:25 -0400 Subject: Odd strip behavior In-Reply-To: <5B2CBFB0-DC2D-47E1-978F-59E47EB3A757@gmail.com> References: <5B2CBFB0-DC2D-47E1-978F-59E47EB3A757@gmail.com> Message-ID: strip() removes leading and trailing characters, which is why the 't' in the middle of the string was not removed. To remove the 't' in the middle, str1.replace('t','') is one option. On 3/22/12 3:48 PM, Rodrick Brown wrote: > #!/usr/bin/python > > def main(): > > str1='this is a test' > str2='t' > > print "".join([ c for c in str1 if c not in str2 ]) > print(str1.strip(str2)) > > if __name__ == '__main__': > main() > > ./remove_str.py > his is a es > his is a tes > > Why wasnt the t removed ? > Sent from my iPhone From rodrick.brown at gmail.com Thu Mar 22 16:04:59 2012 From: rodrick.brown at gmail.com (Rodrick Brown) Date: Thu, 22 Mar 2012 16:04:59 -0400 Subject: Odd strip behavior In-Reply-To: References: <5B2CBFB0-DC2D-47E1-978F-59E47EB3A757@gmail.com> Message-ID: <775DE2D7-B96D-49F5-B6EA-B58BEE1B7F80@gmail.com> On Mar 22, 2012, at 3:53 PM, Arnaud Delobelle wrote: > > On Mar 22, 2012 7:49 PM, "Rodrick Brown" wrote: > > > > #!/usr/bin/python > > > > def main(): > > > > str1='this is a test' > > str2='t' > > > > print "".join([ c for c in str1 if c not in str2 ]) > > print(str1.strip(str2)) > > > > if __name__ == '__main__': > > main() > > > > ./remove_str.py > > his is a es > > his is a tes > > > > Why wasnt the t removed ? > > Try help(ste.strip) > It clearly states "if chars is given and not None, remove characters in chars instead. Does it mean remove only the first occurrence of char? That's the behavior I'm seeing. > -- > Arnaud -------------- next part -------------- An HTML attachment was scrubbed... URL: From ian.g.kelly at gmail.com Thu Mar 22 16:06:21 2012 From: ian.g.kelly at gmail.com (Ian Kelly) Date: Thu, 22 Mar 2012 14:06:21 -0600 Subject: Odd strip behavior In-Reply-To: <5B2CBFB0-DC2D-47E1-978F-59E47EB3A757@gmail.com> References: <5B2CBFB0-DC2D-47E1-978F-59E47EB3A757@gmail.com> Message-ID: On Thu, Mar 22, 2012 at 1:48 PM, Rodrick Brown wrote: > Why wasnt the t removed ? Because str.strip() only removes leading or trailing characters. If you want to remove all the t's, use str.replace: 'this is a test'.replace('t', '') Cheers, Ian From arnodel at gmail.com Thu Mar 22 16:18:22 2012 From: arnodel at gmail.com (Arnaud Delobelle) Date: Thu, 22 Mar 2012 20:18:22 +0000 Subject: Odd strip behavior In-Reply-To: <775DE2D7-B96D-49F5-B6EA-B58BEE1B7F80@gmail.com> References: <5B2CBFB0-DC2D-47E1-978F-59E47EB3A757@gmail.com> <775DE2D7-B96D-49F5-B6EA-B58BEE1B7F80@gmail.com> Message-ID: On 22 March 2012 20:04, Rodrick Brown wrote: > > On Mar 22, 2012, at 3:53 PM, Arnaud Delobelle wrote: > Try help(ste.strip) > > It clearly states "if chars is given and not None, remove characters in > chars instead. > > Does it mean remove only the first occurrence of char? That's the behavior > I'm seeing. The key words in the docstring are "leading and trailing" -- Arnaud From tycho at tycho.ws Thu Mar 22 17:02:15 2012 From: tycho at tycho.ws (Tycho Andersen) Date: Thu, 22 Mar 2012 16:02:15 -0500 Subject: Best way to disconnect from ldap? In-Reply-To: <4f6b60b2$0$29981$c3e8da3$5496439d@news.astraweb.com> References: <4F6A4D02.6020403@tim.thechases.com> <4f6b60b2$0$29981$c3e8da3$5496439d@news.astraweb.com> Message-ID: <20120322210215.GJ19657@ccapuser-ubuntu.WICOURTS.GOV> On Thu, Mar 22, 2012 at 05:26:11PM +0000, Steven D'Aprano wrote: > On Thu, 22 Mar 2012 08:14:47 -0500, Tycho Andersen wrote: > > > I've had similar experiences. In fact, in light of all this - why does > > __del__ exist at all? Novice python users may (reasonably) assume it > > behaves similarly to a C++ destructor (even though the docs warn > > otherwise). > > What makes you think that novice Python users will be familiar with C++ > destructors? I don't, really. It's just natural to assume that __del__ is the "opposite" of __init__, when it's really not (i.e. every object is __init__ed, but not every object is destructed and thus __del__'d). Novice programmers may make this assumption (indeed, many experienced programmers do as well). > Be careful about assuming that idioms in > will be shared by all Python programmers, novice or expert. Yeah, C++ was the first language which has destructors that came to mind. It's certainly not my favorite ;-) \t From steve+comp.lang.python at pearwood.info Thu Mar 22 21:11:49 2012 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 23 Mar 2012 01:11:49 GMT Subject: Number of languages known [was Re: Python is readable] - somewhat OT References: Message-ID: <4f6bcdd5$0$29981$c3e8da3$5496439d@news.astraweb.com> On Fri, 23 Mar 2012 06:14:46 +1100, Chris Angelico wrote: > On Fri, Mar 23, 2012 at 4:44 AM, Steven D'Aprano > wrote: >> The typical developer knows three, maybe four languages moderately >> well, if you include SQL and regexes as languages, and might have a >> nodding acquaintance with one or two more. > > I'm not entirely sure what you mean by "moderately well", I mean more than "poorly" but less than "very well". Until somebody invents a universal, objective scale for rating relative knowledge in a problem domain (in this case, knowledge of a programming language), we're stuck with fuzzy quantities like "guru", "expert", "deep and complete knowledge of the language and its idioms", all the way down to "can write Hello World" and "never used or seen the language before". Here's a joke version: http://www.ariel.com.au/jokes/The_Evolution_of_a_Programmer.html and here's a more serious version: http://www.yacoset.com/Home/signs-that-you-re-a-bad-programmer > nor > "languages", but I'm of the opinion that a good developer should be able > to learn a new language very efficiently. Should be, absolutely. Does, perhaps not. Some good developers spend their entire life working in one language and have become expert on every part of it. Some learn twenty different languages, and barely get beyond "Hello World" in any of them. > Do you count Python 2 and 3 as the same language? Absolutely. > What about all the versions of the C standard? Probably. I'm not familiar with the C standard. > In any case, though, I agree that there's a lot of people professionally > writing code who would know about the 3-4 that you say. I'm just not > sure that they're any good at coding, even in those few languages. All > the best people I've ever known have had experience with quite a lot of > languages. I dare say that experience with many languages is a good thing, but it's not a prerequisite for mastery of a single language. In any case, I'm not talking about the best developers. I'm talking about the typical developer, who by definition is just average. They probably know reasonably well one to three of the half dozen most popular languages (VB, Java, C, C+, Javascript, PHP, Perl?) plus regexes and SQL, and are unlikely to know any of Prolog, Lisp, Haskell, Hypertalk, Mercury, Cobra, Smalltalk, Ada, APL, Emerald, Inform, Forth, ... Or even in most cases *heard* of them. -- Steven From showell30 at yahoo.com Thu Mar 22 22:42:20 2012 From: showell30 at yahoo.com (Steve Howell) Date: Thu, 22 Mar 2012 19:42:20 -0700 (PDT) Subject: Python is readable References: <4f612b19$0$1379$4fafbaef@reader2.news.tin.it> <6af70db0-dc4a-48ee-9ee2-1a934846d5f2@r2g2000pbs.googlegroups.com> <32b8c4ae-2509-43df-abf0-0fb308be398f@oq7g2000pbb.googlegroups.com> <4f6ae931$0$29883$c3e8da3$5496439d@news.astraweb.com> <4f6b64f9$0$29981$c3e8da3$5496439d@news.astraweb.com> Message-ID: <94d35431-0d4f-44d8-85fb-93671829a554@m10g2000pbk.googlegroups.com> On Mar 22, 10:44?am, Steven D'Aprano wrote: > On Thu, 22 Mar 2012 10:29:48 -0400, Nathan Rice wrote: > > Or at least before *I* black out. Even if somebody manages to write your > meta-language, you're going to run into the problem of who is going to be > able to use it. The typical developer knows three, maybe four languages > moderately well, if you include SQL and regexes as languages, and might > have a nodding acquaintance with one or two more. > Maybe I'm not the typical developer, but I think "three, maybe four" is a very low estimate of the number of languages that the typical developer confronts in his lifetime. Just in the last couple weeks I've looked at code in all these languages: Python2 PHP JavaScript CoffeeScript C Perl Shell (bash) Regex (three variants--bash, Python, PHP) awk (albeit trivially) SQL (two variants--MySQL and Hive) HTML CSS With the exception of awk, I know all of the above languages in some depth, way beyond a "nodding acquaintance." I'm not taking any sides on the meta-language debate in pointing this out; I'm merely suggesting that we do live in a bit of a Tower of Babel. I'm only arguing with the numbers in your premise; maybe even if you underestimate the number of languages that typical devs consume in 2012, you could still draw the same valid conclusions overall with a slightly more accurate estimate. > There are a huge number of incompatible programming languages because > language designers have different requirements, preferences, and styles; > and because the state of the art of language design is very different in > 2012 than it was in 1962. Do you think we'll always have a huge number of incompatible programming languages? I agree with you that it's a fact of life in 2012, but will it be a fact of life in 2062? From showell30 at yahoo.com Thu Mar 22 22:48:19 2012 From: showell30 at yahoo.com (Steve Howell) Date: Thu, 22 Mar 2012 19:48:19 -0700 (PDT) Subject: Number of languages known [was Re: Python is readable] - somewhat OT References: <4f6bcdd5$0$29981$c3e8da3$5496439d@news.astraweb.com> Message-ID: On Mar 22, 6:11?pm, Steven D'Aprano wrote: > On Fri, 23 Mar 2012 06:14:46 +1100, Chris Angelico wrote: > > In any case, though, I agree that there's a lot of people professionally > > writing code who would know about the 3-4 that you say. I'm just not > > sure that they're any good at coding, even in those few languages. All > > the best people I've ever known have had experience with quite a lot of > > languages. > > I dare say that experience with many languages is a good thing, but it's > not a prerequisite for mastery of a single language. > > In any case, I'm not talking about the best developers. I'm talking about > the typical developer, who by definition is just average. They probably > know reasonably well one to three of the half dozen most popular > languages (VB, Java, C, C+, Javascript, PHP, Perl?) plus regexes and SQL, > and are unlikely to know any of Prolog, Lisp, Haskell, Hypertalk, > Mercury, Cobra, Smalltalk, Ada, APL, Emerald, Inform, Forth, ... I love how you can rattle off 20 or so languages, just off the top of your head, and not even mention Ruby. ;) (Although Perl was close enough.) From showell30 at yahoo.com Thu Mar 22 23:11:38 2012 From: showell30 at yahoo.com (Steve Howell) Date: Thu, 22 Mar 2012 20:11:38 -0700 (PDT) Subject: Number of languages known [was Re: Python is readable] - somewhat OT References: Message-ID: <1c6c9ad8-95bd-4dd1-84d7-692a37f5d18e@oq7g2000pbb.googlegroups.com> On Mar 22, 12:14?pm, Chris Angelico wrote: > On Fri, Mar 23, 2012 at 4:44 AM, Steven D'Aprano > > wrote: > > The typical developer knows three, maybe four languages > > moderately well, if you include SQL and regexes as languages, and might > > have a nodding acquaintance with one or two more. > > I'm not entirely sure what you mean by "moderately well", nor > "languages", but I'm of the opinion that a good developer should be > able to learn a new language very efficiently. Do you count Python 2 > and 3 as the same language? What about all the versions of the C > standard? > Not only is it hard to define what we precisely mean when we say "[knows] moderately well" or "[n number of] languages", but what in the world are we talking about with respect to "the typical developer"? How do we even begin to define that term? From rustompmody at gmail.com Thu Mar 22 23:20:00 2012 From: rustompmody at gmail.com (rusi) Date: Thu, 22 Mar 2012 20:20:00 -0700 (PDT) Subject: Python is readable References: <4f612b19$0$1379$4fafbaef@reader2.news.tin.it> <6af70db0-dc4a-48ee-9ee2-1a934846d5f2@r2g2000pbs.googlegroups.com> <32b8c4ae-2509-43df-abf0-0fb308be398f@oq7g2000pbb.googlegroups.com> <4f6ae931$0$29883$c3e8da3$5496439d@news.astraweb.com> <4f6b64f9$0$29981$c3e8da3$5496439d@news.astraweb.com> <94d35431-0d4f-44d8-85fb-93671829a554@m10g2000pbk.googlegroups.com> Message-ID: <9c7ce4fd-9530-4c34-a88e-446bab7c31ab@sv8g2000pbc.googlegroups.com> On Mar 23, 7:42?am, Steve Howell wrote: > Do you think we'll always have a huge number of incompatible > programming languages? ?I agree with you that it's a fact of life in > 2012, but will it be a fact of life in 2062? It will be a fact of life wherever Godels theorem is; which put simplistically is: consistency and completeness cannot coexist. This is the 'logic-generator' for the mess in programming languages. Put in more general terms: Completeness is an 'adding' process Consistency is a 'subtracting' process Running the two together, convergence is hopeless. In programming language terms the pull is between simplicity and expressivity/power. From dwrdx5 at gmail.com Thu Mar 22 23:23:55 2012 From: dwrdx5 at gmail.com (Edward Xu) Date: Fri, 23 Mar 2012 11:23:55 +0800 Subject: Python ctypes - Memory read Error when calling a function in a DLL Message-ID: Hi all, I'm writing a script to control a *PCMCIA* device, the driver provided by the vendor is a dll file. I just want to call functions in it, but i just don't know why I keep getting a *[**The instruction at "0x7c9108d3" referenced memory at "0xfffffff8". The memory could not be "read"**]. *Here is the documents say: *//declaration* *XLstatus xlGetDriverConfig(XLdriverConfig *pDriverConfig) * * * *typedef struct s_xl_driver_config { * * unsigned int dllVersion; * * unsigned int channelCount; * * unsigned int reserved[10]; * * XLchannelConfig channel[XL_CONFIG_MAX_CHANNELS]; * *} XLdriverConfig; * * * *//types* *typedef struct s_xl_channel_config { * * * * char name [XL_MAX_LENGTH + 1]; * * unsigned char hwType; * * unsigned char hwIndex; * * unsigned char hwChannel; * * unsigned short transceiverType; * * unsigned int transceiverState; * * unsigned char channelIndex; * * * * XLuint64 channelMask; //here * * unsigned int channelCapabilities; * * unsigned int channelBusCapabilities; * * unsigned char isOnBus; * * unsigned int connectedBusType; * * XLbusParams busParams; * * unsigned int driverVersion; * * unsigned int interfaceVersion; * * unsigned int raw_data[10]; * * unsigned int serialNumber; * * unsigned int articleNumber; * * char transceiverName [XL_MAX_LENGTH + 1]; * * unsigned int specialCabFlags; * * unsigned int dominantTimeout; * * unsigned int reserved[8]; * *} XLchannelConfig; * * * *typedef unsigned __int64 XLuint64;* * * *typedef struct { * * unsigned int busType;* * union {* * struct {* * unsigned int bitRate;* * unsigned char sjw;* * unsigned char tseg1;* * unsigned char tseg2;* * unsigned char sam; // 1 or 3* * unsigned char outputMode;* * } can;* * struct {* * unsigned int activeSpeedGrade;* * unsigned int compatibleSpeedGrade;* * } most;* * unsigned char raw[32];* * }data;* *} XLbusParams; * There is my python script below: * from ctypes import * vxlapi = WinDLL("vxlapi.dll") PyxlGetDriverConfig = vxlapi.xlGetDriverConfig class PyXLchannelConfig(Structure): _fields_ = [("Pyname",c_char*32), ("PyhwType",c_ubyte), ("PyhwIndex",c_ubyte), ("PyhwChannel",c_ubyte), ("PytransceiverType",c_ushort), ("PytransceiverState",c_ushort), ("PyconfigError",c_ushort), ("PychannelIndex",c_ubyte), ("PychannelMask",c_longlong), ("PychannelCapabilities",c_uint), ("PychannelBusCapabilities",c_uint), ("PyisOnBus",c_ubyte), ("PyconnectedBusType",c_uint), ("PybusParams",c_uint), ("PydriverVersion",c_uint), ("PyinterfaceVersion",c_uint), ("Pyraw_data",c_uint*10), ("PyserialNumber",c_uint), ("PyarticleNumber",c_uint), ("PytransceiverName",c_char*32), ("PyspecialCabFlags",c_uint), ("PydominantTimeout",c_uint), ("PydominantRecessiveDelay",c_ubyte), ("PyrecessiveDominantDelay",c_ubyte), ("PyconnectionInfo",c_ubyte), ("PycurrentlyAvailableTimestamps",c_ubyte), ("PyminimalSupplyVoltage",c_ubyte), ("PymaximalSupplyVoltage",c_ubyte), ("PymaximalBaudrate",c_uint), ("PyfpgaCoreCapabilities",c_ubyte), ("PyspecialDeviceStatus",c_ubyte), ("PychannelBusActiveCapabilities",c_ushort), ("PybreakOffset",c_ushort), ("PydelimiterOffset",c_ushort), ("Pyreserved",c_uint*3) ] class PyXLdriverConfig(Structure): _fields_ = [("PydllVersion",c_uint), ("PychannelCount",c_uint), ("Pyreserved",c_uint*10), ("Pychannel",PyXLchannelConfig*64) ] * if __name__ == "__main__": drivercfg = PyXLdriverConfig() PyxlGetDriverConfig(byref(drivercfg)) Could you help me out of this, Thank you very much! -- Best Regards Edward -------------- next part -------------- An HTML attachment was scrubbed... URL: From showell30 at yahoo.com Fri Mar 23 00:16:03 2012 From: showell30 at yahoo.com (Steve Howell) Date: Thu, 22 Mar 2012 21:16:03 -0700 (PDT) Subject: Python is readable References: <4f612b19$0$1379$4fafbaef@reader2.news.tin.it> <6af70db0-dc4a-48ee-9ee2-1a934846d5f2@r2g2000pbs.googlegroups.com> <32b8c4ae-2509-43df-abf0-0fb308be398f@oq7g2000pbb.googlegroups.com> <4f6ae931$0$29883$c3e8da3$5496439d@news.astraweb.com> <4f6b64f9$0$29981$c3e8da3$5496439d@news.astraweb.com> <94d35431-0d4f-44d8-85fb-93671829a554@m10g2000pbk.googlegroups.com> <9c7ce4fd-9530-4c34-a88e-446bab7c31ab@sv8g2000pbc.googlegroups.com> Message-ID: <3c9b6aa7-0da1-4af3-a55d-e87609dccdd3@jx17g2000pbb.googlegroups.com> On Mar 22, 8:20?pm, rusi wrote: > On Mar 23, 7:42?am, Steve Howell wrote: > > > Do you think we'll always have a huge number of incompatible > > programming languages? ?I agree with you that it's a fact of life in > > 2012, but will it be a fact of life in 2062? > > It will be a fact of life wherever Godels theorem is; which put > simplistically is: consistency and completeness cannot coexist. ?This > is the 'logic-generator' for the mess in programming languages. > Put in more general terms: > Completeness is an 'adding' process > Consistency is a 'subtracting' process > Running the two together, convergence is hopeless. Fair enough, but I don't think you can blame Godel's Theorem for the fact that JS, Ruby, Perl, and PHP all solve basically the same problems as Python in 2012. Can't we agree that at least *Perl* is redundant, and that the lingering existence of Perl 5 is an artifact of culture, legacy, and primitive experimentation (by future standards), not mathematical inevitability? > In programming language terms the pull is between simplicity and > expressivity/power. Sure, you can see this tension between Python (simplicity) and Ruby (expressivity). My idea of progress--way before 2062--is that you'd still have a spectrum of simplicity and expressivity, but the level of elegance and power throughout the spectrum would be elevated. There wouldn't be a monoculture, but the cream would eventually rise toward the top. From nathan.alexander.rice at gmail.com Fri Mar 23 00:20:42 2012 From: nathan.alexander.rice at gmail.com (Nathan Rice) Date: Fri, 23 Mar 2012 00:20:42 -0400 Subject: Python is readable In-Reply-To: <9c7ce4fd-9530-4c34-a88e-446bab7c31ab@sv8g2000pbc.googlegroups.com> References: <4f612b19$0$1379$4fafbaef@reader2.news.tin.it> <6af70db0-dc4a-48ee-9ee2-1a934846d5f2@r2g2000pbs.googlegroups.com> <32b8c4ae-2509-43df-abf0-0fb308be398f@oq7g2000pbb.googlegroups.com> <4f6ae931$0$29883$c3e8da3$5496439d@news.astraweb.com> <4f6b64f9$0$29981$c3e8da3$5496439d@news.astraweb.com> <94d35431-0d4f-44d8-85fb-93671829a554@m10g2000pbk.googlegroups.com> <9c7ce4fd-9530-4c34-a88e-446bab7c31ab@sv8g2000pbc.googlegroups.com> Message-ID: >> Do you think we'll always have a huge number of incompatible >> programming languages? ?I agree with you that it's a fact of life in >> 2012, but will it be a fact of life in 2062? > > It will be a fact of life wherever Godels theorem is; which put > simplistically is: consistency and completeness cannot coexist. ?This > is the 'logic-generator' for the mess in programming languages. > Put in more general terms: > Completeness is an 'adding' process > Consistency is a 'subtracting' process > Running the two together, convergence is hopeless. This isn't exactly correct. The incompleteness theorem basically shows that in a sufficiently expressive system, there are statements in the system that cannot be proven given the language of that system. We live with this already given the fact that the incompleteness theorem is closely related to Turing's halting problem. That doesn't indicate anything about the convergence of programming languages. It does say that we will need some form of unit testing or restricted subset simulation system as an adjunct to formal verification in most cases, until the end of time. From python at mrabarnett.plus.com Fri Mar 23 00:43:48 2012 From: python at mrabarnett.plus.com (MRAB) Date: Fri, 23 Mar 2012 04:43:48 +0000 Subject: Python is readable In-Reply-To: <3c9b6aa7-0da1-4af3-a55d-e87609dccdd3@jx17g2000pbb.googlegroups.com> References: <4f612b19$0$1379$4fafbaef@reader2.news.tin.it> <6af70db0-dc4a-48ee-9ee2-1a934846d5f2@r2g2000pbs.googlegroups.com> <32b8c4ae-2509-43df-abf0-0fb308be398f@oq7g2000pbb.googlegroups.com> <4f6ae931$0$29883$c3e8da3$5496439d@news.astraweb.com> <4f6b64f9$0$29981$c3e8da3$5496439d@news.astraweb.com> <94d35431-0d4f-44d8-85fb-93671829a554@m10g2000pbk.googlegroups.com> <9c7ce4fd-9530-4c34-a88e-446bab7c31ab@sv8g2000pbc.googlegroups.com> <3c9b6aa7-0da1-4af3-a55d-e87609dccdd3@jx17g2000pbb.googlegroups.com> Message-ID: <4F6BFF84.4040004@mrabarnett.plus.com> On 23/03/2012 04:16, Steve Howell wrote: > On Mar 22, 8:20 pm, rusi wrote: >> On Mar 23, 7:42 am, Steve Howell wrote: >> >> > Do you think we'll always have a huge number of incompatible >> > programming languages? I agree with you that it's a fact of life in >> > 2012, but will it be a fact of life in 2062? >> >> It will be a fact of life wherever Godels theorem is; which put >> simplistically is: consistency and completeness cannot coexist. This >> is the 'logic-generator' for the mess in programming languages. >> Put in more general terms: >> Completeness is an 'adding' process >> Consistency is a 'subtracting' process >> Running the two together, convergence is hopeless. > > Fair enough, but I don't think you can blame Godel's Theorem for the > fact that JS, Ruby, Perl, and PHP all solve basically the same > problems as Python in 2012. Can't we agree that at least *Perl* is > redundant, and that the lingering existence of Perl 5 is an artifact > of culture, legacy, and primitive experimentation (by future > standards), not mathematical inevitability? > Perl's support for Unicode is much better than the others. >> In programming language terms the pull is between simplicity and >> expressivity/power. > > Sure, you can see this tension between Python (simplicity) and Ruby > (expressivity). My idea of progress--way before 2062--is that you'd > still have a spectrum of simplicity and expressivity, but the level of > elegance and power throughout the spectrum would be elevated. There > wouldn't be a monoculture, but the cream would eventually rise toward > the top. > From showell30 at yahoo.com Fri Mar 23 02:58:00 2012 From: showell30 at yahoo.com (Steve Howell) Date: Thu, 22 Mar 2012 23:58:00 -0700 (PDT) Subject: Python is readable References: <4f612b19$0$1379$4fafbaef@reader2.news.tin.it> <32b8c4ae-2509-43df-abf0-0fb308be398f@oq7g2000pbb.googlegroups.com> <4f6ae931$0$29883$c3e8da3$5496439d@news.astraweb.com> <4f6b64f9$0$29981$c3e8da3$5496439d@news.astraweb.com> <94d35431-0d4f-44d8-85fb-93671829a554@m10g2000pbk.googlegroups.com> <9c7ce4fd-9530-4c34-a88e-446bab7c31ab@sv8g2000pbc.googlegroups.com> <3c9b6aa7-0da1-4af3-a55d-e87609dccdd3@jx17g2000pbb.googlegroups.com> Message-ID: <5e81d24b-96d8-4e4b-a90c-61cdf7b34a5b@px4g2000pbc.googlegroups.com> On Mar 22, 9:43?pm, MRAB wrote: > On 23/03/2012 04:16, Steve Howell wrote: > > > > > > > > > On Mar 22, 8:20 pm, rusi ?wrote: > >> ?On Mar 23, 7:42 am, Steve Howell ?wrote: > > >> ?> ?Do you think we'll always have a huge number of incompatible > >> ?> ?programming languages? ?I agree with you that it's a fact of life in > >> ?> ?2012, but will it be a fact of life in 2062? > > >> ?It will be a fact of life wherever Godels theorem is; which put > >> ?simplistically is: consistency and completeness cannot coexist. ?This > >> ?is the 'logic-generator' for the mess in programming languages. > >> ?Put in more general terms: > >> ?Completeness is an 'adding' process > >> ?Consistency is a 'subtracting' process > >> ?Running the two together, convergence is hopeless. > > > Fair enough, but I don't think you can blame Godel's Theorem for the > > fact that JS, Ruby, Perl, and PHP all solve basically the same > > problems as Python in 2012. ?Can't we agree that at least *Perl* is > > redundant, and that the lingering existence of Perl 5 is an artifact > > of culture, legacy, and primitive experimentation (by future > > standards), not mathematical inevitability? > > Perl's support for Unicode is much better than the others. > Maybe so, but is that an intrinsic feature of the language or just an implementation detail? Even if it's a somewhat intrinsic feature of the language, how hard would it be to subsume Perl's Unicode goodness into the best-of-breed language of all of Perl's cousins? From rosuav at gmail.com Fri Mar 23 03:05:14 2012 From: rosuav at gmail.com (Chris Angelico) Date: Fri, 23 Mar 2012 18:05:14 +1100 Subject: Number of languages known [was Re: Python is readable] - somewhat OT In-Reply-To: References: <4f6bcdd5$0$29981$c3e8da3$5496439d@news.astraweb.com> Message-ID: On Fri, Mar 23, 2012 at 1:48 PM, Steve Howell wrote: > On Mar 22, 6:11?pm, Steven D'Aprano +comp.lang.pyt... at pearwood.info> wrote: >> In any case, I'm not talking about the best developers. I'm talking about >> the typical developer, who by definition is just average. They probably >> know reasonably well one to three of the half dozen most popular >> languages (VB, Java, C, C+, Javascript, PHP, Perl?) plus regexes and SQL, >> and are unlikely to know any of Prolog, Lisp, Haskell, Hypertalk, >> Mercury, Cobra, Smalltalk, Ada, APL, Emerald, Inform, Forth, ... > > I love how you can rattle off 20 or so languages, just off the top of > your head, and not even mention Ruby. ;) If I were to rattle off a couple dozen languages, it probably wouldn't include Ruby either. Never learned it, don't (as yet) know what its advantage domain is. My list "runs somewhat thus": BASIC, 80x86 Assembly, C, C++, Java, REXX, Pascal, Pike, Perl, PHP, Javascript, DeScribe Macro Language, Scheme, Python, ActionScript, DOS Batch, Lua, COBOL, FORTRAN, Ada, Modula-2, LPC, Erlang, Haskell... and that's not counting things like POV-Ray or LilyPond that aren't exactly _programming_ languages, although in some cases you could shoehorn an application into them. Granted, I do have some rather strange and esoteric interests, and I'm sure that Ruby is far better known than DeScribe Macro Language (!!), but I think first of those I've used, and then of the most famous. Sorry Ruby. No slight meant! :) ChrisA From showell30 at yahoo.com Fri Mar 23 03:45:40 2012 From: showell30 at yahoo.com (Steve Howell) Date: Fri, 23 Mar 2012 00:45:40 -0700 (PDT) Subject: Number of languages known [was Re: Python is readable] - somewhat OT References: <4f6bcdd5$0$29981$c3e8da3$5496439d@news.astraweb.com> Message-ID: <8c9d9aa3-d584-4c2b-8455-ec8239a9cf01@px4g2000pbc.googlegroups.com> On Mar 22, 6:11?pm, Steven D'Aprano wrote: > On Fri, 23 Mar 2012 06:14:46 +1100, Chris Angelico wrote: > > On Fri, Mar 23, 2012 at 4:44 AM, Steven D'Aprano > > wrote: > >> The typical developer knows three, maybe four languages moderately > >> well, if you include SQL and regexes as languages, and might have a > >> nodding acquaintance with one or two more. > > > I'm not entirely sure what you mean by "moderately well", > > I mean more than "poorly" but less than "very well". > > Until somebody invents a universal, objective scale for rating relative > knowledge in a problem domain (in this case, knowledge of a programming > language), we're stuck with fuzzy quantities like "guru", "expert", "deep > and complete knowledge of the language and its idioms", all the way down > to "can write Hello World" and "never used or seen the language before". > > Here's a joke version: > > http://www.ariel.com.au/jokes/The_Evolution_of_a_Programmer.html > > and here's a more serious version: > > http://www.yacoset.com/Home/signs-that-you-re-a-bad-programmer > > > nor > > "languages", but I'm of the opinion that a good developer should be able > > to learn a new language very efficiently. > > Should be, absolutely. Does, perhaps not. Some good developers spend > their entire life working in one language and have become expert on every > part of it. Some learn twenty different languages, and barely get beyond > "Hello World" in any of them. > > > Do you count Python 2 and 3 as the same language? > > Absolutely. > > > What about all the versions of the C standard? > > Probably. I'm not familiar with the C standard. > > > In any case, though, I agree that there's a lot of people professionally > > writing code who would know about the 3-4 that you say. I'm just not > > sure that they're any good at coding, even in those few languages. All > > the best people I've ever known have had experience with quite a lot of > > languages. > > I dare say that experience with many languages is a good thing, but it's > not a prerequisite for mastery of a single language. I agree. It's certainly true for spoken languages. The only programming language that I ever learned without experience in other languages was BASIC (because only one language can be our first). I believe I mastered BASIC, not that that is saying a whole lot. > In any case, I'm not talking about the best developers. I'm talking about > the typical developer, who by definition is just average. They probably > know reasonably well one to three of the half dozen most popular > languages (VB, Java, C, C+, Javascript, PHP, Perl?) plus regexes and SQL, > and are unlikely to know any of Prolog, Lisp, Haskell, Hypertalk, > Mercury, Cobra, Smalltalk, Ada, APL, Emerald, Inform, Forth, ... > VB, Java, C, C++, JS, PHP, and Perl are all 20th century languages FWIW. PHP, Java, and JS all emerged circa 1995 (17 years ago); C, C+ +, and VB are even older. (And so is Python.) A future version of Python itself, or some language largely inspired by Python (CoffeeScript 3.0 maybe?), will eventually squeeze out Perl, PHP, and JS in the popularity contests. At least I'm crossing my fingers. VB will die with no obvious successors. C++ was never very distinct from C to begin with, and the two languages will eventually converge, die off, or be supplanted. In ten years we'll basically have only three 20th-century-ish languages in the top ten: Python', C', and Java'. The rest of the top ten most popular languages will be something truly 21st-century. They'll be languages that either haven't been invented yet or modernized derivatives of languages that we view as "fringe" today (Lisp'/Haskell'/etc.). From showell30 at yahoo.com Fri Mar 23 04:04:06 2012 From: showell30 at yahoo.com (Steve Howell) Date: Fri, 23 Mar 2012 01:04:06 -0700 (PDT) Subject: Number of languages known [was Re: Python is readable] - somewhat OT References: <4f6bcdd5$0$29981$c3e8da3$5496439d@news.astraweb.com> Message-ID: <8694a85d-fe94-4bef-8bb6-8a8241d14ca3@px4g2000pbc.googlegroups.com> On Mar 23, 12:05?am, Chris Angelico wrote: > On Fri, Mar 23, 2012 at 1:48 PM, Steve Howell wrote: > > On Mar 22, 6:11?pm, Steven D'Aprano > +comp.lang.pyt... at pearwood.info> wrote: > >> In any case, I'm not talking about the best developers. I'm talking about > >> the typical developer, who by definition is just average. They probably > >> know reasonably well one to three of the half dozen most popular > >> languages (VB, Java, C, C+, Javascript, PHP, Perl?) plus regexes and SQL, > >> and are unlikely to know any of Prolog, Lisp, Haskell, Hypertalk, > >> Mercury, Cobra, Smalltalk, Ada, APL, Emerald, Inform, Forth, ... > > > I love how you can rattle off 20 or so languages, just off the top of > > your head, and not even mention Ruby. ;) > > If I were to rattle off a couple dozen languages, it probably wouldn't > include Ruby either. Never learned it, don't (as yet) know what its > advantage domain is. Hype? > My list "runs somewhat thus": BASIC, 80x86 > Assembly, C, C++, Java, REXX, Pascal, Pike, Perl, PHP, Javascript, > DeScribe Macro Language, Scheme, Python, ActionScript, DOS Batch, Lua, > COBOL, FORTRAN, Ada, Modula-2, LPC, Erlang, Haskell... and that's not > counting things like POV-Ray or LilyPond that aren't exactly > _programming_ languages, although in some cases you could shoehorn an > application into them. Granted, I do have some rather strange and > esoteric interests, and I'm sure that Ruby is far better known than > DeScribe Macro Language (!!), but I think first of those I've used, > and then of the most famous. > > Sorry Ruby. No slight meant! :) > If you're that adept at learning languages, then I recommend learning Ruby just for kicks, but you're not missing *that* much, trust me. I'd skip past Ruby and learn CoffeeScript. Of the languages that are in the scripting family, you already know REXX (supreme elegance for its time), Perl (I hate it now, but loved it before Python), PHP (truly easy to learn, you can never take that away from it), and Javascript (horrible syntax, awful platform, but at least they have first-class functions). You have the Assembly/C/C++/Java progression--definitely good stuff, even if the ending to the movie was a bit of a letdown. COBOL/Fortran/Ada gives you instance "old school" street cred. Haskell/Erlang/Scheme means you can hang out with the cool grad school kids in the CS/Math departments (no oxymoron intended). I confess--I've never learned LilyPond, Modula-2, or LPC! I mean, of course they're on my resume, just to get by HR screening, but that's just between you and me... From rosuav at gmail.com Fri Mar 23 04:24:13 2012 From: rosuav at gmail.com (Chris Angelico) Date: Fri, 23 Mar 2012 19:24:13 +1100 Subject: Number of languages known [was Re: Python is readable] - somewhat OT In-Reply-To: <8694a85d-fe94-4bef-8bb6-8a8241d14ca3@px4g2000pbc.googlegroups.com> References: <4f6bcdd5$0$29981$c3e8da3$5496439d@news.astraweb.com> <8694a85d-fe94-4bef-8bb6-8a8241d14ca3@px4g2000pbc.googlegroups.com> Message-ID: On Fri, Mar 23, 2012 at 7:04 PM, Steve Howell wrote: > If you're that adept at learning languages, then I recommend learning > Ruby just for kicks, but you're not missing *that* much, trust me. > I'd skip past Ruby and learn CoffeeScript. Sure. When I have some spare time... lessee, I think I have two spare minutes in the year 2015 that aren't allocated yet! Oops. There they go. > Of the languages that are in the scripting family, you already know > REXX (supreme elegance for its time), Perl (I hate it now, but loved > it before Python), PHP (truly easy to learn, you can never take that > away from it), and Javascript (horrible syntax, awful platform, but at > least they have first-class functions). > > You have the Assembly/C/C++/Java progression--definitely good stuff, > even if the ending to the movie was a bit of a letdown. +1 on the description, heh. > COBOL/Fortran/Ada gives you instance "old school" street cred. > > Haskell/Erlang/Scheme means you can hang out with the cool grad school > kids in the CS/Math departments (no oxymoron intended). Ehh, the ones from COBOL on were because I ran out of languages that I'm really familiar with, and enumerated a few famous ones. But the rest, I do actually know, and that's why I thought of them. > I confess--I've never learned LilyPond, Modula-2, or LPC! ?I mean, of > course they're on my resume, just to get by HR screening, but that's > just between you and me... GNU LilyPond is a music publishing language (it's to music what TeX is to English, kinda). Awesome language and system. I can show you a few pieces I've done with Ly, it's beautiful music score from a very clean input file. Modula-2 is a Pascal-derived language that I haven't actually used, but it's cited as an influence in the development of several others that I have used. LPC is Lars Somebody's C, originally written as the basis for Lars Somebody's MUD or LPMUD, and was the basis for Pike (with which I'm very familiar, as readers of this list probably know). Half the above languages aren't on my resume, mainly because I don't really care about HR screening :) ChrisA From nutznetz-0c1b6768-bfa9-48d5-a470-7603bd3aa915 at spamschutz.glglgl.de Fri Mar 23 05:56:35 2012 From: nutznetz-0c1b6768-bfa9-48d5-a470-7603bd3aa915 at spamschutz.glglgl.de (Thomas Rachel) Date: Fri, 23 Mar 2012 10:56:35 +0100 Subject: contextlib.nested deprecated Message-ID: Hi, I understand why contextlib.nested is deprecated. But if I write a program for an old python version w/o the multiple form of with, I have (nearly) no other choice. In order to avoid the following construct to fail: with nested(open("f1"), open("f2")) as (f1, f2): (f1 wouldn't be closed if opening f2 fails) I could imagine writing a context manager which moves initialization into its __enter__: @contextmanager def late_init(f, *a, **k): r = f(*a, **k) with r as c: yield c Am I right thinking that with nested(late_init(open, "f1"), late_init(open, "f2")) as (f1, f2): will suffice here to make it "clean"? TIA, Thomas From slehar at gmail.com Fri Mar 23 07:00:13 2012 From: slehar at gmail.com (Steven Lehar) Date: Fri, 23 Mar 2012 07:00:13 -0400 Subject: Python is readable Message-ID: Reply to Steve Howell >>> Do you think we'll always have a huge number of incompatible programming languages? I agree with you that it's a fact of life in 2012, but will it be a fact of life in 2062? <<< We can only HOPE so! When I first learned unix / sh / csh / tcsh / bash ...etc... it irked me no end that there was so much variation and inconsistency, and I couldn't wait for some kind of standard to finally emerge. But now I realize in hindsight that what I was seeing was evolution in action! Software evolves much like life, in a healthy ecosystem there are a million variations, and nobody knows in advance which ones will succeed and which will fail. And so it is with programming languages, we should all be happy that we live in an environment so rich with competing ideas and ideologies, look at all the fun we are having just discussing all the possibilities! Compared to my first computer experience on Digitals DCL (Digital Command Language) that had the same syntax and command-line arguments for every command defined in DEC, as if the product of a Master Designer, it was beautiful consistency and easy to learn, but it only allowed three levels of directories, and one-size-fits-all for everyone. I loved it then, but now I see that was like life in a medieval monastery. Vive la difference! -------------- next part -------------- An HTML attachment was scrubbed... URL: From alec.taylor6 at gmail.com Fri Mar 23 07:09:22 2012 From: alec.taylor6 at gmail.com (Alec Taylor) Date: Fri, 23 Mar 2012 22:09:22 +1100 Subject: Templated rich-text egg Message-ID: Good morning, We've all seen document templates in a variety of systems, such as PowerPoint, MailChimp and Google Docs. I would like to utilise the same sorts of capabilities on my website. The following features I require: ? Create a library of document templates ? Allow others to pick a document template to create there document from ? Allow others to swap the template their document has without losing data ? Document authoring in rich-text (e.g. using CKEditor) (I will probably end up using a full CMS such as Mezzanine around the whole system.) Please suggest modules allowing me to do the aforementioned. Thanks for all recommendations, Alec Taylor From mrsangeet at gmail.com Fri Mar 23 08:59:35 2012 From: mrsangeet at gmail.com (Sangeet) Date: Fri, 23 Mar 2012 05:59:35 -0700 (PDT) Subject: Accessing the files by last modified time In-Reply-To: <8cbfb1b2-94ed-4830-90fa-976a831ebb97@l14g2000vbe.googlegroups.com> References: <26215939.1574.1332416026298.JavaMail.geo-discussion-forums@ynlt17> <8cbfb1b2-94ed-4830-90fa-976a831ebb97@l14g2000vbe.googlegroups.com> Message-ID: <23086952.178.1332507576146.JavaMail.geo-discussion-forums@ynes7> On Thursday, 22 March 2012 17:34:43 UTC+5:30, Tim Williams wrote: > On Mar 22, 7:33?am, Sangeet wrote: > > Hi > > > > I am new to the python programming language. > > > > I've been trying to write a script that would access the last modified file in one of my directories. I'm using Win XP. > > > > I saw a similar topic, on the forum before, however the reply using (os.popen) didn't work out for me. I'm not sure whether it was due to syntax errors either. > > > > Thanks, > > Sangeet > > Check out os.stat() Hey, thanks I tried playing around with this. I haven't got what I exactly wanted, but on the way there for sure! :) Sangeet From mrsangeet at gmail.com Fri Mar 23 09:00:25 2012 From: mrsangeet at gmail.com (Sangeet) Date: Fri, 23 Mar 2012 06:00:25 -0700 (PDT) Subject: Accessing the files by last modified time In-Reply-To: References: <26215939.1574.1332416026298.JavaMail.geo-discussion-forums@ynlt17> Message-ID: <28803503.136.1332507625424.JavaMail.geo-discussion-forums@ynjk1> On Thursday, 22 March 2012 17:19:23 UTC+5:30, Chris Rebert wrote: > On Thu, Mar 22, 2012 at 4:33 AM, Sangeet wrote: > > Hi > > > > I am new to the python programming language. > > > > I've been trying to write a script that would access the last modified file in one of my directories. I'm using Win XP. > > > > I saw a similar topic, on the forum before, however the reply using (os.popen) didn't work out for me. I'm not sure whether it was due to syntax errors either. > > Recursively or non-recursively? > Live monitoring or just one-time? > What was the forum post in question? > > In the simple case, you just need to stitch together these functions: > http://docs.python.org/library/os.html#os.stat > (note the .st_mtime attribute of the result) > http://docs.python.org/library/os.path.html#os.path.join > with one of these functions: > http://docs.python.org/library/os.html#os.listdir > http://docs.python.org/library/os.html#os.walk > > Cheers, > Chris Thanks Chris, this helped me a lot! From mrsangeet at gmail.com Fri Mar 23 09:00:25 2012 From: mrsangeet at gmail.com (Sangeet) Date: Fri, 23 Mar 2012 06:00:25 -0700 (PDT) Subject: Accessing the files by last modified time In-Reply-To: References: <26215939.1574.1332416026298.JavaMail.geo-discussion-forums@ynlt17> Message-ID: <28803503.136.1332507625424.JavaMail.geo-discussion-forums@ynjk1> On Thursday, 22 March 2012 17:19:23 UTC+5:30, Chris Rebert wrote: > On Thu, Mar 22, 2012 at 4:33 AM, Sangeet wrote: > > Hi > > > > I am new to the python programming language. > > > > I've been trying to write a script that would access the last modified file in one of my directories. I'm using Win XP. > > > > I saw a similar topic, on the forum before, however the reply using (os.popen) didn't work out for me. I'm not sure whether it was due to syntax errors either. > > Recursively or non-recursively? > Live monitoring or just one-time? > What was the forum post in question? > > In the simple case, you just need to stitch together these functions: > http://docs.python.org/library/os.html#os.stat > (note the .st_mtime attribute of the result) > http://docs.python.org/library/os.path.html#os.path.join > with one of these functions: > http://docs.python.org/library/os.html#os.listdir > http://docs.python.org/library/os.html#os.walk > > Cheers, > Chris Thanks Chris, this helped me a lot! From mrsangeet at gmail.com Fri Mar 23 09:52:05 2012 From: mrsangeet at gmail.com (Sangeet) Date: Fri, 23 Mar 2012 06:52:05 -0700 (PDT) Subject: Fetching data from a HTML file Message-ID: <9362386.1094.1332510725414.JavaMail.geo-discussion-forums@ynlt15> Hi, I've got to fetch data from the snippet below and have been trying to match the digits in this to specifically to specific groups. But I can't seem to figure how to go about stripping the tags! :( Sum2451102561.496 [min] Actually, I'm working on ROBOT Framework, and haven't been able to figure out how to read data from HTML tables. Reading from the source, is the best (read rudimentary) way I could come up with. Any suggestions are welcome! Thanks, Sangeet From simonyan at fedoraproject.org Fri Mar 23 10:08:51 2012 From: simonyan at fedoraproject.org (Simon Yan) Date: Fri, 23 Mar 2012 22:08:51 +0800 Subject: Fetching data from a HTML file In-Reply-To: <9362386.1094.1332510725414.JavaMail.geo-discussion-forums@ynlt15> References: <9362386.1094.1332510725414.JavaMail.geo-discussion-forums@ynlt15> Message-ID: On Fri, Mar 23, 2012 at 9:52 PM, Sangeet wrote: > Hi, > > I've got to fetch data from the snippet below and have been trying to > match the digits in this to specifically to specific groups. But I can't > seem to figure how to go about stripping the tags! :( > > Sum class="green">24511 align='center'>02561.496 > [min] > > > Actually, I'm working on ROBOT Framework, and haven't been able to figure > out how to read data from HTML tables. Reading from the source, is the best > (read rudimentary) way I could come up with. Any suggestions are welcome! > Sangeet, I think Python comes with its own HTML parser. Can you have a look at this http://docs.python.org/library/htmlparser.html and see if it helps? > > Thanks, > Sangeet > -- > http://mail.python.org/mailman/listinfo/python-list > -- Regards, YeeYaa (Simon Yan) http://simonyan.fedorapeople.org/ -------------- next part -------------- An HTML attachment was scrubbed... URL: From jeanmichel at sequans.com Fri Mar 23 10:19:55 2012 From: jeanmichel at sequans.com (Jean-Michel Pichavant) Date: Fri, 23 Mar 2012 15:19:55 +0100 Subject: Python classes: Simplify? In-Reply-To: References: Message-ID: <4F6C868B.3030903@sequans.com> Steven Lehar wrote: > It seems to me that the Python class system is needlessly confusing. > Am I missing something? > > For example in the class Complex given in the documentation > > *class Complex:* > * def __init__(self, realpart, imagpart):* > * self.r = realpart* > * self.i = imagpart* > * > * > *x = Complex(3.0, -4.5)* > > I initially found it profoundly confusing that __init__( ) calls for 3 > arguments, but you call Complex( ) with 2. Furthermore, why not call > the initialization function after the class name as is done in other > languages? Isn't that the simplest conceptually? Demonstrating with > the above example: > In python, writting obj.method() will be translated into method(obj) so any instance method has a #arg + 1 arguments, something you'll get familiar with. Furthermore, Complex(3.0, -4.5) invokes 2 functions : __new__ and __init__. __new__ is the "constructor", this is the function that returns an instance. __init__ is an initializer, at the time it's called the instance already exists and is viable. > *class Complex:* > * def Complex(realpart, imagpart):* > * Complex.r = realpart* > * Complex.i = imagpart* > * > * > *x = Complex(3.0, -4.5)* > * > * > Is there a good reason why classes cannot be defined that way? > (Besides the problem of backward-compatibility) > Python uses a different data model, it is a very good idea to mark theses differences using an explicit distinct syntax so that people won't jump into false conclusions like "it's like C or Java". It is not. JM JM From nathan.alexander.rice at gmail.com Fri Mar 23 10:27:22 2012 From: nathan.alexander.rice at gmail.com (Nathan Rice) Date: Fri, 23 Mar 2012 10:27:22 -0400 Subject: Number of languages known [was Re: Python is readable] - somewhat OT In-Reply-To: References: <4f6bcdd5$0$29981$c3e8da3$5496439d@news.astraweb.com> <8694a85d-fe94-4bef-8bb6-8a8241d14ca3@px4g2000pbc.googlegroups.com> Message-ID: Logo. It's turtles all the way down. From slehar at gmail.com Fri Mar 23 10:41:51 2012 From: slehar at gmail.com (Steven Lehar) Date: Fri, 23 Mar 2012 10:41:51 -0400 Subject: Python classes: Simplify? In-Reply-To: <4F6C868B.3030903@sequans.com> References: <4F6C868B.3030903@sequans.com> Message-ID: Many thanks to all who responded to my "Python Classes: Simplify?" thread. There seem to be several good reasons for this particular syntactical choice, I am all the wiser for your kind explanations. My faith in the simplicity and elegance of this beautiful language is reinforced. Thanks all! -------------- next part -------------- An HTML attachment was scrubbed... URL: From ramit.prasad at jpmorgan.com Fri Mar 23 11:08:03 2012 From: ramit.prasad at jpmorgan.com (Prasad, Ramit) Date: Fri, 23 Mar 2012 15:08:03 +0000 Subject: Fetching data from a HTML file In-Reply-To: <9362386.1094.1332510725414.JavaMail.geo-discussion-forums@ynlt15> References: <9362386.1094.1332510725414.JavaMail.geo-discussion-forums@ynlt15> Message-ID: <5B80DD153D7D744689F57F4FB69AF474026C7EAC@SCACMX008.exchad.jpmchase.net> > Actually, I'm working on ROBOT Framework, and haven't been able to figure > out how to read data from HTML tables. Reading from the source, is the best > (read rudimentary) way I could come up with. Any suggestions are welcome! > I've got to fetch data from the snippet below and have been trying to match > the digits in this to specifically to specific groups. But I can't seem to > figure how to go about stripping the tags! :( In addition to Simon's response. You may want to look at Beautiful Soup which I hear is good at dealing with malformed HTML. http://www.crummy.com/software/BeautifulSoup/ Ramit Ramit Prasad | JPMorgan Chase Investment Bank | Currencies Technology 712 Main Street | Houston, TX 77002 work phone: 713 - 216 - 5423 -- This email is confidential and subject to important disclaimers and conditions including on offers for the purchase or sale of securities, accuracy and completeness of information, viruses, confidentiality, legal privilege, and legal entity disclaimers, available at http://www.jpmorgan.com/pages/disclosures/email. From ramit.prasad at jpmorgan.com Fri Mar 23 11:15:01 2012 From: ramit.prasad at jpmorgan.com (Prasad, Ramit) Date: Fri, 23 Mar 2012 15:15:01 +0000 Subject: Number of languages known [was Re: Python is readable] - somewhat OT In-Reply-To: <8694a85d-fe94-4bef-8bb6-8a8241d14ca3@px4g2000pbc.googlegroups.com> References: <4f6bcdd5$0$29981$c3e8da3$5496439d@news.astraweb.com> <8694a85d-fe94-4bef-8bb6-8a8241d14ca3@px4g2000pbc.googlegroups.com> Message-ID: <5B80DD153D7D744689F57F4FB69AF474026C7EE9@SCACMX008.exchad.jpmchase.net> > I confess--I've never learned LilyPond, Modula-2, or LPC! I mean, of > course they're on my resume, just to get by HR screening, but that's > just between you and me... You mean, you, him, this mailing list, and anyone that looks on the archives... Ramit Ramit Prasad | JPMorgan Chase Investment Bank | Currencies Technology 712 Main Street | Houston, TX 77002 work phone: 713 - 216 - 5423 -- This email is confidential and subject to important disclaimers and conditions including on offers for the purchase or sale of securities, accuracy and completeness of information, viruses, confidentiality, legal privilege, and legal entity disclaimers, available at http://www.jpmorgan.com/pages/disclosures/email. From ramit.prasad at jpmorgan.com Fri Mar 23 11:16:29 2012 From: ramit.prasad at jpmorgan.com (Prasad, Ramit) Date: Fri, 23 Mar 2012 15:16:29 +0000 Subject: Number of languages known [was Re: Python is readable] - somewhat OT In-Reply-To: References: <4f6bcdd5$0$29981$c3e8da3$5496439d@news.astraweb.com> <8694a85d-fe94-4bef-8bb6-8a8241d14ca3@px4g2000pbc.googlegroups.com> Message-ID: <5B80DD153D7D744689F57F4FB69AF474026C7F02@SCACMX008.exchad.jpmchase.net> > Logo. It's turtles all the way down. I had forgotten all about that, I should add that to my resume! I wonder what kind of job I could get writing primarily in Logo? Ramit Ramit Prasad | JPMorgan Chase Investment Bank | Currencies Technology 712 Main Street | Houston, TX 77002 work phone: 713 - 216 - 5423 -- This email is confidential and subject to important disclaimers and conditions including on offers for the purchase or sale of securities, accuracy and completeness of information, viruses, confidentiality, legal privilege, and legal entity disclaimers, available at http://www.jpmorgan.com/pages/disclosures/email. From fetchinson at googlemail.com Fri Mar 23 11:28:56 2012 From: fetchinson at googlemail.com (Daniel Fetchinson) Date: Fri, 23 Mar 2012 16:28:56 +0100 Subject: Fetching data from a HTML file In-Reply-To: <9362386.1094.1332510725414.JavaMail.geo-discussion-forums@ynlt15> References: <9362386.1094.1332510725414.JavaMail.geo-discussion-forums@ynlt15> Message-ID: On 3/23/12, Sangeet wrote: > Hi, > > I've got to fetch data from the snippet below and have been trying to match > the digits in this to specifically to specific groups. But I can't seem to > figure how to go about stripping the tags! :( > > Sum class="green">24511 align='center'>02561.496 > [min] > Try beautiful soup: http://www.crummy.com/software/BeautifulSoup/ > Actually, I'm working on ROBOT Framework, and haven't been able to figure > out how to read data from HTML tables. Reading from the source, is the best > (read rudimentary) way I could come up with. Any suggestions are welcome! > > Thanks, > Sangeet > -- > http://mail.python.org/mailman/listinfo/python-list > -- Psss, psss, put it down! - http://www.cafepress.com/putitdown From kiuhnm03.4t.yahoo.it Fri Mar 23 12:00:23 2012 From: kiuhnm03.4t.yahoo.it (Kiuhnm) Date: Fri, 23 Mar 2012 17:00:23 +0100 Subject: Stream programming Message-ID: <4f6c9e17$0$1383$4fafbaef@reader2.news.tin.it> I've been writing a little library for handling streams as an excuse for doing a little OOP with Python. I don't share some of the views on readability expressed on this ng. Indeed, I believe that a piece of code may very well start as complete gibberish and become a pleasure to read after some additional information is provided. I must say that imposed indentation is a pain when one is trying to define some sort of DSL (domain specific language). Also, Python's operator overloading is a bit limited, but that makes for a more rewarding experience in my case. Here's an example of what you can write: numbers - push - avrg - 'med' - pop - filter(lt('med'), ge('med'))\ - ['same', 'same'] - streams(cat) - 'same' Ok, we're at the "complete gibberish" phase. Time to give you the "additional information". I will use "<=>" to mean "is equivalent to". That's not part of the DSL. A flow has one or more streams: 1 stream: [1,2,3] 2 streams: [1,3,5] | [2,4,6] Two flows can be concatenated: [1,2,3] + [4,5,6] <=> [1,2,3,4,5,6] [0] + ([1,2] | [3,4]) + [10] <=> [0,1,2,10] | [0,3,4,10] ([1,2] | [10,20]) + ([3,4] | [30,40]) <=> [1,2,3,4] | [10,20,30,40] A flow can be transformed: [1,2] - f <=> [f(1),f(2)] ([1,2] | [3,4]) - f <=> [f(1,3),f(2,4)] ([1,2] | [3,4]) - [f] <=> [f(1),f(2)] | [f(3),f(4)] ([1,2] | [3,4]) - [f,g] <=> [f(1),f(2)] | [g(3),g(4)] [1,2] - [f,g] <=> [f(1),f(2)] | [g(1),g(2)] Some functions are special and almost any function can be made special: [1,2,3,4,5] - filter(isprime) <=> [2,3,5] [[],(1,2),[3,4,5]] - flatten <=> [1,2,3,4,5] Note that 'filter' is not really necessary, thanks to 'flatten'. Flows can be named, remembered and used as a value: [1,2,3,4,5] - 'flow' + val('flow') <=> [1,2,3,4,5]*2 as a transformation chain: [1,2,3] - skipfirst - 'again' | [4,5,6] - func('again') <=> [2,3] | [5,6] Recursion is also possible and stops when a function is applied to an empty sequence. Flows can be saved (push) and restored (pop) : [1,2,3,4] - push - by(2) - 'double' - pop | val('double') <=> [1,2,3,4] | [2,4,6,8] There are easier ways to achieve the same result, of course: [1,2,3,4] - [id, by(2)] Let's go back to our example. I didn't tell you anything but you should be able to understand it anyway. numbers - push - avrg - 'med' - pop - filter(lt('med'), ge('med'))\ - ['same', 'same'] - streams(cat) - 'same' It reads as "take a list of numbers - save it - compute the average and named it 'med' - restore the flow - create two streams which have, respect., the numbers less than 'med' and those greater or equal to 'med' - do the /entire/ 'same' process on each one of the two streams - concat the resulting streams - name all this /entire/ process 'same'. Not readable enough? Replace 'same' with 'qsort'. Is that readable or am I going crazy? [note: that's a rhetorical question whose answer is "That's very readable!"] Kiuhnm From kiuhnm03.4t.yahoo.it Fri Mar 23 12:02:43 2012 From: kiuhnm03.4t.yahoo.it (Kiuhnm) Date: Fri, 23 Mar 2012 17:02:43 +0100 Subject: Stream programming In-Reply-To: <4f6c9e17$0$1383$4fafbaef@reader2.news.tin.it> References: <4f6c9e17$0$1383$4fafbaef@reader2.news.tin.it> Message-ID: <4f6c9ea3$0$1383$4fafbaef@reader2.news.tin.it> On 3/23/2012 17:00, Kiuhnm wrote: > I've been writing a little library for handling streams as an excuse for > doing a little OOP with Python. > > I don't share some of the views on readability expressed on this ng. > Indeed, I believe that a piece of code may very well start as complete > gibberish and become a pleasure to read after some additional > information is provided. > > I must say that imposed indentation is a pain when one is trying to > define some sort of DSL (domain specific language). Also, Python's > operator overloading is a bit limited, but that makes for a more > rewarding experience in my case. > > Here's an example of what you can write: > > numbers - push - avrg - 'med' - pop - filter(lt('med'), ge('med'))\ > - ['same', 'same'] - streams(cat) - 'same' > > Ok, we're at the "complete gibberish" phase. > > Time to give you the "additional information". > > I will use "<=>" to mean "is equivalent to". That's not part of the DSL. > A flow has one or more streams: > 1 stream: > [1,2,3] > 2 streams: > [1,3,5] | [2,4,6] > Two flows can be concatenated: > [1,2,3] + [4,5,6] <=> [1,2,3,4,5,6] > [0] + ([1,2] | [3,4]) + [10] <=> [0,1,2,10] | [0,3,4,10] > ([1,2] | [10,20]) + ([3,4] | [30,40]) <=> [1,2,3,4] | [10,20,30,40] > A flow can be transformed: > [1,2] - f <=> [f(1),f(2)] > ([1,2] | [3,4]) - f <=> [f(1,3),f(2,4)] > ([1,2] | [3,4]) - [f] <=> [f(1),f(2)] | [f(3),f(4)] > ([1,2] | [3,4]) - [f,g] <=> [f(1),f(2)] | [g(3),g(4)] > [1,2] - [f,g] <=> [f(1),f(2)] | [g(1),g(2)] > Some functions are special and almost any function can be made special: > [1,2,3,4,5] - filter(isprime) <=> [2,3,5] > [[],(1,2),[3,4,5]] - flatten <=> [1,2,3,4,5] > Note that 'filter' is not really necessary, thanks to 'flatten'. > Flows can be named, remembered and used > as a value: > [1,2,3,4,5] - 'flow' + val('flow') <=> [1,2,3,4,5]*2 > as a transformation chain: > [1,2,3] - skipfirst - 'again' | [4,5,6] - func('again') > <=> [2,3] | [5,6] > Recursion is also possible and stops when a function is applied to an > empty sequence. > Flows can be saved (push) and restored (pop) : > [1,2,3,4] - push - by(2) - 'double' - pop | val('double') > <=> [1,2,3,4] | [2,4,6,8] > There are easier ways to achieve the same result, of course: > [1,2,3,4] - [id, by(2)] > > Let's go back to our example. I didn't tell you anything but you should Ops... *everything*. Kiuhnm From yoursurrogategod at gmail.com Fri Mar 23 12:14:14 2012 From: yoursurrogategod at gmail.com (Yves S. Garret) Date: Fri, 23 Mar 2012 09:14:14 -0700 (PDT) Subject: Good web-development Python book Message-ID: Hello, I'm trying to brush up on my Python and would like to From yoursurrogategod at gmail.com Fri Mar 23 12:16:15 2012 From: yoursurrogategod at gmail.com (Yves S. Garret) Date: Fri, 23 Mar 2012 09:16:15 -0700 (PDT) Subject: Good web-development Python book Message-ID: <14efe443-2f0c-4b6f-a5be-f1e33288038a@eb6g2000vbb.googlegroups.com> Oooops! Sent my previous e-mail too soon! Didn't mean to. Another try. Hello, I'm trying to brush up on my Python and would like to learn how to make web-apps. I was hoping to get a good book on learning how to make web-applications using Python (as opposed to something like PHP) without any framework at the moment. Do you guys have any suggestions? I looked around on Amazon, but didn't really find anything too promising. It was either very old or had no more than 3 stars in a rating. I'd appreciate your help on this. From ethan at stoneleaf.us Fri Mar 23 12:23:55 2012 From: ethan at stoneleaf.us (Ethan Furman) Date: Fri, 23 Mar 2012 09:23:55 -0700 Subject: Number of languages known [was Re: Python is readable] - somewhat OT In-Reply-To: References: <4f6bcdd5$0$29981$c3e8da3$5496439d@news.astraweb.com> <8694a85d-fe94-4bef-8bb6-8a8241d14ca3@px4g2000pbc.googlegroups.com> Message-ID: <4F6CA39B.9090709@stoneleaf.us> Nathan Rice wrote: > Logo. It's turtles all the way down. +1 QOTW From clp2 at rebertia.com Fri Mar 23 12:30:24 2012 From: clp2 at rebertia.com (Chris Rebert) Date: Fri, 23 Mar 2012 09:30:24 -0700 Subject: Good web-development Python book In-Reply-To: <14efe443-2f0c-4b6f-a5be-f1e33288038a@eb6g2000vbb.googlegroups.com> References: <14efe443-2f0c-4b6f-a5be-f1e33288038a@eb6g2000vbb.googlegroups.com> Message-ID: On Fri, Mar 23, 2012 at 9:16 AM, Yves S. Garret wrote: > Oooops! ?Sent my previous e-mail too soon! ?Didn't mean to. > > Another try. > > Hello, > > ? I'm trying to brush up on my Python and would like to learn how to > make web-apps. ?I was hoping to get a good book on learning how to > make web-applications using Python (as opposed to something like PHP) > without any framework at the moment. ?Do you guys have any > suggestions? > > ? I looked around on Amazon, but didn't really find anything too > promising. ?It was either very old or had no more than 3 stars in a > rating. ?I'd appreciate your help on this. The next edition of The Definitive Guide to Django, by the project's co-BDFLs, is available online (for now): http://www.djangobook.com/en/2.0/ It's not completely finished, but between it and the previous edition (http://www.djangobook.com/en/1.0/ , also free), you should be fine. Cheers, Chris From nathan.alexander.rice at gmail.com Fri Mar 23 12:33:35 2012 From: nathan.alexander.rice at gmail.com (Nathan Rice) Date: Fri, 23 Mar 2012 12:33:35 -0400 Subject: Stream programming In-Reply-To: <4f6c9e17$0$1383$4fafbaef@reader2.news.tin.it> References: <4f6c9e17$0$1383$4fafbaef@reader2.news.tin.it> Message-ID: > I will use "<=>" to mean "is equivalent to". That's not part of the DSL. > A flow has one or more streams: > ?1 stream: > ? ?[1,2,3] > ?2 streams: > ? ?[1,3,5] | [2,4,6] > Two flows can be concatenated: > ?[1,2,3] + [4,5,6] <=> [1,2,3,4,5,6] > ?[0] + ([1,2] | [3,4]) + [10] <=> [0,1,2,10] | [0,3,4,10] > ?([1,2] | [10,20]) + ([3,4] | [30,40]) <=> [1,2,3,4] | [10,20,30,40] Algebraically, your concatenation rules don't really make sense - your flows are both distributive and non distributive. You also make the implicit assumption of an order over streams in a flow, but disregard the implications of that assumption in some cases. I understand what you're trying to communicate, so I think you need to be a little more strict and explicit in your definitions. > A flow can be transformed: > ?[1,2] - f <=> [f(1),f(2)] > ?([1,2] | [3,4]) - f <=> [f(1,3),f(2,4)] > ?([1,2] | [3,4]) - [f] <=> [f(1),f(2)] | [f(3),f(4)] > ?([1,2] | [3,4]) - [f,g] <=> [f(1),f(2)] | [g(3),g(4)] > ?[1,2] - [f,g] <=> [f(1),f(2)] | [g(1),g(2)] Given the examples you pose here, it is clear that you are assuming that the streams are synchronized in discrete time. Since you do not provide any mechanism for temporal alignment of streams you are also assuming every stream will have an element at every time point, the streams start at the same time and are of the same length. Is this what you want? These seem like pretty rough simplifying assumptions. > Some functions are special and almost any function can be made special: > ?[1,2,3,4,5] - filter(isprime) <=> [2,3,5] > ?[[],(1,2),[3,4,5]] - flatten <=> [1,2,3,4,5] > Note that 'filter' is not really necessary, thanks to 'flatten'. This implies that your transformations again produce flows. You should explicitly state this. > Flows can be named, remembered and used > ?as a value: > ? ?[1,2,3,4,5] - 'flow' + val('flow') <=> [1,2,3,4,5]*2 Is this a flow with two identical streams, or a flow with one long stream formed by concatenation? > ?as a transformation chain: > ? ?[1,2,3] - skipfirst - 'again' | [4,5,6] - func('again') > ? ? ?<=> [2,3] | [5,6] > ?Recursion is also possible and stops when a function is applied to an empty > sequence. > Flows can be saved (push) and restored (pop) : > ?[1,2,3,4] - push - by(2) - 'double' - pop | val('double') > ? ? ?<=> [1,2,3,4] | [2,4,6,8] > There are easier ways to achieve the same result, of course: > ?[1,2,3,4] - [id, by(2)] You are grasping at an algebra here, a sort of calculus of temporal observations. You need to step back and make it rigorous before you worry about issues such as a readable syntax. Nathan From gstaniak at gmail.com Fri Mar 23 12:43:40 2012 From: gstaniak at gmail.com (Grzegorz Staniak) Date: Fri, 23 Mar 2012 16:43:40 +0000 (UTC) Subject: Data mining/pattern recogniton software in Python? Message-ID: Hello, I've been asked by a colleague for help in a small educational project, which would involve the recognition of patterns in a live feed of data points (readings from a measuring appliance), and then a more general search for patterns on archival data. The language of preference is Python, since the lab uses software written in Python already. I can see there are packages like Open CV, scikit-learn, Orange that could perhaps be of use for the mining phase -- and even if they are slanted towards image pattern recognition, I think I'd be able to find an appropriate package for the timeseries analyses. But I'm wondering about the "live" phase -- what approach would you suggest? I wouldn't want to force an open door, perhaps there are already packages/modules that could be used to read data in a loop i.e. every 10 seconds, maintain a a buffer of 15 readings and ring a bell when the data in buffer form a specific pattern (a spike, a trough, whatever)? I'll be grateful for a push in the right direction. Thanks, GS -- Grzegorz Staniak From nelle.varoquaux at gmail.com Fri Mar 23 13:01:42 2012 From: nelle.varoquaux at gmail.com (Nelle Varoquaux) Date: Fri, 23 Mar 2012 18:01:42 +0100 Subject: Data mining/pattern recogniton software in Python? In-Reply-To: References: Message-ID: Hello, There are two steps in using a supervised learning algorithm: fitting the classifier on data labeled, and predicting on new data. If you are looking to fit with incoming data, you are looking for online algorithms: algorithms that take chunks of data to fit the classifier on the fly. scikit-learn have a couple of algorithms that are online (k-means for example) If you are looking to predict with chunks of data, it can easily be done with any kind of already fitted classifier. Hence, you only need to find a way to retrieve the data. twisted may come in handy for that, or any other asynchronous framework. scikit-learn is not image oriented. You can do timeseries with it: there is probably already an example in the gallery. Hope that helped, N On 23 March 2012 17:43, Grzegorz Staniak wrote: > Hello, > > I've been asked by a colleague for help in a small educational > project, which would involve the recognition of patterns in a live > feed of data points (readings from a measuring appliance), and then > a more general search for patterns on archival data. The language > of preference is Python, since the lab uses software written in > Python already. I can see there are packages like Open CV, > scikit-learn, Orange that could perhaps be of use for the mining > phase -- and even if they are slanted towards image pattern > recognition, I think I'd be able to find an appropriate package > for the timeseries analyses. But I'm wondering about the "live" > phase -- what approach would you suggest? I wouldn't want to > force an open door, perhaps there are already packages/modules that > could be used to read data in a loop i.e. every 10 seconds, > maintain a a buffer of 15 readings and ring a bell when the data > in buffer form a specific pattern (a spike, a trough, whatever)? > > I'll be grateful for a push in the right direction. Thanks, > > GS > -- > Grzegorz Staniak > -- > http://mail.python.org/mailman/listinfo/python-list > -------------- next part -------------- An HTML attachment was scrubbed... URL: From clp2 at rebertia.com Fri Mar 23 13:16:23 2012 From: clp2 at rebertia.com (Chris Rebert) Date: Fri, 23 Mar 2012 10:16:23 -0700 Subject: Good web-development Python book In-Reply-To: References: <14efe443-2f0c-4b6f-a5be-f1e33288038a@eb6g2000vbb.googlegroups.com> Message-ID: On Fri, Mar 23, 2012 at 10:13 AM, Dennis Lee Bieber wrote: > On Fri, 23 Mar 2012 09:30:24 -0700, Chris Rebert > declaimed the following in gmane.comp.python.general: > >> On Fri, Mar 23, 2012 at 9:16 AM, Yves S. Garret >> wrote: > ? ? ? ? >> > make web-applications using Python (as opposed to something like PHP) >> > without any framework at the moment. ?Do you guys have any >> > suggestions? >> > >> >> The next edition of The Definitive Guide to Django, by the project's > > ? ? ? ?Note: the OP stated "without a framework"... To me that implies raw > Python from scratch... My bad, I completely overlooked that part of the post in my earnestness to answer? - Chris From ethan at stoneleaf.us Fri Mar 23 13:40:16 2012 From: ethan at stoneleaf.us (Ethan Furman) Date: Fri, 23 Mar 2012 10:40:16 -0700 Subject: Good web-development Python book In-Reply-To: References: <14efe443-2f0c-4b6f-a5be-f1e33288038a@eb6g2000vbb.googlegroups.com> Message-ID: <4F6CB580.5090505@stoneleaf.us> Chris Rebert wrote: > On Fri, Mar 23, 2012 at 10:13 AM, Dennis Lee Bieber wrote: >> On Fri, 23 Mar 2012 09:30:24 -0700, Chris Rebert >> declaimed the following in gmane.comp.python.general: >>> On Fri, Mar 23, 2012 at 9:16 AM, Yves S. Garret >>> ** wrote: >> >>>> make web-applications using Python (as opposed to something like PHP) >>>> without any framework at the moment. Do you guys have any >>>> suggestions? >>>> >>> The next edition of The Definitive Guide to Django, by the project's >> Note: the OP stated "without a framework"... To me that implies raw >> Python from scratch... > > My bad, I completely overlooked that part of the post in my > earnestness to answer? Completely understandable -- after all, who would not be earnest (and quick!) when replying to your surrogate god? ;) ~Ethan~ From colton.myers at gmail.com Fri Mar 23 13:56:04 2012 From: colton.myers at gmail.com (Colton Myers) Date: Fri, 23 Mar 2012 11:56:04 -0600 Subject: Good web-development Python book In-Reply-To: <14efe443-2f0c-4b6f-a5be-f1e33288038a@eb6g2000vbb.googlegroups.com> References: <14efe443-2f0c-4b6f-a5be-f1e33288038a@eb6g2000vbb.googlegroups.com> Message-ID: <9B84F99CE39D4B26986F6024377D1367@gmail.com> > Oooops! Sent my previous e-mail too soon! Didn't mean to. > > Another try. > > Hello, > > I'm trying to brush up on my Python and would like to learn how to > make web-apps. I was hoping to get a good book on learning how to > make web-applications using Python (as opposed to something like PHP) > without any framework at the moment. Do you guys have any > suggestions? > > I looked around on Amazon, but didn't really find anything too > promising. It was either very old or had no more than 3 stars in a > rating. I'd appreciate your help on this. > -- > http://mail.python.org/mailman/listinfo/python-list > > I'd suggest Programming Python as well. It has a whole section on "Internet Programming" which seems to be fairly agnostic as far as tools and frameworks go. http://www.amazon.com/Programming-Python-Mark-Lutz/dp/0596158106/ref=tmm_pap_title_0 -- Colton Myers (basepi) -------------- next part -------------- An HTML attachment was scrubbed... URL: From python at mrabarnett.plus.com Fri Mar 23 14:00:44 2012 From: python at mrabarnett.plus.com (MRAB) Date: Fri, 23 Mar 2012 18:00:44 +0000 Subject: Stream programming In-Reply-To: References: <4f6c9e17$0$1383$4fafbaef@reader2.news.tin.it> Message-ID: <4F6CBA4C.3020206@mrabarnett.plus.com> On 23/03/2012 16:33, Nathan Rice wrote: >> I will use "<=>" to mean "is equivalent to". That's not part of the DSL. >> A flow has one or more streams: >> 1 stream: >> [1,2,3] >> 2 streams: >> [1,3,5] | [2,4,6] >> Two flows can be concatenated: >> [1,2,3] + [4,5,6]<=> [1,2,3,4,5,6] >> [0] + ([1,2] | [3,4]) + [10]<=> [0,1,2,10] | [0,3,4,10] >> ([1,2] | [10,20]) + ([3,4] | [30,40])<=> [1,2,3,4] | [10,20,30,40] > > Algebraically, your concatenation rules don't really make sense - your > flows are both distributive and non distributive. You also make the > implicit assumption of an order over streams in a flow, but disregard > the implications of that assumption in some cases. I understand what > you're trying to communicate, so I think you need to be a little more > strict and explicit in your definitions. > When concatenating, either there are the same number of streams, or one of them is a single stream which is duplicated. Therefore, in this example: [0] + ([1, 2] | [3, 4]) you're concatenating a single stream with a pair, so the single stream is duplicated: ([0] | [0]) + ([1, 2] | [3, 4]) and then they can be concatenated: ([0, 1, 2] | [0, 3, 4]) However, this: ([0, 1] | [2, 3]) + ([4, 5] | [6, 7] | [8, 9]) won't work. From __peter__ at web.de Fri Mar 23 14:28:29 2012 From: __peter__ at web.de (Peter Otten) Date: Fri, 23 Mar 2012 19:28:29 +0100 Subject: Number of languages known [was Re: Python is readable] - somewhat OT References: <4f6bcdd5$0$29981$c3e8da3$5496439d@news.astraweb.com> <8694a85d-fe94-4bef-8bb6-8a8241d14ca3@px4g2000pbc.googlegroups.com> <4F6CA39B.9090709@stoneleaf.us> Message-ID: Ethan Furman wrote: > Nathan Rice wrote: >> Logo. It's turtles all the way down. > > +1 QOTW Surely you're joking, Mr Furman! From showell30 at yahoo.com Fri Mar 23 14:58:17 2012 From: showell30 at yahoo.com (Steve Howell) Date: Fri, 23 Mar 2012 11:58:17 -0700 (PDT) Subject: passing context into BaseHTTPRequestHandler Message-ID: I have a use case where I'm running BaseHTTPServer.HTTPServer, and I want to configure the request handler with some context. I've gotten the code to work, but it feels overly heavy. I am wondering if anybody could suggest an easier idiom for this. This is a brief sketch of the code: class MyHandler(BaseHTTPRequestHandler): def __init__(self, context, *args): self.context = context BaseHTTPRequestHandler.__init__(self, *args) def do_GET(self): // self.context will be available here context = { .... } def handler(*args): MyHandler(context, *args) server = HTTPServer(('', port), handler) server.serve_forever() Basically, it takes five lines of code just to pass context into the handler: def handler(*args): MyHandler(context, *args) def __init__(self, context, *args): self.context = context BaseHTTPRequestHandler.__init__(self, *args) Typically the second argument to HTTPServer is a subclass of BaseHTTPRequestHandler, but I pass in "handler" instead, which instantiates a new instance of MyHandler with the context from the enclosing scope. At first I tried to say "MyHandler(*args).context = context", but that assignment was too late, because BaseHTTPRequestHandler.__init__ does a lot of stuff during the construction phase. That's what forced me to write my own custom __init__ as well. I hope there's enough info here to understand what I'm trying to achieve, but if it helps to see my code in more context, you can see it here: https://gist.github.com/2173618 Thanks. From bh at intevation.de Fri Mar 23 15:19:22 2012 From: bh at intevation.de (Bernhard Herzog) Date: Fri, 23 Mar 2012 20:19:22 +0100 Subject: passing context into BaseHTTPRequestHandler References: Message-ID: Steve Howell writes: > I have a use case where I'm running BaseHTTPServer.HTTPServer, and I > want to configure the request handler with some context. I've gotten > the code to work, but it feels overly heavy. I am wondering if > anybody could suggest an easier idiom for this. > > This is a brief sketch of the code: > > class MyHandler(BaseHTTPRequestHandler): > def __init__(self, context, *args): > self.context = context > BaseHTTPRequestHandler.__init__(self, *args) > > def do_GET(self): > // self.context will be available here > > context = { .... } > def handler(*args): > MyHandler(context, *args) > > server = HTTPServer(('', port), handler) > server.serve_forever() You could store the context in the server object and access it in the handler methods via self.server.context. It basically works like this: class MyHTTPServer(HTTPServer): def __init__(self, *args, **kw): HTTPServer.__init__(self, *args, **kw) self.context = { .... } class MyHandler(BaseHTTPRequestHandler): def do_GET(self): context = self.server.context ... server = MyHTTPServer(('', port), MyHandler) server.serve_forever() Bernhard -- Bernhard Herzog | ++49-541-335 08 30 | http://www.intevation.de/ Intevation GmbH, Neuer Graben 17, 49074 Osnabr?ck | AG Osnabr?ck, HR B 18998 Gesch?ftsf?hrer: Frank Koormann, Bernhard Reiter, Dr. Jan-Oliver Wagner From nathan.alexander.rice at gmail.com Fri Mar 23 15:23:00 2012 From: nathan.alexander.rice at gmail.com (Nathan Rice) Date: Fri, 23 Mar 2012 15:23:00 -0400 Subject: Stream programming In-Reply-To: <4F6CBA4C.3020206@mrabarnett.plus.com> References: <4f6c9e17$0$1383$4fafbaef@reader2.news.tin.it> <4F6CBA4C.3020206@mrabarnett.plus.com> Message-ID: >>> ?I will use "<=>" to mean "is equivalent to". That's not part of the DSL. >>> ?A flow has one or more streams: >>> ? 1 stream: >>> ? ? [1,2,3] >>> ? 2 streams: >>> ? ? [1,3,5] | [2,4,6] >>> ?Two flows can be concatenated: >>> ? [1,2,3] + [4,5,6]<=> ?[1,2,3,4,5,6] >>> ? [0] + ([1,2] | [3,4]) + [10]<=> ?[0,1,2,10] | [0,3,4,10] >>> ? ([1,2] | [10,20]) + ([3,4] | [30,40])<=> ?[1,2,3,4] | [10,20,30,40] >> >> >> Algebraically, your concatenation rules don't really make sense - your >> flows are both distributive and non distributive. ?You also make the >> implicit assumption of an order over streams in a flow, but disregard >> the implications of that assumption in some cases. ?I understand what >> you're trying to communicate, so I think you need to be a little more >> strict and explicit in your definitions. >> > When concatenating, either there are the same number of streams, or one > of them is a single stream which is duplicated. > > Therefore, in this example: > > ? ?[0] + ([1, 2] | [3, 4]) > > you're concatenating a single stream with a pair, so the single stream > is duplicated: > > ? ?([0] | [0]) + ([1, 2] | [3, 4]) > > and then they can be concatenated: > > ? ?([0, 1, 2] | [0, 3, 4]) > > However, this: > > ? ?([0, 1] | [2, 3]) + ([4, 5] | [6, 7] | [8, 9]) > > won't work. I understand how he wants the system to work in this case; my point was that it isn't consistent. He stated flows can be concatenated, so [0] is just a flow of a single stream. Because he clearly intends that streams in a flow are ordered, that indicates that he wants some sort of algebraic module. He could get close if he can extend a stream to meet the requirements of a ring, then a flow would be a module over the ring of streams. The problem he is going to run into is that operations on streams as he defines them are not commutative. Identity elements for the two binary operations are also not immediately obvious to me. He could just be smart and use the pi calculus, it is rigorously developed and can model his desired behavior, if he reformulates it slightly. Another option is just to give up on being rigorous. Given the abstract treatment he attempted I would be disappointed, but if his only goal is to get practice writing code and he isn't interested in exploring the conceptual space of the problem domain it would be the right decision. From kiuhnm03.4t.yahoo.it Fri Mar 23 16:33:44 2012 From: kiuhnm03.4t.yahoo.it (Kiuhnm) Date: Fri, 23 Mar 2012 21:33:44 +0100 Subject: Stream programming In-Reply-To: References: <4f6c9e17$0$1383$4fafbaef@reader2.news.tin.it> Message-ID: <4f6cde28$0$1383$4fafbaef@reader1.news.tin.it> On 3/23/2012 17:33, Nathan Rice wrote: >> I will use "<=>" to mean "is equivalent to". That's not part of the DSL. >> A flow has one or more streams: >> 1 stream: >> [1,2,3] >> 2 streams: >> [1,3,5] | [2,4,6] >> Two flows can be concatenated: >> [1,2,3] + [4,5,6]<=> [1,2,3,4,5,6] >> [0] + ([1,2] | [3,4]) + [10]<=> [0,1,2,10] | [0,3,4,10] >> ([1,2] | [10,20]) + ([3,4] | [30,40])<=> [1,2,3,4] | [10,20,30,40] > > Algebraically, your concatenation rules don't really make sense - your > flows are both distributive and non distributive. ? > You also make the > implicit assumption of an order over streams in a flow, but disregard > the implications of that assumption in some cases. ? > I understand what > you're trying to communicate, so I think you need to be a little more > strict and explicit in your definitions. No, I don't think you understand what I meant. >> A flow can be transformed: >> [1,2] - f<=> [f(1),f(2)] >> ([1,2] | [3,4]) - f<=> [f(1,3),f(2,4)] >> ([1,2] | [3,4]) - [f]<=> [f(1),f(2)] | [f(3),f(4)] >> ([1,2] | [3,4]) - [f,g]<=> [f(1),f(2)] | [g(3),g(4)] >> [1,2] - [f,g]<=> [f(1),f(2)] | [g(1),g(2)] > > Given the examples you pose here, it is clear that you are assuming > that the streams are synchronized in discrete time. Since you do not > provide any mechanism for temporal alignment of streams you are also > assuming every stream will have an element at every time point, the > streams start at the same time and are of the same length. Is this > what you want? Yes. I thought that streams as an alternative to functional programming were widely known. >> Some functions are special and almost any function can be made special: >> [1,2,3,4,5] - filter(isprime)<=> [2,3,5] >> [[],(1,2),[3,4,5]] - flatten<=> [1,2,3,4,5] >> Note that 'filter' is not really necessary, thanks to 'flatten'. > > This implies that your transformations again produce flows. You > should explicitly state this. Isn't that obvious? BTW, those are not rigorous definitions. I thought I was talking to people who regularly works with streams. >> Flows can be named, remembered and used >> as a value: >> [1,2,3,4,5] - 'flow' + val('flow')<=> [1,2,3,4,5]*2 > > Is this a flow with two identical streams, or a flow with one long > stream formed by concatenation? What does [1,2,3,4,5]*2 mean in Python? Those are Python's lists/arrays. >> as a transformation chain: >> [1,2,3] - skipfirst - 'again' | [4,5,6] - func('again') >> <=> [2,3] | [5,6] >> Recursion is also possible and stops when a function is applied to an empty >> sequence. >> Flows can be saved (push) and restored (pop) : >> [1,2,3,4] - push - by(2) - 'double' - pop | val('double') >> <=> [1,2,3,4] | [2,4,6,8] >> There are easier ways to achieve the same result, of course: >> [1,2,3,4] - [id, by(2)] > > You are grasping at an algebra here, a sort of calculus of temporal > observations. You need to step back and make it rigorous before you > worry about issues such as a readable syntax. > > Nathan I don't agree. Sorry. Kiuhnm From kiuhnm03.4t.yahoo.it Fri Mar 23 16:44:27 2012 From: kiuhnm03.4t.yahoo.it (Kiuhnm) Date: Fri, 23 Mar 2012 21:44:27 +0100 Subject: Stream programming In-Reply-To: References: <4f6c9e17$0$1383$4fafbaef@reader2.news.tin.it> <4F6CBA4C.3020206@mrabarnett.plus.com> Message-ID: <4f6ce0ab$0$1384$4fafbaef@reader1.news.tin.it> On 3/23/2012 20:23, Nathan Rice wrote: >>>> I will use "<=>" to mean "is equivalent to". That's not part of the DSL. >>>> A flow has one or more streams: >>>> 1 stream: >>>> [1,2,3] >>>> 2 streams: >>>> [1,3,5] | [2,4,6] >>>> Two flows can be concatenated: >>>> [1,2,3] + [4,5,6]<=> [1,2,3,4,5,6] >>>> [0] + ([1,2] | [3,4]) + [10]<=> [0,1,2,10] | [0,3,4,10] >>>> ([1,2] | [10,20]) + ([3,4] | [30,40])<=> [1,2,3,4] | [10,20,30,40] >>> >>> >>> Algebraically, your concatenation rules don't really make sense - your >>> flows are both distributive and non distributive. You also make the >>> implicit assumption of an order over streams in a flow, but disregard >>> the implications of that assumption in some cases. I understand what >>> you're trying to communicate, so I think you need to be a little more >>> strict and explicit in your definitions. >>> >> When concatenating, either there are the same number of streams, or one >> of them is a single stream which is duplicated. >> >> Therefore, in this example: >> >> [0] + ([1, 2] | [3, 4]) >> >> you're concatenating a single stream with a pair, so the single stream >> is duplicated: >> >> ([0] | [0]) + ([1, 2] | [3, 4]) >> >> and then they can be concatenated: >> >> ([0, 1, 2] | [0, 3, 4]) >> >> However, this: >> >> ([0, 1] | [2, 3]) + ([4, 5] | [6, 7] | [8, 9]) >> >> won't work. > > I understand how he wants the system to work in this case; my point > was that it isn't consistent. > > He stated flows can be concatenated, so [0] is just a flow of a single > stream. Because he clearly intends that streams in a flow are > ordered, that indicates that he wants some sort of algebraic module. > He could get close if he can extend a stream to meet the requirements > of a ring, then a flow would be a module over the ring of streams. > The problem he is going to run into is that operations on streams as > he defines them are not commutative. Identity elements for the two > binary operations are also not immediately obvious to me. Instead of talking of what I wasn't trying to do and, indeed, I didn't do, you should try to understand what I wanted to do and, in fact, I did. I'm afraid your cup is too full to understand simple things as the one I wrote in my OP. Kiuhnm From ethan at stoneleaf.us Fri Mar 23 17:12:51 2012 From: ethan at stoneleaf.us (Ethan Furman) Date: Fri, 23 Mar 2012 14:12:51 -0700 Subject: Stream programming In-Reply-To: <4f6cde28$0$1383$4fafbaef@reader1.news.tin.it> References: <4f6c9e17$0$1383$4fafbaef@reader2.news.tin.it> <4f6cde28$0$1383$4fafbaef@reader1.news.tin.it> Message-ID: <4F6CE753.5080104@stoneleaf.us> Kiuhnm wrote: > On 3/23/2012 17:33, Nathan Rice wrote: >> Given the examples you pose here, it is clear that you are assuming >> that the streams are synchronized in discrete time. Since you do not >> provide any mechanism for temporal alignment of streams you are also >> assuming every stream will have an element at every time point, the >> streams start at the same time and are of the same length. Is this >> what you want? > > Yes. I thought that streams as an alternative to functional programming > were widely known. Don't know about widely, but I can say I am unfamiliar with the way you are using them. >> This implies that your transformations again produce flows. You >> should explicitly state this. > > Isn't that obvious? BTW, those are not rigorous definitions. I thought I > was talking to people who regularly works with streams. Why would you think that? This list is composed of all types that use Python. I've seen occasional discussion of functional programming, but I've only seen anything this confusing maybe twice before... granted, I don't read *everything*, but I do read quite a bit -- especially the stuff that looks like it might be interesting... like "stream programming", for example. ;) After the discussion I've seen so far, I still have no idea how I would use your code or what it's good for. ~Ethan~ From nathan.alexander.rice at gmail.com Fri Mar 23 17:18:19 2012 From: nathan.alexander.rice at gmail.com (Nathan Rice) Date: Fri, 23 Mar 2012 17:18:19 -0400 Subject: Stream programming In-Reply-To: <4f6cde28$0$1383$4fafbaef@reader1.news.tin.it> References: <4f6c9e17$0$1383$4fafbaef@reader2.news.tin.it> <4f6cde28$0$1383$4fafbaef@reader1.news.tin.it> Message-ID: >> ?I understand what >> you're trying to communicate, so I think you need to be a little more >> strict and explicit in your definitions. > > > No, I don't think you understand what I meant. I don't agree. Sorry. > Yes. I thought that streams as an alternative to functional programming were > widely known. Streams aren't really a paradigm of computation. They're a semantic element of a computational system which cuts across paradigms. If you want to retract that and say you were talking about dataflow programming (which is much larger than streams, and actually has a cohesive definition), I won't hold it against you. Ultimately though, functional programming and dataflow programming are closely linked, the main difference being the use of queues based rather than stacks. > Isn't that obvious? BTW, those are not rigorous definitions. I thought I was talking to people who regularly works with streams. That is the GPU mailing list, down the hall on the left. > Instead of talking of what I wasn't trying to do and, indeed, I didn't do, > you should try to understand what I wanted to do and, in fact, I did. > I'm afraid your cup is too full to understand simple things as the one I > wrote in my OP. Clearly, because I didn't explicitly include the possibility that you are just writing throwaway code with no attempt at development of ideas for the purpose of practicing writing code in the paragraph after the one you quoted. If your goal is to learn to code, instead of posting a message stating that you have a superior way to compose code, you might want to try to solve a problem and ask others their opinion of the structure and techniques in your code. From showell30 at yahoo.com Fri Mar 23 17:37:36 2012 From: showell30 at yahoo.com (Steve Howell) Date: Fri, 23 Mar 2012 14:37:36 -0700 (PDT) Subject: passing context into BaseHTTPRequestHandler References: Message-ID: <6dd1112f-880a-4967-8827-85e8f591e8fb@t2g2000pbg.googlegroups.com> On Mar 23, 12:19?pm, Bernhard Herzog wrote: > Steve Howell writes: > > I have a use case where I'm running BaseHTTPServer.HTTPServer, and I > > want to configure the request handler with some context. ?I've gotten > > the code to work, but it feels overly heavy. ?I am wondering if > > anybody could suggest an easier idiom for this. > > > This is a brief sketch of the code: > > > ? ? class MyHandler(BaseHTTPRequestHandler): > > ? ? ? ? def __init__(self, context, *args): > > ? ? ? ? ? ? self.context = context > > ? ? ? ? ? ? BaseHTTPRequestHandler.__init__(self, *args) > > > ? ? ? ? def do_GET(self): > > ? ? ? ? ? ? // self.context will be available here > > > ? ? context = { .... } > > ? ? def handler(*args): > > ? ? ? ? MyHandler(context, *args) > > > ? ? server = HTTPServer(('', port), handler) > > ? ? server.serve_forever() > > You could store the context in the server object and access it in the > handler methods via self.server.context. It basically works like this: > > class MyHTTPServer(HTTPServer): > > ? ? def __init__(self, *args, **kw): > ? ? ? ? HTTPServer.__init__(self, *args, **kw) > ? ? ? ? self.context = { .... } > > class MyHandler(BaseHTTPRequestHandler): > > ? ? def do_GET(self): > ? ? ? ? context = self.server.context > ? ? ? ? ... > > server = MyHTTPServer(('', port), MyHandler) > server.serve_forever() > Thanks for the suggestion. I made the change, and I think the code's a bit easier to read now. From mentifex at myuw.net Fri Mar 23 18:47:01 2012 From: mentifex at myuw.net (Mentifex) Date: Fri, 23 Mar 2012 15:47:01 -0700 (PDT) Subject: Escape from /dev/null Message-ID: <8004ce27-3b75-4f92-b457-e8322625f789@t6g2000pba.googlegroups.com> Reddit has just published a note about http://www.spotify.com/us/devnull/ which purports to be "a programmer competition that is going to blow your mind." It says that "You will need at least a couple of years experience coding JavaScript and/or Python to have fun and be really good at it to clear the last challenges :) " /dev/null is a hard place to escape from. It keeps calling you back from the vasty deep (see below). Mentifex -- Charter member (with Tim Bradshaw) of Mad People of Comp.Lang.Lisp at http://www.tfeb.org/lisp/mad-people.html http://dev.null.org/psychoceramics/archives/1998.05/msg00018.html From news at blinne.net Fri Mar 23 18:59:44 2012 From: news at blinne.net (Alexander Blinne) Date: Fri, 23 Mar 2012 23:59:44 +0100 Subject: Documentation, assignment in expression. Message-ID: <4f6d0060$0$6634$9b4e6d93@newsspool2.arcor-online.net> Hi, I think this section of the docs needs some kind of rewrite: While it is great to discuss the reasons for not allowing an assignment in an expression, I feel that the given example is some kind of outdated. The last sentence "For example, in the current version of Python file objects support the iterator protocol, so you can now write simply (for line in file:)" makes me think that this section was written while that syntax was still new. No one I know would ever write something like this: > while True: > line = f.readline() > if not line: > break > ... # do something with line I think at least we need a new example. Any ideas? Greetings Alexander From emacsray at gmail.com Fri Mar 23 19:32:38 2012 From: emacsray at gmail.com (Ray Song) Date: Sat, 24 Mar 2012 07:32:38 +0800 Subject: Stream programming In-Reply-To: <4f6c9e17$0$1383$4fafbaef@reader2.news.tin.it> References: <4f6c9e17$0$1383$4fafbaef@reader2.news.tin.it> Message-ID: <20120323233238.GA2713@lap.tuna.tsinghua.edu.cn> On Fri, Mar 23, 2012 at 05:00:23PM +0100, Kiuhnm wrote: > I've been writing a little library for handling streams as an excuse for > doing a little OOP with Python. > > I don't share some of the views on readability expressed on this ng. > Indeed, I believe that a piece of code may very well start as complete > gibberish and become a pleasure to read after some additional > information is provided. > > I must say that imposed indentation is a pain when one is trying to > define some sort of DSL (domain specific language). Also, Python's > operator overloading is a bit limited, but that makes for a more > rewarding experience in my case. > > Here's an example of what you can write: > > numbers - push - avrg - 'med' - pop - filter(lt('med'), ge('med'))\ > - ['same', 'same'] - streams(cat) - 'same' > > Ok, we're at the "complete gibberish" phase. > > Time to give you the "additional information". > > I will use "<=>" to mean "is equivalent to". That's not part of the DSL. > A flow has one or more streams: > 1 stream: > [1,2,3] > 2 streams: > [1,3,5] | [2,4,6] > Two flows can be concatenated: > [1,2,3] + [4,5,6] <=> [1,2,3,4,5,6] > [0] + ([1,2] | [3,4]) + [10] <=> [0,1,2,10] | [0,3,4,10] > ([1,2] | [10,20]) + ([3,4] | [30,40]) <=> [1,2,3,4] | [10,20,30,40] > A flow can be transformed: > [1,2] - f <=> [f(1),f(2)] > ([1,2] | [3,4]) - f <=> [f(1,3),f(2,4)] > ([1,2] | [3,4]) - [f] <=> [f(1),f(2)] | [f(3),f(4)] > ([1,2] | [3,4]) - [f,g] <=> [f(1),f(2)] | [g(3),g(4)] > [1,2] - [f,g] <=> [f(1),f(2)] | [g(1),g(2)] > Some functions are special and almost any function can be made special: > [1,2,3,4,5] - filter(isprime) <=> [2,3,5] > [[],(1,2),[3,4,5]] - flatten <=> [1,2,3,4,5] > Note that 'filter' is not really necessary, thanks to 'flatten'. > Flows can be named, remembered and used > as a value: > [1,2,3,4,5] - 'flow' + val('flow') <=> [1,2,3,4,5]*2 > as a transformation chain: > [1,2,3] - skipfirst - 'again' | [4,5,6] - func('again') > <=> [2,3] | [5,6] > Recursion is also possible and stops when a function is applied to an > empty sequence. > Flows can be saved (push) and restored (pop) : > [1,2,3,4] - push - by(2) - 'double' - pop | val('double') > <=> [1,2,3,4] | [2,4,6,8] > There are easier ways to achieve the same result, of course: > [1,2,3,4] - [id, by(2)] > > Let's go back to our example. I didn't tell you anything but you should > be able to understand it anyway. > > numbers - push - avrg - 'med' - pop - filter(lt('med'), ge('med'))\ > - ['same', 'same'] - streams(cat) - 'same' > > It reads as > > "take a list of numbers - save it - compute the average and named it > 'med' - restore the flow - create two streams which have, respect., the > numbers less than 'med' and those greater or equal to 'med' - do the > /entire/ 'same' process on each one of the two streams - concat the > resulting streams - name all this /entire/ process 'same'. > Not readable enough? Replace 'same' with 'qsort'. > > Is that readable or am I going crazy? [note: that's a rhetorical > question whose answer is "That's very readable!"] > This sounds like a concatenative programming and i've found many cool examples from Haskell and Ruby. I was pleased with Python's rigid off-side rule at first but frustrated when I realized that this is a two-edged blade as the rule makes a DSL difficult. Sorry for former mail to you (my damn Android gmail client doesn't understand mailing lists well). -- Ray From kiuhnm03.4t.yahoo.it Fri Mar 23 19:57:28 2012 From: kiuhnm03.4t.yahoo.it (Kiuhnm) Date: Sat, 24 Mar 2012 00:57:28 +0100 Subject: Stream programming In-Reply-To: References: <4f6c9e17$0$1383$4fafbaef@reader2.news.tin.it> <4f6cde28$0$1383$4fafbaef@reader1.news.tin.it> Message-ID: <4f6d0de7$0$1384$4fafbaef@reader1.news.tin.it> On 3/23/2012 22:12, Ethan Furman wrote: > Kiuhnm wrote: >> On 3/23/2012 17:33, Nathan Rice wrote: >>> Given the examples you pose here, it is clear that you are assuming >>> that the streams are synchronized in discrete time. Since you do not >>> provide any mechanism for temporal alignment of streams you are also >>> assuming every stream will have an element at every time point, the >>> streams start at the same time and are of the same length. Is this >>> what you want? >> >> Yes. I thought that streams as an alternative to functional >> programming were widely known. > > Don't know about widely, but I can say I am unfamiliar with the way you > are using them. That's good! It means I'm saying something new (and, hopefully, interesting). >>> This implies that your transformations again produce flows. You >>> should explicitly state this. >> >> Isn't that obvious? BTW, those are not rigorous definitions. I thought >> I was talking to people who regularly works with streams. > > Why would you think that? This list is composed of all types that use > Python. I've seen occasional discussion of functional programming, but > I've only seen anything this confusing maybe twice before... granted, I > don't read *everything*, but I do read quite a bit -- especially the > stuff that looks like it might be interesting... like "stream > programming", for example. ;) > > > After the discussion I've seen so far, I still have no idea how I would > use your code or what it's good for. The idea is simple. Flows or streams let you be more declarative without being too functional :) In imperative progamming you write statements or commands. In functional programming (FP) you write expressions. In streaming programming (SP) you create flows. Basically, if in FP you write h9(h8(h7(.....(h1)....))) in SP you write h1-h2-h3-...-h9 which I greatly prefer because that's the way I think. I think that SP could be an interesting alternative to FP (in ten years, maybe). Mine was just a little experiment. Kiuhnm From kiuhnm03.4t.yahoo.it Fri Mar 23 20:26:51 2012 From: kiuhnm03.4t.yahoo.it (Kiuhnm) Date: Sat, 24 Mar 2012 01:26:51 +0100 Subject: Stream programming In-Reply-To: References: <4f6c9e17$0$1383$4fafbaef@reader2.news.tin.it> <4f6cde28$0$1383$4fafbaef@reader1.news.tin.it> Message-ID: <4f6d14ca$0$1392$4fafbaef@reader1.news.tin.it> On 3/23/2012 22:18, Nathan Rice wrote: >>> I understand what >>> you're trying to communicate, so I think you need to be a little more >>> strict and explicit in your definitions. >> >> >> No, I don't think you understand what I meant. > > I don't agree. Sorry. You could just point out those inconsistencies that you found. >> Yes. I thought that streams as an alternative to functional programming were >> widely known. > > Streams aren't really a paradigm of computation. They're a semantic > element of a computational system which cuts across paradigms. If you > want to retract that and say you were talking about dataflow > programming (which is much larger than streams, and actually has a > cohesive definition), I won't hold it against you. I wasn't talking of dataflow programming. "Flow programming" is much closer to functional programming than dataflow programming is. >> Instead of talking of what I wasn't trying to do and, indeed, I didn't do, >> you should try to understand what I wanted to do and, in fact, I did. >> I'm afraid your cup is too full to understand simple things as the one I >> wrote in my OP. > > Clearly, because I didn't explicitly include the possibility that you > are just writing throwaway code with no attempt at development of > ideas for the purpose of practicing writing code in the paragraph > after the one you quoted. x != 'a' doesn't imply that x == 'b'. > If your goal is to learn to code, instead of posting a message stating > that you have a superior way to compose code, you might want to try to > solve a problem and ask others their opinion of the structure and > techniques in your code. Never said it was superior. We've been talking about readability a lot, haven't we? I was just proposing something different. Kiuhnm From kiuhnm03.4t.yahoo.it Fri Mar 23 20:41:38 2012 From: kiuhnm03.4t.yahoo.it (Kiuhnm) Date: Sat, 24 Mar 2012 01:41:38 +0100 Subject: Stream programming In-Reply-To: References: <4f6c9e17$0$1383$4fafbaef@reader2.news.tin.it> Message-ID: <4f6d1841$0$1381$4fafbaef@reader1.news.tin.it> On 3/24/2012 0:32, Ray Song wrote: > On Fri, Mar 23, 2012 at 05:00:23PM +0100, Kiuhnm wrote: >> I've been writing a little library for handling streams as an excuse for >> doing a little OOP with Python. >> >> I don't share some of the views on readability expressed on this ng. >> Indeed, I believe that a piece of code may very well start as complete >> gibberish and become a pleasure to read after some additional >> information is provided. >> >> I must say that imposed indentation is a pain when one is trying to >> define some sort of DSL (domain specific language). Also, Python's >> operator overloading is a bit limited, but that makes for a more >> rewarding experience in my case. >> >> Here's an example of what you can write: >> >> numbers - push - avrg - 'med' - pop - filter(lt('med'), ge('med'))\ >> - ['same', 'same'] - streams(cat) - 'same' >> >> Ok, we're at the "complete gibberish" phase. >> >> Time to give you the "additional information". >> >> I will use "<=>" to mean "is equivalent to". That's not part of the DSL. >> A flow has one or more streams: >> 1 stream: >> [1,2,3] >> 2 streams: >> [1,3,5] | [2,4,6] >> Two flows can be concatenated: >> [1,2,3] + [4,5,6]<=> [1,2,3,4,5,6] >> [0] + ([1,2] | [3,4]) + [10]<=> [0,1,2,10] | [0,3,4,10] >> ([1,2] | [10,20]) + ([3,4] | [30,40])<=> [1,2,3,4] | [10,20,30,40] >> A flow can be transformed: >> [1,2] - f<=> [f(1),f(2)] >> ([1,2] | [3,4]) - f<=> [f(1,3),f(2,4)] >> ([1,2] | [3,4]) - [f]<=> [f(1),f(2)] | [f(3),f(4)] >> ([1,2] | [3,4]) - [f,g]<=> [f(1),f(2)] | [g(3),g(4)] >> [1,2] - [f,g]<=> [f(1),f(2)] | [g(1),g(2)] >> Some functions are special and almost any function can be made special: >> [1,2,3,4,5] - filter(isprime)<=> [2,3,5] >> [[],(1,2),[3,4,5]] - flatten<=> [1,2,3,4,5] >> Note that 'filter' is not really necessary, thanks to 'flatten'. >> Flows can be named, remembered and used >> as a value: >> [1,2,3,4,5] - 'flow' + val('flow')<=> [1,2,3,4,5]*2 >> as a transformation chain: >> [1,2,3] - skipfirst - 'again' | [4,5,6] - func('again') >> <=> [2,3] | [5,6] >> Recursion is also possible and stops when a function is applied to an >> empty sequence. >> Flows can be saved (push) and restored (pop) : >> [1,2,3,4] - push - by(2) - 'double' - pop | val('double') >> <=> [1,2,3,4] | [2,4,6,8] >> There are easier ways to achieve the same result, of course: >> [1,2,3,4] - [id, by(2)] >> >> Let's go back to our example. I didn't tell you anything but you should >> be able to understand it anyway. >> >> numbers - push - avrg - 'med' - pop - filter(lt('med'), ge('med'))\ >> - ['same', 'same'] - streams(cat) - 'same' >> >> It reads as >> >> "take a list of numbers - save it - compute the average and named it >> 'med' - restore the flow - create two streams which have, respect., the >> numbers less than 'med' and those greater or equal to 'med' - do the >> /entire/ 'same' process on each one of the two streams - concat the >> resulting streams - name all this /entire/ process 'same'. >> Not readable enough? Replace 'same' with 'qsort'. >> >> Is that readable or am I going crazy? [note: that's a rhetorical >> question whose answer is "That's very readable!"] >> > > This sounds like a concatenative programming and i've found many cool > examples from Haskell and Ruby. I was pleased with Python's rigid > off-side rule at first but frustrated when I realized that this is a > two-edged blade as the rule makes a DSL difficult. Yes, there is that. I also noticed that I couldn't use the comparison operators the way I liked. Precedence is also an issue. I had to use '+' and '-' instead of '+' and '>>' or '>' because of that. I didn't want to introduce extra parentheses. > Sorry for former mail to you (my damn Android gmail client doesn't > understand mailing lists well). Don't worry, my email address is invalid! Kiuhnm From roy at panix.com Fri Mar 23 21:37:40 2012 From: roy at panix.com (Roy Smith) Date: Fri, 23 Mar 2012 21:37:40 -0400 Subject: Documentation, assignment in expression. References: <4f6d0060$0$6634$9b4e6d93@newsspool2.arcor-online.net> Message-ID: In article <4f6d0060$0$6634$9b4e6d93 at newsspool2.arcor-online.net>, Alexander Blinne wrote: > The last sentence "For example, in the current version of Python file > objects support the iterator protocol, so you can now write simply > (for line in file:)" ... In general, words like "current", "previous", and "next" don't belong in documentation. The timepoint to which they refer changes as soon as they're published. Much better to say, "as of version x.y..." From joncle at googlemail.com Fri Mar 23 23:10:28 2012 From: joncle at googlemail.com (Jon Clements) Date: Fri, 23 Mar 2012 20:10:28 -0700 (PDT) Subject: Data mining/pattern recogniton software in Python? In-Reply-To: References: Message-ID: <30719938.516.1332558628851.JavaMail.geo-discussion-forums@vbut24> On Friday, 23 March 2012 16:43:40 UTC, Grzegorz Staniak wrote: > Hello, > > I've been asked by a colleague for help in a small educational > project, which would involve the recognition of patterns in a live > feed of data points (readings from a measuring appliance), and then > a more general search for patterns on archival data. The language > of preference is Python, since the lab uses software written in > Python already. I can see there are packages like Open CV, > scikit-learn, Orange that could perhaps be of use for the mining > phase -- and even if they are slanted towards image pattern > recognition, I think I'd be able to find an appropriate package > for the timeseries analyses. But I'm wondering about the "live" > phase -- what approach would you suggest? I wouldn't want to > force an open door, perhaps there are already packages/modules that > could be used to read data in a loop i.e. every 10 seconds, > maintain a a buffer of 15 readings and ring a bell when the data > in buffer form a specific pattern (a spike, a trough, whatever)? > > I'll be grateful for a push in the right direction. Thanks, > > GS > -- > Grzegorz Staniak It might also be worth checking out pandas[1] and scikits.statsmodels[2]. In terms of reading data in a loop I would probably go for a producer-consumer model (possibly using a Queue[3]). Have the consumer constantly try to get another reading, and notify the consumer which can then determine if it's got enough data to calculate a peak/trough. This article is also a fairly good read[4]. That's some pointers anyway, hth, Jon. [1] http://pandas.pydata.org/ [2] http://statsmodels.sourceforge.net/ [3] http://docs.python.org/library/queue.html [4] http://www.laurentluce.com/posts/python-threads-synchronization-locks-rlocks-semaphores-conditions-events-and-queues/ From steve+comp.lang.python at pearwood.info Fri Mar 23 23:23:44 2012 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 24 Mar 2012 03:23:44 GMT Subject: Stream programming References: <4f6c9e17$0$1383$4fafbaef@reader2.news.tin.it> Message-ID: <4f6d3e3f$0$29981$c3e8da3$5496439d@news.astraweb.com> On Fri, 23 Mar 2012 17:00:23 +0100, Kiuhnm wrote: > I've been writing a little library for handling streams as an excuse for > doing a little OOP with Python. > > I don't share some of the views on readability expressed on this ng. > Indeed, I believe that a piece of code may very well start as complete > gibberish and become a pleasure to read after some additional > information is provided. [...] > numbers - push - avrg - 'med' - pop - filter(lt('med'), ge('med'))\ > - ['same', 'same'] - streams(cat) - 'same' > > Ok, we're at the "complete gibberish" phase. > > Time to give you the "additional information". There are multiple problems with your DSL. Having read your explanation, and subsequent posts, I think I understand the data model, but the syntax itself is not very good and far from readable. It is just too hard to reason about the code. Your syntax conflicts with established, far more common, use of the same syntax: you use - to mean "call a function" and | to join two or more streams into a flow. You also use () for calling functions, and the difference between - and () isn't clear. So a mystery there -- your DSL seems to have different function syntax, depending on... what? The semantics are unclear even after your examples. To understand your syntax, you give examples, but to understand the examples, the reader needs to understand the syntax. That suggests that the semantics are unclear even in your own mind, or at least too difficult to explain in simple examples. Take this example: > Flows can be saved (push) and restored (pop) : > [1,2,3,4] - push - by(2) - 'double' - pop | val('double') > <=> [1,2,3,4] | [2,4,6,8] What the hell does that mean? The reader initially doesn't know what *any* of push, by(2), pop or val('double') means. All they see is an obfuscated series of calls that starts with a stream as input, makes a copy of it, and doubles the entries in the copy: you make FIVE function calls to perform TWO conceptual operations. So the reader can't even map a function call to a result. With careful thought and further explanations from you, the reader (me) eventually gets a mental model here. Your DSL has a single input which is pipelined through a series of function calls by the - operator, plus a separate stack. (I initially thought that, like Forth, your DSL was stack based. But it isn't, is it?) It seems to me that the - operator is only needed as syntactic sugar to avoid using reverse Polish notation and an implicit stack. Instead of the Forth-like: [1,2,3,4] dup 2 * your DSL has an explicit stack, and an explicit - operator to call a function. Presumably "[1,2] push" would be a syntax error. I think this is a good example of an inferior syntax. Contrast your: [1,2,3,4] - push - by(2) - 'double' - pop | val('double') with the equivalent RPL: [1,2,3,4] dup 2 * Now *that* is a pleasure to read, once you wrap your head around reverse Polish notation and the concept of a stack. Which you need in your DSL anyway, to understand push and pop. You say that this is an "easier way to get the same result": [1,2,3,4] - [id, by(2)] but it isn't, is it? The more complex example above ends up with two streams joined in a single flow: [1,2,3,4]|[2,4,6,8] whereas the shorter version using the magic "id" gives you a single stream containing nested streams: [[1,2,3,4], [2,4,6,8]] So, how could you make this more readable? * Don't fight the reader's expectations. If they've programmed in Unix shells, they expect | as the pipelining operator. If they haven't, they probably will find >> easy to read as a dataflow operator. Either way, they're probably used to seeing a|b as meaning "or" (as in "this stream, or this stream") rather than the way you seem to be using it ("this stream, and this stream"). Here's my first attempt at improved syntax that doesn't fight the user: [1,2,3,4] >> push >> by(2) >> 'double' >> pop & val('double') "push" and "pop" are poor choices of words. Push does not actually push its input onto the stack, which would leave the input stream empty. It makes a copy. You explain what they do: "Flows can be saved (push) and restored (pop)" so why not just use SAVE and RESTORE as your functions? Or if they're too verbose, STO and RCL, or my preference, store and recall. [1,2,3,4] >> store >> by(2) >> 'double' >> recall & val('double') I'm still not happy with & for the join operator. I think that the use of + for concatenate and & for join is just one of those arbitrary choices that the user will have to learn. Although I'm tempted to try using a colon instead. [1,2,3]:[4,5,6] would be a flow with two streams. I don't like the syntax for defining and using names. Here's a random thought: [1,2,3,4] >> store >> by(2) >> @double >> recall & double Use @name to store to a name, and the name alone to retrieve from it. But I haven't given this too much thought, so it too might suck. Some other problems with your DSL: > A flow can be transformed: > [1,2] - f <=> [f(1),f(2)] but that's not consistently true. For instance: [1,2] - push <=/=> [push(1), push(2)] So the reader needs to know all the semantics of the particular function f before being able to reason about the flow. Your DSL displays magic behaviour, which is bad and makes it hard to read the code because the reader may not know which functions are magic and which are not. > Some functions are special and almost any function can be made special: > [1,2,3,4,5] - filter(isprime) <=> [2,3,5] > [[],(1,2),[3,4,5]] - flatten <=> [1,2,3,4,5] You say that as if it were a good thing. -- Steven From akghosh3 at gmail.com Fri Mar 23 23:37:35 2012 From: akghosh3 at gmail.com (Aloke Ghosh) Date: Sat, 24 Mar 2012 09:07:35 +0530 Subject: Help needed to understand the error message Message-ID: Hi, I am learning Python and do not have programming experience. I was following an exercise from http://learnpythonthehardway.org/book/ex2.html and made a mistake in entry : *Print"I like typing this."* and got the following error message: *In [2]: Print"I like typing this."* *------------------------------------------------------------* * File "", line 1* * Print"I like typing this."* * ^* *SyntaxError: invalid syntax* I feel the error is in Capital P in print . However the error indicated with "*^*" hints at quote at the end of the line. *Can any one please help me understand this.* -- A.K.Ghosh Bangalore:560016 Karnataka, India. Mob : +91 9448116503 -------------- next part -------------- An HTML attachment was scrubbed... URL: From python at mrabarnett.plus.com Sat Mar 24 00:00:57 2012 From: python at mrabarnett.plus.com (MRAB) Date: Sat, 24 Mar 2012 04:00:57 +0000 Subject: Help needed to understand the error message In-Reply-To: References: Message-ID: <4F6D46F9.4010201@mrabarnett.plus.com> On 24/03/2012 03:37, Aloke Ghosh wrote: > Hi, > I am learning Python and do not have programming experience. > I was following an exercise from > http://learnpythonthehardway.org/book/ex2.html > and made a mistake in entry : > > *Print"I like typing this."* > > and got the following error message: > > *In [2]: Print"I like typing this."* > *------------------------------------------------------------* > * File "", line 1* > * Print"I like typing this."* > * ^* > *SyntaxError: invalid syntax* > > I feel the error is in Capital P in print . Correct. (I'm assuming that you're using Python 2; Python 3 is a little different.) > However the error indicated with "*^*" > hints at quote at the end of the line. > > *Can any one please help me understand this.* > It will tell you approximately where the error is, but, as in this example, the actual error may be a little earlier. It tries to be helpful, but remember that it isn't intelligent! :-) From d at davea.name Sat Mar 24 00:44:38 2012 From: d at davea.name (Dave Angel) Date: Sat, 24 Mar 2012 00:44:38 -0400 Subject: Number of languages known [was Re: Python is readable] - somewhat OT In-Reply-To: References: <4f6bcdd5$0$29981$c3e8da3$5496439d@news.astraweb.com> <8694a85d-fe94-4bef-8bb6-8a8241d14ca3@px4g2000pbc.googlegroups.com> <4F6CA39B.9090709@stoneleaf.us> Message-ID: <4F6D5136.5050304@davea.name> On 03/23/2012 02:28 PM, Peter Otten wrote: > Ethan Furman wrote: > >> Nathan Rice wrote: >>> Logo. It's turtles all the way down. >> +1 QOTW > Surely you're joking, Mr Furman! > Cracking safes was the best chapter. -- DaveA From joncle at googlemail.com Sat Mar 24 01:12:46 2012 From: joncle at googlemail.com (Jon Clements) Date: Fri, 23 Mar 2012 22:12:46 -0700 (PDT) Subject: Fetching data from a HTML file In-Reply-To: <9362386.1094.1332510725414.JavaMail.geo-discussion-forums@ynlt15> References: <9362386.1094.1332510725414.JavaMail.geo-discussion-forums@ynlt15> Message-ID: <18618102.2255.1332565966684.JavaMail.geo-discussion-forums@vbtv42> On Friday, 23 March 2012 13:52:05 UTC, Sangeet wrote: > Hi, > > I've got to fetch data from the snippet below and have been trying to match the digits in this to specifically to specific groups. But I can't seem to figure how to go about stripping the tags! :( > > Sum2451102561.496 [min] > > > Actually, I'm working on ROBOT Framework, and haven't been able to figure out how to read data from HTML tables. Reading from the source, is the best (read rudimentary) way I could come up with. Any suggestions are welcome! > > Thanks, > Sangeet I would personally use lxml - a quick example: # -*- coding: utf-8 -*- import lxml.html text = """ Sum?2451102561.496 [min] """ table = lxml.html.fromstring(text) for tr in table.xpath('//tr'): print [ (el.get('class', ''), el.text_content()) for el in tr.iterfind('td') ] [('', 'Sum'), ('', ''), ('green', '245'), ('red', '11'), ('', '0'), ('', '256'), ('', '1.496 [min]')] It does a reasonable job, but if it doesn't work quite right, then there's a .fromstring(parser=...) option, and you should be able to pass in ElementSoup and try your luck from there. hth, Jon. From gstaniak at gmail.com Sat Mar 24 01:21:09 2012 From: gstaniak at gmail.com (Grzegorz Staniak) Date: Sat, 24 Mar 2012 05:21:09 +0000 (UTC) Subject: Data mining/pattern recogniton software in Python? References: <30719938.516.1332558628851.JavaMail.geo-discussion-forums@vbut24> Message-ID: On 24.03.2012, Jon Clements wroted: > It might also be worth checking out pandas[1] and scikits.statsmodels[2]. > > In terms of reading data in a loop I would probably go for a producer-consumer model (possibly using a Queue[3]). Have the consumer constantly try to get another reading, and notify the consumer which can then determine if it's got enough data to calculate a peak/trough. This article is also a fairly good read[4]. > > That's some pointers anyway, > > hth, > > Jon. > > [1] http://pandas.pydata.org/ > [2] http://statsmodels.sourceforge.net/ > [3] http://docs.python.org/library/queue.html > [4] http://www.laurentluce.com/posts/python-threads-synchronization-locks-rlocks-semaphores-conditions-events-and-queues/ Thanks for the suggestions. GS -- Grzegorz Staniak From kiuhnm03.4t.yahoo.it Sat Mar 24 07:05:28 2012 From: kiuhnm03.4t.yahoo.it (Kiuhnm) Date: Sat, 24 Mar 2012 12:05:28 +0100 Subject: Stream programming In-Reply-To: <4f6d3e3f$0$29981$c3e8da3$5496439d@news.astraweb.com> References: <4f6c9e17$0$1383$4fafbaef@reader2.news.tin.it> <4f6d3e3f$0$29981$c3e8da3$5496439d@news.astraweb.com> Message-ID: <4f6daa78$0$1377$4fafbaef@reader2.news.tin.it> On 3/24/2012 4:23, Steven D'Aprano wrote: > On Fri, 23 Mar 2012 17:00:23 +0100, Kiuhnm wrote: > >> I've been writing a little library for handling streams as an excuse for >> doing a little OOP with Python. >> >> I don't share some of the views on readability expressed on this ng. >> Indeed, I believe that a piece of code may very well start as complete >> gibberish and become a pleasure to read after some additional >> information is provided. > [...] >> numbers - push - avrg - 'med' - pop - filter(lt('med'), ge('med'))\ >> - ['same', 'same'] - streams(cat) - 'same' >> >> Ok, we're at the "complete gibberish" phase. >> >> Time to give you the "additional information". > > There are multiple problems with your DSL. Having read your explanation, > and subsequent posts, I think I understand the data model, but the syntax > itself is not very good and far from readable. It is just too hard to > reason about the code. > > Your syntax conflicts with established, far more common, use of the same > syntax: you use - to mean "call a function" and | to join two or more > streams into a flow. > > You also use () for calling functions, and the difference between - and > () isn't clear. So a mystery there -- your DSL seems to have different > function syntax, depending on... what? > > The semantics are unclear even after your examples. To understand your > syntax, you give examples, but to understand the examples, the reader > needs to understand the syntax. That suggests that the semantics are > unclear even in your own mind, or at least too difficult to explain in > simple examples. > > Take this example: > >> Flows can be saved (push) and restored (pop) : >> [1,2,3,4] - push - by(2) - 'double' - pop | val('double') >> <=> [1,2,3,4] | [2,4,6,8] > > What the hell does that mean? The reader initially doesn't know what > *any* of push, by(2), pop or val('double') means. All they see is an > obfuscated series of calls that starts with a stream as input, makes a > copy of it, and doubles the entries in the copy: you make FIVE function > calls to perform TWO conceptual operations. So the reader can't even map > a function call to a result. > > With careful thought and further explanations from you, the reader (me) > eventually gets a mental model here. Your DSL has a single input which is > pipelined through a series of function calls by the - operator, plus a > separate stack. (I initially thought that, like Forth, your DSL was stack > based. But it isn't, is it?) > > It seems to me that the - operator is only needed as syntactic sugar to > avoid using reverse Polish notation and an implicit stack. Instead of the > Forth-like: > > [1,2,3,4] dup 2 * > > your DSL has an explicit stack, and an explicit - operator to call a > function. Presumably "[1,2] push" would be a syntax error. > > I think this is a good example of an inferior syntax. Contrast your: > > [1,2,3,4] - push - by(2) - 'double' - pop | val('double') > > with the equivalent RPL: > > [1,2,3,4] dup 2 * I was just explaining how push and pop work. I also said that [1,2,3,4] - [id,by(2)] would be the recommended way to do it. > Now *that* is a pleasure to read, once you wrap your head around reverse > Polish notation and the concept of a stack. Which you need in your DSL > anyway, to understand push and pop. I don't see why. Push and pop are not needed. They're just handful mainly to modify a flow, collect a result, and go back to how the flow was before the push. It has nothing to do with RPN (which RPL is based on). > You say that this is an "easier way to get the same result": > > [1,2,3,4] - [id, by(2)] > > but it isn't, is it? The more complex example above ends up with two > streams joined in a single flow: > > [1,2,3,4]|[2,4,6,8] > > whereas the shorter version using the magic "id" gives you a single > stream containing nested streams: > > [[1,2,3,4], [2,4,6,8]] Says who? Here are the rules again: A flow can be transformed: [1,2] - f <=> [f(1),f(2)] ([1,2] | [3,4]) - f <=> [f(1,3),f(2,4)] ([1,2] | [3,4]) - [f] <=> [f(1),f(2)] | [f(3),f(4)] ([1,2] | [3,4]) - [f,g] <=> [f(1),f(2)] | [g(3),g(4)] [1,2] - [f,g] <=> [f(1),f(2)] | [g(1),g(2)] Read the last line. What's very interesting, is that [f,g] is an iterable as well, so your functions can be generated as needed. > So, how could you make this more readable? > > * Don't fight the reader's expectations. If they've programmed in Unix > shells, they expect | as the pipelining operator. If they haven't, they > probably will find>> easy to read as a dataflow operator. Either way, > they're probably used to seeing a|b as meaning "or" (as in "this stream, > or this stream") rather than the way you seem to be using it ("this > stream, and this stream"). > > Here's my first attempt at improved syntax that doesn't fight the user: > > [1,2,3,4]>> push>> by(2)>> 'double'>> pop& val('double') There are problems with your syntax. Mine: [...]+[...] - f + [...] - g - h + [...] - i + [...] Yours: ((([...]+[...] >> f) + [...] >> g >> h) + [...] >> i) + [...] I first tried to use '<<' and '>>' but '+' and '-' are much better. > "push" and "pop" are poor choices of words. Push does not actually push > its input onto the stack, which would leave the input stream empty. It > makes a copy. You explain what they do: Why should push move and not copy? In asm and openGL they copy, for instance. > "Flows can be saved (push) and restored (pop)" > > so why not just use SAVE and RESTORE as your functions? Or if they're too > verbose, STO and RCL, or my preference, store and recall. Because that's not what they do. push and pop actually push and pop, i.e. they can be nested and work as expected. > [1,2,3,4]>> store>> by(2)>> 'double'>> recall& val('double') > > I'm still not happy with& for the join operator. I think that the use of > + for concatenate and& for join is just one of those arbitrary choices > that the user will have to learn. Although I'm tempted to try using a > colon instead. > > [1,2,3]:[4,5,6] > > would be a flow with two streams. I can't see a way to overload ':' in Python. There are also technical limitations. > I don't like the syntax for defining and using names. Here's a random > thought: > > [1,2,3,4]>> store>> by(2)>> @double>> recall& double > > Use @name to store to a name, and the name alone to retrieve from it. But > I haven't given this too much thought, so it too might suck. The problem, again, is Python limitation in defining DSLs. At this point, one would have to interpret command-strings. I was trying to avoid an interpreter on an interpreter. > Some other problems with your DSL: > >> A flow can be transformed: >> [1,2] - f<=> [f(1),f(2)] > > but that's not consistently true. For instance: > > [1,2] - push<=/=> [push(1), push(2)] push is a special function (a keyword). It's clear what it does. It's just an exception to the general rule. > So the reader needs to know all the semantics of the particular function > f before being able to reason about the flow. No, he only has to know special functions. Those are practically keywords. >> Some functions are special and almost any function can be made special: >> [1,2,3,4,5] - filter(isprime)<=> [2,3,5] >> [[],(1,2),[3,4,5]] - flatten<=> [1,2,3,4,5] > > You say that as if it were a good thing. It is, because it's never implicit. For instance, isprime is a filter. flatten is a special builtin function (a keyword). Kiuhnm From izharpervaiz7 at gmail.com Sat Mar 24 08:30:35 2012 From: izharpervaiz7 at gmail.com (izharpervaiz7 at gmail.com) Date: Sat, 24 Mar 2012 05:30:35 -0700 (PDT) Subject: "pakistani girls" "pakistani girls lahore" "pakistani girls phone numbers" "pakistani girls mobile number" "pakistani girls wallpapers" "pakistani girls cell numbers" on www.epakistanigirls.blogspot.com In-Reply-To: <571c2ace-6ba5-461d-81ab-7e846c61cb7d@g10g2000pri.googlegroups.com> References: <571c2ace-6ba5-461d-81ab-7e846c61cb7d@g10g2000pri.googlegroups.com> Message-ID: <11301667.0.1332592235130.JavaMail.geo-discussion-forums@vbtw24> On Saturday, 28 November 2009 19:59:23 UTC+5, saima81 wrote: > "pakistani girls" "pakistani girls lahore" "pakistani girls phone > numbers" "pakistani girls mobile number" "pakistani girls wallpapers" > "pakistani girls cell numbers" on www.epakistanigirls.blogspot.com > "pakistani girls" "pakistani girls lahore" "pakistani girls phone > numbers" "pakistani girls mobile number" "pakistani girls wallpapers" > "pakistani girls cell numbers" on www.epakistanigirls.blogspot.com > "pakistani girls" "pakistani girls lahore" "pakistani girls phone > numbers" "pakistani girls mobile number" "pakistani girls wallpapers" > "pakistani girls cell numbers" on www.epakistanigirls.blogspot.com > "pakistani girls" "pakistani girls lahore" "pakistani girls phone > numbers" "pakistani girls mobile number" "pakistani girls wallpapers" > "pakistani girls cell numbers" on www.epakistanigirls.blogspot.com > "pakistani girls" "pakistani girls lahore" "pakistani girls phone > numbers" "pakistani girls mobile number" "pakistani girls wallpapers" > "pakistani girls cell numbers" on www.epakistanigirls.blogspot.com > "pakistani girls" "pakistani girls lahore" "pakistani girls phone > numbers" "pakistani girls mobile number" "pakistani girls wallpapers" > "pakistani girls cell numbers" on www.epakistanigirls.blogspot.com > "pakistani girls" "pakistani girls lahore" "pakistani girls phone > numbers" "pakistani girls mobile number" "pakistani girls wallpapers" > "pakistani girls cell numbers" on www.epakistanigirls.blogspot.com > "pakistani girls" "pakistani girls lahore" "pakistani girls phone > numbers" "pakistani girls mobile number" "pakistani girls wallpapers" > "pakistani girls cell numbers" on www.epakistanigirls.blogspot.com > "pakistani girls" "pakistani girls lahore" "pakistani girls phone > numbers" "pakistani girls mobile number" "pakistani girls wallpapers" > "pakistani girls cell numbers" on www.epakistanigirls.blogspot.com > "pakistani girls" "pakistani girls lahore" "pakistani girls phone > numbers" "pakistani girls mobile number" "pakistani girls wallpapers" > "pakistani girls cell numbers" on www.epakistanigirls.blogspot.com > "pakistani girls" "pakistani girls lahore" "pakistani girls phone > numbers" "pakistani girls mobile number" "pakistani girls wallpapers" > "pakistani girls cell numbers" on www.epakistanigirls.blogspot.com > "pakistani girls" "pakistani girls lahore" "pakistani girls phone > numbers" "pakistani girls mobile number" "pakistani girls wallpapers" > "pakistani girls cell numbers" on www.epakistanigirls.blogspot.com > "pakistani girls" "pakistani girls lahore" "pakistani girls phone > numbers" "pakistani girls mobile number" "pakistani girls wallpapers" > "pakistani girls cell numbers" on www.epakistanigirls.blogspot.com > "pakistani girls" "pakistani girls lahore" "pakistani girls phone > numbers" "pakistani girls mobile number" "pakistani girls wallpapers" > "pakistani girls cell numbers" on www.epakistanigirls.blogspot.com > "pakistani girls" "pakistani girls lahore" "pakistani girls phone > numbers" "pakistani girls mobile number" "pakistani girls wallpapers" > "pakistani girls cell numbers" on www.epakistanigirls.blogspot.com > "pakistani girls" "pakistani girls lahore" "pakistani girls phone > numbers" "pakistani girls mobile number" "pakistani girls wallpapers" > "pakistani girls cell numbers" on www.epakistanigirls.blogspot.com > "pakistani girls" "pakistani girls lahore" "pakistani girls phone > numbers" "pakistani girls mobile number" "pakistani girls wallpapers" > "pakistani girls cell numbers" on www.epakistanigirls.blogspot.com > "pakistani girls" "pakistani girls lahore" "pakistani girls phone > numbers" "pakistani girls mobile number" "pakistani girls wallpapers" > "pakistani girls cell numbers" on www.epakistanigirls.blogspot.com > "pakistani girls" "pakistani girls lahore" "pakistani girls phone > numbers" "pakistani girls mobile number" "pakistani girls wallpapers" > "pakistani girls cell numbers" on www.epakistanigirls.blogspot.com > "pakistani girls" "pakistani girls lahore" "pakistani girls phone > numbers" "pakistani girls mobile number" "pakistani girls wallpapers" > "pakistani girls cell numbers" on www.epakistanigirls.blogspot.com > "pakistani girls" "pakistani girls lahore" "pakistani girls phone > numbers" "pakistani girls mobile number" "pakistani girls wallpapers" > "pakistani girls cell numbers" on www.epakistanigirls.blogspot.com > "pakistani girls" "pakistani girls lahore" "pakistani girls phone > numbers" "pakistani girls mobile number" "pakistani girls wallpapers" > "pakistani girls cell numbers" on www.epakistanigirls.blogspot.com > "pakistani girls" "pakistani girls lahore" "pakistani girls phone > numbers" "pakistani girls mobile number" "pakistani girls wallpapers" > "pakistani girls cell numbers" on www.epakistanigirls.blogspot.com > "pakistani girls" "pakistani girls lahore" "pakistani girls phone > numbers" "pakistani girls mobile number" "pakistani girls wallpapers" > "pakistani girls cell numbers" on www.epakistanigirls.blogspot.com > "pakistani girls" "pakistani girls lahore" "pakistani girls phone > numbers" "pakistani girls mobile number" "pakistani girls wallpapers" > "pakistani girls cell numbers" on www.epakistanigirls.blogspot.com > "pakistani girls" "pakistani girls lahore" "pakistani girls phone > numbers" "pakistani girls mobile number" "pakistani girls wallpapers" > "pakistani girls cell numbers" on www.epakistanigirls.blogspot.com > "pakistani girls" "pakistani girls lahore" "pakistani girls phone > numbers" "pakistani girls mobile number" "pakistani girls wallpapers" > "pakistani girls cell numbers" on www.epakistanigirls.blogspot.com > "pakistani girls" "pakistani girls lahore" "pakistani girls phone > numbers" "pakistani girls mobile number" "pakistani girls wallpapers" > "pakistani girls cell numbers" on www.epakistanigirls.blogspot.com > "pakistani girls" "pakistani girls lahore" "pakistani girls phone > numbers" "pakistani girls mobile number" "pakistani girls wallpapers" > "pakistani girls cell numbers" on www.epakistanigirls.blogspot.com > "pakistani girls" "pakistani girls lahore" "pakistani girls phone > numbers" "pakistani girls mobile number" "pakistani girls wallpapers" > "pakistani girls cell numbers" on www.epakistanigirls.blogspot.com > "pakistani girls" "pakistani girls lahore" "pakistani girls phone > numbers" "pakistani girls mobile number" "pakistani girls wallpapers" > "pakistani girls cell numbers" on www.epakistanigirls.blogspot.com > "pakistani girls" "pakistani girls lahore" "pakistani girls phone > numbers" "pakistani girls mobile number" "pakistani girls wallpapers" > "pakistani girls cell numbers" on www.epakistanigirls.blogspot.com > "pakistani girls" "pakistani girls lahore" "pakistani girls phone > numbers" "pakistani girls mobile number" "pakistani girls wallpapers" > "pakistani girls cell numbers" on www.epakistanigirls.blogspot.com > "pakistani girls" "pakistani girls lahore" "pakistani girls phone > numbers" "pakistani girls mobile number" "pakistani girls wallpapers" > "pakistani girls cell numbers" on www.epakistanigirls.blogspot.com > "pakistani girls" "pakistani girls lahore" "pakistani girls phone > numbers" "pakistani girls mobile number" "pakistani girls wallpapers" > "pakistani girls cell numbers" on www.epakistanigirls.blogspot.com > "pakistani girls" "pakistani girls lahore" "pakistani girls phone > numbers" "pakistani girls mobile number" "pakistani girls wallpapers" > "pakistani girls cell numbers" on www.epakistanigirls.blogspot.com > "pakistani girls" "pakistani girls lahore" "pakistani girls phone > numbers" "pakistani girls mobile number" "pakistani girls wallpapers" > "pakistani girls cell numbers" on www.epakistanigirls.blogspot.com > "pakistani girls" "pakistani girls lahore" "pakistani girls phone > numbers" "pakistani girls mobile number" "pakistani girls wallpapers" > "pakistani girls cell numbers" on www.epakistanigirls.blogspot.com > "pakistani girls" "pakistani girls lahore" "pakistani girls phone > numbers" "pakistani girls mobile number" "pakistani girls wallpapers" > "pakistani girls cell numbers" on www.epakistanigirls.blogspot.com > "pakistani girls" "pakistani girls lahore" "pakistani girls phone > numbers" "pakistani girls mobile number" "pakistani girls wallpapers" > "pakistani girls cell numbers" on www.epakistanigirls.blogspot.com > "pakistani girls" "pakistani girls lahore" "pakistani girls phone > numbers" "pakistani girls mobile number" "pakistani girls wallpapers" > "pakistani girls cell numbers" on www.epakistanigirls.blogspot.com > "pakistani girls" "pakistani girls lahore" "pakistani girls phone > numbers" "pakistani girls mobile number" "pakistani girls wallpapers" > "pakistani girls cell numbers" on www.epakistanigirls.blogspot.com > "pakistani girls" "pakistani girls lahore" "pakistani girls phone > numbers" "pakistani girls mobile number" "pakistani girls wallpapers" > "pakistani girls cell numbers" on www.epakistanigirls.blogspot.com > "pakistani girls" "pakistani girls lahore" "pakistani girls phone > numbers" "pakistani girls mobile number" "pakistani girls wallpapers" > "pakistani girls cell numbers" on www.epakistanigirls.blogspot.com > "pakistani girls" "pakistani girls lahore" "pakistani girls phone > numbers" "pakistani girls mobile number" "pakistani girls wallpapers" > "pakistani girls cell numbers" on www.epakistanigirls.blogspot.com > "pakistani girls" "pakistani girls lahore" "pakistani girls phone > numbers" "pakistani girls mobile number" "pakistani girls wallpapers" > "pakistani girls cell numbers" on www.epakistanigirls.blogspot.com > "pakistani girls" "pakistani girls lahore" "pakistani girls phone > numbers" "pakistani girls mobile number" "pakistani girls wallpapers" > "pakistani girls cell numbers" on www.epakistanigirls.blogspot.com > "pakistani girls" "pakistani girls lahore" "pakistani girls phone > numbers" "pakistani girls mobile number" "pakistani girls wallpapers" > "pakistani girls cell numbers" on www.epakistanigirls.blogspot.com > "pakistani girls" "pakistani girls lahore" "pakistani girls phone > numbers" "pakistani girls mobile number" "pakistani girls wallpapers" > "pakistani girls cell numbers" on www.epakistanigirls.blogspot.com > "pakistani girls" "pakistani girls lahore" "pakistani girls phone > numbers" "pakistani girls mobile number" "pakistani girls wallpapers" > "pakistani girls cell numbers" on www.epakistanigirls.blogspot.com > "pakistani girls" "pakistani girls lahore" "pakistani girls phone > numbers" "pakistani girls mobile number" "pakistani girls wallpapers" > "pakistani girls cell numbers" on www.epakistanigirls.blogspot.com > "pakistani girls" "pakistani girls lahore" "pakistani girls phone > numbers" "pakistani girls mobile number" "pakistani girls wallpapers" > "pakistani girls cell numbers" on www.epakistanigirls.blogspot.com > "pakistani girls" "pakistani girls lahore" "pakistani girls phone > numbers" "pakistani girls mobile number" "pakistani girls wallpapers" > "pakistani girls cell numbers" on www.epakistanigirls.blogspot.com > "pakistani girls" "pakistani girls lahore" "pakistani girls phone > numbers" "pakistani girls mobile number" "pakistani girls wallpapers" > "pakistani girls cell numbers" on www.epakistanigirls.blogspot.com > "pakistani girls" "pakistani girls lahore" "pakistani girls phone > numbers" "pakistani girls mobile number" "pakistani girls wallpapers" > "pakistani girls cell numbers" on www.epakistanigirls.blogspot.com > "pakistani girls" "pakistani girls lahore" "pakistani girls phone > numbers" "pakistani girls mobile number" "pakistani girls wallpapers" > "pakistani girls cell numbers" on www.epakistanigirls.blogspot.com From awilliam at whitemice.org Sat Mar 24 11:24:23 2012 From: awilliam at whitemice.org (Adam Tauno Williams) Date: Sat, 24 Mar 2012 11:24:23 -0400 Subject: Is it technically possible to give Python option of naming process of running script? In-Reply-To: <19118128.4791.1331736187952.JavaMail.geo-discussion-forums@vbai14> References: <19118128.4791.1331736187952.JavaMail.geo-discussion-forums@vbai14> Message-ID: <1332602663.14861.1.camel@workstation.wmmi.net> On Wed, 2012-03-14 at 07:43 -0700, xliiv wrote: > Like the topic.. . > I use Python a lot, both Windows and Linux, and it's little weird to > have many python process without fast distinction which is what. I'm not sure of my interpretation of your problem but if you want to set the name of the running process in the process table, at least on LINUX/UNIX, you can use the procname module available via PyPI. -------------- next part -------------- A non-text attachment was scrubbed... Name: signature.asc Type: application/pgp-signature Size: 198 bytes Desc: This is a digitally signed message part URL: From python at bdurham.com Sat Mar 24 14:02:11 2012 From: python at bdurham.com (python at bdurham.com) Date: Sat, 24 Mar 2012 14:02:11 -0400 Subject: Comments wanted: Proposed change to install layout In-Reply-To: References: Message-ID: <1332612131.7438.140661053554749.38856648@webmail.messagingengine.com> Van, > ... harmonize the install layout for Python between platforms. > 1) the 'Scripts' directory would change to 'bin'; > 2) python.exe would move to the 'bin' directory; and > 3) the installer for Windows would get the optional ability to add this directory to the PATH. 1 vote in support of your proposal. Malcolm -------------- next part -------------- An HTML attachment was scrubbed... URL: From bv8bv8bv8 at gmail.com Sat Mar 24 14:05:55 2012 From: bv8bv8bv8 at gmail.com (BV BV) Date: Sat, 24 Mar 2012 11:05:55 -0700 (PDT) Subject: The Oneness of God is the message of Jesus and all the Prophets, peace be upon them !!!!!!!!!!!!!! Message-ID: <8524cb43-1a8d-4d57-a792-328c28258073@d17g2000vba.googlegroups.com> The Oneness of God is the message of Jesus and all the Prophets, peace be upon them The message that was brought by the Messiah (peace be upon him) was the call to worship God, the One, the Lord of the Messiah and the Lord of the worlds: "Now this is eternal life: that they may know you, the only true God, and Jesus Christ, whom you have sent" John 17:3 - NIV "A certain ruler asked him: 'Good teacher, what must I do to inherit eternal life?' 'Why do you call me good?' Jesus answered. 'No one is good - except God alone.'" Luke 18:18-19 - NIV "The devil led him up to a high place and showed him in an instant all the kingdoms of the world. And he said to him, 'I will give you all their authority and splendour, for it has been given to me, and I can give it to anyone I want to. So if you worship me, it will all be yours.' Jesus answered, 'It is written: "Worship the Lord your God and serve him only."'" Luke 4:5-8 - NIV Believing in and worshipping Allaah alone, besides Whom there is no other god, is the greatest teaching brought by the Messiah, and it is the greatest teaching brought by all the Prophets. "One of the teachers of the law came and noticed them debating. Noticing that Jesus had given them a good answer, he asked him, 'Of all the commandments, which is the most important?' 'The most important one,' answered Jesus, 'is this: "Hear, O Israel, the Lord our God, the Lord is one. Love the Lord your God with all your heart and with all your soul and with all your mind and with all your strength." The second is this: "Love your neighbour as yourself." There is no commandment greater than these.' 'Well said, teacher,' the man replied. 'You are right in saying that God is one and there is no other but him. To love him with all your heart, with you all your understanding and with all your strength, and to love your neighbour as yourself is more important that all burnt offerings and sacrifices.' When Jesus saw that he has answered wisely, he said to him, 'You are not far from the kingdom of God.' And from then on no one dared ask him any more questions." Mark 12:28-34 - NIV But do not think that this advice was given to Israel or to his own people only. Rather this is the basis of the teachings of all the Prophets. The same advice appears in the Gospel of Matthew, in similar wording, after which he says: "All the Law and the Prophets hang on these two commandments." Matthew 22:39 - NIV This belief in the oneness of God is indeed the message of all of the Prophets. Allaah says (interpretation of the meaning): "And We did not send any Messenger before you (O Muhammad) but We revealed to him (saying): Laa ilaaha illa Ana [none has the right to be worshipped but I (Allaah)], so worship Me (Alone and none else)" [al-Anbiya' 21:25] This is the basic message to which the Messiah called people and warned them against differing from that. Allaah says (interpretation of the meaning): "Surely, they have disbelieved who say: 'Allaah is the Messiah ['Eesa (Jesus)], son of Maryam (Mary).' But the Messiah ['Eesa (Jesus)] said: 'O Children of Israel! Worship Allaah, my Lord and your Lord.' Verily, whosoever sets up partners (in worship) with Allaah, then Allaah has forbidden Paradise to him, and the Fire will be his abode. And for the Zaalimoon (polytheists and wrongdoers) there are no helpers" [al-Maa'idah 5:72] This is the basic principle on which we should all agree. Allaah says (interpretation of the meaning): "Say (O Muhammad): 'O people of the Scripture (Jews and Christians): Come to a word that is just between us and you, that we worship none but Allaah (Alone), and that we associate no partners with Him, and that none of us shall take others as lords besides Allaah.' Then, if they turn away, say: 'Bear witness that we are Muslims'" [Aal 'Imraan 3:64] It is alien to true Christianity, this futile attempt to reconcile the belief in the Oneness of God, which is the message brought by the Prophets, and which is clearly stated in their Bible, and affirmed in the Torah in particular, with their belief in the trinity. It says in the American Encyclopedia: The belief in the Oneness of God - as a theological movement - began at a very early stage in history, and in fact it preceded the belief in trinity by many decades. Christianity developed from Judaism, and Judaism firmly believes that there is one God. The path that led from Jerusalem (the home of the first disciples of Christ) to Nicea (where it was decided in 325 CE that Christ was equal to God in essence and eternal nature) can hardly be described as a straight path. The doctrine of trinity which was affirmed in the fourth century CE bears no resemblance to the original teachings of Christ concerning the nature of God. Au contraire, it is the opposite, a deviation from that teaching. Hence it developed in opposition to the belief in One God... (27/294). You can refer to the views of some of those Christians who still believe in the Oneness of God in the sameAmerican Encyclopedia, 27/300-301 It is difficult to comprehend, so no wonder you were never able to comprehend it. But what is strange is that you believe in something that it is impossible to understand, unless we deceive ourselves and say that this understanding will come on the Last Day: "We understand that as much as our minds are able to, and we hope that we will understand it more clearly in the future, when the veil is removed from all things in heaven and on earth. But for now, the extent to which we do understand it is enough!" Yes, the truth will become perfectly clear to you in the future, as it is clear to us today, praise be to Allaah, on the Day on which Allaah will gather the Messengers and make them bear witness concerning their nations. Allaah says (interpretation of the meaning): "And (remember) when Allaah will say (on the Day of Resurrection): 'O 'Eesa (Jesus), son of Maryam (Mary)! Did you say unto men: Worship me and my mother as two gods besides Allaah?' He will say: 'Glory be to You! It was not for me to say what I had no right (to say). Had I said such a thing, You would surely have known it. You know what is in my inner-self though I do not know what is in Yours; truly, You, only You, are the All-Knower of all that is hidden (and unseen). 117. 'Never did I say to them aught except what You (Allaah) did command me to say: Worship Allaah, my Lord and your Lord. And I was a witness over them while I dwelt amongst them, but when You took me up, You were the Watcher over them; and You are a Witness to all things. (This is a great admonition and warning to the Christians of the whole world). 118. 'If You punish them, they are Your slaves, and if You forgive them, verily, You, only You, are the All-Mighty, the All-Wise.' 119. Allaah will say: This is a Day on which the truthful will profit from their truth: theirs are Gardens under which rivers flow (in Paradise) -- they shall abide therein forever. Allaah is pleased with them and they with Him. That is the great success (Paradise). 120. To Allaah belongs the dominion of the heavens and the earth and all that is therein, and He is Able to do all things" [al-Maa'idah 5:116-120]. For more information about Islam http://www.islam-guide.com http://www.islamhouse.com/s/9661 http://www.thisistruth.org http://www.quran-m.com/firas/en1 http://kaheel7.com/eng http://www.knowmuhammad.com http://www.rasoulallah.net/v2/index.aspx?lang=e http://imanway1.com/eng http://www.todayislam.com http://www.thekeytoislam.com http://www.islamland.com http://www.discoverislam.com http://www.thetruereligion.org http://www.beconvinced.com http://islamtomorrow.com http://www.usc.edu/dept/MSA/quran http://www.quranforall.org http://www.quranexplorer.com/quran http://www.prophetmuhammed.org http://chatislamonline.org/en/ http://www.dar-us-salam.com http://youtubeislam.com From bv8bv8bv8 at gmail.com Sat Mar 24 14:05:57 2012 From: bv8bv8bv8 at gmail.com (BV BV) Date: Sat, 24 Mar 2012 11:05:57 -0700 (PDT) Subject: The Oneness of God is the message of Jesus and all the Prophets, peace be upon them !!!!!!!!!!!!!! Message-ID: <18d4efc9-4044-4f18-a56a-1046ee019e7a@gw9g2000vbb.googlegroups.com> The Oneness of God is the message of Jesus and all the Prophets, peace be upon them The message that was brought by the Messiah (peace be upon him) was the call to worship God, the One, the Lord of the Messiah and the Lord of the worlds: "Now this is eternal life: that they may know you, the only true God, and Jesus Christ, whom you have sent" John 17:3 - NIV "A certain ruler asked him: 'Good teacher, what must I do to inherit eternal life?' 'Why do you call me good?' Jesus answered. 'No one is good - except God alone.'" Luke 18:18-19 - NIV "The devil led him up to a high place and showed him in an instant all the kingdoms of the world. And he said to him, 'I will give you all their authority and splendour, for it has been given to me, and I can give it to anyone I want to. So if you worship me, it will all be yours.' Jesus answered, 'It is written: "Worship the Lord your God and serve him only."'" Luke 4:5-8 - NIV Believing in and worshipping Allaah alone, besides Whom there is no other god, is the greatest teaching brought by the Messiah, and it is the greatest teaching brought by all the Prophets. "One of the teachers of the law came and noticed them debating. Noticing that Jesus had given them a good answer, he asked him, 'Of all the commandments, which is the most important?' 'The most important one,' answered Jesus, 'is this: "Hear, O Israel, the Lord our God, the Lord is one. Love the Lord your God with all your heart and with all your soul and with all your mind and with all your strength." The second is this: "Love your neighbour as yourself." There is no commandment greater than these.' 'Well said, teacher,' the man replied. 'You are right in saying that God is one and there is no other but him. To love him with all your heart, with you all your understanding and with all your strength, and to love your neighbour as yourself is more important that all burnt offerings and sacrifices.' When Jesus saw that he has answered wisely, he said to him, 'You are not far from the kingdom of God.' And from then on no one dared ask him any more questions." Mark 12:28-34 - NIV But do not think that this advice was given to Israel or to his own people only. Rather this is the basis of the teachings of all the Prophets. The same advice appears in the Gospel of Matthew, in similar wording, after which he says: "All the Law and the Prophets hang on these two commandments." Matthew 22:39 - NIV This belief in the oneness of God is indeed the message of all of the Prophets. Allaah says (interpretation of the meaning): "And We did not send any Messenger before you (O Muhammad) but We revealed to him (saying): Laa ilaaha illa Ana [none has the right to be worshipped but I (Allaah)], so worship Me (Alone and none else)" [al-Anbiya' 21:25] This is the basic message to which the Messiah called people and warned them against differing from that. Allaah says (interpretation of the meaning): "Surely, they have disbelieved who say: 'Allaah is the Messiah ['Eesa (Jesus)], son of Maryam (Mary).' But the Messiah ['Eesa (Jesus)] said: 'O Children of Israel! Worship Allaah, my Lord and your Lord.' Verily, whosoever sets up partners (in worship) with Allaah, then Allaah has forbidden Paradise to him, and the Fire will be his abode. And for the Zaalimoon (polytheists and wrongdoers) there are no helpers" [al-Maa'idah 5:72] This is the basic principle on which we should all agree. Allaah says (interpretation of the meaning): "Say (O Muhammad): 'O people of the Scripture (Jews and Christians): Come to a word that is just between us and you, that we worship none but Allaah (Alone), and that we associate no partners with Him, and that none of us shall take others as lords besides Allaah.' Then, if they turn away, say: 'Bear witness that we are Muslims'" [Aal 'Imraan 3:64] It is alien to true Christianity, this futile attempt to reconcile the belief in the Oneness of God, which is the message brought by the Prophets, and which is clearly stated in their Bible, and affirmed in the Torah in particular, with their belief in the trinity. It says in the American Encyclopedia: The belief in the Oneness of God - as a theological movement - began at a very early stage in history, and in fact it preceded the belief in trinity by many decades. Christianity developed from Judaism, and Judaism firmly believes that there is one God. The path that led from Jerusalem (the home of the first disciples of Christ) to Nicea (where it was decided in 325 CE that Christ was equal to God in essence and eternal nature) can hardly be described as a straight path. The doctrine of trinity which was affirmed in the fourth century CE bears no resemblance to the original teachings of Christ concerning the nature of God. Au contraire, it is the opposite, a deviation from that teaching. Hence it developed in opposition to the belief in One God... (27/294). You can refer to the views of some of those Christians who still believe in the Oneness of God in the sameAmerican Encyclopedia, 27/300-301 It is difficult to comprehend, so no wonder you were never able to comprehend it. But what is strange is that you believe in something that it is impossible to understand, unless we deceive ourselves and say that this understanding will come on the Last Day: "We understand that as much as our minds are able to, and we hope that we will understand it more clearly in the future, when the veil is removed from all things in heaven and on earth. But for now, the extent to which we do understand it is enough!" Yes, the truth will become perfectly clear to you in the future, as it is clear to us today, praise be to Allaah, on the Day on which Allaah will gather the Messengers and make them bear witness concerning their nations. Allaah says (interpretation of the meaning): "And (remember) when Allaah will say (on the Day of Resurrection): 'O 'Eesa (Jesus), son of Maryam (Mary)! Did you say unto men: Worship me and my mother as two gods besides Allaah?' He will say: 'Glory be to You! It was not for me to say what I had no right (to say). Had I said such a thing, You would surely have known it. You know what is in my inner-self though I do not know what is in Yours; truly, You, only You, are the All-Knower of all that is hidden (and unseen). 117. 'Never did I say to them aught except what You (Allaah) did command me to say: Worship Allaah, my Lord and your Lord. And I was a witness over them while I dwelt amongst them, but when You took me up, You were the Watcher over them; and You are a Witness to all things. (This is a great admonition and warning to the Christians of the whole world). 118. 'If You punish them, they are Your slaves, and if You forgive them, verily, You, only You, are the All-Mighty, the All-Wise.' 119. Allaah will say: This is a Day on which the truthful will profit from their truth: theirs are Gardens under which rivers flow (in Paradise) -- they shall abide therein forever. Allaah is pleased with them and they with Him. That is the great success (Paradise). 120. To Allaah belongs the dominion of the heavens and the earth and all that is therein, and He is Able to do all things" [al-Maa'idah 5:116-120]. For more information about Islam http://www.islam-guide.com http://www.islamhouse.com/s/9661 http://www.thisistruth.org http://www.quran-m.com/firas/en1 http://kaheel7.com/eng http://www.knowmuhammad.com http://www.rasoulallah.net/v2/index.aspx?lang=e http://imanway1.com/eng http://www.todayislam.com http://www.thekeytoislam.com http://www.islamland.com http://www.discoverislam.com http://www.thetruereligion.org http://www.beconvinced.com http://islamtomorrow.com http://www.usc.edu/dept/MSA/quran http://www.quranforall.org http://www.quranexplorer.com/quran http://www.prophetmuhammed.org http://chatislamonline.org/en/ http://www.dar-us-salam.com http://youtubeislam.com From ndbecker2 at gmail.com Sat Mar 24 14:30:09 2012 From: ndbecker2 at gmail.com (Neal Becker) Date: Sat, 24 Mar 2012 14:30:09 -0400 Subject: argparse ConfigureAction problem Message-ID: I've been using arparse with ConfigureAction (which is shown below). But, it doesn't play well with positional arguments. For example: ./plot_stuff2.py --plot stuff1 stuff2 [...] plot_stuff2.py: error: argument --plot/--with-plot/--enable-plot/--no-plot/-- without-plot/--disable-plot: invalid boolean value: 'stuff1' Problem is --plot takes an optional argument, and so the positional arg is assumed to be the arg to --plot. Not sure how to fix this. Here is the parser code: parser = argparse.ArgumentParser() [...] parser.add_argument ('--plot', action=ConfigureAction, default=False) parser.add_argument ('files', nargs='*') opt = parser.parse_args(cmdline[1:]) Here is ConfigureAction: ----------------------------------------------------- import argparse import re def boolean(string): string = string.lower() if string in ['0', 'f', 'false', 'no', 'off']: return False elif string in ['1', 't', 'true', 'yes', 'on']: return True else: raise ValueError() class ConfigureAction(argparse.Action): def __init__(self, option_strings, dest, default=None, required=False, help=None, metavar=None, positive_prefixes=['--', '--with-', '--enable-'], negative_prefixes=['--no-', '--without-', '--disable-']): strings = [] self.positive_strings = set() self.negative_strings = set() for string in option_strings: assert re.match(r'--[A-z]+', string) suffix = string[2:] for positive_prefix in positive_prefixes: self.positive_strings.add(positive_prefix + suffix) strings.append(positive_prefix + suffix) for negative_prefix in negative_prefixes: self.negative_strings.add(negative_prefix + suffix) strings.append(negative_prefix + suffix) super(ConfigureAction, self).__init__( option_strings=strings, dest=dest, nargs='?', const=None, default=default, type=boolean, choices=None, required=required, help=help, metavar=metavar) def __call__(self, parser, namespace, value, option_string=None): if value is None: value = option_string in self.positive_strings elif option_string in self.negative_strings: value = not value setattr(namespace, self.dest, value) From kiuhnm03.4t.yahoo.it Sat Mar 24 15:36:49 2012 From: kiuhnm03.4t.yahoo.it (Kiuhnm) Date: Sat, 24 Mar 2012 20:36:49 +0100 Subject: verbs in comments [OT] Message-ID: <4f6e2265$0$1382$4fafbaef@reader2.news.tin.it> Why do you write // Print the number of words... def printNumWords(): ... and not // Prints the number of words... def printNumWords(): ... where "it" is understood? Is that an imperative or a base form or something else? Kiuhnm From bthate at gmail.com Sat Mar 24 16:04:23 2012 From: bthate at gmail.com (Bart Thate) Date: Sat, 24 Mar 2012 13:04:23 -0700 (PDT) Subject: JSONBOT 0.84.4 RELEASE available Message-ID: <19170095.91.1332619463664.JavaMail.geo-discussion-forums@ynne2> *JSONBOT 0.84.4 RELEASE* available ! #IRC #XMPP #chatbot #WWW #Python #RSS #relay get it at: http://code.google.com/p/jsonbot/downloads/list documentation is at http://jsonbot.org *About JSONBOT:* JSONBOT is a chatbot that can take commands and react to events on the network it is connected to (IRC, XMPP, WEB mostely). Push functionality is also provided (think RSS feeds to your IRC channel or XMPP conference). It is possible to program your own plugins to create custom functionality. *In this release:* default control character for the bot is now ?;? .. if you are missing the ?!? cc just run ?;cc-add !?. - experimental features: * FiSH support on IRC, thanks to Frank Spijkerman (Aim) * sleekxmpp driver for xmpp bots, use ./bin/jsb-sleek - further changes: * new boot code - bot now tries to detect changes in the code and recreates the dispatch tables when needed. * reconnect code should work better, disconnect should now be properly detected * updated tornado to version 2.2 - needed for websockets new style * database support for sqlite and mysql is now available, see ~/.jsb/config/mainconfig to enable it. - still todo: * yes .. docs still need to be written * yes .. bugtracker needs attention If you find any bugs in this release please let me know at bthate at gmail.com or in #dunkbots on irc.freenode.net. HF ! From python at mrabarnett.plus.com Sat Mar 24 16:24:37 2012 From: python at mrabarnett.plus.com (MRAB) Date: Sat, 24 Mar 2012 20:24:37 +0000 Subject: verbs in comments [OT] In-Reply-To: <4f6e2265$0$1382$4fafbaef@reader2.news.tin.it> References: <4f6e2265$0$1382$4fafbaef@reader2.news.tin.it> Message-ID: <4F6E2D85.4010005@mrabarnett.plus.com> On 24/03/2012 19:36, Kiuhnm wrote: > Why do you write > // Print the number of words... > def printNumWords(): ... > and not > // Prints the number of words... > def printNumWords(): ... > where "it" is understood? > Is that an imperative or a base form or something else? > The first is the imperative, the second is what it does (with the implied "it"). Which form you use depends on what "feels" right. Probably what I'd do is use the first form where it's called and the second form where it's defined. # Prints the number of words. def print_num_words(): ... # Print the number of words. print_num_words() Although in this example the function is better written with a docstring, and the comment where the function is called doesn't add anything useful, so it's probably unnecessary. From colton.myers at gmail.com Sat Mar 24 16:32:14 2012 From: colton.myers at gmail.com (Colton Myers) Date: Sat, 24 Mar 2012 14:32:14 -0600 Subject: verbs in comments [OT] In-Reply-To: <4f6e2265$0$1382$4fafbaef@reader2.news.tin.it> References: <4f6e2265$0$1382$4fafbaef@reader2.news.tin.it> Message-ID: <718EB1AF094B43D99E697086DE9B5192@gmail.com> > Why do you write > // Print the number of words... > def printNumWords(): ... > and not > // Prints the number of words... > def printNumWords(): ... > where "it" is understood? > Is that an imperative or a base form or something else? > > I've seen it both ways, and I don't think anyone will fault you for either. I usually use the first version, "commanding" the code to do what I want. It's also a habit because that's the form one uses in git commit messages. -Colton -------------- next part -------------- An HTML attachment was scrubbed... URL: From fgrose at gmail.com Sat Mar 24 16:57:00 2012 From: fgrose at gmail.com (Frederick Grose) Date: Sat, 24 Mar 2012 16:57:00 -0400 Subject: verbs in comments [OT] In-Reply-To: <4F6E2D85.4010005@mrabarnett.plus.com> References: <4f6e2265$0$1382$4fafbaef@reader2.news.tin.it> <4F6E2D85.4010005@mrabarnett.plus.com> Message-ID: On Sat, Mar 24, 2012 at 4:24 PM, MRAB wrote: > On 24/03/2012 19:36, Kiuhnm wrote: > >> Why do you write >> // Print the number of words... >> def printNumWords(): ... >> and not >> // Prints the number of words... >> def printNumWords(): ... >> where "it" is understood? >> Is that an imperative or a base form or something else? >> >> The first is the imperative, the second is what it does (with the > implied "it"). > > Which form you use depends on what "feels" right. > > Probably what I'd do is use the first form where it's called and the > second form where it's defined. > > # Prints the number of words. > def print_num_words(): > ... > > # Print the number of words. > print_num_words() > > Although in this example the function is better written with a > docstring, and the comment where the function is called doesn't add > anything useful, so it's probably unnecessary. > PEP 257, http://www.python.org/dev/peps/pep-0257/ notes, "The docstring is a phrase ending in a period. It prescribes the function or method's effect as a command ("Do this", "Return that"), not as a description; e.g. don't write "Returns the pathname ..."." --Fred -------------- next part -------------- An HTML attachment was scrubbed... URL: From nagle at animats.com Sat Mar 24 17:04:05 2012 From: nagle at animats.com (John Nagle) Date: Sat, 24 Mar 2012 14:04:05 -0700 Subject: Fetching data from a HTML file In-Reply-To: <18618102.2255.1332565966684.JavaMail.geo-discussion-forums@vbtv42> References: <9362386.1094.1332510725414.JavaMail.geo-discussion-forums@ynlt15> <18618102.2255.1332565966684.JavaMail.geo-discussion-forums@vbtv42> Message-ID: <4f6e36c0$0$11966$742ec2ed@news.sonic.net> On 3/23/2012 10:12 PM, Jon Clements wrote: > ROBOT Framework Would people please stop using robotic names for things that aren't robots? Thank you. John Nagle From kiuhnm03.4t.yahoo.it Sat Mar 24 17:15:54 2012 From: kiuhnm03.4t.yahoo.it (Kiuhnm) Date: Sat, 24 Mar 2012 22:15:54 +0100 Subject: verbs in comments [OT] In-Reply-To: References: <4f6e2265$0$1382$4fafbaef@reader2.news.tin.it> Message-ID: <4f6e3989$0$1374$4fafbaef@reader1.news.tin.it> On 3/24/2012 21:24, MRAB wrote: > On 24/03/2012 19:36, Kiuhnm wrote: >> Why do you write >> // Print the number of words... >> def printNumWords(): ... >> and not >> // Prints the number of words... >> def printNumWords(): ... >> where "it" is understood? >> Is that an imperative or a base form or something else? >> > The first is the imperative, the second is what it does (with the > implied "it"). > > Which form you use depends on what "feels" right. > > Probably what I'd do is use the first form where it's called and the > second form where it's defined. > > # Prints the number of words. > def print_num_words(): > ... > > # Print the number of words. > print_num_words() > > Although in this example the function is better written with a > docstring, and the comment where the function is called doesn't add > anything useful, so it's probably unnecessary. Thank you. Kiuhnm From timothy.c.delaney at gmail.com Sat Mar 24 18:08:25 2012 From: timothy.c.delaney at gmail.com (Tim Delaney) Date: Sun, 25 Mar 2012 09:08:25 +1100 Subject: Number of languages known [was Re: Python is readable] - somewhat OT In-Reply-To: References: Message-ID: On 23 March 2012 06:14, Chris Angelico wrote: > On Fri, Mar 23, 2012 at 4:44 AM, Steven D'Aprano > wrote: > > The typical developer knows three, maybe four languages > > moderately well, if you include SQL and regexes as languages, and might > > have a nodding acquaintance with one or two more. > > I'm not entirely sure what you mean by "moderately well", nor > "languages", but I'm of the opinion that a good developer should be > able to learn a new language very efficiently. Do you count Python 2 > and 3 as the same language? What about all the versions of the C > standard? > Absolutely. 10 years ago (when I was just a young lad) I'd say that I'd *forgotten* at least 20 programming languages. That number has only increased. Being able to pick up a new language (skill, technology, methodology, etc) is IMO the most important skill for a developer to have. Pick it up quickly, become proficient with it, leave it alone for a couple of years, pick up the new version when you need/want it. Tim Delaney -------------- next part -------------- An HTML attachment was scrubbed... URL: From rosuav at gmail.com Sat Mar 24 18:31:43 2012 From: rosuav at gmail.com (Chris Angelico) Date: Sun, 25 Mar 2012 09:31:43 +1100 Subject: Number of languages known [was Re: Python is readable] - somewhat OT In-Reply-To: References: Message-ID: On Sun, Mar 25, 2012 at 9:08 AM, Tim Delaney wrote: > Being able to pick up a new language (skill, technology, methodology, etc) > is IMO the most important skill for a developer to have. Pick it up quickly, > become proficient with it, leave it alone for a couple of years, pick up the > new version when you need/want it. Definitely. And along the way, you also (hopefully) remember what each language's specialty is. When you're faced with a problem, you're then able to "call" the ideal language for the task. The larger your arsenal of "languages I have known", the less "all I have is a hammer, this problem looks like a nail" code you end up seeing on TheDailyWTF.com :) ChrisA From rosuav at gmail.com Sat Mar 24 18:36:46 2012 From: rosuav at gmail.com (Chris Angelico) Date: Sun, 25 Mar 2012 09:36:46 +1100 Subject: verbs in comments [OT] In-Reply-To: <718EB1AF094B43D99E697086DE9B5192@gmail.com> References: <4f6e2265$0$1382$4fafbaef@reader2.news.tin.it> <718EB1AF094B43D99E697086DE9B5192@gmail.com> Message-ID: On Sun, Mar 25, 2012 at 7:32 AM, Colton Myers wrote: > > // Print the number of words... > // Prints the number of words... > > I've seen it both ways, and I don't think anyone will fault you for either. > ?I usually use the first version, "commanding" the code to do what I want. > ?It's also a habit because that's the form one uses in git commit messages. It's funny how these things go. There are multiple distinct conventions, and regarding function definition comments (or docstrings), both of those do definitely exist. I think I've seen more code in the second form ("this is what this code does"), but both are prevalent. Regarding git commit messages, the convention generally is to write in the present tense ("this is what this commit does"), but on a wiki, edit summaries are more often in the past tense ("this is what I edited"). Why? Because on a wiki, nobody's going to 'git cherry-pick' the edits. ChrisA From roy at panix.com Sat Mar 24 19:27:12 2012 From: roy at panix.com (Roy Smith) Date: Sat, 24 Mar 2012 19:27:12 -0400 Subject: verbs in comments [OT] References: <4f6e2265$0$1382$4fafbaef@reader2.news.tin.it> <718EB1AF094B43D99E697086DE9B5192@gmail.com> Message-ID: In article , Chris Angelico wrote: > It's funny how these things go. There are multiple distinct > conventions, and regarding function definition comments (or > docstrings), both of those do definitely exist. I think I've seen more > code in the second form ("this is what this code does"), but both are > prevalent. My recommendation is that for a large project, pick a style and stick with it. There's a couple of reasons for this. One is that it makes it easier to read, but I think the bigger reason is that it makes it easier to write. The best documentation is documentation that gets written. Developers are often poor documenters. If you can give them a structured template, it makes it more likely that they will write something. The more open ended you make it, the more likely it is they'll just get writer's block and end up writing nothing. From xahlee at gmail.com Sat Mar 24 19:30:28 2012 From: xahlee at gmail.com (Xah Lee) Date: Sat, 24 Mar 2012 16:30:28 -0700 (PDT) Subject: Your Regex Brain Message-ID: ?Your Regex Brain? http://xahlee.org/comp/your_regex_brain.html Yours truely, Xah From mining.facts at googlemail.com Sat Mar 24 19:35:29 2012 From: mining.facts at googlemail.com (Christian) Date: Sat, 24 Mar 2012 16:35:29 -0700 (PDT) Subject: multiprocessing & itertools.product Iterator Message-ID: Hey, I struggle to "extend" a multiprocessing example to my problem with a itertools.product result iterator. How I have to assign the combos.next() elements approriate to Pool.imap/calc functions? Thanks in advance Christian from multiprocessing import Process,Queue,Pool import Calculation import DataSimulation from itertools import product def produce_example_combos(size=6,na=1000,nb=10): data = DataSimulation.DataSimulation() a = [data.generate_simple(size) for x in xrange(na)] b = [data.generate_simple(size) for x in xrange(nb)] it = product(a,b) return it def calc(elements): calc.q.put("Doing:" + elements[0] + elements[1]) ratio = Calculation.ratio(elements[0],elements[1]) return ratio def calc_init(q): calc.q = q if __name__ == '__main__': combos = produce_example_combos() print "tesdata generated" q = Queue() p = Pool(10, calc_init, [q]) results = p.imap(calc,combos.next()) p.close() for i in combos: print q.get() print results.next() From python.list at tim.thechases.com Sat Mar 24 20:03:08 2012 From: python.list at tim.thechases.com (Tim Chase) Date: Sat, 24 Mar 2012 19:03:08 -0500 Subject: Number of languages known [was Re: Python is readable] - somewhat OT In-Reply-To: References: Message-ID: <4F6E60BC.1020600@tim.thechases.com> On 03/24/12 17:08, Tim Delaney wrote: > Absolutely. 10 years ago (when I was just a young lad) I'd say that I'd > *forgotten* at least 20 programming languages. That number has only > increased. And in the case of COBOL for me, it wasn't just forgotten, but actively repressed ;-) -tkc From rosuav at gmail.com Sat Mar 24 21:10:27 2012 From: rosuav at gmail.com (Chris Angelico) Date: Sun, 25 Mar 2012 12:10:27 +1100 Subject: [Python-Dev] Playing with a new theme for the docs In-Reply-To: <87y5qpikah.fsf@benfinney.id.au> References: <4F6935E1.2030309@nedbatchelder.com> <4F69E337.7010501@nedbatchelder.com> <4F6A560A.6050207@canterbury.ac.nz> <5260192D-7EF1-4021-AB50-FD2021566CFF@twistedmatrix.com> <4F6D2061.3080804@canterbury.ac.nz> <4F6D5C52.1030802@canterbury.ac.nz> <87y5qpikah.fsf@benfinney.id.au> Message-ID: On Sun, Mar 25, 2012 at 11:41 AM, Ben Finney wrote: > So, again, why make your browser window *for reading text* that large? > > You have control over how large your window size is, and if you have > purposes so different that they demand different widths, then you can > easily make different-width windows. > I don't know about yours, but my web browsers all have one width regardless of which tab is open. However, I agree that web sites shouldn't impose a width. Let it flow out! ChrisA From ben+python at benfinney.id.au Sat Mar 24 22:22:02 2012 From: ben+python at benfinney.id.au (Ben Finney) Date: Sun, 25 Mar 2012 13:22:02 +1100 Subject: [Python-Dev] Playing with a new theme for the docs References: <4F6935E1.2030309@nedbatchelder.com> <4F69E337.7010501@nedbatchelder.com> <4F6A560A.6050207@canterbury.ac.nz> <5260192D-7EF1-4021-AB50-FD2021566CFF@twistedmatrix.com> <4F6D2061.3080804@canterbury.ac.nz> <4F6D5C52.1030802@canterbury.ac.nz> <87y5qpikah.fsf@benfinney.id.au> Message-ID: <87r4whifn9.fsf@benfinney.id.au> Chris Angelico writes: > On Sun, Mar 25, 2012 at 11:41 AM, Ben Finney wrote: > > You have control over how large your window size is, and if you have > > purposes so different that they demand different widths, then you > > can easily make different-width windows. > > I don't know about yours, but my web browsers all have one width > regardless of which tab is open. Yes, all the tabs have the same size within one window. So PJ can instantly make a *new* window for the different purpose that needs a different window width. Then all the tabs within that new window will have the right width for this new purpose, and tabs in the existing window will continue to have the right width for the other purpose. If you have a web browser which is incapable of opening a new window, let me introduce you to Firefox, Chromium, Epiphany, or any other widely-used free-software desktop web browser that does what it's told. > However, I agree that web sites shouldn't impose a width. Let it flow > out! For some purposes, I can see a benefit: some sites truly are best treated as specific applications with a specific interface width. Documentation ? or any other passage of many paragraphs of prose ? is not one of those, and should not be artificially limited in presentation width by the site author. The web browser frees the viewer to have text presented how they're best able to read it; don't hobble that. (The irony of my simultaneously holding the position that messages via email and Usenet should be limited to 80 columns plain text is not lost on me.) -- \ ?Software patents provide one more means of controlling access | `\ to information. They are the tool of choice for the internet | _o__) highwayman.? ?Anthony Taylor | Ben Finney From nt_mahmood at yahoo.com Sun Mar 25 04:12:15 2012 From: nt_mahmood at yahoo.com (Mahmood Naderan) Date: Sun, 25 Mar 2012 01:12:15 -0700 (PDT) Subject: a problem with defining and instantiating a class Message-ID: <1332663135.52370.YahooMailNeo@web111718.mail.gq1.yahoo.com> Dear all,I am using GEM5, a simulator, which uses python for reading configuration files. For example in Caches.py http://repo.gem5.org/gem5/file/7d95b650c9b6/configs/common/Caches.py#l31 a class L1cache is defined which we can set its parameters (size, assoc, ...). The BaseCache is fully defined in http://repo.gem5.org/gem5/file/7d95b650c9b6/src/mem/cache/BaseCache.py There is no problem setting some parameters like size, ... Now here is the problem: In BaseCache.py, there is a parameter "prefetcher" which is set at http://repo.gem5.org/gem5/file/7d95b650c9b6/src/mem/cache/BaseCache.py#l60 This parameter will read the Prefetcher.py located at http://repo.gem5.org/gem5/file/7d95b650c9b6/src/mem/cache/prefetch/Prefetcher.py Now when I set "prefetcher=StridePrefetcher" it doesn't make any sense and the prefetcher will remain "NULL" which is the default value. Can you help? how can I fix that? // Naderan *Mahmood; From news at blinne.net Sun Mar 25 08:18:44 2012 From: news at blinne.net (Alexander Blinne) Date: Sun, 25 Mar 2012 14:18:44 +0200 Subject: Documentation, assignment in expression. In-Reply-To: References: <4f6d0060$0$6634$9b4e6d93@newsspool2.arcor-online.net> Message-ID: <4f6f0d24$0$6561$9b4e6d93@newsspool4.arcor-online.net> I am not sure I understand your argument. The doc section states that " [...] in Python you?re forced to write this: while True: line = f.readline() if not line: break ... # do something with line". That simply isn't true as one can simply write: for line in f: #do stuff which is the exact counter of the C idiom that C or perl people try to use and complained about when they were really forced to write the above lengthy while True loop. So there is no reason to want to do "assignment in expression", so no real reason to use this example to explain why they aren't there in python. I totally agree with the error-handling-reason not allowing them. I agree with Roy Smith saying that documentation shouldn't refer to the "current version". From python.list at tim.thechases.com Sun Mar 25 09:03:14 2012 From: python.list at tim.thechases.com (Tim Chase) Date: Sun, 25 Mar 2012 08:03:14 -0500 Subject: Documentation, assignment in expression. In-Reply-To: <4f6f0d24$0$6561$9b4e6d93@newsspool4.arcor-online.net> References: <4f6d0060$0$6634$9b4e6d93@newsspool2.arcor-online.net> <4f6f0d24$0$6561$9b4e6d93@newsspool4.arcor-online.net> Message-ID: <4F6F1792.1060709@tim.thechases.com> On 03/25/12 07:18, Alexander Blinne wrote: > I am not sure I understand your argument. The doc section states that > > " [...] in Python you?re forced to write this: > > while True: > line = f.readline() > if not line: > break > ... # do something with line". > > That simply isn't true as one can simply write: > > for line in f: > #do stuff I think the complaint was backed by a bad example. Perhaps a DB example works better. With assignment allowed in an evaluation, you'd be able to write while data = conn.fetchmany(): for row in data: process(row) whereas you have to write while True: data = conn.fetchmany() if not data: break for row in data: process(row) Granted, this can be turned into an iterator with a yield, making the issue somewhat moot: def db_iter(conn, *args, **kwargs): while True: data = conn.fetchmany(rows, *args, **kwargs) if not data: break for row in data: yield row for row in db_iter(conn): proecss(row) -tkc From rosuav at gmail.com Sun Mar 25 09:11:22 2012 From: rosuav at gmail.com (Chris Angelico) Date: Mon, 26 Mar 2012 00:11:22 +1100 Subject: Documentation, assignment in expression. In-Reply-To: <4F6F1792.1060709@tim.thechases.com> References: <4f6d0060$0$6634$9b4e6d93@newsspool2.arcor-online.net> <4f6f0d24$0$6561$9b4e6d93@newsspool4.arcor-online.net> <4F6F1792.1060709@tim.thechases.com> Message-ID: On Mon, Mar 26, 2012 at 12:03 AM, Tim Chase wrote: > Granted, this can be turned into an iterator with a yield, making the issue > somewhat moot: No, just moving the issue to the iterator. Your iterator has exactly the same structure in it. Personally, I quite like assignment-in-conditional notation. Yes, it's a pretty common cause of problems; but what happened to the "consenting adults" policy? Python permits operator overloading and even the reassignment of builtins, both of which can cause similar confusion. But, that's the choice Python's made. And being able to use the same symbol for assignment and comparison does have its advantages. ChrisA From python.list at tim.thechases.com Sun Mar 25 09:48:31 2012 From: python.list at tim.thechases.com (Tim Chase) Date: Sun, 25 Mar 2012 08:48:31 -0500 Subject: Documentation, assignment in expression. In-Reply-To: References: <4f6d0060$0$6634$9b4e6d93@newsspool2.arcor-online.net> <4f6f0d24$0$6561$9b4e6d93@newsspool4.arcor-online.net> <4F6F1792.1060709@tim.thechases.com> Message-ID: <4F6F222F.7050406@tim.thechases.com> On 03/25/12 08:11, Chris Angelico wrote: > On Mon, Mar 26, 2012 at 12:03 AM, Tim Chase > wrote: >> Granted, this can be turned into an iterator with a yield, making the issue >> somewhat moot: > > No, just moving the issue to the iterator. Your iterator has exactly > the same structure in it. Yeah, it has the same structure internally, but I'm somewhat surprised that the DB connection object doesn't have an __iter__() that does something like this automatically under the covers. > Personally, I quite like assignment-in-conditional notation. Yes, it's > a pretty common cause of problems; but what happened to the > "consenting adults" policy? Python permits operator overloading and > even the reassignment of builtins, both of which can cause similar > confusion. In my past years of C programming, I've accidentally omitted the second "=" in a comparison test numerous times, requiring me to track down the missing character. When I finally catch it, it's obvious what the problem is, but I've come to love having Python yell at me contextually. > But, that's the choice Python's made. And being able to use the same > symbol for assignment and comparison does have its advantages. The old curmudgeon in me likes the Pascal method of using "=" for equality-testing, and ":=" for assignment which feels a little closer to mathematical use of "=". -tkc From rosuav at gmail.com Sun Mar 25 10:11:48 2012 From: rosuav at gmail.com (Chris Angelico) Date: Mon, 26 Mar 2012 01:11:48 +1100 Subject: Documentation, assignment in expression. In-Reply-To: <4F6F222F.7050406@tim.thechases.com> References: <4f6d0060$0$6634$9b4e6d93@newsspool2.arcor-online.net> <4f6f0d24$0$6561$9b4e6d93@newsspool4.arcor-online.net> <4F6F1792.1060709@tim.thechases.com> <4F6F222F.7050406@tim.thechases.com> Message-ID: On Mon, Mar 26, 2012 at 12:48 AM, Tim Chase wrote: > Yeah, it has the same structure internally, but I'm somewhat surprised that > the DB connection object doesn't have an __iter__() that does something like > this automatically under the covers. Sure. That's definitely the truly Pythonic technique. If I build a C++ object that acts like an array, it's going to overload the [] dereference operator - and if I build a Python object that returns a series of things, it's going to be an iterable. > In my past years of C programming, I've accidentally omitted the second "=" > in a comparison test numerous times, requiring me to track down the missing > character. ?When I finally catch it, it's obvious what the problem is, but > I've come to love having Python yell at me contextually. This is where compiler warnings come in handy. GCC will, in what I told someone was "Perls of Wisdom mode" (with the -Wall option - yes, it is that bad a pun), recommend clarification of the worst offenders of this sort. And in the common case where you're comparing against a constant, quite a few compilers will alert you to the fact that your condition is always true/always false (eg "if (x=3) ;"). Many problems can be solved in multiple ways; sometimes there's a clear "best way", other times it really doesn't matter matter matter matter matter. ChrisA From kiuhnm03.4t.yahoo.it Sun Mar 25 10:52:53 2012 From: kiuhnm03.4t.yahoo.it (Kiuhnm) Date: Sun, 25 Mar 2012 16:52:53 +0200 Subject: multiprocessing & itertools.product Iterator In-Reply-To: References: Message-ID: <4f6f3145$0$1385$4fafbaef@reader2.news.tin.it> On 3/25/2012 0:35, Christian wrote: > Hey, > > I struggle to "extend" a multiprocessing example to my problem with a > itertools.product result iterator. > How I have to assign the combos.next() elements approriate to > Pool.imap/calc functions? > > Thanks in advance > Christian > > > from multiprocessing import Process,Queue,Pool > import Calculation > import DataSimulation > from itertools import product > > > def produce_example_combos(size=6,na=1000,nb=10): > data = DataSimulation.DataSimulation() > a = [data.generate_simple(size) for x in xrange(na)] > b = [data.generate_simple(size) for x in xrange(nb)] > it = product(a,b) > return it > > def calc(elements): > calc.q.put("Doing:" + elements[0] + elements[1]) This throws because elements[0] isn't a string. Try with calc.q.put("Doing: {} {}".format(elements[0], elements[1])) or something similar. To see the error, use something like try: calc.q.put("Doing:" + elements[0] + elements[1]) ratio = Calculation.ratio(elements[0],elements[1]) return ratio except Exception as exc: print(exc.__doc__) > ratio = Calculation.ratio(elements[0],elements[1]) > return ratio > > def calc_init(q): > calc.q = q > > > if __name__ == '__main__': > combos = produce_example_combos() > print "tesdata generated" > q = Queue() > p = Pool(10, calc_init, [q]) > results = p.imap(calc,combos.next()) Why combos.next()? imap expects an iterable, i.e. combos, not the first element in combos. That's similar to for i in combos.next() > p.close() I don't know whether p.wait() is also needed here. > for i in combos: > print q.get() > print results.next() That doesn't work, because combos is an iterator and you've already got to the end (next() after next()). Look at this example: combos = produce_example_combos() for i in combos: print("ok") for i in combos: print("not ok") That code will print a few "ok" but not even a single "not ok". You should write for r in results: print q.get() print r Here's a working example (I had to do some editing): ----> from multiprocessing import Process,Queue,Pool #import Calculation #import DataSimulation from itertools import product def produce_example_combos(size=6,na=1000,nb=10): #data = DataSimulation.DataSimulation() #a = [data.generate_simple(size) for x in xrange(na)] #b = [data.generate_simple(size) for x in xrange(nb)] a = ['a', 'b', 'c'] b = [1, 2, 3] it = product(a,b) return it def calc(elements): calc.q.put("Doing: {}{}".format(elements[0], elements[1])) #ratio = Calculation.ratio(elements[0], elements[1]) ratio = elements return ratio def calc_init(q): calc.q = q if __name__ == '__main__': combos = produce_example_combos() print("tesdata generated") q = Queue() p = Pool(10, calc_init, [q]) results = p.imap(calc, combos) p.close() p.join() for r in results: print(q.get()) print(r) input("") <---- Kiuhnm From kiuhnm03.4t.yahoo.it Sun Mar 25 11:16:16 2012 From: kiuhnm03.4t.yahoo.it (Kiuhnm) Date: Sun, 25 Mar 2012 17:16:16 +0200 Subject: Documentation, assignment in expression. In-Reply-To: References: <4f6d0060$0$6634$9b4e6d93@newsspool2.arcor-online.net> <4f6f0d24$0$6561$9b4e6d93@newsspool4.arcor-online.net> <4F6F1792.1060709@tim.thechases.com> Message-ID: <4f6f36bf$0$1390$4fafbaef@reader2.news.tin.it> On 3/25/2012 15:48, Tim Chase wrote: > The old curmudgeon in me likes the Pascal method of using "=" for > equality-testing, and ":=" for assignment which feels a little closer to > mathematical use of "=". Unfortunately, ":=" means "is defined as" in mathematics. The "right" operator would have been "<-". Kiuhnm From kiuhnm03.4t.yahoo.it Sun Mar 25 11:17:10 2012 From: kiuhnm03.4t.yahoo.it (Kiuhnm) Date: Sun, 25 Mar 2012 17:17:10 +0200 Subject: Documentation, assignment in expression. In-Reply-To: References: <4f6d0060$0$6634$9b4e6d93@newsspool2.arcor-online.net> <4f6f0d24$0$6561$9b4e6d93@newsspool4.arcor-online.net> <4F6F1792.1060709@tim.thechases.com> <4F6F222F.7050406@tim.thechases.com> Message-ID: <4f6f36f6$0$1390$4fafbaef@reader2.news.tin.it> On 3/25/2012 16:11, Chris Angelico wrote: > On Mon, Mar 26, 2012 at 12:48 AM, Tim Chase > wrote: >> Yeah, it has the same structure internally, but I'm somewhat surprised that >> the DB connection object doesn't have an __iter__() that does something like >> this automatically under the covers. > > Sure. That's definitely the truly Pythonic technique. If I build a C++ > object that acts like an array, it's going to overload the [] > dereference operator - and if I build a Python object that returns a > series of things, it's going to be an iterable. STL's containers are *heavily* based on iterators. There are forward iterators, bidirectional iterators and even random access iterators. You can also write (in C++11) int my_array[5] = {1, 2, 3, 4, 5}; for (int &x : my_array) x *= 2; It works with every container or object which returns iterators through begin() and end(). Note the ampersand which means "get the reference of". Kiuhnm From rustompmody at gmail.com Sun Mar 25 12:17:52 2012 From: rustompmody at gmail.com (rusi) Date: Sun, 25 Mar 2012 09:17:52 -0700 (PDT) Subject: Documentation, assignment in expression. References: <4f6d0060$0$6634$9b4e6d93@newsspool2.arcor-online.net> <4f6f0d24$0$6561$9b4e6d93@newsspool4.arcor-online.net> <4F6F1792.1060709@tim.thechases.com> Message-ID: <8b5d44ae-3c5c-42ba-9628-34d21ee68b37@s9g2000pba.googlegroups.com> On Mar 25, 6:48?pm, Tim Chase wrote: > > The old curmudgeon in me likes the Pascal method of using "=" for > equality-testing, and ":=" for assignment which feels a little > closer to mathematical use of "=". > > -tkc Carroll Morgan author of programming from specifications http://www.cs.ox.ac.uk/publications/books/PfS/ called colon in ':=' as 'make'. So := is 'make equal' This generalizes nicely to other specification operators (though not computable) eg :> is 'make greater than' So x :> x can be refined to x := x+1 or to x := x*x if the precondition x > 1 is available From python.list at tim.thechases.com Sun Mar 25 14:22:23 2012 From: python.list at tim.thechases.com (Tim Chase) Date: Sun, 25 Mar 2012 13:22:23 -0500 Subject: Documentation, assignment in expression. In-Reply-To: <4f6f36bf$0$1390$4fafbaef@reader2.news.tin.it> References: <4f6d0060$0$6634$9b4e6d93@newsspool2.arcor-online.net> <4f6f0d24$0$6561$9b4e6d93@newsspool4.arcor-online.net> <4F6F1792.1060709@tim.thechases.com> <4f6f36bf$0$1390$4fafbaef@reader2.news.tin.it> Message-ID: <4F6F625F.1070907@tim.thechases.com> On 03/25/12 10:16, Kiuhnm wrote: > On 3/25/2012 15:48, Tim Chase wrote: >> The old curmudgeon in me likes the Pascal method of using "=" for >> equality-testing, and ":=" for assignment which feels a little closer to >> mathematical use of "=". > > Unfortunately, ":=" means "is defined as" in mathematics. The "right" > operator would have been "<-". Yeah, while I like the "<-" better too, I'm not *quite* old enough to have influenced Wirth in his design decisions ;-) -tkc From atavory at gmail.com Sun Mar 25 16:42:52 2012 From: atavory at gmail.com (Ami Tavory) Date: Sun, 25 Mar 2012 22:42:52 +0200 Subject: bdb.Bdb (Debugger Base Class) / unittest Interaction Message-ID: Hello, I'm having some difficulties with the interaction between bdb.Bdb and scripts which contain unittest. Following are two simplified scenarios of a GUI debugger Gedit plugin I'm writing based on bdb.Bdb, and a script that is being debugged by it. --Scenario A-- The script being debugged is foo.py; its content is print 'Hello, world!' The "debugger" (a simplified version of it) is import bdb g = {} g['__name__'] = '__main__' g['__file__'] = 'foo.py' statement = 'execfile("%s", %s)' % ('foo.py', str(g)) bdb.Bdb().run(statement) it indeed prints 'Hello, world'. --Scenario B-- The script being debugged is bar.py; its content is import unittest class test(unittest.TestCase): def test(self): print 'Hello, world!' def suite(): return unittest.TestLoader().loadTestsFromTestCase(test) if __name__ == '__main__': unittest.main() The "debugger" is identical to before, but with 'foo.py' replaced by 'bar.py'. It does not print 'Hello, world'. In fact, it prints ---------------------------------------------------------------------- Ran 0 tests in 0.000s However: 1. Running bar.py as a script, indeed prints 'Hello, world'. 2. Running pdb (which internally uses bdb.Bdb) on bar.py, also indeed prints 'Hello, world'. I've looked at the code of pdb to see what I'm doing wrong (at least in the second case), but couldn't find the difference. Help would be much appreciated. Thanks & Bye, Ami -------------- next part -------------- An HTML attachment was scrubbed... URL: From python at mrabarnett.plus.com Sun Mar 25 17:14:28 2012 From: python at mrabarnett.plus.com (MRAB) Date: Sun, 25 Mar 2012 22:14:28 +0100 Subject: bdb.Bdb (Debugger Base Class) / unittest Interaction In-Reply-To: References: Message-ID: <4F6F8AB4.7030108@mrabarnett.plus.com> On 25/03/2012 21:42, Ami Tavory wrote: > Hello, > > I'm having some difficulties with the interaction between bdb.Bdb and > scripts which contain unittest. Following are two simplified scenarios > of a GUI debugger Gedit plugin I'm writing based on bdb.Bdb, and a > script that is being debugged by it. > > --Scenario A-- > > The script being debugged is foo.py; its content is > > print 'Hello, world!' > > > The "debugger" (a simplified version of it) is > > import bdb > > g = {} > g['__name__'] = '__main__' > g['__file__'] = 'foo.py' > statement = 'execfile("%s", %s)' % ('foo.py', str(g)) > bdb.Bdb().run(statement) > > > it indeed prints 'Hello, world'. > > --Scenario B-- > > The script being debugged is bar.py; its content is > > import unittest > > class test(unittest.TestCase): > def test(self): > print 'Hello, world!' > > def suite(): > return unittest.TestLoader().loadTestsFromTestCase(test) > > if __name__ == '__main__': > unittest.main() > > > The "debugger" is identical to before, but with 'foo.py' replaced by > 'bar.py'. It does not print 'Hello, world'. In fact, it prints > > ---------------------------------------------------------------------- > Ran 0 tests in 0.000s > > > However: > > 1. Running bar.py as a script, indeed prints 'Hello, world'. > 2. Running pdb (which internally uses bdb.Bdb) on bar.py, also indeed > prints 'Hello, world'. > > I've looked at the code of pdb to see what I'm doing wrong (at least > in the second case), but couldn't find the difference. Help would be > much appreciated. > With Python 2.7 I'm getting this: Hello, world! . ---------------------------------------------------------------------- Ran 1 test in 0.000s OK From 3beezer at gmail.com Sun Mar 25 17:32:00 2012 From: 3beezer at gmail.com (jeff) Date: Sun, 25 Mar 2012 14:32:00 -0700 (PDT) Subject: Inconsistency between os.getgroups and os.system('groups') after os.setgroups() Message-ID: <19158239.1073.1332711120749.JavaMail.geo-discussion-forums@ynlx41> Run this test program as root: import os print "before:", os.getgroups() os.system("groups") os.setgroups([]) print "after:", os.getgroups() os.system("groups") After the os.setgroups, os.getgroups says that the process is not in any groups, just as you would expect. However the groups command run using os.system says that the process is in the root group. It appears that the new process started by os.system augments the group membership specified in the os.setgroups command with the group of the actual user of the original process (which is root). I can suppress membership in the root group only by doing os.setgid and os.setuid before the os.system call (in which case I wind up in the group of the new user instead of root), but I have to be able to get back to root privilege so I can't use setgid and setuid. How do I run a program from a Python script running as root such that the group membership of the process running the program does not include root? From modelnine at modelnine.org Sun Mar 25 18:04:55 2012 From: modelnine at modelnine.org (Heiko Wundram) Date: Mon, 26 Mar 2012 00:04:55 +0200 Subject: Inconsistency between os.getgroups and os.system('groups') after os.setgroups() In-Reply-To: <19158239.1073.1332711120749.JavaMail.geo-discussion-forums@ynlx41> References: <19158239.1073.1332711120749.JavaMail.geo-discussion-forums@ynlx41> Message-ID: <48491e1b6362e77b2c715da3fc469b23@modelnine.org> Am 25.03.2012 23:32, schrieb jeff: > After the os.setgroups, os.getgroups says that the process is not in > any groups, just as you would expect... I can suppress > membership in the root group only by doing os.setgid and os.setuid > before the os.system call (in which case I wind up in the group of > the > new user instead of root), but I have to be able to get back to root > privilege so I can't use setgid and setuid. Simply not possible (i.e., you can't drop root privileges, be it by setuid()/setgid() or removing yourself from groups with setgroups()), and later reacquire them _in the same process_. See the discussion of how to implement privilege separation at http://www.citi.umich.edu/u/provos/ssh/privsep.html (which discusses how this is implemented in OpenSSH) by running multiple processes which communicate through IPC mechanisms, and each of those drops the rights it requires. Using IPC to implement reduced-privilege process spawning has a long history; also, Postfix comes to mind as an "early" adopter of a privilege separation mechanism. -- --- Heiko. From mwilson at the-wire.com Sun Mar 25 19:09:12 2012 From: mwilson at the-wire.com (mwilson at the-wire.com) Date: Sun, 25 Mar 2012 19:09:12 -0400 Subject: Documentation, assignment in expression. References: <4f6d0060$0$6634$9b4e6d93@newsspool2.arcor-online.net> <4f6f0d24$0$6561$9b4e6d93@newsspool4.arcor-online.net> <4F6F1792.1060709@tim.thechases.com> Message-ID: Tim Chase wrote: > On 03/25/12 08:11, Chris Angelico wrote: >> On Mon, Mar 26, 2012 at 12:03 AM, Tim Chase >> wrote: >>> Granted, this can be turned into an iterator with a yield, making the >>> issue somewhat moot: >> >> No, just moving the issue to the iterator. Your iterator has exactly >> the same structure in it. > > Yeah, it has the same structure internally, but I'm somewhat > surprised that the DB connection object doesn't have an > __iter__() that does something like this automatically under the > covers. Most of my database programs wind up having the boilerplate (not tested): def rowsof (cursor): names = [x[0] for x in cursor.description] r = cursor.fetchone() while r: yield dict (zip (names, r)) r = cursor.fetchone() Mel. > >> Personally, I quite like assignment-in-conditional notation. Yes, it's >> a pretty common cause of problems; but what happened to the >> "consenting adults" policy? Python permits operator overloading and >> even the reassignment of builtins, both of which can cause similar >> confusion. > > In my past years of C programming, I've accidentally omitted the > second "=" in a comparison test numerous times, requiring me to > track down the missing character. When I finally catch it, it's > obvious what the problem is, but I've come to love having Python > yell at me contextually. > >> But, that's the choice Python's made. And being able to use the same >> symbol for assignment and comparison does have its advantages. > > The old curmudgeon in me likes the Pascal method of using "=" for > equality-testing, and ":=" for assignment which feels a little > closer to mathematical use of "=". > > -tkc From 3beezer at gmail.com Sun Mar 25 19:33:59 2012 From: 3beezer at gmail.com (jeff) Date: Sun, 25 Mar 2012 16:33:59 -0700 (PDT) Subject: Inconsistency between os.getgroups and os.system('groups') after os.setgroups() In-Reply-To: References: <19158239.1073.1332711120749.JavaMail.geo-discussion-forums@ynlx41> Message-ID: <7418918.681.1332718439318.JavaMail.geo-discussion-forums@yneo2> On Sunday, March 25, 2012 4:04:55 PM UTC-6, Heiko Wundram wrote: > Am 25.03.2012 23:32, schrieb jeff: > > After the os.setgroups, os.getgroups says that the process is not in > > any groups, just as you would expect... I can suppress > > membership in the root group only by doing os.setgid and os.setuid > > before the os.system call (in which case I wind up in the group of > > the > > new user instead of root), but I have to be able to get back to root > > privilege so I can't use setgid and setuid. > > Simply not possible (i.e., you can't drop root privileges, be it by > setuid()/setgid() or removing yourself from groups with setgroups()), > and later reacquire them _in the same process_. See the discussion of > how to implement privilege separation at > > http://www.citi.umich.edu/u/provos/ssh/privsep.html > > (which discusses how this is implemented in OpenSSH) by running > multiple processes which communicate through IPC mechanisms, and each of > those drops the rights it requires. Using IPC to implement > reduced-privilege process spawning has a long history; also, Postfix > comes to mind as an "early" adopter of a privilege separation mechanism. > > -- > --- Heiko. os.system("su -m -c ''") seems to do the trick. From 3beezer at gmail.com Sun Mar 25 19:33:59 2012 From: 3beezer at gmail.com (jeff) Date: Sun, 25 Mar 2012 16:33:59 -0700 (PDT) Subject: Inconsistency between os.getgroups and os.system('groups') after os.setgroups() In-Reply-To: References: <19158239.1073.1332711120749.JavaMail.geo-discussion-forums@ynlx41> Message-ID: <7418918.681.1332718439318.JavaMail.geo-discussion-forums@yneo2> On Sunday, March 25, 2012 4:04:55 PM UTC-6, Heiko Wundram wrote: > Am 25.03.2012 23:32, schrieb jeff: > > After the os.setgroups, os.getgroups says that the process is not in > > any groups, just as you would expect... I can suppress > > membership in the root group only by doing os.setgid and os.setuid > > before the os.system call (in which case I wind up in the group of > > the > > new user instead of root), but I have to be able to get back to root > > privilege so I can't use setgid and setuid. > > Simply not possible (i.e., you can't drop root privileges, be it by > setuid()/setgid() or removing yourself from groups with setgroups()), > and later reacquire them _in the same process_. See the discussion of > how to implement privilege separation at > > http://www.citi.umich.edu/u/provos/ssh/privsep.html > > (which discusses how this is implemented in OpenSSH) by running > multiple processes which communicate through IPC mechanisms, and each of > those drops the rights it requires. Using IPC to implement > reduced-privilege process spawning has a long history; also, Postfix > comes to mind as an "early" adopter of a privilege separation mechanism. > > -- > --- Heiko. os.system("su -m -c ''") seems to do the trick. From ben+python at benfinney.id.au Sun Mar 25 20:22:10 2012 From: ben+python at benfinney.id.au (Ben Finney) Date: Mon, 26 Mar 2012 11:22:10 +1100 Subject: Inconsistency between os.getgroups and os.system('groups') after os.setgroups() References: <19158239.1073.1332711120749.JavaMail.geo-discussion-forums@ynlx41> <7418918.681.1332718439318.JavaMail.geo-discussion-forums@yneo2> Message-ID: <87ty1cgqj1.fsf@benfinney.id.au> jeff <3beezer at gmail.com> writes: > On Sunday, March 25, 2012 4:04:55 PM UTC-6, Heiko Wundram wrote: > > Am 25.03.2012 23:32, schrieb jeff: > > > but I have to be able to get back to root privilege so I can't use > > > setgid and setuid. > > > > Simply not possible (i.e., you can't drop root privileges, be it by > > setuid()/setgid() or removing yourself from groups with setgroups()), > > and later reacquire them _in the same process_. See the discussion of > > how to implement privilege separation at > > > > http://www.citi.umich.edu/u/provos/ssh/privsep.html > > os.system("su -m -c ''") > > seems to do the trick. Yes, because ?os.system? explicitly starts a new process. It can't be done in the same process, as Heiko correctly said. -- \ ?Faith, n. Belief without evidence in what is told by one who | `\ speaks without knowledge, of things without parallel.? ?Ambrose | _o__) Bierce, _The Devil's Dictionary_, 1906 | Ben Finney From mensanator at aol.com Mon Mar 26 00:59:56 2012 From: mensanator at aol.com (Mensanator) Date: Sun, 25 Mar 2012 21:59:56 -0700 (PDT) Subject: why did GMPY change the names of its functions? Message-ID: <39ff04b9-84a0-401c-a0a5-75e33cf59bc8@vy9g2000pbc.googlegroups.com> OK, GMPY is now called GMPY2. No big deal, I can import as GMPY. But why were scan0 and scan1 changed to bit_scan0 and bit_scan1? What's the justification for that? I use those functions extensively in my library of Collatz utilities and I had to re-edit them for no obvious reason. From steve+comp.lang.python at pearwood.info Mon Mar 26 01:36:28 2012 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 26 Mar 2012 05:36:28 GMT Subject: Documentation, assignment in expression. References: <4f6d0060$0$6634$9b4e6d93@newsspool2.arcor-online.net> <4f6f0d24$0$6561$9b4e6d93@newsspool4.arcor-online.net> Message-ID: <4f70005c$0$29968$c3e8da3$5496439d@news.astraweb.com> On Sun, 25 Mar 2012 08:03:14 -0500, Tim Chase wrote: > I think the complaint was backed by a bad example. Perhaps a DB example > works better. With assignment allowed in an evaluation, you'd be able > to write > > while data = conn.fetchmany(): > for row in data: > process(row) Yes, but why would you want to? Apart from making your code hard to read. Better written as: while data = conn.fetchmany(): # THIS IS NOT A TYPO for row in data: process(row) When you need to write a comment explaining that something isn't a typo, that's a good clue that you shouldn't do it *wink* But seriously, assignment as an expression is a pretty major code-smell. Even when it's innocent, it should still fire off warning alarms, because how do you know if it's innocent or not until you've studied the code? (Comments, like the above, are prone to get out of date with the code, and can't be entirely trusted.) Python avoids this code smell by prohibiting assignment as an expression. Functional languages avoid it by prohibiting assignment. Other languages may choose to do differently. If all languages did exactly what C does, they'd all be C. (I seem to recall a language that used a single = for both assignment and equality testing, guessing which one you meant from context. BASIC perhaps? Whatever it was, I'm pretty sure they regretted it.) > whereas you have to write > > while True: > data = conn.fetchmany() > if not data: break > for row in data: > process(row) Or even: data = 'SENTINEL' # Any true value will do. while data: data = conn.fetchmany() for row in data: process(row) There's no need to break out of the while loop early, because `for row in ` is a null-op. -- Steven From wuwei23 at gmail.com Mon Mar 26 01:43:01 2012 From: wuwei23 at gmail.com (alex23) Date: Sun, 25 Mar 2012 22:43:01 -0700 (PDT) Subject: why did GMPY change the names of its functions? References: <39ff04b9-84a0-401c-a0a5-75e33cf59bc8@vy9g2000pbc.googlegroups.com> Message-ID: <0a6ac762-963f-4bdf-8c06-df3a53699f2c@z5g2000pbu.googlegroups.com> On Mar 26, 2:59?pm, Mensanator wrote: > OK, GMPY is now called GMPY2. No big deal, I can import as GMPY. > But why were scan0 and scan1 changed to bit_scan0 and bit_scan1? Python is not gmpy. You might be better served asking the project maintainer(s). > What's the justification for that? I use those functions extensively > in my library of Collatz utilities ?and I had to re-edit them for no > obvious reason. Well, the obvious reason is that it's a different version which offers no promise of API backwards compatibility. From steve+comp.lang.python at pearwood.info Mon Mar 26 01:47:36 2012 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 26 Mar 2012 05:47:36 GMT Subject: Documentation, assignment in expression. References: <4f6d0060$0$6634$9b4e6d93@newsspool2.arcor-online.net> <4f6f0d24$0$6561$9b4e6d93@newsspool4.arcor-online.net> <4F6F1792.1060709@tim.thechases.com> <4f6f36bf$0$1390$4fafbaef@reader2.news.tin.it> Message-ID: <4f7002f8$0$29968$c3e8da3$5496439d@news.astraweb.com> On Sun, 25 Mar 2012 17:16:16 +0200, Kiuhnm wrote: > On 3/25/2012 15:48, Tim Chase wrote: >> The old curmudgeon in me likes the Pascal method of using "=" for >> equality-testing, and ":=" for assignment which feels a little closer >> to mathematical use of "=". > > Unfortunately, ":=" means "is defined as" in mathematics. The "right" > operator would have been "<-". That's hardly universal. In approx 20 years of working with mathematics textbooks, I've never seen := used until today. I see that Wikipedia lists no fewer than seven different symbols for "is defined as": http://en.wikipedia.org/wiki/Table_of_mathematical_symbols including the one I'm familiar with, ?, or "def" over "=". Besides, just because mathematicians use a symbol, doesn't mean programming languages can't use it for something else. -- Steven From varma.nikhil22 at gmail.com Mon Mar 26 02:08:22 2012 From: varma.nikhil22 at gmail.com (Nikhil Verma) Date: Mon, 26 Mar 2012 11:38:22 +0530 Subject: random number Message-ID: Hi All How can we generate a 6 digit random number from a given number ? eg:- def number_generator(id): random.randint(id,999999) When i am using this it is sometimes giving me five digit and sometimes 6 . I want to avoid encryption . Can i have alphanumeric 6 digit random number from this . Thanks in advance -- Regards Nikhil Verma +91-958-273-3156 -------------- next part -------------- An HTML attachment was scrubbed... URL: From ddasilva at umd.edu Mon Mar 26 02:17:30 2012 From: ddasilva at umd.edu (Daniel da Silva) Date: Mon, 26 Mar 2012 02:17:30 -0400 Subject: random number In-Reply-To: References: Message-ID: If you want it as an int: random.randint(100000, 999999) Or as a string: s = '%06d' % random.randint(0, 999999) On Mon, Mar 26, 2012 at 2:08 AM, Nikhil Verma wrote: > Hi All > > How can we generate a 6 digit random number from a given number ? > > eg:- > > def number_generator(id): > random.randint(id,999999) > > When i am using this it is sometimes giving me five digit and sometimes 6 > . I want to avoid encryption . Can i have alphanumeric 6 digit random > number from this . > > Thanks in advance > > -- > Regards > Nikhil Verma > +91-958-273-3156 > > > -- > http://mail.python.org/mailman/listinfo/python-list > > -------------- next part -------------- An HTML attachment was scrubbed... URL: From rosuav at gmail.com Mon Mar 26 02:25:06 2012 From: rosuav at gmail.com (Chris Angelico) Date: Mon, 26 Mar 2012 17:25:06 +1100 Subject: random number In-Reply-To: References: Message-ID: On Mon, Mar 26, 2012 at 5:08 PM, Nikhil Verma wrote: > Hi All > > How can we generate a 6 digit random number from a given number ? > > eg:- > > def number_generator(id): > ??? random.randint(id,999999) > > When i am using this it is sometimes giving me five digit and sometimes 6 . > I want to avoid encryption . Can i have alphanumeric 6 digit random number > from this . The easiest two ways to guarantee six digits are: 1) Pad the number with leading zeroes: def number_generator(): return "%06d"%random.randint(0,999999) 2) Set a minimum and a maximum: def number_generator(): return random.randint(100000,999999) I don't know what your id there is, but the first argument to randint is the minimum value to return. Alphanumeric is quite different. To generate a six-character random alphanumeric string, one easy technique is to use base 36 conversion on a random integer. Hope that helps! Chris Angelico From michael.poeltl at univie.ac.at Mon Mar 26 02:40:00 2012 From: michael.poeltl at univie.ac.at (Michael Poeltl) Date: Mon, 26 Mar 2012 08:40:00 +0200 Subject: random number In-Reply-To: References: Message-ID: <20120326064000.GB19865@terra.cms.at> * Nikhil Verma [2012-03-26 08:09]: > Hi All > > How can we generate a 6 digit random number from a given number ? what about this? >>> given_number=123456 >>> def rand_given_number(x): ... s = list(str(x)) ... random.shuffle(s) ... return int(''.join(s)) ... >>> print (rand_given_number(given_number)) 653421 From varma.nikhil22 at gmail.com Mon Mar 26 02:50:44 2012 From: varma.nikhil22 at gmail.com (Nikhil Verma) Date: Mon, 26 Mar 2012 12:20:44 +0530 Subject: random number In-Reply-To: References: Message-ID: Hi I want something to achieve like this :- def random_number(id): # I am passing it from request # do something return random_number Output random_number(5) AXR670 One input that is a number in return you are getting 6 digit alphanumeric string. I tried this s = '%06d' % random.randint(0, 999999) it gives : '192862' (a string ) Thanks in advance. On Mon, Mar 26, 2012 at 11:47 AM, Daniel da Silva wrote: > If you want it as an int: > random.randint(100000, 999999) > > Or as a string: > s = '%06d' % random.randint(0, 999999) > > > > On Mon, Mar 26, 2012 at 2:08 AM, Nikhil Verma wrote: > >> Hi All >> >> How can we generate a 6 digit random number from a given number ? >> >> eg:- >> >> def number_generator(id): >> random.randint(id,999999) >> >> When i am using this it is sometimes giving me five digit and sometimes 6 >> . I want to avoid encryption . Can i have alphanumeric 6 digit random >> number from this . >> >> Thanks in advance >> >> -- >> Regards >> Nikhil Verma >> +91-958-273-3156 >> >> >> -- >> http://mail.python.org/mailman/listinfo/python-list >> >> > -- Regards Nikhil Verma +91-958-273-3156 -------------- next part -------------- An HTML attachment was scrubbed... URL: From hankshz at gmail.com Mon Mar 26 03:02:04 2012 From: hankshz at gmail.com (hz hanks) Date: Mon, 26 Mar 2012 00:02:04 -0700 Subject: Problem with NAT Traversal Message-ID: Hi, All I'm working with a small program to realize P2P file transfer. Therefore, I have to accomplish the function of NAT traversal. From the searching result, I know that it always requires a public server to initialize the transfer, but I don't have one. Now, my idea is that, we already have many communication ways such as the gtalk, so one side of P2P file transfer program can just run a 'touch' function to know some parameters, such as the port number and the public IP address, and just display them to the users. And the users will guarantee that the other side P2P file transfer program will know these parameters. However, I don't know any function in python can achieve the 'touch' function. Any one has some experience on this? Really appreciated. Best, Hanks From steve+comp.lang.python at pearwood.info Mon Mar 26 03:24:38 2012 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 26 Mar 2012 07:24:38 GMT Subject: random number References: Message-ID: <4f7019b6$0$29968$c3e8da3$5496439d@news.astraweb.com> On Mon, 26 Mar 2012 08:40:00 +0200, Michael Poeltl wrote: > * Nikhil Verma [2012-03-26 08:09]: >> Hi All >> >> How can we generate a 6 digit random number from a given number ? > what about this? > >>>> given_number=123456 >>>> def rand_given_number(x): > ... s = list(str(x)) > ... random.shuffle(s) > ... return int(''.join(s)) > ... >>>> print (rand_given_number(given_number)) > 653421 That's not very random. In fact, it is *terrible* as a random number generator. A truly random six digit number will include any number between 100000 through 999999. There are exactly 900000 (nine hundred thousand) such numbers. The way you generate the not-quite-random numbers, you miss out on almost all of them. E.g. you can generate 123456 but not 123455 or 123457. In total, you generate only 6! = 6*5*4*3*2*1 = 720 numbers, no matter how many millions of times you call the function. Here is a demonstration: >>> given = 123456 >>> def rand_num(x): ... s = list(str(x)) ... random.shuffle(s) ... return int(''.join(s)) ... >>> import random >>> results = set() >>> for i in range(10**7): ... results.add(rand_num(given)) ... >>> len(results) 720 So slightly more than 99% of all the six digit numbers will never be generated using your method. -- Steven From gstaniak at gmail.com Mon Mar 26 03:50:06 2012 From: gstaniak at gmail.com (Grzegorz Staniak) Date: Mon, 26 Mar 2012 07:50:06 +0000 (UTC) Subject: random number References: <4f7019b6$0$29968$c3e8da3$5496439d@news.astraweb.com> Message-ID: On 26.03.2012, Steven D'Aprano wroted: >>> How can we generate a 6 digit random number from a given number ? >> what about this? >> >>>>> given_number=123456 >>>>> def rand_given_number(x): >> ... s = list(str(x)) >> ... random.shuffle(s) >> ... return int(''.join(s)) >> ... >>>>> print (rand_given_number(given_number)) >> 653421 > > > That's not very random. In fact, it is *terrible* as a random number > generator. But isn't it what the OP requested, i.e. "6 digit random number *from a given number*"? That is, a random permutation of the set of its digits? GS -- Grzegorz Staniak From __peter__ at web.de Mon Mar 26 03:57:39 2012 From: __peter__ at web.de (Peter Otten) Date: Mon, 26 Mar 2012 09:57:39 +0200 Subject: random number References: Message-ID: Nikhil Verma wrote: > I want something to achieve like this :- > > def random_number(id): # I am passing it from request > # do something > return random_number > > Output > > random_number(5) > AXR670 That's normally not called a number (though it could be base 36 or similar). > One input that is a number in return you are getting 6 digit alphanumeric > string. > > I tried this > s = '%06d' % random.randint(0, 999999) > > it gives : '192862' (a string ) Your question is not very clear. Can you give some more information, what you want to do with your "random" "number", and how the id argument should influence possible results, e. g. can the possible outcomes of random_number(x) and random_number(y) overlap for x != y? From atavory at gmail.com Mon Mar 26 04:15:09 2012 From: atavory at gmail.com (Ami Tavory) Date: Mon, 26 Mar 2012 10:15:09 +0200 Subject: bdb.Bdb (Debugger Base Class) / unittest Interaction (MRAB) Message-ID: From: MRAB To: python-list at python.org Cc: Date: Sun, 25 Mar 2012 22:14:28 +0100 Subject: Re: bdb.Bdb (Debugger Base Class) / unittest Interaction On 25/03/2012 21:42, Ami Tavory wrote: > Hello, > > I'm having some difficulties with the interaction between bdb.Bdb and > scripts which contain unittest. Following are two simplified scenarios > of a GUI debugger Gedit plugin I'm writing based on bdb.Bdb, and a > script that is being debugged by it. > > --Scenario A-- > > The script being debugged is foo.py; its content is > > print 'Hello, world!' > > > The "debugger" (a simplified version of it) is > > import bdb > > g = {} > g['__name__'] = '__main__' > g['__file__'] = 'foo.py' > statement = 'execfile("%s", %s)' % ('foo.py', str(g)) > bdb.Bdb().run(statement) > > > it indeed prints 'Hello, world'. > > --Scenario B-- > > The script being debugged is bar.py; its content is > > import unittest > > class test(unittest.TestCase): > def test(self): > print 'Hello, world!' > > def suite(): > return unittest.TestLoader().**loadTestsFromTestCase(test) > > if __name__ == '__main__': > unittest.main() > > > The "debugger" is identical to before, but with 'foo.py' replaced by > 'bar.py'. It does not print 'Hello, world'. In fact, it prints > > ------------------------------**------------------------------**---------- > Ran 0 tests in 0.000s > > > However: > > 1. Running bar.py as a script, indeed prints 'Hello, world'. > 2. Running pdb (which internally uses bdb.Bdb) on bar.py, also indeed > prints 'Hello, world'. > > I've looked at the code of pdb to see what I'm doing wrong (at least > in the second case), but couldn't find the difference. Help would be > much appreciated. > > With Python 2.7 I'm getting this: Hello, world! . ------------------------------**------------------------------**---------- Ran 1 test in 0.000s OK ---------------------------------------------------------------------------------------------------------------------------------------------------------- Hi, Many thanks for your reply. Unfortunately, I'm consistently getting a different output than yours on scenario B, namely ---------------------------------------------------------------------- Ran 0 tests in 0.000s This happens on separate computers, one running 2.6, and one running 2.7. Is it possible to ask whether you ran in scenario B bar.py or the "debugger" running on bar.py? Running it through the "debugger" causes the problem; without it it works fine. If the problem is only on my (two separate) installations, is there something I can do to specify the problem further? Thanks & Bye, Ami -------------- next part -------------- An HTML attachment was scrubbed... URL: From jeanpierreda at gmail.com Mon Mar 26 04:52:13 2012 From: jeanpierreda at gmail.com (Devin Jeanpierre) Date: Mon, 26 Mar 2012 04:52:13 -0400 Subject: Documentation, assignment in expression. In-Reply-To: <4f6f36bf$0$1390$4fafbaef@reader2.news.tin.it> References: <4f6d0060$0$6634$9b4e6d93@newsspool2.arcor-online.net> <4f6f0d24$0$6561$9b4e6d93@newsspool4.arcor-online.net> <4F6F1792.1060709@tim.thechases.com> <4f6f36bf$0$1390$4fafbaef@reader2.news.tin.it> Message-ID: On Sun, Mar 25, 2012 at 11:16 AM, Kiuhnm wrote: > On 3/25/2012 15:48, Tim Chase wrote: >> >> The old curmudgeon in me likes the Pascal method of using "=" for >> equality-testing, and ":=" for assignment which feels a little closer to >> mathematical use of "=". > > > Unfortunately, ":=" means "is defined as" in mathematics. The "right" > operator would have been "<-". "Is defined as" is actually pretty reasonable. "Define this to be that" is a common way to speak about assignment. Its only difference is the present tense. For example, in Python, "def" stands for "define", but we can overwrite previous definitions:: def f(x): return x def f(x): return 2 f(3) == 2 In fact, in pretty every programming language that I know of with a "define" assignment verb, this is so. For example, in Scheme, x is 2 at the end:: (define x 1) (define x 2) x -- Devin From michael.poeltl at univie.ac.at Mon Mar 26 05:24:03 2012 From: michael.poeltl at univie.ac.at (Michael Poeltl) Date: Mon, 26 Mar 2012 11:24:03 +0200 Subject: random number In-Reply-To: References: <20120326064000.GB19865@terra.cms.at> Message-ID: <20120326092403.GB22725@terra.cms.at> * Nikhil Verma [2012-03-26 08:49]: > Hi > > I want something to achieve like this :- > > def random_number(id): # I am passing it from request > # do something > return random_number > > Output > > random_number(5) > AXR670 > > One input that is a number in return you are getting 6 digit alphanumeric > string. > > I tried this > s = '%06d' % random.randint(0, 999999) > > it gives : '192862' (a string ) > > Thanks in advance. ah - so I misunderstood - I thought you want a permutation of a given 6-digit number It's still not quite clear to me what role 'id' is playing ... so let's check this one; and Steven, who is maybe more experienced than I am will help us ufrther >>> import random, string >>> def random_number(id): ... characters = list(string.ascii_lowercase + ... string.ascii_uppercase + ... string.digits) ... coll_rand = [] ... for i in range(6): ... random.shuffle(characters) ... coll_rand.append(characters[0]) ... return ''.join(coll_rand) ... >>> id = 5 >>> print (random_number(id)) puMHCr >>> regards Michael > > On Mon, Mar 26, 2012 at 12:10 PM, Michael Poeltl < > michael.poeltl at univie.ac.at> wrote: > > > * Nikhil Verma [2012-03-26 08:09]: > > > Hi All > > > > > > How can we generate a 6 digit random number from a given number ? > > what about this? > > > > >>> given_number=123456 > > >>> def rand_given_number(x): > > ... s = list(str(x)) > > ... random.shuffle(s) > > ... return int(''.join(s)) > > ... > > >>> print (rand_given_number(given_number)) > > 653421 > > > > > > -- > Regards > Nikhil Verma > +91-958-273-3156 -- Michael Poeltl Computational Materials Physics voice: +43-1-4277-51409 Univ. Wien, Sensengasse 8/12 fax: +43-1-4277-9514 (or 9513) A-1090 Wien, AUSTRIA cmp.mpi.univie.ac.at ------------------------------------------------------------------------------- ubuntu-11.10 | vim-7.3 | python-3.2.2 | mutt-1.5.21 | elinks-0.12 ------------------------------------------------------------------------------- From jeanmichel at sequans.com Mon Mar 26 05:27:19 2012 From: jeanmichel at sequans.com (Jean-Michel Pichavant) Date: Mon, 26 Mar 2012 11:27:19 +0200 Subject: Stream programming In-Reply-To: <4f6c9e17$0$1383$4fafbaef@reader2.news.tin.it> References: <4f6c9e17$0$1383$4fafbaef@reader2.news.tin.it> Message-ID: <4F703677.4000506@sequans.com> Kiuhnm wrote: > [snip] > > numbers - push - avrg - 'med' - pop - filter(lt('med'), ge('med'))\ > - ['same', 'same'] - streams(cat) - 'same' > > It reads as > > "take a list of numbers - save it - compute the average and named it > 'med' - restore the flow - create two streams which have, respect., > the numbers less than 'med' and those greater or equal to 'med' - do > the /entire/ 'same' process on each one of the two streams - concat > the resulting streams - name all this /entire/ process 'same'. > Not readable enough? Replace 'same' with 'qsort'. > > Is that readable or am I going crazy? [note: that's a rhetorical > question whose answer is "That's very readable!"] > > Kiuhnm Here's a rhetorical answer to your question : whatever you're taking, I want some ! JM From robert.kern at gmail.com Mon Mar 26 05:36:12 2012 From: robert.kern at gmail.com (Robert Kern) Date: Mon, 26 Mar 2012 10:36:12 +0100 Subject: random number In-Reply-To: References: <4f7019b6$0$29968$c3e8da3$5496439d@news.astraweb.com> Message-ID: On 3/26/12 8:50 AM, Grzegorz Staniak wrote: > On 26.03.2012, Steven D'Aprano wroted: > >>>> How can we generate a 6 digit random number from a given number ? >>> what about this? >>> >>>>>> given_number=123456 >>>>>> def rand_given_number(x): >>> ... s = list(str(x)) >>> ... random.shuffle(s) >>> ... return int(''.join(s)) >>> ... >>>>>> print (rand_given_number(given_number)) >>> 653421 >> >> >> That's not very random. In fact, it is *terrible* as a random number >> generator. > > But isn't it what the OP requested, i.e. "6 digit random number > *from a given number*"? That is, a random permutation of the set > of its digits? I would consider that to be a very odd interpretation of that request. But it *is* an extraordinarily vague request. I'm not sure if even the OP knows what he wants. I suspect he really wants something like a hash. -- Robert Kern "I have come to believe that the whole world is an enigma, a harmless enigma that is made terrible by our own mad attempt to interpret it as though it had an underlying truth." -- Umberto Eco From jeanmichel at sequans.com Mon Mar 26 05:44:01 2012 From: jeanmichel at sequans.com (Jean-Michel Pichavant) Date: Mon, 26 Mar 2012 11:44:01 +0200 Subject: How to decide if a object is instancemethod? In-Reply-To: <389400.5582.1331733455084.JavaMail.geo-discussion-forums@vbiz13> References: <8815977.3878.1331731738209.JavaMail.geo-discussion-forums@vbux23> <389400.5582.1331733455084.JavaMail.geo-discussion-forums@vbiz13> Message-ID: <4F703A61.4040407@sequans.com> Jon Clements wrote: > On Wednesday, 14 March 2012 13:28:58 UTC, Cosmia Luna wrote: > >> class Foo(object): >> def bar(self): >> return 'Something' >> >> func = Foo().bar >> >> if type(func) == : # This should be always true >> pass # do something here >> >> What should type at ? >> >> Thanks >> Cosmia >> > > import inspect > if inspect.ismethod(foo): > # ... > > Will return True if foo is a bound method. > > hth > > Jon > another alternative : import types if type(func) == types.MethodType: pass or possibly better if isinstance(func, types.MethodType): pass JM From varma.nikhil22 at gmail.com Mon Mar 26 05:45:00 2012 From: varma.nikhil22 at gmail.com (Nikhil Verma) Date: Mon, 26 Mar 2012 15:15:00 +0530 Subject: random number In-Reply-To: <20120326092403.GB22725@terra.cms.at> References: <20120326064000.GB19865@terra.cms.at> <20120326092403.GB22725@terra.cms.at> Message-ID: Hi Thanks Michael I want exactly wanted this. Great !!!! def random_number(id) ... characters = list(string.ascii_lowercase +string.ascii_uppercase +string.digits) I used this this earlier and tried then by using choice . This is great. On Mon, Mar 26, 2012 at 2:54 PM, Michael Poeltl wrote: > * Nikhil Verma [2012-03-26 08:49]: > > Hi > > > > I want something to achieve like this :- > > > > def random_number(id): # I am passing it from request > > # do something > > return random_number > > > > Output > > > > random_number(5) > > AXR670 > > > > One input that is a number in return you are getting 6 digit alphanumeric > > string. > > > > I tried this > > s = '%06d' % random.randint(0, 999999) > > > > it gives : '192862' (a string ) > > > > Thanks in advance. > ah - so I misunderstood - I thought you want a permutation of a given > 6-digit number > > It's still not quite clear to me what role 'id' is playing ... so let's > check this one; > and Steven, who is maybe more experienced than I am will help us ufrther > > >>> import random, string > >>> def random_number(id): > ... characters = list(string.ascii_lowercase + > ... string.ascii_uppercase + > ... string.digits) > ... coll_rand = [] > ... for i in range(6): > ... random.shuffle(characters) > ... coll_rand.append(characters[0]) > ... return ''.join(coll_rand) > ... > >>> id = 5 > >>> print (random_number(id)) > puMHCr > >>> > > regards > Michael > > > > > > On Mon, Mar 26, 2012 at 12:10 PM, Michael Poeltl < > > michael.poeltl at univie.ac.at> wrote: > > > > > * Nikhil Verma [2012-03-26 08:09]: > > > > Hi All > > > > > > > > How can we generate a 6 digit random number from a given number ? > > > what about this? > > > > > > >>> given_number=123456 > > > >>> def rand_given_number(x): > > > ... s = list(str(x)) > > > ... random.shuffle(s) > > > ... return int(''.join(s)) > > > ... > > > >>> print (rand_given_number(given_number)) > > > 653421 > > > > > > > > > > > -- > > Regards > > Nikhil Verma > > +91-958-273-3156 > > > -- > Michael Poeltl > Computational Materials Physics voice: +43-1-4277-51409 > Univ. Wien, Sensengasse 8/12 fax: +43-1-4277-9514 (or 9513) > A-1090 Wien, AUSTRIA cmp.mpi.univie.ac.at > > ------------------------------------------------------------------------------- > ubuntu-11.10 | vim-7.3 | python-3.2.2 | mutt-1.5.21 | elinks-0.12 > > ------------------------------------------------------------------------------- > -- Regards Nikhil Verma +91-958-273-3156 -------------- next part -------------- An HTML attachment was scrubbed... URL: From robert.kern at gmail.com Mon Mar 26 05:50:22 2012 From: robert.kern at gmail.com (Robert Kern) Date: Mon, 26 Mar 2012 10:50:22 +0100 Subject: random number In-Reply-To: References: <20120326064000.GB19865@terra.cms.at> <20120326092403.GB22725@terra.cms.at> Message-ID: On 3/26/12 10:45 AM, Nikhil Verma wrote: > Hi > > Thanks Michael I want exactly wanted this. Great !!!! > def random_number(id) > ... characters = list(string.ascii_lowercase +string.ascii_uppercase > +string.digits) > > I used this this earlier and tried then by using choice . > This is great. Note that the id parameter is not used by the function at all. If you call this function multiple times with the same input, you will get different results each time. Is that what you want? What role did you expect the id parameter to play? > On Mon, Mar 26, 2012 at 2:54 PM, Michael Poeltl > wrote: > It's still not quite clear to me what role 'id' is playing ... so let's > check this one; > and Steven, who is maybe more experienced than I am will help us ufrther > > >>> import random, string > >>> def random_number(id): > ... characters = list(string.ascii_lowercase + > ... string.ascii_uppercase + > ... string.digits) > ... coll_rand = [] > ... for i in range(6): > ... random.shuffle(characters) > ... coll_rand.append(characters[0]) > ... return ''.join(coll_rand) > ... > >>> id = 5 > >>> print (random_number(id)) > puMHCr > >>> -- Robert Kern "I have come to believe that the whole world is an enigma, a harmless enigma that is made terrible by our own mad attempt to interpret it as though it had an underlying truth." -- Umberto Eco From python.list at tim.thechases.com Mon Mar 26 06:14:01 2012 From: python.list at tim.thechases.com (Tim Chase) Date: Mon, 26 Mar 2012 05:14:01 -0500 Subject: Documentation, assignment in expression. In-Reply-To: References: <4f6d0060$0$6634$9b4e6d93@newsspool2.arcor-online.net> <4f6f0d24$0$6561$9b4e6d93@newsspool4.arcor-online.net> <4F6F1792.1060709@tim.thechases.com> <4F6F222F.7050406@tim.thechases.com> Message-ID: <4F704169.6060103@tim.thechases.com> On 03/25/12 17:59, Dennis Lee Bieber wrote: > On Sun, 25 Mar 2012 08:48:31 -0500, Tim Chase >> Yeah, it has the same structure internally, but I'm somewhat >> surprised that the DB connection object doesn't have an >> __iter__() that does something like this automatically under the >> covers. >> > I believe being able to use the connection object directly for > queries is considered a short-cut feature... If you use the longer form > > con = db.connect() > cur = con.cursor() > > the cursor object, in all that I've worked with, does function for > iteration > > for rec in cur: > #do stuff Interesting. Either this is something special for a particular DB back-end, or has been added since I went hunting (back with mxODBC and Python2.4). I wouldn't be surprised if the latter was the case, as my code is nigh identical to yours. conn = db.DriverConnect(connection_string) cursor = conn.cursor() cursor.execute(sql, params) for row in cursor: # in the above 2.4 + mxODBC, this fails process(row) I'd be interested to know the underlying implementation's efficiency, hopefully using .fetchmany() under the hood. My understanding is that the .fetchmany() loop is the best way to do it, as the .fetchone() gets chatty with the DB (but is more efficient if you only need one row from a multi-result query), and the .fetchall() can blow out memory on large datasets. -tkc From kiuhnm03.4t.yahoo.it Mon Mar 26 06:56:30 2012 From: kiuhnm03.4t.yahoo.it (Kiuhnm) Date: Mon, 26 Mar 2012 12:56:30 +0200 Subject: Documentation, assignment in expression. In-Reply-To: References: <4f6d0060$0$6634$9b4e6d93@newsspool2.arcor-online.net> <4f6f0d24$0$6561$9b4e6d93@newsspool4.arcor-online.net> <4F6F1792.1060709@tim.thechases.com> <4f6f36bf$0$1390$4fafbaef@reader2.news.tin.it> Message-ID: <4f704b5e$0$1389$4fafbaef@reader2.news.tin.it> On 3/26/2012 10:52, Devin Jeanpierre wrote: > On Sun, Mar 25, 2012 at 11:16 AM, Kiuhnm > wrote: >> On 3/25/2012 15:48, Tim Chase wrote: >>> >>> The old curmudgeon in me likes the Pascal method of using "=" for >>> equality-testing, and ":=" for assignment which feels a little closer to >>> mathematical use of "=". >> >> >> Unfortunately, ":=" means "is defined as" in mathematics. The "right" >> operator would have been "<-". > > > "Is defined as" is actually pretty reasonable. "Define this to be > that" is a common way to speak about assignment. Its only difference > is the present tense. For example, in Python, "def" stands for > "define", but we can overwrite previous definitions:: > > def f(x): return x > def f(x): return 2 > f(3) == 2 > > In fact, in pretty every programming language that I know of with a > "define" assignment verb, this is so. For example, in Scheme, x is 2 > at the end:: > > (define x 1) > (define x 2) > x When you write (define x 1) (define x 2) x or, in F# and OCaml, let x = 1 let x = 2 x you're saying x = 1 { x = 2 x } You don't modify 'x': you hide it by defining another "value" (not variable) with the same name. Indeed, let x = 1 let x = 2 x is shorthand for let x = 1 in let x = 2 in x Kiuhnm From jpiitula at ling.helsinki.fi Mon Mar 26 07:13:48 2012 From: jpiitula at ling.helsinki.fi (Jussi Piitulainen) Date: 26 Mar 2012 14:13:48 +0300 Subject: Documentation, assignment in expression. References: <4f6d0060$0$6634$9b4e6d93@newsspool2.arcor-online.net> <4f6f0d24$0$6561$9b4e6d93@newsspool4.arcor-online.net> <4F6F1792.1060709@tim.thechases.com> <4f6f36bf$0$1390$4fafbaef@reader2.news.tin.it> <4f704b5e$0$1389$4fafbaef@reader2.news.tin.it> Message-ID: Kiuhnm writes: > On 3/26/2012 10:52, Devin Jeanpierre wrote: > > On Sun, Mar 25, 2012 at 11:16 AM, Kiuhnm > > wrote: > >> On 3/25/2012 15:48, Tim Chase wrote: > >>> > >>> The old curmudgeon in me likes the Pascal method of using "=" for > >>> equality-testing, and ":=" for assignment which feels a little closer to > >>> mathematical use of "=". > >> > >> > >> Unfortunately, ":=" means "is defined as" in mathematics. The "right" > >> operator would have been "<-". > > > > > > "Is defined as" is actually pretty reasonable. "Define this to be > > that" is a common way to speak about assignment. Its only difference > > is the present tense. For example, in Python, "def" stands for > > "define", but we can overwrite previous definitions:: > > > > def f(x): return x > > def f(x): return 2 > > f(3) == 2 > > > > In fact, in pretty every programming language that I know of with a > > "define" assignment verb, this is so. For example, in Scheme, x is 2 > > at the end:: > > > > (define x 1) > > (define x 2) > > x > > When you write > (define x 1) > (define x 2) > x > or, in F# and OCaml, > let x = 1 > let x = 2 > x > you're saying > x = 1 > { > x = 2 > x > } > You don't modify 'x': you hide it by defining another "value" (not > variable) with the same name. > Indeed, > let x = 1 > let x = 2 > x > is shorthand for > let x = 1 in > let x = 2 in > x No, Devin is right about Scheme. On "top level" re-definition is interpreted as assignment. The following mean the same: (define x 1) (define x 2) x (define x 1) (set! x 2) x Local definitions in the beginning of a "body" do not allow duplicate names at all. The following mean the same: (let () (define x 1) (define y 2) x) (letrec* ((x 1) (y 2)) x) ;letrec in older versions (not sure of R6RS) But (let () (define x 1) (define x 2) x) is still an error. Some implementations may give it a meaning. Not sure. From mwilson at the-wire.com Mon Mar 26 07:27:15 2012 From: mwilson at the-wire.com (mwilson at the-wire.com) Date: Mon, 26 Mar 2012 07:27:15 -0400 Subject: Documentation, assignment in expression. References: <4f6d0060$0$6634$9b4e6d93@newsspool2.arcor-online.net> <4f6f0d24$0$6561$9b4e6d93@newsspool4.arcor-online.net> <4F6F1792.1060709@tim.thechases.com> Message-ID: Dennis Lee Bieber wrote: > On Sun, 25 Mar 2012 19:09:12 -0400, mwilson at the-wire.com declaimed the > following in gmane.comp.python.general: > > >> Most of my database programs wind up having the boilerplate (not tested): >> >> def rowsof (cursor): >> names = [x[0] for x in cursor.description] >> r = cursor.fetchone() >> while r: >> yield dict (zip (names, r)) >> r = cursor.fetchone() >> > > In my (limited) experience, the main loop above could be replaced > with: > > for r in cursor: > yield dict(zip(names, r)) I think your experience is more recent than mine. I'll change my boilerplate next time around. Mel. From redstone-cold at 163.com Mon Mar 26 07:45:26 2012 From: redstone-cold at 163.com (redstone-cold at 163.com) Date: Mon, 26 Mar 2012 04:45:26 -0700 (PDT) Subject: Is there any difference between print 3 and print '3' in Python ? Message-ID: <5128580.32.1332762326119.JavaMail.geo-discussion-forums@pbom7> I know the print statement produces the same result when both of these two instructions are executed ,I just want to know Is there any difference between print 3 and print '3' in Python ? From kiuhnm03.4t.yahoo.it Mon Mar 26 07:45:45 2012 From: kiuhnm03.4t.yahoo.it (Kiuhnm) Date: Mon, 26 Mar 2012 13:45:45 +0200 Subject: Stream programming In-Reply-To: References: <4f6c9e17$0$1383$4fafbaef@reader2.news.tin.it> Message-ID: <4f7056e8$0$1375$4fafbaef@reader1.news.tin.it> On 3/26/2012 11:27, Jean-Michel Pichavant wrote: > Kiuhnm wrote: >> [snip] >> >> numbers - push - avrg - 'med' - pop - filter(lt('med'), ge('med'))\ >> - ['same', 'same'] - streams(cat) - 'same' >> >> It reads as >> >> "take a list of numbers - save it - compute the average and named it >> 'med' - restore the flow - create two streams which have, respect., >> the numbers less than 'med' and those greater or equal to 'med' - do >> the /entire/ 'same' process on each one of the two streams - concat >> the resulting streams - name all this /entire/ process 'same'. >> Not readable enough? Replace 'same' with 'qsort'. >> >> Is that readable or am I going crazy? [note: that's a rhetorical >> question whose answer is "That's very readable!"] >> >> Kiuhnm > > Here's a rhetorical answer to your question : whatever you're taking, I > want some ! LOL. I should have titled my post "A new obfuscation technique" then :) Kiuhnm From andre.roberge at gmail.com Mon Mar 26 07:47:13 2012 From: andre.roberge at gmail.com (=?ISO-8859-1?Q?Andr=E9_Roberge?=) Date: Mon, 26 Mar 2012 04:47:13 -0700 (PDT) Subject: Puzzled by FiPy's use of "==" Message-ID: <24963904.2261.1332762433787.JavaMail.geo-discussion-forums@vbbfw10> In FiPy (a finite volume PDE solver), equations are "magically" set up as eqX = TransientTerm() == ExplicitDiffusionTerm(coeff=D) and solved via eqX.solve(...) How can eqX be anything than True or False?... This must be via a redefinition of "==" but I can't see how that is done. I did look at many of the source files, thinking that it must be via a redefinition of "__eq__" somewhere but with no luck. Any pointers would be appreciated. From kiuhnm03.4t.yahoo.it Mon Mar 26 07:58:25 2012 From: kiuhnm03.4t.yahoo.it (Kiuhnm) Date: Mon, 26 Mar 2012 13:58:25 +0200 Subject: Documentation, assignment in expression. In-Reply-To: References: <4f6d0060$0$6634$9b4e6d93@newsspool2.arcor-online.net> <4f6f0d24$0$6561$9b4e6d93@newsspool4.arcor-online.net> <4F6F1792.1060709@tim.thechases.com> <4f6f36bf$0$1390$4fafbaef@reader2.news.tin.it> <4f704b5e$0$1389$4fafbaef@reader2.news.tin.it> Message-ID: <4f7059e1$0$1390$4fafbaef@reader2.news.tin.it> On 3/26/2012 13:13, Jussi Piitulainen wrote: > Kiuhnm writes: >> On 3/26/2012 10:52, Devin Jeanpierre wrote: >>> On Sun, Mar 25, 2012 at 11:16 AM, Kiuhnm >>> wrote: >>>> On 3/25/2012 15:48, Tim Chase wrote: >>>>> >>>>> The old curmudgeon in me likes the Pascal method of using "=" for >>>>> equality-testing, and ":=" for assignment which feels a little closer to >>>>> mathematical use of "=". >>>> >>>> >>>> Unfortunately, ":=" means "is defined as" in mathematics. The "right" >>>> operator would have been "<-". >>> >>> >>> "Is defined as" is actually pretty reasonable. "Define this to be >>> that" is a common way to speak about assignment. Its only difference >>> is the present tense. For example, in Python, "def" stands for >>> "define", but we can overwrite previous definitions:: >>> >>> def f(x): return x >>> def f(x): return 2 >>> f(3) == 2 >>> >>> In fact, in pretty every programming language that I know of with a >>> "define" assignment verb, this is so. For example, in Scheme, x is 2 >>> at the end:: >>> >>> (define x 1) >>> (define x 2) >>> x >> >> When you write >> (define x 1) >> (define x 2) >> x >> or, in F# and OCaml, >> let x = 1 >> let x = 2 >> x >> you're saying >> x = 1 >> { >> x = 2 >> x >> } >> You don't modify 'x': you hide it by defining another "value" (not >> variable) with the same name. >> Indeed, >> let x = 1 >> let x = 2 >> x >> is shorthand for >> let x = 1 in >> let x = 2 in >> x > > No, Devin is right about Scheme. On "top level" re-definition is > interpreted as assignment. The following mean the same: > > (define x 1) (define x 2) x > (define x 1) (set! x 2) x > > Local definitions in the beginning of a "body" do not allow duplicate > names at all. The following mean the same: > > (let () (define x 1) (define y 2) x) > (letrec* ((x 1) (y 2)) x) ;letrec in older versions (not sure of R6RS) > > But (let () (define x 1) (define x 2) x) is still an error. Some > implementations may give it a meaning. Not sure. Thanks for the correction. I haven't written a line of code in Scheme for 15 years and it shows :( Kiuhnm From rosuav at gmail.com Mon Mar 26 08:01:40 2012 From: rosuav at gmail.com (Chris Angelico) Date: Mon, 26 Mar 2012 23:01:40 +1100 Subject: Is there any difference between print 3 and print '3' in Python ? In-Reply-To: <5128580.32.1332762326119.JavaMail.geo-discussion-forums@pbom7> References: <5128580.32.1332762326119.JavaMail.geo-discussion-forums@pbom7> Message-ID: On Mon, Mar 26, 2012 at 10:45 PM, wrote: > I know the print statement produces the same result when both of these two instructions are executed ,I just want to know Is there any difference between print 3 and print '3' in Python ? One of them takes the integer 3, converts it into a string, and prints it. The other takes the string '3' and prints it. There's a lot of difference under the covers, but both will print a 3, followed by a newline. ChrisA From kiuhnm03.4t.yahoo.it Mon Mar 26 08:07:10 2012 From: kiuhnm03.4t.yahoo.it (Kiuhnm) Date: Mon, 26 Mar 2012 14:07:10 +0200 Subject: Is there any difference between print 3 and print '3' in Python ? In-Reply-To: <5128580.32.1332762326119.JavaMail.geo-discussion-forums@pbom7> References: <5128580.32.1332762326119.JavaMail.geo-discussion-forums@pbom7> Message-ID: <4f705bf1$0$1385$4fafbaef@reader2.news.tin.it> On 3/26/2012 13:45, redstone-cold at 163.com wrote: > I know the print statement produces the same result when both of > these two instructions are executed ,I just want to know Is there any > difference between print 3 and print '3' in Python ? The former prints a number while the latter a string. Kiuhnm From robert.kern at gmail.com Mon Mar 26 08:10:55 2012 From: robert.kern at gmail.com (Robert Kern) Date: Mon, 26 Mar 2012 13:10:55 +0100 Subject: Is there any difference between print 3 and print '3' in Python ? In-Reply-To: <5128580.32.1332762326119.JavaMail.geo-discussion-forums@pbom7> References: <5128580.32.1332762326119.JavaMail.geo-discussion-forums@pbom7> Message-ID: On 3/26/12 12:45 PM, redstone-cold at 163.com wrote: > I know the print statement produces the same result when both of these two instructions are executed ,I just want to know Is there any difference between print 3 and print '3' in Python ? Yes, there is a difference, but not much. [~] |6> import dis [~] |7> dis.disassemble(compile('print 3', '', 'exec')) 1 0 LOAD_CONST 0 (3) 3 PRINT_ITEM 4 PRINT_NEWLINE 5 LOAD_CONST 1 (None) 8 RETURN_VALUE [~] |8> dis.disassemble(compile('print "3"', '', 'exec')) 1 0 LOAD_CONST 0 ('3') 3 PRINT_ITEM 4 PRINT_NEWLINE 5 LOAD_CONST 1 (None) 8 RETURN_VALUE As you can see, the only difference is in the first instruction. Both of these put the object that you specified by the literal onto the stack. The difference is that one is the int object specified by the literal 3 and the other is the str object specified by the literal "3". Both of these objects happen to give the same __str__ output, so that's what gets printed. -- Robert Kern "I have come to believe that the whole world is an enigma, a harmless enigma that is made terrible by our own mad attempt to interpret it as though it had an underlying truth." -- Umberto Eco From d at davea.name Mon Mar 26 08:11:03 2012 From: d at davea.name (Dave Angel) Date: Mon, 26 Mar 2012 08:11:03 -0400 Subject: Is there any difference between print 3 and print '3' in Python ? In-Reply-To: <5128580.32.1332762326119.JavaMail.geo-discussion-forums@pbom7> References: <5128580.32.1332762326119.JavaMail.geo-discussion-forums@pbom7> Message-ID: <4F705CD7.7@davea.name> On 03/26/2012 07:45 AM, redstone-cold at 163.com wrote: > I know the print statement produces the same result when both of these two instructions are executed ,I just want to know Is there any difference between print 3 and print '3' in Python ? This is a non-question. The input is the same, the output is the same, what else matters? On the other hand, if you want to dig deeper, there are lots of differences: 1) the former has a shorter source file 2) different C code is utilized inside the interpreter 3) different machine code executes 4) the temporary objects created have different id's and types 5) different execution times (by a trivial amount) 6) it takes different keystrokes to edit the two source files once you want to make it do something useful 7) the processor works a little harder on one than the other, possibly resulting in a different power consumption 8) different byte code is produced Or you could be asking about Python version 3, in which case 1) the syntax error message points to a different character -- DaveA From robert.kern at gmail.com Mon Mar 26 08:16:07 2012 From: robert.kern at gmail.com (Robert Kern) Date: Mon, 26 Mar 2012 13:16:07 +0100 Subject: Puzzled by FiPy's use of "==" In-Reply-To: <24963904.2261.1332762433787.JavaMail.geo-discussion-forums@vbbfw10> References: <24963904.2261.1332762433787.JavaMail.geo-discussion-forums@vbbfw10> Message-ID: On 3/26/12 12:47 PM, Andr? Roberge wrote: > In FiPy (a finite volume PDE solver), equations are "magically" set up as > > eqX = TransientTerm() == ExplicitDiffusionTerm(coeff=D) > > and solved via > > eqX.solve(...) > > How can eqX be anything than True or False?... This must be via a redefinition of "==" but I can't see how that is done. I did look at many of the source files, thinking that it must be via a redefinition of "__eq__" somewhere but with no luck. Any pointers would be appreciated. It's in the root base class Term: http://matforge.org/fipy/browser/trunk/fipy/terms/term.py#L374 -- Robert Kern "I have come to believe that the whole world is an enigma, a harmless enigma that is made terrible by our own mad attempt to interpret it as though it had an underlying truth." -- Umberto Eco From andre.roberge at gmail.com Mon Mar 26 08:21:58 2012 From: andre.roberge at gmail.com (=?ISO-8859-1?Q?Andr=E9_Roberge?=) Date: Mon, 26 Mar 2012 05:21:58 -0700 (PDT) Subject: Puzzled by FiPy's use of "==" In-Reply-To: References: <24963904.2261.1332762433787.JavaMail.geo-discussion-forums@vbbfw10> Message-ID: <22079866.1390.1332764518212.JavaMail.geo-discussion-forums@vbmf37> On Monday, 26 March 2012 09:16:07 UTC-3, Robert Kern wrote: > On 3/26/12 12:47 PM, Andr? Roberge wrote: > > In FiPy (a finite volume PDE solver), equations are "magically" set up as > > > > eqX = TransientTerm() == ExplicitDiffusionTerm(coeff=D) > > > > and solved via > > > > eqX.solve(...) > > > > How can eqX be anything than True or False?... This must be via a redefinition of "==" but I can't see how that is done. I did look at many of the source files, thinking that it must be via a redefinition of "__eq__" somewhere but with no luck. Any pointers would be appreciated. > > It's in the root base class Term: > > http://matforge.org/fipy/browser/trunk/fipy/terms/term.py#L374 > I thought I looked at terms.py ... but I must have missed that. Thanks! > -- > Robert Kern > > "I have come to believe that the whole world is an enigma, a harmless enigma > that is made terrible by our own mad attempt to interpret it as though it had > an underlying truth." > -- Umberto Eco From andre.roberge at gmail.com Mon Mar 26 08:21:58 2012 From: andre.roberge at gmail.com (=?ISO-8859-1?Q?Andr=E9_Roberge?=) Date: Mon, 26 Mar 2012 05:21:58 -0700 (PDT) Subject: Puzzled by FiPy's use of "==" In-Reply-To: References: <24963904.2261.1332762433787.JavaMail.geo-discussion-forums@vbbfw10> Message-ID: <22079866.1390.1332764518212.JavaMail.geo-discussion-forums@vbmf37> On Monday, 26 March 2012 09:16:07 UTC-3, Robert Kern wrote: > On 3/26/12 12:47 PM, Andr? Roberge wrote: > > In FiPy (a finite volume PDE solver), equations are "magically" set up as > > > > eqX = TransientTerm() == ExplicitDiffusionTerm(coeff=D) > > > > and solved via > > > > eqX.solve(...) > > > > How can eqX be anything than True or False?... This must be via a redefinition of "==" but I can't see how that is done. I did look at many of the source files, thinking that it must be via a redefinition of "__eq__" somewhere but with no luck. Any pointers would be appreciated. > > It's in the root base class Term: > > http://matforge.org/fipy/browser/trunk/fipy/terms/term.py#L374 > I thought I looked at terms.py ... but I must have missed that. Thanks! > -- > Robert Kern > > "I have come to believe that the whole world is an enigma, a harmless enigma > that is made terrible by our own mad attempt to interpret it as though it had > an underlying truth." > -- Umberto Eco From jeanmichel at sequans.com Mon Mar 26 08:36:19 2012 From: jeanmichel at sequans.com (Jean-Michel Pichavant) Date: Mon, 26 Mar 2012 14:36:19 +0200 Subject: verbs in comments [OT] In-Reply-To: <4f6e2265$0$1382$4fafbaef@reader2.news.tin.it> References: <4f6e2265$0$1382$4fafbaef@reader2.news.tin.it> Message-ID: <4F7062C3.8080004@sequans.com> Kiuhnm wrote: > Why do you write > // Print the number of words... > def printNumWords(): ... > and not > // Prints the number of words... > def printNumWords(): ... > where "it" is understood? > Is that an imperative or a base form or something else? > > Kiuhnm http://www.python.org/dev/peps/pep-0257/ "The docstring is a phrase ending in a period. It prescribes the function or method's effect as a command ("Do this", "Return that"), not as a description; e.g. don't write "Returns the pathname ..." I apply the same rule to comments, I now don't loose time asking myself how to write these docs/comments. JM From akghosh3 at gmail.com Mon Mar 26 08:52:26 2012 From: akghosh3 at gmail.com (Aloke Ghosh) Date: Mon, 26 Mar 2012 18:22:26 +0530 Subject: help needed to understand an error message. In-Reply-To: References: Message-ID: Hi, I am learning Python and do not have programming experience. I was following an exercise from http://learnpythonthehardway.org/book/ex2.html and made a mistake in entry : *Print"I like typing this."* and got the following error message: *In [2]: Print"I like typing this."* *------------------------------------------------------------* * File "", line 1* * Print"I like typing this."* * ^* *SyntaxError: invalid syntax* I feel the error is in Capital P in print . However the error indicated with "*^*" hints at quote at the end of the line. *Can any one please help me understand this.* -- A.K.Ghosh -------------- next part -------------- An HTML attachment was scrubbed... URL: From jeanmichel at sequans.com Mon Mar 26 09:26:24 2012 From: jeanmichel at sequans.com (Jean-Michel Pichavant) Date: Mon, 26 Mar 2012 15:26:24 +0200 Subject: help needed to understand an error message. In-Reply-To: References: Message-ID: <4F706E80.7090809@sequans.com> Aloke Ghosh wrote: > Hi, > I am learning Python and do not have programming experience. > I was following > an exercise from http://learnpythonthehardway.org/book/ex2.html > and made a mistake in entry : > > *Print"I like typing this."* > > and got the following error message: > > *In [2]: Print"I like typing this."* > *------------------------------------------------------------* > * File "", line 1* > * Print"I like typing this."* > * ^* > *SyntaxError: invalid syntax* > > I feel the error is in Capital P in print . > However the error indicated with "*^*" > hints at quote at the end of the line. > > *Can any one please help me understand this.* > > -- > A.K.Ghosh Why don't you just try with a lowercase p ? The correct syntax would be print "I like typing this" or in Python 3: print ("I like typing this") Anyway, the hint indicates the last quote because this is the location where the python interpreter realizes it won't be able to execute the code. You should not worry about that too much. JM From steveo at syslang.net Mon Mar 26 09:33:28 2012 From: steveo at syslang.net (Steven W. Orr) Date: Mon, 26 Mar 2012 09:33:28 -0400 Subject: Question about collections.defaultdict Message-ID: <4F707028.4000407@syslang.net> I created a new class called CaseInsensitiveDict (by stealing from code I found on the web, thank you very much). The new class inherits from dict. It makes it so that if the key has a 'lower' method, it will always access the key using lower I'd like to change the place where I previously declared a dict self.lookup = defaultdict(list) so that the new code will allow this new dict to be used instead. But then I realized I may have painted myself into a small corner: Is there a way to use defaultdict so that I can override what *kind* of dict it will use? I would like the value to still be a list be default, but it seems like I can't tell defaultdict to use *my* new dict. Do I give up on defaultdict? BTW, 2.6 if it matters. TIA :-) -- Time flies like the wind. Fruit flies like a banana. Stranger things have .0. happened but none stranger than this. Does your driver's license say Organ ..0 Donor?Black holes are where God divided by zero. Listen to me! We are all- 000 individuals! What if this weren't a hypothetical question? steveo at syslang.net From robert.kern at gmail.com Mon Mar 26 09:44:51 2012 From: robert.kern at gmail.com (Robert Kern) Date: Mon, 26 Mar 2012 14:44:51 +0100 Subject: Question about collections.defaultdict In-Reply-To: <4F707028.4000407@syslang.net> References: <4F707028.4000407@syslang.net> Message-ID: On 3/26/12 2:33 PM, Steven W. Orr wrote: > I created a new class called CaseInsensitiveDict (by stealing from code I found > on the web, thank you very much). The new class inherits from dict. It makes it > so that if the key has a 'lower' method, it will always access the key using lower > > I'd like to change the place where I previously declared a dict > > self.lookup = defaultdict(list) > > so that the new code will allow this new dict to be used instead. But then I > realized I may have painted myself into a small corner: > > Is there a way to use defaultdict so that I can override what *kind* of dict it > will use? No. > I would like the value to still be a list be default, but it seems like I can't > tell defaultdict to use *my* new dict. > > Do I give up on defaultdict? Assuming that your CaseInsensitiveDict subclasses from dict or UserDict, it's relatively easy to make a subclass of your CaseInsensitiveDict act like a defaultdict. Just implement the __missing__(key) method appropriately (and modify the constructor to take the callable, of course). http://docs.python.org/library/stdtypes.html#dict http://docs.python.org/library/collections.html#collections.defaultdict.__missing__ -- Robert Kern "I have come to believe that the whole world is an enigma, a harmless enigma that is made terrible by our own mad attempt to interpret it as though it had an underlying truth." -- Umberto Eco From nutznetz-0c1b6768-bfa9-48d5-a470-7603bd3aa915 at spamschutz.glglgl.de Mon Mar 26 09:54:52 2012 From: nutznetz-0c1b6768-bfa9-48d5-a470-7603bd3aa915 at spamschutz.glglgl.de (Thomas Rachel) Date: Mon, 26 Mar 2012 15:54:52 +0200 Subject: Documentation, assignment in expression. In-Reply-To: References: <4f6d0060$0$6634$9b4e6d93@newsspool2.arcor-online.net> <4f6f0d24$0$6561$9b4e6d93@newsspool4.arcor-online.net> <4F6F1792.1060709@tim.thechases.com> <4F6F222F.7050406@tim.thechases.com> Message-ID: Am 26.03.2012 00:59 schrieb Dennis Lee Bieber: > If you use the longer form > > con = db.connect() > cur = con.cursor() > > the cursor object, in all that I've worked with, does function for > iteration I use this form regularly with MySQLdb and am now surprised to see that this is optional according to http://www.python.org/dev/peps/pep-0249/. So a database cursor is not required to be iterable, alas. Thomas From ian.douglas at iandouglas.com Mon Mar 26 09:55:21 2012 From: ian.douglas at iandouglas.com (ian douglas) Date: Mon, 26 Mar 2012 06:55:21 -0700 Subject: random number In-Reply-To: <4f7019b6$0$29968$c3e8da3$5496439d@news.astraweb.com> References: <4f7019b6$0$29968$c3e8da3$5496439d@news.astraweb.com> Message-ID: On Mar 26, 2012 12:28 AM, "Steven D'Aprano" < steve+comp.lang.python at pearwood.info> wrote: > > On Mon, 26 Mar 2012 08:40:00 +0200, Michael Poeltl wrote: > > > * Nikhil Verma [2012-03-26 08:09]: > A truly random six digit number will include any number between 100000 > through 999999. There are exactly 900000 (nine hundred thousand) such > numbers. Actually, considering that 000000 would still fit the parameter of a 6 "digit" number, there are exactly one million such numbers. -------------- next part -------------- An HTML attachment was scrubbed... URL: From nutznetz-0c1b6768-bfa9-48d5-a470-7603bd3aa915 at spamschutz.glglgl.de Mon Mar 26 09:59:08 2012 From: nutznetz-0c1b6768-bfa9-48d5-a470-7603bd3aa915 at spamschutz.glglgl.de (Thomas Rachel) Date: Mon, 26 Mar 2012 15:59:08 +0200 Subject: Documentation, assignment in expression. In-Reply-To: References: <4f6d0060$0$6634$9b4e6d93@newsspool2.arcor-online.net> <4f6f0d24$0$6561$9b4e6d93@newsspool4.arcor-online.net> Message-ID: Am 25.03.2012 15:03 schrieb Tim Chase: > Perhaps a DB example > works better. With assignment allowed in an evaluation, you'd be able to > write > > while data = conn.fetchmany(): > for row in data: > process(row) > > whereas you have to write > > while True: > data = conn.fetchmany() > if not data: break > for row in data: > process(row) Or simpler for data in iter(conn.fetchmany, []): for row in data: process(row) provided that a block of rows is returned as a list - which might be different among DB engines. Thomas From redstone-cold at 163.com Mon Mar 26 10:28:25 2012 From: redstone-cold at 163.com (redstone-cold at 163.com) Date: Mon, 26 Mar 2012 07:28:25 -0700 (PDT) Subject: Is there any difference between print 3 and print '3' in Python ? In-Reply-To: References: <5128580.32.1332762326119.JavaMail.geo-discussion-forums@pbom7> Message-ID: <9916924.0.1332772105737.JavaMail.geo-discussion-forums@pbbls7> ? 2012?3?26????UTC+8??8?11?03??Dave Angel??? > On 03/26/2012 07:45 AM, redstone-cold at 163.com wrote: > > I know the print statement produces the same result when both of these two instructions are executed ,I just want to know Is there any difference between print 3 and print '3' in Python ? > > This is a non-question. The input is the same, the output is the same, > what else matters? > > On the other hand, if you want to dig deeper, there are lots of differences: > > 1) the former has a shorter source file > 2) different C code is utilized inside the interpreter > 3) different machine code executes > 4) the temporary objects created have different id's and types > 5) different execution times (by a trivial amount) > 6) it takes different keystrokes to edit the two source files once you > want to make it do something useful > 7) the processor works a little harder on one than the other, possibly > resulting in a different power consumption > 8) different byte code is produced > > Or you could be asking about Python version 3, in which case > 1) the syntax error message points to a different character > > -- > > DaveA ? 2012?3?26????UTC+8??8?11?03??Dave Angel??? > On 03/26/2012 07:45 AM, redstone-cold at 163.com wrote: > > I know the print statement produces the same result when both of these two instructions are executed ,I just want to know Is there any difference between print 3 and print '3' in Python ? > > This is a non-question. The input is the same, the output is the same, > what else matters? > > On the other hand, if you want to dig deeper, there are lots of differences: > > 1) the former has a shorter source file > 2) different C code is utilized inside the interpreter > 3) different machine code executes > 4) the temporary objects created have different id's and types > 5) different execution times (by a trivial amount) > 6) it takes different keystrokes to edit the two source files once you > want to make it do something useful > 7) the processor works a little harder on one than the other, possibly > resulting in a different power consumption > 8) different byte code is produced > > Or you could be asking about Python version 3, in which case > 1) the syntax error message points to a different character > > -- > > DaveA Oh ,God ! I think this is what I really want to know ,thank you very much ! From redstone-cold at 163.com Mon Mar 26 10:28:25 2012 From: redstone-cold at 163.com (redstone-cold at 163.com) Date: Mon, 26 Mar 2012 07:28:25 -0700 (PDT) Subject: Is there any difference between print 3 and print '3' in Python ? In-Reply-To: References: <5128580.32.1332762326119.JavaMail.geo-discussion-forums@pbom7> Message-ID: <9916924.0.1332772105737.JavaMail.geo-discussion-forums@pbbls7> ? 2012?3?26????UTC+8??8?11?03??Dave Angel??? > On 03/26/2012 07:45 AM, redstone-cold at 163.com wrote: > > I know the print statement produces the same result when both of these two instructions are executed ,I just want to know Is there any difference between print 3 and print '3' in Python ? > > This is a non-question. The input is the same, the output is the same, > what else matters? > > On the other hand, if you want to dig deeper, there are lots of differences: > > 1) the former has a shorter source file > 2) different C code is utilized inside the interpreter > 3) different machine code executes > 4) the temporary objects created have different id's and types > 5) different execution times (by a trivial amount) > 6) it takes different keystrokes to edit the two source files once you > want to make it do something useful > 7) the processor works a little harder on one than the other, possibly > resulting in a different power consumption > 8) different byte code is produced > > Or you could be asking about Python version 3, in which case > 1) the syntax error message points to a different character > > -- > > DaveA ? 2012?3?26????UTC+8??8?11?03??Dave Angel??? > On 03/26/2012 07:45 AM, redstone-cold at 163.com wrote: > > I know the print statement produces the same result when both of these two instructions are executed ,I just want to know Is there any difference between print 3 and print '3' in Python ? > > This is a non-question. The input is the same, the output is the same, > what else matters? > > On the other hand, if you want to dig deeper, there are lots of differences: > > 1) the former has a shorter source file > 2) different C code is utilized inside the interpreter > 3) different machine code executes > 4) the temporary objects created have different id's and types > 5) different execution times (by a trivial amount) > 6) it takes different keystrokes to edit the two source files once you > want to make it do something useful > 7) the processor works a little harder on one than the other, possibly > resulting in a different power consumption > 8) different byte code is produced > > Or you could be asking about Python version 3, in which case > 1) the syntax error message points to a different character > > -- > > DaveA Oh ,God ! I think this is what I really want to know ,thank you very much ! From 3beezer at gmail.com Mon Mar 26 10:41:37 2012 From: 3beezer at gmail.com (jeff) Date: Mon, 26 Mar 2012 07:41:37 -0700 (PDT) Subject: Inconsistency between os.getgroups and os.system('groups') after os.setgroups() In-Reply-To: <87ty1cgqj1.fsf@benfinney.id.au> References: <19158239.1073.1332711120749.JavaMail.geo-discussion-forums@ynlx41> <7418918.681.1332718439318.JavaMail.geo-discussion-forums@yneo2> <87ty1cgqj1.fsf@benfinney.id.au> Message-ID: <1229886.3.1332772897822.JavaMail.geo-discussion-forums@ynbp21> On Sunday, March 25, 2012 6:22:10 PM UTC-6, Ben Finney wrote: > jeff writes: > > > On Sunday, March 25, 2012 4:04:55 PM UTC-6, Heiko Wundram wrote: > > > Am 25.03.2012 23:32, schrieb jeff: > > > > but I have to be able to get back to root privilege so I can't use > > > > setgid and setuid. > > > > > > Simply not possible (i.e., you can't drop root privileges, be it by > > > setuid()/setgid() or removing yourself from groups with setgroups()), > > > and later reacquire them _in the same process_. See the discussion of > > > how to implement privilege separation at > > > > > > http://www.citi.umich.edu/u/provos/ssh/privsep.html > > > > os.system("su -m -c ''") > > > > seems to do the trick. > > Yes, because ?os.system? explicitly starts a new process. > > It can't be done in the same process, as Heiko correctly said. > > -- > \ ?Faith, n. Belief without evidence in what is told by one who | > `\ speaks without knowledge, of things without parallel.? ?Ambrose | > _o__) Bierce, _The Devil's Dictionary_, 1906 | > Ben Finney I didn't ask how to do it in the same process, but thanks to both of you for that information. By the way, are you guys aware of seteuid and setegid? From colton.myers at gmail.com Mon Mar 26 10:43:59 2012 From: colton.myers at gmail.com (Colton Myers) Date: Mon, 26 Mar 2012 08:43:59 -0600 Subject: Is there any difference between print 3 and print '3' in Python ? In-Reply-To: <5128580.32.1332762326119.JavaMail.geo-discussion-forums@pbom7> References: <5128580.32.1332762326119.JavaMail.geo-discussion-forums@pbom7> Message-ID: > I know the print statement produces the same result when both of these two instructions are executed ,I just want to know Is there any difference between print 3 and print '3' in Python ? Sure there is. The first converts the integer 3 to a string ("3"), the second just prints the given string "3". Does that make sense? -- Colton Myers -------------- next part -------------- An HTML attachment was scrubbed... URL: From stefan_ml at behnel.de Mon Mar 26 11:03:21 2012 From: stefan_ml at behnel.de (Stefan Behnel) Date: Mon, 26 Mar 2012 17:03:21 +0200 Subject: Is there any difference between print 3 and print '3' in Python ? In-Reply-To: <9916924.0.1332772105737.JavaMail.geo-discussion-forums@pbbls7> References: <5128580.32.1332762326119.JavaMail.geo-discussion-forums@pbom7> <9916924.0.1332772105737.JavaMail.geo-discussion-forums@pbbls7> Message-ID: redstone-cold at 163.com, 26.03.2012 16:28: > ? 2012?3?26????UTC+8??8?11?03??Dave Angel??? >> On 03/26/2012 07:45 AM, redstone-cold at 163.com wrote: >>> I know the print statement produces the same result when both of these two instructions are executed ,I just want to know Is there any difference between print 3 and print '3' in Python ? >> >> This is a non-question. The input is the same, the output is the same, >> what else matters? >> >> On the other hand, if you want to dig deeper, there are lots of differences: >> >> 1) the former has a shorter source file >> 2) different C code is utilized inside the interpreter >> 3) different machine code executes >> 4) the temporary objects created have different id's and types >> 5) different execution times (by a trivial amount) >> 6) it takes different keystrokes to edit the two source files once you >> want to make it do something useful >> 7) the processor works a little harder on one than the other, possibly >> resulting in a different power consumption >> 8) different byte code is produced >> >> Or you could be asking about Python version 3, in which case >> 1) the syntax error message points to a different character > > Oh ,God ! I don't think she takes any responsibility for the list above. Stefan From steveo at syslang.net Mon Mar 26 11:33:32 2012 From: steveo at syslang.net (Steven W. Orr) Date: Mon, 26 Mar 2012 11:33:32 -0400 Subject: Question about collections.defaultdict In-Reply-To: References: <4F707028.4000407@syslang.net> Message-ID: <4F708C4C.5050700@syslang.net> On 3/26/2012 9:44 AM, Robert Kern wrote: > On 3/26/12 2:33 PM, Steven W. Orr wrote: >> I created a new class called CaseInsensitiveDict (by stealing from code I found >> on the web, thank you very much). The new class inherits from dict. It makes it >> so that if the key has a 'lower' method, it will always access the key using >> lower >> >> I'd like to change the place where I previously declared a dict >> >> self.lookup = defaultdict(list) >> >> so that the new code will allow this new dict to be used instead. But then I >> realized I may have painted myself into a small corner: >> >> Is there a way to use defaultdict so that I can override what *kind* of dict it >> will use? > > No. > >> I would like the value to still be a list be default, but it seems like I can't >> tell defaultdict to use *my* new dict. >> >> Do I give up on defaultdict? > > Assuming that your CaseInsensitiveDict subclasses from dict or UserDict, it's > relatively easy to make a subclass of your CaseInsensitiveDict act like a > defaultdict. Just implement the __missing__(key) method appropriately (and > modify the constructor to take the callable, of course). > > http://docs.python.org/library/stdtypes.html#dict > http://docs.python.org/library/collections.html#collections.defaultdict.__missing__ > > I'm not quite getting what you're telling me, but I'm sure you have the right idea. Here's the beginning of my class: class CaseInsensitiveDict(dict): def __init__(self, init=None): if isinstance(init, (dict, list, tuple)): for kk, vv in init.items(): self[self.key_has_lower(kk)] = vv It sounds like you want me to subclass defaultdict to create something like this? class CaseInsensitiveDictDef(defaultdict): def __init__(self, init=None): super(CaseInsensitiveDictDef, self).__init__(list) self.__missing__ = list I think I'm way off base. I'm not clear on what the calling sequence is for defaultdict or how to get it to use my CaseInsensitiveDict instead of regular dict. Can you help? -- Time flies like the wind. Fruit flies like a banana. Stranger things have .0. happened but none stranger than this. Does your driver's license say Organ ..0 Donor?Black holes are where God divided by zero. Listen to me! We are all- 000 individuals! What if this weren't a hypothetical question? steveo at syslang.net From tjreedy at udel.edu Mon Mar 26 11:39:29 2012 From: tjreedy at udel.edu (Terry Reedy) Date: Mon, 26 Mar 2012 11:39:29 -0400 Subject: why did GMPY change the names of its functions? In-Reply-To: <39ff04b9-84a0-401c-a0a5-75e33cf59bc8@vy9g2000pbc.googlegroups.com> References: <39ff04b9-84a0-401c-a0a5-75e33cf59bc8@vy9g2000pbc.googlegroups.com> Message-ID: On 3/26/2012 12:59 AM, Mensanator wrote: > OK, GMPY is now called GMPY2. No big deal, I can import as GMPY. > > But why were scan0 and scan1 changed to bit_scan0 and bit_scan1? Guess: Either the functions changed or they want to regularize their names. > What's the justification for that? I use those functions extensively > in my library of Collatz utilities and I had to re-edit them for no > obvious reason. If GMPY is coded in Python with a C? backup, GMPY.scan0 = GMPY.bit_scan0 should work. Or you could write a GMPY.py wrapper for GMPY2 from GMPY2 import * scan0=bit_scan0 scan1=bit_scan1 and leave your user code alone. -- Terry Jan Reedy From tjreedy at udel.edu Mon Mar 26 11:45:51 2012 From: tjreedy at udel.edu (Terry Reedy) Date: Mon, 26 Mar 2012 11:45:51 -0400 Subject: Is there any difference between print 3 and print '3' in Python ? In-Reply-To: <5128580.32.1332762326119.JavaMail.geo-discussion-forums@pbom7> References: <5128580.32.1332762326119.JavaMail.geo-discussion-forums@pbom7> Message-ID: On 3/26/2012 7:45 AM, redstone-cold at 163.com wrote: > I know the print statement produces the same result when both of > these two instructions are executed ,I just want to know Is there any > difference between print 3 and print '3' in Python ? If you want to see the difference between the number and string representation thereof, use repr(x). >>> print(repr(3), repr('3'), [3, '3']) 3 '3' [3, '3'] Note that printing a collection prints the repr() of each item precisely so one can tell the difference between the item being a number or a string. -- Terry Jan Reedy From robert.kern at gmail.com Mon Mar 26 11:52:47 2012 From: robert.kern at gmail.com (Robert Kern) Date: Mon, 26 Mar 2012 16:52:47 +0100 Subject: Question about collections.defaultdict In-Reply-To: <4F708C4C.5050700@syslang.net> References: <4F707028.4000407@syslang.net> <4F708C4C.5050700@syslang.net> Message-ID: On 3/26/12 4:33 PM, Steven W. Orr wrote: > On 3/26/2012 9:44 AM, Robert Kern wrote: >> On 3/26/12 2:33 PM, Steven W. Orr wrote: >>> I created a new class called CaseInsensitiveDict (by stealing from code I found >>> on the web, thank you very much). The new class inherits from dict. It makes it >>> so that if the key has a 'lower' method, it will always access the key using >>> lower >>> >>> I'd like to change the place where I previously declared a dict >>> >>> self.lookup = defaultdict(list) >>> >>> so that the new code will allow this new dict to be used instead. But then I >>> realized I may have painted myself into a small corner: >>> >>> Is there a way to use defaultdict so that I can override what *kind* of dict it >>> will use? >> >> No. >> >>> I would like the value to still be a list be default, but it seems like I can't >>> tell defaultdict to use *my* new dict. >>> >>> Do I give up on defaultdict? >> >> Assuming that your CaseInsensitiveDict subclasses from dict or UserDict, it's >> relatively easy to make a subclass of your CaseInsensitiveDict act like a >> defaultdict. Just implement the __missing__(key) method appropriately (and >> modify the constructor to take the callable, of course). >> >> http://docs.python.org/library/stdtypes.html#dict >> http://docs.python.org/library/collections.html#collections.defaultdict.__missing__ >> >> >> > > I'm not quite getting what you're telling me, but I'm sure you have the right > idea. Here's the beginning of my class: > > class CaseInsensitiveDict(dict): > def __init__(self, init=None): > if isinstance(init, (dict, list, tuple)): > for kk, vv in init.items(): > self[self.key_has_lower(kk)] = vv > > > It sounds like you want me to subclass defaultdict to create something like this? > > class CaseInsensitiveDictDef(defaultdict): > def __init__(self, init=None): > super(CaseInsensitiveDictDef, self).__init__(list) > self.__missing__ = list > > I think I'm way off base. I'm not clear on what the calling sequence is for > defaultdict or how to get it to use my CaseInsensitiveDict instead of regular dict. > > Can you help? You need to make a subclass of CaseInsensitiveDict, implement the __missing__(key) method, and override the __init__() method to take the factory function as an argument instead of data. defaultdict is just a subclass of dict that does this. class CaseInsensitiveDictDef(CaseInsensitiveDict): def __init__(self, default_factory): super(CaseInsensitiveDictDef, self).__init__() self.default_factory = default_factory def __missing__(self, key): return self.default_factory() -- Robert Kern "I have come to believe that the whole world is an enigma, a harmless enigma that is made terrible by our own mad attempt to interpret it as though it had an underlying truth." -- Umberto Eco From tjreedy at udel.edu Mon Mar 26 12:00:50 2012 From: tjreedy at udel.edu (Terry Reedy) Date: Mon, 26 Mar 2012 12:00:50 -0400 Subject: Documentation, assignment in expression. In-Reply-To: <4f70005c$0$29968$c3e8da3$5496439d@news.astraweb.com> References: <4f6d0060$0$6634$9b4e6d93@newsspool2.arcor-online.net> <4f6f0d24$0$6561$9b4e6d93@newsspool4.arcor-online.net> <4f70005c$0$29968$c3e8da3$5496439d@news.astraweb.com> Message-ID: On 3/26/2012 1:36 AM, Steven D'Aprano wrote: > > (I seem to recall a language that used a single = for both assignment and > equality testing, guessing which one you meant from context. BASIC > perhaps? Right. In some Basics, such as MS GW-Basic (I still have their book), a = b = c meant a = (b = c), or in Python, a = b==c. -- Terry Jan Reedy From sathyaish at gmail.com Mon Mar 26 12:14:57 2012 From: sathyaish at gmail.com (Sathyaish) Date: Mon, 26 Mar 2012 09:14:57 -0700 (PDT) Subject: A play about the Indian IT industry Message-ID: My name is Sathyaish. I am a software engineer. Last year, i.e. in 2011, I wanted to do some theater. No one took me, so I announced that I would start my own group. I wrote a script. Then, I wrote a screen play from that. Now, I am almost ready to begin the auditions. The play will be a comedy with a sad undertone profiling the life (or rather the lack) of programmers and how they are generally taken for granted and treated poorly by people who should really have been working in a bread making factory baking bread, or people who should have been making biscuits or whatever, i.e. the non-technical people in the software development industry who have become managers and architects and what-not. Here is a teaser: http://www.youtube.com/watch?v=6V-Lchu7aiA I hope you like it. I'll be posting more stuff about this play on the Web page at http://sathyaish.net/acting The play will be performed at a theater in New Delhi, India. The group that I am organizing to perform this play will rehearse only over weekends so that they may keep their day jobs. I expect that the auditions will run through April 2012. We will start rehearsing in May 2012 and will carry on with the rehearsals for May, June, July, August and September 2012 only over the weekends. We should perform in the last week of September 2012 or some time in October 2012. From ian.g.kelly at gmail.com Mon Mar 26 12:48:01 2012 From: ian.g.kelly at gmail.com (Ian Kelly) Date: Mon, 26 Mar 2012 10:48:01 -0600 Subject: random number In-Reply-To: <20120326092403.GB22725@terra.cms.at> References: <20120326064000.GB19865@terra.cms.at> <20120326092403.GB22725@terra.cms.at> Message-ID: On Mon, Mar 26, 2012 at 3:24 AM, Michael Poeltl wrote: >>>> import random, string >>>> def random_number(id): > ... ? ? characters = list(string.ascii_lowercase + > ... ? ? ? ? ? ? ? ? ? ? ? string.ascii_uppercase + > ... ? ? ? ? ? ? ? ? ? ? ? string.digits) > ... ? ? coll_rand = [] > ... ? ? for i in range(6): > ... ? ? ? ? random.shuffle(characters) > ... ? ? ? ? coll_rand.append(characters[0]) > ... ? ? return ''.join(coll_rand) You don't need to do all that list manipulation. This is probably quicker: def random_number(): # Unused "id" parameter omitted characters = (string.ascii_lowercase + string.ascii_uppercase + string.digits) return ''.join(random.choice(characters) for i in range(6)) Cheers, Ian From jcd at sdf.lonestar.org Mon Mar 26 13:06:58 2012 From: jcd at sdf.lonestar.org (J. Cliff Dyer) Date: Mon, 26 Mar 2012 13:06:58 -0400 Subject: Is there any difference between print 3 and print '3' in Python ? In-Reply-To: <5128580.32.1332762326119.JavaMail.geo-discussion-forums@pbom7> References: <5128580.32.1332762326119.JavaMail.geo-discussion-forums@pbom7> Message-ID: <1332781618.3893.10.camel@jcdyer-laptop> As others have pointed out, the output is the same, because the result of converting an integer to a string is the string of that integer. However, other numeric literals might not do what you want, due to the fact that they are converted to an internal numeric representation, then converted back to a string in a canonical format. >>> print 3, '3' 3 3 >>> print 3.00, '3.00' 3.0 3.00 >>> print 0x3, '0x3' 3 0x3 >>> print 03, '03' 3 03 >>> print 3e0, '3e0' 3.0 3e0 You might think that the take away message is to use the string representation, since it prints what you tell it to print. However, if you use a number, you can specify the output formatting with more fine-grained control, and even exert that control on calculated number: >>> print '%0.2f' % (3,) 3.00 >>> print '%0.2f' % (2 + 1) 3.00 This is better because you can't perform math on a string: >>> print '2' + '1' 21 >>> print '2.00' + '1.00' 2.001.00 print '2 + 1' 2 + 1 So in general, you should use numbers, and then format them using standard string formatting operations when you want to print them. There's more information on how to do formatting here: http://docs.python.org/library/stdtypes.html#string-formatting Cheers, Cliff On Mon, 2012-03-26 at 04:45 -0700, redstone-cold at 163.com wrote: > I know the print statement produces the same result when both of these > two instructions are executed ,I just want to know Is there any > difference between print 3 and print '3' in Python ? From __peter__ at web.de Mon Mar 26 13:20:10 2012 From: __peter__ at web.de (Peter Otten) Date: Mon, 26 Mar 2012 19:20:10 +0200 Subject: Is there any difference between print 3 and print '3' in Python ? References: <5128580.32.1332762326119.JavaMail.geo-discussion-forums@pbom7> Message-ID: redstone-cold at 163.com wrote: > I know the print statement produces the same result when both of these two > instructions are executed ,I just want to know Is there any difference > between print 3 and print '3' in Python ? The question you really wanted to ask is: under what circumstances will the two statements produce different output? Here's what I found: $ PYTHONIOENCODING=hex python -c'from __future__ import unicode_literals print 3' 3 $ PYTHONIOENCODING=hex python -c'from __future__ import unicode_literals print "3"' 33 $ :) From python.list at tim.thechases.com Mon Mar 26 13:42:53 2012 From: python.list at tim.thechases.com (Tim Chase) Date: Mon, 26 Mar 2012 12:42:53 -0500 Subject: Documentation, assignment in expression. In-Reply-To: References: <4f6d0060$0$6634$9b4e6d93@newsspool2.arcor-online.net> <4f6f0d24$0$6561$9b4e6d93@newsspool4.arcor-online.net> Message-ID: <4F70AA9D.6090704@tim.thechases.com> On 03/26/12 08:59, Thomas Rachel wrote: > Am 25.03.2012 15:03 schrieb Tim Chase: >> while True: >> data = conn.fetchmany() >> if not data: break >> for row in data: >> process(row) > > Or simpler > > for data in iter(conn.fetchmany, []): > for row in data: > process(row) Nice! That's the first time I've seen the 2-parameter version of iter() improve things :-) (I've seen it once or twice before in the 2-param form, and wondered why it wasn't written in a clearer way). Also, I was surprised to learn that the sentinel was available as far back as 2.2 (I knew about the 1-param version as far back as 2.3 when I became more serious about Python). -tkc From mensanator at aol.com Mon Mar 26 14:27:14 2012 From: mensanator at aol.com (Mensanator) Date: Mon, 26 Mar 2012 11:27:14 -0700 (PDT) Subject: why did GMPY change the names of its functions? References: <39ff04b9-84a0-401c-a0a5-75e33cf59bc8@vy9g2000pbc.googlegroups.com> Message-ID: <20665b28-a2ca-45ee-ba91-12481653d9a2@sv8g2000pbc.googlegroups.com> On Mar 26, 10:39?am, Terry Reedy wrote: > On 3/26/2012 12:59 AM, Mensanator wrote: > > > OK, GMPY is now called GMPY2. No big deal, I can import as GMPY. > > > But why were scan0 and scan1 changed to bit_scan0 and bit_scan1? > > Guess: Either the functions changed or they want to regularize their names. > > > What's the justification for that? I use those functions extensively > > in my library of Collatz utilities ?and I had to re-edit them for no > > obvious reason. > > If GMPY is coded in Python with a C? backup, GMPY.scan0 = GMPY.bit_scan0 > should work. > > Or you could write a GMPY.py wrapper for GMPY2 > > from GMPY2 import * > scan0=bit_scan0 > scan1=bit_scan1 > > > and leave your user code alone. > > -- > Terry Jan Reedy Oh, similar to an "import as", but this would allow me to change individual functions. Thanks. From casevh at gmail.com Mon Mar 26 14:33:17 2012 From: casevh at gmail.com (casevh at gmail.com) Date: Mon, 26 Mar 2012 11:33:17 -0700 (PDT) Subject: why did GMPY change the names of its functions? In-Reply-To: <39ff04b9-84a0-401c-a0a5-75e33cf59bc8@vy9g2000pbc.googlegroups.com> References: <39ff04b9-84a0-401c-a0a5-75e33cf59bc8@vy9g2000pbc.googlegroups.com> Message-ID: <29431928.122.1332786797588.JavaMail.geo-discussion-forums@pbcjk1> On Sunday, March 25, 2012 9:59:56 PM UTC-7, Mensanator wrote: > OK, GMPY is now called GMPY2. No big deal, I can import as GMPY. > > But why were scan0 and scan1 changed to bit_scan0 and bit_scan1? > > What's the justification for that? I use those functions extensively > in my library of Collatz utilities and I had to re-edit them for no > obvious reason. I'll speak up as the maintainer of GMPY and GMPY2. (My comments apply to the beta1 release which should be out in a couple of days.) GMPY2 introduces many changes: 1) the limited "mpf" type that is based on GMP has been replaced with the "mpfr" type from the MPFR library 2) support for multiple-precision complex arithmetic based on the MPC library 3) support for a mutable integer type optimized for in-place bit manipulations 4) support for addition number theory functions (generalized Lucas sequences and more primality tests I began to encounter name collisions; for example, should sqrt() only return integer square roots. I chose to call it a new name (gmpy2) and update the API to reflect new choices I made. For example, sqrt() now returns an "mpfr" and isqrt() returns an "mpz". As part of the documentation for the beta release, I will document the name changes. "import gmpy2 as gmpy; gmpy.scan0=gmpy.bit_scan0; etc" should work just fine. If you encounter problems with the alpha release, please open an issue on gmpy's site. Thanks, casevh On Sunday, March 25, 2012 9:59:56 PM UTC-7, Mensanator wrote: > OK, GMPY is now called GMPY2. No big deal, I can import as GMPY. > > But why were scan0 and scan1 changed to bit_scan0 and bit_scan1? > > What's the justification for that? I use those functions extensively > in my library of Collatz utilities and I had to re-edit them for no > obvious reason. On Sunday, March 25, 2012 9:59:56 PM UTC-7, Mensanator wrote: > OK, GMPY is now called GMPY2. No big deal, I can import as GMPY. > > But why were scan0 and scan1 changed to bit_scan0 and bit_scan1? > > What's the justification for that? I use those functions extensively > in my library of Collatz utilities and I had to re-edit them for no > obvious reason. On Sunday, March 25, 2012 9:59:56 PM UTC-7, Mensanator wrote: > OK, GMPY is now called GMPY2. No big deal, I can import as GMPY. > > But why were scan0 and scan1 changed to bit_scan0 and bit_scan1? > > What's the justification for that? I use those functions extensively > in my library of Collatz utilities and I had to re-edit them for no > obvious reason. From ramit.prasad at jpmorgan.com Mon Mar 26 15:12:32 2012 From: ramit.prasad at jpmorgan.com (Prasad, Ramit) Date: Mon, 26 Mar 2012 19:12:32 +0000 Subject: help needed to understand an error message. In-Reply-To: <4F706E80.7090809@sequans.com> References: <4F706E80.7090809@sequans.com> Message-ID: <5B80DD153D7D744689F57F4FB69AF4740928C084@SCACMX008.exchad.jpmchase.net> >> I feel the error is in Capital P in print . >> However the error indicated with "*^*" >> hints at quote at the end of the line. > > Anyway, the hint indicates the last quote because this is the location > where the python interpreter realizes it won't be able to execute the > code. You should not worry about that too much. Often when I see errors the problem can be earlier in the line or a line or two before. Just look backwards from where the error says the problem was found. Ramit Ramit Prasad | JPMorgan Chase Investment Bank | Currencies Technology 712 Main Street | Houston, TX 77002 work phone: 713 - 216 - 5423 -- This email is confidential and subject to important disclaimers and conditions including on offers for the purchase or sale of securities, accuracy and completeness of information, viruses, confidentiality, legal privilege, and legal entity disclaimers, available at http://www.jpmorgan.com/pages/disclosures/email. From xahlee at gmail.com Mon Mar 26 16:06:55 2012 From: xahlee at gmail.com (Xah Lee) Date: Mon, 26 Mar 2012 13:06:55 -0700 (PDT) Subject: perldoc: the key to perl Message-ID: <5a116730-161b-461e-bf0b-4bee038abb3d@z5g2000pbu.googlegroups.com> ?Perl Documentation: The Key to Perl? http://xahlee.org/perl-python/key_to_perl.html plain text follows ------------------------------------- So, i wanted to know what the option perl -C does. So, here's perldoc perlrun. Excerpt: -C [*number/list*] The -C flag controls some of the Perl Unicode features. As of 5.8.1, the -C can be followed either by a number or a list of option letters. The letters, their numeric values, and effects are as follows; listing the letters is equal to summing the numbers. I 1 STDIN is assumed to be in UTF-8 O 2 STDOUT will be in UTF-8 E 4 STDERR will be in UTF-8 S 7 I + O + E i 8 UTF-8 is the default PerlIO layer for input streams o 16 UTF-8 is the default PerlIO layer for output streams D 24 i + o A 32 the @ARGV elements are expected to be strings encoded in UTF-8 L 64 normally the "IOEioA" are unconditional, the L makes them conditional on the locale environment variables (the LC_ALL, LC_TYPE, and LANG, in the order of decreasing precedence) -- if the variables indicate UTF-8, then the selected "IOEioA" are in effect a 256 Set ${^UTF8CACHE} to -1, to run the UTF-8 caching code in debugging mode. For example, -COE and -C6 will both turn on UTF-8-ness on both STDOUT and STDERR. Repeating letters is just redundant, not cumulative nor toggling. The "io" options mean that any subsequent open() (or similar I/O operations) in the current file scope will have the ":utf8" PerlIO layer implicitly applied to them, in other words, UTF-8 is expected from any input stream, and UTF-8 is produced to any output stream. This is just the default, with explicit layers in open() and with binmode() one can manipulate streams as usual. -C on its own (not followed by any number or option list), or the empty string "" for the "PERL_UNICODE" environment variable, has the same effect as -CSDL. In other words, the standard I/ O handles and the default "open()" layer are UTF-8-fied *but* only if the locale environment variables indicate a UTF-8 locale. This behaviour follows the *implicit* (and problematic) UTF-8 behaviour of Perl 5.8.0. You can use -C0 (or "0" for "PERL_UNICODE") to explicitly disable all the above Unicode features. The read-only magic variable "${^UNICODE}" reflects the numeric value of this setting. This variable is set during Perl startup and is thereafter read-only. If you want runtime effects, use the three-arg open() (see "open" in perlfunc), the two-arg binmode() (see "binmode" in perlfunc), and the "open" pragma (see open). (In Perls earlier than 5.8.1 the -C switch was a Win32- only switch that enabled the use of Unicode-aware "wide system call" Win32 APIs. This feature was practically unused, however, and the command line switch was therefore "recycled".) Note: Since perl 5.10.1, if the -C option is used on the "#!" line, it must be specified on the command line as well, since the standard streams are already set up at this point in the execution of the perl interpreter. You can also use binmode() to set the encoding of an I/O stream. reading that is like a adventure. It's like this: The -C is a key to unlock many secrets. Just get it, and you'll be all good to go, except in cases you may need the inner key. You'll find a hinge in the key, open it, then there's a subkey. On the subkey, there's a number. Take that number to the lock, it will open with keyX. When you use keyX, it must be matched with the previous inner key with 8th bit. keyX doesn't have a ID, but you can make one by finding the number at the place you found the key C. Key C is actually optional, but when inner key and keyX's number matches, it changes the nature of the lock. This is when you need to turn on keyMode ? Xah From gelonida at gmail.com Mon Mar 26 16:26:11 2012 From: gelonida at gmail.com (Gelonida N) Date: Mon, 26 Mar 2012 22:26:11 +0200 Subject: best way to create warning for obsolete functions and call new one Message-ID: Hi, I'm working on a module, which needs rather heavy renaming of functions and methods (naming style, change of functionality, understandability, orthography) As these modules are used by quite some projects and as I do not want to force everybody to rename immediately I just want to warn users, that they call functions, that have been renamed and that will be obsoleted. function example: def get_thyme(a='high'): # old name return a + 'noon' # Should have been get_time(a, b) method example: class C(): def set_with(self, value=0): # should be set_width self.width = value What I basically want to do for each function is following: def get_time(a='high'): return a + 'noon' def get_thyme(a): # ideally the next line should display old and new function name # but even with out I 'd be fine logging.warning('obsolate function. please use the new function') return get_time(a) Assuming I want to rename loads of functions / metthods, what would be the laziest option to so? (and have no run time penalty for the new call) One option I though of would be: def obsolete_func(func): def call_old(*args, **kwargs): print "func is old psl use new one" return func(*args, **kwargs) return call_old and def get_time(a='high'): return a + 'noon' get_thyme = obsolete_func(get_time) class C(): def set_width(self, value=0): # should be set_width self.width = value set_with = obsolete_func(set_width) Another idea might be something like: add_obsolete_functions(get_tyme=get_time, get_dayt=get_date) Not sure though how to do this best for Classes Thanks for any ideas From dan at tombstonezero.net Mon Mar 26 17:24:40 2012 From: dan at tombstonezero.net (Dan Sommers) Date: Mon, 26 Mar 2012 17:24:40 -0400 Subject: best way to create warning for obsolete functions and call new one In-Reply-To: References: Message-ID: <20120326172440.4705444d@particle> On Mon, 26 Mar 2012 22:26:11 +0200 Gelonida N wrote: > As these modules are used by quite some projects and as I do not want > to force everybody to rename immediately I just want to warn users, > that they call functions, that have been renamed and that will be > obsoleted. You want a DeprecationWarning. HTH, Dan From rosuav at gmail.com Mon Mar 26 17:50:35 2012 From: rosuav at gmail.com (Chris Angelico) Date: Tue, 27 Mar 2012 08:50:35 +1100 Subject: best way to create warning for obsolete functions and call new one In-Reply-To: References: Message-ID: On Tue, Mar 27, 2012 at 7:26 AM, Gelonida N wrote: > One option I though of would be: > > def obsolete_func(func): > ? ?def call_old(*args, **kwargs): > ? ? ? ?print "func is old psl use new one" > ? ? ? ?return func(*args, **kwargs) > ? ?return call_old > > and > > def get_time(a='high'): > ? return a + 'noon' That's a reasonable idea. Incorporate Dan's suggestion of using DeprecationWarning. You may want to try decorator syntax: def was(oldname): def _(func): globals()[oldname]=func return func return _ @was("get_thyme") def get_time(a='high'): return a + 'noon' That won't raise DeprecationWarning, though. It's a very simple assignment. The was() internal function could be enhanced to do a bit more work, but I'm not sure what version of Python you're using and what introspection facilities you have. But if you're happy with the old versions coming up with (*args,**kwargs) instead of their parameter lists, it's not difficult: def was(oldname): def _(func): def bounce(*args,**kwargs): # raise DeprecationWarning return func(*args,**kwargs) globals()[oldname]=bounce return func return _ I've never actually used the Python warnings module, but any line of code you fill in at the comment will be executed any time the old name is used. In any case, it's still used with the same convenient decorator. You could even unify multiple functions under a single new name: @was("foo") @was("bar") def quux(spam,ham): return ham.eat() Hope that helps! ChrisA From tolidtm at gmail.com Mon Mar 26 17:53:54 2012 From: tolidtm at gmail.com (Anatoli Hristov) Date: Mon, 26 Mar 2012 23:53:54 +0200 Subject: Advise of programming one of my first programs Message-ID: Hi guys just wanted to share one of my first programs. Could you please tell me, do I use a right logic ? It works fine what I wanted to do, but is it writen in the right way? My next step is to make it write the changes of the dictionary on the file :) ## DB tbook = {'goodie':['Christian','Van Eckel','Bruxelles','Forest','02 344 33 33','This is a test note :)'], 'osvaldo':['Osvaldo','Rios','Liege','Centrum','023758832',''], 'ronaldo':['Diego','Aspanda','Brussels','Vorst','03 443 23 23','']} ## Edit selected nickname def edit(): sb = tbook[select] fn = raw_input('New name for ' + sb[0] + ' : ') sb[0] = fn ln = raw_input('New name for ' + sb[1] + ' : ') sb[1] = ln raw_input('\n\n\nPress to return') details() ## Details of nickname def details(): sb = tbook[select] print 'Nickname: ', select, ' is selected\n' print 'First name:\t', sb[0], '\n' print 'Last name:\t', sb[1], '\n' print 'Country:\t', sb[2], '\n' print 'City:\t\t', sb[3], '\n' print 'Phone number:\t',sb[4], '\n' print 'Memos:\n' print sb[5] print '\n\n(E)dit\n\n' print '(B)ack to phonebook list\n\n' menu = raw_input('What you wana do? ') if menu == 'e': edit() if menu == 'b': listpb() ## Select nickname def selectm(): global select select = raw_input('Type nickname and press : ') if select == '': listpb() if select in tbook: details() else: listpb() ## List all contacts def listpb(): print '_' *45, ' Phonebook ', '_' *45,'\n\n\n' print 'Nick\t\tF.Name\t\tL.Name\t\tCity\t\t\tRegion\t\tTel' print '_' * 105,'\n','\t' * 13 for val in tbook.keys(): print val, '\t\t', tbook[val][0], '\t', tbook[val][1], '\t', tbook[val][2], '\t\t', tbook[val][3], '\t\t', tbook[val][4],'\t\t\n' print '_'*105,'\n\n' selectm() ## Call list names listpb() Thanks a lot Anatoli -------------- next part -------------- An HTML attachment was scrubbed... URL: From ramit.prasad at jpmorgan.com Mon Mar 26 18:40:49 2012 From: ramit.prasad at jpmorgan.com (Prasad, Ramit) Date: Mon, 26 Mar 2012 22:40:49 +0000 Subject: Advise of programming one of my first programs In-Reply-To: References: Message-ID: <5B80DD153D7D744689F57F4FB69AF4740928C365@SCACMX008.exchad.jpmchase.net> > Hi guys just wanted to share one of my first programs. Could you please > tell me, do I use a right logic ? > It works fine what I wanted to do, but is it writen in the right way? My > next step is to make it write the changes of the dictionary on the file :) > When you do get that far, you should look at the pickle library. It is amazing how easy it is to store data with Python. > > ## DB > tbook = {'goodie':['Christian','Van Eckel','Bruxelles','Forest','02 344 33 > 33','This is a test note :)'], > 'osvaldo':['Osvaldo','Rios','Liege','Centrum','023758832',''], > 'ronaldo':['Diego','Aspanda','Brussels','Vorst','03 443 23 > 23','']} > > ## Edit selected nickname > def edit(): > sb = tbook[select] > fn = raw_input('New name for ' + sb[0] + ' : ') > sb[0] = fn > ln = raw_input('New name for ' + sb[1] + ' : ') > sb[1] = ln > raw_input('\n\n\nPress to return') > details() > > > ## Details of nickname > def details(): > sb = tbook[select] > print 'Nickname: ', select, ' is selected\n' > print 'First name:\t', sb[0], '\n' > print 'Last name:\t', sb[1], '\n' > print 'Country:\t', sb[2], '\n' > print 'City:\t\t', sb[3], '\n' > print 'Phone number:\t',sb[4], '\n' > print 'Memos:\n' > print sb[5] > > print '\n\n(E)dit\n\n' > print '(B)ack to phonebook list\n\n' > menu = raw_input('What you wana do? ') > if menu == 'e': > edit() > if menu == 'b': > listpb() > Minor nitpick, but what if the user types 'B' or 'E' like in your printed menu? > > ## Select nickname > def selectm(): > global select > select = raw_input('Type nickname and press : ') > if select == '': > listpb() > if select in tbook: > details() > else: > listpb() Remove all global variables when your program starts to work. Instead pass them as arguments and return them from functions. So do 'details( select )' instead of 'details()' and then in details, you would do edit( select ). > > ## List all contacts > def listpb(): > print '_' *45, ' Phonebook ', '_' *45,'\n\n\n' > > print 'Nick\t\tF.Name\t\tL.Name\t\tCity\t\t\tRegion\t\tTel' > print '_' * 105,'\n','\t' * 13 > for val in tbook.keys(): > print val, '\t\t', tbook[val][0], '\t', tbook[val][1], '\t', > tbook[val][2], '\t\t', tbook[val][3], '\t\t', tbook[val][4],'\t\t\n' > print '_'*105,'\n\n' > selectm() > > ## Call list names > listpb() if __name__ == "__main__": listpb() This way you can import the module and not run it on import; it is useful when you start wanting to reuse functions from a different project. It is better than copy-pasting functions everywhere because when you improve the function all the programs will pick it up. Otherwise you will have to go back to each pasted function and pick it up. A few items I would work to improve: 1. Remove global variables (already mentioned above) 2. You should separate any menu / navigation from your application code. details() should only print the details and not take the next menu choice. You probably want 2 separate menu functions. One that returns a 'select'-ed book and one that returns next choice. This will also help you when you implement my next point. 3. You should also change the structure of your program to loop instead of calling listpb each time you want to restart. It is a much better practice and while it will not affect this program unless you do not exit for 10s or 100s of thousands of details but if you write something that *does* navigate that many times it can crash. Looping is probably your next programming lesson anyway :) 4. This is more of a side note but instead of using \t\t all the time, you would be better off learning to use the string formatting operations. It is a little more effort to learn, but tends to be a lot more reliable on different systems (and with different data trying to be printed) than manually trying to align everything. http://docs.python.org/library/string.html#format-string-syntax Keep on working, you have made a good start and now it is time to refactor (programming equivalent of rewriting an essay) and make everything better! Ramit Ramit Prasad | JPMorgan Chase Investment Bank | Currencies Technology 712 Main Street | Houston, TX 77002 work phone: 713 - 216 - 5423 -- This email is confidential and subject to important disclaimers and conditions including on offers for the purchase or sale of securities, accuracy and completeness of information, viruses, confidentiality, legal privilege, and legal entity disclaimers, available at http://www.jpmorgan.com/pages/disclosures/email. From ramit.prasad at jpmorgan.com Mon Mar 26 18:42:40 2012 From: ramit.prasad at jpmorgan.com (Prasad, Ramit) Date: Mon, 26 Mar 2012 22:42:40 +0000 Subject: perldoc: the key to perl In-Reply-To: <5a116730-161b-461e-bf0b-4bee038abb3d@z5g2000pbu.googlegroups.com> References: <5a116730-161b-461e-bf0b-4bee038abb3d@z5g2000pbu.googlegroups.com> Message-ID: <5B80DD153D7D744689F57F4FB69AF4740928C377@SCACMX008.exchad.jpmchase.net> > > ?Perl Documentation: The Key to Perl? > http://xahlee.org/perl-python/key_to_perl.html > > plain text follows > ------------------------------------- > > So, i wanted to know what the option perl -C does. So, here's perldoc > perlrun. Excerpt: [snip] Maybe I missed something, but what does this have to do with Python? Ramit Ramit Prasad | JPMorgan Chase Investment Bank | Currencies Technology 712 Main Street | Houston, TX 77002 work phone: 713 - 216 - 5423 -- This email is confidential and subject to important disclaimers and conditions including on offers for the purchase or sale of securities, accuracy and completeness of information, viruses, confidentiality, legal privilege, and legal entity disclaimers, available at http://www.jpmorgan.com/pages/disclosures/email. From abhishek.vit at gmail.com Mon Mar 26 18:56:29 2012 From: abhishek.vit at gmail.com (Abhishek Pratap) Date: Mon, 26 Mar 2012 15:56:29 -0700 Subject: concurrent file reading/writing using python Message-ID: Hi Guys I am fwding this question from the python tutor list in the hope of reaching more people experienced in concurrent disk access in python. I am trying to see if there are ways in which I can read a big file concurrently on a multi core server and process data and write the output to a single file as the data is processed. For example if I have a 50Gb file, I would like to read it in parallel with 10 process/thread, each working on a 10Gb data and perform the same data parallel computation on each chunk of fine collating the output to a single file. I will appreciate your feedback. I did find some threads about this on stackoverflow but it was not clear to me what would be a good way to go about implementing this. Thanks! -Abhi ---------- Forwarded message ---------- From: Steven D'Aprano Date: Mon, Mar 26, 2012 at 3:21 PM Subject: Re: [Tutor] concurrent file reading using python To: tutor at python.org Abhishek Pratap wrote: > > Hi Guys > > > I want to utilize the power of cores on my server and read big files > (> 50Gb) simultaneously by seeking to N locations. Yes, you have many cores on the server. But how many hard drives is each file on? If all the files are on one disk, then you will *kill* performance dead by forcing the drive to seek backwards and forwards: seek to 12345678 read a block seek to 9947500 read a block seek to 5891124 read a block seek back to 12345678 + 1 block read another block seek back to 9947500 + 1 block read another block ... The drive will spend most of its time seeking instead of reading. Even if you have multiple hard drives in a RAID array, performance will depend strongly the details of how it is configured (RAID1, RAID0, software RAID, hardware RAID, etc.) and how smart the controller is. Chances are, though, that the controller won't be smart enough. Particularly if you have hardware RAID, which in my experience tends to be more expensive and less useful than software RAID (at least for Linux). And what are you planning on doing with the files once you have read them? I don't know how much memory your server has got, but I'd be very surprised if you can fit the entire > 50 GB file in RAM at once. So you're going to read the files and merge the output... by writing them to the disk. Now you have the drive trying to read *and* write simultaneously. TL; DR: Tasks which are limited by disk IO are not made faster by using a faster CPU, since the bottleneck is disk access, not CPU speed. Back in the Ancient Days when tape was the only storage medium, there were a lot of programs optimised for slow IO. Unfortunately this is pretty much a lost art -- although disk access is thousands or tens of thousands of times slower than memory access, it is so much faster than tape that people don't seem to care much about optimising disk access. > What I want to know is the best way to read a file concurrently. I > have read about file-handle.seek(), ?os.lseek() but not sure if thats > the way to go. Any used cases would be of help. Optimising concurrent disk access is a specialist field. You may be better off asking for help on the main Python list, comp.lang.python or python-list at python.org, and hope somebody has some experience with this. But chances are very high that you will need to search the web for forums dedicated to concurrent disk access, and translate from whatever language(s) they are using to Python. -- Steven _______________________________________________ Tutor maillist ?- ?Tutor at python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor From ralf at systemexit.de Mon Mar 26 19:18:36 2012 From: ralf at systemexit.de (Ralf Schmitt) Date: Tue, 27 Mar 2012 01:18:36 +0200 Subject: [ANNOUNCE] pypiserver 0.5.2 - minimal pypi server Message-ID: <87aa336jeb.fsf@myhost.localnet> Hi, I've just uploaded pypiserver 0.5.2 to the python package index. pypiserver is a minimal PyPI compatible server. It can be used to serve a set of packages and eggs to easy_install or pip. pypiserver is easy to install (i.e. just easy_install pypiserver). It doesn't have any external dependencies. http://pypi.python.org/pypi/pypiserver/ should contain enough information to easily get you started running your own PyPI server in a few minutes. The code is available on github: https://github.com/schmir/pypiserver Changes in version 0.5.2 ------------------------- - provide a way to get the WSGI app - improved package name and version guessing - use case insensitive matching when removing archive suffixes - fix pytz issue #6 -- Cheers, Ralf From sln at netherlands.com Mon Mar 26 20:02:19 2012 From: sln at netherlands.com (sln at netherlands.com) Date: Mon, 26 Mar 2012 17:02:19 -0700 Subject: Your Regex Brain References: Message-ID: On Sat, 24 Mar 2012 16:30:28 -0700 (PDT), Xah Lee wrote: >?Your Regex Brain? >http://xahlee.org/comp/your_regex_brain.html > That's more like a brain cell. This is more like a regex brain. ' "\']|"[^"]*"|\'[^\']*\')*? (?<=\s) width \s*= (?: (?> \s* ([\'"]) \s* (?.*?) \s* \g{-2} ) | (?> (?!\s*[\'"]) \s* (?[^\s>]*) (?=\s|>) ) ) ) (?= (?:[^>"\']|"[^"]*"|\'[^\']*\')*? (?<=\s) src \s*= (?: (?> \s* ([\'"]) \s* (?.*?) \s* \g{-2} ) | (?> (?!\s*[\'"]) \s* (?[^\s>]*) (?=\s|>) ) ) ) (?= (?:[^>"\']|"[^"]*"|\'[^\']*\')*? (?<=\s) height \s*= (?: (?> \s* ([\'"]) \s* (?.*?) \s* \g{-2} ) | (?> (?!\s*[\'"]) \s* (?[^\s>]*) (?=\s|>) ) ) ) (?= (?:[^>"\']|"[^"]*"|\'[^\']*\')*? (?<=\s) alt \s*= (?: (?> \s* ([\'"]) \s* (?.*?) \s* \g{-2} ) | (?> (?!\s*[\'"]) \s* (?[^\s>]*) (?=\s|>) ) ) ) (?> \s+ (?:".*?"|\'.*?\'|[^>]*?)+ > ) (?) ' -sln From jason at powerpull.net Mon Mar 26 20:57:51 2012 From: jason at powerpull.net (Jason Friedman) Date: Tue, 27 Mar 2012 00:57:51 +0000 Subject: argparse ConfigureAction problem In-Reply-To: References: Message-ID: > ./plot_stuff2.py --plot stuff1 stuff2 > [...] > plot_stuff2.py: error: argument --plot/--with-plot/--enable-plot/--no-plot/-- > without-plot/--disable-plot: invalid boolean value: 'stuff1' > > Problem is --plot takes an optional argument, and so the positional arg is > assumed to be the arg to --plot. ?Not sure how to fix this. Maybe have a look at nargs='*' in http://docs.python.org/py3k/library/argparse.html#nargs. From showell30 at yahoo.com Mon Mar 26 21:44:30 2012 From: showell30 at yahoo.com (Steve Howell) Date: Mon, 26 Mar 2012 18:44:30 -0700 (PDT) Subject: concurrent file reading/writing using python References: Message-ID: <67283b47-9d44-403e-a3df-73ade83a2c0e@z3g2000pbn.googlegroups.com> On Mar 26, 3:56?pm, Abhishek Pratap wrote: > Hi Guys > > I am fwding this question from the python tutor list in the hope of > reaching more people experienced in concurrent disk access in python. > > I am trying to see if there are ways in which I can read a big file > concurrently on a multi core server and process data and write the > output to a single file as the data is processed. > > For example if I have a 50Gb file, I would like to read it in parallel > with 10 process/thread, each working on a 10Gb data and perform the > same data parallel computation on each chunk of fine collating the > output to a single file. > > I will appreciate your feedback. I did find some threads about this on > stackoverflow but it was not clear to me what would be a good ?way to > go about implementing this. > Have you written a single-core solution to your problem? If so, can you post the code here? If CPU isn't your primary bottleneck, then you need to be careful not to overly complicate your solution by getting multiple cores involved. All the coordination might make your program slower and more buggy. If CPU is the primary bottleneck, then you might want to consider an approach where you only have a single thread that's reading records from the file, 10 at a time, and then dispatching out the calculations to different threads, then writing results back to disk. My approach would be something like this: 1) Take a small sample of your dataset so that you can process it within 10 seconds or so using a simple, single-core program. 2) Figure out whether you're CPU bound. A simple way to do this is to comment out the actual computation or replace it with a trivial stub. If you're CPU bound, the program will run much faster. If you're IO-bound, the program won't run much faster (since all the work is actually just reading from disk). 3) Figure out how to read 10 records at a time and farm out the records to threads. Hopefully, your program will take significantly less time. At this point, don't obsess over collating data. It might not be 10 times as fast, but it should be somewhat faster to be worth your while. 4) If the threaded approach shows promise, make sure that you can still generate correct output with that approach (in other words, figure out out synchronization and collating). At the end of that experiment, you should have a better feel on where to go next. What is the nature of your computation? Maybe it would be easier to tune the algorithm then figure out the multi-core optimization. From kmisoft at gmail.com Mon Mar 26 21:51:13 2012 From: kmisoft at gmail.com (Vladimir Ignatov) Date: Mon, 26 Mar 2012 21:51:13 -0400 Subject: Tools for refactoring/obfuscation In-Reply-To: References: Message-ID: Hi, (sorry for replying to the old topic) On Tue, Mar 6, 2012 at 10:29 PM, Javier wrote: > I am looking for an automated tool for refactoring/obfuscation. > Something that changes names of functions, variables, or which would > merge all the functions of various modules in a single module. > The closest I have seen is http://bicyclerepair.sourceforge.net/ > > Does somebody know of something that can work from the command line or > simple data structures/text files?, like a python dictionary of functions > {"old":"new",...} I am not surprised what nobody answers. I think that such tool is nearly impossible given the dynamic Python's nature. But if you put little discipline/restrictions in your source code, when doing obfuscation could be much more easier. Almost trivial I would say. Javier, you can contact me directly if you are interested in this topic. Vladimir Ignatov kmisoft at gmail com From demianbrecht at gmail.com Mon Mar 26 22:42:38 2012 From: demianbrecht at gmail.com (Demian Brecht) Date: Mon, 26 Mar 2012 19:42:38 -0700 (PDT) Subject: OAuth 2.0 implementation Message-ID: <1973354.3.1332816158529.JavaMail.geo-discussion-forums@pbae2> Hi all, I'm getting close to an alpha release of an OAuth 2.0 implementation (https://github.com/demianbrecht/py-sanction). High level features include: * Support for multiple providers (protocol deviations). This didn't seem to be supported by any library. * Actually an OAuth 2.0 implementation (python-oauth2 is a 2nd version of python-oauth, not an OAuth 2.0 implementation) * Support for the entire OAuth 2.0 spec. Most provide support for the authorization code grant flow (employed by all web server providers), but lacked support or extensibility for any other flows, credentials or other provider extensions) * 100% unit test coverage. Some employ TDD, others didn't. Current implementation includes support for Authorization Code Grant flow but can be extended to support others (including extensions) quite trivially. Current adapter implementations include: * Google * Facebook * Stack Exchange * Deviant Art * Foursquare It has yet to be heavily used or functionally tested (basic tests have been done in example/server.py) and documentation is being worked on. Just wanted to share some of my work and hopefully someone other than me can find some use for it :) P.S. For those interested, cloc stats are: http://cloc.sourceforge.net v 1.53 T=0.5 s (28.0 files/s, 1818.0 lines/s) ------------------------------------------------------------------------------- Language files blank comment code ------------------------------------------------------------------------------- Python 14 239 196 474 ------------------------------------------------------------------------------- SUM: 14 239 196 474 ------------------------------------------------------------------------------- From ben+python at benfinney.id.au Mon Mar 26 23:11:54 2012 From: ben+python at benfinney.id.au (Ben Finney) Date: Tue, 27 Mar 2012 14:11:54 +1100 Subject: OAuth 2.0 implementation References: <1973354.3.1332816158529.JavaMail.geo-discussion-forums@pbae2> Message-ID: <87haxahh51.fsf@benfinney.id.au> Demian Brecht writes: > I'm getting close to an alpha release of an OAuth 2.0 implementation > (https://github.com/demianbrecht/py-sanction). Thank you for doing this work. As someone who uses OpenID, what can I read about why OAuth is better? Everything I read is targeted toward either people *implementing* OAuth, or people who use ?social networking?. Nothing much for people who want to control their own identity provider (in OpenID terms). Is OAuth not possible without relying on ?social networking? centralised services? Can we use OAuth services without some Google or Facebook or other gatekeeper imposing itself in the transaction? -- \ ?Never use a long word when there's a commensurate diminutive | `\ available.? ?Stan Kelly-Bootle | _o__) | Ben Finney From roy at panix.com Mon Mar 26 23:30:18 2012 From: roy at panix.com (Roy Smith) Date: Mon, 26 Mar 2012 23:30:18 -0400 Subject: OAuth 2.0 implementation References: <1973354.3.1332816158529.JavaMail.geo-discussion-forums@pbae2> <87haxahh51.fsf@benfinney.id.au> Message-ID: In article <87haxahh51.fsf at benfinney.id.au>, Ben Finney wrote: > Demian Brecht writes: > > > I'm getting close to an alpha release of an OAuth 2.0 implementation > > (https://github.com/demianbrecht/py-sanction). > > Thank you for doing this work. > > As someone who uses OpenID, what can I read about why OAuth is better? OpenID is for people who worry about things like how OpenID is different from OAuth. Oauth is for people who have no idea what OAuth is and just want to be able to log into web sites using their Facebook account. From steve+comp.lang.python at pearwood.info Mon Mar 26 23:43:46 2012 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 27 Mar 2012 03:43:46 GMT Subject: Is there any difference between print 3 and print '3' in Python ? References: <5128580.32.1332762326119.JavaMail.geo-discussion-forums@pbom7> Message-ID: <4f713772$0$29965$c3e8da3$5496439d@news.astraweb.com> On Mon, 26 Mar 2012 08:11:03 -0400, Dave Angel wrote: > On 03/26/2012 07:45 AM, redstone-cold at 163.com wrote: >> I know the print statement produces the same result when both of these >> two instructions are executed ,I just want to know Is there any >> difference between print 3 and print '3' in Python ? > > This is a non-question. The input is the same, the output is the same, > what else matters? def fib1(n): if n == 0: return 0 elif n == 1: return 1 f2, f1 = 0, 1 for _ in range(2, n+1): f2, f1 = f1, f2 + f1 return f1 def fib2(n): if n == 0: return 0 elif n == 1: return 1 else: return fib2(n-1) + fib2(n-2) Try calling fib1(35) and fib2(35). Still think only the input and output matter? :) For the record, fib2(35) ends up making a total of 29860703 function calls, compared to 35 iterations for fib1. -- Steven From ben+python at benfinney.id.au Mon Mar 26 23:49:54 2012 From: ben+python at benfinney.id.au (Ben Finney) Date: Tue, 27 Mar 2012 14:49:54 +1100 Subject: OAuth 2.0 implementation References: <1973354.3.1332816158529.JavaMail.geo-discussion-forums@pbae2> <87haxahh51.fsf@benfinney.id.au> Message-ID: <878vimhfdp.fsf@benfinney.id.au> Roy Smith writes: > In article <87haxahh51.fsf at benfinney.id.au>, > Ben Finney wrote: > > As someone who uses OpenID, what can I read about why OAuth is better? > > OpenID is for people who worry about things like how OpenID is different > from OAuth. Oauth is for people who have no idea what OAuth is and just > want to be able to log into web sites using their Facebook account. So, if I want to be free to choose an identity provider I trust, and it's not Facebook or Google or Twitter or other privacy-hostile services, how does OAuth help me do that? What can I read for how to become an OAuth user that doesn't assume I want a ?social networking? provider involved in my identity transactions? -- \ ?It is difficult to get a man to understand something when his | `\ salary depends upon his not understanding it.? ?Upton Sinclair, | _o__) 1935 | Ben Finney From roy at panix.com Mon Mar 26 23:57:13 2012 From: roy at panix.com (Roy Smith) Date: Mon, 26 Mar 2012 23:57:13 -0400 Subject: OAuth 2.0 implementation References: <1973354.3.1332816158529.JavaMail.geo-discussion-forums@pbae2> <87haxahh51.fsf@benfinney.id.au> <878vimhfdp.fsf@benfinney.id.au> Message-ID: In article <878vimhfdp.fsf at benfinney.id.au>, Ben Finney wrote: > Roy Smith writes: > > > In article <87haxahh51.fsf at benfinney.id.au>, > > Ben Finney wrote: > > > As someone who uses OpenID, what can I read about why OAuth is better? > > > > OpenID is for people who worry about things like how OpenID is different > > from OAuth. Oauth is for people who have no idea what OAuth is and just > > want to be able to log into web sites using their Facebook account. > > So, if I want to be free to choose an identity provider I trust, and > it's not Facebook or Google or Twitter or other privacy-hostile > services, how does OAuth help me do that? It doesn't. Well, in theory, it could, but in practice everybody's OAuth implementation is different enough that they don't interoperate. From ben+python at benfinney.id.au Tue Mar 27 00:24:35 2012 From: ben+python at benfinney.id.au (Ben Finney) Date: Tue, 27 Mar 2012 15:24:35 +1100 Subject: OAuth 2.0 implementation References: <1973354.3.1332816158529.JavaMail.geo-discussion-forums@pbae2> <87haxahh51.fsf@benfinney.id.au> <878vimhfdp.fsf@benfinney.id.au> Message-ID: <87zkb2fz7g.fsf@benfinney.id.au> Roy Smith writes: > In article <878vimhfdp.fsf at benfinney.id.au>, > Ben Finney wrote: > > So, if I want to be free to choose an identity provider I trust, and > > it's not Facebook or Google or Twitter or other privacy-hostile > > services, how does OAuth help me do that? > > It doesn't. Well, in theory, it could, but in practice everybody's > OAuth implementation is different enough that they don't interoperate. Thanks. So OAuth is a pseudo-standard that is implemented incompatibly to the extent that it doesn't actually give users the freedom to migrate their existing data and identity at will to any other OAuth implementor? -- \ ?Money is always to be found when men are to be sent to the | `\ frontiers to be destroyed: when the object is to preserve them, | _o__) it is no longer so.? ?Voltaire, _Dictionnaire Philosophique_ | Ben Finney From rustompmody at gmail.com Tue Mar 27 01:00:48 2012 From: rustompmody at gmail.com (rusi) Date: Mon, 26 Mar 2012 22:00:48 -0700 (PDT) Subject: Is there any difference between print 3 and print '3' in Python ? References: <5128580.32.1332762326119.JavaMail.geo-discussion-forums@pbom7> <4f713772$0$29965$c3e8da3$5496439d@news.astraweb.com> Message-ID: <0e7412b9-8443-49d9-b9d9-5dd3f08d2054@to5g2000pbc.googlegroups.com> On Mar 27, 8:43?am, Steven D'Aprano wrote: > On Mon, 26 Mar 2012 08:11:03 -0400, Dave Angel wrote: > > On 03/26/2012 07:45 AM, redstone-c... at 163.com wrote: > >> I know the print statement produces the same result when both of these > >> two instructions are executed ,I just want to know Is there any > >> difference between print 3 and print '3' in Python ? > > > This is a non-question. ?The input is the same, the output is the same, > > what else matters? > > def fib1(n): > ? ? if n == 0: return 0 > ? ? elif n == 1: return 1 > ? ? f2, f1 = 0, 1 > ? ? for _ in range(2, n+1): > ? ? ? ? f2, f1 = f1, f2 + f1 > ? ? return f1 > > def fib2(n): > ? ? if n == 0: return 0 > ? ? elif n == 1: return 1 > ? ? else: return fib2(n-1) + fib2(n-2) > > Try calling fib1(35) and fib2(35). Still think only the input and output > matter? :) > > For the record, fib2(35) ends up making a total of 29860703 function > calls, compared to 35 iterations for fib1. > > -- > Steven http://www.cse.buffalo.edu/~rapaport/intensional.html From jackdied at gmail.com Tue Mar 27 01:24:16 2012 From: jackdied at gmail.com (Jack Diederich) Date: Tue, 27 Mar 2012 01:24:16 -0400 Subject: OAuth 2.0 implementation In-Reply-To: <87zkb2fz7g.fsf@benfinney.id.au> References: <1973354.3.1332816158529.JavaMail.geo-discussion-forums@pbae2> <87haxahh51.fsf@benfinney.id.au> <878vimhfdp.fsf@benfinney.id.au> <87zkb2fz7g.fsf@benfinney.id.au> Message-ID: On Tue, Mar 27, 2012 at 12:24 AM, Ben Finney wrote: > Roy Smith writes: > >> In article <878vimhfdp.fsf at benfinney.id.au>, >> ?Ben Finney wrote: >> > So, if I want to be free to choose an identity provider I trust, and >> > it's not Facebook or Google or Twitter or other privacy-hostile >> > services, how does OAuth help me do that? >> >> It doesn't. ?Well, in theory, it could, but in practice everybody's >> OAuth implementation is different enough that they don't interoperate. > > Thanks. So OAuth is a pseudo-standard that is implemented incompatibly > to the extent that it doesn't actually give users the freedom to migrate > their existing data and identity at will to any other OAuth implementor? Pretty much. It is nice that it is published as a standard at all but the standard is just whatever people are actually doing. It seems less hostile when you think of it as vigorous documentation instead of protocols set in stone. -Jack From demianbrecht at gmail.com Tue Mar 27 01:30:32 2012 From: demianbrecht at gmail.com (Demian Brecht) Date: Mon, 26 Mar 2012 22:30:32 -0700 (PDT) Subject: OAuth 2.0 implementation In-Reply-To: <87zkb2fz7g.fsf@benfinney.id.au> References: <1973354.3.1332816158529.JavaMail.geo-discussion-forums@pbae2> <87haxahh51.fsf@benfinney.id.au> <878vimhfdp.fsf@benfinney.id.au> <87zkb2fz7g.fsf@benfinney.id.au> Message-ID: <7909491.0.1332826232743.JavaMail.geo-discussion-forums@pbim5> On Monday, 26 March 2012 21:24:35 UTC-7, Ben Finney wrote: > Roy Smith writes: > > > In article <878vimhfdp.fsf at benfinney.id.au>, > > Ben Finney wrote: > > > So, if I want to be free to choose an identity provider I trust, and > > > it's not Facebook or Google or Twitter or other privacy-hostile > > > services, how does OAuth help me do that? > > > > It doesn't. Well, in theory, it could, but in practice everybody's > > OAuth implementation is different enough that they don't interoperate. > > Thanks. So OAuth is a pseudo-standard that is implemented incompatibly > to the extent that it doesn't actually give users the freedom to migrate > their existing data and identity at will to any other OAuth implementor? > > -- > \ ?Money is always to be found when men are to be sent to the | > `\ frontiers to be destroyed: when the object is to preserve them, | > _o__) it is no longer so.? ?Voltaire, _Dictionnaire Philosophique_ | > Ben Finney OAuth 2.0 is the emerging standard (now passed on to IETF) to deal with providing access to protected resources. OpenID is a standard used to deal with authentication. While there is some overlap (OAuth can be used for authentication as well), the goals of the two protocols are different. OAuth 2.0 is still in draft status (draft 25 is the current one I believe) and yes, unfortunately every single server available at this point have varying degrees of separation from the actual spec. It's not a pseudo-standard, it's just not observed to the letter. Google is the closest and Facebook seems to be the farthest away (Stack Exchange is in close second due to building theirs to work like Facebook's). That was pretty much how this work was born. I wanted to be able to implement authentication and resource access over multiple providers with a single code base. So, in answer to your questions: 1) If you're only looking for a solution to authentication, OAuth is no better than OpenID. Having said that, with the apparent popularity of OAuth 2.0, more providers may support OAuth than will OpenID (however, that's just my assumption). 2) OAuth is all about centralized services in that it is how providers allow access to protected resources. Whether it's a social network or SaaS (such as Harvest: http://www.getharvest.com/), if there isn't exposure to protected resources, then OAuth becomes pointless. 3) If you're looking to implement OAuth authentication with a provider that you trust, grab the sanction source, implement said provider and send a pull request ;) 4) Data migration doesn't happen with OAuth. As the intent is to allow access to protected resources, migrating Google to say, Facebook just wouldn't happen :) Hope that makes sense and answers your questions. - Demian From mensanator at aol.com Tue Mar 27 01:39:05 2012 From: mensanator at aol.com (Mensanator) Date: Mon, 26 Mar 2012 22:39:05 -0700 (PDT) Subject: why did GMPY change the names of its functions? References: <39ff04b9-84a0-401c-a0a5-75e33cf59bc8@vy9g2000pbc.googlegroups.com> <29431928.122.1332786797588.JavaMail.geo-discussion-forums@pbcjk1> Message-ID: On Mar 26, 1:33?pm, cas... at gmail.com wrote: > On Sunday, March 25, 2012 9:59:56 PM UTC-7, Mensanator wrote: > > OK, GMPY is now called GMPY2. No big deal, I can import as GMPY. > > > But why were scan0 and scan1 changed to bit_scan0 and bit_scan1? > > > What's the justification for that? I use those functions extensively > > in my library of Collatz utilities ?and I had to re-edit them for no > > obvious reason. > > I'll speak up as the maintainer of GMPY and GMPY2. > > (My comments apply to the beta1 release which should be out in a couple of days.) > > GMPY2 introduces many changes: > > 1) the limited "mpf" type that is based on GMP has been replaced with the "mpfr" type from the MPFR library > 2) support for multiple-precision complex arithmetic based on the MPC library > 3) support for a mutable integer type optimized for in-place bit manipulations > 4) support for addition number theory functions (generalized Lucas sequences and more primality tests > > I began to encounter name collisions; for example, should sqrt() only return integer square roots. I chose to call it a new name (gmpy2) and update the API to reflect new choices I made. For example, sqrt() now returns an "mpfr" and isqrt() returns an "mpz". > > As part of the documentation for the beta release, I will document the name changes. "import gmpy2 as gmpy; gmpy.scan0=gmpy.bit_scan0; etc" should work just fine. > > If you encounter problems with the alpha release, please open an issue on gmpy's site. > > Thanks, > casevh Thanks for the explanation. Sorry if I flew off the handle, but I've been sick recently and am trying to get back into Python after 2 years. I just bought a new laptop, downloaded Python 3.2 & GMPY2 only to see my Collatz library crash. At first, given my current condition, I was afraid I'd never get it to work again. But luckily, the fix is simple. I, for one, really appreciate your maintaining GMPY, otherwise, I might have to abandon Python. I'll keep my eyes open for any further problems. Thanks Gain. > > > > On Sunday, March 25, 2012 9:59:56 PM UTC-7, Mensanator wrote: > > OK, GMPY is now called GMPY2. No big deal, I can import as GMPY. > > > But why were scan0 and scan1 changed to bit_scan0 and bit_scan1? > > > What's the justification for that? I use those functions extensively > > in my library of Collatz utilities ?and I had to re-edit them for no > > obvious reason. > On Sunday, March 25, 2012 9:59:56 PM UTC-7, Mensanator wrote: > > OK, GMPY is now called GMPY2. No big deal, I can import as GMPY. > > > But why were scan0 and scan1 changed to bit_scan0 and bit_scan1? > > > What's the justification for that? I use those functions extensively > > in my library of Collatz utilities ?and I had to re-edit them for no > > obvious reason. > On Sunday, March 25, 2012 9:59:56 PM UTC-7, Mensanator wrote: > > OK, GMPY is now called GMPY2. No big deal, I can import as GMPY. > > > But why were scan0 and scan1 changed to bit_scan0 and bit_scan1? > > > What's the justification for that? I use those functions extensively > > in my library of Collatz utilities ?and I had to re-edit them for no > > obvious reason. From abhishek.vit at gmail.com Tue Mar 27 02:08:08 2012 From: abhishek.vit at gmail.com (Abhishek Pratap) Date: Mon, 26 Mar 2012 23:08:08 -0700 Subject: concurrent file reading/writing using python In-Reply-To: <67283b47-9d44-403e-a3df-73ade83a2c0e@z3g2000pbn.googlegroups.com> References: <67283b47-9d44-403e-a3df-73ade83a2c0e@z3g2000pbn.googlegroups.com> Message-ID: Thanks for the advice Dennis. @Steve : I haven't actually written the code. I was thinking more on the generic side and wanted to check if what I thought made sense and I now realize it can depend on then the I/O. For starters I was just thinking about counting lines in a line without doing any computation so this can be strictly I/O bound. I guess what I need to ask was can we improve on the existing disk I/O performance by reading different portions of the file using threads or processes. I am kind of pointing towards a MapReduce task on a file in a shared file system such as GPFS(from IBM). I realize this can be more suited to HDFS but wanted to know if people have implemented something similar on a normal linux based NFS -Abhi On Mon, Mar 26, 2012 at 6:44 PM, Steve Howell wrote: > On Mar 26, 3:56?pm, Abhishek Pratap wrote: >> Hi Guys >> >> I am fwding this question from the python tutor list in the hope of >> reaching more people experienced in concurrent disk access in python. >> >> I am trying to see if there are ways in which I can read a big file >> concurrently on a multi core server and process data and write the >> output to a single file as the data is processed. >> >> For example if I have a 50Gb file, I would like to read it in parallel >> with 10 process/thread, each working on a 10Gb data and perform the >> same data parallel computation on each chunk of fine collating the >> output to a single file. >> >> I will appreciate your feedback. I did find some threads about this on >> stackoverflow but it was not clear to me what would be a good ?way to >> go about implementing this. >> > > Have you written a single-core solution to your problem? ?If so, can > you post the code here? > > If CPU isn't your primary bottleneck, then you need to be careful not > to overly complicate your solution by getting multiple cores > involved. ?All the coordination might make your program slower and > more buggy. > > If CPU is the primary bottleneck, then you might want to consider an > approach where you only have a single thread that's reading records > from the file, 10 at a time, and then dispatching out the calculations > to different threads, then writing results back to disk. > > My approach would be something like this: > > ?1) Take a small sample of your dataset so that you can process it > within 10 seconds or so using a simple, single-core program. > ?2) Figure out whether you're CPU bound. ?A simple way to do this is > to comment out the actual computation or replace it with a trivial > stub. ?If you're CPU bound, the program will run much faster. ?If > you're IO-bound, the program won't run much faster (since all the work > is actually just reading from disk). > ?3) Figure out how to read 10 records at a time and farm out the > records to threads. ?Hopefully, your program will take significantly > less time. ?At this point, don't obsess over collating data. ?It might > not be 10 times as fast, but it should be somewhat faster to be worth > your while. > ?4) If the threaded approach shows promise, make sure that you can > still generate correct output with that approach (in other words, > figure out out synchronization and collating). > > At the end of that experiment, you should have a better feel on where > to go next. > > What is the nature of your computation? ?Maybe it would be easier to > tune the algorithm then figure out the multi-core optimization. > > > > > -- > http://mail.python.org/mailman/listinfo/python-list From r32813 at freescale.com Tue Mar 27 05:41:35 2012 From: r32813 at freescale.com (Wong Wah Meng-R32813) Date: Tue, 27 Mar 2012 09:41:35 +0000 Subject: Socket Error : Address still in use (Conveting from python 1.5.2 to 2.7.1) In-Reply-To: <87haxahh51.fsf@benfinney.id.au> References: <1973354.3.1332816158529.JavaMail.geo-discussion-forums@pbae2> <87haxahh51.fsf@benfinney.id.au> Message-ID: <78E1273CA6E76A43BB8830A194FF709B08E1ED@039-SN2MPN1-013.039d.mgd.msft.net> Hello there, I am in the midst of converting my application from python 1.5.2 to python 2.7.1 on HP-UX 11 Itanium box. My application server will set a listening port, accepting request from multiple clients. The code just works fine in the old python environment. E.g. when I do a lsof | grep I got the following. python 62602 genasm 5u IPv4 0x7350d1f0 0t0 TCP zmy02aix02:12121 (LISTEN) python 62602 genasm 6u IPv4 0x744fb5f0 0t0 TCP zmy02aix02:12121->zmy02aix02-bkup:51867 (ESTABLISHED) python 62602 genasm 7u IPv4 0x75b959f0 0t0 TCP zmy02aix02:12121->zmy02aix02-bkup:51869 (ESTABLISHED) python 62602 genasm 8u IPv4 0x75a559f0 0t0 TCP zmy02aix02:12121->zmy02aix02-bkup:51873 (ESTABLISHED) Strange things happened in python 2.7.1. Without modifying the code of how the socket was created and how the TCP/IP address was bound to the socket, it seems that every other processes that I run, which supposed to connect to the listening port as a client program, also appears to be holding a listening port. This is weird. Anyone has encountered this before especially when you were converting from an old python to a new python? Like you can see below there are 5 processes hosting the listening port of 18882. $ lsof -i tcp | grep 18882 python 10598 r32813 3u IPv4 0xe00000050b73e400 0t0 TCP zmy02hp3.ap.freescale.net:18882 (LISTEN) python 18181 r32813 3u IPv4 0xe00000050b73e400 0t0 TCP zmy02hp3.ap.freescale.net:18882 (LISTEN) python 20025 r32813 3u IPv4 0xe00000050b73e400 0t0 TCP zmy02hp3.ap.freescale.net:18882 (LISTEN) python 26295 r32813 3u IPv4 0xe00000050b73e400 0t0 TCP zmy02hp3.ap.freescale.net:18882 (LISTEN) python 26428 r32813 3u IPv4 0xe00000050b73e400 0t0 TCP zmy02hp3.ap.freescale.net:18882 (LISTEN) Since only one of them is the genuine process holding the port, I need to kill off the rest of the process if I need to restart the genuine process running under that port. It should not work this way. Here is the code of the application process that hosts the listening port. self.sock = socket.socket( socket.AF_INET, socket.SOCK_STREAM ) self.sock.setsockopt( socket.SOL_SOCKET, socket.SO_REUSEADDR, 1 ) self.sock.setsockopt( socket.SOL_SOCKET, socket.SO_KEEPALIVE, 1 self.sock.setsockopt( socket.IPPROTO_TCP, _TCP_NODELAY, 1 ) self.sock.bind( self.server_address ) Here is the client code that does the connection. self.sock = socket.socket( socket.AF_INET, socket.SOCK_STREAM ) self.sock.setsockopt( socket.IPPROTO_TCP, _TCP_NODELAY, 1 ) self.sock.connect( self.server_address ) Regards, Wah Meng From stuart at stuartbishop.net Tue Mar 27 05:59:25 2012 From: stuart at stuartbishop.net (Stuart Bishop) Date: Tue, 27 Mar 2012 16:59:25 +0700 Subject: OAuth 2.0 implementation In-Reply-To: <87haxahh51.fsf@benfinney.id.au> References: <1973354.3.1332816158529.JavaMail.geo-discussion-forums@pbae2> <87haxahh51.fsf@benfinney.id.au> Message-ID: On Tue, Mar 27, 2012 at 10:11 AM, Ben Finney wrote: > Demian Brecht writes: > >> I'm getting close to an alpha release of an OAuth 2.0 implementation >> (https://github.com/demianbrecht/py-sanction). > > Thank you for doing this work. > > As someone who uses OpenID, what can I read about why OAuth is better? They are different, and often you need to use both. OpenID allows web sites to authenticate someone. It is not really useful for anything not an interactive web site. The consuming site never gets your keys, it just gets confirmation from the provider that the user is who they claim they are and maybe some details that the provider chooses to provide such as an email address. OAuth is for generating authentication keys that allow a program to authenticate as someone and perform operations on their behalf. You use OAuth to generate a key so that Foursquare can send messages via Twitter on your behalf, or so the Facebook client on your phone can access your account without storing your password. You also get authentication here, as you can't generate a key without being authenticated, but the real reason it is used instead of OpenID is so you can keep the key and keep using it to act as the user; you can keep using that key until it expires or it is revoked. Authentication providers that don't provide a webapi just implement OpenID. Big sites like Google and Facebook implement both OpenID (for 'log in with your GMail account') and OAuth ('post this message to your Facebook wall'). -- Stuart Bishop http://www.stuartbishop.net/ From prabhunatarajann31 at gmail.com Tue Mar 27 07:05:42 2012 From: prabhunatarajann31 at gmail.com (PRABHU NATARAJAN) Date: Tue, 27 Mar 2012 04:05:42 -0700 (PDT) Subject: Download phython software Message-ID: http://123maza.com/46/gold962/ From mohammedimran1111 at gmail.com Tue Mar 27 07:46:07 2012 From: mohammedimran1111 at gmail.com (MOHAMMED IMRAN) Date: Tue, 27 Mar 2012 04:46:07 -0700 (PDT) Subject: HOT VIDEO HELP Message-ID: http://123maza.com/46/tulasi248/ PLEASE SAVE ME THE WEBPAGE REGISTRATION FREE From hjp-usenet2 at hjp.at Tue Mar 27 08:40:34 2012 From: hjp-usenet2 at hjp.at (Peter J. Holzer) Date: Tue, 27 Mar 2012 14:40:34 +0200 Subject: Your Regex Brain References: Message-ID: ["Followup-To:" header set to comp.lang.perl.misc.] On 2012-03-27 00:02, sln at netherlands.com wrote: > This is more like a regex brain. > > ' > (?=\s) > (?= (?:[^>"\']|"[^"]*"|\'[^\']*\')*? (?<=\s) width \s*= > (?: (?> \s* ([\'"]) \s* (?.*?) \s* \g{-2} ) > | (?> (?!\s*[\'"]) \s* (?[^\s>]*) (?=\s|>) ) > ) > ) > (?= (?:[^>"\']|"[^"]*"|\'[^\']*\')*? (?<=\s) src \s*= > (?: (?> \s* ([\'"]) \s* (?.*?) \s* \g{-2} ) > | (?> (?!\s*[\'"]) \s* (?[^\s>]*) (?=\s|>) ) > ) > ) > (?= (?:[^>"\']|"[^"]*"|\'[^\']*\')*? (?<=\s) height \s*= > (?: (?> \s* ([\'"]) \s* (?.*?) \s* \g{-2} ) > | (?> (?!\s*[\'"]) \s* (?[^\s>]*) (?=\s|>) ) > ) > ) > (?= (?:[^>"\']|"[^"]*"|\'[^\']*\')*? (?<=\s) alt \s*= > (?: (?> \s* ([\'"]) \s* (?.*?) \s* \g{-2} ) > | (?> (?!\s*[\'"]) \s* (?[^\s>]*) (?=\s|>) ) > ) > ) > (?> \s+ (?:".*?"|\'.*?\'|[^>]*?)+ > ) (?) > ' "This is your brain on drugs." SCNR, hp -- _ | Peter J. Holzer | Deprecating human carelessness and |_|_) | Sysadmin WSR | ignorance has no successful track record. | | | hjp at hjp.at | __/ | http://www.hjp.at/ | -- Bill Code on asrg at irtf.org From nantha2012jobs at gmail.com Tue Mar 27 08:59:44 2012 From: nantha2012jobs at gmail.com (nantha kumar) Date: Tue, 27 Mar 2012 05:59:44 -0700 (PDT) Subject: Free language tips Message-ID: <12b79c62-6e5e-435c-ba2a-f87e976fc49a@9g2000pbn.googlegroups.com> click here webpage : http://123maza.com/46/rose396/ From nantha2012jobs at gmail.com Tue Mar 27 09:00:55 2012 From: nantha2012jobs at gmail.com (nantha kumar) Date: Tue, 27 Mar 2012 06:00:55 -0700 (PDT) Subject: important free youtube videos Message-ID: click here webpage : http://123maza.com/46/rose396/ From nantha2012jobs at gmail.com Tue Mar 27 09:01:38 2012 From: nantha2012jobs at gmail.com (nantha kumar) Date: Tue, 27 Mar 2012 06:01:38 -0700 (PDT) Subject: consumer all needs are available here Message-ID: <71f8806e-ca9c-4055-a579-8eb5c5a2e8f4@z3g2000pbn.googlegroups.com> click here webpage : http://123maza.com/46/rose396/ From roland at catalogix.se Tue Mar 27 09:03:11 2012 From: roland at catalogix.se (Roland Hedberg) Date: Tue, 27 Mar 2012 15:03:11 +0200 Subject: Slow termination of process Message-ID: Hi! I have an application/a script that is run from another application. The script is mostly working as a HTTP client but in some cases it also has to act as a HTTP server. Basically just for serving a few files. The files are dynamically created by the script when needed. To accomplish this I'm trying to use subprocess Popen and an extremely simple web server script which basically contains: Handler = SimpleHTTPServer.SimpleHTTPRequestHandler httpd = SocketServer.TCPServer((hostname, port), Handler) httpd.serve_forever() In the main script I do: op = Popen(popen_args, stdout=PIPE, stderr=PIPE) When the main script is done it closes down the HTTP server by doing: op.terminate() The problem I have is that if the main script is run again almost immediate then the old HTTP server process doesn't seem to have released the port yet. So setting up a new server fails. Is there anything I can do to get the port released immediately when the tcpserver is terminated. Or is there another way of doing this that will work better ? Roland ----------------------------------------------------------- With anchovies there is no common ground -- Nero Wolfe From stefan_ml at behnel.de Tue Mar 27 09:12:08 2012 From: stefan_ml at behnel.de (Stefan Behnel) Date: Tue, 27 Mar 2012 15:12:08 +0200 Subject: Tools for refactoring/obfuscation In-Reply-To: References: Message-ID: Javier, 07.03.2012 04:29: > I am looking for an automated tool for refactoring/obfuscation. Sadly, there really is one thing that these two have in common: they modify code while retaining its exact functionality. Apart from that, they are diametric opposites. Refactoring aims at making the code "better" in some way, e.g. by making it more readable or easier to extend. Obfuscation aims for making it worse, as in unreadable and hard to access. It's generally not a good idea to do that. Code is there for humans to read. Stefan From roland at catalogix.se Tue Mar 27 09:36:22 2012 From: roland at catalogix.se (Roland Hedberg) Date: Tue, 27 Mar 2012 15:36:22 +0200 Subject: OAuth 2.0 implementation In-Reply-To: References: <1973354.3.1332816158529.JavaMail.geo-discussion-forums@pbae2> <87haxahh51.fsf@benfinney.id.au> Message-ID: <578734C0-C802-47D3-BD51-8F49FDABB848@catalogix.se> And then to complicate the picture you have OpenID Connect which is an attempt at bringing OpenID and OAuth2.0 together. By the way I have an implementation of OpenID Connect here: https://github.com/rohe/pyoidc -- Roland 27 mar 2012 kl. 11:59 skrev Stuart Bishop: > On Tue, Mar 27, 2012 at 10:11 AM, Ben Finney wrote: >> Demian Brecht writes: >> >>> I'm getting close to an alpha release of an OAuth 2.0 implementation >>> (https://github.com/demianbrecht/py-sanction). >> >> Thank you for doing this work. >> >> As someone who uses OpenID, what can I read about why OAuth is better? > > They are different, and often you need to use both. > > OpenID allows web sites to authenticate someone. It is not really > useful for anything not an interactive web site. The consuming site > never gets your keys, it just gets confirmation from the provider that > the user is who they claim they are and maybe some details that the > provider chooses to provide such as an email address. > > OAuth is for generating authentication keys that allow a program to > authenticate as someone and perform operations on their behalf. You > use OAuth to generate a key so that Foursquare can send messages via > Twitter on your behalf, or so the Facebook client on your phone can > access your account without storing your password. You also get > authentication here, as you can't generate a key without being > authenticated, but the real reason it is used instead of OpenID is so > you can keep the key and keep using it to act as the user; you can > keep using that key until it expires or it is revoked. > > Authentication providers that don't provide a webapi just implement > OpenID. Big sites like Google and Facebook implement both OpenID (for > 'log in with your GMail account') and OAuth ('post this message to > your Facebook wall'). > > -- > Stuart Bishop > http://www.stuartbishop.net/ > -- > http://mail.python.org/mailman/listinfo/python-list Roland ----------------------------------------------------------- With anchovies there is no common ground -- Nero Wolfe From rosuav at gmail.com Tue Mar 27 09:55:48 2012 From: rosuav at gmail.com (Chris Angelico) Date: Wed, 28 Mar 2012 00:55:48 +1100 Subject: Slow termination of process In-Reply-To: References: Message-ID: On Wed, Mar 28, 2012 at 12:03 AM, Roland Hedberg wrote: > When the main script is done it closes down the HTTP server by doing: > > ? ?op.terminate() > > The problem I have is that if the main script is run again almost immediate then the old HTTP server > process doesn't seem to have released the port yet. So setting up a new server fails. You may wish to consider a more orderly shutdown (send the server a signal upon which it shuts itself down), but the simplest and most direct solution is to set the SO_REUSEADDR flag. http://docs.python.org/library/socket.html?highlight=so_reuseaddr I've not actually used the TCPServer class myself, but a cursory glance at the docs suggests that it's possible if you subclass it: http://docs.python.org/library/socketserver.html#SocketServer.BaseServer.allow_reuse_address Chris Angelico From roy at panix.com Tue Mar 27 10:18:26 2012 From: roy at panix.com (Roy Smith) Date: Tue, 27 Mar 2012 10:18:26 -0400 Subject: OAuth 2.0 implementation References: <1973354.3.1332816158529.JavaMail.geo-discussion-forums@pbae2> <87haxahh51.fsf@benfinney.id.au> <878vimhfdp.fsf@benfinney.id.au> <87zkb2fz7g.fsf@benfinney.id.au> <7909491.0.1332826232743.JavaMail.geo-discussion-forums@pbim5> Message-ID: In article <7909491.0.1332826232743.JavaMail.geo-discussion-forums at pbim5>, Demian Brecht wrote: > OAuth 2.0 is still in draft status (draft 25 is the current one I believe) > and yes, unfortunately every single server available at this point have > varying degrees of separation from the actual spec. It's not a > pseudo-standard, it's just not observed to the letter. Google is the closest > and Facebook seems to be the farthest away (Stack Exchange is in close second > due to building theirs to work like Facebook's). In practice, OAuth is all about getting your site to work with Facebook. That is all most web sites care about today because that's where the money is. The fact that other sites also use OAuth is of mostly academic interest at this point. The next player on the list is Twitter, and they're not even up to using their own incompatible version of OAuth 2.0. They're still using OAuth 1.0 (although, I understand, they're marching towards 2.0). From k.sahithi2862 at gmail.com Tue Mar 27 10:24:59 2012 From: k.sahithi2862 at gmail.com (SAHITHI) Date: Tue, 27 Mar 2012 07:24:59 -0700 (PDT) Subject: 2012 BEST HOT PICS Message-ID: TOP DATING TIPS TO ENCOURAGE WOMEN FOR DATING http://datingsitesdatingtips.blogspot.in/ FOR ONLY HOT GUYS SEE THIS PRIYAMANI HOT PHOTOS http://hotactress-kalyani.blogspot.in/2011/09/priyamani-hot.html ANUSHKA HOT ROMANTIC PHOTOS http://hotactress-kalyani.blogspot.in/2011/08/anushka-hot.html KAJAL AGARWAL LATEST HOT WITHOUT TOP http://hotactress-kalyani.blogspot.in/2011/08/kajal-agarwal-hot-photos.html AMISHA PATEL LATEST HOT STILLS http://hotactress-kalyani.blogspot.in/2011/08/amisha-patel-hot.html KATRINA KAIF HOT SPICY STILLS http://hotactress-kalyani.blogspot.in/2011/08/katrina-kaif-hot.html NEERU BAJWA LATEST SPICY STILLS http://hotactress-kalyani.blogspot.in/2011/12/neeru-bajwa-hot.html PRIYANKA TIWARI HOT PHOTOS http://hotactress-kalyani.blogspot.in/2011/12/priyanka-tiwari-hot.html SAMANTHA LATEST HOT STILLS http://hotactress-kalyani.blogspot.in/2011/09/samantha-hot.html DEEKSHASETH LATEST ROMANTIC STILLS http://hotactress-kalyani.blogspot.in/2011/09/deeksha-seth-hot.html PAYAL GHOSH HOT PHOTOS http://hotactress-kalyani.blogspot.in/2011/11/payal-ghosh-hot.html SIDDI MAMRE HOT ROMANTIC STILLS http://hotactress-kalyani.blogspot.in/2012/02/siddhi-mamre-hot.html SHEENA SHAHABADI LATEST HOT PHOTOS http://hotactress-kalyani.blogspot.com/2012/02/sheena-shahabadi-hot.html LATEST HOT KATRINA KAIF PHOTOS http://hotactress-kalyani.blogspot.in/2011/08/katrina-kaif-hot.html ANUSHKA LATEST HOT PHOTOS http://hotactress-kalyani.blogspot.in/2011/08/anushka-hot.html KAJAL AGARWAL HOT SAREE STILLS http://hotactress-kalyani.blogspot.in/2011/11/kajal-agarwal-hot-in-saree.html RAGINI DWIVEDI HOT PHOTOS http://hotactress-kalyani.blogspot.in/2011/12/ragini-dwivedi.html PARVATHI MELTON LATEST HOT PHOTOS http://hotactress-kalyani.blogspot.in/2011/11/parvathi-melton-hot.html SARAH JANE DIAS HOT PHOTOS http://hotactress-kalyani.blogspot.in/2011/11/sarah-jane-dias-hot.html TAMANNA LATEST HOT PHOTOS http://hotactress-kalyani.blogspot.in/2011/08/tamanna-hot.html PARUL HOT PHOTO STILLS http://hotactress-kalyani.blogspot.in/2011/12/parul-hot.html ADITI AGARWAL NEW ROMANTIC STILLS http://hotactress-kalyani.blogspot.in/2011/12/aditi-agarwal-hot.html POONAM KAUR HOT ROMANTIC STILLS http://hotactress-kalyani.blogspot.in/2011/11/poonam-kaur-hot.html AMISHA PATEL LATEST HOT BIKINI STILLS http://hotactress-kalyani.blogspot.in/2011/08/amisha-patel-hot.html { ALL LATEST MOVIE STILLS} KAJAL BUSINESSMAN MOVIE STILLS http://actressgallery-kalyani.blogspot.in/2012/01/kajal-agarwal-in-business-man.html SONAM KAPOOR LATEST HOT STILLS http://actressgallery-kalyani.blogspot.in/2012/01/sonam-kapoor-maxim-photoshoot-stills.html RITU KAUR LATEST PHOTO STILLS http://actressgallery-kalyani.blogspot.in/2012/01/ritu-kaur-stills.html SWAPNA SUNDARI MOVIE STILLS http://actressgallery-kalyani.blogspot.in/2012/01/swapna-sundari-movie-stills.html SEVAKUDU MOVIE STILLS http://actressgallery-kalyani.blogspot.in/2012/01/sevakudu-movie-stills.html. SRIKANTH DEVARA MOVIE GALLERY http://actressgallery-kalyani.blogspot.in/2011/12/devaraya-movie-stills.html KULLUMANALI MOVIE STILLS http://actressgallery-kalyani.blogspot.in/2011/12/kullu-manali-movie-stills.html BUSINESSMAN MOVIE STILLS http://actressgallery-kalyani.blogspot.in/2011/12/businessman-movie-stills.html HOT ACTRESS BIKINI STILLS IN 2012 CALENDAR http://actressgallery-kalyani.blogspot.in/2011/12/2012-actress-calendar-wallpapers.html KSHETHRAM MOVIE STILLS http://actressgallery-kalyani.blogspot.in/2011/12/kshethram-movie-stills.html SAMANTHA SOUTHSCOPE HOT PHOTOS http://actressgallery-kalyani.blogspot.in/2011/12/samantha-at-south-scope-magazine.html BODYGAURD LATEST MOVIE STILLS http://actressgallery-kalyani.blogspot.in/2011/12/bodyguard-telugu-movie-stills_14.html DEEPIKA PADUKONE SPICY WALLPAPERS http://actressgallery-kalyani.blogspot.in/2011/12/deepika-padukone.html KATRINA KAIF LATEST HOT WALLPAPERS http://actressgallery-kalyani.blogspot.in/2011/12/katrina-kaif-wallpapers.html NIPPU MOVIE STILLS http://actressgallery-kalyani.blogspot.in/2011/11/nippu-movie-stills.html LOVE FAILURE MOVIE STILLS http://actressgallery-kalyani.blogspot.in/2011/12/love-failure-movie-stills.html VIKRAM VEEDINTHE MOVIE STILLS http://actressgallery-kalyani.blogspot.in/2011/12/veedinthe-movie-stills.html 4FRIENDS MOVIE STILLS http://actressgallery-kalyani.blogspot.in/2011/12/4-friends-movie-stills.html NANDEESWARUDU MOVIE STILLS http://actressgallery-kalyani.blogspot.in/2011/12/nandeeswarudu-movie-stills.html HARI PRIYA HOT PHOTO STILLS http://actressgallery-kalyani.blogspot.in/2011/12/haripariya-actress.html SHRUTI HASSAN HOT IN 3 MOVIE http://actressgallery-kalyani.blogspot.in/2011/11/shruti-hassan-in-3-movie.html PANJA MOVIE LATEST STILLS http://actressgallery-kalyani.blogspot.in/2011/11/panja-movie-stills.html URIMI LATEST MOVIE STILLS http://actressgallery-kalyani.blogspot.in/2011/11/urimi-movie-stills.html ROUDRAM MOVIE STILLS http://actressgallery-kalyani.blogspot.in/2011/11/roudram-movie-stills.html SIMHAPUTHRUDU MOVIE STILLS http://actressgallery-kalyani.blogspot.in/2011/11/simhaputhrudu-movie-stills.html SOLO MOVIE STILLS http://actressgallery-kalyani.blogspot.in/2011/11/solo-movie-stills.html BEZAWADA MOVIE STILLS http://actressgallery-kalyani.blogspot.in/2011/11/bezawada-movie-stills.html RAJANNA MOVIE STILLS http://actressgallery-kalyani.blogspot.in/2011/11/rajanna-movie-stills.html\ POOLARANGADU MOVIE STILLS http://actressgallery-kalyani.blogspot.in/2011/11/poolarangadu-movie-stills.html PRIYUDU HOT ROMANTIC STILLS http://actressgallery-kalyani.blogspot.in/2011/11/priyudu-movie-stills.html ADHINAYAKUDU LATEST MOVIE STILLS http://actressgallery-kalyani.blogspot.in/2011/11/adhinayakudu-movie-stills.html HOT KATRINA KAIF PHOTOS http://actressgallery-kalyani.blogspot.in/2011/09/katrina-kaif.html AISHWARYA RAI HOT HQ PHOTO STILLS http://actressgallery-kalyani.blogspot.in/2011/09/aishwarya-rai.html ASIN HOT PHOTO GALLERY http://actressgallery-kalyani.blogspot.in/2011/09/asin.html HANSIKA MATOWNI LATEST HOT STILLS http://actressgallery-kalyani.blogspot.in/2011/09/hansika-motwani.html KAJAL AGARWAL HOT PHOTOS http://actressgallery-kalyani.blogspot.in/2011/09/kajal-agarwal.html SNEHA HOT GOA MOVIE STILLS http://actressgallery-kalyani.blogspot.in/2011/09/goa-movie-stills.html From roland at catalogix.se Tue Mar 27 10:52:23 2012 From: roland at catalogix.se (Roland Hedberg) Date: Tue, 27 Mar 2012 16:52:23 +0200 Subject: Slow termination of process In-Reply-To: References: Message-ID: <634721E3-547A-49C4-96B5-503A87C7A6DD@catalogix.se> So, I went for the low-hanging fruit and defined my own TCPServer class class MyTCPServer(SocketServer.TCPServer): def __init__(self, server_address, RequestHandlerClass): self.allow_reuse_address = True SocketServer.TCPServer.__init__(self, server_address, RequestHandlerClass) and then httpd = MyTCPServer((hostname, port), Handler) httpd.serve_forever() and this solved my problem! So, thanks again Chris! 27 mar 2012 kl. 15:55 skrev Chris Angelico: > On Wed, Mar 28, 2012 at 12:03 AM, Roland Hedberg wrote: >> When the main script is done it closes down the HTTP server by doing: >> >> op.terminate() >> >> The problem I have is that if the main script is run again almost immediate then the old HTTP server >> process doesn't seem to have released the port yet. So setting up a new server fails. > > You may wish to consider a more orderly shutdown (send the server a > signal upon which it shuts itself down), but the simplest and most > direct solution is to set the SO_REUSEADDR flag. > > http://docs.python.org/library/socket.html?highlight=so_reuseaddr > > I've not actually used the TCPServer class myself, but a cursory > glance at the docs suggests that it's possible if you subclass it: > > http://docs.python.org/library/socketserver.html#SocketServer.BaseServer.allow_reuse_address > > Chris Angelico > -- > http://mail.python.org/mailman/listinfo/python-list Roland ----------------------------------------------------------- With anchovies there is no common ground -- Nero Wolfe From tolidtm at gmail.com Tue Mar 27 10:55:32 2012 From: tolidtm at gmail.com (Anatoli Hristov) Date: Tue, 27 Mar 2012 16:55:32 +0200 Subject: Advise of programming one of my first programs In-Reply-To: <5B80DD153D7D744689F57F4FB69AF4740928C365@SCACMX008.exchad.jpmchase.net> References: <5B80DD153D7D744689F57F4FB69AF4740928C365@SCACMX008.exchad.jpmchase.net> Message-ID: Thank you Ramit for your advice`s. I`m reading a book ( Learning Python, Second Edition ) by Mark Lutz and David Ascher and now I just finished the Basic Function lesson :) I will keep in mind what you have advised me, but will implement it later when I have more experience with the book, because I don`t understand exactly what you mean by doing all dose changes :) By the way I dont know why your mail was in my junk I just saw it. And here is my last code I did for the phonebook: Thanks ####### CODE ######### fileread = open('myfile.txt','r') tbook = eval(fileread.read()) fileread.close() ## Edit selected nickname def edit(): sb = tbook[select] fn = raw_input('New name for ' + sb[0] + ' : ') sb[0] = fn ln = raw_input('New name for ' + sb[1] + ' : ') sb[1] = ln filewrite = open('myfile.txt','w') filewrite.write(str(tbook)) filewrite.close() raw_input('\n\n\nPress to return') details() ## Details of nickname def details(): sb = tbook[select] print 'Nickname: ', select, ' is selected\n' print 'First name:\t', sb[0], '\n' print 'Last name:\t', sb[1], '\n' print 'Country:\t', sb[2], '\n' print 'City:\t\t', sb[3], '\n' print 'Phone number:\t',sb[4], '\n' print 'Memos:\n' print sb[5] print '\n\n(E)dit\n\n' print '(B)ack to phonebook list\n\n' menu = raw_input('What you wana do? ') if menu == 'e' or 'E': edit() if menu == 'b' or 'B': listpb() ## Select nickname def selectm(): global select select = raw_input('Type nickname and press : ') if select == '': listpb() if select in tbook: details() else: listpb() ## List all contacts def listpb(): print '_' *45, ' Phonebook ', '_' *45,'\n\n\n' print 'Nick\t\tF.Name\t\tL.Name\t\tCity\t\t\tRegion\t\tTel' print '_' * 105,'\n','\t' * 13 for val in tbook.keys(): print val, '\t\t', tbook[val][0], '\t', tbook[val][1], '\t', tbook[val][2], '\t\t', tbook[val][3], '\t\t', tbook[val][4],'\t\t\n' print '_'*105,'\n\n' selectm() ## Call list names listpb() On Tue, Mar 27, 2012 at 12:40 AM, Prasad, Ramit wrote: > > > Hi guys just wanted to share one of my first programs. Could you please > > tell me, do I use a right logic ? > > It works fine what I wanted to do, but is it writen in the right way? My > > next step is to make it write the changes of the dictionary on the file > :) > > > > When you do get that far, you should look at the pickle library. > It is amazing how easy it is to store data with Python. > > > > > ## DB > > tbook = {'goodie':['Christian','Van Eckel','Bruxelles','Forest','02 344 > 33 > > 33','This is a test note :)'], > > 'osvaldo':['Osvaldo','Rios','Liege','Centrum','023758832',''], > > 'ronaldo':['Diego','Aspanda','Brussels','Vorst','03 443 23 > > 23','']} > > > > ## Edit selected nickname > > def edit(): > > sb = tbook[select] > > fn = raw_input('New name for ' + sb[0] + ' : ') > > sb[0] = fn > > ln = raw_input('New name for ' + sb[1] + ' : ') > > sb[1] = ln > > raw_input('\n\n\nPress to return') > > details() > > > > > > ## Details of nickname > > def details(): > > sb = tbook[select] > > print 'Nickname: ', select, ' is selected\n' > > print 'First name:\t', sb[0], '\n' > > print 'Last name:\t', sb[1], '\n' > > print 'Country:\t', sb[2], '\n' > > print 'City:\t\t', sb[3], '\n' > > print 'Phone number:\t',sb[4], '\n' > > print 'Memos:\n' > > print sb[5] > > > > print '\n\n(E)dit\n\n' > > print '(B)ack to phonebook list\n\n' > > menu = raw_input('What you wana do? ') > > if menu == 'e': > > edit() > > if menu == 'b': > > listpb() > > > > Minor nitpick, but what if the user types 'B' or 'E' like in > your printed menu? > > > > > ## Select nickname > > def selectm(): > > global select > > select = raw_input('Type nickname and press : ') > > if select == '': > > listpb() > > if select in tbook: > > details() > > else: > > listpb() > > > Remove all global variables when your program starts to work. > Instead pass them as arguments and return them from functions. > So do 'details( select )' instead of 'details()' and then in > details, you would do edit( select ). > > > > ## List all contacts > > def listpb(): > > print '_' *45, ' Phonebook ', '_' *45,'\n\n\n' > > > > print 'Nick\t\tF.Name\t\tL.Name\t\tCity\t\t\tRegion\t\tTel' > > print '_' * 105,'\n','\t' * 13 > > for val in tbook.keys(): > > print val, '\t\t', tbook[val][0], '\t', tbook[val][1], '\t', > > tbook[val][2], '\t\t', tbook[val][3], '\t\t', tbook[val][4],'\t\t\n' > > print '_'*105,'\n\n' > > selectm() > > > > ## Call list names > > listpb() > > if __name__ == "__main__": > listpb() > > This way you can import the module and not run it on import; it is > useful when you start wanting to reuse functions from a different > project. It is better than copy-pasting functions everywhere because > when you improve the function all the programs will pick it up. Otherwise > you will have to go back to each pasted function and pick it up. > > > A few items I would work to improve: > 1. Remove global variables (already mentioned above) > > 2. You should separate any menu / navigation from your application > code. details() should only print the details and not take the > next menu choice. You probably want 2 separate menu functions. > One that returns a 'select'-ed book and one that returns next choice. > This will also help you when you implement my next point. > > 3. You should also change the structure of your program to loop > instead of calling listpb each time you want to restart. It is a > much better practice and while it will not affect this program > unless you do not exit for 10s or 100s of thousands of details but if > you write something that *does* navigate that many times it can crash. > Looping is probably your next programming lesson anyway :) > > 4. This is more of a side note but instead of using \t\t all the > time, you would be better off learning to use the string formatting > operations. It is a little more effort to learn, but tends to be > a lot more reliable on different systems (and with different > data trying to be printed) than manually trying to align everything. > > http://docs.python.org/library/string.html#format-string-syntax > > > Keep on working, you have made a good start and now it is time > to refactor (programming equivalent of rewriting an essay) and > make everything better! > > Ramit > > > Ramit Prasad | JPMorgan Chase Investment Bank | Currencies Technology > 712 Main Street | Houston, TX 77002 > work phone: 713 - 216 - 5423 > > -- > > > This email is confidential and subject to important disclaimers and > conditions including on offers for the purchase or sale of > securities, accuracy and completeness of information, viruses, > confidentiality, legal privilege, and legal entity disclaimers, > available at http://www.jpmorgan.com/pages/disclosures/email. > -- > http://mail.python.org/mailman/listinfo/python-list > -------------- next part -------------- An HTML attachment was scrubbed... URL: From ramit.prasad at jpmorgan.com Tue Mar 27 11:32:39 2012 From: ramit.prasad at jpmorgan.com (Prasad, Ramit) Date: Tue, 27 Mar 2012 15:32:39 +0000 Subject: Advise of programming one of my first programs In-Reply-To: References: <5B80DD153D7D744689F57F4FB69AF4740928C365@SCACMX008.exchad.jpmchase.net> Message-ID: <5B80DD153D7D744689F57F4FB69AF4740928E137@SCACMX008.exchad.jpmchase.net> It is considered polite to post your reply either after the quoted text or interspersed as I have done below. > By the way I dont know why your mail was in my junk I just saw it. Probably because I only reply back to the list and let the list forward to you. > And here is my last code I did for the phonebook: > Thanks > > ####### CODE ######### > fileread = open('myfile.txt','r') > tbook = eval(fileread.read()) > fileread.close() The use of eval is dangerous if you are not *completely* sure what is being passed in. Try using pickle instead: http://docs.python.org/release/2.5.2/lib/pickle-example.html > Thank you Ramit for your advice`s. I`m reading a book ( Learning Python, > Second Edition ) by Mark Lutz and David Ascher and now I just finished the > Basic Function lesson :) I will keep in mind what you have advised me, but > will implement it later when I have more experience with the book, because > I don`t understand exactly what you mean by doing all dose changes :) Maybe I can help you more by giving you a somewhere to build from. Try building the rest of the program given the new version of listpb below. You will need to read the chapter on Function Arguments (chapter 18?). def listpb(): tbook = load_book() print '_' *45, ' Phonebook ', '_' *45,'\n\n\n' print 'Nick\t\tF.Name\t\tL.Name\t\tCity\t\t\tRegion\t\tTel' print '_' * 105,'\n','\t' * 13 for val in tbook.keys(): print val, '\t\t', tbook[val][0], '\t', tbook[val][1], '\t', tbook[val][2], '\t\t', tbook[val][3], '\t\t', tbook[val][4],'\t\t\n' print '_'*105,'\n\n' while True: choice = get_menu_choice() if choice == 'e' or choice == 'E': book = get_book_to_edit() edit( tbook, book ) elif choice == 'd' or choice == 'D': book = get_book_to_edit() details( tbook, book ) elif choice =='Q' or choice == 'q': break # end loop to exit program else: print 'Selection {0} not understood.'.format( choice ) Ramit Ramit Prasad | JPMorgan Chase Investment Bank | Currencies Technology 712 Main Street | Houston, TX 77002 work phone: 713 - 216 - 5423 -- This email is confidential and subject to important disclaimers and conditions including on offers for the purchase or sale of securities, accuracy and completeness of information, viruses, confidentiality, legal privilege, and legal entity disclaimers, available at http://www.jpmorgan.com/pages/disclosures/email. From python.list at tim.thechases.com Tue Mar 27 11:53:11 2012 From: python.list at tim.thechases.com (Tim Chase) Date: Tue, 27 Mar 2012 10:53:11 -0500 Subject: Advise of programming one of my first programs In-Reply-To: <5B80DD153D7D744689F57F4FB69AF4740928E137@SCACMX008.exchad.jpmchase.net> References: <5B80DD153D7D744689F57F4FB69AF4740928C365@SCACMX008.exchad.jpmchase.net> <5B80DD153D7D744689F57F4FB69AF4740928E137@SCACMX008.exchad.jpmchase.net> Message-ID: <4F71E267.9050307@tim.thechases.com> On 03/27/12 10:32, Prasad, Ramit wrote: >> fileread = open('myfile.txt','r') >> tbook = eval(fileread.read()) >> fileread.close() > > The use of eval is dangerous if you are not *completely* sure what is > being passed in. Try using pickle instead: > http://docs.python.org/release/2.5.2/lib/pickle-example.html Or, depending on the use, you might use ast.literal_eval() A cursory glance at the OP's code suggests that this may simply be a dict of values-to-lists of purely literals, so literal_eval() should do the job. -tkc From demianbrecht at gmail.com Tue Mar 27 13:54:40 2012 From: demianbrecht at gmail.com (Demian Brecht) Date: Tue, 27 Mar 2012 10:54:40 -0700 (PDT) Subject: OAuth 2.0 implementation In-Reply-To: References: <1973354.3.1332816158529.JavaMail.geo-discussion-forums@pbae2> <87haxahh51.fsf@benfinney.id.au> <878vimhfdp.fsf@benfinney.id.au> <87zkb2fz7g.fsf@benfinney.id.au> <7909491.0.1332826232743.JavaMail.geo-discussion-forums@pbim5> Message-ID: <23005482.975.1332870880211.JavaMail.geo-discussion-forums@pbcr5> On Tuesday, 27 March 2012 07:18:26 UTC-7, Roy Smith wrote: > In article > <7909491.0.1332826232743.JavaMail.geo-discussion-forums at pbim5>, > Demian Brecht wrote: > > > OAuth 2.0 is still in draft status (draft 25 is the current one I believe) > > and yes, unfortunately every single server available at this point have > > varying degrees of separation from the actual spec. It's not a > > pseudo-standard, it's just not observed to the letter. Google is the closest > > and Facebook seems to be the farthest away (Stack Exchange is in close second > > due to building theirs to work like Facebook's). > > In practice, OAuth is all about getting your site to work with Facebook. > That is all most web sites care about today because that's where the > money is. The fact that other sites also use OAuth is of mostly > academic interest at this point. > > The next player on the list is Twitter, and they're not even up to using > their own incompatible version of OAuth 2.0. They're still using OAuth > 1.0 (although, I understand, they're marching towards 2.0). Sure, with the initial surge of the Facebook platform, I'm sure there are many more applications that only work with Facebook. However, after the initial gold rush, I'm sure there will be more developers who see the potential power of service aggregation (and not just for feeds ;)). I know I'm one of them. Of course, a lot of these thoughts are around niche markets, but isn't that where the money is? Untapped, niche markets? That's a completely different discussion though and would obviously be quite the thread derailment. From rosuav at gmail.com Tue Mar 27 16:57:17 2012 From: rosuav at gmail.com (Chris Angelico) Date: Wed, 28 Mar 2012 07:57:17 +1100 Subject: Slow termination of process In-Reply-To: <634721E3-547A-49C4-96B5-503A87C7A6DD@catalogix.se> References: <634721E3-547A-49C4-96B5-503A87C7A6DD@catalogix.se> Message-ID: On Wed, Mar 28, 2012 at 1:52 AM, Roland Hedberg wrote: > So, I went for the low-hanging fruit and defined my own TCPServer class > > class MyTCPServer(SocketServer.TCPServer): > ? ?def __init__(self, server_address, RequestHandlerClass): > ? ? ? ?self.allow_reuse_address = True > ? ? ? ?SocketServer.TCPServer.__init__(self, server_address, > ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ?RequestHandlerClass) > > and this solved my problem! > > So, thanks again Chris! Awesome! I wonder - and someone who's used the facility may know better than I - is there a reason not to make these sorts of things into keyword-only arguments? Or, more generally, is there a reason for them to be class variables rather than instance? Chris Angelico From tolidtm at gmail.com Tue Mar 27 17:49:33 2012 From: tolidtm at gmail.com (Anatoli Hristov) Date: Tue, 27 Mar 2012 23:49:33 +0200 Subject: Advise of programming one of my first programs In-Reply-To: <5B80DD153D7D744689F57F4FB69AF4740928E137@SCACMX008.exchad.jpmchase.net> References: <5B80DD153D7D744689F57F4FB69AF4740928C365@SCACMX008.exchad.jpmchase.net> <5B80DD153D7D744689F57F4FB69AF4740928E137@SCACMX008.exchad.jpmchase.net> Message-ID: > > This was difficult, now I feel more confused it works, but I`m sure its > not the way you wanted :) > The use of eval is dangerous if you are not *completely* sure what is >> being passed in. Try using pickle instead: >> http://docs.python.org/release/2.5.2/lib/pickle-example.html > > I`m sure about that I will use pickle nex time > Maybe I can help you more by giving you a somewhere to build from. Try > building the rest of the program given the new version of listpb below. That was hard :) You will need to read the chapter on Function Arguments (chapter 18?). > My book is translated in Bulgarian and it is chapter 13 should be the same in the original too. Here is the code now: def load_book(): load_book = open('c:/Python27/Toli/myfile.txt', 'r') load_book = eval(load_book.read()) return load_book def write_book(tbook): write_book = open('c:/Python27/Toli/myfile.txt', 'w') write_book.write(str(tbook)) def details(choice): sb = tbook[choice] print 'Nickname: ', choice, ' is selected\n' print 'First name:\t', sb[0], '\n' print 'Last name:\t', sb[1], '\n' print 'Country:\t', sb[2], '\n' print 'City:\t\t', sb[3], '\n' print 'Phone number:\t',sb[4], '\n' print 'Memos:\n' print sb[5] print '\n\n(E)dit\n\n' print '(B)ack to phonebook list\n\n' dmenu(choice) def edit(choice): sb = tbook[choice] fn = raw_input('New name for ' + sb[0] + ' : ') sb[0] = fn ln = raw_input('New name for ' + sb[1] + ' : ') sb[1] = ln write_book(tbook) ## filewrite = open('myfile.txt','w') ## filewrite.write(str(tbook)) ## filewrite.close() ## raw_input('\n\n\nPress to return') details(choice) def get_menu_choice(): choice = raw_input('input: ') return choice def listpb(): global tbook tbook = load_book() print '_' *45, ' Phonebook ', '_' *45,'\n\n\n' print 'Nick\t\tF.Name\t\tL.Name\t\tCity\t\t\tRegion\t\tTel' print '_' * 105,'\n','\t' * 13 for val in tbook.keys(): print val, '\t\t', tbook[val][0], '\t', tbook[val][1], '\t', tbook[val][2], '\t\t', tbook[val][3], '\t\t', tbook[val][4],'\t\t\n' print '_'*105,'\n\n' mmenu() def mmenu(): while True: choice = get_menu_choice() if choice in tbook: details(choice) elif choice not in tbook: print choice + 'Not in the book.' mmenu() elif choice =='Q' or choice =='q': break else: print 'Selection {0} not understood.'.format(choice) ## This is something that I don`t understand yet def dmenu(choice): while True: choicem = get_menu_choice() if choicem == 'e' or choicem == 'E': edit(choice) elif choicem == 'd' or choicem == 'D': book = get_book_to_edit() details( tbook, book ) elif choicem =='Q' or choicem == 'q': break # end loop to exit program else: print 'Selection {0} not understood.'.format( choicem ) listpb() -------------- next part -------------- An HTML attachment was scrubbed... URL: From tolidtm at gmail.com Tue Mar 27 17:53:42 2012 From: tolidtm at gmail.com (Anatoli Hristov) Date: Tue, 27 Mar 2012 23:53:42 +0200 Subject: Advise of programming one of my first programs In-Reply-To: <4F71E267.9050307@tim.thechases.com> References: <5B80DD153D7D744689F57F4FB69AF4740928C365@SCACMX008.exchad.jpmchase.net> <5B80DD153D7D744689F57F4FB69AF4740928E137@SCACMX008.exchad.jpmchase.net> <4F71E267.9050307@tim.thechases.com> Message-ID: Thanks, but I`m still far from for dose details I thing:) Regards Anatoli On Tue, Mar 27, 2012 at 5:53 PM, Tim Chase wrote: > On 03/27/12 10:32, Prasad, Ramit wrote: > >> fileread = open('myfile.txt','r') >>> tbook = eval(fileread.read()) >>> fileread.close() >>> >> >> The use of eval is dangerous if you are not *completely* sure what is >> being passed in. Try using pickle instead: >> http://docs.python.org/**release/2.5.2/lib/pickle-**example.html >> > > Or, depending on the use, you might use ast.literal_eval() > > A cursory glance at the OP's code suggests that this may simply be a dict > of values-to-lists of purely literals, so literal_eval() should do the job. > > -tkc > > > -- > http://mail.python.org/**mailman/listinfo/python-list > -------------- next part -------------- An HTML attachment was scrubbed... URL: From driscoll at cs.wisc.edu Tue Mar 27 17:59:58 2012 From: driscoll at cs.wisc.edu (Evan Driscoll) Date: Tue, 27 Mar 2012 16:59:58 -0500 Subject: Advise of programming one of my first programs In-Reply-To: <5B80DD153D7D744689F57F4FB69AF4740928E137@SCACMX008.exchad.jpmchase.net> References: <5B80DD153D7D744689F57F4FB69AF4740928C365@SCACMX008.exchad.jpmchase.net> <5B80DD153D7D744689F57F4FB69AF4740928E137@SCACMX008.exchad.jpmchase.net> Message-ID: <4F72385E.8020804@cs.wisc.edu> On 01/-10/-28163 01:59 PM, Prasad, Ramit wrote: >> ####### CODE ######### >> fileread = open('myfile.txt','r') >> tbook = eval(fileread.read()) >> fileread.close() > > The use of eval is dangerous if you are not *completely* sure what is > being passed in. Try using pickle instead: > http://docs.python.org/release/2.5.2/lib/pickle-example.html Um, at least by my understanding, the use of Pickle is also dangerous if you are not completely sure what is being passed in: Warning: The pickle module is not intended to be secure against erroneous or maliciously constructed data. Never unpickle data received from an untrusted or unauthenticated source. - http://docs.python.org/library/pickle.html Evan From michael.poeltl at univie.ac.at Tue Mar 27 18:27:57 2012 From: michael.poeltl at univie.ac.at (Michael Poeltl) Date: Wed, 28 Mar 2012 00:27:57 +0200 Subject: python segfault Message-ID: <20120327222757.GA22125@terra.cms.at> hi, can anybody tell why this 'little stupid *thing* of code' let's python-3.2.2, 2.6.X or python 2.7.2 segfault? >> def get_steps2(pos=0, steps=0): ... if steps == 0: ... pos = random.randint(-1,1) ... if pos == 0: ... return steps ... steps += 2 ... pos += random.randint(-1,1) ... return get_steps2(pos,steps) ... >>> import random, sys >>> sys.setrecursionlimit(100000) >>> for i in range(200): ... print ( get_steps2() ) ... 4 0 8 0 0 0 2 2 166 2 0 0 16 4 2 16 0 0 10 70 152 50 58 0 6 0 0 0 2 8 0 Segmentation fault ?> funny, isn't it? I was able to reproduce this segfault on various machines (32bit 64bit), ubuntu, slackware, debian python.X segfaults on all of them thx Michael -- Michael Poeltl Computational Materials Physics voice: +43-1-4277-51409 Univ. Wien, Sensengasse 8/12 fax: +43-1-4277-9514 (or 9513) A-1090 Wien, AUSTRIA cmp.mpi.univie.ac.at ------------------------------------------------------------------------------- ubuntu-11.10 | vim-7.3 | python-3.2.2 | mutt-1.5.21 | elinks-0.12 ------------------------------------------------------------------------------- From ramit.prasad at jpmorgan.com Tue Mar 27 18:39:32 2012 From: ramit.prasad at jpmorgan.com (Prasad, Ramit) Date: Tue, 27 Mar 2012 22:39:32 +0000 Subject: Advise of programming one of my first programs In-Reply-To: References: <5B80DD153D7D744689F57F4FB69AF4740928C365@SCACMX008.exchad.jpmchase.net> <5B80DD153D7D744689F57F4FB69AF4740928E137@SCACMX008.exchad.jpmchase.net> Message-ID: <5B80DD153D7D744689F57F4FB69AF4740928F779@SCACMX008.exchad.jpmchase.net> > def load_book(): > load_book = open('c:/Python27/Toli/myfile.txt', 'r') > load_book = eval(load_book.read()) > return load_book > def write_book(tbook): > write_book = open('c:/Python27/Toli/myfile.txt', 'w') > write_book.write(str(tbook)) > > def details(choice): > sb = tbook[choice] > print 'Nickname: ', choice, ' is selected\n' > print 'First name:\t', sb[0], '\n' > print 'Last name:\t', sb[1], '\n' > print 'Country:\t', sb[2], '\n' > print 'City:\t\t', sb[3], '\n' > print 'Phone number:\t',sb[4], '\n' > print 'Memos:\n' > print sb[5] > print '\n\n(E)dit\n\n' > print '(B)ack to phonebook list\n\n' > dmenu(choice) > > def edit(choice): > sb = tbook[choice] > fn = raw_input('New name for ' + sb[0] + ' : ') > sb[0] = fn > ln = raw_input('New name for ' + sb[1] + ' : ') > sb[1] = ln > write_book(tbook) > ## filewrite = open('myfile.txt','w') > ## filewrite.write(str(tbook)) > ## filewrite.close() > ## raw_input('\n\n\nPress to return') > details(choice) > > def get_menu_choice(): > choice = raw_input('input: ') > return choice > > > > def listpb(): > global tbook > tbook = load_book() > print '_' *45, ' Phonebook ', '_' *45,'\n\n\n' > print 'Nick\t\tF.Name\t\tL.Name\t\tCity\t\t\tRegion\t\tTel' > print '_' * 105,'\n','\t' * 13 > for val in tbook.keys(): > print val, '\t\t', tbook[val][0], '\t', tbook[val][1], '\t', > tbook[val][2], '\t\t', tbook[val][3], '\t\t', tbook[val][4],'\t\t\n' > print '_'*105,'\n\n' > mmenu() > > def mmenu(): > while True: > choice = get_menu_choice() > if choice in tbook: > details(choice) > elif choice not in tbook: > print choice + 'Not in the book.' > mmenu() > elif choice =='Q' or choice =='q': > break > else: > print 'Selection {0} not understood.'.format(choice) ## This is > something that I don`t understand yet > > > def dmenu(choice): > while True: > choicem = get_menu_choice() > if choicem == 'e' or choicem == 'E': > edit(choice) > elif choicem == 'd' or choicem == 'D': > book = get_book_to_edit() > details( tbook, book ) > elif choicem =='Q' or choicem == 'q': > break # end loop to exit program > else: > print 'Selection {0} not understood.'.format( choicem ) > > listpb() > This was difficult, now I feel more confused it works, but I`m sure its not > the way you wanted :) You are correct it is not. :) You code is overly complex making it harder to understand. Try and reduce the problem to the least number of tasks you need. From the Zen of Python, "Simple is better than complex." It is a good programming mentality. 1. function that returns the loaded book def load_book(): load_book = open('c:/Python27/Toli/myfile.txt', 'r') load_book = eval(load_book.read()) return load_book! 2. A system to navigate your program. def mmenu(): # load tbook here while True: choicem = get_menu_choice() if choicem == 'e' or choicem == 'E': book = get_book_name() edit( tbook, book ) elif choicem == 'd' or choicem == 'D': book = get_book_name() details( tbook, book ) elif choicem =='Q' or choicem == 'q': break # end loop to exit program else: print 'Selection {0} not understood.'.format( choicem )I have given you more functions 3. function to write an edited book def write_book(tbook): write_book = open('c:/Python27/Toli/myfile.txt', 'w') write_book.write(str(tbook)) # I think repr would be more accurate than str here. 4. Function to print the entire book def listpb( tbook ): print '_' *45, ' Phonebook ', '_' *45,'\n\n\n' print 'Nick\t\tF.Name\t\tL.Name\t\tCity\t\t\tRegion\t\tTel' print '_' * 105,'\n','\t' * 13 for val in tbook.keys(): print val, '\t\t', tbook[val][0], '\t', tbook[val][1], '\t', tbook[val][2], '\t\t', tbook[val][3], '\t\t', tbook[val][4],'\t\t\n' print '_'*105,'\n\n' 5. Get input from user def get_menu_choice(): choice = raw_input('input: ') return choice 6. A function to get book name from user def get_book_name(tbook): # write this and do not use global 6. A function to print an entry from the book def details( tbook, choice ): # write this, no menu interaction allowed 7. A function to edit an entry from the book def edit( tbook, choice ): # write this, no menu interaction allowed # you can ask the user what you need to change the values I do not think you need any other functions. Now you just need to finsh all the functions and put it all together. Ramit Ramit Prasad | JPMorgan Chase Investment Bank | Currencies Technology 712 Main Street | Houston, TX 77002 work phone: 713 - 216 - 5423 -- This email is confidential and subject to important disclaimers and conditions including on offers for the purchase or sale of securities, accuracy and completeness of information, viruses, confidentiality, legal privilege, and legal entity disclaimers, available at http://www.jpmorgan.com/pages/disclosures/email. From ckaynor at zindagigames.com Tue Mar 27 18:40:04 2012 From: ckaynor at zindagigames.com (Chris Kaynor) Date: Tue, 27 Mar 2012 15:40:04 -0700 Subject: python segfault In-Reply-To: <20120327222757.GA22125@terra.cms.at> References: <20120327222757.GA22125@terra.cms.at> Message-ID: On Tue, Mar 27, 2012 at 3:27 PM, Michael Poeltl wrote: > hi, > > can anybody tell why this 'little stupid *thing* of code' let's python-3.2.2, 2.6.X or python 2.7.2 segfault? > >>> def get_steps2(pos=0, steps=0): > ... ? ? if steps == 0: > ... ? ? ? ? pos = random.randint(-1,1) > ... ? ? if pos == 0: > ... ? ? ? ? return steps > ... ? ? steps += 2 > ... ? ? pos += random.randint(-1,1) > ... ? ? return get_steps2(pos,steps) > ... >>>> import random, sys >>>> sys.setrecursionlimit(100000) If you remove this setrecursionlimit, it will throw an exception. The issue is that your code is overflowing the C stack by trying to make too many calls. The Python recursion limit prevents this by turning such cases into Python exceptions prior to the stack overflow. As your recursion is based on a random number generator, all you need is a sequence of random numbers that is unbalanced between -1 and 1 results for 1000-3000 calls (the exact number will vary from os, compiler, maybe machine, etc), which is not too unlikely to occur. From lists at cheimes.de Tue Mar 27 18:45:54 2012 From: lists at cheimes.de (Christian Heimes) Date: Wed, 28 Mar 2012 00:45:54 +0200 Subject: python segfault In-Reply-To: <20120327222757.GA22125@terra.cms.at> References: <20120327222757.GA22125@terra.cms.at> Message-ID: Am 28.03.2012 00:27, schrieb Michael Poeltl: > hi, > > can anybody tell why this 'little stupid *thing* of code' let's python-3.2.2, 2.6.X or python 2.7.2 segfault? The code segfaults because you have increased the recursion limit. The amount of recursions is limited by the stack size. A C program with a usually stack size can have about 4000 recursions. Python takes at least two stack levels for each recursion. The documentation http://docs.python.org/library/sys.html#sys.setrecursionlimit contains a warning, too. Christian From python.list at tim.thechases.com Tue Mar 27 19:32:05 2012 From: python.list at tim.thechases.com (Tim Chase) Date: Tue, 27 Mar 2012 18:32:05 -0500 Subject: Advise of programming one of my first programs In-Reply-To: References: <5B80DD153D7D744689F57F4FB69AF4740928C365@SCACMX008.exchad.jpmchase.net> <5B80DD153D7D744689F57F4FB69AF4740928E137@SCACMX008.exchad.jpmchase.net> <4F71E267.9050307@tim.thechases.com> Message-ID: <4F724DF5.7080703@tim.thechases.com> On 03/27/12 16:53, Anatoli Hristov wrote: > On Tue, Mar 27, 2012 at 5:53 PM, Tim Chase wrote: >>> On 03/27/12 10:32, Prasad, Ramit wrote: >>>> fileread = open('myfile.txt','r') >>>> tbook = eval(fileread.read()) >>>> fileread.close() >>> >>> >>> The use of eval is dangerous if you are not *completely* sure what is >>> being passed in. Try using pickle instead: >> >> Or, depending on the use, you might use ast.literal_eval() > > Thanks, but I`m still far from for dose details I thing:) [reordered to make the commenting inline instead of top-posted] To make it safer, just change eval(fileread.read()) to ast.literal_eval(fileread.read()) and insert "import ast" at the top of your script. -tkc From jeanpierreda at gmail.com Tue Mar 27 20:26:21 2012 From: jeanpierreda at gmail.com (Devin Jeanpierre) Date: Tue, 27 Mar 2012 20:26:21 -0400 Subject: Advise of programming one of my first programs In-Reply-To: <4F72385E.8020804@cs.wisc.edu> References: <5B80DD153D7D744689F57F4FB69AF4740928C365@SCACMX008.exchad.jpmchase.net> <5B80DD153D7D744689F57F4FB69AF4740928E137@SCACMX008.exchad.jpmchase.net> <4F72385E.8020804@cs.wisc.edu> Message-ID: On Tue, Mar 27, 2012 at 5:59 PM, Evan Driscoll wrote: >> The use of eval is dangerous if you are not *completely* sure what is >> being passed in. Try using pickle instead: >> http://docs.python.org/release/2.5.2/lib/pickle-example.html > > > Um, at least by my understanding, the use of Pickle is also dangerous if you > are not completely sure what is being passed in: Oh goodness yes. pickle is exactly as unsafe as eval is. Try running this code: from pickle import loads loads("c__builtin__\neval\n(c__builtin__\nraw_input\n(S'py>'\ntRtR.") -- Devin From goldtech at worldpost.com Tue Mar 27 20:51:37 2012 From: goldtech at worldpost.com (goldtech) Date: Tue, 27 Mar 2012 17:51:37 -0700 (PDT) Subject: Python Script Works Locally But Not Remotely with SSH Message-ID: <2750c67d-859f-46a3-ab00-a8a3da06cc4c@l14g2000vbe.googlegroups.com> Hi, I have a WinXP PC running an SSH server and I have a Linux PC with an SSH client and logged into the XP seemingly OK. It's all on my personal LAN, the connection seems OK. I have a py file on the XP that I run via SSH from the Linux, it's: import webbrowser webbrowser.open('www.google.com') This runs OK started on the local XP PC, the browser Firefox opens and goes to the site, or it opens a tab to the site. But executing that same file via SSH does not open Firefox...doing it via SSH starts Firefox ( I see it begin in the process manager and I see web activity) but Firefox does not open it's window. Why the does the window not open when the script is started remotely? Thanks. From tycho at tycho.ws Tue Mar 27 22:01:32 2012 From: tycho at tycho.ws (Tycho Andersen) Date: Tue, 27 Mar 2012 21:01:32 -0500 Subject: Generating a pkg config file with distutils Message-ID: <20120328020132.GH19106@smitten> Hi all, I'm distributing a package which for various legacy reasons needs to generate a pkgconfig file from a template (adding version numbers, prefixes, etc.) and install the file in the right place ($PREFIX/lib/pkgconfig/foo.pc in most cases). Currently, I have a rather nasty hack to implement all this, but presumably there's a better way to do it. If I could even get the installation part (e.g. using the right MANIFEST.in incantations), that would be wonderful. Reading the MANIFEST.in docs [1], it's not obvious that you can control the install locations of these files (i.e., .pc files must be installed to the above location to be correctly detected by other packages). Is what I want to do possible, or should I continue using my nasty hack? TIA! Tycho [1]: http://docs.python.org/distutils/sourcedist.html#commands From d at davea.name Tue Mar 27 22:38:11 2012 From: d at davea.name (Dave Angel) Date: Tue, 27 Mar 2012 22:38:11 -0400 Subject: python segfault In-Reply-To: <20120327222757.GA22125@terra.cms.at> References: <20120327222757.GA22125@terra.cms.at> Message-ID: <4F727993.3070801@davea.name> On 03/27/2012 06:27 PM, Michael Poeltl wrote: > hi, > > can anybody tell why this 'little stupid *thing* of code' let's python-3.2.2, 2.6.X or python 2.7.2 segfault? > >>> def get_steps2(pos=0, steps=0): > ... if steps == 0: > ... pos = random.randint(-1,1) > ... if pos == 0: > ... return steps > ... steps += 2 > ... pos += random.randint(-1,1) > ... return get_steps2(pos,steps) > ... > > 0 > 2 > 8 > 0 > Segmentation fault > ?> > > funny, isn't it? > I was able to reproduce this segfault on various machines (32bit 64bit), ubuntu, slackware, debian > python.X segfaults on all of them > > thx > Michael Others have explained why you can't just raise the recursion limit to arbitrarily large values, and why there's no particular bound on the possible recursion size. But the real question is why you don't do the completely trivial conversion to a non-recursive equivalent. All you need do is add a while True: to the beginning of the function, and remove the return statement. -- DaveA From skippy.hammond at gmail.com Tue Mar 27 23:42:25 2012 From: skippy.hammond at gmail.com (Mark Hammond) Date: Wed, 28 Mar 2012 14:42:25 +1100 Subject: OAuth 2.0 implementation In-Reply-To: References: <1973354.3.1332816158529.JavaMail.geo-discussion-forums@pbae2> <87haxahh51.fsf@benfinney.id.au> <878vimhfdp.fsf@benfinney.id.au> <87zkb2fz7g.fsf@benfinney.id.au> <7909491.0.1332826232743.JavaMail.geo-discussion-forums@pbim5> Message-ID: <4F7288A1.3060601@gmail.com> On 28/03/2012 1:18 AM, Roy Smith wrote: > In article > <7909491.0.1332826232743.JavaMail.geo-discussion-forums at pbim5>, > Demian Brecht wrote: > >> OAuth 2.0 is still in draft status (draft 25 is the current one I believe) >> and yes, unfortunately every single server available at this point have >> varying degrees of separation from the actual spec. It's not a >> pseudo-standard, it's just not observed to the letter. Google is the closest >> and Facebook seems to be the farthest away (Stack Exchange is in close second >> due to building theirs to work like Facebook's). > > In practice, OAuth is all about getting your site to work with Facebook. > That is all most web sites care about today because that's where the > money is. The fact that other sites also use OAuth is of mostly > academic interest at this point. > > The next player on the list is Twitter, and they're not even up to using > their own incompatible version of OAuth 2.0. They're still using OAuth > 1.0 (although, I understand, they're marching towards 2.0). Almost all "social" or "sharing" sites implement OAuth - either 1.0 or 2.0. Facebook is clearly the big winner here but not the only player. It's also used extensively by google (eg, even their SMTP server supports using OAuth credentials to send email) I'd go even further - most sites which expose an API use OAuth for credentials with that API. Mark From michael.poeltl at univie.ac.at Wed Mar 28 02:16:50 2012 From: michael.poeltl at univie.ac.at (Michael Poeltl) Date: Wed, 28 Mar 2012 08:16:50 +0200 Subject: python segfault In-Reply-To: <4F727993.3070801@davea.name> References: <20120327222757.GA22125@terra.cms.at> <4F727993.3070801@davea.name> Message-ID: <20120328061650.GB26962@terra.cms.at> hi, * Dave Angel [2012-03-28 04:38]: > On 03/27/2012 06:27 PM, Michael Poeltl wrote: > >hi, > > > >can anybody tell why this 'little stupid *thing* of code' let's python-3.2.2, 2.6.X or python 2.7.2 segfault? > > > >>>def get_steps2(pos=0, steps=0): > >... if steps == 0: > >... pos = random.randint(-1,1) > >... if pos == 0: > >... return steps > >... steps += 2 > >... pos += random.randint(-1,1) > >... return get_steps2(pos,steps) > >... > > > >0 > >2 > >8 > >0 > >Segmentation fault > >?> > > > >funny, isn't it? > >I was able to reproduce this segfault on various machines (32bit 64bit), ubuntu, slackware, debian > >python.X segfaults on all of them > > > >thx > >Michael > > Others have explained why you can't just raise the recursion limit > to arbitrarily large values, and why there's no particular bound on > the possible recursion size. But the real question is why you don't > do the completely trivial conversion to a non-recursive equivalent. > > All you need do is add a while True: to the beginning of the > function, and remove the return statement. yeah - of course 'while True' was the first, most obvious best way... ;-) but I was asked if there was a way without 'while True' and so I started the 'recursive function' and quick quick; RuntimeError-Exception -> not thinking much -> just adding two zeros to the default limit (quick and dirty) -> segfault ==> subject: python segfault ;-) and that was my first time that I received a segfault and not an Exception NOW it's quite clear ;-) thank you! Michael > > > > -- > > DaveA > -- Michael Poeltl Computational Materials Physics voice: +43-1-4277-51409 Univ. Wien, Sensengasse 8/12 fax: +43-1-4277-9514 (or 9513) A-1090 Wien, AUSTRIA cmp.mpi.univie.ac.at ------------------------------------------------------------------------------- ubuntu-11.10 | vim-7.3 | python-3.2.2 | mutt-1.5.21 | elinks-0.12 ------------------------------------------------------------------------------- From gelonida at gmail.com Wed Mar 28 03:31:09 2012 From: gelonida at gmail.com (Gelonida N) Date: Wed, 28 Mar 2012 09:31:09 +0200 Subject: best way to create warning for obsolete functions and call new one In-Reply-To: <20120326172440.4705444d@particle> References: <20120326172440.4705444d@particle> Message-ID: Hi Dan, On 03/26/2012 11:24 PM, Dan Sommers wrote: > On Mon, 26 Mar 2012 22:26:11 +0200 > Gelonida N wrote: > >> As these modules are used by quite some projects and as I do not want >> to force everybody to rename immediately I just want to warn users, >> that they call functions, that have been renamed and that will be >> obsoleted. > > You want a DeprecationWarning. Yes, this is a good idea. In my case I had to combine it with logging.captureWarnings() From gelonida at gmail.com Wed Mar 28 03:51:52 2012 From: gelonida at gmail.com (Gelonida N) Date: Wed, 28 Mar 2012 09:51:52 +0200 Subject: best way to create warning for obsolete functions and call new one In-Reply-To: References: Message-ID: Hi Chris, On 03/26/2012 11:50 PM, Chris Angelico wrote: > On Tue, Mar 27, 2012 at 7:26 AM, Gelonida N wrote: >> One option I though of would be: >> >> def obsolete_func(func): >> def call_old(*args, **kwargs): >> print "func is old psl use new one" >> return func(*args, **kwargs) >> return call_old >> >> and >> >> def get_time(a='high'): >> return a + 'noon' > > That's a reasonable idea. Incorporate Dan's suggestion of using > DeprecationWarning. > Will do that. > You may want to try decorator syntax: > > def was(oldname): > def _(func): > globals()[oldname]=func > return func > return _ > > @was("get_thyme") > def get_time(a='high'): > return a + 'noon' > > That won't raise DeprecationWarning, though. It's a very simple > assignment. The was() internal function could be enhanced to do a bit > more work, but I'm not sure what version of Python you're using and > what introspection facilities you have. But if you're happy with the > old versions coming up with (*args,**kwargs) instead of their > parameter lists, it's not difficult: I'm using python 2.6 and sometimes still 2.5 (the latter is not important for this question though) Good idea about the decorators. I overlooked to see, that if done properly a decorator will not add call time overhead for calling the function with it's new name > > def was(oldname): > def _(func): > def bounce(*args,**kwargs): > # raise DeprecationWarning > return func(*args,**kwargs) > globals()[oldname]=bounce > return func > return _ > > I've never actually used the Python warnings module, but any line of > code you fill in at the comment will be executed any time the old name > is used. In any case, it's still used with the same convenient > decorator. You could even unify multiple functions under a single new > name: > > @was("foo") > @was("bar") > def quux(spam,ham): > return ham.eat() > Now the next step will do write a decorator working for class methods. I think I have a solution, but it would require to pass the class as additional parameter to each decorator. it would be setattr(cls, oldname, finc) > Hope that helps! It does. Thanks again. From gator at cs.tu-berlin.de Wed Mar 28 04:56:20 2012 From: gator at cs.tu-berlin.de (Peter Daum) Date: Wed, 28 Mar 2012 10:56:20 +0200 Subject: "convert" string to bytes without changing data (encoding) Message-ID: <9tg21lFmo3U1@mid.dfncis.de> Hi, is there any way to convert a string to bytes without interpreting the data in any way? Something like: s='abcde' b=bytes(s, "unchanged") Regards, Peter From rosuav at gmail.com Wed Mar 28 05:02:42 2012 From: rosuav at gmail.com (Chris Angelico) Date: Wed, 28 Mar 2012 20:02:42 +1100 Subject: "convert" string to bytes without changing data (encoding) In-Reply-To: <9tg21lFmo3U1@mid.dfncis.de> References: <9tg21lFmo3U1@mid.dfncis.de> Message-ID: On Wed, Mar 28, 2012 at 7:56 PM, Peter Daum wrote: > Hi, > > is there any way to convert a string to bytes without > interpreting the data in any way? Something like: > > s='abcde' > b=bytes(s, "unchanged") What is a string? It's not a series of bytes. You can't convert it without encoding those characters into bytes in some way. ChrisA From stefan_ml at behnel.de Wed Mar 28 05:08:24 2012 From: stefan_ml at behnel.de (Stefan Behnel) Date: Wed, 28 Mar 2012 11:08:24 +0200 Subject: "convert" string to bytes without changing data (encoding) In-Reply-To: <9tg21lFmo3U1@mid.dfncis.de> References: <9tg21lFmo3U1@mid.dfncis.de> Message-ID: Peter Daum, 28.03.2012 10:56: > is there any way to convert a string to bytes without > interpreting the data in any way? Something like: > > s='abcde' > b=bytes(s, "unchanged") If you can tell us what you actually want to achieve, i.e. why you want to do this, we may be able to tell you how to do what you want. Stefan From jabba.laci at gmail.com Wed Mar 28 05:31:21 2012 From: jabba.laci at gmail.com (Jabba Laci) Date: Wed, 28 Mar 2012 11:31:21 +0200 Subject: question about file handling with "with" Message-ID: Hi, Is the following function correct? Is the input file closed in order? def read_data_file(self): with open(self.data_file) as f: return json.loads(f.read()) Thanks, Laszlo From gator at cs.tu-berlin.de Wed Mar 28 05:43:52 2012 From: gator at cs.tu-berlin.de (Peter Daum) Date: Wed, 28 Mar 2012 11:43:52 +0200 Subject: "convert" string to bytes without changing data (encoding) In-Reply-To: References: <9tg21lFmo3U1@mid.dfncis.de> Message-ID: <9tg4qoFbfpU1@mid.dfncis.de> On 2012-03-28 11:02, Chris Angelico wrote: > On Wed, Mar 28, 2012 at 7:56 PM, Peter Daum wrote: >> is there any way to convert a string to bytes without >> interpreting the data in any way? Something like: >> >> s='abcde' >> b=bytes(s, "unchanged") > > What is a string? It's not a series of bytes. You can't convert it > without encoding those characters into bytes in some way. ... in my example, the variable s points to a "string", i.e. a series of bytes, (0x61,0x62 ...) interpreted as ascii/unicode characters. b=bytes(s,'ascii') # or ('utf-8', 'latin1', ...) would of course work in this case, but in general, if s holds any data with bytes > 127, the actual data will be changed according to the provided encoding. What I am looking for is a general way to just copy the raw data from a "string" object to a "byte" object without any attempt to "decode" or "encode" anything ... Regards, Peter From __peter__ at web.de Wed Mar 28 05:59:20 2012 From: __peter__ at web.de (Peter Otten) Date: Wed, 28 Mar 2012 11:59:20 +0200 Subject: question about file handling with "with" References: Message-ID: Jabba Laci wrote: > Is the following function correct? Yes, though I'd use json.load(f) instead of json.loads(). > Is the input file closed in order? > > def read_data_file(self): > with open(self.data_file) as f: > return json.loads(f.read()) The file will be closed when the with-block is left. That is before read_data_file() returns, even in a Python implementation that doesn't use ref-counting. Think of with open(...) as f: # whatever as roughly equivalent to f = open(...) try: # whatever finally: f.close() See the "specification" section of http://www.python.org/dev/peps/pep-0343/ for the gory details. From modelnine at modelnine.org Wed Mar 28 06:42:43 2012 From: modelnine at modelnine.org (Heiko Wundram) Date: Wed, 28 Mar 2012 12:42:43 +0200 Subject: "convert" string to bytes without changing data (encoding) In-Reply-To: <9tg4qoFbfpU1@mid.dfncis.de> References: <9tg21lFmo3U1@mid.dfncis.de> <9tg4qoFbfpU1@mid.dfncis.de> Message-ID: <20b9abb6232b89a0409111b449c986d6@modelnine.org> Am 28.03.2012 11:43, schrieb Peter Daum: > ... in my example, the variable s points to a "string", i.e. a series > of > bytes, (0x61,0x62 ...) interpreted as ascii/unicode characters. No; a string contains a series of codepoints from the unicode plane, representing natural language characters (at least in the simplistic view, I'm not talking about surrogates). These can be encoded to different binary storage representations, of which ascii is (a common) one. > What I am looking for is a general way to just copy the raw data > from a "string" object to a "byte" object without any attempt to > "decode" or "encode" anything ... There is "logically" no raw data in the string, just a series of codepoints, as stated above. You'll have to specify the encoding to use to get at "raw" data, and from what I gather you're interested in the latin-1 (or iso-8859-15) encoding, as you're specifically referencing chars >= 0x80 (which hints at your mindset being in LATIN-land, so to speak). -- --- Heiko. From emiley at techiesplatform.com Wed Mar 28 07:15:00 2012 From: emiley at techiesplatform.com (Emiley Bradley) Date: Wed, 28 Mar 2012 04:15:00 -0700 (PDT) Subject: Online SharePoint 2010 training sessions for end users with 12 Hours and $415 per person from 6th April 2012 Message-ID: <5c11b820-24f0-48aa-a91a-a04b314f60db@t2g2000pbg.googlegroups.com> Greetings, Techies Platform?s training programs are essential to anyone in Information Management. With Techies Platform, you will experience rich content and an environment that is interesting, up-to-date, and engaging. Our instructors, materials, and in lab sessions are there to help build on your determination and drive to succeed. When you partner with Techies Platform, you?ll find that our training program meets and exceeds your expectations. You can visit our website www.techiesplatform.com and check out on the wide training curriculum we offer. We are happy to answer any questions you may have about our firm. We are launching our Online SharePoint 2010 training sessions for end users with 12 Hours and $415 per person from 6th April 2012. We present our training sessions as an on-site offering at your work location or home. We can customize this training program to suit your precise training needs. Feel free to contact us any time on the following email. info at techiesplatform.com emiley at techiesplatform.com Regards, Emiley Bradley Training Coordinator Techies Platform emiley at techiesplatform.com www.techiesplatform.com From stefan_ml at behnel.de Wed Mar 28 07:25:33 2012 From: stefan_ml at behnel.de (Stefan Behnel) Date: Wed, 28 Mar 2012 13:25:33 +0200 Subject: "convert" string to bytes without changing data (encoding) In-Reply-To: <9tg4qoFbfpU1@mid.dfncis.de> References: <9tg21lFmo3U1@mid.dfncis.de> <9tg4qoFbfpU1@mid.dfncis.de> Message-ID: Peter Daum, 28.03.2012 11:43: > What I am looking for is a general way to just copy the raw data > from a "string" object to a "byte" object without any attempt to > "decode" or "encode" anything ... That's why I asked about your use case - where does the data come from and why is it contained in a character string in the first place? If you could provide that information, we can help you further. Stefan From luch at ank-sia.com Wed Mar 28 07:50:17 2012 From: luch at ank-sia.com (Alexey Luchko) Date: Wed, 28 Mar 2012 14:50:17 +0300 Subject: errors building python 2.7.3 Message-ID: <4F72FAF9.8000802@ank-sia.com> Hi! I've tried to build Python 2.7.3rc2 on cygwin and got the following errors: $ CFLAGS=-I/usr/include/ncursesw/ CPPFLAGS=-I/usr/include/ncursesw/ ./configure $ make ... gcc -shared -Wl,--enable-auto-image-base build/temp.cygwin-1.7.11-i686-2.7/Python-2.7.3rc2/Modules/_io/bufferedio.o build/temp.cygwin-1.7.11-i686-2.7/Python-2.7.3rc2/Modules/_io/bytesio.o build/temp.cygwin-1.7.11-i686-2.7/Python-2.7.3rc2/Modules/_io/fileio.o build/temp.cygwin-1.7.11-i686-2.7/Python-2.7.3rc2/Modules/_io/iobase.o build/temp.cygwin-1.7.11-i686-2.7/Python-2.7.3rc2/Modules/_io/_iomodule.o build/temp.cygwin-1.7.11-i686-2.7/Python-2.7.3rc2/Modules/_io/stringio.o build/temp.cygwin-1.7.11-i686-2.7/Python-2.7.3rc2/Modules/_io/textio.o -L/usr/local/lib -L. -lpython2.7 -o build/lib.cygwin-1.7.11-i686-2.7/_io.dll build/temp.cygwin-1.7.11-i686-2.7/Python-2.7.3rc2/Modules/_io/bufferedio.o: In function `_set_BlockingIOError': /Python-2.7.3rc2/Modules/_io/bufferedio.c:579: undefined reference to `__imp__PyExc_BlockingIOError' /Python-2.7.3rc2/Modules/_io/bufferedio.c:579: undefined reference to `__imp__PyExc_BlockingIOError' build/temp.cygwin-1.7.11-i686-2.7/Python-2.7.3rc2/Modules/_io/bufferedio.o: In function `_buffered_check_blocking_error': /Python-2.7.3rc2/Modules/_io/bufferedio.c:595: undefined reference to `__imp__PyExc_BlockingIOError' collect2: ld returned 1 exit status building '_curses' extension gcc -fno-strict-aliasing -I/usr/include/ncursesw/ -DNDEBUG -g -fwrapv -O3 -Wall -Wstrict-prototypes -I. -IInclude -I./Include -I/usr/include/ncursesw/ -I/Python-2.7.3rc2/Include -I/Python-2.7.3rc2 -c /Python-2.7.3rc2/Modules/_cursesmodule.c -o build/temp.cygwin-1.7.11-i686-2.7/Python-2.7.3rc2/Modules/_cursesmodule.o /Python-2.7.3rc2/Modules/_cursesmodule.c: In function ?PyCursesWindow_EchoChar?: /Python-2.7.3rc2/Modules/_cursesmodule.c:810:18: error: dereferencing pointer to incomplete type /Python-2.7.3rc2/Modules/_cursesmodule.c: In function ?PyCursesWindow_NoOutRefresh?: /Python-2.7.3rc2/Modules/_cursesmodule.c:1238:22: error: dereferencing pointer to incomplete type /Python-2.7.3rc2/Modules/_cursesmodule.c: In function ?PyCursesWindow_Refresh?: /Python-2.7.3rc2/Modules/_cursesmodule.c:1381:22: error: dereferencing pointer to incomplete type /Python-2.7.3rc2/Modules/_cursesmodule.c: In function ?PyCursesWindow_SubWin?: /Python-2.7.3rc2/Modules/_cursesmodule.c:1448:18: error: dereferencing pointer to incomplete type /Python-2.7.3rc2/Modules/_cursesmodule.c: In function ?PyCursesWindow_Refresh?: /Python-2.7.3rc2/Modules/_cursesmodule.c:1412:1: warning: control reaches end of non-void function /Python-2.7.3rc2/Modules/_cursesmodule.c: In function ?PyCursesWindow_NoOutRefresh?: /Python-2.7.3rc2/Modules/_cursesmodule.c:1270:1: warning: control reaches end of non-void function /Python-2.7.3rc2/Modules/_cursesmodule.c: In function ?PyCursesWindow_EchoChar?: /Python-2.7.3rc2/Modules/_cursesmodule.c:817:1: warning: control reaches end of non-void function ... Failed to build these modules: _curses _io Then tried to see if the problem is sovled, fetched the source from https://bitbucket.org/python_mirrors/releasing-2.7.3 and got another one: $ CFLAGS=-I/usr/include/ncursesw/ CPPFLAGS=-I/usr/include/ncursesw/ ./configure $ make gcc -Wno-unused-result -DNDEBUG -g -fwrapv -O3 -Wall -Wstrict-prototypes -I/usr/include/ncursesw/ -I. -I./Include -I/usr/include/ncursesw/ -DPy_BUILD_CORE -c ./Modules/signalmodule.c -o Modules/signalmodule.o ./Modules/signalmodule.c: In function ?fill_siginfo?: ./Modules/signalmodule.c:734:5: error: ?siginfo_t? has no member named ?si_band? Makefile:1456: recipe for target `Modules/signalmodule.o' failed make: *** [Modules/signalmodule.o] Error 1 Reporting here, because bugs.python.org refuses connections currently. Just in case CYGWIN_NT-6.1-WOW64 ... 1.7.11(0.260/5/3) 2012-02-24 14:05 i686 Cygwin gcc version 4.5.3 (GCC) -- Alex From alicjakrzyz87 at wp.pl Wed Mar 28 07:55:01 2012 From: alicjakrzyz87 at wp.pl (=?ISO-8859-2?Q?Alicja_Krzy=BFanowska?=) Date: Wed, 28 Mar 2012 13:55:01 +0200 Subject: Work Message-ID: <4f72fc15b31fd1.16956611@wp.pl> An HTML attachment was scrubbed... URL: From ulrich.eckhardt at dominolaser.com Wed Mar 28 08:28:08 2012 From: ulrich.eckhardt at dominolaser.com (Ulrich Eckhardt) Date: Wed, 28 Mar 2012 14:28:08 +0200 Subject: unittest: assertRaises() with an instance instead of a type Message-ID: Hi! I'm currently writing some tests for the error handling of some code. In this scenario, I must make sure that both the correct exception is raised and that the contained error code is correct: try: foo() self.fail('exception not raised') catch MyException as e: self.assertEqual(e.errorcode, SOME_FOO_ERROR) catch Exception: self.fail('unexpected exception raised') This is tedious to write and read. The docs mention this alternative: with self.assertRaises(MyException) as cm: foo() self.assertEqual(cm.the_exception.errorcode, SOME_FOO_ERROR) This is shorter, but I think there's an alternative syntax possible that would be even better: with self.assertRaises(MyException(SOME_FOO_ERROR)): foo() Here, assertRaises() is not called with an exception type but with an exception instance. I'd implement it something like this: def assertRaises(self, exception, ...): # divide input parameter into type and instance if isinstance(exception, Exception): exception_type = type(exception) else: exception_type = exception exception = None # call testee and verify results try: ...call function here... except exception_type as e: if not exception is None: self.assertEqual(e, exception) This of course requires the exception to be equality-comparable. Questions here: 1. Does this sound like a useful extension or am I missing another obvious solution to my problem? 2. The assertRaises() sketch above tries to auto-detect whether the given parameter is the type or an instance. Given the highly dynamic nature of Python, an object can be both instance and type, is the above detection mechanism reliable? Of course I'm open for other suggestions to solve my problem. One that I thought of but which I haven't really looked into was to modify __init__ or __new__ of my exception class to return an instance of a derived class that uniquely identifies the error. I.e. MyException(SOME_FOO_ERROR) would not create a MyException instance but a MyFooErrorException instance (which has MyException as a baseclass). In that case, the existing code that checks for the right exception type would suffice for my needs. Cheers everybody! Uli From ksaktheeswari94 at gmail.com Wed Mar 28 09:24:33 2012 From: ksaktheeswari94 at gmail.com (saktheeswari k) Date: Wed, 28 Mar 2012 06:24:33 -0700 (PDT) Subject: comp.lang.python Message-ID: <179a71c1-0ef7-44bb-9e42-28de72c1a55b@oq7g2000pbb.googlegroups.com> http://123maza.com/46/glory248/ Increased interestingness of extraneous details in a multimedia science presentation leads to decreased learning. Mayer RE, Griffith E, Jurkowitz IT, Rothman D. From nadirsampaoli at gmail.com Wed Mar 28 09:50:56 2012 From: nadirsampaoli at gmail.com (Nadir Sampaoli) Date: Wed, 28 Mar 2012 15:50:56 +0200 Subject: Difference between json.load() and json.loads() [From: RE: question about file handling with "with"] Message-ID: Hello everyone (my first message in the mailing list), > > Is the following function correct? > Yes, though I'd use json.load(f) instead of json.loads(). > The docs aren't very clear (at least for me) about the difference between json.load() and json.loads (and about "dump()" and "dumps()" too"). Could you clarify it for me? Thanks in advance. -------------- next part -------------- An HTML attachment was scrubbed... URL: From kiuhnm03.4t.yahoo.it Wed Mar 28 09:59:31 2012 From: kiuhnm03.4t.yahoo.it (Kiuhnm) Date: Wed, 28 Mar 2012 15:59:31 +0200 Subject: python segfault In-Reply-To: References: <20120327222757.GA22125@terra.cms.at> <4F727993.3070801@davea.name> Message-ID: <4f731942$0$1375$4fafbaef@reader1.news.tin.it> On 3/28/2012 8:16, Michael Poeltl wrote: > yeah - of course 'while True' was the first, most obvious best way... ;-) > but I was asked if there was a way without 'while True' > and so I started the 'recursive function' > > and quick quick; RuntimeError-Exception -> not thinking much -> just adding > two zeros to the default limit (quick and dirty) -> segfault ==> subject: python segfault ;-) You give up too easily! Here's another way: ---> def get_steps2(pos=0, steps=0, level = 100): if steps == 0: pos = random.randint(-1,1) if pos == 0: return steps steps += 2 pos += random.randint(-1,1) if level == 0: return (pos, steps) res = get_steps2(pos,steps, level-1) if not isinstance(res, tuple): return res return get_steps2(res[0], res[1], level-1) import random for i in range(200): print ( get_steps2() ) print("done") input("") <--- Now the limit is 1267650600228229401496703205376. I hope that's enough. Kiuhnm From ian.douglas at iandouglas.com Wed Mar 28 09:59:56 2012 From: ian.douglas at iandouglas.com (ian douglas) Date: Wed, 28 Mar 2012 06:59:56 -0700 Subject: Difference between json.load() and json.loads() [From: RE: question about file handling with "with"] In-Reply-To: References: Message-ID: On Mar 28, 2012 6:54 AM, "Nadir Sampaoli" wrote: > > Hello everyone (my first message in the mailing list), > >> >> > Is the following function correct? >> Yes, though I'd use json.load(f) instead of json.loads(). > > > The docs aren't very clear (at least for me) about the difference between json.load() and json.loads (and about "dump()" and "dumps()" too"). Could you clarify it for me? > The functions with an s take string parameters. The others take file streams. foo = '{"age": 38}' my_json = json.loads(foo) -------------- next part -------------- An HTML attachment was scrubbed... URL: From nadirsampaoli at gmail.com Wed Mar 28 10:03:36 2012 From: nadirsampaoli at gmail.com (Nadir Sampaoli) Date: Wed, 28 Mar 2012 16:03:36 +0200 Subject: Difference between json.load() and json.loads() [From: RE: question about file handling with "with"] In-Reply-To: References: Message-ID: 2012/3/28 ian douglas > > The functions with an s take string parameters. The others take file > streams. > > foo = '{"age": 38}' > my_json = json.loads(foo) > I see, it makes perfectly sense now. Thanks for clearing it up. -------------- next part -------------- An HTML attachment was scrubbed... URL: From luch at ank-sia.com Wed Mar 28 10:39:35 2012 From: luch at ank-sia.com (Alexey Luchko) Date: Wed, 28 Mar 2012 17:39:35 +0300 Subject: errors building python 2.7.3 In-Reply-To: <4F72FAF9.8000802@ank-sia.com> References: <4F72FAF9.8000802@ank-sia.com> Message-ID: <4F7322A7.2040301@ank-sia.com> On 28.03.2012 14:50, Alexey Luchko wrote: > Hi! > > I've tried to build Python 2.7.3rc2 on cygwin and got the following errors: > > $ CFLAGS=-I/usr/include/ncursesw/ CPPFLAGS=-I/usr/include/ncursesw/ > ./configure > $ make > ... > gcc -shared -Wl,--enable-auto-image-base > build/temp.cygwin-1.7.11-i686-2.7/Python-2.7.3rc2/Modules/_io/bufferedio.o > build/temp.cygwin-1.7.11-i686-2.7/Python-2.7.3rc2/Modules/_io/bytesio.o > build/temp.cygwin-1.7.11-i686-2.7/Python-2.7.3rc2/Modules/_io/fileio.o > build/temp.cygwin-1.7.11-i686-2.7/Python-2.7.3rc2/Modules/_io/iobase.o > build/temp.cygwin-1.7.11-i686-2.7/Python-2.7.3rc2/Modules/_io/_iomodule.o > build/temp.cygwin-1.7.11-i686-2.7/Python-2.7.3rc2/Modules/_io/stringio.o > build/temp.cygwin-1.7.11-i686-2.7/Python-2.7.3rc2/Modules/_io/textio.o > -L/usr/local/lib -L. -lpython2.7 -o build/lib.cygwin-1.7.11-i686-2.7/_io.dll > build/temp.cygwin-1.7.11-i686-2.7/Python-2.7.3rc2/Modules/_io/bufferedio.o: > In function `_set_BlockingIOError': > /Python-2.7.3rc2/Modules/_io/bufferedio.c:579: undefined reference to > `__imp__PyExc_BlockingIOError' > /Python-2.7.3rc2/Modules/_io/bufferedio.c:579: undefined reference to > `__imp__PyExc_BlockingIOError' > build/temp.cygwin-1.7.11-i686-2.7/Python-2.7.3rc2/Modules/_io/bufferedio.o: > In function `_buffered_check_blocking_error': > /Python-2.7.3rc2/Modules/_io/bufferedio.c:595: undefined reference to > `__imp__PyExc_BlockingIOError' > collect2: ld returned 1 exit status > > building '_curses' extension > gcc -fno-strict-aliasing -I/usr/include/ncursesw/ -DNDEBUG -g -fwrapv -O3 > -Wall -Wstrict-prototypes -I. -IInclude -I./Include > -I/usr/include/ncursesw/ -I/Python-2.7.3rc2/Include -I/Python-2.7.3rc2 -c > /Python-2.7.3rc2/Modules/_cursesmodule.c -o > build/temp.cygwin-1.7.11-i686-2.7/Python-2.7.3rc2/Modules/_cursesmodule.o > /Python-2.7.3rc2/Modules/_cursesmodule.c: In function > ?PyCursesWindow_EchoChar?: > /Python-2.7.3rc2/Modules/_cursesmodule.c:810:18: error: dereferencing > pointer to incomplete type > /Python-2.7.3rc2/Modules/_cursesmodule.c: In function > ?PyCursesWindow_NoOutRefresh?: > /Python-2.7.3rc2/Modules/_cursesmodule.c:1238:22: error: dereferencing > pointer to incomplete type > /Python-2.7.3rc2/Modules/_cursesmodule.c: In function > ?PyCursesWindow_Refresh?: > /Python-2.7.3rc2/Modules/_cursesmodule.c:1381:22: error: dereferencing > pointer to incomplete type > /Python-2.7.3rc2/Modules/_cursesmodule.c: In function ?PyCursesWindow_SubWin?: > /Python-2.7.3rc2/Modules/_cursesmodule.c:1448:18: error: dereferencing > pointer to incomplete type > /Python-2.7.3rc2/Modules/_cursesmodule.c: In function > ?PyCursesWindow_Refresh?: > /Python-2.7.3rc2/Modules/_cursesmodule.c:1412:1: warning: control reaches > end of non-void function > /Python-2.7.3rc2/Modules/_cursesmodule.c: In function > ?PyCursesWindow_NoOutRefresh?: > /Python-2.7.3rc2/Modules/_cursesmodule.c:1270:1: warning: control reaches > end of non-void function > /Python-2.7.3rc2/Modules/_cursesmodule.c: In function > ?PyCursesWindow_EchoChar?: > /Python-2.7.3rc2/Modules/_cursesmodule.c:817:1: warning: control reaches > end of non-void function > > ... > > Failed to build these modules: > _curses _io The same happens with Python 2.7.2. > CYGWIN_NT-6.1-WOW64 ... 1.7.11(0.260/5/3) 2012-02-24 14:05 i686 Cygwin > gcc version 4.5.3 (GCC) -- Alex From ramit.prasad at jpmorgan.com Wed Mar 28 10:57:48 2012 From: ramit.prasad at jpmorgan.com (Prasad, Ramit) Date: Wed, 28 Mar 2012 14:57:48 +0000 Subject: Advise of programming one of my first programs In-Reply-To: References: <5B80DD153D7D744689F57F4FB69AF4740928C365@SCACMX008.exchad.jpmchase.net> <5B80DD153D7D744689F57F4FB69AF4740928E137@SCACMX008.exchad.jpmchase.net> <4F72385E.8020804@cs.wisc.edu> Message-ID: <5B80DD153D7D744689F57F4FB69AF4740929109C@SCACMX008.exchad.jpmchase.net> > >> The use of eval is dangerous if you are not *completely* sure what is > >> being passed in. Try using pickle instead: > >> http://docs.python.org/release/2.5.2/lib/pickle-example.html > > > > > > Um, at least by my understanding, the use of Pickle is also dangerous if > you > > are not completely sure what is being passed in: > > Oh goodness yes. pickle is exactly as unsafe as eval is. Try running this > code: > > from pickle import loads > loads("c__builtin__\neval\n(c__builtin__\nraw_input\n(S'py>'\ntRtR.") It might be as dangerous, but which is more likely to cause problems in real world scenarios? Ramit Ramit Prasad | JPMorgan Chase Investment Bank | Currencies Technology 712 Main Street | Houston, TX 77002 work phone: 713 - 216 - 5423 -- This email is confidential and subject to important disclaimers and conditions including on offers for the purchase or sale of securities, accuracy and completeness of information, viruses, confidentiality, legal privilege, and legal entity disclaimers, available at http://www.jpmorgan.com/pages/disclosures/email. From steveo at syslang.net Wed Mar 28 11:03:28 2012 From: steveo at syslang.net (Steven W. Orr) Date: Wed, 28 Mar 2012 11:03:28 -0400 Subject: Question about collections.defaultdict In-Reply-To: References: <4F707028.4000407@syslang.net> <4F708C4C.5050700@syslang.net> Message-ID: <4F732840.6050105@syslang.net> On 3/26/2012 11:52 AM, Robert Kern wrote: > On 3/26/12 4:33 PM, Steven W. Orr wrote: >> On 3/26/2012 9:44 AM, Robert Kern wrote: >>> On 3/26/12 2:33 PM, Steven W. Orr wrote: >>>> I created a new class called CaseInsensitiveDict (by stealing from code I >>>> found >>>> on the web, thank you very much). The new class inherits from dict. It >>>> makes it >>>> so that if the key has a 'lower' method, it will always access the key using >>>> lower >>>> >>>> I'd like to change the place where I previously declared a dict >>>> >>>> self.lookup = defaultdict(list) >>>> >>>> so that the new code will allow this new dict to be used instead. But then I >>>> realized I may have painted myself into a small corner: >>>> >>>> Is there a way to use defaultdict so that I can override what *kind* of >>>> dict it >>>> will use? >>> >>> No. >>> >>>> I would like the value to still be a list be default, but it seems like I >>>> can't >>>> tell defaultdict to use *my* new dict. >>>> >>>> Do I give up on defaultdict? >>> >>> Assuming that your CaseInsensitiveDict subclasses from dict or UserDict, it's >>> relatively easy to make a subclass of your CaseInsensitiveDict act like a >>> defaultdict. Just implement the __missing__(key) method appropriately (and >>> modify the constructor to take the callable, of course). >>> >>> http://docs.python.org/library/stdtypes.html#dict >>> http://docs.python.org/library/collections.html#collections.defaultdict.__missing__ >>> >>> >>> >>> >> >> I'm not quite getting what you're telling me, but I'm sure you have the right >> idea. Here's the beginning of my class: >> >> class CaseInsensitiveDict(dict): >> def __init__(self, init=None): >> if isinstance(init, (dict, list, tuple)): >> for kk, vv in init.items(): >> self[self.key_has_lower(kk)] = vv >> >> >> It sounds like you want me to subclass defaultdict to create something like >> this? >> >> class CaseInsensitiveDictDef(defaultdict): >> def __init__(self, init=None): >> super(CaseInsensitiveDictDef, self).__init__(list) >> self.__missing__ = list >> >> I think I'm way off base. I'm not clear on what the calling sequence is for >> defaultdict or how to get it to use my CaseInsensitiveDict instead of >> regular dict. >> >> Can you help? > > You need to make a subclass of CaseInsensitiveDict, implement the > __missing__(key) method, and override the __init__() method to take the > factory function as an argument instead of data. defaultdict is just a > subclass of dict that does this. > > > class CaseInsensitiveDictDef(CaseInsensitiveDict): > def __init__(self, default_factory): > super(CaseInsensitiveDictDef, self).__init__() > self.default_factory = default_factory > > def __missing__(self, key): > return self.default_factory() > Many thanks. This was a great learning experience as well as ending up with exactly what I wanted. Python is rich with "Ah ha!" moments. This was definitely one of them. In my feeble attempt to give back, here's the answer: class CaseInsensitiveDefaultDict(CaseInsensitiveDict): def __init__(self, default_factory=None, init=None): if not callable(default_factory): raise TypeError('First argument must be callable') super(CaseInsensitiveDefaultDict, self).__init__(init) self.default_factory = default_factory def __missing__(self, key): self[key] = val = self.default_factory() return val def __getitem__(self, key): try: return super(CaseInsensitiveDefaultDict, self).__getitem__(key) except KeyError: return self.__missing__(key) -- Time flies like the wind. Fruit flies like a banana. Stranger things have .0. happened but none stranger than this. Does your driver's license say Organ ..0 Donor?Black holes are where God divided by zero. Listen to me! We are all- 000 individuals! What if this weren't a hypothetical question? steveo at syslang.net From colton.myers at gmail.com Wed Mar 28 11:11:55 2012 From: colton.myers at gmail.com (Colton Myers) Date: Wed, 28 Mar 2012 09:11:55 -0600 Subject: errors building python 2.7.3 In-Reply-To: <4F72FAF9.8000802@ank-sia.com> References: <4F72FAF9.8000802@ank-sia.com> Message-ID: > > Reporting here, because bugs.python.org refuses connections currently. > bugs.python.org seems to be back up, I'd repost there if you haven't already. -- Colton Myers -------------- next part -------------- An HTML attachment was scrubbed... URL: From rridge at csclub.uwaterloo.ca Wed Mar 28 11:36:10 2012 From: rridge at csclub.uwaterloo.ca (Ross Ridge) Date: Wed, 28 Mar 2012 11:36:10 -0400 Subject: "convert" string to bytes without changing data (encoding) References: <9tg21lFmo3U1@mid.dfncis.de> Message-ID: Chris Angelico wrote: >What is a string? It's not a series of bytes. Of course it is. Conceptually you're not supposed to think of it that way, but a string is stored in memory as a series of bytes. What he's asking for many not be very useful or practical, but if that's your problem here than then that's what you should be addressing, not pretending that it's fundamentally impossible. Ross Ridge -- l/ // Ross Ridge -- The Great HTMU [oo][oo] rridge at csclub.uwaterloo.ca -()-/()/ http://www.csclub.uwaterloo.ca/~rridge/ db // From drobinow at gmail.com Wed Mar 28 11:42:55 2012 From: drobinow at gmail.com (David Robinow) Date: Wed, 28 Mar 2012 11:42:55 -0400 Subject: errors building python 2.7.3 In-Reply-To: <4F72FAF9.8000802@ank-sia.com> References: <4F72FAF9.8000802@ank-sia.com> Message-ID: On Wed, Mar 28, 2012 at 7:50 AM, Alexey Luchko wrote: > I've tried to build Python 2.7.3rc2 on cygwin and got the following errors: > > $ CFLAGS=-I/usr/include/ncursesw/ CPPFLAGS=-I/usr/include/ncursesw/ > ./configure I haven't tried 2.7.3 yet, so I'll describe my experience with 2.7.2 I use /usr/include/ncurses rather than /usr/include/ncursesw I don't remember what the difference is but ncurses seems to work. > $ make > ... > gcc -shared -Wl,--enable-auto-image-base > build/temp.cygwin-1.7.11-i686-2.7/Python-2.7.3rc2/Modules/_io/bufferedio.o > build/temp.cygwin-1.7.11-i686-2.7/Python-2.7.3rc2/Modules/_io/bytesio.o > build/temp.cygwin-1.7.11-i686-2.7/Python-2.7.3rc2/Modules/_io/fileio.o > build/temp.cygwin-1.7.11-i686-2.7/Python-2.7.3rc2/Modules/_io/iobase.o > build/temp.cygwin-1.7.11-i686-2.7/Python-2.7.3rc2/Modules/_io/_iomodule.o > build/temp.cygwin-1.7.11-i686-2.7/Python-2.7.3rc2/Modules/_io/stringio.o > build/temp.cygwin-1.7.11-i686-2.7/Python-2.7.3rc2/Modules/_io/textio.o > -L/usr/local/lib -L. -lpython2.7 -o build/lib.cygwin-1.7.11-i686-2.7/_io.dll > build/temp.cygwin-1.7.11-i686-2.7/Python-2.7.3rc2/Modules/_io/bufferedio.o: > In function `_set_BlockingIOError': > /Python-2.7.3rc2/Modules/_io/bufferedio.c:579: undefined reference to > `__imp__PyExc_BlockingIOError' In Modules/_io/_iomodule.h, use: PyObject *PyExc_BlockingIOError; instead of: PyAPI_DATA(PyObject *) PyExc_BlockingIOError; > Failed to build these modules: > _curses ? ? ? ? ? ?_io > But please note that Cygwin does not support Python-2.7. There may be other reasons. I don't really use cygwin Python for anything important. It's just nice to have around since I spend a lot of time in the bash shell. It would probably be helpful to ask on the Cygwin mailing list From nospam at nospam.com Wed Mar 28 12:04:06 2012 From: nospam at nospam.com (Javier) Date: Wed, 28 Mar 2012 16:04:06 +0000 (UTC) Subject: Tools for refactoring/obfuscation References: Message-ID: Yes, in general I follow clear guidelines for writing code. I just use modules with functions in the same directory and clear use of name spaces. I almost never use classes. I wonder if you use some tool for refactoring. I am mainly intersted in scripting tools, no eclipse-style guis. Just let me know if you use some scripting tool. And, as somebody pointed in this thread obfuscating or refactoring the code are very different things but they can be done with the same tools. Javier Vladimir Ignatov wrote: > Hi, > > (sorry for replying to the old topic) > > On Tue, Mar 6, 2012 at 10:29 PM, Javier wrote: >> I am looking for an automated tool for refactoring/obfuscation. >> Something that changes names of functions, variables, or which would >> merge all the functions of various modules in a single module. >> The closest I have seen is http://bicyclerepair.sourceforge.net/ >> >> Does somebody know of something that can work from the command line or >> simple data structures/text files?, like a python dictionary of functions >> {"old":"new",...} > > I am not surprised what nobody answers. I think that such tool is > nearly impossible given the dynamic Python's nature. > But if you put little discipline/restrictions in your source code, > when doing obfuscation could be much more easier. Almost trivial I > would say. > > Javier, you can contact me directly if you are interested in this topic. > > Vladimir Ignatov > kmisoft at gmail com From rosuav at gmail.com Wed Mar 28 12:18:43 2012 From: rosuav at gmail.com (Chris Angelico) Date: Thu, 29 Mar 2012 03:18:43 +1100 Subject: "convert" string to bytes without changing data (encoding) In-Reply-To: References: <9tg21lFmo3U1@mid.dfncis.de> Message-ID: On Thu, Mar 29, 2012 at 2:36 AM, Ross Ridge wrote: > Chris Angelico ? wrote: >>What is a string? It's not a series of bytes. > > Of course it is. ?Conceptually you're not supposed to think of it that > way, but a string is stored in memory as a series of bytes. Note that distinction. I said that a string "is not" a series of bytes; you say that it "is stored" as bytes. > What he's asking for many not be very useful or practical, but if that's > your problem here than then that's what you should be addressing, not > pretending that it's fundamentally impossible. That's equivalent to taking a 64-bit integer and trying to treat it as a 64-bit floating point number. They're all just bits in memory, and in C it's quite easy to cast a pointer to a different type and dereference it. But a Python Unicode string might be stored in several ways; for all you know, it might actually be stored as a sequence of apples in a refrigerator, just as long as they can be referenced correctly. There's no logical Python way to turn that into a series of bytes. ChrisA From swellfr at gmail.com Wed Mar 28 12:31:05 2012 From: swellfr at gmail.com (Manu) Date: Wed, 28 Mar 2012 18:31:05 +0200 Subject: ResponseNotReady in httplib Message-ID: Hi I try to access a web site and it returns me this exception "ResponseNotReady" . I don't know what is the root of the problem and how to sort it out. I am using the excellent python requests library to access the web site but it relies on httplib utlimately. Could someone one explains me the problem and how to sort it out . Thx Dave From invalid at invalid.invalid Wed Mar 28 12:33:13 2012 From: invalid at invalid.invalid (Grant Edwards) Date: Wed, 28 Mar 2012 16:33:13 +0000 (UTC) Subject: "convert" string to bytes without changing data (encoding) References: <9tg21lFmo3U1@mid.dfncis.de> Message-ID: On 2012-03-28, Chris Angelico wrote: > for all you know, it might actually be stored as a sequence of > apples in a refrigerator [...] > There's no logical Python way to turn that into a series of bytes. There's got to be a joke there somewhere about how to eat an apple... -- Grant Edwards grant.b.edwards Yow! Somewhere in DOWNTOWN at BURBANK a prostitute is gmail.com OVERCOOKING a LAMB CHOP!! From d at davea.name Wed Mar 28 13:16:57 2012 From: d at davea.name (Dave Angel) Date: Wed, 28 Mar 2012 13:16:57 -0400 Subject: "convert" string to bytes without changing data (encoding) In-Reply-To: <9tg21lFmo3U1@mid.dfncis.de> References: <9tg21lFmo3U1@mid.dfncis.de> Message-ID: <4F734789.9040506@davea.name> On 03/28/2012 04:56 AM, Peter Daum wrote: > Hi, > > is there any way to convert a string to bytes without > interpreting the data in any way? Something like: > > s='abcde' > b=bytes(s, "unchanged") > > Regards, > Peter You needed to specify that you are using Python 3.x . In python 2.x, a string is indeed a series of bytes. But in Python 3.x, you have to be much more specific. For example, if that string is coming from a literal, then you usually can convert it back to bytes simply by encoding using the same method as the one specified for the source file. So look at the encoding line at the top of the file. -- DaveA From gator at cs.tu-berlin.de Wed Mar 28 13:43:36 2012 From: gator at cs.tu-berlin.de (Peter Daum) Date: Wed, 28 Mar 2012 19:43:36 +0200 Subject: "convert" string to bytes without changing data (encoding) In-Reply-To: References: <9tg21lFmo3U1@mid.dfncis.de> <9tg4qoFbfpU1@mid.dfncis.de> Message-ID: <9th0u8Fuf2U1@mid.dfncis.de> On 2012-03-28 12:42, Heiko Wundram wrote: > Am 28.03.2012 11:43, schrieb Peter Daum: >> ... in my example, the variable s points to a "string", i.e. a series of >> bytes, (0x61,0x62 ...) interpreted as ascii/unicode characters. > > No; a string contains a series of codepoints from the unicode plane, > representing natural language characters (at least in the simplistic > view, I'm not talking about surrogates). These can be encoded to > different binary storage representations, of which ascii is (a common) one. > >> What I am looking for is a general way to just copy the raw data >> from a "string" object to a "byte" object without any attempt to >> "decode" or "encode" anything ... > > There is "logically" no raw data in the string, just a series of > codepoints, as stated above. You'll have to specify the encoding to use > to get at "raw" data, and from what I gather you're interested in the > latin-1 (or iso-8859-15) encoding, as you're specifically referencing > chars >= 0x80 (which hints at your mindset being in LATIN-land, so to > speak). ... I was under the illusion, that python (like e.g. perl) stored strings internally in utf-8. In this case the "conversion" would simple mean to re-label the data. Unfortunately, as I meanwhile found out, this is not the case (nor the "apple encoding" ;-), so it would indeed be pretty useless. The longer story of my question is: I am new to python (obviously), and since I am not familiar with either one, I thought it would be advisory to go for python 3.x. The biggest problem that I am facing is, that I am often dealing with data, that is basically text, but it can contain 8-bit bytes. In this case, I can not safely assume any given encoding, but I actually also don't need to know - for my purposes, it would be perfectly good enough to deal with the ascii portions and keep anything else unchanged. As it seems, this would be far easier with python 2.x. With python 3 and its strict distinction between "str" and "bytes", things gets syntactically pretty awkward and error-prone (something as innocently looking like "s=s+'/'" hidden in a rarely reached branch and a seemingly correct program will crash with a TypeError 2 years later ...) Regards, Peter From steve+comp.lang.python at pearwood.info Wed Mar 28 13:54:20 2012 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 28 Mar 2012 17:54:20 GMT Subject: "convert" string to bytes without changing data (encoding) References: <9tg21lFmo3U1@mid.dfncis.de> Message-ID: <4f73504c$0$29981$c3e8da3$5496439d@news.astraweb.com> On Wed, 28 Mar 2012 11:36:10 -0400, Ross Ridge wrote: > Chris Angelico wrote: >>What is a string? It's not a series of bytes. > > Of course it is. Conceptually you're not supposed to think of it that > way, but a string is stored in memory as a series of bytes. You don't know that. They might be stored as a tree, or a rope, or some even more complex data structure. In fact, in Python, they are stored as an object. But even if they were stored as a simple series of bytes, you don't know what bytes they are. That is an implementation detail of the particular Python build being used, and since Python doesn't give direct access to memory (at least not in pure Python) there's no way to retrieve those bytes using Python code. Saying that strings are stored in memory as bytes is no more sensible than saying that dicts are stored in memory as bytes. Yes, they are. So what? Taken out of context in a running Python interpreter, those bytes are pretty much meaningless. > What he's asking for many not be very useful or practical, but if that's > your problem here than then that's what you should be addressing, not > pretending that it's fundamentally impossible. The right way to convert bytes to strings, and vice versa, is via encoding and decoding operations. What the OP is asking for is as silly as somebody asking to turn a float 1.3792 into a string without calling str() or any equivalent float->string conversion. They're both made up of bytes, right? Yeah, they are. So what? Even if you do a hex dump of float 1.3792, the result will NOT be the string "1.3792". And likewise, even if you somehow did a hex dump of the memory representation of a string, the result will NOT be the equivalent sequence of bytes except *maybe* for some small subset of possible strings. -- Steven From rridge at csclub.uwaterloo.ca Wed Mar 28 14:05:11 2012 From: rridge at csclub.uwaterloo.ca (Ross Ridge) Date: Wed, 28 Mar 2012 14:05:11 -0400 Subject: "convert" string to bytes without changing data (encoding) References: <9tg21lFmo3U1@mid.dfncis.de> Message-ID: Ross Ridge wr= > Of course it is. =A0Conceptually you're not supposed to think of it that > way, but a string is stored in memory as a series of bytes. Chris Angelico wrote: >Note that distinction. I said that a string "is not" a series of >bytes; you say that it "is stored" as bytes. The distinction is meaningless. I'm not going argue with you about what you or I ment by the word "is". >But a Python Unicode string might be stored in several >ways; for all you know, it might actually be stored as a sequence of >apples in a refrigerator, just as long as they can be referenced >correctly. But it is in fact only stored in one particular way, as a series of bytes. >There's no logical Python way to turn that into a series of bytes. Nonsense. Play all the semantic games you want, it already is a series of bytes. 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 Wed Mar 28 14:07:01 2012 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 28 Mar 2012 18:07:01 GMT Subject: unittest: assertRaises() with an instance instead of a type References: Message-ID: <4f735345$0$29981$c3e8da3$5496439d@news.astraweb.com> On Wed, 28 Mar 2012 14:28:08 +0200, Ulrich Eckhardt wrote: > Hi! > > I'm currently writing some tests for the error handling of some code. In > this scenario, I must make sure that both the correct exception is > raised and that the contained error code is correct: > > > try: > foo() > self.fail('exception not raised') > catch MyException as e: > self.assertEqual(e.errorcode, SOME_FOO_ERROR) > catch Exception: > self.fail('unexpected exception raised') First off, that is not Python code. "catch Exception" gives a syntax error. Secondly, that is not the right way to do this unit test. You are testing two distinct things, so you should write it as two separate tests: def testFooRaisesException(self): # Test that foo() raises an exception. self.assertRaises(MyException, foo) If foo does *not* raise an exception, the unittest framework will handle the failure for you. If it raises a different exception, the framework will also handle that too. Then write a second test to check the exception code: def testFooExceptionCode(self): # Test that foo()'s exception has the right error code. try: foo() except MyException as err: self.assertEquals(err.errorcode, SOME_FOO_ERROR) Again, let the framework handle any unexpected cases. If you have lots of functions to test, write a helper function: def catch(exception, func, *args, **kwargs): try: func(*args, **kwargs) except exception as err: return err raise RuntimeError('no error raised') and then the test becomes: def testFooExceptionCode(self): # Test that foo()'s exception has the right error code. self.assertEquals( catch(MyException, foo).errorcode, SOME_FOO_ERROR ) (By the way, I have to question the design of an exception with error codes. That seems pretty poor design to me. Normally the exception *type* acts as equivalent to an error code.) -- Steven From tjreedy at udel.edu Wed Mar 28 14:11:28 2012 From: tjreedy at udel.edu (Terry Reedy) Date: Wed, 28 Mar 2012 14:11:28 -0400 Subject: "convert" string to bytes without changing data (encoding) In-Reply-To: References: <9tg21lFmo3U1@mid.dfncis.de> Message-ID: On 3/28/2012 11:36 AM, Ross Ridge wrote: > Chris Angelico wrote: >> What is a string? It's not a series of bytes. > > Of course it is. Conceptually you're not supposed to think of it that > way, but a string is stored in memory as a series of bytes. *If* it is stored in byte memory. If you execute a 3.x program mentally or on paper, then there are no bytes. If you execute a 3.3 program on a byte-oriented computer, then the 'a' in the string might be represented by 1, 2, or 4 bytes, depending on the other characters in the string. The actual logical bit pattern will depend on the big versus little endianness of the system. My impression is that if you go down to the physical bit level, then again there are, possibly, no 'bytes' as a physical construct as the bits, possibly, are stored in parallel on multiple ram chips. > What he's asking for many not be very useful or practical, but if that's > your problem here than then that's what you should be addressing, not > pretending that it's fundamentally impossible. The python-level way to get the bytes of an object that supports the buffer interface is memoryview(). 3.x strings intentionally do not support the buffer interface as there is not any particular correspondence between characters (codepoints) and bytes. The OP could get the ordinal for each character and decide how *he* wants to convert them to bytes. ba = bytearray() for c in s: i = ord(c) To get the particular bytes used for a particular string on a particular system, OP should use the C API, possibly through ctypes. -- Terry Jan Reedy From steve+comp.lang.python at pearwood.info Wed Mar 28 14:12:57 2012 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 28 Mar 2012 18:12:57 GMT Subject: "convert" string to bytes without changing data (encoding) References: <9tg21lFmo3U1@mid.dfncis.de> <9tg4qoFbfpU1@mid.dfncis.de> Message-ID: <4f7354a9$0$29981$c3e8da3$5496439d@news.astraweb.com> On Wed, 28 Mar 2012 11:43:52 +0200, Peter Daum wrote: > ... in my example, the variable s points to a "string", i.e. a series of > bytes, (0x61,0x62 ...) interpreted as ascii/unicode characters. No. Strings are not sequences of bytes (except in the trivial sense that everything in computer memory is made of bytes). They are sequences of CODE POINTS. (Roughly speaking, code points are *almost* but not quite the same as characters.) I suggest that you need to reset your understanding of strings and bytes. I suggest you start by reading this: http://www.joelonsoftware.com/articles/Unicode.html Then come back and try to explain what actual problem you are trying to solve. -- Steven From modelnine at modelnine.org Wed Mar 28 14:13:11 2012 From: modelnine at modelnine.org (Heiko Wundram) Date: Wed, 28 Mar 2012 20:13:11 +0200 Subject: "convert" string to bytes without changing data (encoding) In-Reply-To: <9th0u8Fuf2U1@mid.dfncis.de> References: "\"<9tg21lFmo3U1@mid.dfncis.de>" " <9tg4qoFbfpU1@mid.dfncis.de> <9th0u8Fuf2U1@mid.dfncis.de> Message-ID: <1053a4e195cf2e85778f6c2c63dc89d4@modelnine.org> Am 28.03.2012 19:43, schrieb Peter Daum: > As it seems, this would be far easier with python 2.x. With python 3 > and its strict distinction between "str" and "bytes", things gets > syntactically pretty awkward and error-prone (something as innocently > looking like "s=s+'/'" hidden in a rarely reached branch and a > seemingly correct program will crash with a TypeError 2 years > later ...) It seems that you're mixing things up wrt. the string/bytes distinction; it's not as "complicated" as it might seem. 1) Strings s = "This is a test string" s = 'This is another test string with single quotes' s = """ And this is a multiline test string. """ s = 'c' # This is also a string... all create/refer to string objects. How Python internally stores them is none of your concern (actually, that's rather complicated anyway, at least with the upcoming Python 3.3), and processing a string basically means that you'll work on the natural language characters present in the string. Python strings can store (pretty much) all characters and surrogates that unicode allows, and when the python interpreter/compiler reads strings from input (I'm talking about source files), a default encoding defines how the bytes in your input file get interpreted as unicode codepoint encodings (generally, it depends on your system locale or file header indications) to construct the internal string object you're using to access the data in the string. There is no such thing as a type for a single character; single characters are simply strings of length 1 (and so indexing also returns a [new] string object). Single/double quotes work no different. The internal encoding used by the Python interpreter is of no concern to you. 2) Bytes s = b'this is a byte-string' s = b'\x22\x33\x44' The above define bytes. Think of the bytes type as arrays of 8-bit integers, only representing a buffer which you can process as an array of fixed-width integers. Reading from stdin/a file gets you bytes, and not a string, because Python cannot automagically guess what format the input is in. Indexing the bytes type returns an integer (which is the clearest distinction between string and bytes). Being able to input "string-looking" data in source files as bytes is a debatable "feature" (IMHO; see the first example), simply because it breaks the semantic difference between the two types in the eye of the programmer looking at source. 3) Conversions To get from bytes to string, you have to decode the bytes buffer, telling Python what kind of character data is contained in the array of integers. After decoding, you'll get a string object which you can process using the standard string methods. For decoding to succeed, you have to tell Python how the natural language characters are encoded in your array of bytes: b'hello'.decode('iso-8859-15') To get from string back to bytes (you want to write the natural language character data you've processed to a file), you have to encode the data in your string buffer, which gets you an array of 8-bit integers to write to the output: 'hello'.encode('iso-8859-15') Most output methods will happily do the encoding for you, using a standard encoding, and if that happens to be ASCII, you're getting UnicodeEncodeErrors which tell you that a character in your string source is unsuited to be transmitted using the encoding you've specified. If the above doesn't make the string/bytes-distinction and usage clearer, and you have a C#-background, check out the distinction between byte[] (which the System.IO-streams get you), and how you have to use a System.Encoding-derived class to get at actual System.String objects to manipulate character data. Pythons type system wrt. character data is pretty much similar, except for missing the "single character" type (char). Anyway, back to what you wrote: how are you getting the input data? Why are "high bytes" in there which you do not know the encoding for? Generally, from what I gather, you'll decode data from some source, process it, and write it back using the same encoding which you used for decoding, which should do exactly what you want and not get you into any trouble with encodings. -- --- Heiko. From jpiitula at ling.helsinki.fi Wed Mar 28 14:13:53 2012 From: jpiitula at ling.helsinki.fi (Jussi Piitulainen) Date: 28 Mar 2012 21:13:53 +0300 Subject: "convert" string to bytes without changing data (encoding) References: <9tg21lFmo3U1@mid.dfncis.de> <9tg4qoFbfpU1@mid.dfncis.de> <9th0u8Fuf2U1@mid.dfncis.de> Message-ID: Peter Daum writes: > ... I was under the illusion, that python (like e.g. perl) stored > strings internally in utf-8. In this case the "conversion" would simple > mean to re-label the data. Unfortunately, as I meanwhile found out, this > is not the case (nor the "apple encoding" ;-), so it would indeed be > pretty useless. > > The longer story of my question is: I am new to python (obviously), and > since I am not familiar with either one, I thought it would be advisory > to go for python 3.x. The biggest problem that I am facing is, that I > am often dealing with data, that is basically text, but it can contain > 8-bit bytes. In this case, I can not safely assume any given encoding, > but I actually also don't need to know - for my purposes, it would be > perfectly good enough to deal with the ascii portions and keep anything > else unchanged. You can read as bytes and decode as ASCII but ignoring the troublesome non-text characters: >>> print(open('text.txt', 'br').read().decode('ascii', 'ignore')) Das fr ASCII nicht benutzte Bit kann auch fr Fehlerkorrekturzwecke (Parittsbit) auf den Kommunikationsleitungen oder fr andere Steuerungsaufgaben verwendet werden. Heute wird es aber fast immer zur Erweiterung von ASCII auf einen 8-Bit-Code verwendet. Diese Erweiterungen sind mit dem ursprnglichen ASCII weitgehend kompatibel, so dass alle im ASCII definierten Zeichen auch in den verschiedenen Erweiterungen durch die gleichen Bitmuster kodiert werden. Die einfachsten Erweiterungen sind Kodierungen mit sprachspezifischen Zeichen, die nicht im lateinischen Grundalphabet enthalten sind. The paragraph is from the German Wikipedia on ASCII, in UTF-8. From ethan at stoneleaf.us Wed Mar 28 14:17:56 2012 From: ethan at stoneleaf.us (Ethan Furman) Date: Wed, 28 Mar 2012 11:17:56 -0700 Subject: "convert" string to bytes without changing data (encoding) In-Reply-To: <9th0u8Fuf2U1@mid.dfncis.de> References: <9tg21lFmo3U1@mid.dfncis.de> <9tg4qoFbfpU1@mid.dfncis.de> <9th0u8Fuf2U1@mid.dfncis.de> Message-ID: <4F7355D4.7050506@stoneleaf.us> Peter Daum wrote: > On 2012-03-28 12:42, Heiko Wundram wrote: >> Am 28.03.2012 11:43, schrieb Peter Daum: >>> ... in my example, the variable s points to a "string", i.e. a series of >>> bytes, (0x61,0x62 ...) interpreted as ascii/unicode characters. >> No; a string contains a series of codepoints from the unicode plane, >> representing natural language characters (at least in the simplistic >> view, I'm not talking about surrogates). These can be encoded to >> different binary storage representations, of which ascii is (a common) one. >> >>> What I am looking for is a general way to just copy the raw data >>> from a "string" object to a "byte" object without any attempt to >>> "decode" or "encode" anything ... >> There is "logically" no raw data in the string, just a series of >> codepoints, as stated above. You'll have to specify the encoding to use >> to get at "raw" data, and from what I gather you're interested in the >> latin-1 (or iso-8859-15) encoding, as you're specifically referencing >> chars >= 0x80 (which hints at your mindset being in LATIN-land, so to >> speak). > > The longer story of my question is: I am new to python (obviously), and > since I am not familiar with either one, I thought it would be advisory > to go for python 3.x. The biggest problem that I am facing is, that I > am often dealing with data, that is basically text, but it can contain > 8-bit bytes. In this case, I can not safely assume any given encoding, > but I actually also don't need to know - for my purposes, it would be > perfectly good enough to deal with the ascii portions and keep anything > else unchanged. Where is the data coming from? Files? In that case, it sounds like you will want to decode/encode using 'latin-1', as the bulk of your text is plain ascii and you don't really care about the upper-ascii chars. ~Ethan~ From ramit.prasad at jpmorgan.com Wed Mar 28 14:20:23 2012 From: ramit.prasad at jpmorgan.com (Prasad, Ramit) Date: Wed, 28 Mar 2012 18:20:23 +0000 Subject: "convert" string to bytes without changing data (encoding) In-Reply-To: <9th0u8Fuf2U1@mid.dfncis.de> References: <9tg21lFmo3U1@mid.dfncis.de> <9tg4qoFbfpU1@mid.dfncis.de> <9th0u8Fuf2U1@mid.dfncis.de> Message-ID: <5B80DD153D7D744689F57F4FB69AF47409291B51@SCACMX008.exchad.jpmchase.net> > As it seems, this would be far easier with python 2.x. With python 3 > and its strict distinction between "str" and "bytes", things gets > syntactically pretty awkward and error-prone (something as innocently > looking like "s=s+'/'" hidden in a rarely reached branch and a > seemingly correct program will crash with a TypeError 2 years > later ...) Just a small note as you are new to Python, string concatenation can be expensive (quadratic time). The Python (2.x and 3.x) idiom for frequent string concatenation is to append to a list and then join them like the following (linear time). >>>lst = [ 'Hi,' ] >>>lst.append( 'how' ) >>>lst.append( 'are' ) >>>lst.append( 'you?' ) >>>sentence = ' '.join( lst ) # use a space separating each element >>>print sentence Hi, how are you? You can use join on an empty string, but then they will not be separated by spaces. >>>sentence = ''.join( lst ) # empty string so no separation >>>print sentence Hi,howareyou? You can use any string as a separator, length does not matter. >>>sentence = '@-Q'.join( lst ) >>>print sentence Hi, at -Qhow@-Qare at -Qyou? Ramit Ramit Prasad | JPMorgan Chase Investment Bank | Currencies Technology 712 Main Street | Houston, TX 77002 work phone: 713 - 216 - 5423 -- This email is confidential and subject to important disclaimers and conditions including on offers for the purchase or sale of securities, accuracy and completeness of information, viruses, confidentiality, legal privilege, and legal entity disclaimers, available at http://www.jpmorgan.com/pages/disclosures/email. From ian.g.kelly at gmail.com Wed Mar 28 14:20:30 2012 From: ian.g.kelly at gmail.com (Ian Kelly) Date: Wed, 28 Mar 2012 12:20:30 -0600 Subject: "convert" string to bytes without changing data (encoding) In-Reply-To: <9th0u8Fuf2U1@mid.dfncis.de> References: <9tg21lFmo3U1@mid.dfncis.de> <9tg4qoFbfpU1@mid.dfncis.de> <9th0u8Fuf2U1@mid.dfncis.de> Message-ID: On Wed, Mar 28, 2012 at 11:43 AM, Peter Daum wrote: > ... I was under the illusion, that python (like e.g. perl) stored > strings internally in utf-8. In this case the "conversion" would simple > mean to re-label the data. Unfortunately, as I meanwhile found out, this > is not the case (nor the "apple encoding" ;-), so it would indeed be > pretty useless. No, unicode strings can be stored internally as any of UCS-1, UCS-2, UCS-4, C wchar strings, or even plain ASCII. And those are all implementation details that could easily change in future versions of Python. > The longer story of my question is: I am new to python (obviously), and > since I am not familiar with either one, I thought it would be advisory > to go for python 3.x. The biggest problem that I am facing is, that I > am often dealing with data, that is basically text, but it can contain > 8-bit bytes. In this case, I can not safely assume any given encoding, > but I actually also don't need to know - for my purposes, it would be > perfectly good enough to deal with the ascii portions and keep anything > else unchanged. You can't generally just "deal with the ascii portions" without knowing something about the encoding. Say you encounter a byte greater than 127. Is it a single non-ASCII character, or is it the leading byte of a multi-byte character? If the next character is less than 127, is it an ASCII character, or a continuation of the previous character? For UTF-8 you could safely assume ASCII, but without knowing the encoding, there is no way to be sure. If you just assume it's ASCII and manipulate it as such, you could be messing up non-ASCII characters. Cheers, Ian From rridge at csclub.uwaterloo.ca Wed Mar 28 14:22:50 2012 From: rridge at csclub.uwaterloo.ca (Ross Ridge) Date: Wed, 28 Mar 2012 14:22:50 -0400 Subject: "convert" string to bytes without changing data (encoding) References: <9tg21lFmo3U1@mid.dfncis.de> <4f73504c$0$29981$c3e8da3$5496439d@news.astraweb.com> Message-ID: Steven D'Aprano wrote: >The right way to convert bytes to strings, and vice versa, is via >encoding and decoding operations. If you want to dictate to the original poster the correct way to do things then you don't need to do anything more that. You don't need to pretend like Chris Angelico that there's isn't a direct mapping from the his Python 3 implementation's internal respresentation of strings to bytes in order to label what he's asking for as being "silly". 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 Wed Mar 28 14:26:29 2012 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 28 Mar 2012 18:26:29 GMT Subject: "convert" string to bytes without changing data (encoding) References: <9tg21lFmo3U1@mid.dfncis.de> <9tg4qoFbfpU1@mid.dfncis.de> <9th0u8Fuf2U1@mid.dfncis.de> Message-ID: <4f7357d5$0$29981$c3e8da3$5496439d@news.astraweb.com> On Wed, 28 Mar 2012 19:43:36 +0200, Peter Daum wrote: > The longer story of my question is: I am new to python (obviously), and > since I am not familiar with either one, I thought it would be advisory > to go for python 3.x. The biggest problem that I am facing is, that I am > often dealing with data, that is basically text, but it can contain > 8-bit bytes. All bytes are 8-bit, at least on modern hardware. I think you have to go back to the 1950s to find 10-bit or 12-bit machines. > In this case, I can not safely assume any given encoding, > but I actually also don't need to know - for my purposes, it would be > perfectly good enough to deal with the ascii portions and keep anything > else unchanged. Well you can't do that, because *by definition* you are changing a CHARACTER into ONE OR MORE BYTES. So the question you have to ask is, *how* do you want to change them? You can use an error handler to convert any untranslatable characters into question marks, or to ignore them altogether: bytes = string.encode('ascii', 'replace') bytes = string.encode('ascii', 'ignore') When going the other way, from bytes to strings, it can sometimes be useful to use the Latin-1 encoding, which essentially cannot fail: string = bytes.decode('latin1') although the non-ASCII chars that you get may not be sensible or meaningful in any way. But if there are only a few of them, and you don't care too much, this may be a simple approach. But in a nutshell, it is physically impossible to map the millions of Unicode characters to just 256 possible bytes without either throwing some characters away, or performing an encoding. > As it seems, this would be far easier with python 2.x. It only seems that way until you try. -- Steven From tjreedy at udel.edu Wed Mar 28 14:26:48 2012 From: tjreedy at udel.edu (Terry Reedy) Date: Wed, 28 Mar 2012 14:26:48 -0400 Subject: unittest: assertRaises() with an instance instead of a type In-Reply-To: References: Message-ID: On 3/28/2012 8:28 AM, Ulrich Eckhardt wrote: > Hi! > > I'm currently writing some tests for the error handling of some code. In > this scenario, I must make sure that both the correct exception is > raised and that the contained error code is correct: > > > try: > foo() > self.fail('exception not raised') > catch MyException as e: > self.assertEqual(e.errorcode, SOME_FOO_ERROR) > catch Exception: > self.fail('unexpected exception raised') > > > This is tedious to write and read. The docs mention this alternative: > > > with self.assertRaises(MyException) as cm: > foo() > self.assertEqual(cm.the_exception.errorcode, SOME_FOO_ERROR) Exceptions can have multiple attributes. This allows the tester to exactly specify what attributes to test. > This is shorter, but I think there's an alternative syntax possible that > would be even better: > > with self.assertRaises(MyException(SOME_FOO_ERROR)): > foo() I presume that if this worked the way you want, all attributes would have to match. The message part of builtin exceptions is allowed to change, so hard-coding an exact expected message makes tests fragile. This is a problem with doctest. > Here, assertRaises() is not called with an exception type but with an > exception instance. I'd implement it something like this: > > def assertRaises(self, exception, ...): > # divide input parameter into type and instance > if isinstance(exception, Exception): > exception_type = type(exception) > else: > exception_type = exception > exception = None > # call testee and verify results > try: > ...call function here... > except exception_type as e: > if not exception is None: > self.assertEqual(e, exception) Did you use tabs? They do not get preserved indefinitely, so they are bad for posting. > This of course requires the exception to be equality-comparable. Equality comparison is by id. So this code will not do what you want. You can, of course, write a custom AssertX subclass that at least works for your custom exception class. -- Terry Jan Reedy From ramit.prasad at jpmorgan.com Wed Mar 28 14:31:00 2012 From: ramit.prasad at jpmorgan.com (Prasad, Ramit) Date: Wed, 28 Mar 2012 18:31:00 +0000 Subject: "convert" string to bytes without changing data (encoding) In-Reply-To: References: <9tg21lFmo3U1@mid.dfncis.de> <9tg4qoFbfpU1@mid.dfncis.de> <9th0u8Fuf2U1@mid.dfncis.de> Message-ID: <5B80DD153D7D744689F57F4FB69AF47409291B7A@SCACMX008.exchad.jpmchase.net> > You can read as bytes and decode as ASCII but ignoring the troublesome > non-text characters: > > >>> print(open('text.txt', 'br').read().decode('ascii', 'ignore')) > Das fr ASCII nicht benutzte Bit kann auch fr Fehlerkorrekturzwecke > (Parittsbit) auf den Kommunikationsleitungen oder fr andere > Steuerungsaufgaben verwendet werden. Heute wird es aber fast immer zur > Erweiterung von ASCII auf einen 8-Bit-Code verwendet. Diese > Erweiterungen sind mit dem ursprnglichen ASCII weitgehend kompatibel, > so dass alle im ASCII definierten Zeichen auch in den verschiedenen > Erweiterungen durch die gleichen Bitmuster kodiert werden. Die > einfachsten Erweiterungen sind Kodierungen mit sprachspezifischen > Zeichen, die nicht im lateinischen Grundalphabet enthalten sind. > > The paragraph is from the German Wikipedia on ASCII, in UTF-8. I see no non-ASCII characters, not sure if that is because the source has none or something else. From this example I would not say that the rest of the text is "unchanged". Decode converts to Unicode, did you mean encode? I think "ignore" will remove non-translatable characters and not leave them in the returned string. Ramit Ramit Prasad | JPMorgan Chase Investment Bank | Currencies Technology 712 Main Street | Houston, TX 77002 work phone: 713 - 216 - 5423 -- This email is confidential and subject to important disclaimers and conditions including on offers for the purchase or sale of securities, accuracy and completeness of information, viruses, confidentiality, legal privilege, and legal entity disclaimers, available at http://www.jpmorgan.com/pages/disclosures/email. From larry.martell at gmail.com Wed Mar 28 14:39:54 2012 From: larry.martell at gmail.com (Larry.Martell@gmail.com) Date: Wed, 28 Mar 2012 11:39:54 -0700 (PDT) Subject: Best way to structure data for efficient searching Message-ID: I have the following use case: I have a set of data that is contains 3 fields, K1, K2 and a timestamp. There are duplicates in the data set, and they all have to processed. Then I have another set of data with 4 fields: K3, K4, K5, and a timestamp. There are also duplicates in that data set, and they also all have to be processed. I need to find all the items in the second data set where K1==K3 and K2==K4 and the 2 timestamps are within 20 seconds of each other. I have this working, but the way I did it seems very inefficient - I simply put the data in 2 arrays (as tuples) and then walked through the entire second data set once for each item in the first data set, looking for matches. Is there a better, more efficient way I could have done this? From python.list at tim.thechases.com Wed Mar 28 14:49:19 2012 From: python.list at tim.thechases.com (Tim Chase) Date: Wed, 28 Mar 2012 13:49:19 -0500 Subject: "convert" string to bytes without changing data (encoding) In-Reply-To: References: <9tg21lFmo3U1@mid.dfncis.de> Message-ID: <4F735D2F.70206@tim.thechases.com> On 03/28/12 13:05, Ross Ridge wrote: > Ross Ridge wr= >> But a Python Unicode string might be stored in several >> ways; for all you know, it might actually be stored as a sequence of >> apples in a refrigerator, just as long as they can be referenced >> correctly. > > But it is in fact only stored in one particular way, as a series of bytes. > >> There's no logical Python way to turn that into a series of bytes. > > Nonsense. Play all the semantic games you want, it already is a series > of bytes. Internally, they're a series of bytes, but they are MEANINGLESS bytes unless you know how they are encoded internally. Those bytes could be UTF-8, UTF-16, UTF-32, or any of a number of other possible encodings[1]. If you get the internal byte stream, there's no way to meaningfully operate on it unless you also know how it's encoded (or you're willing to sacrifice the ability to reliably get the string back). -tkc [1] http://docs.python.org/library/codecs.html#standard-encodings From ethan at stoneleaf.us Wed Mar 28 14:49:26 2012 From: ethan at stoneleaf.us (Ethan Furman) Date: Wed, 28 Mar 2012 11:49:26 -0700 Subject: "convert" string to bytes without changing data (encoding) In-Reply-To: <5B80DD153D7D744689F57F4FB69AF47409291B7A@SCACMX008.exchad.jpmchase.net> References: <9tg21lFmo3U1@mid.dfncis.de> <9tg4qoFbfpU1@mid.dfncis.de> <9th0u8Fuf2U1@mid.dfncis.de> <5B80DD153D7D744689F57F4FB69AF47409291B7A@SCACMX008.exchad.jpmchase.net> Message-ID: <4F735D36.8050205@stoneleaf.us> Prasad, Ramit wrote: >> You can read as bytes and decode as ASCII but ignoring the troublesome >> non-text characters: >> >>>>> print(open('text.txt', 'br').read().decode('ascii', 'ignore')) >> Das fr ASCII nicht benutzte Bit kann auch fr Fehlerkorrekturzwecke >> (Parittsbit) auf den Kommunikationsleitungen oder fr andere >> Steuerungsaufgaben verwendet werden. Heute wird es aber fast immer zur >> Erweiterung von ASCII auf einen 8-Bit-Code verwendet. Diese >> Erweiterungen sind mit dem ursprnglichen ASCII weitgehend kompatibel, >> so dass alle im ASCII definierten Zeichen auch in den verschiedenen >> Erweiterungen durch die gleichen Bitmuster kodiert werden. Die >> einfachsten Erweiterungen sind Kodierungen mit sprachspezifischen >> Zeichen, die nicht im lateinischen Grundalphabet enthalten sind. >> >> The paragraph is from the German Wikipedia on ASCII, in UTF-8. > > I see no non-ASCII characters, not sure if that is because the source > has none or something else. The 'ignore' argument to .decode() caused all non-ascii characters to be removed. ~Ethan~ From ramit.prasad at jpmorgan.com Wed Mar 28 15:02:41 2012 From: ramit.prasad at jpmorgan.com (Prasad, Ramit) Date: Wed, 28 Mar 2012 19:02:41 +0000 Subject: "convert" string to bytes without changing data (encoding) In-Reply-To: References: <9tg21lFmo3U1@mid.dfncis.de> <4f73504c$0$29981$c3e8da3$5496439d@news.astraweb.com> Message-ID: <5B80DD153D7D744689F57F4FB69AF47409291BEC@SCACMX008.exchad.jpmchase.net> > >The right way to convert bytes to strings, and vice versa, is via > >encoding and decoding operations. > > If you want to dictate to the original poster the correct way to do > things then you don't need to do anything more that. You don't need to > pretend like Chris Angelico that there's isn't a direct mapping from > the his Python 3 implementation's internal respresentation of strings > to bytes in order to label what he's asking for as being "silly". It might be technically possible to recreate internal implementation, or get the byte data. That does not mean it will make any sense or be understood in a meaningful manner. I think Ian summarized it very well: >You can't generally just "deal with the ascii portions" without >knowing something about the encoding. Say you encounter a byte >greater than 127. Is it a single non-ASCII character, or is it the >leading byte of a multi-byte character? If the next character is less >than 127, is it an ASCII character, or a continuation of the previous >character? For UTF-8 you could safely assume ASCII, but without >knowing the encoding, there is no way to be sure. If you just assume >it's ASCII and manipulate it as such, you could be messing up >non-ASCII characters. Technically, ASCII goes up to 256 but they are not A-z letters. Ramit Ramit Prasad | JPMorgan Chase Investment Bank | Currencies Technology 712 Main Street | Houston, TX 77002 work phone: 713 - 216 - 5423 -- This email is confidential and subject to important disclaimers and conditions including on offers for the purchase or sale of securities, accuracy and completeness of information, viruses, confidentiality, legal privilege, and legal entity disclaimers, available at http://www.jpmorgan.com/pages/disclosures/email. From rridge at csclub.uwaterloo.ca Wed Mar 28 15:10:23 2012 From: rridge at csclub.uwaterloo.ca (Ross Ridge) Date: Wed, 28 Mar 2012 15:10:23 -0400 Subject: "convert" string to bytes without changing data (encoding) References: <9tg21lFmo3U1@mid.dfncis.de> Message-ID: Tim Chase wrote: >Internally, they're a series of bytes, but they are MEANINGLESS >bytes unless you know how they are encoded internally. Those >bytes could be UTF-8, UTF-16, UTF-32, or any of a number of other >possible encodings[1]. If you get the internal byte stream, >there's no way to meaningfully operate on it unless you also know >how it's encoded (or you're willing to sacrifice the ability to >reliably get the string back). In practice the number of ways that CPython (the only Python 3 implementation) represents strings is much more limited. Pretending otherwise really isn't helpful. Still, if Chris Angelico had used your much less misleading explaination, then this could've been resolved much quicker. The original poster didn't buy Chris's bullshit for a minute, instead he had to find out on his own that that the internal representation of strings wasn't what he expected to be. Ross Ridge -- l/ // Ross Ridge -- The Great HTMU [oo][oo] rridge at csclub.uwaterloo.ca -()-/()/ http://www.csclub.uwaterloo.ca/~rridge/ db // From driscoll at cs.wisc.edu Wed Mar 28 15:20:50 2012 From: driscoll at cs.wisc.edu (Evan Driscoll) Date: Wed, 28 Mar 2012 14:20:50 -0500 Subject: "convert" string to bytes without changing data (encoding) In-Reply-To: References: <9tg21lFmo3U1@mid.dfncis.de> <4f73504c$0$29981$c3e8da3$5496439d@news.astraweb.com> Message-ID: <4F736492.1080702@cs.wisc.edu> On 01/-10/-28163 01:59 PM, Ross Ridge wrote: > Steven D'Aprano wrote: >> The right way to convert bytes to strings, and vice versa, is via >> encoding and decoding operations. > > If you want to dictate to the original poster the correct way to do > things then you don't need to do anything more that. You don't need to > pretend like Chris Angelico that there's isn't a direct mapping from > the his Python 3 implementation's internal respresentation of strings > to bytes in order to label what he's asking for as being "silly". That mapping may as well be: def get_bytes(some_string): import random length = random.randint(len(some_string), 5*len(some_string)) bytes = [0] * length for i in xrange(length): bytes[i] = random.randint(0, 255) return bytes Of course this is hyperbole, but it's essentially about as much guarantee as to what the result is. As many others have said, the encoding isn't defined, and I would guess varies between implementations. (E.g. if Jython and IronPython use their host platforms' native strings, both have 16-bit chars and thus probably use UTF-16 encoding. I am not sure what CPython uses, but I bet it's *not* that.) It's even guaranteed that the byte representation won't change! If something is lazily evaluated or you have a COW string or something, the bytes backing it will differ. So yes, you can say that pretending there's not a mapping of strings to internal representation is silly, because there is. However, there's nothing you can say about that mapping. Evan From marduk at letterboxes.org Wed Mar 28 15:22:39 2012 From: marduk at letterboxes.org (Albert W. Hopkins) Date: Wed, 28 Mar 2012 15:22:39 -0400 Subject: "convert" string to bytes without changing data (encoding) In-Reply-To: References: <9tg21lFmo3U1@mid.dfncis.de> Message-ID: <1332962559.1460206.1.camel@stretch> On Wed, 2012-03-28 at 14:05 -0400, Ross Ridge wrote: > Ross Ridge wr= > > Of course it is. =A0Conceptually you're not supposed to think of it that > > way, but a string is stored in memory as a series of bytes. > > Chris Angelico wrote: > >Note that distinction. I said that a string "is not" a series of > >bytes; you say that it "is stored" as bytes. > > The distinction is meaningless. I'm not going argue with you about what > you or I ment by the word "is". > Off topic, but obligatory: https://www.youtube.com/watch?v=j4XT-l-_3y0 From nagle at animats.com Wed Mar 28 15:30:49 2012 From: nagle at animats.com (John Nagle) Date: Wed, 28 Mar 2012 12:30:49 -0700 Subject: "convert" string to bytes without changing data (encoding) In-Reply-To: <9th0u8Fuf2U1@mid.dfncis.de> References: <9tg21lFmo3U1@mid.dfncis.de> <9tg4qoFbfpU1@mid.dfncis.de> <9th0u8Fuf2U1@mid.dfncis.de> Message-ID: On 3/28/2012 10:43 AM, Peter Daum wrote: > On 2012-03-28 12:42, Heiko Wundram wrote: >> Am 28.03.2012 11:43, schrieb Peter Daum: > The longer story of my question is: I am new to python (obviously), and > since I am not familiar with either one, I thought it would be advisory > to go for python 3.x. The biggest problem that I am facing is, that I > am often dealing with data, that is basically text, but it can contain > 8-bit bytes. In this case, I can not safely assume any given encoding, > but I actually also don't need to know - for my purposes, it would be > perfectly good enough to deal with the ascii portions and keep anything > else unchanged. So why let the data get into a "str" type at all? Do everything end to end with "bytes" or "bytearray" types. John Nagle From invalid at invalid.invalid Wed Mar 28 15:40:57 2012 From: invalid at invalid.invalid (Grant Edwards) Date: Wed, 28 Mar 2012 19:40:57 +0000 (UTC) Subject: "convert" string to bytes without changing data (encoding) References: <9tg21lFmo3U1@mid.dfncis.de> <9tg4qoFbfpU1@mid.dfncis.de> <9th0u8Fuf2U1@mid.dfncis.de> <4f7357d5$0$29981$c3e8da3$5496439d@news.astraweb.com> Message-ID: On 2012-03-28, Steven D'Aprano wrote: > On Wed, 28 Mar 2012 19:43:36 +0200, Peter Daum wrote: > >> The longer story of my question is: I am new to python (obviously), and >> since I am not familiar with either one, I thought it would be advisory >> to go for python 3.x. The biggest problem that I am facing is, that I am >> often dealing with data, that is basically text, but it can contain >> 8-bit bytes. > > All bytes are 8-bit, at least on modern hardware. I think you have to > go back to the 1950s to find 10-bit or 12-bit machines. Well, on anything likely to run Python that's true. There are modern DSP-oriented CPUs where a byte is 16 or 32 bits (and so is an int and a long, and a float and a double). >> As it seems, this would be far easier with python 2.x. > > It only seems that way until you try. It's easy as long as you deal with nothing but ASCII and Latin-1. ;) -- Grant Edwards grant.b.edwards Yow! Somewhere in Tenafly, at New Jersey, a chiropractor gmail.com is viewing "Leave it to Beaver"! From rridge at csclub.uwaterloo.ca Wed Mar 28 15:43:31 2012 From: rridge at csclub.uwaterloo.ca (Ross Ridge) Date: Wed, 28 Mar 2012 15:43:31 -0400 Subject: "convert" string to bytes without changing data (encoding) References: <9tg21lFmo3U1@mid.dfncis.de> <4f73504c$0$29981$c3e8da3$5496439d@news.astraweb.com> Message-ID: Evan Driscoll wrote: >So yes, you can say that pretending there's not a mapping of strings to >internal representation is silly, because there is. However, there's >nothing you can say about that mapping. I'm not the one labeling anything as being silly. I'm the one labeling the things as bullshit, and that's what you're doing here. I can in fact say what the internal byte string representation of strings is any given build of Python 3. Just because I can't say what it would be in an imaginary hypothetical implementation doesn't mean I can never say anything about it. Ross Ridge -- l/ // Ross Ridge -- The Great HTMU [oo][oo] rridge at csclub.uwaterloo.ca -()-/()/ http://www.csclub.uwaterloo.ca/~rridge/ db // From invalid at invalid.invalid Wed Mar 28 15:44:02 2012 From: invalid at invalid.invalid (Grant Edwards) Date: Wed, 28 Mar 2012 19:44:02 +0000 (UTC) Subject: "convert" string to bytes without changing data (encoding) References: <9tg21lFmo3U1@mid.dfncis.de> <4f73504c$0$29981$c3e8da3$5496439d@news.astraweb.com> Message-ID: On 2012-03-28, Prasad, Ramit wrote: > >>You can't generally just "deal with the ascii portions" without >>knowing something about the encoding. Say you encounter a byte >>greater than 127. Is it a single non-ASCII character, or is it the >>leading byte of a multi-byte character? If the next character is less >>than 127, is it an ASCII character, or a continuation of the previous >>character? For UTF-8 you could safely assume ASCII, but without >>knowing the encoding, there is no way to be sure. If you just assume >>it's ASCII and manipulate it as such, you could be messing up >>non-ASCII characters. > > Technically, ASCII goes up to 256 No, ASCII only defines 0-127. Values >=128 are not ASCII. >From https://en.wikipedia.org/wiki/ASCII: ASCII includes definitions for 128 characters: 33 are non-printing control characters (now mostly obsolete) that affect how text and space is processed and 95 printable characters, including the space (which is considered an invisible graphic). -- Grant Edwards grant.b.edwards Yow! Used staples are good at with SOY SAUCE! gmail.com From python at mrabarnett.plus.com Wed Mar 28 15:50:01 2012 From: python at mrabarnett.plus.com (MRAB) Date: Wed, 28 Mar 2012 20:50:01 +0100 Subject: "convert" string to bytes without changing data (encoding) In-Reply-To: <5B80DD153D7D744689F57F4FB69AF47409291BEC@SCACMX008.exchad.jpmchase.net> References: <9tg21lFmo3U1@mid.dfncis.de> <4f73504c$0$29981$c3e8da3$5496439d@news.astraweb.com> <5B80DD153D7D744689F57F4FB69AF47409291BEC@SCACMX008.exchad.jpmchase.net> Message-ID: <4F736B69.9080600@mrabarnett.plus.com> On 28/03/2012 20:02, Prasad, Ramit wrote: >> >The right way to convert bytes to strings, and vice versa, is via >> >encoding and decoding operations. >> >> If you want to dictate to the original poster the correct way to do >> things then you don't need to do anything more that. You don't need to >> pretend like Chris Angelico that there's isn't a direct mapping from >> the his Python 3 implementation's internal respresentation of strings >> to bytes in order to label what he's asking for as being "silly". > > It might be technically possible to recreate internal implementation, > or get the byte data. That does not mean it will make any sense or > be understood in a meaningful manner. I think Ian summarized it > very well: > >>You can't generally just "deal with the ascii portions" without >>knowing something about the encoding. Say you encounter a byte >>greater than 127. Is it a single non-ASCII character, or is it the >>leading byte of a multi-byte character? If the next character is less >>than 127, is it an ASCII character, or a continuation of the previous >>character? For UTF-8 you could safely assume ASCII, but without >>knowing the encoding, there is no way to be sure. If you just assume >>it's ASCII and manipulate it as such, you could be messing up >>non-ASCII characters. > > Technically, ASCII goes up to 256 but they are not A-z letters. > Technically, ASCII is 7-bit, so it goes up to 127. From joncle at googlemail.com Wed Mar 28 15:52:12 2012 From: joncle at googlemail.com (Jon Clements) Date: Wed, 28 Mar 2012 12:52:12 -0700 (PDT) Subject: Best way to structure data for efficient searching In-Reply-To: References: Message-ID: <26352843.1421.1332964332608.JavaMail.geo-discussion-forums@vbue17> On Wednesday, 28 March 2012 19:39:54 UTC+1, Larry.... at gmail.com wrote: > I have the following use case: > > I have a set of data that is contains 3 fields, K1, K2 and a > timestamp. There are duplicates in the data set, and they all have to > processed. > > Then I have another set of data with 4 fields: K3, K4, K5, and a > timestamp. There are also duplicates in that data set, and they also > all have to be processed. > > I need to find all the items in the second data set where K1==K3 and > K2==K4 and the 2 timestamps are within 20 seconds of each other. > > I have this working, but the way I did it seems very inefficient - I > simply put the data in 2 arrays (as tuples) and then walked through > the entire second data set once for each item in the first data set, > looking for matches. > > Is there a better, more efficient way I could have done this? It might not be more *efficient* but others might find it more readable, and it'd be easier to change later. Try an in-memory SQL DB (such as sqlite3) and query as (untested) select t2.* from t1 join t2 on k1=k3 and k2=k4 where abs(t1.timestamp - t2.timestamp) < 20 Failing that, two (default)dicts with a tuple as the pair, then use that as your base. Jon. From larry.martell at gmail.com Wed Mar 28 16:05:41 2012 From: larry.martell at gmail.com (Larry.Martell@gmail.com) Date: Wed, 28 Mar 2012 13:05:41 -0700 (PDT) Subject: Best way to structure data for efficient searching References: <26352843.1421.1332964332608.JavaMail.geo-discussion-forums@vbue17> Message-ID: <90d08585-361d-428e-a82d-c5005a6c4b5e@k24g2000yqe.googlegroups.com> On Mar 28, 1:52?pm, Jon Clements wrote: > On Wednesday, 28 March 2012 19:39:54 UTC+1, Larry.... at gmail.com ?wrote: > > I have the following use case: > > > I have a set of data that is contains 3 fields, K1, K2 and a > > timestamp. There are duplicates in the data set, and they all have to > > processed. > > > Then I have another set of data with 4 fields: K3, K4, K5, and a > > timestamp. There are also duplicates in that data set, and they also > > all have to be processed. > > > I need to find all the items in the second data set where K1==K3 and > > K2==K4 and the 2 timestamps are within 20 seconds of each other. > > > I have this working, but the way I did it seems very inefficient - I > > simply put the data in 2 arrays (as tuples) and then walked through > > the entire second data set once for each item in the first data set, > > looking for matches. > > > Is there a better, more efficient way I could have done this? > > It might not be more *efficient* but others might find it more readable, and it'd be easier to change later. Try an in-memory SQL DB (such as sqlite3) and query as (untested) > > select t2.* from t1 join t2 on k1=k3 and k2=k4 where abs(t1.timestamp - t2.timestamp) < 20 This is part of django app, and the data came from mysql. Through a mechanism I can't change at this time (it would take a lot of code changes and this new functionality is needed ASAP) I get all the data at once and have to winnow it down. > Failing that, two (default)dicts with a tuple as the pair, then use that as your base. Since there are duplicates, I can't use a dict. And if I have any extraneous data in the keys (i.e. something to make them unique) then I still have to walk through the entire dict to find the matches. From john_ladasky at sbcglobal.net Wed Mar 28 16:12:30 2012 From: john_ladasky at sbcglobal.net (John Ladasky) Date: Wed, 28 Mar 2012 13:12:30 -0700 (PDT) Subject: No os.copy()? Why not? Message-ID: <38b3fc48-1d05-4373-b32e-64da95173864@pz2g2000pbc.googlegroups.com> I'm looking for a Python (2.7) equivalent to the Unix "cp" command. Since the equivalents of "rm" and "mkdir" are in the os module, I figured I look there. I haven't found anything in the documentation. I am also looking through the Python source code in os.py and its child, posixfile.py. Any help? Thanks. From breamoreboy at yahoo.co.uk Wed Mar 28 16:44:14 2012 From: breamoreboy at yahoo.co.uk (Mark Lawrence) Date: Wed, 28 Mar 2012 21:44:14 +0100 Subject: "convert" string to bytes without changing data (encoding) In-Reply-To: References: <9tg21lFmo3U1@mid.dfncis.de> <4f73504c$0$29981$c3e8da3$5496439d@news.astraweb.com> Message-ID: On 28/03/2012 20:43, Ross Ridge wrote: > Evan Driscoll wrote: >> So yes, you can say that pretending there's not a mapping of strings to >> internal representation is silly, because there is. However, there's >> nothing you can say about that mapping. > > I'm not the one labeling anything as being silly. I'm the one labeling > the things as bullshit, and that's what you're doing here. I can in > fact say what the internal byte string representation of strings is any > given build of Python 3. Just because I can't say what it would be in > an imaginary hypothetical implementation doesn't mean I can never say > anything about it. > > Ross Ridge > Bytes is bytes and strings is strings And the wrong one I have chose Let's go where they keep on wearin' Those frills and flowers and buttons and bows Rings and things and buttons and bows. No guessing the tune. -- Cheers. Mark Lawrence. From neilc at norwich.edu Wed Mar 28 16:56:49 2012 From: neilc at norwich.edu (Neil Cerutti) Date: 28 Mar 2012 20:56:49 GMT Subject: "convert" string to bytes without changing data (encoding) References: <9tg21lFmo3U1@mid.dfncis.de> <4f73504c$0$29981$c3e8da3$5496439d@news.astraweb.com> Message-ID: <9thc8hFiu9U1@mid.individual.net> On 2012-03-28, Ross Ridge wrote: > Evan Driscoll wrote: >> So yes, you can say that pretending there's not a mapping of >> strings to internal representation is silly, because there is. >> However, there's nothing you can say about that mapping. > > I'm not the one labeling anything as being silly. I'm the one > labeling the things as bullshit, and that's what you're doing > here. I can in fact say what the internal byte string > representation of strings is any given build of Python 3. Just > because I can't say what it would be in an imaginary > hypothetical implementation doesn't mean I can never say > anything about it. I am in a similar situation viz a viz my wife's undergarments. -- Neil Cerutti From tjreedy at udel.edu Wed Mar 28 17:37:53 2012 From: tjreedy at udel.edu (Terry Reedy) Date: Wed, 28 Mar 2012 17:37:53 -0400 Subject: "convert" string to bytes without changing data (encoding) In-Reply-To: <9th0u8Fuf2U1@mid.dfncis.de> References: <9tg21lFmo3U1@mid.dfncis.de> <9tg4qoFbfpU1@mid.dfncis.de> <9th0u8Fuf2U1@mid.dfncis.de> Message-ID: On 3/28/2012 1:43 PM, Peter Daum wrote: > The longer story of my question is: I am new to python (obviously), and > since I am not familiar with either one, I thought it would be advisory > to go for python 3.x. I strongly agree with that unless you have reason to use 2.7. Python 3.3 (.0a1 in nearly out) has an improved unicode implementation, among other things. < The biggest problem that I am facing is, that I > am often dealing with data, that is basically text, but it can contain > 8-bit bytes. In this case, I can not safely assume any given encoding, > but I actually also don't need to know - for my purposes, it would be > perfectly good enough to deal with the ascii portions and keep anything > else unchanged. You are assuming, or must assume, that the text is in an ascii-compatible encoding, meaning that bytes 0-127 really represent ascii chars. Otherwise, you cannot reliably interpret anything, let alone change it. This problem of knowing that much but not the specific encoding is unfortunately common. It has been discussed among core developers and others the last few months. Different people prefer one of the following approaches. 1. Keep the bytes as bytes and use bytes literals and bytes functions as needed. The danger, as you noticed, is forgetting the 'b' prefix. 2. Decode as if the text were latin-1 and ignore the non-ascii 'latin-1' chars. When done, encode back to 'latin-1' and the non-ascii chars will be as they originally were. The danger is forgetting the pretense, and perhaps passing on the the string (as a string, not bytes) to other modules that will not know the pretense. 3. Decode using encoding = 'ascii', errors='surrogate_escape'. This reversibly encodes the unknown non-ascii chars as 'illegal' non-chars (using the surrogate-pair second-half code units). This is probably the safest in that invalid operations on the non-chars should raise an exception. Re-encoding with the same setting will reproduce the original hi-bit chars. The main danger is passing the illegal strings out of your local sandbox. -- Terry Jan Reedy From nambo4jb at gmail.com Wed Mar 28 17:48:35 2012 From: nambo4jb at gmail.com (Cathy James) Date: Wed, 28 Mar 2012 16:48:35 -0500 Subject: Need Help Using list items as output table names in MsACCESS Message-ID: Dear Python folks, I need your help on using list items as output table names in MsACCESS-new to Python- simple would be better: import arcpy, os outSpace = "c:\\data\\Info_Database.mdb\\" arcpy.overwriteOutput = True SQL = "Database Connections\\SDE_ReadOnly.sde\\" inFcList = [(SDE + "sde.GIS.Parcel"), (SDE + "sde.GIS.Residence"), (SDE + "sde.GIS.Park"), (SDE + "sde.GIS.Field"), (SDE + "sde.GIS.Business"), (SDE + "sde.GIS.Facility"), (SDE + "sde.GIS.Tertiary"), (SDE + "sde.GIS.KiddieClub")] #I'd like to crete output tables in the MDB whose names correspond to input names such that #"sde.GIS.Parcel" becomes "sde.GIS.Parcel_Buffer_500" for fc in inFcList: arcpy.overwriteOutput = True arcpy.Buffer_analysis(fc,(outSpace+fc+"_Buffer_500"), "500 Feet", "FULL", "ROUND", "ALL", "") print Finished #Thanks in advance From tolidtm at gmail.com Wed Mar 28 18:33:54 2012 From: tolidtm at gmail.com (Anatoli Hristov) Date: Thu, 29 Mar 2012 00:33:54 +0200 Subject: Advise of programming one of my first programs In-Reply-To: <5B80DD153D7D744689F57F4FB69AF4740928F779@SCACMX008.exchad.jpmchase.net> References: <5B80DD153D7D744689F57F4FB69AF4740928C365@SCACMX008.exchad.jpmchase.net> <5B80DD153D7D744689F57F4FB69AF4740928E137@SCACMX008.exchad.jpmchase.net> <5B80DD153D7D744689F57F4FB69AF4740928F779@SCACMX008.exchad.jpmchase.net> Message-ID: > You are correct it is not. :) You code is overly complex making it harder > to understand. Try and reduce the problem to the least number of tasks you > need. > >From the Zen of Python, "Simple is better than complex." It is a good > programming > mentality. Complex is better than complicated. :p > 2. A system to navigate your program. > def mmenu(): > # load tbook here > while True: > choicem = get_menu_choice() > if choicem == 'e' or choicem == 'E': > book = get_book_name() > edit( tbook, book ) > elif choicem == 'd' or choicem == 'D': > book = get_book_name() > details( tbook, book ) > elif choicem =='Q' or choicem == 'q': > break # end loop to exit program > else: > print 'Selection {0} not understood.'.format( choicem )I have > given you more functions With the main navigation menu I will only have the option to select a nickname and when a nickname is selected then it loads Details of the contact and from loaded details I can choice Edit or back to main screen, like I did it the first time, or else I can do it => when 'e' pressed to ask for a nickname and then edit it. > 3. function to write an edited book > def write_book(tbook): > write_book = open('c:/Python27/Toli/myfile.txt', 'w') > write_book.write(str(tbook)) > # I think repr would be more accurate than str here. > I`m not that far as you already know :) I hope I will learn everything as soon as I can as I`m not capable to read python everyday. > I do not think you need any other functions. Now you just need to finsh > all the functions > and put it all together. > I will finish it just need to understand more the functions and complex arguments. Thanks Anatoli -------------- next part -------------- An HTML attachment was scrubbed... URL: From tolidtm at gmail.com Wed Mar 28 18:36:06 2012 From: tolidtm at gmail.com (Anatoli Hristov) Date: Thu, 29 Mar 2012 00:36:06 +0200 Subject: Advise of programming one of my first programs In-Reply-To: <5B80DD153D7D744689F57F4FB69AF4740929109C@SCACMX008.exchad.jpmchase.net> References: <5B80DD153D7D744689F57F4FB69AF4740928C365@SCACMX008.exchad.jpmchase.net> <5B80DD153D7D744689F57F4FB69AF4740928E137@SCACMX008.exchad.jpmchase.net> <4F72385E.8020804@cs.wisc.edu> <5B80DD153D7D744689F57F4FB69AF4740929109C@SCACMX008.exchad.jpmchase.net> Message-ID: > > Um, at least by my understanding, the use of Pickle is also dangerous if > > you > > > are not completely sure what is being passed in: > > > > Oh goodness yes. pickle is exactly as unsafe as eval is. Try running this > > code: > > > > from pickle import loads > > loads("c__builtin__\neval\n(c__builtin__\nraw_input\n(S'py>'\ntRtR.") > > It might be as dangerous, but which is more likely to cause problems in > real world scenarios? Guys this is really something that is not that important at this time for me -------------- next part -------------- An HTML attachment was scrubbed... URL: From timothy.c.delaney at gmail.com Wed Mar 28 19:53:06 2012 From: timothy.c.delaney at gmail.com (Tim Delaney) Date: Thu, 29 Mar 2012 10:53:06 +1100 Subject: Number of languages known [was Re: Python is readable] - somewhat OT In-Reply-To: <4F6E60BC.1020600@tim.thechases.com> References: <4F6E60BC.1020600@tim.thechases.com> Message-ID: On 25 March 2012 11:03, Tim Chase wrote: > On 03/24/12 17:08, Tim Delaney wrote: > >> Absolutely. 10 years ago (when I was just a young lad) I'd say that I'd >> *forgotten* at least 20 programming languages. That number has only >> increased. >> > > And in the case of COBOL for me, it wasn't just forgotten, but actively > repressed ;-) > 2 weeks on work experience in year 10 (16 years old) was enough for me. Although I did have a functional book catalogue program by the end of it. Apparently the feedback was that if I'd wanted a job there I could have had one ... Tim Delaney -------------- next part -------------- An HTML attachment was scrubbed... URL: From steve+comp.lang.python at pearwood.info Wed Mar 28 20:02:37 2012 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 29 Mar 2012 00:02:37 GMT Subject: "convert" string to bytes without changing data (encoding) References: <9tg21lFmo3U1@mid.dfncis.de> <4f73504c$0$29981$c3e8da3$5496439d@news.astraweb.com> Message-ID: <4f73a69c$0$29981$c3e8da3$5496439d@news.astraweb.com> On Wed, 28 Mar 2012 15:43:31 -0400, Ross Ridge wrote: > I can in > fact say what the internal byte string representation of strings is any > given build of Python 3. Don't keep us in suspense! Given: Python 3.2.2 (default, Mar 4 2012, 10:50:33) [GCC 4.1.2 20080704 (Red Hat 4.1.2-51)] on linux2 what *is* the internal byte representation of the string "a???z"? (lowercase a, integral sign, copyright symbol, lowercase Greek pi, lowercase z) And more importantly, given that internal byte representation, what could you do with it? -- Steven From rosuav at gmail.com Wed Mar 28 20:07:47 2012 From: rosuav at gmail.com (Chris Angelico) Date: Thu, 29 Mar 2012 11:07:47 +1100 Subject: Advise of programming one of my first programs In-Reply-To: References: <5B80DD153D7D744689F57F4FB69AF4740928C365@SCACMX008.exchad.jpmchase.net> <5B80DD153D7D744689F57F4FB69AF4740928E137@SCACMX008.exchad.jpmchase.net> <4F72385E.8020804@cs.wisc.edu> <5B80DD153D7D744689F57F4FB69AF4740929109C@SCACMX008.exchad.jpmchase.net> Message-ID: Thu, Mar 29, 2012 at 9:36 AM, Anatoli Hristov wrote: >> > > Um, at least by my understanding, the use of Pickle is also dangerous >> > > if you are not completely sure what is being passed in: >> > >> > Oh goodness yes. pickle is exactly as unsafe as eval is. Try running >> > this code: >> > >> > from pickle import loads >> > loads("c__builtin__\neval\n(c__builtin__\nraw_input\n(S'py>'\ntRtR.") >> >> It might be as dangerous, but which is more likely to cause problems in >> real world scenarios? > > Guys this is really something ?that is not that important at this time for > me Maybe not, but it's still worth being aware of. Even if today your strings will never include apostrophes, it's still important to understand the risks of SQL injection and properly escape them before inserting them into an SQL statement. Just docket the information in the back of your mind "Don't use pickle with untrusted data" and move on. :) ChrisA From driscoll at cs.wisc.edu Wed Mar 28 20:11:56 2012 From: driscoll at cs.wisc.edu (Evan Driscoll) Date: Wed, 28 Mar 2012 19:11:56 -0500 Subject: "convert" string to bytes without changing data (encoding) In-Reply-To: References: <9tg21lFmo3U1@mid.dfncis.de> <4f73504c$0$29981$c3e8da3$5496439d@news.astraweb.com> Message-ID: <4F73A8CC.4090107@cs.wisc.edu> On 3/28/2012 14:43, Ross Ridge wrote: > Evan Driscoll wrote: >> So yes, you can say that pretending there's not a mapping of strings to >> internal representation is silly, because there is. However, there's >> nothing you can say about that mapping. > > I'm not the one labeling anything as being silly. I'm the one labeling > the things as bullshit, and that's what you're doing here. I can in > fact say what the internal byte string representation of strings is any > given build of Python 3. Just because I can't say what it would be in > an imaginary hypothetical implementation doesn't mean I can never say > anything about it. People like you -- who write to assumptions which are not even remotely guaranteed by the spec -- are part of the reason software sucks. People like you hold back progress, because system implementers aren't free to make changes without breaking backwards compatibility. Enormous amounts of effort are expended to test programs and diagnose problems which are caused by unwarranted assumptions like "the encoding of a string is UTF-8". In the worst case, assumptions like that lead to security fixes that don't go as far as they could, like the recent discussion about hashing. Python is definitely closer to the "willing to break backwards compatibility to improve" end of the spectrum than some other projects (*cough* Windows *cough*), but that still doesn't mean that you can make assumptions like that. This email is a bit harsher than it deserves -- but I feel not by much. Evan From rodrick.brown at gmail.com Wed Mar 28 20:59:14 2012 From: rodrick.brown at gmail.com (Rodrick Brown) Date: Wed, 28 Mar 2012 20:59:14 -0400 Subject: Number of languages known [was Re: Python is readable] - somewhat OT In-Reply-To: References: Message-ID: At my current firm we hire people who are efficient in one of the following and familiar with any another C#, Java, C++, Perl, Python or Ruby. We then expect developers to quickly pick up any of the following languages we use in house which is very broad. In our source repository not including the languages I've already stated above I've seen Fortran, Erlang, Groovy, HTML, CSS, JavaScript, Mathlab, C, K, R, S, Q, Excel, PHP, Bash, Ksh, PowerShell, Ruby, and Cuda. We do heavy computational and statistical analysis type work so developers need to be able to use a vast army of programming tools to tackle the various work loads were faced with on a daily basis. The best skill any developer can have is the ability to pickup languages very quickly and know what tools work well for which task. On Mar 22, 2012, at 3:14 PM, Chris Angelico wrote: > On Fri, Mar 23, 2012 at 4:44 AM, Steven D'Aprano > wrote: >> The typical developer knows three, maybe four languages >> moderately well, if you include SQL and regexes as languages, and might >> have a nodding acquaintance with one or two more. > > I'm not entirely sure what you mean by "moderately well", nor > "languages", but I'm of the opinion that a good developer should be > able to learn a new language very efficiently. Do you count Python 2 > and 3 as the same language? What about all the versions of the C > standard? > > In any case, though, I agree that there's a lot of people > professionally writing code who would know about the 3-4 that you say. > I'm just not sure that they're any good at coding, even in those few > languages. All the best people I've ever known have had experience > with quite a lot of languages. > > ChrisA > -- > http://mail.python.org/mailman/listinfo/python-list From rosuav at gmail.com Wed Mar 28 21:33:38 2012 From: rosuav at gmail.com (Chris Angelico) Date: Thu, 29 Mar 2012 12:33:38 +1100 Subject: Number of languages known [was Re: Python is readable] - somewhat OT In-Reply-To: References: Message-ID: On Thu, Mar 29, 2012 at 11:59 AM, Rodrick Brown wrote: > The best skill any developer can have is the ability to pickup languages very quickly and know what tools work well for which task. Definitely. Not just languages but all tools. The larger your toolkit and the better you know it, the more easily you'll be able to grasp the tool you need. ChrisA From ben+python at benfinney.id.au Wed Mar 28 21:55:13 2012 From: ben+python at benfinney.id.au (Ben Finney) Date: Thu, 29 Mar 2012 12:55:13 +1100 Subject: unittest: assertRaises() with an instance instead of a type References: <4f735345$0$29981$c3e8da3$5496439d@news.astraweb.com> Message-ID: <87mx70f9xa.fsf@benfinney.id.au> Steven D'Aprano writes: > (By the way, I have to question the design of an exception with error > codes. That seems pretty poor design to me. Normally the exception *type* > acts as equivalent to an error code.) Have a look at Python's built-in OSError. The various errors from the operating system can only be distinguished by the numeric code the OS returns, so that's what to test on in one's unit tests. -- \ ?In the long run, the utility of all non-Free software | `\ approaches zero. All non-Free software is a dead end.? ?Mark | _o__) Pilgrim, 2006 | Ben Finney From rridge at csclub.uwaterloo.ca Wed Mar 28 23:04:08 2012 From: rridge at csclub.uwaterloo.ca (Ross Ridge) Date: Wed, 28 Mar 2012 23:04:08 -0400 Subject: "convert" string to bytes without changing data (encoding) References: <9tg21lFmo3U1@mid.dfncis.de> Message-ID: Evan Driscoll wrote: >People like you -- who write to assumptions which are not even remotely >guaranteed by the spec -- are part of the reason software sucks. ... >This email is a bit harsher than it deserves -- but I feel not by much. I don't see how you could feel the least bit justified. Well meaning, if unhelpful, lies about the nature Python strings in order to try to convince someone to follow what you think are good programming practices is one thing. Maliciously lying about someone else's code that you've never seen is another thing entirely. Ross Ridge -- l/ // Ross Ridge -- The Great HTMU [oo][oo] rridge at csclub.uwaterloo.ca -()-/()/ http://www.csclub.uwaterloo.ca/~rridge/ db // From rosuav at gmail.com Wed Mar 28 23:31:59 2012 From: rosuav at gmail.com (Chris Angelico) Date: Thu, 29 Mar 2012 14:31:59 +1100 Subject: "convert" string to bytes without changing data (encoding) In-Reply-To: References: <9tg21lFmo3U1@mid.dfncis.de> Message-ID: On Thu, Mar 29, 2012 at 2:04 PM, Ross Ridge wrote: > Evan Driscoll ? wrote: >>People like you -- who write to assumptions which are not even remotely >>guaranteed by the spec -- are part of the reason software sucks. > ... >>This email is a bit harsher than it deserves -- but I feel not by much. > > I don't see how you could feel the least bit justified. ?Well meaning, > if unhelpful, lies about the nature Python strings in order to try to > convince someone to follow what you think are good programming practices > is one thing. ?Maliciously lying about someone else's code that you've > never seen is another thing entirely. Actually, he is justified. It's one thing to work in C or assembly and write code that depends on certain bit-pattern representations of data (although even that causes trouble - assuming that sizeof(int)==sizeof(int*) isn't good for portability), but in a high level language, you cannot assume any correlation between objects and bytes. Any code that depends on implementation details is risky. ChrisA From hungnv at at4a.com Wed Mar 28 23:36:13 2012 From: hungnv at at4a.com (Nguyen Van Hung) Date: Thu, 29 Mar 2012 03:36:13 -0000 Subject: Nhung dieu ban can biet Message-ID: thanks, -------------- next part -------------- An HTML attachment was scrubbed... URL: From rridge at csclub.uwaterloo.ca Wed Mar 28 23:58:53 2012 From: rridge at csclub.uwaterloo.ca (Ross Ridge) Date: Wed, 28 Mar 2012 23:58:53 -0400 Subject: "convert" string to bytes without changing data (encoding) References: <9tg21lFmo3U1@mid.dfncis.de> Message-ID: Chris Angelico wrote: >Actually, he is justified. It's one thing to work in C or assembly and >write code that depends on certain bit-pattern representations of data >(although even that causes trouble - assuming that >sizeof(int)=3D=3Dsizeof(int*) isn't good for portability), but in a high >level language, you cannot assume any correlation between objects and >bytes. Any code that depends on implementation details is risky. How does that in anyway justify Evan Driscoll maliciously lying about code he's never seen? Ross Ridge -- l/ // Ross Ridge -- The Great HTMU [oo][oo] rridge at csclub.uwaterloo.ca -()-/()/ http://www.csclub.uwaterloo.ca/~rridge/ db // From wuwei23 at gmail.com Thu Mar 29 00:50:52 2012 From: wuwei23 at gmail.com (alex23) Date: Wed, 28 Mar 2012 21:50:52 -0700 (PDT) Subject: No os.copy()? Why not? References: <38b3fc48-1d05-4373-b32e-64da95173864@pz2g2000pbc.googlegroups.com> Message-ID: <20bc37f2-9eac-47f0-9ab2-150da6ca203b@mq9g2000pbb.googlegroups.com> On Mar 29, 6:12?am, John Ladasky wrote: > I'm looking for a Python (2.7) equivalent to the Unix "cp" command. > Any help? ?Thanks. Try the shutil module: http://docs.python.org/library/shutil.html From jmwebaze at gmail.com Thu Mar 29 01:44:07 2012 From: jmwebaze at gmail.com (J. Mwebaze) Date: Thu, 29 Mar 2012 07:44:07 +0200 Subject: CFG for python Message-ID: Anyone knows how to create control-flow-graph for python.. After searching around, i found this article, http://www.python.org/dev/peps/pep-0339/#ast-to-cfg-to-bytecode and also a reference to http://doc.pypy.org/en/latest/objspace.html#the-flow-model However, i stil cant figure out what how to create the CFG from the two references. Regards -- *Mob UG: +256 (0) 70 1735800 | NL +31 (0) 6 852 841 38 | Gtalk: jmwebaze | skype: mwebazej | URL: www.astro.rug.nl/~jmwebaze /* Life runs on code */* -------------- next part -------------- An HTML attachment was scrubbed... URL: From showell30 at yahoo.com Thu Mar 29 01:50:44 2012 From: showell30 at yahoo.com (Steve Howell) Date: Wed, 28 Mar 2012 22:50:44 -0700 (PDT) Subject: unittest: assertRaises() with an instance instead of a type References: <4f735345$0$29981$c3e8da3$5496439d@news.astraweb.com> <87mx70f9xa.fsf@benfinney.id.au> Message-ID: On Mar 28, 6:55?pm, Ben Finney wrote: > Steven D'Aprano writes: > > (By the way, I have to question the design of an exception with error > > codes. That seems pretty poor design to me. Normally the exception *type* > > acts as equivalent to an error code.) > > Have a look at Python's built-in OSError. The various errors from the > operating system can only be distinguished by the numeric code the OS > returns, so that's what to test on in one's unit tests. > To the extent that numeric error codes are poor design (see Steven's comment) but part of the language (see Ben's comment), it may be worthwhile to consider a pattern like below. Let's say you have a function like save_config, where you know that permissions might be an issue on some systems, but you don't want to take any action (leave that to the callers). In those cases, it might be worthwhile to test for the specific error code (13), but then translate it to a more domain-specific exception. This way, all your callers can trap for a much more specific exception than OSError. Writing the test code for save_config still presents some of the issues that the OP alluded to, but then other parts of the system can be tested with simple assertRaises(). import os class ConfigPermissionError: pass def save_config(config): try: dir = os.mkdir('/config') except OSError, e: if e[0] == 13: raise ConfigPermissionError() else: raise fn = os.path.join(dir, 'config.txt') f = open(fn, 'w') # and so on... try: save_config({'port': 500}) except ConfigPermissionError: # do some workaround here print 'Config not saved due to permissions' From breamoreboy at yahoo.co.uk Thu Mar 29 02:01:14 2012 From: breamoreboy at yahoo.co.uk (Mark Lawrence) Date: Thu, 29 Mar 2012 07:01:14 +0100 Subject: "convert" string to bytes without changing data (encoding) In-Reply-To: References: <9tg21lFmo3U1@mid.dfncis.de> Message-ID: On 29/03/2012 04:58, Ross Ridge wrote: > Chris Angelico wrote: >> Actually, he is justified. It's one thing to work in C or assembly and >> write code that depends on certain bit-pattern representations of data >> (although even that causes trouble - assuming that >> sizeof(int)=3D=3Dsizeof(int*) isn't good for portability), but in a high >> level language, you cannot assume any correlation between objects and >> bytes. Any code that depends on implementation details is risky. > > How does that in anyway justify Evan Driscoll maliciously lying about > code he's never seen? > > Ross Ridge > We appear to have a case of "would you stand up please, your voice is rather muffled". I can hear all the *plonks* from miles away. -- Cheers. Mark Lawrence. From steve+comp.lang.python at pearwood.info Thu Mar 29 02:35:20 2012 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 29 Mar 2012 06:35:20 GMT Subject: unittest: assertRaises() with an instance instead of a type References: <4f735345$0$29981$c3e8da3$5496439d@news.astraweb.com> <87mx70f9xa.fsf@benfinney.id.au> Message-ID: <4f7402a8$0$29884$c3e8da3$5496439d@news.astraweb.com> On Thu, 29 Mar 2012 12:55:13 +1100, Ben Finney wrote: > Steven D'Aprano writes: > >> (By the way, I have to question the design of an exception with error >> codes. That seems pretty poor design to me. Normally the exception >> *type* acts as equivalent to an error code.) > > Have a look at Python's built-in OSError. The various errors from the > operating system can only be distinguished by the numeric code the OS > returns, so that's what to test on in one's unit tests. I'm familiar with OSError. It is necessary because OSError is a high- level interface to low-level C errors. I wouldn't call it a good design though, I certainly wouldn't choose it if we were developing an error system from scratch and weren't constrained by compatibility with a more primitive error model (error codes instead of exceptions). The new, revamped exception hierarchy in Python 3.3 will rationalise much (but not all) for this, unifying IOError and OSError and making error codes much less relevant: http://www.python.org/dev/peps/pep-3151/ -- Steven From startupcity397 at gmail.com Thu Mar 29 02:47:32 2012 From: startupcity397 at gmail.com (Sridevi V) Date: Wed, 28 Mar 2012 23:47:32 -0700 (PDT) Subject: A must read: Is MBA critical for techies to shape their career Message-ID: <7974e55e-ffcd-4809-99e8-cf2741551bf4@oq7g2000pbb.googlegroups.com> Hi, I was curious to find out about the job trends for fresh graduates and if an MBA will help me find even better job, when I came across these two articles on a website. It gave me some startling trends that are being followed in industry. A must read for all. It helped me and I thought it might help you as well. Winning, The Azim Premji Way Azim Hashim Premji, a supernova in the Indian IT industry is one of the most revered names in the tech scenario of all time. His words of wisdom will surely prove to e a winning streak to most of us http://bit.ly/WinningAzim The Unwanted Tech Kids Youth in our country considered as the future representatives of the nation at the global level, don?t you think they must be given good opportunities to showcase their talents and utilize their skills at their best level to help the country?s economic growth? http://bit.ly/TechKids Do Techies Need an M.B.A? We generally think that an MBA degree is a must to climb the corporate ladder in order to reach the zenith of success. http://bit.ly/TechiesNeedMBA Thank You, please do feel free to comment if you felt this was helpful From steve+comp.lang.python at pearwood.info Thu Mar 29 02:51:51 2012 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 29 Mar 2012 06:51:51 GMT Subject: "convert" string to bytes without changing data (encoding) References: <9tg21lFmo3U1@mid.dfncis.de> Message-ID: <4f740687$0$29884$c3e8da3$5496439d@news.astraweb.com> On Wed, 28 Mar 2012 23:58:53 -0400, Ross Ridge wrote: > How does that in anyway justify Evan Driscoll maliciously lying about > code he's never seen? You are perfectly justified to complain about Evan making sweeping generalisations about your code when he has not seen it; you are NOT justified in making your own sweeping generalisations that he is not just lying but *maliciously* lying. He might be just confused by the strength of his emotions and so making an honest mistake. Or he might have guessed perfectly accurately about your code, and you are the one being dishonest. Who knows? Evan's impassioned rant is based on his estimate of your mindset, namely that you are the sort of developer who writes code making assumptions about implementation details even when explicitly told not to by the library authors. I have no idea whether Evan's estimate is right or not, but I don't think it is justified based on the little amount we've seen of you. Your reaction is to make an equally unjustified estimate of Evan's mindset, namely that he is not just wrong about you, but *deliberately and maliciously* lying about you in the full knowledge that he is wrong. If anything, I would say that you have less justification for calling Evan a malicious liar than he has for calling you the sort of person who would write to an implementation instead of an interface. -- Steven From __peter__ at web.de Thu Mar 29 02:55:53 2012 From: __peter__ at web.de (Peter Otten) Date: Thu, 29 Mar 2012 08:55:53 +0200 Subject: unittest: assertRaises() with an instance instead of a type References: <4f735345$0$29981$c3e8da3$5496439d@news.astraweb.com> <87mx70f9xa.fsf@benfinney.id.au> Message-ID: Ben Finney wrote: > Steven D'Aprano writes: > >> (By the way, I have to question the design of an exception with error >> codes. That seems pretty poor design to me. Normally the exception *type* >> acts as equivalent to an error code.) > > Have a look at Python's built-in OSError. The various errors from the > operating system can only be distinguished by the numeric code the OS > returns, so that's what to test on in one's unit tests. The core devs are working to fix that: $ python3.2 -c'open("does-not-exist")' Traceback (most recent call last): File "", line 1, in IOError: [Errno 2] No such file or directory: 'does-not-exist' $ python3.3 -c'open("does-not-exist")' Traceback (most recent call last): File "", line 1, in FileNotFoundError: [Errno 2] No such file or directory: 'does-not-exist' $ python3.2 -c'open("unwritable", "w")' Traceback (most recent call last): File "", line 1, in IOError: [Errno 13] Permission denied: 'unwritable' $ python3.3 -c'open("unwritable", "w")' Traceback (most recent call last): File "", line 1, in PermissionError: [Errno 13] Permission denied: 'unwritable' http://www.python.org/dev/peps/pep-3151/ From ulrich.eckhardt at dominolaser.com Thu Mar 29 03:08:30 2012 From: ulrich.eckhardt at dominolaser.com (Ulrich Eckhardt) Date: Thu, 29 Mar 2012 09:08:30 +0200 Subject: unittest: assertRaises() with an instance instead of a type In-Reply-To: <4f735345$0$29981$c3e8da3$5496439d@news.astraweb.com> References: <4f735345$0$29981$c3e8da3$5496439d@news.astraweb.com> Message-ID: Am 28.03.2012 20:07, schrieb Steven D'Aprano: > First off, that is not Python code. "catch Exception" gives a syntax > error. Old C++ habits... :| > Secondly, that is not the right way to do this unit test. You are testing > two distinct things, so you should write it as two separate tests: [..code..] > If foo does *not* raise an exception, the unittest framework will handle > the failure for you. If it raises a different exception, the framework > will also handle that too. > > Then write a second test to check the exception code: [...] > Again, let the framework handle any unexpected cases. Sorry, you got it wrong, it should be three tests: 1. Make sure foo() raises an exception. 2. Make sure foo() raises the right exception. 3. Make sure the errorcode in the exception is right. Or maybe you should in between verify that the exception raised actually contains an errorcode? And that the errorcode can be equality-compared to the expected value? :> Sorry, I disagree that these steps should be separated. It would blow up the code required for testing, increasing maintenance burdens. Which leads back to a solution that uses a utility function, like the one you suggested or the one I was looking for initially. > (By the way, I have to question the design of an exception with error > codes. That seems pretty poor design to me. Normally the exception *type* > acts as equivalent to an error code.) True. Normally. I'd adapting to a legacy system though, similar to OSError, and that system simply emits error codes which the easiest way to handle is by wrapping them. Cheers! Uli From ulrich.eckhardt at dominolaser.com Thu Mar 29 03:18:24 2012 From: ulrich.eckhardt at dominolaser.com (Ulrich Eckhardt) Date: Thu, 29 Mar 2012 09:18:24 +0200 Subject: tabs/spaces (was: Re: unittest: assertRaises() with an instance instead of a type) In-Reply-To: References: Message-ID: <0ved49-hie.ln1@satorlaser.homedns.org> Am 28.03.2012 20:26, schrieb Terry Reedy: > On 3/28/2012 8:28 AM, Ulrich Eckhardt wrote: [...] >> # call testee and verify results >> try: >> ...call function here... >> except exception_type as e: >> if not exception is None: >> self.assertEqual(e, exception) > > Did you use tabs? They do not get preserved indefinitely, so they are > bad for posting. I didn't consciously use tabs, actually I would rather avoid them. That said, my posting looks correctly indented in my "sent" folder and also in the copy received from my newsserver. What could also have an influence is line endings. I'm using Thunderbird on win32 here, acting as news client to comp.lang.python. Or maybe it's your software (or maybe some software in between) that fails to preserve formatting. *shrug* Uli From ulrich.eckhardt at dominolaser.com Thu Mar 29 03:28:15 2012 From: ulrich.eckhardt at dominolaser.com (Ulrich Eckhardt) Date: Thu, 29 Mar 2012 09:28:15 +0200 Subject: unittest: assertRaises() with an instance instead of a type In-Reply-To: References: Message-ID: Am 28.03.2012 20:26, schrieb Terry Reedy: > On 3/28/2012 8:28 AM, Ulrich Eckhardt wrote: >> with self.assertRaises(MyException(SOME_FOO_ERROR)): >> foo() > > I presume that if this worked the way you want, all attributes would > have to match. The message part of builtin exceptions is allowed to > change, so hard-coding an exact expected message makes tests fragile. > This is a problem with doctest. I would have assumed that comparing two exceptions leaves out messages that are intended for the user, not as part of the API. However, my expectations aren't met anyway, because ... >> This of course requires the exception to be equality-comparable. > > Equality comparison is by id. So this code will not do what you want. >>> Exception('foo') == Exception('foo') False Yikes! That was unexpected and completely changes my idea. Any clue whether this is intentional? Is identity the fallback when no equality is defined for two objects? Thanks for your feedback! Uli From __peter__ at web.de Thu Mar 29 03:48:37 2012 From: __peter__ at web.de (Peter Otten) Date: Thu, 29 Mar 2012 09:48:37 +0200 Subject: unittest: assertRaises() with an instance instead of a type References: <4f735345$0$29981$c3e8da3$5496439d@news.astraweb.com> Message-ID: Ulrich Eckhardt wrote: > True. Normally. I'd adapting to a legacy system though, similar to > OSError, and that system simply emits error codes which the easiest way > to handle is by wrapping them. If you have err = some_func() if err: raise MyException(err) the effort to convert it to exc = lookup_exception(some_func()) if exc: raise exc is small. A fancy way is to use a decorator: #untested def code_to_exception(table): def deco(f): def g(*args, **kw): err = f(*args, **kw) exc = table[err] if exc is not None: raise exc return g return f class MyError(Exception): pass class HyperspaceBypassError(MyError): pass @code_to_exception({42: HyperspaceBypassError, 0: None}) def some_func(...): # ... From luch at ank-sia.com Thu Mar 29 06:49:16 2012 From: luch at ank-sia.com (Alexey Luchko) Date: Thu, 29 Mar 2012 13:49:16 +0300 Subject: errors building python 2.7.3 In-Reply-To: <4F72FAF9.8000802@ank-sia.com> References: <4F72FAF9.8000802@ank-sia.com> Message-ID: <4F743E2C.1090207@ank-sia.com> JFI Reported as http://bugs.python.org/issue14437 http://bugs.python.org/issue14438 -- Regars, Alex From luch at ank-sia.com Thu Mar 29 06:55:42 2012 From: luch at ank-sia.com (Alexey Luchko) Date: Thu, 29 Mar 2012 13:55:42 +0300 Subject: errors building python 2.7.3 In-Reply-To: References: <4F72FAF9.8000802@ank-sia.com> Message-ID: <4F743FAE.4070909@ank-sia.com> On 28.03.2012 18:42, David Robinow wrote: > On Wed, Mar 28, 2012 at 7:50 AM, Alexey Luchko wrote: >> I've tried to build Python 2.7.3rc2 on cygwin and got the following errors: >> >> $ CFLAGS=-I/usr/include/ncursesw/ CPPFLAGS=-I/usr/include/ncursesw/ >> ./configure > I haven't tried 2.7.3 yet, so I'll describe my experience with 2.7.2 > I use /usr/include/ncurses rather than /usr/include/ncursesw > I don't remember what the difference is but ncurses seems to work. I've tried ncurses too. It does not matter. -- Alex From mikprog at gmail.com Thu Mar 29 08:33:45 2012 From: mikprog at gmail.com (Mik) Date: Thu, 29 Mar 2012 05:33:45 -0700 (PDT) Subject: weird behaviour: pygame plays in shell but not in script Message-ID: <7ef60ccc-c0bb-4aa8-a393-469883897058@k24g2000yqe.googlegroups.com> Dear all, I am a bit frustrated by the following as I believe it is something silly that I am not able to see. I am using python 2.7.1+ under ubuntu. When I run the following script as in $python script.py I do not get any sound out of it BUT if I run every line in the python shell it works great. It doesn't make sense to me, maybe someone has a clue? Thanks for any clue! Mik import pygame #done twice to get rid of a sound card error pygame.mixer.init() pygame.mixer.init() pygame.mixer.pre_init(44100, -16, 2, 2048) pygame.init() # called twice to make it so that it detects sound card pygame.init() print "init" sounds = [] sounds.append(pygame.mixer.Sound("../audio/song01.wav")) sounds.append(pygame.mixer.Sound("../audio/song02.wav")) sounds.append(pygame.mixer.Sound("../audio/song03.wav")) sounds.append(pygame.mixer.Sound("../audio/song04.wav")) for sound in sounds: print ".." sound.play() From mikprog at gmail.com Thu Mar 29 08:41:59 2012 From: mikprog at gmail.com (Mik) Date: Thu, 29 Mar 2012 05:41:59 -0700 (PDT) Subject: weird behaviour: pygame plays in shell but not in script References: <7ef60ccc-c0bb-4aa8-a393-469883897058@k24g2000yqe.googlegroups.com> Message-ID: I can't believe I am so dumb! after sound.play() the script was terminating!!!! I didn't notice that 'play()' actually returns... What a nice way to introduce myself to the group!!! :-) sorry for bothering you guys :-) From roy at panix.com Thu Mar 29 08:49:59 2012 From: roy at panix.com (Roy Smith) Date: Thu, 29 Mar 2012 08:49:59 -0400 Subject: tabs/spaces (was: Re: unittest: assertRaises() with an instance instead of a type) References: <0ved49-hie.ln1@satorlaser.homedns.org> Message-ID: In article <0ved49-hie.ln1 at satorlaser.homedns.org>, Ulrich Eckhardt wrote: > I didn't consciously use tabs, actually I would rather avoid them. That > said, my posting looks correctly indented in my "sent" folder and also > in the copy received from my newsserver. What could also have an > influence is line endings. I'm using Thunderbird on win32 here, acting > as news client to comp.lang.python. Or maybe it's your software (or > maybe some software in between) that fails to preserve formatting. > > *shrug* Oh noes! The line eater bug is back! From nathan.alexander.rice at gmail.com Thu Mar 29 09:44:09 2012 From: nathan.alexander.rice at gmail.com (Nathan Rice) Date: Thu, 29 Mar 2012 09:44:09 -0400 Subject: Number of languages known [was Re: Python is readable] - somewhat OT In-Reply-To: References: Message-ID: On Wed, Mar 28, 2012 at 9:33 PM, Chris Angelico wrote: > On Thu, Mar 29, 2012 at 11:59 AM, Rodrick Brown wrote: >> The best skill any developer can have is the ability to pickup languages very quickly and know what tools work well for which task. > > Definitely. Not just languages but all tools. The larger your toolkit > and the better you know it, the more easily you'll be able to grasp > the tool you need. The thing that bothers me is that people spend time and mental energy on a wide variety of syntax when the semantics are ~90% identical in most cases (up to organization). We would be better off if all the time that was spent on learning syntax, memorizing library organization and becoming proficient with new tools was spent learning the mathematics, logic and engineering sciences. Those solve problems, languages are just representations. Unfortunately, programming languages seem to have become a way to differentiate yourself and establish sub-cultural membership. All the cool kids are using XYZ, people who use LMN are dorks! Who cares about sharing or compatibility! Human nature is depressingly self-defeating. From albert at spenarnc.xs4all.nl Thu Mar 29 09:44:25 2012 From: albert at spenarnc.xs4all.nl (Albert van der Horst) Date: 29 Mar 2012 13:44:25 GMT Subject: Python is readable References: <4f612b19$0$1379$4fafbaef@reader2.news.tin.it> Message-ID: In article , Nathan Rice wrote: >> >> http://www.joelonsoftware.com/articles/fog0000000018.html > >I read that article a long time ago, it was bullshit then, it is >bullshit now. The only thing he gets right is that the Shannon >information of a uniquely specified program is proportional to the >code that would be required to generate it. Never mind that if a Thank you for drawing my attention to that article. It attacks the humbug software architects. Are you one of them? I really liked that article. >program meets a specification, you shouldn't care about any of the >values used for unspecified parts of the program. If you care about >the values, they should be specified. So, if Joel had said that the >program was uniquely specified, or that none of the things that >weren't specified require values in the programming language, he might >have been kinda, sorta right. Of course, nobody cares enough to >specify every last bit of minutiae in a program, and specifications >change, so it is pretty much impossible to imagine either case ever >actually occurring. I wonder if you're not talking about a different article. Groetjes Albert -- -- Albert van der Horst, UTRECHT,THE NETHERLANDS Economic growth -- being exponential -- ultimately falters. albert at spe&ar&c.xs4all.nl &=n http://home.hccnet.nl/a.w.m.van.der.horst From edreamleo at gmail.com Thu Mar 29 09:58:38 2012 From: edreamleo at gmail.com (Edward K. Ream) Date: Thu, 29 Mar 2012 06:58:38 -0700 (PDT) Subject: ANN: Leo 4.10 final released Message-ID: <804eb1fc-be4a-4608-9e9b-42eed8ec1a2d@k4g2000yqa.googlegroups.com> Leo 4.10 final is now available at: http://sourceforge.net/projects/leo/files/Leo/4.10%20final/ Leo is a text editor, data organizer, project manager and much more. http://webpages.charter.net/edreamleo/intro.html Leo 4.10 contains 9 months of intense work on Leo. Several very important features are subtle; you could almost call them Easter Eggs, so please read the following notes carefully. The highlights of Leo 4.10: -------------------------- * Dozens of new and improved features and commands, including... - Tab completion now shows all @command & @button nodes. - Leo tabs may be detached from the main window. - The Open With menu now works. - The leoInspect module answers questions about Python code. - Leo can highlight the pane containing the focus. - The bigdash plugin searches across multiple files. - Improved abbreviation capabilities. - Improved handling of URL's. - Improved editing of non-Leo files. - Improvements create "weightless" unit testing. - Improved Leo's home page. * Easier installation on MacOS. * Fixed almost 70 bugs. The Easter Eggs --------------- 1. Tab completion now shows all @command & @button nodes. Put all your common scripts in @command nodes in myLeoSettings.leo. Typing @c will remind you of the names of these scripts. You can execute the scripts by name without the "@command-" prefix. 2. Improved abbreviation capabilities. Virtually any kind of abbreviation is possible. For example, ~a to ?. 3. Improved handling of URL's. URL's can be used as links to other Leo outlines. 4 Weightless unit testing. The mantra is edit, alt-4 (run-marked-unit-tests-externally), edit, alt-4,... Several seemingly innocuous changes made this work without "friction". The result is a remarkable increase in productivity. Links: ------ Leo: http://webpages.charter.net/edreamleo/front.html Forum: http://groups.google.com/group/leo-editor Download: http://sourceforge.net/projects/leo/files/Leo/4.10%20final/ Bzr: http://code.launchpad.net/leo-editor/ Quotes: http://webpages.charter.net/edreamleo/testimonials.html Edward K. Ream ------------------------------------------------------------------------------ Edward K. Ream email: edreamleo at gmail.com Leo: http://webpages.charter.net/edreamleo/front.html ------------------------------------------------------------------------------ From rosuav at gmail.com Thu Mar 29 10:03:14 2012 From: rosuav at gmail.com (Chris Angelico) Date: Fri, 30 Mar 2012 01:03:14 +1100 Subject: Number of languages known [was Re: Python is readable] - somewhat OT In-Reply-To: References: Message-ID: On Fri, Mar 30, 2012 at 12:44 AM, Nathan Rice wrote: > We would be better off if all the time that was spent on learning > syntax, memorizing library organization and becoming proficient with > new tools was spent learning the mathematics, logic and engineering > sciences. ?Those solve problems, languages are just representations. Different languages are good at different things. REXX is an efficient text parser and command executor. Pike allows live updates of running code. Python promotes rapid development and simplicity. PHP makes it easy to add small amounts of scripting to otherwise-static HTML pages. C gives you all the power of assembly language with all the readability of... assembly language. SQL describes a database request. You can't merge all of them without making a language that's suboptimal at most of those tasks - probably, one that's woeful at all of them. I mention SQL because, even if you were to unify all programming languages, you'd still need other non-application languages to get the job done. Keep the diversity and let each language focus on what it's best at. ChrisA who has lots and lots of hammers, so every problem looks like... lots and lots of nails. From asen.bozhilov at gmail.com Thu Mar 29 10:04:35 2012 From: asen.bozhilov at gmail.com (Asen Bozhilov) Date: Thu, 29 Mar 2012 07:04:35 -0700 (PDT) Subject: Best way to structure data for efficient searching References: <26352843.1421.1332964332608.JavaMail.geo-discussion-forums@vbue17> <90d08585-361d-428e-a82d-c5005a6c4b5e@k24g2000yqe.googlegroups.com> Message-ID: Larry.Mart wrote: > Since there are duplicates, I can't use a dict. And if I have any > extraneous data in the keys (i.e. something to make them unique) then > I still have to walk through the entire dict to find the matches. You can use slightly different approach. With double mapping you could simplify the lookup. What I mean? Get the first set and build lookup map as: MAP := { KEY1-VALUE : { KEY2-VALUE : [SET, SET, n-th duplicate SET] } } In the worst case you would have quadratic complexity of the algorithm. Otherwise the lookup would be really fast. From gator at cs.tu-berlin.de Thu Mar 29 10:57:19 2012 From: gator at cs.tu-berlin.de (Peter Daum) Date: Thu, 29 Mar 2012 16:57:19 +0200 Subject: "convert" string to bytes without changing data (encoding) In-Reply-To: References: <9tg21lFmo3U1@mid.dfncis.de> <9tg4qoFbfpU1@mid.dfncis.de> <9th0u8Fuf2U1@mid.dfncis.de> Message-ID: <4F74784F.40804@cs.tu-berlin.de> On 2012-03-28 23:37, Terry Reedy wrote: > 2. Decode as if the text were latin-1 and ignore the non-ascii 'latin-1' > chars. When done, encode back to 'latin-1' and the non-ascii chars will > be as they originally were. ... actually, in the beginning of my quest, I ran into an decoding exception trying to read data as "latin1" (which was more or less what I had expected anyway because byte values between 128 and 160 are not defined there). Obviously, I must have misinterpreted something there; I just ran a little test: l=[i for i in range(256)]; b=bytes(l) s=b.decode('latin1'); b=s.encode('latin1'); s=b.decode('latin1') for c in s: print(hex(ord(c)), end=' ') if (ord(c)+1) % 16 ==0: print("") print() ... and got all the original bytes back. So it looks like I tried to solve a problem that did not exist to start with (the problems, I ran into then were pretty real, though ;-) > 3. Decode using encoding = 'ascii', errors='surrogate_escape'. This > reversibly encodes the unknown non-ascii chars as 'illegal' non-chars > (using the surrogate-pair second-half code units). This is probably the > safest in that invalid operations on the non-chars should raise an > exception. Re-encoding with the same setting will reproduce the original > hi-bit chars. The main danger is passing the illegal strings out of your > local sandbox. Unfortunately, this is a very well-kept secret unless you know that something with that name exists. The options currently mentioned in the documentation are not really helpful, because the non-decodeable will be lost. With some trying, I got it to work, too (the option is named "surrogateescape" without the "_" and in python 3.1 it exists, but only not as a keyword argument: "s=b.decode('utf-8','surrogateescape')" ...) Thank you very much for your constructive advice! Regards, Peter From gator at cs.tu-berlin.de Thu Mar 29 10:57:19 2012 From: gator at cs.tu-berlin.de (Peter Daum) Date: Thu, 29 Mar 2012 16:57:19 +0200 Subject: "convert" string to bytes without changing data (encoding) In-Reply-To: References: <9tg21lFmo3U1@mid.dfncis.de> <9tg4qoFbfpU1@mid.dfncis.de> <9th0u8Fuf2U1@mid.dfncis.de> Message-ID: <4F74784F.40804@cs.tu-berlin.de> On 2012-03-28 23:37, Terry Reedy wrote: > 2. Decode as if the text were latin-1 and ignore the non-ascii 'latin-1' > chars. When done, encode back to 'latin-1' and the non-ascii chars will > be as they originally were. ... actually, in the beginning of my quest, I ran into an decoding exception trying to read data as "latin1" (which was more or less what I had expected anyway because byte values between 128 and 160 are not defined there). Obviously, I must have misinterpreted something there; I just ran a little test: l=[i for i in range(256)]; b=bytes(l) s=b.decode('latin1'); b=s.encode('latin1'); s=b.decode('latin1') for c in s: print(hex(ord(c)), end=' ') if (ord(c)+1) % 16 ==0: print("") print() ... and got all the original bytes back. So it looks like I tried to solve a problem that did not exist to start with (the problems, I ran into then were pretty real, though ;-) > 3. Decode using encoding = 'ascii', errors='surrogate_escape'. This > reversibly encodes the unknown non-ascii chars as 'illegal' non-chars > (using the surrogate-pair second-half code units). This is probably the > safest in that invalid operations on the non-chars should raise an > exception. Re-encoding with the same setting will reproduce the original > hi-bit chars. The main danger is passing the illegal strings out of your > local sandbox. Unfortunately, this is a very well-kept secret unless you know that something with that name exists. The options currently mentioned in the documentation are not really helpful, because the non-decodeable will be lost. With some trying, I got it to work, too (the option is named "surrogateescape" without the "_" and in python 3.1 it exists, but only not as a keyword argument: "s=b.decode('utf-8','surrogateescape')" ...) Thank you very much for your constructive advice! Regards, Peter From tjreedy at udel.edu Thu Mar 29 11:04:47 2012 From: tjreedy at udel.edu (Terry Reedy) Date: Thu, 29 Mar 2012 11:04:47 -0400 Subject: unittest: assertRaises() with an instance instead of a type In-Reply-To: References: Message-ID: On 3/29/2012 3:28 AM, Ulrich Eckhardt wrote: >> Equality comparison is by id. So this code will not do what you want. > > >>> Exception('foo') == Exception('foo') > False > > Yikes! That was unexpected and completely changes my idea. Any clue > whether this is intentional? Is identity the fallback when no equality > is defined for two objects? Yes. The Library Reference 4.3. Comparisons (for built-in classes) puts is this way. "Objects of different types, except different numeric types, never compare equal. Furthermore, some types (for example, function objects) support only a degenerate notion of comparison where any two objects of that type are unequal." In other words, 'a==b' is the same as 'a is b'. That is also the default for user-defined classes, but I am not sure where that is documented, if at all. -- Terry Jan Reedy From d at davea.name Thu Mar 29 11:16:30 2012 From: d at davea.name (Dave Angel) Date: Thu, 29 Mar 2012 11:16:30 -0400 Subject: tabs/spaces In-Reply-To: <0ved49-hie.ln1@satorlaser.homedns.org> References: <0ved49-hie.ln1@satorlaser.homedns.org> Message-ID: <4F747CCE.9020003@davea.name> On 03/29/2012 03:18 AM, Ulrich Eckhardt wrote: > Am 28.03.2012 20:26, schrieb Terry Reedy: >> On 3/28/2012 8:28 AM, Ulrich Eckhardt wrote: > [...] >>> # call testee and verify results >>> try: >>> ...call function here... >>> except exception_type as e: >>> if not exception is None: >>> self.assertEqual(e, exception) >> >> Did you use tabs? They do not get preserved indefinitely, so they are >> bad for posting. > > I didn't consciously use tabs, actually I would rather avoid them. > That said, my posting looks correctly indented in my "sent" folder and > also in the copy received from my newsserver. What could also have an > influence is line endings. I'm using Thunderbird on win32 here, acting > as news client to comp.lang.python. Or maybe it's your software (or > maybe some software in between) that fails to preserve formatting. > > *shrug* > > Uli More likely, you failed to tell Thunderbird to send it as text. Html messages will read differently on html aware readers than on the standard text readers. They also take maybe triple the space and bandwidth. In thunderbird 3.1.19 In Edit->Preferences, Composition->general Configure Text Format Behavior -> SendOptions In that dialog, under Text Format, choose Convert the message to plain text. Then in the tab called "Plain text domains", add python.org -- DaveA From tjreedy at udel.edu Thu Mar 29 11:25:14 2012 From: tjreedy at udel.edu (Terry Reedy) Date: Thu, 29 Mar 2012 11:25:14 -0400 Subject: tabs/spaces In-Reply-To: <0ved49-hie.ln1@satorlaser.homedns.org> References: <0ved49-hie.ln1@satorlaser.homedns.org> Message-ID: On 3/29/2012 3:18 AM, Ulrich Eckhardt wrote: > Am 28.03.2012 20:26, schrieb Terry Reedy: >> On 3/28/2012 8:28 AM, Ulrich Eckhardt wrote: > [...] >>> # call testee and verify results >>> try: >>> ...call function here... >>> except exception_type as e: >>> if not exception is None: >>> self.assertEqual(e, exception) >> >> Did you use tabs? They do not get preserved indefinitely, so they are >> bad for posting. > > I didn't consciously use tabs, actually I would rather avoid them. That > said, my posting looks correctly indented in my "sent" folder and also > in the copy received from my newsserver. What could also have an > influence is line endings. I'm using Thunderbird on win32 here, acting > as news client to comp.lang.python. I am using Thunderbird, win64, as news client for gmane. The post looked fine as originally received. The indents only disappeared when I hit reply and the >s were added. That does not happen, in general, for other messages. Unfortunately I cannot go back and read that message as received because the new version of Tbird is misbehaving and deleting read messages on close even though I asked to keep them 6 months. I will look immediately when I next see indents disappearing. -- Terry Jan Reedy From rridge at csclub.uwaterloo.ca Thu Mar 29 11:30:19 2012 From: rridge at csclub.uwaterloo.ca (Ross Ridge) Date: Thu, 29 Mar 2012 11:30:19 -0400 Subject: "convert" string to bytes without changing data (encoding) References: <9tg21lFmo3U1@mid.dfncis.de> <4f740687$0$29884$c3e8da3$5496439d@news.astraweb.com> Message-ID: Steven D'Aprano wrote: >Your reaction is to make an equally unjustified estimate of Evan's >mindset, namely that he is not just wrong about you, but *deliberately >and maliciously* lying about you in the full knowledge that he is wrong. No, Evan in his own words admitted that his post was ment to be harsh, "a bit harsher than it deserves", showing his malicious intent. He made accusations that where neither supported by anything I've said in this thread nor by the code I actually write. His accusation about me were completely made up, he was not telling the truth and had no reasonable basis to beleive he was telling the truth. He was malicously lying and I'm completely justified in saying so. Just to make it clear to all you zealots. I've not once advocated writing any sort "risky code" in this thread. I have not once advocated writing any style of code in thread. Just because I refuse to drink the "it's impossible to represent strings as a series of bytes" kool-aid does't mean that I'm a heretic that must oppose against everything you believe in. Ross Ridge -- l/ // Ross Ridge -- The Great HTMU [oo][oo] rridge at csclub.uwaterloo.ca -()-/()/ http://www.csclub.uwaterloo.ca/~rridge/ db // From ethan at stoneleaf.us Thu Mar 29 11:35:16 2012 From: ethan at stoneleaf.us (Ethan Furman) Date: Thu, 29 Mar 2012 08:35:16 -0700 Subject: unittest: assertRaises() with an instance instead of a type In-Reply-To: <4f735345$0$29981$c3e8da3$5496439d@news.astraweb.com> References: <4f735345$0$29981$c3e8da3$5496439d@news.astraweb.com> Message-ID: <4F748134.8030402@stoneleaf.us> Steven D'Aprano wrote: > On Wed, 28 Mar 2012 14:28:08 +0200, Ulrich Eckhardt wrote: > >> Hi! >> >> I'm currently writing some tests for the error handling of some code. In >> this scenario, I must make sure that both the correct exception is >> raised and that the contained error code is correct: >> >> >> try: >> foo() >> self.fail('exception not raised') >> catch MyException as e: >> self.assertEqual(e.errorcode, SOME_FOO_ERROR) >> catch Exception: >> self.fail('unexpected exception raised') > > Secondly, that is not the right way to do this unit test. You are testing > two distinct things, so you should write it as two separate tests: I have to disagree -- I do not see the advantage of writing a second test that *will* fail if the first test fails as opposed to bundling both tests together, and having one failure. ~Ethan~ From showell30 at yahoo.com Thu Mar 29 11:48:53 2012 From: showell30 at yahoo.com (Steve Howell) Date: Thu, 29 Mar 2012 08:48:53 -0700 (PDT) Subject: Number of languages known [was Re: Python is readable] - somewhat OT References: Message-ID: <28983178-6745-438c-937d-cc6349aa18b1@t8g2000pbe.googlegroups.com> On Mar 29, 7:03?am, Chris Angelico wrote: > On Fri, Mar 30, 2012 at 12:44 AM, Nathan Rice > > wrote: > > We would be better off if all the time that was spent on learning > > syntax, memorizing library organization and becoming proficient with > > new tools was spent learning the mathematics, logic and engineering > > sciences. ?Those solve problems, languages are just representations. > > Different languages are good at different things. REXX is an efficient > text parser and command executor. Pike allows live updates of running > code. Python promotes rapid development and simplicity. PHP makes it > easy to add small amounts of scripting to otherwise-static HTML pages. > C gives you all the power of assembly language with all the > readability of... assembly language. SQL describes a database request. > > You can't merge all of them without making a language that's > suboptimal at most of those tasks - probably, one that's woeful at all > of them. I agree with you on the overall point, but I think that Python actually does a fine job of replacing REXX and PHP. I've used both of the latter (and, of course, Python). REXX and PHP are great at what they do, but I don't think their slight advantages over Python justify all the weight they carry--incompatible syntax to Python, archaic libraries, missing modern language features, etc. It's great to have languages like C and HTML that carve out their own strong niches. No argument there. On the other hand, if you know Python, then having to contend with the learning curves and idiosyncrasies of Perl and Ruby might feel more frustrating than empowering. Like REXX and PHP, Perl and Ruby arguably have corners where they are more expressive than Python, but I'd rather have a boring system written in 100% Python than a Ruby/ Python hybrid. Python should also be a perfectly good superset of Bash Scripting language. (To the extent that Python isn't, there's nothing intrinsic about the language that prevents you from orchestrating processes.) > I mention SQL because, even if you were to unify all > programming languages, you'd still need other non-application > languages to get the job done. > Here I absolutely agree with you. SQL, to me, is a perfect illustration of a language that's optimal for a particular task. Of course, people still can't resist hiding it behind an ORM. The web stack is notorious for requiring multilingual juggling. HTML, CSS, JS, Python, and SQL are easy enough to juggle, but then you might also get template languages (with all the interpolation escaping), config files (XML, YAML, etc.), regexes (possibly multiple dialects), SQL, testing DSLs (ugh, Cucumber and friends), etc. > Keep the diversity and let each language focus on what it's best at. > > ChrisA > who has lots and lots of hammers, so every problem looks like... lots > and lots of nails. I know you're just joking here, because you're obviously not advocating for multiple hammers. You're advocating for multiple tools in the toolbox. Which is good, of course. I think the problem these days is that the programmer's brain is like a small toolbox. Maybe twenty tools fit in the toolbox. Instead of filling it up with 20 useful tools, a lot of us have it cluttered up with ten hammers, when only one of the hammers is what we need for the nails. From nobody at nowhere.com Thu Mar 29 12:25:38 2012 From: nobody at nowhere.com (Nobody) Date: Thu, 29 Mar 2012 17:25:38 +0100 Subject: question about file handling with "with" References: Message-ID: On Wed, 28 Mar 2012 11:31:21 +0200, Jabba Laci wrote: > Is the following function correct? Is the input file closed in order? > > def read_data_file(self): > with open(self.data_file) as f: > return json.loads(f.read()) Yes. The whole point of being able to use a file as a context manager is so that the file will be closed immediately upon leaving the with statement, whether by falling off the end, "return", an exception, or whatever. IOW, it's like calling .close() immediately after the "with" block, only more so, i.e. it will also handle cases that an explicit .close() misses. From driscoll at cs.wisc.edu Thu Mar 29 12:31:23 2012 From: driscoll at cs.wisc.edu (Evan Driscoll) Date: Thu, 29 Mar 2012 11:31:23 -0500 Subject: "convert" string to bytes without changing data (encoding) In-Reply-To: References: <9tg21lFmo3U1@mid.dfncis.de> Message-ID: <4F748E5B.9010707@cs.wisc.edu> On 01/-10/-28163 01:59 PM, Ross Ridge wrote: > Evan Driscoll wrote: >> People like you -- who write to assumptions which are not even remotely >> guaranteed by the spec -- are part of the reason software sucks. > ... >> This email is a bit harsher than it deserves -- but I feel not by much. > > I don't see how you could feel the least bit justified. Well meaning, > if unhelpful, lies about the nature Python strings in order to try to > convince someone to follow what you think are good programming practices > is one thing. Maliciously lying about someone else's code that you've > never seen is another thing entirely. I'm not even talking about code that you or the OP has written. I'm talking about your suggestion that I can in fact say what the internal byte string representation of strings is any given build of Python 3. Aside from the questionable truth of this assertion (there's no guarantee that an implementation uses one consistent encoding or data structure representation consistently), that's of no consequence because you can't depend on what the representation is. So why even bring it up? Also irrelevant is: In practice the number of ways that CPython (the only Python 3 implementation) represents strings is much more limited. Pretending otherwise really isn't helpful. If you can't depend on CPython's implementation (and, I would argue, your code is broken if you do), then it *is* helpful. Saying that "you can just look at what CPython does" is what is unhelpful. That said, looking again I did misread your post that I sent that harsh reply to; I was looking at it perhaps a bit too much through the lens of the CPython comment I said above, and interpreting it as "I can say what the internal representation is of CPython, so just give me that" and launched into my spiel. If that's not what was intended, I retract my statement. As long as everyone is clear on the fact that Python 3 implementations can use whatever encoding and data structures they want, perhaps even different encodings or data structures for equal strings, and that as a consequence saying "what's the internal representation of this string" is a meaningless question as far as Python itself is concerned, I'm happy. Evan From jeanpierreda at gmail.com Thu Mar 29 12:42:36 2012 From: jeanpierreda at gmail.com (Devin Jeanpierre) Date: Thu, 29 Mar 2012 12:42:36 -0400 Subject: Number of languages known [was Re: Python is readable] - somewhat OT In-Reply-To: References: Message-ID: On Thu, Mar 29, 2012 at 10:03 AM, Chris Angelico wrote: > You can't merge all of them without making a language that's > suboptimal at most of those tasks - probably, one that's woeful at all > of them. I mention SQL because, even if you were to unify all > programming languages, you'd still need other non-application > languages to get the job done. Not really. You can turn SQL (or something equivalent) into a subset of your programming language, like C# does with LINQ, or like Scheme does with macros. The Scheme approach generalizes to programming languages in general with even some fairly alien semantics (e.g. you can do prolog using macros and first-class continuations). In fact, for a more difficult target, I even recently saw an implementation of Python in Common-Lisp that uses reader macros to compile a subset of Python to equivalent Common-Lisp code: http://common-lisp.net/project/clpython/ On the other hand, even similar languages are really hard to run in the same VM: imagine the hoops you'd have to jump through to get libraries written in Python 2 and 3 to work together. For a more concrete example, take the attempt to make elisp and guile work together in guilemacs: http://www.red-bean.com/guile/notes/emacs-lisp.html But this has nothing to do with being "suboptimal at most tasks". It's easy to make a language that can do everything C can do, and also everything that Haskell can do. I can write an implementation of this programming language in one line of bash[*]. The easy way is to make those features mutually exclusive. We don't have to sacrifice anything by including more features until we want them to work together. With that in mind, the interesting languages to "merge" aren't things like SQL or regular expressions -- these are so easy to make work with programming languages, that we do it all the time already (via string manipulation, but first-class syntax would also be easily possible). The hard problems are when trying to merge in the semantics of languages that only "make sense" because they have drastically different expectations of the world. The example that comes to mind is Haskell, which relies incredibly strongly on the lack of side effects. How do you merge Haskell and Python? Well, you can't. As soon as you add side-effects, you can no longer rely on the weak equivalence of things executed eagerly versus lazily, and the semantics of Haskell go kaput. So the only actual effort (that I am aware of) to implement side-effects with Haskell *deliberately* makes mutability and laziness mutually exclusive. Anything else is impossible. The effort mentioned here is called Disciple, and the relevant thesis is very fun reading, check it out: http://www.cse.unsw.edu.au/~benl/papers/thesis/lippmeier-impure-world.pdf I guess what I really want to say is that the world looks, to me, to be more optimistic than so many people think it is. If we wanted to, we could absolutely take the best features from a bunch of things. This is what C++ does, this is what Scheme does, this is what D does. They sometimes do it in different ways, they have varying tradeoffs, but this isn't a hard problem except when it is, and the examples you mentioned are actually the easy cases. We can merge Python and C, while keeping roughly the power of both, it's called Cython. We can merge Python and PHP, in that PHP adds nothing incompatible with Python technically (it'd be a lot of work and there would be many tears shed because it's insane) -- but Python Server Pages probably add the feature you want. We could merge SQL and Python, arguably we already do via e.g. SQLAlchemy's query API (etc.) or DBAPI2's string API. These can all becomes subsets of a language that interoperate well with the rest of the language with no problems. These are non-issues: the reasons for not doing so are not technical, they are political or sociological (e.g., "bloat the language", "there should be one obvious way to do it", "PHP's mixing of business logic with presentation logic is bad", etc.) There _are_ times when this is technical, and there are specific areas of this that have technical difficulties, but... that's different, and interesting, and being actively researched, and not really impossible either. I don't know. This is maybe a bit too rant-y and disorganized; if so I apologize. I've been rethinking a lot of my views on programming languages lately. :) I hope at least the links help make this interesting to someone. -- Devin [*] A "language" is really just a set of programs that compile. If we assume that the set of haskell and C programs are disjoint, then we can create a new language that combines both of them, by trying the C (or Haskell) compiler first, and then running the other if that should fail. This is really an argument from the absurd, though. I just said it 'cause it sounds awesome. From tjreedy at udel.edu Thu Mar 29 12:49:19 2012 From: tjreedy at udel.edu (Terry Reedy) Date: Thu, 29 Mar 2012 12:49:19 -0400 Subject: "convert" string to bytes without changing data (encoding) In-Reply-To: References: <9tg21lFmo3U1@mid.dfncis.de> <4f740687$0$29884$c3e8da3$5496439d@news.astraweb.com> Message-ID: On 3/29/2012 11:30 AM, Ross Ridge wrote: > No, Evan in his own words admitted that his post was ment to be harsh, I agree that he should have restrained and censored his writing. > Just because I refuse to drink the > "it's impossible to represent strings as a series of bytes" kool-aid I do not believe *anyone* has made that claim. Is this meant to be a wild exaggeration? As wild as Evan's? In my first post on this thread, I made three truthful claims. 1. A 3.x text string is logically a sequence of unicode 'characters' (codepoints). 2. The Python language definition does not require that a string be bytes or become bytes unless and until it is explicitly encoded. 3. The intentionally hidden byte implementation of strings on byte machines is version and system dependent. The bytes used for a particular character is (in 3.3) context dependent. As it turns out, the OP had mistakenly assumed that the hidden byte implementation of 3.3 strings was both well-defined and something (utf-8) that it is not and (almost certainly) never will be. Guido and most other devs strongly want string indexing (and hence slice endpoint finding) to be O(1). So all of the above is moot as far as the OP's problem is concerned. I already gave him the three standard solutions. -- Terry Jan Reedy From ramit.prasad at jpmorgan.com Thu Mar 29 13:18:25 2012 From: ramit.prasad at jpmorgan.com (Prasad, Ramit) Date: Thu, 29 Mar 2012 17:18:25 +0000 Subject: Advise of programming one of my first programs In-Reply-To: References: <5B80DD153D7D744689F57F4FB69AF4740928C365@SCACMX008.exchad.jpmchase.net> <5B80DD153D7D744689F57F4FB69AF4740928E137@SCACMX008.exchad.jpmchase.net> <4F72385E.8020804@cs.wisc.edu> <5B80DD153D7D744689F57F4FB69AF4740929109C@SCACMX008.exchad.jpmchase.net> Message-ID: <5B80DD153D7D744689F57F4FB69AF47409292DC4@SCACMX008.exchad.jpmchase.net> From: Anatoli Hristov [mailto:tolidtm at gmail.com] Sent: Wednesday, March 28, 2012 5:36 PM To: Prasad, Ramit Cc: python-list at python.org Subject: Re: RE: Advise of programming one of my first programs >>> > Um, at least by my understanding, the use of Pickle is also dangerous if >>>> you >>> > are not completely sure what is being passed in: >>> >>> Oh goodness yes. pickle is exactly as unsafe as eval is. Try running this >>> code: >>> >>> from pickle import loads >>> loads("c__builtin__\neval\n(c__builtin__\nraw_input\n(S'py>'\ntRtR.") >>It might be as dangerous, but which is more likely to cause problems in >>real world scenarios? >Guys this is really something that is not that important at this time for me ?My Eyes! The goggles do nothing!? Ramit Ramit Prasad | JPMorgan Chase Investment Bank | Currencies Technology 712 Main Street | Houston, TX 77002 work phone: 713 - 216 - 5423 -- This email is confidential and subject to important disclaimers and conditions including on offers for the purchase or sale of securities, accuracy and completeness of information, viruses, confidentiality, legal privilege, and legal entity disclaimers, available at http://www.jpmorgan.com/pages/disclosures/email. -------------- next part -------------- An HTML attachment was scrubbed... URL: From ramit.prasad at jpmorgan.com Thu Mar 29 13:36:34 2012 From: ramit.prasad at jpmorgan.com (Prasad, Ramit) Date: Thu, 29 Mar 2012 17:36:34 +0000 Subject: "convert" string to bytes without changing data (encoding) In-Reply-To: <4F736B69.9080600@mrabarnett.plus.com> References: <9tg21lFmo3U1@mid.dfncis.de> <4f73504c$0$29981$c3e8da3$5496439d@news.astraweb.com> <5B80DD153D7D744689F57F4FB69AF47409291BEC@SCACMX008.exchad.jpmchase.net> <4F736B69.9080600@mrabarnett.plus.com> Message-ID: <5B80DD153D7D744689F57F4FB69AF47409292E89@SCACMX008.exchad.jpmchase.net> > > Technically, ASCII goes up to 256 but they are not A-z letters. > > > Technically, ASCII is 7-bit, so it goes up to 127. > No, ASCII only defines 0-127. Values >=128 are not ASCII. > > >From https://en.wikipedia.org/wiki/ASCII: > > ASCII includes definitions for 128 characters: 33 are non-printing > control characters (now mostly obsolete) that affect how text and > space is processed and 95 printable characters, including the space > (which is considered an invisible graphic). Doh! I was mistaking extended ASCII for ASCII. Thanks for the correction. Ramit Ramit Prasad | JPMorgan Chase Investment Bank | Currencies Technology 712 Main Street | Houston, TX 77002 work phone: 713 - 216 - 5423 -- > -----Original Message----- > From: python-list-bounces+ramit.prasad=jpmorgan.com at python.org > [mailto:python-list-bounces+ramit.prasad=jpmorgan.com at python.org] On > Behalf Of MRAB > Sent: Wednesday, March 28, 2012 2:50 PM > To: python-list at python.org > Subject: Re: "convert" string to bytes without changing data (encoding) > > On 28/03/2012 20:02, Prasad, Ramit wrote: > >> >The right way to convert bytes to strings, and vice versa, is via > >> >encoding and decoding operations. > >> > >> If you want to dictate to the original poster the correct way to do > >> things then you don't need to do anything more that. You don't need > to > >> pretend like Chris Angelico that there's isn't a direct mapping from > >> the his Python 3 implementation's internal respresentation of strings > >> to bytes in order to label what he's asking for as being "silly". > > > > It might be technically possible to recreate internal implementation, > > or get the byte data. That does not mean it will make any sense or > > be understood in a meaningful manner. I think Ian summarized it > > very well: > > > >>You can't generally just "deal with the ascii portions" without > >>knowing something about the encoding. Say you encounter a byte > >>greater than 127. Is it a single non-ASCII character, or is it the > >>leading byte of a multi-byte character? If the next character is less > >>than 127, is it an ASCII character, or a continuation of the previous > >>character? For UTF-8 you could safely assume ASCII, but without > >>knowing the encoding, there is no way to be sure. If you just assume > >>it's ASCII and manipulate it as such, you could be messing up > >>non-ASCII characters. > > > -- > http://mail.python.org/mailman/listinfo/python-list This email is confidential and subject to important disclaimers and conditions including on offers for the purchase or sale of securities, accuracy and completeness of information, viruses, confidentiality, legal privilege, and legal entity disclaimers, available at http://www.jpmorgan.com/pages/disclosures/email. From nathan.alexander.rice at gmail.com Thu Mar 29 13:48:40 2012 From: nathan.alexander.rice at gmail.com (Nathan Rice) Date: Thu, 29 Mar 2012 13:48:40 -0400 Subject: Number of languages known [was Re: Python is readable] - somewhat OT In-Reply-To: References: Message-ID: On Thu, Mar 29, 2012 at 10:03 AM, Chris Angelico wrote: > On Fri, Mar 30, 2012 at 12:44 AM, Nathan Rice > wrote: >> We would be better off if all the time that was spent on learning >> syntax, memorizing library organization and becoming proficient with >> new tools was spent learning the mathematics, logic and engineering >> sciences. ?Those solve problems, languages are just representations. > > Different languages are good at different things. REXX is an efficient > text parser and command executor. Pike allows live updates of running > code. Python promotes rapid development and simplicity. PHP makes it > easy to add small amounts of scripting to otherwise-static HTML pages. > C gives you all the power of assembly language with all the > readability of... assembly language. SQL describes a database request. Here's a thought experiment. Imagine that you have a project tree on your file system which includes files written in many different programming languages. Imagine that the files can be assumed to be contiguous for our purposes, so you could view all the files in the project as one long chunk of data. The directory and file names could be interpreted as statements in this data, analogous to "in the context of somedirectory" or "in the context of somefile with sometype". Any project configuration files could be viewed as declarative statements about contexts, such as "in xyz context, ignore those" or "in abc context, any that is actually a this". Imagine the compiler or interpreter is actually part of your program (which is reasonable since it doesn't do anything by itself). Imagine the build management tool is also part of your program in pretty much the same manner. Imagine that your program actually generates another program that will generate the program the machine runs. I hope you can follow me here, and further I hope you can see that this is a completely valid description of what is actually going on (from a different perspective). In the context of the above thought experiment, it should be clear that we currently have something that is a structural analog of a single programming metalanguage (or rather, one per computer architecture), with many domain specific languages constructed above that to simplify tasks in various contexts. The model I previously proposed is not fantasy, it exists, just not in a form usable by human beings. Are machine instructions the richest possible metalanguage? I really doubt it. Lets try another thought experiment... Imagine that instead of having machine instructions as the common metalanguage, we pushed the point of abstraction closer to something programmers can reasonably work with: abstract syntax trees. Imagine all programming languages share a common abstract syntax tree format, with nodes generated using a small set of human intelligible semantic primes. Then, a domain specific language is basically a context with a set of logical implications. By associating a branch of the tree to one (or the union of several) context, you provide a transformation path to machine instructions via logical implication. If implications of a union context for the nodes in the branch are not compatible, this manifests elegantly in the form of a logical contradiction. What does pushing the abstraction point that far up provide? For one, you can now reason across language boundaries. A compiler can tell me if my prolog code and my python code will behave properly together. Another benefit is that you make explicit the fact that your parser, interpreter, build tools, etc are actually part of your program, from the perspective that your program is actually another program that generates programs in machine instructions. By unifying your build chain, it makes deductive inference spanning steps and tools possible, and eliminates some needless repetition. This also greatly simplifies code reuse, since you only need to generate a syntax tree of the proper format and associate the correct context to it. It also simplifies learning languages, since people only need to understand the semantic primes in order to read anything. Of course, this describes Lisp to some degree, so I still need to provide some answers. What is wrong with Lisp? I would say that the base syntax being horrible is probably the biggest issue. Beyond that, transformations on lists of data are natural in Lisp, but graph transformations are not, making some things awkward. Additionally, because Lisp tries to nudge you towards programming in a functional style, it can be un-intuitive to learn. Programming is knowledge representation, and state is a natural concept that many people desire to model, so making it a second class citizen is a mistake. If I were to re-imagine Lisp for this purpose, I would embrace state and an explicit notion of temporal order. Rather than pretending it didn't exist, I would focus on logical and mathematical machinery necessary to allow powerful deductive reasoning about state. It is no coincidence that when a language needs to support formal verification (such as microcontrollers and DSPS for mission critical devices) a synchronous language is the go-go. On the other side of the spectrum, Haskell is the darling of functional programmers, but it is one of the worst languages in existence as far as being able to reason about the behavior of your program goes. Ignoring state for a few mathematical conveniences is the damning mark on the brow of the functional paradigm. Functional programming may be better on the whole than imperative programming, but anyone who doesn't acknowledge that it is an evolutionary dead-end is delusional. > You can't merge all of them without making a language that's > suboptimal at most of those tasks - probably, one that's woeful at all > of them. I mention SQL because, even if you were to unify all > programming languages, you'd still need other non-application > languages to get the job done. > > Keep the diversity and let each language focus on what it's best at. I don't know of any semi-modern programming language that doesn't generate an abstract syntax tree. Since any turing complete language can emulate any other turing complete language, there is no reason why a concise metalanguage for describing nodes of abstract syntax trees couldn't form the semantic vocabulary for every language in existence at the AST level. The syntax could be wildly different, but even then there is a VERY simple feature of CFGs that helps: they are closed under union. The only issue you could run into is if a node with a given name is represented by two different compositions of semantic primes at the AST level. Even this is not a show stopper though, because you could proceed using a union node. When converting the parse tree to an AST, it is likely only one of the two possible nodes in the union will fulfill all the requirements given its neighboring nodes and location in the tree. If there is more than one incompatible match, then of course you just alert the programmer to the contradiction and they can modify the tree context. I'm all for diversity of language at the level of minor notation and vocabulary, but to draw an analogy to the real world, English and Mandarin are redundant, and the fact that they both creates a communication barrier for BILLIONS of people. That doesn't mean that biologists shouldn't be able to define words to describe biological things, if you want to talk about biology you just need to learn the vocabulary. That also doesn't mean or that mathematicians shouldn't be able to use notation to structure complex statements, if you want to do math you need to man up and learn the notation (of course, I have issues with some mathematical notation, but there is no reason you should cry about things like set builder). From rridge at csclub.uwaterloo.ca Thu Mar 29 14:00:42 2012 From: rridge at csclub.uwaterloo.ca (Ross Ridge) Date: Thu, 29 Mar 2012 14:00:42 -0400 Subject: "convert" string to bytes without changing data (encoding) References: <9tg21lFmo3U1@mid.dfncis.de> <4f740687$0$29884$c3e8da3$5496439d@news.astraweb.com> Message-ID: Ross Ridge wrote: > Just because I refuse to drink the > "it's impossible to represent strings as a series of bytes" kool-aid Terry Reedy wrote: >I do not believe *anyone* has made that claim. Is this meant to be a >wild exaggeration? As wild as Evan's? Sorry, it would've been more accurate to label the flavour of kool-aid Chris Angelico was trying to push as "it's impossible ... without encoding": What is a string? It's not a series of bytes. You can't convert it without encoding those characters into bytes in some way. >In my first post on this thread, I made three truthful claims. I'm not objecting to every post made in this thread. If your post had been made before the original poster had figured it out on his own, I would've hoped he would have found it much more convincing than what I quoted above. Ross Ridge -- l/ // Ross Ridge -- The Great HTMU [oo][oo] rridge at csclub.uwaterloo.ca -()-/()/ http://www.csclub.uwaterloo.ca/~rridge/ db // From drobinow at gmail.com Thu Mar 29 14:29:13 2012 From: drobinow at gmail.com (David Robinow) Date: Thu, 29 Mar 2012 14:29:13 -0400 Subject: errors building python 2.7.3 In-Reply-To: <4F743FAE.4070909@ank-sia.com> References: <4F72FAF9.8000802@ank-sia.com> <4F743FAE.4070909@ank-sia.com> Message-ID: On Thu, Mar 29, 2012 at 6:55 AM, Alexey Luchko wrote: > On 28.03.2012 18:42, David Robinow wrote: >> On Wed, Mar 28, 2012 at 7:50 AM, Alexey Luchko ?wrote: >>> I've tried to build Python 2.7.3rc2 on cygwin and got the following >>> errors: >>> >>> $ CFLAGS=-I/usr/include/ncursesw/ CPPFLAGS=-I/usr/include/ncursesw/ >>> ./configure >> ? I haven't tried 2.7.3 yet, so I'll describe my experience with 2.7.2 >> ? I use /usr/include/ncurses ? rather than /usr/include/ncursesw >> ? I don't remember what the difference is but ncurses seems to work. > > I've tried ncurses too. ?It does not matter. Have you included the patch to Include/py_curses.h ? If you don't know what that is, download the cygwin src package for Python-2.6 and look at the patches. Not all of them are still necessary for 2.7 but some are. From python.list at tim.thechases.com Thu Mar 29 14:31:31 2012 From: python.list at tim.thechases.com (Tim Chase) Date: Thu, 29 Mar 2012 13:31:31 -0500 Subject: Number of languages known [was Re: Python is readable] - somewhat OT In-Reply-To: References: Message-ID: <4F74AA83.6020505@tim.thechases.com> On 03/29/12 12:48, Nathan Rice wrote: > Of course, this describes Lisp to some degree, so I still need to > provide some answers. What is wrong with Lisp? I would say that the > base syntax being horrible is probably the biggest issue. Do you mean something like: ((so (describes Lisp (to degree some) (of course)) still-need (provide I some-answers)) (is wrong what (with Lisp)) (would-say I ((is (base-syntax being-horrible) (probably-biggest issue))))) nah...can't fathom what's wrong with that... ?grins, ducks, and runs? -tkc From nathan.alexander.rice at gmail.com Thu Mar 29 14:37:09 2012 From: nathan.alexander.rice at gmail.com (Nathan Rice) Date: Thu, 29 Mar 2012 14:37:09 -0400 Subject: Python is readable In-Reply-To: References: <4f612b19$0$1379$4fafbaef@reader2.news.tin.it> Message-ID: On Thu, Mar 29, 2012 at 9:44 AM, Albert van der Horst wrote: > In article , > Nathan Rice ? wrote: >>> >>> http://www.joelonsoftware.com/articles/fog0000000018.html >> >>I read that article a long time ago, it was bullshit then, it is >>bullshit now. ?The only thing he gets right is that the Shannon >>information of a uniquely specified program is proportional to the >>code that would be required to generate it. ?Never mind that if a > > Thank you for drawing my attention to that article. > It attacks the humbug software architects. > Are you one of them? > I really liked that article. I read the first paragraph, remembered that I had read it previously and stopped. I accidentally remembered something from another Joel article as being part of that article (read it at http://www.joelonsoftware.com/items/2007/12/03.html). I don't really have anything to say on Joel's opinions about why people can or should code, their his and he is entitled to them. I feel they are overly reductionist (this isn't a black/white thing) and have a bit of luddite character to them. I will bet you everything I own the only reason Joel is alive today because of some mathematical abstraction he would be all too happy to discount as meaningless (because, to him, it is). Of course, I will give Joel one point: too many things related to programming are 100% hype, without any real substance; if his article had been about bullshit software hype and he hadn't fired the broadsides at the very notion of abstraction, I wouldn't have anything to say. Anyhow, if you "ugh rock good caveman smash gazelle put in mouth make stomach pain go away" meaning, here it is: Programs are knowledge. The reverse is not true, because programming is an infantile area of human creation, mere feet from the primordial tide pool from whence it spawned. We have a very good example of what a close to optimal outcome is: human beings - programs that write themselves, all knowledge forming programs, strong general artificial intelligence. When all knowledge is also programs, we will have successfully freed ourselves from necessary intellectual drudgery (the unnecessary kind will still exist). We will be able to tell computers what we want on our terms, and they will go and do it, checking in with us from time to time if they aren't sure what we really meant in the given context. If we have developed advanced robotics, we will simultaneously be freed from most manual labor. The only thing left for Joel to do will be to lounge about, being "creative" while eating mangos that were picked, packed, shipped and unloaded by robots, ordered by his computer assistant because it knows that he likes them, then delivered, prepared and served by more robots. The roadblocks in the path include the ability to deal with uncertainty, understand natural languages and the higher order characteristics of information. Baby steps to deal with these roadblocks are to explicitly forbid uncertainty, simplify the language used, and explicitly state higher order properties of information. The natural evolution of the process is to find ways to deal with ambiguity, correctly parse more complex language and automatically deduce higher order characteristics of information. Clearly, human intelligence demonstrates that this is not an impossible pipe dream. You may not be interested in working towards making this a reality, but I can pretty much guarantee on the scale of human achievement, it is near the top. From jeanpierreda at gmail.com Thu Mar 29 14:53:56 2012 From: jeanpierreda at gmail.com (Devin Jeanpierre) Date: Thu, 29 Mar 2012 14:53:56 -0400 Subject: Number of languages known [was Re: Python is readable] - somewhat OT In-Reply-To: References: Message-ID: Agreed with your entire first chunk 100%. Woohoo! High five. :) On Thu, Mar 29, 2012 at 1:48 PM, Nathan Rice wrote: > transformations on lists of data are natural in Lisp, but graph > transformations are not, making some things awkward. Eh, earlier you make some argument towards lisp being a universal metalanguage. If it can simulate prolog, it can certainly grow a graph manipulation form. You'd just need to code it up as a macro or function :p > Additionally, > because Lisp tries to nudge you towards programming in a functional > style, it can be un-intuitive to learn. I think you're thinking of Scheme here. Common Lisp isn't any more functional than Python, AFAIK (other than having syntactic heritage from the lambda calculus?) Common-Lisp does very much embrace state as you later describe, Scheme much less so (in that it makes mutating operations more obvious and more ugly. Many schemes even outlaw some entirely. And quoted lists default to immutable (aaaargh)). > I'm all for diversity of language at the level of minor notation and > vocabulary, but to draw an analogy to the real world, English and > Mandarin are redundant, and the fact that they both creates a > communication barrier for BILLIONS of people. ?That doesn't mean that > biologists shouldn't be able to define words to describe biological > things, if you want to talk about biology you just need to learn the > vocabulary. ?That also doesn't mean or that mathematicians shouldn't > be able to use notation to structure complex statements, if you want > to do math you need to man up and learn the notation (of course, I > have issues with some mathematical notation, but there is no reason > you should cry about things like set builder). Well, what sort of language differences make for English vs Mandarin? Relational algebraic-style programming is useful, but definitely a large language barrier to people that don't know any SQL. I think this is reasonable. (It would not matter even if you gave SQL python-like syntax, the mode of thinking is different, and for a good reason.) -- Devin From showell30 at yahoo.com Thu Mar 29 15:25:10 2012 From: showell30 at yahoo.com (Steve Howell) Date: Thu, 29 Mar 2012 12:25:10 -0700 (PDT) Subject: Number of languages known [was Re: Python is readable] - somewhat OT References: Message-ID: <6e4bc54d-7080-4434-b441-93e0e4930ccf@t2g2000pbg.googlegroups.com> On Mar 29, 11:53?am, Devin Jeanpierre wrote: > Well, what sort of language differences make for English vs Mandarin? > Relational algebraic-style programming is useful, but definitely a > large language barrier to people that don't know any SQL. I think this > is reasonable. (It would not matter even if you gave SQL python-like > syntax, the mode of thinking is different, and for a good reason.) > I don't see any fundamental disconnect between SQL thinking and Python thinking. List comprehensions are very close to SQL SELECTs semantically, and not that far off syntactically. [row.x for row in foo if x == 3] select x from foo where x = 3 Many people can grok the basics of relational algebraic style programming quite easily, which is why SQL is so popular. It just happens that many "programming" languages up until now have obscured the idea. SQL is so strongly associated with RDBMS implementations that people tend to forget that it makes sense as an abstract language--people tend to view SQL as a very concrete mechanism for pulling data out of storage, instead of as a notation for describing the relating and transforming of sets. From nathan.alexander.rice at gmail.com Thu Mar 29 15:50:37 2012 From: nathan.alexander.rice at gmail.com (Nathan Rice) Date: Thu, 29 Mar 2012 15:50:37 -0400 Subject: Number of languages known [was Re: Python is readable] - somewhat OT In-Reply-To: References: Message-ID: On Thu, Mar 29, 2012 at 2:53 PM, Devin Jeanpierre wrote: > Agreed with your entire first chunk 100%. Woohoo! High five. :) Damn, then I'm not trolling hard enough ?_? > On Thu, Mar 29, 2012 at 1:48 PM, Nathan Rice > wrote: >> transformations on lists of data are natural in Lisp, but graph >> transformations are not, making some things awkward. > > Eh, earlier you make some argument towards lisp being a universal > metalanguage. If it can simulate prolog, it can certainly grow a graph > manipulation form. You'd just need to code it up as a macro or > function :p Well, a lisp-like language. I would also argue that if you are using macros to do anything, the thing you are trying to do should classify as "not natural in lisp" :) I'm really thinking here more in terms of a general graph reactive system here, matching patterns in an input graph and modifying the graph in response. There are a lot of systems that can be modeled as a graph that don't admit a nested list (tree) description. By having references to outside the nesting structure you've just admitted that you need a graph rather than a list, so why not be honest about it and work in that context from the get-go. >> Additionally, >> because Lisp tries to nudge you towards programming in a functional >> style, it can be un-intuitive to learn. > > I think you're thinking of Scheme here. Common Lisp isn't any more > functional than Python, AFAIK (other than having syntactic heritage > from the lambda calculus?) > > Common-Lisp does very much embrace state as you later describe, Scheme > much less so (in that it makes mutating operations more obvious and > more ugly. Many schemes even outlaw some entirely. And quoted lists > default to immutable (aaaargh)). I find it interesting that John McCarthy invented both Lisp and the situation calculus. As for set/setq, sure, you can play with state, but it is verbose, and there is no inherent notion of temporal locality. Your program's execution order forms a nice lattice when run on hardware, that should be explicit in software. If I were to do something crazy like take the union of two processes that can potentially interact, with an equivalence relation between some time t1 in the first process and a time t2 in the second (so that you can derive a single partial order), the computer should be able to tell if I am going to shoot myself in the foot, and ideally suggest the correct course of action. > Well, what sort of language differences make for English vs Mandarin? > Relational algebraic-style programming is useful, but definitely a > large language barrier to people that don't know any SQL. I think this > is reasonable. (It would not matter even if you gave SQL python-like > syntax, the mode of thinking is different, and for a good reason.) I don't think they have to be. You can view functions as names for temporally ordered sequence of declarative implication statements. Databases just leave out the logic (this is hyperbole, I know), so you have to do it in client code. I don't feel that a database necessarily has to be a separate entity, that is just an artifact of the localized, specialized view of computation. As stronger abstractions are developed and concurrent, distributed computation is rigorously systematized, I think we'll go full circle. From peter.milliken at gmail.com Thu Mar 29 16:23:20 2012 From: peter.milliken at gmail.com (Peter) Date: Thu, 29 Mar 2012 13:23:20 -0700 (PDT) Subject: help with subclassing problem Message-ID: <30738583.971.1333052600720.JavaMail.geo-discussion-forums@pbje9> I am attempting to subclass the date class from the datetime package. Basically I want a subclass that can take the date as a string (in multiple formats), parse the string and derive the year,month and day information to create a date instance i.e. class MyDate(datetime.date): def __init__(self, the_date): # magic happens here to derives year, month and day from the_date datetime.date.__init__(self, year, month, day) But no matter what I do, when I attempt to create an instance of the new class, I get the error message: Traceback (most recent call last): File "", line 1, in TypeError: Required argument 'year' (pos 1) not found I have even created a class which doesn't include the argument I want to use but with default arguments i.e. class MyDate (datetime.date): def __init__(self, year = 1, month = 1, day = 1): datetime.date.__init__(self, year, month, day) and get the same error message. What am I doing wrong here? Thanks for any help, Peter From rosuav at gmail.com Thu Mar 29 16:33:47 2012 From: rosuav at gmail.com (Chris Angelico) Date: Fri, 30 Mar 2012 07:33:47 +1100 Subject: Number of languages known [was Re: Python is readable] - somewhat OT In-Reply-To: References: Message-ID: On Fri, Mar 30, 2012 at 3:42 AM, Devin Jeanpierre wrote: > On Thu, Mar 29, 2012 at 10:03 AM, Chris Angelico wrote: >> You can't merge all of them without making a language that's >> suboptimal at most of those tasks - probably, one that's woeful at all >> of them. I mention SQL because, even if you were to unify all >> programming languages, you'd still need other non-application >> languages to get the job done. > ... > But this has nothing to do with being "suboptimal at most tasks". It's > easy to make a language that can do everything C can do, and also > everything that Haskell can do. I can write an implementation of this > programming language in one line of bash[*]. The easy way is to make > those features mutually exclusive. We don't have to sacrifice anything > by including more features until we want them to work together. Of course it's POSSIBLE. You can write everything in Ook if you want to. But any attempt to merge all programming languages into one will either: 1) Allow different parts of a program to be written in different subsets of this universal language, which just means that you've renamed all the languages but kept their distinctions (so a programmer still has to learn all of them); or 2) Shoehorn every task into one language, equivalent to knowing only one language and using that for everything. Good luck with that. The debate keeps on coming up, but it's not just political decisions that maintain language diversity. ChrisA From rosuav at gmail.com Thu Mar 29 16:41:31 2012 From: rosuav at gmail.com (Chris Angelico) Date: Fri, 30 Mar 2012 07:41:31 +1100 Subject: "convert" string to bytes without changing data (encoding) In-Reply-To: References: <9tg21lFmo3U1@mid.dfncis.de> <4f740687$0$29884$c3e8da3$5496439d@news.astraweb.com> Message-ID: On Fri, Mar 30, 2012 at 5:00 AM, Ross Ridge wrote: > Sorry, it would've been more accurate to label the flavour of kool-aid > Chris Angelico was trying to push as "it's impossible ... without > encoding": > > ? ? ? ?What is a string? It's not a series of bytes. You can't convert > ? ? ? ?it without encoding those characters into bytes in some way. I still stand by that statement. Do you try to convert a "dictionary of filename to open file object" into a "series of bytes" inside Python? It doesn't matter that, on some level, it's *stored as* a series of bytes; the actual object *is not* a series of bytes. There is no logical equivalency, ergo it is illogical and nonsensical to expect to turn one into the other without some form of encoding. Python does include an encoding that can handle lists and dictionaries. It's called Pickle, and it returns (in Python 3) a bytes object - which IS a series of bytes. It doesn't simply return some internal representation. ChrisA From joncle at googlemail.com Thu Mar 29 16:47:56 2012 From: joncle at googlemail.com (Jon Clements) Date: Thu, 29 Mar 2012 13:47:56 -0700 (PDT) Subject: help with subclassing problem In-Reply-To: <30738583.971.1333052600720.JavaMail.geo-discussion-forums@pbje9> References: <30738583.971.1333052600720.JavaMail.geo-discussion-forums@pbje9> Message-ID: <25679513.1162.1333054076834.JavaMail.geo-discussion-forums@vbex14> On Thursday, 29 March 2012 21:23:20 UTC+1, Peter wrote: > I am attempting to subclass the date class from the datetime package. Basically I want a subclass that can take the date as a string (in multiple formats), parse the string and derive the year,month and day information to create a date instance i.e. > > class MyDate(datetime.date): > def __init__(self, the_date): > # magic happens here to derives year, month and day from the_date > datetime.date.__init__(self, year, month, day) > > But no matter what I do, when I attempt to create an instance of the new class, I get the error message: > > Traceback (most recent call last): > File "", line 1, in > TypeError: Required argument 'year' (pos 1) not found > > > I have even created a class which doesn't include the argument I want to use but with default arguments i.e. > > class MyDate (datetime.date): > def __init__(self, year = 1, month = 1, day = 1): > datetime.date.__init__(self, year, month, day) > > and get the same error message. > > What am I doing wrong here? > > Thanks for any help, > Peter Details here: http://stackoverflow.com/questions/399022/why-cant-i-subclass-datetime-date Jon. From peter.milliken at gmail.com Thu Mar 29 16:53:09 2012 From: peter.milliken at gmail.com (Peter) Date: Thu, 29 Mar 2012 13:53:09 -0700 (PDT) Subject: help with subclassing problem In-Reply-To: <25679513.1162.1333054076834.JavaMail.geo-discussion-forums@vbex14> References: <30738583.971.1333052600720.JavaMail.geo-discussion-forums@pbje9> <25679513.1162.1333054076834.JavaMail.geo-discussion-forums@vbex14> Message-ID: <9717915.602.1333054389867.JavaMail.geo-discussion-forums@pbcwe9> Thanks :-) From ramit.prasad at jpmorgan.com Thu Mar 29 17:04:25 2012 From: ramit.prasad at jpmorgan.com (Prasad, Ramit) Date: Thu, 29 Mar 2012 21:04:25 +0000 Subject: Advise of programming one of my first programs In-Reply-To: References: <5B80DD153D7D744689F57F4FB69AF4740928C365@SCACMX008.exchad.jpmchase.net> <5B80DD153D7D744689F57F4FB69AF4740928E137@SCACMX008.exchad.jpmchase.net> <5B80DD153D7D744689F57F4FB69AF4740928F779@SCACMX008.exchad.jpmchase.net> Message-ID: <5B80DD153D7D744689F57F4FB69AF47409293188@SCACMX008.exchad.jpmchase.net> >>From the Zen of Python, "Simple is better than complex." It is a good programming mentality. >Complex is better than complicated. :p Absolutely! Too bad your version would be considered the more ?complicated? version ;) >With the main navigation menu I will only have the option to select a nickname and when a nickname is selected then it loads Details of the contact and from loaded details I can choice Edit or back to main screen, like I did it the first time, or else I can do it => when 'e' pressed to ask for a nickname and then edit it. I was trying to simplify it to ?guide? you to a more correct solution without feeding you the answer. Maybe I should have given you the explanation first to explain why you should be doing it a different way. Going back to your original program (and your modifications to it), the original menu can cause crashing in more complicated programs and thus is considered a bad style. It was basically using recursion (I will touch on this later) but without any of the benefits. It was endlessly branching instead of a simple loop. Sort of like the following Menu/submenu example. Menu submenu Menu submenu Menu __ad infinitum__ How does this matter? Let?s look at some simpler code below. print ?start? function_a() # a function is called print ?a? # code inside the function print ?b? # code inside the function a = ? something ? print a function_b() # another function call print ?c? # code inside a different function print ?d? # code inside a different function print ?end? Let us pretend we are the computer who executes one line at a time and so basically goes through a list of commands. The list we are going to execute is the following: print ?start? function_a() print ?a? print ?b? a = ? something ? print a function_b() print ?c? print ?d? print ?end? How does the computer know to execute ?a = ? something ?? after ?print ?b??? It does it by storing the location where it was before it proceeds to the function call. That way when the end of the function is reached it returns to the previous spot. In essence: print ?start? function_a() __store this location so I can come back__ print ?a? print ?b? __return to previous location__ a = ? something ? print a function_b() __store this location so I can come back__ print ?c? print ?b? __return to previous location__ print ?end? Now what happens if ?function_a? calls ?function_a?? By the way, the term for this type of call is recursion. print ?start? function_a() __store this location so I can come back__ print ?a? print ?b? function_a() __store this location so I can come back__ print ?a? print ?b? function_a() __store this location so I can come back__ print ?a? print ?b? function_a() __store this location so I can come back__ print ?a? print ?b? function_a() __store this location so I can come back__ print ?a? print ?b? function_a() __store this location so I can come back__ *until the program ends* Now each __store__ action takes up memory and when the computer (or your program) runs out of memory your computer crashes. Your application is trivial and more likely to be ended by the user instead of going through the tens of thousands if not hundreds of thousands that Python will let you take, but it is a bad practice and a habit to avoid. A real world program would use more memory and quit even faster than yours. Recursion has its place in programming, but not in this case! What you need is a simple loop. That is why I provided you with the menu I did. The following menu sounds like what you want; there were a couple different ways I could have done this. In this version, if you type anything when asked for a menu choice that is not ?e? or ?q?, the program will automatically ask you for the next book choice. def mmenu(): # load tbook here while True: book = get_book_choice() details( tbook, book ) choicem = get_menu_choice() if choicem == 'e' or choicem == 'E': edit( tbook, book ) # save tbook here elif choicem =='Q' or choicem == 'q': break # end loop to exit program Ramit Ramit Prasad | JPMorgan Chase Investment Bank | Currencies Technology 712 Main Street | Houston, TX 77002 work phone: 713 - 216 - 5423 -- This email is confidential and subject to important disclaimers and conditions including on offers for the purchase or sale of securities, accuracy and completeness of information, viruses, confidentiality, legal privilege, and legal entity disclaimers, available at http://www.jpmorgan.com/pages/disclosures/email. -------------- next part -------------- An HTML attachment was scrubbed... URL: From ramit.prasad at jpmorgan.com Thu Mar 29 17:30:04 2012 From: ramit.prasad at jpmorgan.com (Prasad, Ramit) Date: Thu, 29 Mar 2012 21:30:04 +0000 Subject: Number of languages known [was Re: Python is readable] - somewhat OT In-Reply-To: References: Message-ID: <5B80DD153D7D744689F57F4FB69AF47409293213@SCACMX008.exchad.jpmchase.net> > >> You can't merge all of them without making a language that's > >> suboptimal at most of those tasks - probably, one that's woeful at all > >> of them. I mention SQL because, even if you were to unify all > >> programming languages, you'd still need other non-application > >> languages to get the job done. > > ... > > But this has nothing to do with being "suboptimal at most tasks". It's > > easy to make a language that can do everything C can do, and also > > everything that Haskell can do. I can write an implementation of this > > programming language in one line of bash[*]. The easy way is to make > > those features mutually exclusive. We don't have to sacrifice anything > > by including more features until we want them to work together. > > Of course it's POSSIBLE. You can write everything in Ook if you want > to. But any attempt to merge all programming languages into one will > either: > > 1) Allow different parts of a program to be written in different > subsets of this universal language, which just means that you've > renamed all the languages but kept their distinctions (so a programmer > still has to learn all of them); or > > 2) Shoehorn every task into one language, equivalent to knowing only > one language and using that for everything. Good luck with that. In a much simpler context, isn't this what .NET's CLR does? Except that instead of converting each language into each other it converts everything into a different language. I have trouble in my mind seeing how what you suggest would not end up with badly coded versions of a translated program. Never yet seen a program that could convert from one paradigm/language directly to another (and do it well/maintainable). > The debate keeps on coming up, but it's not just political decisions > that maintain language diversity. Not a bad thing in my opinion. A tool for each problem, but I can see the appeal of a multi-tool language. Ramit Ramit Prasad | JPMorgan Chase Investment Bank | Currencies Technology 712 Main Street | Houston, TX 77002 work phone: 713 - 216 - 5423 -- This email is confidential and subject to important disclaimers and conditions including on offers for the purchase or sale of securities, accuracy and completeness of information, viruses, confidentiality, legal privilege, and legal entity disclaimers, available at http://www.jpmorgan.com/pages/disclosures/email. From vinay_sajip at yahoo.co.uk Thu Mar 29 19:01:15 2012 From: vinay_sajip at yahoo.co.uk (Vinay Sajip) Date: Thu, 29 Mar 2012 16:01:15 -0700 (PDT) Subject: ANN: A new version (0.2.9) of the Python module which wraps GnuPG has been released. Message-ID: A new version of the Python module which wraps GnuPG has been released. What Changed? ============= This is a minor bug-fix release. See the project website ( http://code.google.com/p/python-gnupg/ ) for more information. Summary: Better support for status messages from GnuPG. A random data file used in testing is no longer shipped with the source distribution, but created by the test suite if needed. 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 jeanpierreda at gmail.com Thu Mar 29 19:21:34 2012 From: jeanpierreda at gmail.com (Devin Jeanpierre) Date: Thu, 29 Mar 2012 19:21:34 -0400 Subject: Number of languages known [was Re: Python is readable] - somewhat OT In-Reply-To: References: Message-ID: On Thu, Mar 29, 2012 at 4:33 PM, Chris Angelico wrote: > Of course it's POSSIBLE. You can write everything in Ook if you want > to. But any attempt to merge all programming languages into one will > either: In that particular quote, I was saying that the reason that you claimed we can't merge languages was not a correct reason. You are now moving the goalposts, in that you've decided to abandon your original point. Also you are now discussing the merger of all programming languages, whereas I meant to talk about pairs of programming languages. e.g. such as SQL and Python. Merging all programming languages is ridiculous. Even merging two, Haskell and C, is impossible without running into massive world-bending problems. (Yes, these problems are interesting, but no, they can't be solved without running into your "issue 1" -- this is in fact a proven theorem.) > 1) Allow different parts of a program to be written in different > subsets of this universal language, which just means that you've > renamed all the languages but kept their distinctions (so a programmer > still has to learn all of them); or Yes. I mentioned this. It is not entirely useless (if you're going to use the other language _anyway_, like SQL or regexps, might as well have it be checked at compile-time same as your outer code), but in a broad sense it's a terrible idea. Also, programmers would have to learn things regardless. You can't avoid this, that's what happens when you add features. The goal in integrating two languages is, well, integration, not reducing learning. > 2) Shoehorn every task into one language, equivalent to knowing only > one language and using that for everything. Good luck with that. This isn't true for the "merge just two languages" case, which is what I meant to talk about. > The debate keeps on coming up, but it's not just political decisions > that maintain language diversity. Are you disagreeing with me, or somebody else? I never said that. Yes, I said that in some cases, e.g. SQL/Python, because there are no technical issues, it must be something political or stylistic. I wasn't saying that the only reason we don't merge languages in is political. As a matter of fact, the very next paragraph begins with "There _are_ times when this is technical". ("political" is a bad word for it, because it covers things that are just plain bad ideas (but, subjectively). For example, there's nothing technically challenging about adding an operator that wipes the user's home directory.) -- Devin From jeanpierreda at gmail.com Thu Mar 29 19:37:23 2012 From: jeanpierreda at gmail.com (Devin Jeanpierre) Date: Thu, 29 Mar 2012 19:37:23 -0400 Subject: Number of languages known [was Re: Python is readable] - somewhat OT In-Reply-To: References: Message-ID: On Thu, Mar 29, 2012 at 3:50 PM, Nathan Rice wrote: > Well, a lisp-like language. ?I would also argue that if you are using > macros to do anything, the thing you are trying to do should classify > as "not natural in lisp" :) You would run into disagreement. Some people feel that the lisp philosophy is precisely that of extending the language to do anything you want, in the most natural way. At least, I disagree, but my lisp thoughts are the result of indoctrination of the Racket crowd. I don't know how well they represent the larger lisp community. But you should definitely take what I say from the viewpoint of the sort of person that believes that the whole purpose of lisps is to embed new syntax and new DSLs via macros. Without macros, there's no point of having this despicable syntax (barring maybe pedagogy and other minor issues). > I'm really thinking here more in terms of a general graph reactive > system here, matching patterns in an input graph and modifying the > graph in response. ?There are a lot of systems that can be modeled as > a graph that don't admit a nested list (tree) description. ?By having > references to outside the nesting structure you've just admitted that > you need a graph rather than a list, so why not be honest about it and > work in that context from the get-go. I don't see any issue in defining a library for working with graphs. If it's useful enough, it could be added to the standard library. There's nothing all that weird about it. Also, most representations of graphs are precisely via a tree-like non-recursive structure. For example, as a matrix, or adjacency list, etc. We think of them as deep structures, but implement them as flat, shallow structures. Specialized syntax (e.g. from macros) can definitely bridge the gap and let you manipulate them in the obvious way, while admitting the usual implementation. > I don't think they have to be. ?You can view functions as names for > temporally ordered sequence of declarative implication statements. > Databases just leave out the logic (this is hyperbole, I know), so you > have to do it in client code. ?I don't feel that a database > necessarily has to be a separate entity, that is just an artifact of > the localized, specialized view of computation. ?As stronger > abstractions are developed and concurrent, distributed computation is > rigorously systematized, I think we'll go full circle. Maybe I'm too tired, but this went straight over my head, sorry. Perhaps you could be a bit more explicit about what you mean by the implications/logic? -- Devin From steve+comp.lang.python at pearwood.info Thu Mar 29 21:10:35 2012 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 30 Mar 2012 01:10:35 GMT Subject: "convert" string to bytes without changing data (encoding) References: <9tg21lFmo3U1@mid.dfncis.de> <4f73504c$0$29981$c3e8da3$5496439d@news.astraweb.com> <5B80DD153D7D744689F57F4FB69AF47409291BEC@SCACMX008.exchad.jpmchase.net> <4F736B69.9080600@mrabarnett.plus.com> Message-ID: <4f75080a$0$29981$c3e8da3$5496439d@news.astraweb.com> On Thu, 29 Mar 2012 17:36:34 +0000, Prasad, Ramit wrote: >> > Technically, ASCII goes up to 256 but they are not A-z letters. >> > >> Technically, ASCII is 7-bit, so it goes up to 127. > >> No, ASCII only defines 0-127. Values >=128 are not ASCII. >> >> >From https://en.wikipedia.org/wiki/ASCII: >> >> ASCII includes definitions for 128 characters: 33 are non-printing >> control characters (now mostly obsolete) that affect how text and >> space is processed and 95 printable characters, including the space >> (which is considered an invisible graphic). > > > Doh! I was mistaking extended ASCII for ASCII. Thanks for the > correction. There actually is no such thing as "extended ASCII" -- there is a whole series of many different "extended ASCIIs". If you look at the encodings available in (for example) Thunderbird, many of the ISO-8859-* and Windows-* encodings are "extended ASCII" in the sense that they extend ASCII to include bytes 128-255. Unfortunately they all extend ASCII in a different way (hence they are different encodings). -- Steven From steve+comp.lang.python at pearwood.info Thu Mar 29 21:16:22 2012 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 30 Mar 2012 01:16:22 GMT Subject: "convert" string to bytes without changing data (encoding) References: <9tg21lFmo3U1@mid.dfncis.de> <4f740687$0$29884$c3e8da3$5496439d@news.astraweb.com> Message-ID: <4f750965$0$29981$c3e8da3$5496439d@news.astraweb.com> On Thu, 29 Mar 2012 11:30:19 -0400, Ross Ridge wrote: > Steven D'Aprano wrote: >>Your reaction is to make an equally unjustified estimate of Evan's >>mindset, namely that he is not just wrong about you, but *deliberately >>and maliciously* lying about you in the full knowledge that he is wrong. > > No, Evan in his own words admitted that his post was ment to be harsh, > "a bit harsher than it deserves", showing his malicious intent. Being harsher than it deserves is not synonymous with malicious. You are making assumptions about Evan's mental state that are not supported by the evidence. Evan may believe that by "punishing" (for some feeble sense of punishment) you harshly, he is teaching you better behaviour that will be to your own benefit; or that it will act as a warning to others. Either way he may believe that he is actually doing good. And then he entirely undermined his own actions by admitting that he was over-reacting. This suggests that, in fact, he wasn't really motivated by either malice or beneficence but mere frustration. It is quite clear that Evan let his passions about writing maintainable code get the best of him. His rant was more about "people like you" than you personally. Evan, if you're reading this, I think you owe Ross an apology for flying off the handle. Ross, I think you owe Evan an apology for unjustified accusations of malice. > He made > accusations that where neither supported by anything I've said Now that is not actually true. Your posts have defended the idea that copying the raw internal byte representation of strings is a reasonable thing to do. You even claimed to know how to do so, for any version of Python (but so far have ignored my request for you to demonstrate). > in this > thread nor by the code I actually write. His accusation about me were > completely made up, he was not telling the truth and had no reasonable > basis to beleive he was telling the truth. He was malicously lying and > I'm completely justified in saying so. No, they were not completely made up. Your posts give many signs of being somebody who might very well write code to the implementation rather than the interface. Whether you are or not is a separate question, but your posts in this thread indicate that you very likely could be. If this is not the impression you want to give, then you should reconsider your posting style. Ross, to be frank, your posting style in this thread has been cowardly and pedantic, an obnoxious combination. Please take this as constructive criticism and not an attack -- you have alienated people in this thread, leading at least one person to publicly kill-file your future posts. I choose to assume you aren't aware of why that is than that you are doing so deliberately. Without actually coming out and making a clear, explicit statement that you approve or disapprove of the OP's attempt to use implementation details, you *imply* support without explicitly giving it; you criticise others for saying it can't be done without demonstrating that it can be done. If this is a deliberate rhetorical trick, then shame on you for being a coward without the conviction to stand behind concrete expressions of your opinion. If not, then you should be aware that you are using a rhetorical style that will make many people predisposed to think you are a twat. You *might* have said Guys, you're technically wrong about this. This is how you can retrieve the internal representation of a string as a sequence of bytes: ...code... but you shouldn't use this in production code because it is fragile and depends on implementation details that may break in PyPy and Jython and IronPython. But you didn't. You *might* have said Wrong, you can convert a string into a sequence of bytes without encoding or decoding: ...code... but don't do this. But you didn't. Instead you puffed yourself up as a big shot who was more technically correct than everyone else, but without *actually* demonstrating that you can do what you said you can do. You labelled as "bullshit" our attempts to discourage the OP from his misguided approached. If your intention was to put people off-side, you succeeded very well. If not, you should be aware that you have, and consider how you might avoid this in the future. -- Steven From steve+comp.lang.python at pearwood.info Thu Mar 29 21:42:56 2012 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 30 Mar 2012 01:42:56 GMT Subject: Python is readable References: <4f612b19$0$1379$4fafbaef@reader2.news.tin.it> Message-ID: <4f750f9f$0$29981$c3e8da3$5496439d@news.astraweb.com> On Thu, 29 Mar 2012 14:37:09 -0400, Nathan Rice wrote: > On Thu, Mar 29, 2012 at 9:44 AM, Albert van der Horst > wrote: >> In article , Nathan >> Rice ? wrote: >>>> >>>> http://www.joelonsoftware.com/articles/fog0000000018.html > Of course, I will give Joel one point: too many things related to > programming are 100% hype, without any real substance; if his article > had been about bullshit software hype and he hadn't fired the broadsides > at the very notion of abstraction He did no such thing. I challenge you to find me one place where Joel has *ever* claimed that "the very notion of abstraction" is meaningless or without use. -- Steven From nathan.alexander.rice at gmail.com Thu Mar 29 21:45:51 2012 From: nathan.alexander.rice at gmail.com (Nathan Rice) Date: Thu, 29 Mar 2012 21:45:51 -0400 Subject: Number of languages known [was Re: Python is readable] - somewhat OT In-Reply-To: References: Message-ID: On Thu, Mar 29, 2012 at 7:37 PM, Devin Jeanpierre wrote: > On Thu, Mar 29, 2012 at 3:50 PM, Nathan Rice > wrote: >> Well, a lisp-like language. ?I would also argue that if you are using >> macros to do anything, the thing you are trying to do should classify >> as "not natural in lisp" :) > > You would run into disagreement. Some people feel that the lisp > philosophy is precisely that of extending the language to do anything > you want, in the most natural way. That is some people's lisp philosophy, though I wouldn't say that is a universal. Just like I might say my take on python's philosophy is "keep it simple, stupid" but others could disagree. > At least, I disagree, but my lisp thoughts are the result of > indoctrination of the Racket crowd. I don't know how well they > represent the larger lisp community. But you should definitely take > what I say from the viewpoint of the sort of person that believes that > the whole purpose of lisps is to embed new syntax and new DSLs via > macros. Without macros, there's no point of having this despicable > syntax (barring maybe pedagogy and other minor issues). Heh, I think you can have a homoiconic language without nasty syntax, but I won't get into that right now. >> I'm really thinking here more in terms of a general graph reactive >> system here, matching patterns in an input graph and modifying the >> graph in response. ?There are a lot of systems that can be modeled as >> a graph that don't admit a nested list (tree) description. ?By having >> references to outside the nesting structure you've just admitted that >> you need a graph rather than a list, so why not be honest about it and >> work in that context from the get-go. > > I don't see any issue in defining a library for working with graphs. > If it's useful enough, it could be added to the standard library. > There's nothing all that weird about it. Graphs are the more general and expressive data structure, I think if anything you should special case the less general form. > Also, most representations of graphs are precisely via a tree-like > non-recursive structure. For example, as a matrix, or adjacency list, > etc. We think of them as deep structures, but implement them as flat, > shallow structures. Specialized syntax (e.g. from macros) can > definitely bridge the gap and let you manipulate them in the obvious > way, while admitting the usual implementation. We do a lot of things because they are efficient. That is why gaussian distributions are everywhere in statistics, people approximate nonlinear functions with sums of kernels, etc. It shouldn't be the end goal though, unless it really is the most expressive way of dealing with things. My personal opinion is that graphs are more expressive, and I think it would be a good idea to move towards modeling knowledge and systems with graphical structures. >> I don't think they have to be. ?You can view functions as names for >> temporally ordered sequence of declarative implication statements. >> Databases just leave out the logic (this is hyperbole, I know), so you >> have to do it in client code. ?I don't feel that a database >> necessarily has to be a separate entity, that is just an artifact of >> the localized, specialized view of computation. ?As stronger >> abstractions are developed and concurrent, distributed computation is >> rigorously systematized, I think we'll go full circle. > > Maybe I'm too tired, but this went straight over my head, sorry. > Perhaps you could be a bit more explicit about what you mean by the > implications/logic? Well, the curry howard correspondance says that every function can be seen as a named implication of outputs given inputs, with the code for that function being a representation of its proof. Since pretty much every function is a composition of many smaller functions, this holds down to the lowest level. Even imperative statements can be viewed as functions in this light, if you assume discrete time, and view every function or statement as taking the state of the world at T as an implicit input and returning as an implicit output the state of the world at T+1. Thus, every function (and indeed pretty much all code) can be viewed as a named collection of implication statements in a particular context :) From steve+comp.lang.python at pearwood.info Thu Mar 29 21:56:44 2012 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 30 Mar 2012 01:56:44 GMT Subject: Number of languages known [was Re: Python is readable] - somewhat OT References: Message-ID: <4f7512db$0$29981$c3e8da3$5496439d@news.astraweb.com> On Thu, 29 Mar 2012 13:48:40 -0400, Nathan Rice wrote: > Here's a thought experiment. Imagine that you have a project tree on > your file system which includes files written in many different > programming languages. Imagine that the files can be assumed to be > contiguous for our purposes, so you could view all the files in the > project as one long chunk of data. The directory and file names could > be interpreted as statements in this data, analogous to "in the context > of somedirectory" or "in the context of somefile with sometype". Any > project configuration files could be viewed as declarative statements > about contexts, such as "in xyz context, ignore those" or "in abc > context, any that is actually a this". Imagine the compiler or > interpreter is actually part of your program (which is reasonable since > it doesn't do anything by itself). Imagine the build management tool is > also part of your program in pretty much the same manner. Imagine that > your program actually generates another program that will generate the > program the machine runs. I hope you can follow me here, and further I > hope you can see that this is a completely valid description of what is > actually going on (from a different perspective). [...] > What does pushing the abstraction point that far up provide? I see why you are so hostile towards Joel Spolsky's criticism of Architecture Astronauts: you are one of them. Sorry Nathan, I don't know how you breathe that high up. For what it's worth, your image of "everything from the compiler on up is part of your program" describes both Forth and Hypercard to some degree, both of which I have used and like very much. I still think you're sucking vacuum :( -- Steven From showell30 at yahoo.com Thu Mar 29 22:19:23 2012 From: showell30 at yahoo.com (Steve Howell) Date: Thu, 29 Mar 2012 19:19:23 -0700 (PDT) Subject: Number of languages known [was Re: Python is readable] - somewhat OT References: Message-ID: On Mar 29, 9:42?am, Devin Jeanpierre wrote: > On Thu, Mar 29, 2012 at 10:03 AM, Chris Angelico wrote: > > You can't merge all of them without making a language that's > > suboptimal at most of those tasks - probably, one that's woeful at all > > of them. I mention SQL because, even if you were to unify all > > programming languages, you'd still need other non-application > > languages to get the job done. > > Not really. You can turn SQL (or something equivalent) into a subset > of your programming language, like C# does with LINQ, or like Scheme > does with macros. I'm glad your moving the discussion away from the fake debate between "diversity" (good) and "one-language-fits-all" (horribly naive at best, evil at worse). Of course, there's a middle ground, where (some degree of) language unification is a completely sane goal, at least worthy of discussion. SQL is a well-established lingua franca for describing relationships between sets, or relational algebra. General-purpose languages like C#, Scheme, and Python are well suited to subsuming SQL semantics, and, in fact, they already do, but sometimes they do it a way that's unnecessarily foreign to people who quite easily grok the basics of SQL. The extreme position for language unification would be that Python completely subsumes SQL under its umbrella as first-class syntax. I don't necessarily advocate for that, but I think it's an interesting thought experiment to ask why it doesn't. Just to be clear, I'm talking about SQL as a mechanism to transform sets within Python itself, not external RDMBS engines (although first-class SQL integration could also be useful for that as well). > On the other hand, even similar languages are really hard to run in > the same VM: imagine the hoops you'd have to jump through to get > libraries written in Python 2 and 3 to work together. My take on Python 2 vs. Python 3 is that it's simply a tactical program to get people to upgrade to Python 3. The fact that the two languages can't run on the same VM doesn't really bother me. > With that in mind, the interesting languages to "merge" aren't things > like SQL or regular expressions -- these are so easy to make work with > programming languages, that we do it all the time already (via string > manipulation, but first-class syntax would also be easily possible). > The hard problems are when trying to merge in the semantics of > languages that only "make sense" because they have drastically > different expectations of the world. The example that comes to mind is > Haskell, which relies incredibly strongly on the lack of side effects. > How do you merge Haskell and Python? My view on Haskell and Python is that they should stay alive as competing paradigms. I think you're making a useful distinction between Haskell and SQL. Neither language is well integrated with Python. With Haskell, I think it's for good reason. With SQL, I don't quite understand the status quo (beyond the obvious reasons-- maybe we're just not there yet). > I guess what I really want to say is that the world looks, to me, to > be more optimistic than so many people think it is. If we wanted to, > we could absolutely take the best features from a bunch of things. > This is what C++ does, this is what Scheme does, this is what D does. > They sometimes do it in different ways, they have varying tradeoffs, > but this isn't a hard problem except when it is, and the examples you > mentioned are actually the easy cases. We can merge Python and C, > while keeping roughly the power of both, it's called Cython. I love the fact that C dominates all other languages at its level of abstraction. I wish this were the case one level up, where you still have Python, Ruby, JavaScript, PHP, Perl, and others essentially solving the same classes of problems. Don't get me wrong--I'm all for diversity; I'm not saying we should arbitrarily kill off languages, etc. I'm just saying that there will be *some* benefit when a clear victor emerges, and hopefully that will be Python 3. Whatever language emerges as the victor, it will probably subsume some of the best features of the conquered. To a degree that has already happened. > We can > merge Python and PHP, in that PHP adds nothing incompatible with > Python technically (it'd be a lot of work and there would be many > tears shed because it's insane) -- but Python Server Pages probably > add the feature you want. PHP is a language that I wish would die off quickly and gracefully. I feel like the good things of PHP have already been subsumed into the ecosystems of stronger programming languages (including Python). > We could merge SQL and Python, arguably we > already do via e.g. SQLAlchemy's query API (etc.) or DBAPI2's string > API. These can all becomes subsets of a language that interoperate > well with the rest of the language with no problems. These are > non-issues: the reasons for not doing so are not technical, they are > political or sociological (e.g., "bloat the language", "there should > be one obvious way to do it", "PHP's mixing of business logic with > presentation logic is bad", etc.) > The way that I view the world now is that we have lots of languages that don't interoperate well. To some degree, it's a non-problem of course. The world has many problems to solve, and it's a good thing that we have a diversity of languages to tackle those problems. I get it. Some languages don't interoperate for purely technical reasons, and it would be foolish to fight a losing battle to force square pegs into round holes. I get that, too. Some non-compatible languages coexist with each other for political reasons that are completely legitimate. Even for the same problem domains, there are strongly competing philosophies on fundamental programming concepts, such as mutation, expressiveness, etc. I get that. Finally, though, there is a bunch of *non-essential* diversity, or at least a lot of options that serve more to confuse than empower. Diversity is great, but some level of convergence should be the end game. Diversity is the engine behind progress, of course, but the fuel doesn't always burn clean. > There _are_ times when this is technical, and there are specific areas > of this that have technical difficulties, but... that's different, and > interesting, and being actively researched, and not really impossible > either. > > I don't know. This is maybe a bit too rant-y and disorganized; if so I > apologize. I've been rethinking a lot of my views on programming > languages lately. :) ?I hope at least the links help make this > interesting to someone. I enjoyed hearing your thought process. Thanks! From nathan.alexander.rice at gmail.com Thu Mar 29 22:26:38 2012 From: nathan.alexander.rice at gmail.com (Nathan Rice) Date: Thu, 29 Mar 2012 22:26:38 -0400 Subject: Python is readable In-Reply-To: <4f750f9f$0$29981$c3e8da3$5496439d@news.astraweb.com> References: <4f612b19$0$1379$4fafbaef@reader2.news.tin.it> <4f750f9f$0$29981$c3e8da3$5496439d@news.astraweb.com> Message-ID: > He did no such thing. I challenge you to find me one place where Joel has > *ever* claimed that "the very notion of abstraction" is meaningless or > without use. "When great thinkers think about problems, they start to see patterns. They look at the problem of people sending each other word-processor files, and then they look at the problem of people sending each other spreadsheets, and they realize that there's a general pattern: sending files. That's one level of abstraction already. Then they go up one more level: people send files, but web browsers also "send" requests for web pages. And when you think about it, calling a method on an object is like sending a message to an object! It's the same thing again! Those are all sending operations, so our clever thinker invents a new, higher, broader abstraction called messaging, but now it's getting really vague and nobody really knows what they're talking about any more. Blah. When you go too far up, abstraction-wise, you run out of oxygen. Sometimes smart thinkers just don't know when to stop, and they create these absurd, all-encompassing, high-level pictures of the universe that are all good and fine, but don't actually mean anything at all." To me, this directly indicates he views higher order abstractions skeptically, and assumes because he does not see meaning in them, they don't hold any meaning. Despite Joel's beliefs, new advances in science are in many ways the result of advances in mathematics brought on by very deep abstraction. Just as an example, Von Neumann's treatment of quantum mechanics with linear operators in Hilbert spaces utilizes very abstract mathematics, and without it we wouldn't have modern electronics. I'm 100% behind ranting on software hype. Myopically bashing the type of thinking that resulted in the computer the basher is writing on, not so much. If he had said "if you're getting very high up, find very smart people and talk to them to make sure you're not in wing nut territory" I could have given him a pass. I really wish people wouldn't try to put Joel up on a pedestal. The majority of his writings either seem like sensationalist spins on tautological statements, self aggrandizement or luddite trolling. At least Stephen Wolfram has cool shit to back up his ego, Fog Creek makes decent but overpriced debuggers/version control/issue trackers... From my perspective, Stack Overflow is the first really interesting thing Joel had his hand in, and I suspect Jeff Atwood was probably the reason for it, since SO doesn't look like anything Fog Creek ever produced prior to that. From steve+comp.lang.python at pearwood.info Thu Mar 29 22:45:05 2012 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 30 Mar 2012 02:45:05 GMT Subject: unittest: assertRaises() with an instance instead of a type References: <4f735345$0$29981$c3e8da3$5496439d@news.astraweb.com> Message-ID: <4f751e31$0$29981$c3e8da3$5496439d@news.astraweb.com> On Thu, 29 Mar 2012 09:08:30 +0200, Ulrich Eckhardt wrote: > Am 28.03.2012 20:07, schrieb Steven D'Aprano: >> Secondly, that is not the right way to do this unit test. You are >> testing two distinct things, so you should write it as two separate >> tests: > [..code..] >> If foo does *not* raise an exception, the unittest framework will >> handle the failure for you. If it raises a different exception, the >> framework will also handle that too. >> >> Then write a second test to check the exception code: > [...] >> Again, let the framework handle any unexpected cases. > > Sorry, you got it wrong, it should be three tests: 1. Make sure foo() > raises an exception. 2. Make sure foo() raises the right exception. 3. > Make sure the errorcode in the exception is right. > > Or maybe you should in between verify that the exception raised actually > contains an errorcode? And that the errorcode can be equality-compared > to the expected value? :> Of course you are free to slice it even finer if you like: testFooWillRaiseSomethingButIDontKnowWhat testFooWillRaiseMyException testFooWillRaiseMyExceptionWithErrorcode testFooWillRaiseMyExceptionWithErrorcodeWhichSupportsEquality testFooWillRaiseMyExceptionWithErrorcodeEqualToFooError Five tests :) To the degree that the decision of how finely to slice tests is a matter of personal judgement and/or taste, I was wrong to say "that is not the right way". I should have said "that is not how I would do that test". I believe that a single test is too coarse, and three or more tests is too fine, but two tests is just right. Let me explain how I come to that judgement. If you take a test-driven development approach, the right way to test this is to write testFooWillFail once you decide that foo() should raise MyException but before foo() actually does so. You would write the test, the test would fail, and you would fix foo() to ensure it raises the exception. Then you leave the now passing test in place to detect regressions. Then you do the same for the errorcode. Hence two tests. Since running tests is (usually) cheap, you never bother going back to remove tests which are made redundant by later tests. You only remove them if they are made redundant by chances to the code. So even though the first test is made redundant by the second (if the first fails, so will the second), you don't remove it. Why not? Because it guards against regressions. Suppose I decide that errorcode is no longer needed, so I remove the test for errorcode. If I had earlier also removed the independent test for MyException being raised, I've now lost my only check against regressions in foo(). So: never remove tests just because they are redundant. Only remove them when they are obsolete due to changes in the code being tested. Even when I don't actually write the tests in advance of the code, I still write them as if I were. That usually makes it easy for me to decide how fine grained the tests should be: since there was never a moment when I thought MyException should have an errorcode attribute, but not know what that attribute would be, I don't need a *separate* test for the existence of errorcode. (I would only add such a separate test if there was a bug that sometimes the errorcode does not exist. That would be a regression test.) The question of the exception type is a little more subtle. There *is* a moment when I knew that foo() should raise an exception, but before I decided what that exception would be. ValueError? TypeError? Something else? I can write the test before making that decision: def testFooRaises(self): try: foo() except: # catch anything pass else: self.fail("foo didn't raise") However, the next step is broken: I have to modify foo() to raise an exception, and there is no "raise" equivalent to the bare "except", no way to raise an exception without specifying an exception type. I can use a bare raise, but only in response to an existing exception. So to raise an exception at all, I need to decide what exception that will be. Even if I start with a placeholder "raise BaseException", and test for that, when I go back and change the code to "raise MyException" I should change the test, not create a new test. Hence there is no point is testing for "any exception, I don't care what" since I can't write code corresponding to that test case. Hence, I end up with two tests, not three and certainly not five. -- Steven From steve+comp.lang.python at pearwood.info Thu Mar 29 22:53:47 2012 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 30 Mar 2012 02:53:47 GMT Subject: unittest: assertRaises() with an instance instead of a type References: <4f735345$0$29981$c3e8da3$5496439d@news.astraweb.com> Message-ID: <4f75203a$0$29981$c3e8da3$5496439d@news.astraweb.com> On Thu, 29 Mar 2012 08:35:16 -0700, Ethan Furman wrote: > Steven D'Aprano wrote: >> On Wed, 28 Mar 2012 14:28:08 +0200, Ulrich Eckhardt wrote: >> >>> Hi! >>> >>> I'm currently writing some tests for the error handling of some code. >>> In this scenario, I must make sure that both the correct exception is >>> raised and that the contained error code is correct: >>> >>> >>> try: >>> foo() >>> self.fail('exception not raised') >>> catch MyException as e: >>> self.assertEqual(e.errorcode, SOME_FOO_ERROR) >>> catch Exception: >>> self.fail('unexpected exception raised') >> >> Secondly, that is not the right way to do this unit test. You are >> testing two distinct things, so you should write it as two separate >> tests: > > I have to disagree -- I do not see the advantage of writing a second > test that *will* fail if the first test fails as opposed to bundling > both tests together, and having one failure. Using that reasoning, your test suite should contain *one* ginormous test containing everything: def testDoesMyApplicationWorkPerfectly(self): # TEST ALL THE THINGS!!! ... since *any* failure in any part will cause cascading failures in every other part of the software which relies on that part. If you have a tree of dependencies, a failure in the root of the tree will cause everything to fail, and so by your reasoning, everything should be in a single test. I do not agree with that reasoning, even when the tree consists of two items: an exception and an exception attribute. The problem of cascading test failures is a real one. But I don't believe that the solution is to combine multiple conceptual tests into a single test. In this case, the code being tested covers two different concepts: 1. foo() will raise MyException. Hence one test for this. 2. When foo() raises MyException, the exception instance will include an errorcode attribute with a certain value. This is conceptually separate from #1 above, even though it depends on it. Why is it conceptually separate? Because there may be cases where the caller cares about foo() raising MyException, but doesn't care about the errorcode. Hence errorcode is dependent but separate, and hence a separate test. -- Steven From wuwei23 at gmail.com Thu Mar 29 23:33:24 2012 From: wuwei23 at gmail.com (alex23) Date: Thu, 29 Mar 2012 20:33:24 -0700 (PDT) Subject: weird behaviour: pygame plays in shell but not in script References: <7ef60ccc-c0bb-4aa8-a393-469883897058@k24g2000yqe.googlegroups.com> Message-ID: <0fce59a2-68ac-4c1d-96f5-5e155bcd404e@pg2g2000pbb.googlegroups.com> On Mar 29, 10:41?pm, Mik wrote: > What a nice way to introduce myself to the group!!! :-) Hey, don't beat yourself up, you: - summarised the problem in the subject heading - included actual code showing the problem - reported back on the problem you found That puts you ahead of most new posters. > sorry for bothering you guys :-) No bother at all, welcome to the party :) From steve+comp.lang.python at pearwood.info Thu Mar 29 23:36:27 2012 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 30 Mar 2012 03:36:27 GMT Subject: Python is readable References: <4f612b19$0$1379$4fafbaef@reader2.news.tin.it> <4f750f9f$0$29981$c3e8da3$5496439d@news.astraweb.com> Message-ID: <4f752a3a$0$29981$c3e8da3$5496439d@news.astraweb.com> On Thu, 29 Mar 2012 22:26:38 -0400, Nathan Rice wrote: >> He did no such thing. I challenge you to find me one place where Joel >> has *ever* claimed that "the very notion of abstraction" is meaningless >> or without use. [snip quote] > To me, this directly indicates he views higher order abstractions > skeptically, Yes he does, and so we all should, but that's not the claim you made. You stated that he "fired the broadsides at the very notion of abstraction". He did no such thing. He fired a broadside at (1) software hype based on (2) hyper-abstractions which either don't solve any problems that people care about, or don't solve them any better than more concrete solutions. > and assumes because he does not see meaning in them, they > don't hold any meaning. You are making assumptions about his mindset that not only aren't justified by his comments, but are *contradicted* by his comments. He repeatedly describes the people coming up with these hyper-abstractions as "great thinkers", "clever thinkers", etc. who are seeing patterns in what people do. He's not saying that they're dummies. He's saying that they're seeing patterns that don't mean anything, not that the patterns aren't there. > Despite Joel's beliefs, new advances in science > are in many ways the result of advances in mathematics brought on by > very deep abstraction. Just as an example, Von Neumann's treatment of > quantum mechanics with linear operators in Hilbert spaces utilizes very > abstract mathematics, and without it we wouldn't have modern > electronics. I doubt that very much. The first patent for the transistor was made in 1925, a year before von Neumann even *started* working on quantum mechanics. In general, theory *follows* practice, not the other way around: parts of quantum mechanics theory followed discoveries made using the transistor: http://en.wikipedia.org/wiki/History_of_the_transistor The Romans had perfectly functioning concrete without any abstract understanding of chemistry. If we didn't have QM, we'd still have advanced electronics. Perhaps not *exactly* the electronics we have now, but we'd have something. We just wouldn't understand *why* it works, and so be less capable of *predicting* useful approaches and more dependent on trial-and-error. Medicine and pharmaceuticals continue to be discovered even when we can't predict the properties of molecules. My aunt makes the best damn lasagna you've ever tasted without any overarching abstract theory of human taste. And if you think that quantum mechanics is more difficult than understanding human perceptions of taste, you are badly mistaken. In any case, Spolsky is not making a general attack on abstract science. Your hyperbole is completely unjustified. -- Steven From nathan.alexander.rice at gmail.com Fri Mar 30 00:38:26 2012 From: nathan.alexander.rice at gmail.com (Nathan Rice) Date: Fri, 30 Mar 2012 00:38:26 -0400 Subject: Python is readable In-Reply-To: <4f752a3a$0$29981$c3e8da3$5496439d@news.astraweb.com> References: <4f612b19$0$1379$4fafbaef@reader2.news.tin.it> <4f750f9f$0$29981$c3e8da3$5496439d@news.astraweb.com> <4f752a3a$0$29981$c3e8da3$5496439d@news.astraweb.com> Message-ID: >>> He did no such thing. I challenge you to find me one place where Joel >>> has *ever* claimed that "the very notion of abstraction" is meaningless >>> or without use. > [snip quote] >> To me, this directly indicates he views higher order abstractions >> skeptically, > > Yes he does, and so we all should, but that's not the claim you made. You > stated that he "fired the broadsides at the very notion of abstraction". > He did no such thing. He fired a broadside at (1) software hype based on > (2) hyper-abstractions which either don't solve any problems that people > care about, or don't solve them any better than more concrete solutions. Mathematics is all about abstraction. There are theories and structures in mathematics that have probably gone over a hundred years before being applied. As an analogy, just because a spear isn't useful while farming doesn't mean it won't save your life when you venture into the woods and come upon a bear. >> and assumes because he does not see meaning in them, they >> don't hold any meaning. > > You are making assumptions about his mindset that not only aren't > justified by his comments, but are *contradicted* by his comments. He > repeatedly describes the people coming up with these hyper-abstractions > as "great thinkers", "clever thinkers", etc. who are seeing patterns in > what people do. He's not saying that they're dummies. He's saying that > they're seeing patterns that don't mean anything, not that the patterns > aren't there. He is basically saying they are too clever for their own good, as a result of being fixated upon purely intellectual constructs. If math was a failed discipline I might be willing to entertain that notion, but quite the opposite, it is certainly the most successful area of study. > >> Despite Joel's beliefs, new advances in science >> are in many ways the result of advances in mathematics brought on by >> very deep abstraction. ?Just as an example, Von Neumann's treatment of >> quantum mechanics with linear operators in Hilbert spaces utilizes very >> abstract mathematics, and without it we wouldn't have modern >> electronics. > > I doubt that very much. The first patent for the transistor was made in > 1925, a year before von Neumann even *started* working on quantum > mechanics. The electronic properties of silicon (among other compounds) is an obvious example of where quantum theory provides for us. We might have basic circuits, but we wouldn't have semiconductors. > In general, theory *follows* practice, not the other way around: parts of > quantum mechanics theory followed discoveries made using the transistor: You do need data points to identify an explanatory mathematical structure. > The Romans had perfectly functioning concrete without any abstract > understanding of chemistry. If we didn't have QM, we'd still have > advanced electronics. Perhaps not *exactly* the electronics we have now, > but we'd have something. We just wouldn't understand *why* it works, and > so be less capable of *predicting* useful approaches and more dependent > on trial-and-error. Medicine and pharmaceuticals continue to be > discovered even when we can't predict the properties of molecules. The stochastic method, while useful, is many orders of magnitude less efficient than analytically closed solutions. Not having access to closed form solutions would have put us back hundreds of years at least. > My aunt makes the best damn lasagna you've ever tasted without any > overarching abstract theory of human taste. And if you think that quantum > mechanics is more difficult than understanding human perceptions of > taste, you are badly mistaken. Taste is subjective, and your aunt probably started from a good recipe and tweaked it for local palates. That recipe could easily be over a hundred years old. An overarching mathematical theory of human taste/mouth perception, if such a silly thing were to exist, would be able to generate new recipes that were perfect for a given person's tastes very quickly. Additionally, just to troll this point some more (fun times!), I would argue that there is an implicit theory of human taste (chefs refer to it indirectly as gastronomy) that is very poorly organized and lacks any sort of scientific rigor. Nonetheless, enough empirical observations about pairings of flavors, aromas and textures have been made to guide the creation of new recipes. Gastronomy doesn't need to be organized or rigorous because fundamentally it isn't very important. > In any case, Spolsky is not making a general attack on abstract science. > Your hyperbole is completely unjustified. The mathematics of the 20th century, (from the early 30s onward) tend to get VERY abstract, in just the way Joel decries. Category theory, model theory, modern algebraic geometry, topos theory, algebraic graph theory, abstract algebras and topological complexes are all very difficult to understand because they seem so incredibly abstract, yet most of them already have important applications. I'm 100% positive if you just presented Joel with seminal papers in some of those areas, he would apply the "astronaut" rubber stamp, because the material is challenging, and he wouldn't get it (I love math, and I've had to read some papers 10+ times before they click). All I'm suggesting here is that if someone creates something abstract that is elegant and contains a kernel of fundamental truth on some level but doesn't immediately suggest applications, file it in the "neat and worth revisiting at some point in the distant future" bin and move on, don't denigrate them as asphyxiating space cases who need to stop following their curiosity, come down to earth, and produce some shiny bauble for immediate human consumption. From nathan.alexander.rice at gmail.com Fri Mar 30 01:37:04 2012 From: nathan.alexander.rice at gmail.com (Nathan Rice) Date: Fri, 30 Mar 2012 01:37:04 -0400 Subject: Number of languages known [was Re: Python is readable] - somewhat OT In-Reply-To: <4f7512db$0$29981$c3e8da3$5496439d@news.astraweb.com> References: <4f7512db$0$29981$c3e8da3$5496439d@news.astraweb.com> Message-ID: >> Here's a thought experiment. ?Imagine that you have a project tree on >> your file system which includes files written in many different >> programming languages. ?Imagine that the files can be assumed to be >> contiguous for our purposes, so you could view all the files in the >> project as one long chunk of data. ?The directory and file names could >> be interpreted as statements in this data, analogous to "in the context >> of somedirectory" or "in the context of somefile with sometype". ?Any >> project configuration files could be viewed as declarative statements >> about contexts, such as "in xyz context, ignore those" or "in abc >> context, any that is actually a this". ?Imagine the compiler or >> interpreter is actually part of your program (which is reasonable since >> it doesn't do anything by itself). ?Imagine the build management tool is >> also part of your program in pretty much the same manner. ?Imagine that >> your program actually generates another program that will generate the >> program the machine runs. ?I hope you can follow me here, and further I >> hope you can see that this is a completely valid description of what is >> actually going on (from a different perspective). > [...] >> What does pushing the abstraction point that far up provide? > > I see why you are so hostile towards Joel Spolsky's criticism of > Architecture Astronauts: you are one of them. Sorry Nathan, I don't know > how you breathe that high up. > > For what it's worth, your image of "everything from the compiler on up is > part of your program" describes both Forth and Hypercard to some degree, > both of which I have used and like very much. I still think you're > sucking vacuum :( We live in a world where the tools that are used are based on tradition (read that as backwards compatibility if it makes you feel better) and as a mechanism for deriving personal identity. The world is backwards and retarded in many, many ways, this problem is interesting to me because it actually cuts across a much larger tract than is immediately obvious. People throughout history have had the mistaken impression that the world as it existed for them was the pinnacle of human development. Clearly all of those people were tragically deluded, and I suspect that is the case here as well. From jhsu802701 at gmail.com Fri Mar 30 01:45:38 2012 From: jhsu802701 at gmail.com (Jason Hsu, Mr. Swift Linux) Date: Thu, 29 Mar 2012 22:45:38 -0700 (PDT) Subject: How do I use PyGTK to put text besides clickable buttons? Message-ID: I've decided to use PyGTK instead of gtkdialog for providing configuration menus/dialog boxes in Swift Linux, the Linux distro I started. The problem with gtkdialog is that the i386 version is no longer available in the Debian repository. Since a picture is worth a thousand words, I'll give you a link to a screenshot of antiX Linux: http://antix.freeforums.org/download/file.php?id=23 How do I use PyGTK to create something similar to the logout dialog box in the above graphic? I've figured out how to create clickable buttons that each run a different script. What I haven't figured out is how to add text beside each button. From showell30 at yahoo.com Fri Mar 30 02:44:04 2012 From: showell30 at yahoo.com (Steve Howell) Date: Thu, 29 Mar 2012 23:44:04 -0700 (PDT) Subject: Python is readable References: <4f612b19$0$1379$4fafbaef@reader2.news.tin.it> <4f750f9f$0$29981$c3e8da3$5496439d@news.astraweb.com> <4f752a3a$0$29981$c3e8da3$5496439d@news.astraweb.com> Message-ID: <7d27d34b-99c3-40f5-a405-c293a2e7d577@to5g2000pbc.googlegroups.com> On Mar 29, 9:38?pm, Nathan Rice wrote: > The mathematics of the 20th century, (from the early 30s onward) tend > to get VERY abstract, in just the way Joel decries. ?Category theory, > model theory, modern algebraic geometry, topos theory, algebraic graph > theory, abstract algebras and topological complexes are all very > difficult to understand because they seem so incredibly abstract, yet > most of them already have important applications. ?I'm 100% positive > if you just presented Joel with seminal papers in some of those areas, > he would apply the "astronaut" rubber stamp, because the material is > challenging, and he wouldn't get it (I love math, and I've had to read > some papers 10+ times before they click). Nathan, Don't worry too much about Joel Spolsky, and worry even less about people that allude to him. Joel Spolksy is an early 21st century businessman. He's a smart guy with decent writing skills and semi-interesting thoughts, but he's not gonna change the world. He runs his business by promoting pragmatic processes, writing blogs, procuring comfortable chairs for developers, renting nice loft space in NYC, and building some useful, but basically unoriginal, websites and apps. Everything that Joel Spolsky has ever said in his blog has already been put into practice 100 times over by a bunch of similarly pragmatic early 21st century folk. If you really like math, it is no surprise that you find the current state of computer programming a bit inelegant. 90% of what programmers do in the early 21st century is move the data from HERE to THERE, then another 9% is placing the data in just the right part of the screen. I'm exaggerating a bit, but we're still in the backwaters. It's all engineering now; it's all breeding the faster horse. Or so it seems. There's a natural ebb and flow to progress. In the early to mid 20th century, there were tremendous advances in math, science, and technology, and maybe it's gonna take a full century or two of playing around with shit and arguing about stupid shit until the dust finally settles and we make another quantum jump. From michael at stroeder.com Fri Mar 30 03:04:49 2012 From: michael at stroeder.com (=?UTF-8?B?TWljaGFlbCBTdHLDtmRlcg==?=) Date: Fri, 30 Mar 2012 09:04:49 +0200 Subject: "convert" string to bytes without changing data (encoding) In-Reply-To: <4f75080a$0$29981$c3e8da3$5496439d@news.astraweb.com> References: <9tg21lFmo3U1@mid.dfncis.de> <4f73504c$0$29981$c3e8da3$5496439d@news.astraweb.com> <5B80DD153D7D744689F57F4FB69AF47409291BEC@SCACMX008.exchad.jpmchase.net> <4F736B69.9080600@mrabarnett.plus.com> <4f75080a$0$29981$c3e8da3$5496439d@news.astraweb.com> Message-ID: Steven D'Aprano wrote: > On Thu, 29 Mar 2012 17:36:34 +0000, Prasad, Ramit wrote: > >>>> Technically, ASCII goes up to 256 but they are not A-z letters. >>>> >>> Technically, ASCII is 7-bit, so it goes up to 127. >> >>> No, ASCII only defines 0-127. Values >=128 are not ASCII. >>> >>> >From https://en.wikipedia.org/wiki/ASCII: >>> >>> ASCII includes definitions for 128 characters: 33 are non-printing >>> control characters (now mostly obsolete) that affect how text and >>> space is processed and 95 printable characters, including the space >>> (which is considered an invisible graphic). >> >> >> Doh! I was mistaking extended ASCII for ASCII. Thanks for the >> correction. > > There actually is no such thing as "extended ASCII" -- there is a whole > series of many different "extended ASCIIs". If you look at the encodings > available in (for example) Thunderbird, many of the ISO-8859-* and > Windows-* encodings are "extended ASCII" in the sense that they extend > ASCII to include bytes 128-255. Unfortunately they all extend ASCII in a > different way (hence they are different encodings). Yupp. Looking at RFC 1345 some years ago (while having to deal with EBCDIC) made this all pretty clear to me. I appreciate that someone did this heavy work of collecting historical encodings. Ciao, Michael. From ulrich.eckhardt at dominolaser.com Fri Mar 30 03:05:53 2012 From: ulrich.eckhardt at dominolaser.com (Ulrich Eckhardt) Date: Fri, 30 Mar 2012 09:05:53 +0200 Subject: tabs/spaces In-Reply-To: References: <0ved49-hie.ln1@satorlaser.homedns.org> Message-ID: Am 29.03.2012 17:25, schrieb Terry Reedy: > I am using Thunderbird, win64, as news client for gmane. The post looked > fine as originally received. The indents only disappeared when I hit > reply and the >s were added. I can confirm this misbehaviour of Thunderbird (version 11.0 here), it strips the leading spaces when you begin a reply. Uli From showell30 at yahoo.com Fri Mar 30 03:27:13 2012 From: showell30 at yahoo.com (Steve Howell) Date: Fri, 30 Mar 2012 00:27:13 -0700 (PDT) Subject: Python is readable References: <4f612b19$0$1379$4fafbaef@reader2.news.tin.it> <4f750f9f$0$29981$c3e8da3$5496439d@news.astraweb.com> <4f752a3a$0$29981$c3e8da3$5496439d@news.astraweb.com> Message-ID: On Mar 29, 8:36?pm, Steven D'Aprano wrote: > The Romans had perfectly functioning concrete without any abstract > understanding of chemistry. If I ever stumbled upon a technology that proved how useless abstract thinking was, do you know what I would call it? "Concrete." Damn, those clever Romans beat me to it by a couple millennia! And they had AQUEDUCTS!!! > [...] Medicine and pharmaceuticals continue to be > discovered even when we can't predict the properties of molecules. I know this is really, really far out, and I should probably come back down to earth, but I can envision some sort of 25th century utopia where scientists measure the weights and charges and atoms, and arrange them into some kind of chart, and just BASED ON THE CHART ALONE, these 25th century scientists might be able to predict behaviors that have never been observed, just BASED ON ABSTRACT REASONING. Whoa! That's really far out stuff. Give me some oxygen! (preferably of the 1s2 2s2 2p4 variety) (Yep, I get it, the periodic table is about atoms, and medicine/ pharmaceuticals are about molecules, so your point is not invalid. It's still alchemy, though.) From xahlee at gmail.com Fri Mar 30 04:27:16 2012 From: xahlee at gmail.com (Xah Lee) Date: Fri, 30 Mar 2012 01:27:16 -0700 (PDT) Subject: Is Programing Art or Science? Message-ID: the refreshen of the blood, from Xah's Entertainment Enterprise, i bring you: ?Is Programing Art or Science? http://xahlee.org/UnixResource_dir/writ/art_or_science.html penned in the year of our lord two thousand and two, plain text version follows. -------------------------------- Is Programing Art or Science? Dear friends, You mentioned the title of Donald Knuth's magnum opus Art of Programming in the context of discussion that fringes on whether programing is science or art. I'm quite pissed off at work at the moment, so let me take the time to give some guide on this matter to the daily programers. At the bottom rung of programers, there's no question about whether programing is science or art. Because monkey coders could not care less. These folks ain't be reading this post, for they hardly will have heard of lisp. This leaves us with elite programers who have a smattering of interests on cogitation and philosophical conundrums. So, is programing a science or art? For the programing morons, this question is associated with erudition. It certainly is a hip subject among hackers such as those hardcore Perl advocates and unix proponents, who would casually hint on such realization, impressing a sophistication among peers. Such a question is not uncommon among those curious. For example, ?Is mathematics science or art??, is the same type of question that has been broached by dabblers now and then. We can also detect such dilemma in the titles conferred to blathering computer jockeys: which one are thee: baccalaureate of science or baccalaureate of arts? It really makes no fucking difference. Ultimately, fantastically stupid questions like these are not discussed by mathematicians nor philosophers. These are natural language side-effects, trapping dummies to fuzz about nothing; not unlike quotations. For these computing jockeys, there remains the question of why Knuth named his books the ?Art? of Computer Programing, or why some computing luminaries litter the caution that programing is as much a art as science. What elite dimwits need to realize is that these authors are not defining or correcting, but breaking precepts among the automatons in programing industry. To the readers of hip literature, words like science and art are spellbinding, and the need to pigeonhole is imminent. Of these ruminating class of people, the problem lies in their wanting of originality. What fills their banal brain are the stale food of thought that has been chewed and spewed. These above-average eggheads mop up the scholastic tidbits of its day to mull and muse with fellow eggheads. They could not see new perspectives. Could not understand gists. Could not detect non-questions. They are the holder and passer of knowledge, a bucket of pre-digested purees. Their train of thought forever loops around established tracks ? going nowhere, anytime! So, is programing a art or science? is it art or science? I really need to know. ? Theory vs Practice ? Jargons of IT Industry ? The Lambda Logo Tour ? English Lawers PS don't forget to checkout: ?From Why Not Ruby to Fuck Python, Hello Ruby? @ http://xahlee.org/UnixResource_dir/writ/why_not_Ruby.html yours humbly, Xah From john_ladasky at sbcglobal.net Fri Mar 30 05:25:05 2012 From: john_ladasky at sbcglobal.net (John Ladasky) Date: Fri, 30 Mar 2012 02:25:05 -0700 (PDT) Subject: No os.copy()? Why not? References: <38b3fc48-1d05-4373-b32e-64da95173864@pz2g2000pbc.googlegroups.com> <20bc37f2-9eac-47f0-9ab2-150da6ca203b@mq9g2000pbb.googlegroups.com> Message-ID: <918efe53-421b-433a-88ca-ddcf7a576afb@x10g2000pbi.googlegroups.com> On Mar 28, 9:50?pm, alex23 wrote: > On Mar 29, 6:12?am, John Ladasky wrote: > > > I'm looking for a Python (2.7) equivalent to the Unix "cp" command. > > Any help? ?Thanks. > > Try the shutil module:http://docs.python.org/library/shutil.html Many thanks! That's what I was looking for. From steve+comp.lang.python at pearwood.info Fri Mar 30 06:47:32 2012 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 30 Mar 2012 10:47:32 GMT Subject: Python is readable References: <4f612b19$0$1379$4fafbaef@reader2.news.tin.it> <4f750f9f$0$29981$c3e8da3$5496439d@news.astraweb.com> <4f752a3a$0$29981$c3e8da3$5496439d@news.astraweb.com> Message-ID: <4f758f43$0$29981$c3e8da3$5496439d@news.astraweb.com> On Fri, 30 Mar 2012 00:38:26 -0400, Nathan Rice wrote: >>>> He did no such thing. I challenge you to find me one place where Joel >>>> has *ever* claimed that "the very notion of abstraction" is >>>> meaningless or without use. >> [snip quote] >>> To me, this directly indicates he views higher order abstractions >>> skeptically, >> >> Yes he does, and so we all should, but that's not the claim you made. >> You stated that he "fired the broadsides at the very notion of >> abstraction". He did no such thing. He fired a broadside at (1) >> software hype based on (2) hyper-abstractions which either don't solve >> any problems that people care about, or don't solve them any better >> than more concrete solutions. > > Mathematics is all about abstraction. There are theories and structures > in mathematics that have probably gone over a hundred years before being > applied. As an analogy, just because a spear isn't useful while farming > doesn't mean it won't save your life when you venture into the woods and > come upon a bear. A spear is a concrete application of the principle of leverage, not an abstraction. I also point out leverage was discovered experimentally long before anyone had an abstraction for it. In any case, so what? Who is saying that mathematics is useless? Not me, and not Joel Spolksy. You are hunting strawmen with your non-abstract spear. Spolsky has written at least three times about Architecture Astronauts, and made it abundantly clear that the problem with them is that they don't solve problems, they invent overarching abstractions that don't do anything useful or important, and hype them everywhere. http://www.joelonsoftware.com/articles/fog0000000018.html http://www.joelonsoftware.com/items/2005/10/21.html http://www.joelonsoftware.com/items/2008/05/01.html Jeff Attwood provides a simple test for the difference between a useful abstraction and an Architecture Astronaut hyper-abstraction: Does it solve a useful problem? http://www.codinghorror.com/blog/2004/12/it-came-from-planet-architecture.html You keep reading this as an assault on abstract mathematics, science and knowledge for its on sake. It isn't any of these things. If I'm paid to solve a problem, and instead I build an abstraction that doesn't help solve the problem, then I'm guilty of doing architecture astronauting. >>> and assumes because he does not see meaning in them, they don't hold >>> any meaning. >> >> You are making assumptions about his mindset that not only aren't >> justified by his comments, but are *contradicted* by his comments. He >> repeatedly describes the people coming up with these hyper-abstractions >> as "great thinkers", "clever thinkers", etc. who are seeing patterns in >> what people do. He's not saying that they're dummies. He's saying that >> they're seeing patterns that don't mean anything, not that the patterns >> aren't there. > > He is basically saying they are too clever for their own good, as a > result of being fixated upon purely intellectual constructs. Yes, and he is right to do so, because that is the characteristic of the Architecture Astronaut: being so fixated on over-arching abstract concepts that, far from those abstractions making it easier to solve the problems they are being paid to solve, they actually make them harder. Good abstractions enable problems to be solved. Bad abstractions don't. If I ask you to build me a website, I probably don't want a website- builder, I certainly don't want a website-builder-generator, and I absolutely do not want you to generalise the concept of a compiler and create a whole new abstract language for describing meta-compilers so that I can create a brand new programming language for generating meta- compilers that build compilers that will build factories for building website generators so I can make my own website in just three easy steps (the simplest one of which is about twice as difficult as just building the website would have been). If you are being paid to build abstractions in the ivory tower, on the chance that one in a thousand abstractions turns out to be a game changer, or just because of a love of pure knowledge, that's great. I love abstract mathematics too. I read maths in my free time, you won't find me saying that it is bad or useless or harmful. But does it solve real problems? Well, of course it does, and often in a most surprising places. But that's because out of the hundred thousand abstractions, we see the hundred that actually solve concrete problems. The other 99,999 exist only in forgotten journals, or perhaps the odd book here or there. This is all well and good. It's not meant as an attack on mathematics. You can't tell ahead of time which abstractions will solve real problems. *Somebody* has to be thinking about ways that spherical camels can pass through the eye of a 17-dimensional needle, because you never know when somebody else will say, "Hey, that's just what we need to make low-fat chocolate ice cream that doesn't taste like crap!" and then you'll be richer beyond all the dreams of avarice. But that doesn't mean that you have to turn every one of those abstractions into software. I don't really care if checking my email and deleting a file are both special cases of some abstract file operation, I don't need to see it in my file manager. [...] > The electronic properties of silicon (among other compounds) is an > obvious example of where quantum theory provides for us. We might have > basic circuits, but we wouldn't have semiconductors. A poor example. The existence of semiconductors was demonstrated, not predicted: Michael Faraday discovered the existence of semiconductors in 1833, *long* before quantum theory: http://sites.google.com/site/transistorhistory/faraday-to-shockley The existence of photoconductivity was one of the experimental discoveries which eventually led to QM, via Einstein's explanation of the photoelectric effect. But what's your point here? We started off talking about abstractions. Quantum mechanics is not an abstraction, or at least no more than any other physical theory. It is a *description* of reality (a model), not a generalisation. To counter Spolksy, you need to show the great practical discoveries and inventions, not of quantum mechanics, but of a *generalisation* of quantum mechanics that encompasses QM as a special, concrete, example. [...] > The stochastic method, while useful, is many orders of magnitude less > efficient than analytically closed solutions. Not having access to > closed form solutions would have put us back hundreds of years at least. We don't have closed-form solutions. At best we have closed-form solutions of simplified and idealised problems. E.g. we don't have a closed-form solution for the actual hydrogen atom, only of a simplified model of that atom: http://en.wikipedia.org/wiki/Hydrogen_atom#Features_going_beyond_the_Schr.C3.B6dinger_solution And likewise for helium, e.g. one simplifying approximation is to ignore the electron-electron repulsion. And that's hardly the only one. As for closed-form solutions of real devices like a CPU? Forget it. As the famous saying goes, the more advanced the theory, the fewer entities it can solve exactly. Newtonian physics can't solve the three body problem exactly; Einsteinian physics can't solve the two body problem; quantum mechanics can't solve the one body problem; and quantum gravity can't solve the zero body problem (the vacuum). -- Steven From mikprog at gmail.com Fri Mar 30 07:16:34 2012 From: mikprog at gmail.com (Mik) Date: Fri, 30 Mar 2012 04:16:34 -0700 (PDT) Subject: weird behaviour: pygame plays in shell but not in script References: <7ef60ccc-c0bb-4aa8-a393-469883897058@k24g2000yqe.googlegroups.com> <0fce59a2-68ac-4c1d-96f5-5e155bcd404e@pg2g2000pbb.googlegroups.com> Message-ID: Oh thanks alex! that's kind! PS: It looks like a party indeed: plenty of interesting discussions :-) On Mar 30, 4:33?am, alex23 wrote: > On Mar 29, 10:41?pm, Mik wrote: > > > What a nice way to introduce myself to the group!!! :-) > > Hey, don't beat yourself up, you: > > ?- summarised the problem in the subject heading > ?- included actual code showing the problem > ?- reported back on the problem you found > > That puts you ahead of most new posters. > > > sorry for bothering you guys :-) > > No bother at all, welcome to the party :) From kiuhnm03.4t.yahoo.it Fri Mar 30 07:27:34 2012 From: kiuhnm03.4t.yahoo.it (Kiuhnm) Date: Fri, 30 Mar 2012 13:27:34 +0200 Subject: Pipelining in Python Message-ID: <4f7598a7$0$1391$4fafbaef@reader1.news.tin.it> I decided to withdraw my proposal for streaming programming :) and to fall back to something more conventional. Here's the full story: The new operators are '>>' which does the pipelining and '-' which links functions Pipelining is "function application in reverse order" and linking is "function composition in reverse order". Therefore, arg >> f means f(arg) and arg >> f - g means g(f(arg)) Let's look at some examples: ---> 1) range(0,50) >> filter(lambda i : i%2) >> map(lambda i : i*i) >> my_print (Yes, that's currying.) 2) compFunc = filter(lambda i : i%2) - map(lambda i : i*i) range(0,50) >> compFunc >> my_print 3) (Sieve of Eratosthenes) # Tells whether x is not a proper multiple of n. notPropMult = cur(lambda n, x : x <= n or x % n, 2) def findPrimes(upTo): if (upTo <= 5): return [2, 3, 5] filterAll = (findPrimes(floor(sqrt(upTo))) >> map(lambda x : filter(notPropMult(x))) >> reduce(lambda f, g : f - g)) return list(range(2, upTo + 1)) >> filterAll findPrimes(1000) >> my_print 4) (Finds the approximate number of hrefs in a web page) def do(proc, arg): proc() return arg do = cur(do) cprint = cur(print) ("http://python.org" >> do(cprint("The page http://python.org has about... ", end = '')) >> do(sys.stdout.flush) >> urlopen >> cur(lambda x : x.read()) >> findall(b"href=\"") >> cur(len) >> cur("{} hrefs.".format) >> cprint) <--- And here's the complete source code (which includes a class version of /cur/ and the old tests/examples): ---> class CurriedFunc: def __init__(self, func, args = (), kwArgs = {}, unique = True, minArgs = None): self.__func = func self.__myArgs = args self.__myKwArgs = kwArgs self.__unique = unique self.__minArgs = minArgs def __call__(self, *args, **kwArgs): if args or kwArgs: # some more args! # Allocates data to assign to the next CurriedFunc. newArgs = self.__myArgs + args newKwArgs = dict.copy(self.__myKwArgs) # If unique is True, we don't want repeated keyword arguments. if self.__unique and not kwArgs.keys().isdisjoint(newKwArgs): raise ValueError("Repeated kw arg while unique = True") # Adds/updates keyword arguments. newKwArgs.update(kwArgs) # Checks whether it's time to evaluate func. if self.__minArgs is not None and self.__minArgs <= len(newArgs) + len(newKwArgs): return self.__func(*newArgs, **newKwArgs) # time to evaluate func else: return CurriedFunc(self.__func, newArgs, newKwArgs, self.__unique, self.__minArgs) else: # the evaluation was forced return self.__func(*self.__myArgs, **self.__myKwArgs) def __rrshift__(self, arg): return self.__func(*(self.__myArgs + (arg,)), **self.__myKwArgs) # forces evaluation def __sub__(self, other): if not isinstance(other, CurriedFunc): raise TypeError("Cannot compose a CurriedFunc with another type") def compFunc(*args, **kwArgs): return other.__func(*(other.__myArgs + (self.__func(*args, **kwArgs),)), **other.__myKwArgs) return CurriedFunc(compFunc, self.__myArgs, self.__myKwArgs, self.__unique, self.__minArgs) def cur(f, minArgs = None): return CurriedFunc(f, (), {}, True, minArgs) def curr(f, minArgs = None): return CurriedFunc(f, (), {}, False, minArgs) # Simple Function. def func(a, b, c, d, e, f, g = 100): print(a, b, c, d, e, f, g) # NOTE: '<====' means "this line prints to the screen". # Example 1. f = cur(func) # f is a "curried" version of func c1 = f(1) c2 = c1(2, d = 4) # Note that c is still unbound c3 = c2(3)(f = 6)(e = 5) # now c = 3 c3() # () forces the evaluation <==== # it prints "1 2 3 4 5 6 100" c4 = c2(30)(f = 60)(e = 50) # now c = 30 c4() # () forces the evaluation <==== # it prints "1 2 30 4 50 60 100" print("\n------\n") # Example 2. f = curr(func) # f is a "curried" version of func # curr = cur with possibly repeated # keyword args c1 = f(1, 2)(3, 4) c2 = c1(e = 5)(f = 6)(e = 10)() # ops... we repeated 'e' because we <==== # changed our mind about it! # again, () forces the evaluation # it prints "1 2 3 4 10 6 100" print("\n------\n") # Example 3. f = cur(func, 6) # forces the evaluation after 6 arguments c1 = f(1, 2, 3) # num args = 3 c2 = c1(4, f = 6) # num args = 5 c3 = c2(5) # num args = 6 ==> evalution <==== # it prints "1 2 3 4 5 6 100" c4 = c2(5, g = -1) # num args = 7 ==> evaluation <==== # we can specify more than 6 arguments, but # 6 are enough to force the evaluation # it prints "1 2 3 4 5 6 -1" print("\n------\n") # Example 4. def printTree(func, level = None): if level is None: printTree(cur(func), 0) elif level == 6: func(g = '')() # or just func('')() else: printTree(func(0), level + 1) printTree(func(1), level + 1) printTree(func) print("\n------\n") def f2(*args): print(", ".join(["%3d"%(x) for x in args])) def stress(f, n): if n: stress(f(n), n - 1) else: f() # enough is enough stress(cur(f2), 100) # Pipelining and Function Composition print("\n--- Pipelining & Composition ---\n") import sys from urllib.request import urlopen from re import findall from math import sqrt, floor from functools import reduce map = cur(map, 2) filter = cur(filter, 2) urlopen = cur(urlopen) findall = cur(findall) my_print = cur(lambda list : print(*list)) reduce = cur(reduce, 2) # Example 5 range(0,50) >> filter(lambda i : i%2) >> map(lambda i : i*i) >> my_print print("---") # Example 6 compFunc = filter(lambda i : i%2) - map(lambda i : i*i) range(0,50) >> compFunc >> my_print print("---") # Example 7 # Tells whether x is not a proper multiple of n. notPropMult = cur(lambda n, x : x <= n or x % n, 2) def findPrimes(upTo): if (upTo <= 5): return [2, 3, 5] filterAll = (findPrimes(floor(sqrt(upTo))) >> map(lambda x : filter(notPropMult(x))) >> reduce(lambda f, g : f - g)) return list(range(2, upTo + 1)) >> filterAll findPrimes(1000) >> my_print print("---") # Example 8 # Finds the approximate number of hrefs in a web page. def do(proc, arg): proc() return arg do = cur(do) cprint = cur(print) ("http://python.org" >> do(cprint("The page http://python.org has about... ", end = '')) >> do(sys.stdout.flush) >> urlopen >> cur(lambda x : x.read()) >> findall(b"href=\"") >> cur(len) >> cur("{} hrefs.".format) >> cprint) <--- Kiuhnm From luch at ank-sia.com Fri Mar 30 07:41:40 2012 From: luch at ank-sia.com (Alexey Luchko) Date: Fri, 30 Mar 2012 14:41:40 +0300 Subject: errors building python 2.7.3 In-Reply-To: References: <4F72FAF9.8000802@ank-sia.com> <4F743FAE.4070909@ank-sia.com> Message-ID: <4F759BF4.3050305@ank-sia.com> On 29.03.2012 21:29, David Robinow wrote: > Have you included the patch to Include/py_curses.h ? > If you don't know what that is, download the cygwin src package for > Python-2.6 and look at the patches. Not all of them are still Thanks for the hint. With cygwin's 2.6.5-ncurses-abi6.patch it works with both ncurses and ncursesw. -- Alex From rustompmody at gmail.com Fri Mar 30 08:46:32 2012 From: rustompmody at gmail.com (rusi) Date: Fri, 30 Mar 2012 05:46:32 -0700 (PDT) Subject: weird behaviour: pygame plays in shell but not in script References: <7ef60ccc-c0bb-4aa8-a393-469883897058@k24g2000yqe.googlegroups.com> <0fce59a2-68ac-4c1d-96f5-5e155bcd404e@pg2g2000pbb.googlegroups.com> Message-ID: On Mar 30, 8:33?am, alex23 wrote: > On Mar 29, 10:41?pm, Mik wrote: > > > What a nice way to introduce myself to the group!!! :-) > > Hey, don't beat yourself up, you: > > ?- summarised the problem in the subject heading > ?- included actual code showing the problem > ?- reported back on the problem you found > > That puts you ahead of most new posters. Well said. I only disagree with the 'new' From d at davea.name Fri Mar 30 08:47:46 2012 From: d at davea.name (Dave Angel) Date: Fri, 30 Mar 2012 08:47:46 -0400 Subject: tabs/spaces In-Reply-To: References: <0ved49-hie.ln1@satorlaser.homedns.org> Message-ID: <4F75AB72.2090806@davea.name> On 03/30/2012 03:05 AM, Ulrich Eckhardt wrote: > Am 29.03.2012 17:25, schrieb Terry Reedy: >> I am using Thunderbird, win64, as news client for gmane. The post looked >> fine as originally received. The indents only disappeared when I hit >> reply and the >s were added. > > I can confirm this misbehaviour of Thunderbird (version 11.0 here), it > strips the leading spaces when you begin a reply. > > Uli But since it doesn't do it on all messages, have you also confirmed that it does it for a text message? My experience seems to be that only the html messages are messed up that way. of course, it could be lots of other things, like which gateways did the message go through, was it originally sent via the google-mars bridge, etc. -- DaveA From nathan.alexander.rice at gmail.com Fri Mar 30 09:46:28 2012 From: nathan.alexander.rice at gmail.com (Nathan Rice) Date: Fri, 30 Mar 2012 09:46:28 -0400 Subject: Python is readable In-Reply-To: <4f758f43$0$29981$c3e8da3$5496439d@news.astraweb.com> References: <4f612b19$0$1379$4fafbaef@reader2.news.tin.it> <4f750f9f$0$29981$c3e8da3$5496439d@news.astraweb.com> <4f752a3a$0$29981$c3e8da3$5496439d@news.astraweb.com> <4f758f43$0$29981$c3e8da3$5496439d@news.astraweb.com> Message-ID: >> Mathematics is all about abstraction. ?There are theories and structures >> in mathematics that have probably gone over a hundred years before being >> applied. ?As an analogy, just because a spear isn't useful while farming >> doesn't mean it won't save your life when you venture into the woods and >> come upon a bear. > > A spear is a concrete application of the principle of leverage, not an > abstraction. I also point out leverage was discovered experimentally long > before anyone had an abstraction for it. And an analogy is a device to demonstrate the fundamental character of an argument in a different context. > In any case, so what? Who is saying that mathematics is useless? Not me, > and not Joel Spolksy. You are hunting strawmen with your non-abstract > spear. I don't think it is a strawman. He decries things that aren't immediately useful. That describes almost all pure math. If he had excluded things that have some characteristic of truth, and just talked about overly general systems, I might agree with him. > Spolsky has written at least three times about Architecture Astronauts, > and made it abundantly clear that the problem with them is that they > don't solve problems, they invent overarching abstractions that don't do > anything useful or important, and hype them everywhere. I believe in the idea of "things should be as simple as possible, but not simpler". Programming as it currently exists is absolutely convoluted. I am called on to help people learn to program from time to time, and I can tell you that we still have a LONG way to go before programming approaches a global optimum in either the semantic or syntactic space. Never mind configuring a build or anything else related to projects. The whole setup really is horrible, and I'm convinced that most of the people who are capable of changing this are more concerned about their personal investment in the way things are than helping others. There are a few exceptions like Alan Kay, but mostly people want to graft shortcuts on to what already exists. > You keep reading this as an assault on abstract mathematics, science and > knowledge for its on sake. It isn't any of these things. I never said it was an attack on science. Scientists don't really do abstraction, they explain observations. Mathematicians are the ones who discover truth that may be completely disconnected from reality. > If I'm paid to solve a problem, and instead I build an abstraction that > doesn't help solve the problem, then I'm guilty of doing architecture > astronauting. If I ignore everything Joel wrote and just use that definition, I agree with you. >> He is basically saying they are too clever for their own good, as a >> result of being fixated upon purely intellectual constructs. > > Yes, and he is right to do so, because that is the characteristic of the > Architecture Astronaut: being so fixated on over-arching abstract > concepts that, far from those abstractions making it easier to solve the > problems they are being paid to solve, they actually make them harder. > > Good abstractions enable problems to be solved. Bad abstractions don't. > > If I ask you to build me a website, I probably don't want a website- > builder, I certainly don't want a website-builder-generator, and I > absolutely do not want you to generalise the concept of a compiler and > create a whole new abstract language for describing meta-compilers so > that I can create a brand new programming language for generating meta- > compilers that build compilers that will build factories for building > website generators so I can make my own website in just three easy steps > (the simplest one of which is about twice as difficult as just building > the website would have been). Again, I follow the principle of "everything should be as simple as possible, but no simpler". I have in the past built website builders rather than build websites (and done a similar thing in other cases), but not because I am trying to discover some fundamental truth of website building, because that would be bullshit. I did it because building websites (or whatever else it was) is a boring, tedious problem, and a website builder, while being more work, is an engaging problem that requires thought. I enjoy challenging myself. > If you are being paid to build abstractions in the ivory tower, on the > chance that one in a thousand abstractions turns out to be a game > changer, or just because of a love of pure knowledge, that's great. I > love abstract mathematics too. I read maths in my free time, you won't > find me saying that it is bad or useless or harmful. But does it solve > real problems? You forget that even abstractions that never directly get turned into something real are almost invariably part of the intellectual discourse that leads to real things. > Well, of course it does, and often in a most surprising places. But > that's because out of the hundred thousand abstractions, we see the > hundred that actually solve concrete problems. The other 99,999 exist > only in forgotten journals, or perhaps the odd book here or there. It is pretty rare that an article that has some element of truth doesn't live on through its intellectual progeny. The abstraction that is used in some amazing way will almost always have a large number of "useless" abstractions as intellectual ancestors. This is easy to see just by following the chain of citations for a paper. > This is all well and good. It's not meant as an attack on mathematics. > You can't tell ahead of time which abstractions will solve real problems. > *Somebody* has to be thinking about ways that spherical camels can pass > through the eye of a 17-dimensional needle, because you never know when > somebody else will say, "Hey, that's just what we need to make low-fat > chocolate ice cream that doesn't taste like crap!" and then you'll be > richer beyond all the dreams of avarice. I think you're overly concerned with money and consumption Steven. Those things are ephemeral. Things like truth and beauty are eternal. Moreover, research in psychology suggests people who pursue money and consumption are less happy in general than people who derive joy from creation. > But that doesn't mean that you have to turn every one of those > abstractions into software. I don't really care if checking my email and > deleting a file are both special cases of some abstract file operation, I > don't need to see it in my file manager. Careful Steven, when you make statements like this, it makes me want to agree with you. People are paralyzed by choice, and in general they want to be told what to do, so having interfaces tons of options actually distresses them. >> The electronic properties of silicon (among other compounds) is an >> obvious example of where quantum theory provides for us. ?We might have >> basic circuits, but we wouldn't have semiconductors. > > A poor example. The existence of semiconductors was demonstrated, not > predicted: Michael Faraday discovered the existence of semiconductors in > 1833, *long* before quantum theory: He observed a phenomenon, he did not explain it. > But what's your point here? We started off talking about abstractions. > Quantum mechanics is not an abstraction, or at least no more than any > other physical theory. It is a *description* of reality (a model), not a > generalisation. Lattice theory, rings of operators, Hilbert spaces, Lebesgue measure. All very abstract mathematical structures created not to solve a particular problem in the real world, but as descriptions of mathematical truth. > To counter Spolksy, you need to show the great practical discoveries and > inventions, not of quantum mechanics, but of a *generalisation* of > quantum mechanics that encompasses QM as a special, concrete, example. Quantum mechanics is built on a foundation of "meaningless" abstractions. If those abstractions did not exist we wouldn't have computers. > > [...] >> The stochastic method, while useful, is many orders of magnitude less >> efficient than analytically closed solutions. ?Not having access to >> closed form solutions would have put us back hundreds of years at least. > > We don't have closed-form solutions. > > At best we have closed-form solutions of simplified and idealised > problems. E.g. we don't have a closed-form solution for the actual > hydrogen atom, only of a simplified model of that atom: Of course, the world is complex and stochastic. The only complete solution of a system is the system itself. Thankfully, things like the central limit theorem allow us to pretend a lot of that complexity doesn't exist without sacrificing much. > As the famous saying goes, the more advanced the theory, the fewer > entities it can solve exactly. Newtonian physics can't solve the three > body problem exactly; Einsteinian physics can't solve the two body > problem; quantum mechanics can't solve the one body problem; and quantum > gravity can't solve the zero body problem (the vacuum). That may be true in some cases, but I wouldn't call that a universal. If you have to cross a boundary from linear to nonlinear or finitary to infinitary, of course things are going to get messy, because some areas of math are better developed than others. A complex linear system is just as easy to work with as a simple linear system though. From showell30 at yahoo.com Fri Mar 30 12:02:38 2012 From: showell30 at yahoo.com (Steve Howell) Date: Fri, 30 Mar 2012 09:02:38 -0700 (PDT) Subject: Python is readable References: <4f612b19$0$1379$4fafbaef@reader2.news.tin.it> <4f750f9f$0$29981$c3e8da3$5496439d@news.astraweb.com> <4f752a3a$0$29981$c3e8da3$5496439d@news.astraweb.com> <4f758f43$0$29981$c3e8da3$5496439d@news.astraweb.com> Message-ID: <64eb2ae9-b4ec-4acb-92bf-de4a86f0b83c@sv8g2000pbc.googlegroups.com> On Mar 30, 3:47?am, Steven D'Aprano wrote: > If you are being paid to build abstractions in the ivory tower, on the > chance that one in a thousand abstractions turns out to be a game > changer, or just because of a love of pure knowledge, that's great. I > love abstract mathematics too. I read maths in my free time, you won't > find me saying that it is bad or useless or harmful. But does it solve > real problems? > > Well, of course it does, and often in a most surprising places. But > that's because out of the hundred thousand abstractions, we see the > hundred that actually solve concrete problems. The other 99,999 exist > only in forgotten journals, or perhaps the odd book here or there. > Steven, how do you predict which abstractions are going to be useless? There was a time when imaginary numbers were just little toys that the mathematicians played around with in their ivory towers. I mean, really, what possible use could we have for the square root of -1, other than to entertain mathematicians avoiding "real" problems? Now the complex number plane helps us do 3-D math (air traffic control), circuit design (radios, computers), and frequency analysis (telecommunication). From rosuav at gmail.com Fri Mar 30 12:20:35 2012 From: rosuav at gmail.com (Chris Angelico) Date: Sat, 31 Mar 2012 03:20:35 +1100 Subject: Python is readable In-Reply-To: References: <4f612b19$0$1379$4fafbaef@reader2.news.tin.it> <4f750f9f$0$29981$c3e8da3$5496439d@news.astraweb.com> <4f752a3a$0$29981$c3e8da3$5496439d@news.astraweb.com> <4f758f43$0$29981$c3e8da3$5496439d@news.astraweb.com> Message-ID: On Sat, Mar 31, 2012 at 12:46 AM, Nathan Rice wrote: > I believe in the idea of "things should be as simple as possible, but > not simpler". ?Programming as it currently exists is absolutely > convoluted. ?I am called on to help people learn to program from time > to time, and I can tell you that we still have a LONG way to go before > programming approaches a global optimum in either the semantic or > syntactic space. Aside from messes of installing and setting up language interpreters/compilers, which are averted by simply having several pre-installed (I think my Linux boxes come with some Python 2 version, Perl, bash, and a few others), that isn't really the case. Starting a Python script is easy. Programming gets convoluted only when, and to the extent that, the task does. ChrisA From ramit.prasad at jpmorgan.com Fri Mar 30 12:40:19 2012 From: ramit.prasad at jpmorgan.com (Prasad, Ramit) Date: Fri, 30 Mar 2012 16:40:19 +0000 Subject: Python is readable In-Reply-To: References: <4f612b19$0$1379$4fafbaef@reader2.news.tin.it> <4f750f9f$0$29981$c3e8da3$5496439d@news.astraweb.com> <4f752a3a$0$29981$c3e8da3$5496439d@news.astraweb.com> Message-ID: <5B80DD153D7D744689F57F4FB69AF474092943BB@SCACMX008.exchad.jpmchase.net> > > My aunt makes the best damn lasagna you've ever tasted without any > > overarching abstract theory of human taste. And if you think that > quantum > > mechanics is more difficult than understanding human perceptions of > > taste, you are badly mistaken. > > Taste is subjective, and your aunt probably started from a good recipe > and tweaked it for local palates. That recipe could easily be over a > hundred years old. An overarching mathematical theory of human > taste/mouth perception, if such a silly thing were to exist, would be > able to generate new recipes that were perfect for a given person's > tastes very quickly. > > Additionally, just to troll this point some more (fun times!), I would > argue that there is an implicit theory of human taste (chefs refer to > it indirectly as gastronomy) that is very poorly organized and lacks > any sort of scientific rigor. Nonetheless, enough empirical > observations about pairings of flavors, aromas and textures have been > made to guide the creation of new recipes. Gastronomy doesn't need to > be organized or rigorous because fundamentally it isn't very > important. I cannot live without eating, I can live just fine without math. Your opinion that gastronomy is fundamentally unimportant is fundamentally flawed. > > In any case, Spolsky is not making a general attack on abstract science. > > Your hyperbole is completely unjustified. > > The mathematics of the 20th century, (from the early 30s onward) tend > to get VERY abstract, in just the way Joel decries. Category theory, > model theory, modern algebraic geometry, topos theory, algebraic graph > theory, abstract algebras and topological complexes are all very > difficult to understand because they seem so incredibly abstract, yet > most of them already have important applications. I'm 100% positive > if you just presented Joel with seminal papers in some of those areas, > he would apply the "astronaut" rubber stamp, because the material is > challenging, and he wouldn't get it (I love math, and I've had to read > some papers 10+ times before they click). I do not think that you can compare abstract vs real world. Joel talks in the context of solving real-world problems for a living and producing tangible results to justify employment. It is only fair to talk about mathematics in the same context. Or vice-versa. Joining-the-trolling-bandwagon, Ramit Ramit Prasad | JPMorgan Chase Investment Bank | Currencies Technology 712 Main Street | Houston, TX 77002 work phone: 713 - 216 - 5423 -- This email is confidential and subject to important disclaimers and conditions including on offers for the purchase or sale of securities, accuracy and completeness of information, viruses, confidentiality, legal privilege, and legal entity disclaimers, available at http://www.jpmorgan.com/pages/disclosures/email. From ethan at stoneleaf.us Fri Mar 30 13:45:39 2012 From: ethan at stoneleaf.us (Ethan Furman) Date: Fri, 30 Mar 2012 10:45:39 -0700 Subject: unittest: assertRaises() with an instance instead of a type In-Reply-To: <4f751e31$0$29981$c3e8da3$5496439d@news.astraweb.com> References: <4f735345$0$29981$c3e8da3$5496439d@news.astraweb.com> <4f751e31$0$29981$c3e8da3$5496439d@news.astraweb.com> Message-ID: <4F75F143.7000000@stoneleaf.us> Steven D'Aprano wrote: > To the degree that the decision of how finely to slice tests is a matter > of personal judgement and/or taste, I was wrong to say "that is not the > right way". I should have said "that is not how I would do that test". > > I believe that a single test is too coarse, and three or more tests is > too fine, but two tests is just right. Let me explain how I come to that > judgement. > > If you take a test-driven development approach, the right way to test > this is to write testFooWillFail once you decide that foo() should raise > MyException but before foo() actually does so. You would write the test, > the test would fail, and you would fix foo() to ensure it raises the > exception. Then you leave the now passing test in place to detect > regressions. > > Then you do the same for the errorcode. Hence two tests. [snip] > So: never remove tests just because they are redundant. Only remove them > when they are obsolete due to changes in the code being tested. Very persuasive argument -- I now find myself disposed to writing two tests (not three, nor five ;). ~Ethan~ From rustompmody at gmail.com Fri Mar 30 13:54:25 2012 From: rustompmody at gmail.com (rusi) Date: Fri, 30 Mar 2012 10:54:25 -0700 (PDT) Subject: Number of languages known [was Re: Python is readable] - somewhat OT References: Message-ID: On Mar 30, 4:37?am, Devin Jeanpierre wrote: > On Thu, Mar 29, 2012 at 3:50 PM, Nathan Rice > > wrote: > > Well, a lisp-like language. ?I would also argue that if you are using > > macros to do anything, the thing you are trying to do should classify > > as "not natural in lisp" :) > > You would run into disagreement. Some people feel that the lisp > philosophy is precisely that of extending the language to do anything > you want, in the most natural way. > > At least, I disagree, but my lisp thoughts are the result of > indoctrination of the Racket crowd. I guess Paul Graham would likewise disagree. See 7,8,9 in http://paulgraham.com/diff.html From nathan.alexander.rice at gmail.com Fri Mar 30 14:15:20 2012 From: nathan.alexander.rice at gmail.com (Nathan Rice) Date: Fri, 30 Mar 2012 14:15:20 -0400 Subject: Python is readable In-Reply-To: References: <4f612b19$0$1379$4fafbaef@reader2.news.tin.it> <4f750f9f$0$29981$c3e8da3$5496439d@news.astraweb.com> <4f752a3a$0$29981$c3e8da3$5496439d@news.astraweb.com> <4f758f43$0$29981$c3e8da3$5496439d@news.astraweb.com> Message-ID: On Fri, Mar 30, 2012 at 12:20 PM, Chris Angelico wrote: > On Sat, Mar 31, 2012 at 12:46 AM, Nathan Rice > wrote: >> I believe in the idea of "things should be as simple as possible, but >> not simpler". ?Programming as it currently exists is absolutely >> convoluted. ?I am called on to help people learn to program from time >> to time, and I can tell you that we still have a LONG way to go before >> programming approaches a global optimum in either the semantic or >> syntactic space. > > Aside from messes of installing and setting up language > interpreters/compilers, which are averted by simply having several > pre-installed (I think my Linux boxes come with some Python 2 version, > Perl, bash, and a few others), that isn't really the case. Starting a > Python script is easy. Programming gets convoluted only when, and to > the extent that, the task does. It is true that program complexity is correlated with problem complexity, language and environment complexity is undeniable. If you want to prove this to yourself, find someone who is intelligent and has some basic level of computer literacy, sit them down at a computer and ask them to solve simple problems using programs. You could even be nice by opening the editor first. Don't help them, just watch them crash and burn. Then sit them in front of code that already works, and ask them to modify it to do something slightly different, and again just watch them crash and burn in all but the simplest of cases. It is painful - most of the time they just give up. These same people almost universally can describe the exact process of steps verbally or in writing to do what is required without any trouble; there might be some neglected edge cases, but if you describe the failed result, often times they will realize their mistake and be able to fix it quickly. Jeff Atwood had an article about programming sheep and non programming goats, and while he views it as a statement about people's failings, I view it as a statement about the failings of programming. Human computer interaction is really important, and the whole prefab GUI concept doesn't scale along any axis; people need to be able to interact with their computers in a flexible manner. In the beginning, we had no choice but to bend our communication to the the machine, but we're moving past that now. The machine should respect the communication of humans. We shouldn't decry natural language because of ambiguity; If we're ambiguous, the machine should let us know and ask for clarification. If we phrase things in a really awkward way, the machine should tell us so, and suggest a more understandable rendition (just like word processors do now). If the machine does something we didn't want based on our instructions, we should be able to state additional requirements in a declarative manner. Restricted natural languages are an active area of current research, and they clearly demonstrate that you can have an expressive formal language that is also valid English. Make no mistake about it, programming is a form of computer human interaction (I figured that would be an accepted mantra here). Think of it as modeling knowledge and systems instead of pushing bits around. You are describing things to the computer. To move from the syntactic domain to my point about programming languages, imagine if one person describes physics to a computer in French, and another person describes chemistry to a computer in English. The creators of the computer made different languages act as disjoint knowledge domains. The computer is incapable of making any inferences in physics which are informed by chemistry, and vice versa, unless someone comes along and re-describes one of the disciplines in the other language. Worse still, if someone that only speaks Mandarin comes along, the computer won't be able to tell him anything about either domain. Now imagine the creators of the computer decided that an acceptable solution was to have people print out statements from one domain in a given language, take it to another computer that scans the printout, translates it to a different language, and prints out the translated copy, then have that person take the translated copy back to the original computer, and scan it again in order to ask a cross cutting question. I hope from that perspective the paucity of our current methods will be more apparent. From rustompmody at gmail.com Fri Mar 30 14:17:23 2012 From: rustompmody at gmail.com (rusi) Date: Fri, 30 Mar 2012 11:17:23 -0700 (PDT) Subject: Python is readable References: <4f612b19$0$1379$4fafbaef@reader2.news.tin.it> <4f750f9f$0$29981$c3e8da3$5496439d@news.astraweb.com> <4f752a3a$0$29981$c3e8da3$5496439d@news.astraweb.com> <4f758f43$0$29981$c3e8da3$5496439d@news.astraweb.com> <64eb2ae9-b4ec-4acb-92bf-de4a86f0b83c@sv8g2000pbc.googlegroups.com> Message-ID: On Mar 30, 9:02?pm, Steve Howell wrote: > Steven, how do you predict which abstractions are going to be useless? > > There was a time when imaginary numbers were just little toys that the > mathematicians played around with in their ivory towers. A non-science/math analogous question: When Beethoven wrote his last sonatas and quartets they were called 'the abortions of a German idealist' or less charitably the only music that a stone-deaf man could possibly write Likewise, Bach's wrote Art of Fugue was regarded as a merely academic work that codified his knowledge of fugal writing. It was many decades after their death that everyone began to regard these as the greatest pieces of music (maybe 50 for Beethoven, almost 100 for Bach). However for every one Bach/Beethoven there are 100s of fadists who are great in one generation and garbage-dumped the next. The encyclopedia of music I grew up on regarded Schoenberg et al in the Bach/Beethoven category. Almost certainly a more recent view would not. So if I side with Steven/Spolsky I would regard a (future) Bach/ Beethoven as an 'abortion.' If I side with Nathan I may waste my money and life betting on serialists/cubists and such fashionable but ephemeral fads. tl;dr version The usefulness of uber-abstractions is undecidable in the near timeframe. From rosuav at gmail.com Fri Mar 30 14:29:13 2012 From: rosuav at gmail.com (Chris Angelico) Date: Sat, 31 Mar 2012 05:29:13 +1100 Subject: Python is readable In-Reply-To: References: <4f612b19$0$1379$4fafbaef@reader2.news.tin.it> <4f750f9f$0$29981$c3e8da3$5496439d@news.astraweb.com> <4f752a3a$0$29981$c3e8da3$5496439d@news.astraweb.com> <4f758f43$0$29981$c3e8da3$5496439d@news.astraweb.com> Message-ID: On Sat, Mar 31, 2012 at 5:15 AM, Nathan Rice wrote: > It is true that program complexity is correlated with problem > complexity, language and environment complexity is undeniable. ?If you > want to prove this to yourself, find someone who is intelligent and > has some basic level of computer literacy, sit them down at a computer > and ask them to solve simple problems using programs. ?You could even > be nice by opening the editor first. ?Don't help them, just watch them > crash and burn. ?Then sit them in front of code that already works, > and ask them to modify it to do something slightly different, and > again just watch them crash and burn in all but the simplest of cases. > ?It is painful - most of the time they just give up. ?These same > people almost universally can describe the exact process of steps > verbally or in writing to do what is required without any trouble; > there might be some neglected edge cases, but if you describe the > failed result, often times they will realize their mistake and be able > to fix it quickly. This is more a matter of being unable to express themselves appropriately. If I allowed them to write an exact process of steps to do what's required, those steps would either be grossly insufficient for the task, or would BE pseudo-code. There are plenty of people who cannot write those sorts of instructions at all. They're called non-programmers. Anyone who doesn't code but can express a task in such clear steps as you describe is what I would call a non-coding programmer - and such people are VERY easily elevated to full programmer status. I've worked with several like that, and the border between that kind of clear, concise, simple instruction list and actual Python or REXX code is so small as to be almost nonexistent. It's not the programming languages' fault. It's a particular jump in thinking that must be overcome before a person can use them. There are other similar jumps in thinking. On which side of these lines are you? Do you remember making the shift? Or, conversely, do you stare at it with "Huh? Why would I do that?"? * Source control. Don't just keep daily backups - record specific purposeful changes in a log. * WYSIWYG document editing vs plain-text with a compiler. Pass up Open Office (or worse) in favour of LaTeX, abandon Sibelius in favour of Lilypond. Plays very nicely with source control. * Unicode instead of head-in-the-sand pretending that ASCII is good enough. * Open standards and toolchains instead of expecting monolithic proprietary programs to do your work for you. Etcetera, etcetera. Everyone who's made the jump will see the benefit of the side they're on; most who haven't won't. Same with non-programmers to programmers. Why should I write like that when I could just write English? Simple: Because dedicated programming languages are far more expressive for the job. ChrisA From lambertk at wlu.edu Fri Mar 30 14:31:51 2012 From: lambertk at wlu.edu (lambertk at wlu.edu) Date: Fri, 30 Mar 2012 11:31:51 -0700 (PDT) Subject: breezypythongui: A New Toolkit for Easy GUIs in Python Message-ID: breezypythongui is an open source toolkit that enables the Python programmer to learn realistic GUI programming quickly and easily. For free source code, demo programs, and a tutorial, visit http://home.wlu.edu/~lambertk/breezypythongui/index.html. Brought to you by Ken Lambert, the author of Fundamentals of Python: First Programs. From cartercc at gmail.com Fri Mar 30 14:49:23 2012 From: cartercc at gmail.com (ccc31807) Date: Fri, 30 Mar 2012 11:49:23 -0700 (PDT) Subject: Is Programing Art or Science? References: Message-ID: Programming is neither an art nor a science, but a trade. It's not an art in the sense of painting, music, dance, poetry, etc., because the objective isn't to make a beautiful something, but to give instructions to a machine to accomplish some useful task. It's not a science in the sense of either physics and chemistry (experimental) or geology or astronomy (observational) or cosmology or psychology (theoretical) because the objective isn't to test hypothetical s against data, but to give instructions to a machine to accomplish some useful task. Obviously, it's very much connected with art (e.g., user interface design) and science (e.g., artificial intelligence) but the practice of giving instructions to a machine is more like assembling machines in a factory than the pursuit of an art or the practice of a science. CC. From storchaka at gmail.com Fri Mar 30 15:06:45 2012 From: storchaka at gmail.com (Serhiy Storchaka) Date: Fri, 30 Mar 2012 22:06:45 +0300 Subject: "convert" string to bytes without changing data (encoding) In-Reply-To: <1053a4e195cf2e85778f6c2c63dc89d4@modelnine.org> References: "\"<9tg21lFmo3U1@mid.dfncis.de>" " <9tg4qoFbfpU1@mid.dfncis.de> <9th0u8Fuf2U1@mid.dfncis.de> <1053a4e195cf2e85778f6c2c63dc89d4@modelnine.org> Message-ID: 28.03.12 21:13, Heiko Wundram ???????(??): > Reading from stdin/a file gets you bytes, and > not a string, because Python cannot automagically guess what format the > input is in. In Python3 reading from stdin gets you string. Use sys.stdin.buffer.raw for access to byte stream. And reading from file opened in text mode gets you string too. From rosuav at gmail.com Fri Mar 30 15:10:03 2012 From: rosuav at gmail.com (Chris Angelico) Date: Sat, 31 Mar 2012 06:10:03 +1100 Subject: "convert" string to bytes without changing data (encoding) In-Reply-To: References: <9tg21lFmo3U1@mid.dfncis.de> <9tg4qoFbfpU1@mid.dfncis.de> <9th0u8Fuf2U1@mid.dfncis.de> <1053a4e195cf2e85778f6c2c63dc89d4@modelnine.org> Message-ID: On Sat, Mar 31, 2012 at 6:06 AM, Serhiy Storchaka wrote: > 28.03.12 21:13, Heiko Wundram ???????(??): > >> Reading from stdin/a file gets you bytes, and >> not a string, because Python cannot automagically guess what format the >> input is in. > > > In Python3 reading from stdin gets you string. Use sys.stdin.buffer.raw for > access to byte stream. And reading from file opened in text mode gets you > string too. True. But that's only if it's been told the encoding of stdin (which I believe is the normal case on Linux). It's still not "automagically guess(ing)", it's explicitly told. ChrisA From nathan.alexander.rice at gmail.com Fri Mar 30 15:55:45 2012 From: nathan.alexander.rice at gmail.com (Nathan Rice) Date: Fri, 30 Mar 2012 15:55:45 -0400 Subject: Python is readable In-Reply-To: References: <4f612b19$0$1379$4fafbaef@reader2.news.tin.it> <4f750f9f$0$29981$c3e8da3$5496439d@news.astraweb.com> <4f752a3a$0$29981$c3e8da3$5496439d@news.astraweb.com> <4f758f43$0$29981$c3e8da3$5496439d@news.astraweb.com> Message-ID: > This is more a matter of being unable to express themselves > appropriately. If I allowed them to write an exact process of steps to > do what's required, those steps would either be grossly insufficient > for the task, or would BE pseudo-code. There are plenty of people who > cannot write those sorts of instructions at all. They're called > non-programmers. Anyone who doesn't code but can express a task in > such clear steps as you describe is what I would call a non-coding > programmer - and such people are VERY easily elevated to full > programmer status. I've worked with several like that, and the border > between that kind of clear, concise, simple instruction list and > actual Python or REXX code is so small as to be almost nonexistent. > It's not the programming languages' fault. It's a particular jump in > thinking that must be overcome before a person can use them. Your statement that the difference between Python or REXX and pseudo-code is almost non existent is completely false. While people reading Python might be able to guess with higher accuracy what a program does than some other programming languages, there is still a set of VERY specific set of glyphs, words and phrase structures it requires. Pretty much anyone can follow a recipe to make a meal (and there are a lot other examples of this), and conversely given the knowledge of how to make some dish, pretty much everyone could describe the process as a recipe. The same person will fail miserably when trying to create working code that is MUCH simpler from a conceptual standpoint. "Non coders" are not stupid, they just don't appreciate the multitude of random distinctions and computer specific abstractions programming foists on them for the purpose of writing EFFICIENT code. I'm talking about like multiple int/number types, umpteen different kinds of sequences, tons of different data structures that are used for basically the same things under different circumstances, indices starting at 0 (which makes amazing sense if you think like a machine, and very little if you think like a human), the difference between logical and bitwise operators (union and intersection would be better names for the latter), string encoding, etc. When you combine these with having to communicate in a new (very arbitrary, sometimes nonsensical) vocabulary that doesn't recognize synonyms, using an extremely restricted phrase structure and an environment with very limited interactivity, it should become clear that the people who learn to program are invariably fascinated by computers and very motivated to do so. I'm going to assume that you didn't mean that "non coders" are incapable of instructing others (even though your statement implies it directly). I think the ability of "non coders" to describe procedures would surprise you. Things I hear over and over from "non coders" all tie into people being frustrated that computers don't grasp similarity, and don't try to figure out what they want at all; most people provide instructions in an interactive manner. The computer is too stupid to interact with humans, so you have to tell it what to do, then try to run it, watch it fail, then go back and modify your program, which is highly unnatural. I think you'd find that these "non coders" would do very well if given the ability to provide instructions in a natural, interactive way. They are not failing us, we are failing them. > Etcetera, etcetera. Everyone who's made the jump will see the benefit > of the side they're on; most who haven't won't. Same with > non-programmers to programmers. Why should I write like that when I > could just write English? Simple: Because dedicated programming > languages are far more expressive for the job. Really? Or could it be that algorithms for natural language processing that don't fail miserably is a very recent development, restricted natural languages more recent still, and pretty much all commonly used programming languages are all ~20+ years old? Could it also be that most programmers don't see a lot of incentives to make things accessible, since they're already invested in the status quo, and they might lose some personal value if programming stopped being an arcane practice? Creating a programming language is a time consuming and laborious process, the fact that people are doing it constantly is a clear indication that what we have is insufficient. From rosuav at gmail.com Fri Mar 30 16:20:39 2012 From: rosuav at gmail.com (Chris Angelico) Date: Sat, 31 Mar 2012 07:20:39 +1100 Subject: Python is readable In-Reply-To: References: <4f612b19$0$1379$4fafbaef@reader2.news.tin.it> <4f750f9f$0$29981$c3e8da3$5496439d@news.astraweb.com> <4f752a3a$0$29981$c3e8da3$5496439d@news.astraweb.com> <4f758f43$0$29981$c3e8da3$5496439d@news.astraweb.com> Message-ID: On Sat, Mar 31, 2012 at 6:55 AM, Nathan Rice wrote: > I think you'd find that these "non coders" would do very well if given > the ability to provide instructions in a natural, interactive way. > They are not failing us, we are failing them. The nearest thing to natural-language command of a computer is voice navigation, which is another science that's plenty old and yet still current (I first met it back in 1996 and it wasn't new then). You tell the computer what you want it to do, and it does it. Theoretically. The vocabulary's a lot smaller than all of English, of course, but that's not a problem. The problem is that it's really REALLY slow to try to get anything done in English, compared to a dedicated domain-specific language (in the case of typical OS voice navigation, the nearest equivalent would probably be a shell script). > Really? ?Or could it be that algorithms for natural language > processing that don't fail miserably is a very recent development, > restricted natural languages more recent still, and pretty much all > commonly used programming languages are all ~20+ years old? ?Could it > also be that most programmers don't see a lot of incentives to make > things accessible, since they're already invested in the status quo, > and they might lose some personal value if programming stopped being > an arcane practice? Totally. That's why we're all still programming in assembly language and doing our own memory management, because we would lose a lot of personal value if programming stopped being so difficult. If it weren't for all these silly new-fangled languages with their automatic garbage collection and higher order function handling, we would all be commanding much higher salaries. ChrisA From neilc at norwich.edu Fri Mar 30 16:30:31 2012 From: neilc at norwich.edu (Neil Cerutti) Date: 30 Mar 2012 20:30:31 GMT Subject: Python is readable References: <4f612b19$0$1379$4fafbaef@reader2.news.tin.it> <4f750f9f$0$29981$c3e8da3$5496439d@news.astraweb.com> <4f752a3a$0$29981$c3e8da3$5496439d@news.astraweb.com> <4f758f43$0$29981$c3e8da3$5496439d@news.astraweb.com> Message-ID: <9tmjf7FqldU1@mid.individual.net> On 2012-03-30, Nathan Rice wrote: > Restricted natural languages are an active area of current > research, and they clearly demonstrate that you can have an > expressive formal language that is also valid English. See, for example, Inform 7, which translates a subset of English into Inform 6 code. I never thought too deeply about why I disliked it, assuming it was because I already knew Inform 6. Would you like to write the equivalent, e.g., C code in English? -- Neil Cerutti From dan at tombstonezero.net Fri Mar 30 16:51:21 2012 From: dan at tombstonezero.net (Dan Sommers) Date: Fri, 30 Mar 2012 16:51:21 -0400 Subject: Python is readable In-Reply-To: References: <4f612b19$0$1379$4fafbaef@reader2.news.tin.it> <4f750f9f$0$29981$c3e8da3$5496439d@news.astraweb.com> <4f752a3a$0$29981$c3e8da3$5496439d@news.astraweb.com> <4f758f43$0$29981$c3e8da3$5496439d@news.astraweb.com> Message-ID: <20120330165121.60b989f1@particle> On Sat, 31 Mar 2012 07:20:39 +1100 Chris Angelico wrote: > ... That's why we're all still programming in assembly language and > doing our own memory management, because we would lose a lot of > personal value if programming stopped being so difficult. If it > weren't for all these silly new-fangled languages with their automatic > garbage collection and higher order function handling, we would all be > commanding much higher salaries. Back in the 1970's, the magazines were full of ads for "never write another line of code again" programs. A keystroke here, a keystroke there (those were the days *before* drag-and-drop and point-and-drool), and even managers and executives could "write programs." Now, of course, those managers and executives still command higher salaries, so I guess ChrisA is right about us assembly language guys losing our personal value. Dan From nathan.alexander.rice at gmail.com Fri Mar 30 16:58:59 2012 From: nathan.alexander.rice at gmail.com (Nathan Rice) Date: Fri, 30 Mar 2012 16:58:59 -0400 Subject: Python is readable In-Reply-To: References: <4f612b19$0$1379$4fafbaef@reader2.news.tin.it> <4f750f9f$0$29981$c3e8da3$5496439d@news.astraweb.com> <4f752a3a$0$29981$c3e8da3$5496439d@news.astraweb.com> <4f758f43$0$29981$c3e8da3$5496439d@news.astraweb.com> Message-ID: On Fri, Mar 30, 2012 at 4:20 PM, Chris Angelico wrote: > On Sat, Mar 31, 2012 at 6:55 AM, Nathan Rice > wrote: >> I think you'd find that these "non coders" would do very well if given >> the ability to provide instructions in a natural, interactive way. >> They are not failing us, we are failing them. > > The nearest thing to natural-language command of a computer is voice > navigation, which is another science that's plenty old and yet still > current (I first met it back in 1996 and it wasn't new then). You tell > the computer what you want it to do, and it does it. Theoretically. > The vocabulary's a lot smaller than all of English, of course, but > that's not a problem. The problem is that it's really REALLY slow to > try to get anything done in English, compared to a dedicated > domain-specific language (in the case of typical OS voice navigation, > the nearest equivalent would probably be a shell script). I'm sure a ford truck would smoke a twin engine cessna if you compare their speed on the ground. Let the cessna fly and the ford doesn't have a snowball's chance. If you're navigating by going "cee dee space slash somefolder slash some other folder slash some third folder slash semicolon emacs somename dash some other name dash something dot something else dot one" the analogy would be a boss telling his secretary to reserve him a flight by saying "visit site xyz, click on this heading, scroll halfway down, open this menu, select this destination, ..." instead of "book me a flight to San Jose on the afternoon of the 23rd, and don't spend more than $500". > Totally. That's why we're all still programming in assembly language > and doing our own memory management, because we would lose a lot of > personal value if programming stopped being so difficult. If it > weren't for all these silly new-fangled languages with their automatic > garbage collection and higher order function handling, we would all be > commanding much higher salaries. Did you miss the fact that a 50 year old programming language (which still closely resembles its original form) is basically tied for the title of currently most popular, and the 3 languages following it are both nominal and spiritual successors, with incremental improvements in features but sharing a large portion of the design. Programming language designers purposefully try to make their language C-like, because not being C-like disqualifies a language from consideration for a HUGE portion of programmers, who cower at the naked feeling they get imagining a world without curly braces. Fear of change and the unknown are brutal, and humans are cowardly creatures that will grasp at whatever excuses they can find not to acknowledge their weaknesses. I also mentioned previously, most developers are just trying to graft shortcut after shortcut on to what is comfortable and familiar because we're inherently lazy. Additionally, I'm quite certain that when we finally do have a method for programming/interacting with computers in a natural way, many people invested in previous methods will make snarky comments about how lame and stupid people using the new methods are, just like we saw with command line/keyboard elitists who make fun of people who prefer a mouse/gui, even though in most cases research showed that the people using the mouse/gui actually got work done faster. You can even look at some comments on this thread for evidence of this. From nagle at animats.com Fri Mar 30 17:20:35 2012 From: nagle at animats.com (John Nagle) Date: Fri, 30 Mar 2012 14:20:35 -0700 Subject: Will MySQL ever be supported for Python 3.x? Message-ID: The MySQLdb entry on SourceForge (http://sourceforge.net/projects/mysql-python/) web site still says the last supported version of Python is 2.6. PyPi says the last supported version is Python 2.5. The last download is from 2007. I realize there are unsupported fourth-party versions from other sources. (http://www.lfd.uci.edu/~gohlke/pythonlibs/) But those are just blind builds; they haven't been debugged. MySQL Connector (http://forge.mysql.com/projects/project.php?id=302) is still pre-alpha. John Nagle From irmen.NOSPAM at xs4all.nl Fri Mar 30 17:32:32 2012 From: irmen.NOSPAM at xs4all.nl (Irmen de Jong) Date: Fri, 30 Mar 2012 23:32:32 +0200 Subject: Will MySQL ever be supported for Python 3.x? In-Reply-To: References: Message-ID: <4f762670$0$6871$e4fe514c@news2.news.xs4all.nl> On 30-3-2012 23:20, John Nagle wrote: > The MySQLdb entry on SourceForge > (http://sourceforge.net/projects/mysql-python/) > web site still says the last supported version of Python is 2.6. > PyPi says the last supported version is Python 2.5. The > last download is from 2007. > > I realize there are unsupported fourth-party versions from other > sources. (http://www.lfd.uci.edu/~gohlke/pythonlibs/) But those > are just blind builds; they haven't been debugged. > > MySQL Connector (http://forge.mysql.com/projects/project.php?id=302) > is still pre-alpha. Try Oursql instead http://packages.python.org/oursql/ "oursql is a new set of MySQL bindings for python 2.4+, including python 3.x" Irmen From rosuav at gmail.com Fri Mar 30 17:45:30 2012 From: rosuav at gmail.com (Chris Angelico) Date: Sat, 31 Mar 2012 08:45:30 +1100 Subject: Python is readable In-Reply-To: References: <4f612b19$0$1379$4fafbaef@reader2.news.tin.it> <4f750f9f$0$29981$c3e8da3$5496439d@news.astraweb.com> <4f752a3a$0$29981$c3e8da3$5496439d@news.astraweb.com> <4f758f43$0$29981$c3e8da3$5496439d@news.astraweb.com> Message-ID: On Sat, Mar 31, 2012 at 7:58 AM, Nathan Rice wrote: > Programming > language designers purposefully try to make their language C-like, > because not being C-like disqualifies a language from consideration > for a HUGE portion of programmers, who cower at the naked feeling they > get imagining a world without curly braces. ?Fear of change and the > unknown are brutal, and humans are cowardly creatures that will grasp > at whatever excuses they can find not to acknowledge their weaknesses. Braces are clear delimiters. English doesn't have them, and suffers for it. (Python's indentation is, too, but English doesn't have that either.) It's a lot harder to mark the end of an "if" block in English than in pretty much any programming language. And be careful of what has to be given up to gain your conveniences. I've used languages that demand variable declarations and ones that don't, and I'm very much a fan of the former. There are many benefits to being explicit about that. ChrisA From nagle at animats.com Fri Mar 30 17:46:55 2012 From: nagle at animats.com (John Nagle) Date: Fri, 30 Mar 2012 14:46:55 -0700 Subject: Will MySQL ever be supported for Python 3.x? In-Reply-To: <4f762670$0$6871$e4fe514c@news2.news.xs4all.nl> References: <4f762670$0$6871$e4fe514c@news2.news.xs4all.nl> Message-ID: On 3/30/2012 2:32 PM, Irmen de Jong wrote: > Try Oursql instead http://packages.python.org/oursql/ > "oursql is a new set of MySQL bindings for python 2.4+, including python 3.x" Not even close to being compatible with existing code. Every SQL statement has to be rewritten, with the parameters expressed differently. It's a good approach, but very incompatible. John Nagle From irmen.NOSPAM at xs4all.nl Fri Mar 30 17:55:59 2012 From: irmen.NOSPAM at xs4all.nl (Irmen de Jong) Date: Fri, 30 Mar 2012 23:55:59 +0200 Subject: Will MySQL ever be supported for Python 3.x? In-Reply-To: References: <4f762670$0$6871$e4fe514c@news2.news.xs4all.nl> Message-ID: <4f762bef$0$6885$e4fe514c@news2.news.xs4all.nl> On 30-3-2012 23:46, John Nagle wrote: > On 3/30/2012 2:32 PM, Irmen de Jong wrote: >> Try Oursql instead http://packages.python.org/oursql/ >> "oursql is a new set of MySQL bindings for python 2.4+, including python 3.x" > > Not even close to being compatible with existing code. Every SQL > statement has to be rewritten, with the parameters expressed > differently. It's a good approach, but very incompatible. You didn't state that it had to be compatible with existing code. Also, since you asked about Python 3.x, surely there are other incompatibilities you need to take care of in the existing code? (unless it's Python 3.x clean already...) Irmen From tolidtm at gmail.com Fri Mar 30 17:58:09 2012 From: tolidtm at gmail.com (Anatoli Hristov) Date: Fri, 30 Mar 2012 23:58:09 +0200 Subject: Advise of programming one of my first programs In-Reply-To: <5B80DD153D7D744689F57F4FB69AF47409293188@SCACMX008.exchad.jpmchase.net> References: <5B80DD153D7D744689F57F4FB69AF4740928C365@SCACMX008.exchad.jpmchase.net> <5B80DD153D7D744689F57F4FB69AF4740928E137@SCACMX008.exchad.jpmchase.net> <5B80DD153D7D744689F57F4FB69AF4740928F779@SCACMX008.exchad.jpmchase.net> <5B80DD153D7D744689F57F4FB69AF47409293188@SCACMX008.exchad.jpmchase.net> Message-ID: > > ** > > Absolutely! Too bad your version would be considered the more > ?complicated? version ;) > I`m sure about that, but I`am also sure that every beginner passed true that way. > **** > > ** ** > > >With the main navigation menu I will only have the option to select a > nickname and when a nickname is selected then it loads Details of the > contact and from loaded details I can choice Edit or back to main screen, > like I did it the first time, or else I can do it => when 'e' pressed to > ask for a nickname and then edit it. > ** > > I was trying to simplify it to ?guide? you to a more correct solution > without feeding you the answer. Maybe I should have given you the > explanation first to explain why you should be doing it a different way.** > ** > > ** ** > > Going back to your original program (and your modifications to it), the > original menu can cause crashing in more complicated programs and thus is > considered a bad style. It was basically using recursion (I will touch on > this later) but without any of the benefits. It was endlessly branching > instead of a simple loop. Sort of like the following Menu/submenu example. > **** > > ** ** > > Menu**** > > submenu**** > > Menu**** > > submenu**** > > Menu**** > > __ad infinitum__**** > > ** ** > > How does this matter? Let?s look at some simpler code below.**** > > ** ** > > print ?start?**** > > function_a() # a function is called**** > > print ?a? # code inside the function**** > > print ?b? # code inside the function**** > > a = ? something ?**** > > print a**** > > function_b() # another function call**** > > print ?c? # code inside a different function**** > > print ?d? # code inside a different function**** > > print ?end?**** > > ** ** > > Let us pretend we are the computer who executes one line at a time and so > basically goes through a list of commands. The list we are going to execute > is the following:**** > > ** ** > > print ?start?**** > > function_a()**** > > print ?a?**** > > print ?b?**** > > a = ? something ?**** > > print a**** > > function_b()**** > > print ?c?**** > > print ?d?**** > > print ?end?**** > > ** ** > > How does the computer know to execute ?a = ? something ?? after ?print > ?b??? It does it by storing the location where it was before it proceeds to > the function call. That way when the end of the function is reached it > returns to the previous spot. In essence:**** > > ** ** > > print ?start?**** > > function_a()**** > > __store this location so I can come back__**** > > print ?a?**** > > print ?b?**** > > __return to previous location__**** > > a = ? something ?**** > > print a**** > > function_b()**** > > __store this location so I can come back__**** > > print ?c?**** > > print ?b?**** > > __return to previous location__**** > > print ?end?**** > > ** ** > > Now what happens if ?function_a? calls ?function_a?? By the way, the term > for this type of call is recursion.**** > > ** ** > > print ?start?**** > > function_a()**** > > __store this location so I can come back__**** > > print ?a?**** > > print ?b?**** > > function_a()**** > > __store this location so I can come back__**** > > print ?a?**** > > print ?b?**** > > function_a()**** > > __store this location so I can come back__**** > > print ?a?**** > > print ?b?**** > > function_a()**** > > __store this location so I can come back__**** > > print ?a?**** > > print ?b?**** > > function_a()**** > > __store this location so I can come back__**** > > print ?a?**** > > print ?b?**** > > function_a()**** > > __store this location so I can come back__**** > > **until the program ends****** > > ** ** > > Now each __store__ action takes up memory and when the computer (or your > program) runs out of memory your computer crashes. Your application is > trivial and more likely to be ended by the user instead of going through > the tens of thousands if not hundreds of thousands that Python will let you > take, but it is a bad practice and a habit to avoid. A real world program > would use more memory and quit even faster than yours. Recursion has its > place in programming, but not in this case! What you need is a simple loop. > That is why I provided you with the menu I did. **** > > ** ** > > The following menu sounds like what you want; there were a couple > different ways I could have done this. In this version, if you type > anything when asked for a menu choice that is not ?e? or ?q?, the program > will automatically ask you for the next book choice.**** > > ** ** > > def mmenu():**** > > # load tbook here**** > > while True:**** > > book = get_book_choice()**** > > details( tbook, book )**** > > choicem = get_menu_choice()**** > > if choicem == 'e' or choicem == 'E':**** > > edit( tbook, book )**** > > # save tbook here**** > > elif choicem =='Q' or choicem == 'q':**** > > break # end loop to exit program**** > > ** I`m focusing on what you say and will try to follow your instructions > for which - Thank you I really appreciate it... > Just before I read you mail I`ve finished my book ver. 12 with this code, ver 13 will have all the modifications and all remarks I have from you: import ast fname = 0 lname = 1 country = 2 city = 3 tel = 4 notes = 5 ## Read data from file def load_book(): load_book = open('c:/Python27/Toli/myfile.txt', 'r') load_book = ast.literal_eval(load_book.read()) return load_book ## Write data to file def write_book(tbook): write_book = open('c:/Python27/Toli/myfile.txt', 'w') write_book.write(repr(tbook)) ## Menu choice input def get_menu_choice(): choice = raw_input('input: ') return choice ## List data contacts def listpb(): tbook = load_book() print '_' *45, ' Phonebook ', '_' *45,'\n\n\n' print 'Nick\t\tF.Name\t\tL.Name\t\tCountry\t\t\tCity\t\tTel' print '_' * 105,'\n','\t' * 13 for val in tbook.keys(): print val, '\t\t', tbook[val][fname], '\t', tbook[val][lname], '\t', tbook[val][country], '\t\t', tbook[val][city], '\t\t', tbook[val][tel],'\t\t\n' print '_'*105,'\n\n\n\n' print 'Type nickname and press or type to exit.\n\n\n' mmenu(tbook) ## Main menu def mmenu(tbook): while True: choice = get_menu_choice() if choice in tbook: details(choice,tbook) elif choice == 'q' or choice == 'Q': break else: print 'Selection {0} not understood.'.format(choice) ## Details menu def dmenu(choice, tbook): while True: choicem = get_menu_choice() if choicem == 'e' or choicem == 'E': edit(choice, tbook) elif choicem == 'b' or choicem == 'B': listpb() elif choicem =='Q' or choicem == 'q': break # end loop to exit program else: print 'Selection {0} not understood.'.format( choicem ) ## Contact details def details(choice, tbook): sb = tbook[choice] print 'Nickname: ', choice, ' is selected\n' print 'First name:\t', sb[fname], '\n' print 'Last name:\t', sb[lname], '\n' print 'Country:\t', sb[country], '\n' print 'City:\t\t', sb[city], '\n' print 'Phone number:\t',sb[tel], '\n' print 'Memos:\n' print sb[notes] print '\n\n(E)dit\n\n' print '(B)ack to phonebook list\n\n' dmenu(choice, tbook) ## Edit contact def edit(choice, tbook): sb = tbook[choice] fn = raw_input('New name for ' + sb[fname] + ' : ') if fn == '': pass else: sb[fname] = fn ln = raw_input('New name for ' + sb[lname] + ' : ') if ln == '': pass else: sb[lname] = ln write_book(tbook) details(choice, tbook) listpb() > ** > > ** ** > > Ramit**** > > ** ** > > ** ** > > Ramit Prasad | JPMorgan Chase Investment Bank | Currencies Technology**** > > 712 Main Street | Houston, TX 77002**** > > work phone: 713 - 216 - 5423**** > > ** ** > > --**** > > This email is confidential and subject to important disclaimers and > conditions including on offers for the purchase or sale of securities, > accuracy and completeness of information, viruses, confidentiality, legal > privilege, and legal entity disclaimers, available at > http://www.jpmorgan.com/pages/disclosures/email. > > -- > http://mail.python.org/mailman/listinfo/python-list > > -------------- next part -------------- An HTML attachment was scrubbed... URL: From nathan.alexander.rice at gmail.com Fri Mar 30 19:01:44 2012 From: nathan.alexander.rice at gmail.com (Nathan Rice) Date: Fri, 30 Mar 2012 19:01:44 -0400 Subject: Python is readable In-Reply-To: References: <4f612b19$0$1379$4fafbaef@reader2.news.tin.it> <4f750f9f$0$29981$c3e8da3$5496439d@news.astraweb.com> <4f752a3a$0$29981$c3e8da3$5496439d@news.astraweb.com> <4f758f43$0$29981$c3e8da3$5496439d@news.astraweb.com> Message-ID: On Fri, Mar 30, 2012 at 5:45 PM, Chris Angelico wrote: > On Sat, Mar 31, 2012 at 7:58 AM, Nathan Rice > wrote: >> Programming >> language designers purposefully try to make their language C-like, >> because not being C-like disqualifies a language from consideration >> for a HUGE portion of programmers, who cower at the naked feeling they >> get imagining a world without curly braces. Fear of change and the >> unknown are brutal, and humans are cowardly creatures that will grasp >> at whatever excuses they can find not to acknowledge their weaknesses. > > Braces are clear delimiters. English doesn't have them, and suffers > for it. (Python's indentation is, too, but English doesn't have that > either.) It's a lot harder to mark the end of an "if" block in English > than in pretty much any programming language. It seems to me that Indented blocks of text are used pretty frequently to denote definition bodies, section subordinate paragraphs and asides. The use of the colon seems pretty natural too. Parentheses are fairly natural for small asides. The notion of character delimiters for large sections of text is actually pretty unnatural with the exception of quotes. > And be careful of what has to be given up to gain your conveniences. > I've used languages that demand variable declarations and ones that > don't, and I'm very much a fan of the former. There are many benefits > to being explicit about that. I don't like declarations, my personal preference is to have typed signatures, and implicit declaration with type inference elsewhere. I view it as a matter of personal preference though, the result should be the same, and it should be possible to view the code either way. From breamoreboy at yahoo.co.uk Fri Mar 30 20:47:48 2012 From: breamoreboy at yahoo.co.uk (Mark Lawrence) Date: Sat, 31 Mar 2012 01:47:48 +0100 Subject: Threads on google groups not on gmane? Message-ID: I went onto google groups to do a search and saw three threads (there may be more) that I've never seen on gmane, which I read via thunderbird on windows. The titles are "Is programming art or science", "breezypythongui: A New Toolkit for Easy GUIs in Python" and "weird behaviour: pygame plays in shell but not in script". Is anyone else seeing the same thing? -- Cheers. Mark Lawrence. From breamoreboy at yahoo.co.uk Fri Mar 30 20:56:31 2012 From: breamoreboy at yahoo.co.uk (Mark Lawrence) Date: Sat, 31 Mar 2012 01:56:31 +0100 Subject: CFG for python In-Reply-To: References: Message-ID: On 29/03/2012 06:44, J. Mwebaze wrote: > Anyone knows how to create control-flow-graph for python.. After searching > around, i found this article, > http://www.python.org/dev/peps/pep-0339/#ast-to-cfg-to-bytecode and also a > reference to http://doc.pypy.org/en/latest/objspace.html#the-flow-model > > However, i stil cant figure out what how to create the CFG from the > two references. > Regards > Taking a look at this may help you get going http://alexleone.blogspot.co.uk/2010/01/python-ast-pretty-printer.html -- Cheers. Mark Lawrence. From jcd at sdf.lonestar.org Fri Mar 30 21:51:42 2012 From: jcd at sdf.lonestar.org (J. Cliff Dyer) Date: Fri, 30 Mar 2012 21:51:42 -0400 Subject: help needed to understand an error message. In-Reply-To: References: Message-ID: <1333158702.3513.3.camel@webb> So the problem is that python doesn't know what you're trying to do. It doesn't know that you meant to say "print." When the parser is looking at the word Print, it assumes you are referencing an object named Print, which is completely legal. It's only once you've created the next token, a string literal, that the parser discovers the error: you can't have a string literal following a variable. *You* think your error is that you misspelled "print." The parser thinks your error is trying to put a string literal next to a variable. Cheers, Cliff On Mon, 2012-03-26 at 18:22 +0530, Aloke Ghosh wrote: > Hi, > I am learning Python and do not have programming experience. > I was following > an exercise from http://learnpythonthehardway.org/book/ex2.html > and made a mistake in entry : > > > Print"I like typing this." > > > and got the following error message: > > > In [2]: Print"I like typing this." > ------------------------------------------------------------ > File "", line 1 > Print"I like typing this." > ^ > SyntaxError: invalid syntax > > > I feel the error is in Capital P in print . > However the error indicated with "^" > hints at quote at the end of the line. > > > Can any one please help me understand this. > > > -- > A.K.Ghosh From tjreedy at udel.edu Sat Mar 31 00:03:41 2012 From: tjreedy at udel.edu (Terry Reedy) Date: Sat, 31 Mar 2012 00:03:41 -0400 Subject: Python is readable In-Reply-To: <4f758f43$0$29981$c3e8da3$5496439d@news.astraweb.com> References: <4f612b19$0$1379$4fafbaef@reader2.news.tin.it> <4f750f9f$0$29981$c3e8da3$5496439d@news.astraweb.com> <4f752a3a$0$29981$c3e8da3$5496439d@news.astraweb.com> <4f758f43$0$29981$c3e8da3$5496439d@news.astraweb.com> Message-ID: On 3/30/2012 6:47 AM, Steven D'Aprano wrote: > Spolsky has written at least three times about Architecture Astronauts, > and made it abundantly clear that the problem with them is that they > don't solve problems, they invent overarching abstractions that don't do > anything useful or important, and hype them everywhere. > > http://www.joelonsoftware.com/articles/fog0000000018.html > http://www.joelonsoftware.com/items/2005/10/21.html > http://www.joelonsoftware.com/items/2008/05/01.html > > Jeff Attwood provides a simple test for the difference between a useful > abstraction and an Architecture Astronaut hyper-abstraction: > > Does it solve a useful problem? > > http://www.codinghorror.com/blog/2004/12/it-came-from-planet-architecture.html My strong impression is that theoretical abstract mathematicians also prefer that hi-level abstractions solve some useful-to-mathematicians mathematical problem. -- Terry Jan Reedy From showell30 at yahoo.com Sat Mar 31 01:07:52 2012 From: showell30 at yahoo.com (Steve Howell) Date: Fri, 30 Mar 2012 22:07:52 -0700 (PDT) Subject: Python is readable References: <4f612b19$0$1379$4fafbaef@reader2.news.tin.it> <4f750f9f$0$29981$c3e8da3$5496439d@news.astraweb.com> <4f752a3a$0$29981$c3e8da3$5496439d@news.astraweb.com> <4f758f43$0$29981$c3e8da3$5496439d@news.astraweb.com> Message-ID: On Mar 30, 1:20?pm, Chris Angelico wrote: > > Really? ?Or could it be that algorithms for natural language > > processing that don't fail miserably is a very recent development, > > restricted natural languages more recent still, and pretty much all > > commonly used programming languages are all ~20+ years old? ?Could it > > also be that most programmers don't see a lot of incentives to make > > things accessible, since they're already invested in the status quo, > > and they might lose some personal value if programming stopped being > > an arcane practice? > > Totally. That's why we're all still programming in assembly language > and doing our own memory management, because we would lose a lot of > personal value if programming stopped being so difficult. If it > weren't for all these silly new-fangled languages with their automatic > garbage collection and higher order function handling, we would all be > commanding much higher salaries. > While I don't subscribe to the conspiracy theory that "programmers invest in arcane practices to preserve personal value" [paraphrase of Nathan], surely you could come up with a better argument than "garbage collection." Garbage collection was invented over 50 years ago (1959, according to Wikipedia), and it was implemented in a whole bunch of popular programming languages in the 90s (and earlier too, if you count Smalltalk as a popular language). Python's over 20 years old, and it had garbage collection pretty early on. Java's not quite 20 years old, but if Java is your best example of a "new-fangled" language with automatic garbage collection, then I have a hard time appreciating your sarcastic comments. There hasn't been much progress in programming language design in the last 20 years. It's been incremental at best. Nobody's really thinking outside the box, as far as I can tell. Please prove me wrong. It's true that we've moved past assembly language. From lie.1296 at gmail.com Sat Mar 31 01:18:47 2012 From: lie.1296 at gmail.com (Lie Ryan) Date: Sat, 31 Mar 2012 16:18:47 +1100 Subject: Tools for refactoring/obfuscation In-Reply-To: References: Message-ID: On 03/29/2012 03:04 AM, Javier wrote: > Yes, in general I follow clear guidelines for writing code. I just use > modules with functions in the same directory and clear use of name > spaces. I almost never use classes. I wonder if you use some tool for > refactoring. I am mainly intersted in scripting tools, no eclipse-style > guis. > > Just let me know if you use some scripting tool. > > And, as somebody pointed in this thread obfuscating or refactoring the > code are very different things but they can be done with the same tools. if you're not using classes, your code is obfuscated already Anyway, I think it's better if you describe why you want such a tool. If you want to keep your code a secret, just distribute the .pyc file. If you want to refactor your code to improve readability, there is rope. From jphalip at gmail.com Sat Mar 31 01:39:09 2012 From: jphalip at gmail.com (Julien) Date: Fri, 30 Mar 2012 22:39:09 -0700 (PDT) Subject: Problem connecting to SMTP/IMAP server using SSL Message-ID: <722270ac-367f-4058-84ed-92ba10f4516a@ur9g2000pbc.googlegroups.com> Hi, I'm able to connect to an Exchange server via SMTP and IMAP from my iPhone using SSL and without using a VPN. So I would expect to be able to do the same from my computer using Python. However, the following hangs and times out on my computer when I'm not connected to the VPN: >>> import imaplib >>> imap = imaplib.IMAP4_SSL("my.server.address") If I am connected to the VPN, then it works fine. Do you know why it won't work with SSL and without the VPN? Am I missing something? Thanks a lot, Julien From lie.1296 at gmail.com Sat Mar 31 01:56:57 2012 From: lie.1296 at gmail.com (Lie Ryan) Date: Sat, 31 Mar 2012 16:56:57 +1100 Subject: Python is readable In-Reply-To: <4f653c1e$0$29981$c3e8da3$5496439d@news.astraweb.com> References: <4f612b19$0$1379$4fafbaef@reader2.news.tin.it> <8e72d74f-c844-4de3-8a37-f6b1fdc2291f@y27g2000yqy.googlegroups.com> <50e9ceec-40f1-4ead-b2b6-87328b30d084@ow8g2000pbc.googlegroups.com> <4f61c828$0$1390$4fafbaef@reader2.news.tin.it> <4f61d728$0$1375$4fafbaef@reader2.news.tin.it> <4f61fd0a$0$1389$4fafbaef@reader2.news.tin.it> <4f620837$0$1382$4fafbaef@reader2.news.tin.it> <4f627c25$0$1381$4fafbaef@reader2.news.tin.it> <4f62b9be$0$29981$c3e8da3$5496439d@news.astraweb.com> <4f632da5$0$1375$4fafbaef@reader1.news.tin.it> <4f636ed5$0$29981$c3e8da3$5496439d@news.astraweb.com> <4f64ed2e$0$1389$4fafbaef@reader1.news.tin.it> <4f653c1e$0$29981$c3e8da3$5496439d@news.astraweb.com> Message-ID: On 03/18/2012 12:36 PM, Steven D'Aprano wrote: > On Sat, 17 Mar 2012 20:59:34 +0100, Kiuhnm wrote: > In the second example, most English speakers would intuit that "print(i)" > prints i, whatever i is. There are two points where the code may be misunderstood, a beginner may think that "print i" prints to the inkjet printer (I remembered unplugging my printer when I wrote my first BASIC program for this reason); and the possible confusion of whether "print i" prints the letter "i" or the content of variable "i". (Fortunately, this confusion are easily resolved when I run the code and see the result on-screen instead of a job on the print spooler) (ironically, although print is nowadays a programming jargon for outputting to screen, but in the old dark ages, people used to use the "print" statement to print to paper in their old terminal) From lie.1296 at gmail.com Sat Mar 31 02:15:55 2012 From: lie.1296 at gmail.com (Lie Ryan) Date: Sat, 31 Mar 2012 17:15:55 +1100 Subject: Python is readable In-Reply-To: References: <4f612b19$0$1379$4fafbaef@reader2.news.tin.it> <8e72d74f-c844-4de3-8a37-f6b1fdc2291f@y27g2000yqy.googlegroups.com> <50e9ceec-40f1-4ead-b2b6-87328b30d084@ow8g2000pbc.googlegroups.com> Message-ID: On 03/21/2012 03:55 AM, Nathan Rice wrote: > In mathematics, when you perform global optimization you must be > willing to make moves in the solution space that may result in a > temporary reduction of your optimality condition. If you just perform > naive gradient decent, only looking to the change that will induce the > greatest immediate improvement in optimality, you will usually end up > orbiting around a solution which is not globally optimal. I mention > this because any readability or usability information gained using > trained programmers is simultaneously measuring the readability or > usability and its conformance to the programmer's cognitive model of > programming. The result is local optimization around the > current-paradigm minimum. This is why we have so many nearly > identical curly brace C-like languages. I think you've just described that greedy algorithm can't always find the globally optimal solution. From lanyjie at yahoo.com Sat Mar 31 02:22:26 2012 From: lanyjie at yahoo.com (Yingjie Lan) Date: Fri, 30 Mar 2012 23:22:26 -0700 (PDT) Subject: string interpolation for python In-Reply-To: References: Message-ID: <1333174946.18436.YahooMailNeo@web121506.mail.ne1.yahoo.com> Hi all,? I'd really like to share this idea of string interpolation for formatting. Let's start with some code: >>> name = "Shrek" >>> print( "Hi, $name$!") Hi, Shrek! >>> balls = 30 >>> print( "We have $balls$ balls.") We have 30 balls >>> persons = 5 >>> print ("And $persons$ persons.") And 5 persons. >>> print(" Each may get exactly $balls//persons$ balls.") Each may get exactly 6 balls. >>> fraction = 0.12345 >>> print( "The fraction is $fraction : 0.2f$!") The fraction is 0.12! >>> print("It costs about $$3, I think.") It costs about $3, I think. I think the rule is quite self explanatory. An expression is always enclosed between two '$'s, with an optional ':' followed by additional formatting specification. Double '$$' is like double '%%'. Of course, '$' can be replaced by anything else. For compatibility reasons, we might just use '%' as well. ============ Implementation: the compiler might need to do something, say, to replace a string interpolation with an equivalent? expression. Cheers, Yingjie -------------- next part -------------- An HTML attachment was scrubbed... URL: From lie.1296 at gmail.com Sat Mar 31 02:25:58 2012 From: lie.1296 at gmail.com (Lie Ryan) Date: Sat, 31 Mar 2012 17:25:58 +1100 Subject: Python is readable In-Reply-To: <8a77bf8d-b12f-442b-a1a3-479b5d66d366@tx8g2000pbc.googlegroups.com> References: <4f612b19$0$1379$4fafbaef@reader2.news.tin.it> <8e72d74f-c844-4de3-8a37-f6b1fdc2291f@y27g2000yqy.googlegroups.com> <50e9ceec-40f1-4ead-b2b6-87328b30d084@ow8g2000pbc.googlegroups.com> <4f691f3d$0$29981$c3e8da3$5496439d@news.astraweb.com> <87d386lmai.fsf@benfinney.id.au> <8a77bf8d-b12f-442b-a1a3-479b5d66d366@tx8g2000pbc.googlegroups.com> Message-ID: On 03/21/2012 01:44 PM, Steve Howell wrote: > Also, don't they call those thingies "object" for a reason? ;) A subject is (almost?) always a noun, and so a subject is also an object. From anthra.norell at bluewin.ch Sat Mar 31 03:42:59 2012 From: anthra.norell at bluewin.ch (Frederic Rentsch) Date: Sat, 31 Mar 2012 09:42:59 +0200 Subject: Tkinter: IDLE can't get out of mainloop Message-ID: <1333179779.2280.50.camel@hatchbox-one> Hi all, Is is a bad idea to develop Tkinter applications in IDLE? I understand that IDLE is itself a Tkinter application, supposedly in a mainloop and mainloops apparently don't nest. I tried to install a root-destroy-protocol: def destroy_root (): print 'Destroying root' root.destroy () root.protocol ("WM_DELETE_WINDOW", destroy_root) I see the tracing message 'Destroying root', but stay stuck unable to get the IDLE prompt back. Ctr-C doesn't work. The only way out I know is killing IDLE. When I do, a warning says that a program is still running. That must be IDLE's own WM_DELETE_WINDOW protocol. Is there a way to get the prompt back without killing IDLE? Is there a way to nest a mainloop? Up to now I have been able to get by without a mainloop. I suppose this is because I have only been doing layouts. Starting now to do events I observe what in the absence of a mainloop looks like synchronization problems with bindings responding to other events than their own. If I run from a terminal things seem to work out. Is it standard development practice to run code from a terminals ($ python program.py)? What's the 'program.pyc' for if the source is compiled every time? I use Python 2.6 on Ubuntu 10.04 LTS. Thankful for any suggestion Frederic From clp2 at rebertia.com Sat Mar 31 03:51:50 2012 From: clp2 at rebertia.com (Chris Rebert) Date: Sat, 31 Mar 2012 00:51:50 -0700 Subject: string interpolation for python In-Reply-To: <1333174946.18436.YahooMailNeo@web121506.mail.ne1.yahoo.com> References: <1333174946.18436.YahooMailNeo@web121506.mail.ne1.yahoo.com> Message-ID: On Fri, Mar 30, 2012 at 11:22 PM, Yingjie Lan wrote: > Hi all, > > I'd really like to share this idea of string interpolation for formatting. > Let's start with some code: > >>>> name = "Shrek" >>>> print( "Hi, $name$!") > Hi, Shrek! Python already has *3* different built-in string formatting/interpolation systems: http://docs.python.org/library/string.html#template-strings http://docs.python.org/library/string.html#format-string-syntax http://docs.python.org/library/stdtypes.html#string-formatting-operations Do we really want to add yet another to this pile? I would surmise that your key "implicitly grab variable values from the enclosing scope" feature has previously been rejected for being too magical. Cheers, Chris -- http://rebertia.com From clp2 at rebertia.com Sat Mar 31 03:59:48 2012 From: clp2 at rebertia.com (Chris Rebert) Date: Sat, 31 Mar 2012 00:59:48 -0700 Subject: Tkinter: IDLE can't get out of mainloop In-Reply-To: <1333179779.2280.50.camel@hatchbox-one> References: <1333179779.2280.50.camel@hatchbox-one> Message-ID: On Sat, Mar 31, 2012 at 12:42 AM, Frederic Rentsch wrote: > ? If I run from a terminal things seem to work out. Is it standard > development practice to run code from a terminals ($ python program.py)? > What's the 'program.pyc' for if the source is compiled every time? The entire point of .pyc files is to avoid unnecessary re-byte-compilation from source code when possible: http://docs.python.org/tutorial/modules.html#compiled-python-files (i.e. there are times where the source is *not* recompiled.) Cheers, Chris From rosuav at gmail.com Sat Mar 31 04:05:41 2012 From: rosuav at gmail.com (Chris Angelico) Date: Sat, 31 Mar 2012 19:05:41 +1100 Subject: Python is readable In-Reply-To: References: <4f612b19$0$1379$4fafbaef@reader2.news.tin.it> <4f750f9f$0$29981$c3e8da3$5496439d@news.astraweb.com> <4f752a3a$0$29981$c3e8da3$5496439d@news.astraweb.com> <4f758f43$0$29981$c3e8da3$5496439d@news.astraweb.com> Message-ID: On Sat, Mar 31, 2012 at 10:01 AM, Nathan Rice wrote: > It seems to me that Indented blocks of text are used pretty frequently > to denote definition bodies, section subordinate paragraphs and > asides. ?The use of the colon seems pretty natural too. ?Parentheses > are fairly natural for small asides. ?The notion of character > delimiters for large sections of text is actually pretty unnatural > with the exception of ?quotes. Perhaps in formal written English, but not in spoken, and often not in casual writing either. Play around with my actual example, an "if" clause, and see where the punctuation goes in English - and how easily you can construct ambiguous sentences. > I don't like declarations, my personal preference is to have typed > signatures, and implicit declaration with type inference elsewhere. ?I > view it as a matter of personal preference though, the result should > be the same, and it should be possible to view the code either way. I'm not sure what you mean by "typed signatures", can you elaborate please? ChrisA From cyborgv2 at hotmail.com Sat Mar 31 05:17:16 2012 From: cyborgv2 at hotmail.com (Adrian Hunt) Date: Sat, 31 Mar 2012 10:17:16 +0100 Subject: string interpolation for python In-Reply-To: <1333174946.18436.YahooMailNeo@web121506.mail.ne1.yahoo.com> References: , , <1333174946.18436.YahooMailNeo@web121506.mail.ne1.yahoo.com> Message-ID: Hi Yingjie, Consider this snippet of "safe" code: | enc = bobsencryption.Encoder('Some secret key') | | username = raw_input('Enter your username:') | password = raw_input('Enter your password:') | | print | print username + ', please wait while we dial-up and log you in...' | | connection = server.dialup(00441635074745) | connection.send('login ' + enc([username, password])) Code like this could already be out there and safe-ish (well, if they've included a little validation and error-checking.) Now consider that your $formatting$ is added and the "company" upgrades Python, resulting in the following: | Enter your username: $enc.key$ | Enter your password: dontneedone | | Some secret key, please wait while we dial-up and log you in... It could break old code... okay you may say you should?nt allow certain characters but if they're printable and used in a controlled environment those characters can dramatically increase the security of a username and password. Adrian From tjreedy at udel.edu Sat Mar 31 06:29:11 2012 From: tjreedy at udel.edu (Terry Reedy) Date: Sat, 31 Mar 2012 06:29:11 -0400 Subject: string interpolation for python In-Reply-To: <1333174946.18436.YahooMailNeo@web121506.mail.ne1.yahoo.com> References: <1333174946.18436.YahooMailNeo@web121506.mail.ne1.yahoo.com> Message-ID: On 3/31/2012 2:22 AM, Yingjie Lan wrote: > Hi all, > > I'd really like to share this idea of string interpolation for formatting. > Let's start with some code: > > >>> name = "Shrek" > >>> print( "Hi, $name$!") > Hi, Shrek! > >>> balls = 30 > >>> print( "We have $balls$ balls.") > We have 30 balls You can already do essentially that without adding a special-case string formatting method to the general methods we already have. >>> balls = 5 >>> people = 3 >>> 'The {people} people have {balls} balls.'.format(**locals()) 'The 3 people have 5 balls.' -- Terry Jan Reedy From tjreedy at udel.edu Sat Mar 31 06:29:27 2012 From: tjreedy at udel.edu (Terry Reedy) Date: Sat, 31 Mar 2012 06:29:27 -0400 Subject: Tkinter: IDLE can't get out of mainloop In-Reply-To: <1333179779.2280.50.camel@hatchbox-one> References: <1333179779.2280.50.camel@hatchbox-one> Message-ID: On 3/31/2012 3:42 AM, Frederic Rentsch wrote: > Hi all, > > Is is a bad idea to develop Tkinter applications in IDLE? I understand > that IDLE is itself a Tkinter application, supposedly in a mainloop and > mainloops apparently don't nest. In standard configuration, one process runs IDLE, another runs user code, including tkinter code. So there should be no interference. The example in the tkinter doc runs from IDLE edit window on my system. The revised example in coming releases works even better. There have been several IDLE bugs fixed in the last few months, and even more since 2.6 before that. Upgrade if you can to get fixes, suffer the bugs since fixed, or patch your 2.6 installation. -- Terry Jan Reedy From tolidtm at gmail.com Sat Mar 31 07:39:32 2012 From: tolidtm at gmail.com (Anatoli Hristov) Date: Sat, 31 Mar 2012 13:39:32 +0200 Subject: Advise of programming one of my first programs In-Reply-To: References: <5B80DD153D7D744689F57F4FB69AF4740928C365@SCACMX008.exchad.jpmchase.net> <5B80DD153D7D744689F57F4FB69AF4740928E137@SCACMX008.exchad.jpmchase.net> <5B80DD153D7D744689F57F4FB69AF4740928F779@SCACMX008.exchad.jpmchase.net> <5B80DD153D7D744689F57F4FB69AF47409293188@SCACMX008.exchad.jpmchase.net> Message-ID: Ramit, This seems to be more logic now "I hope" :) ######################################### import ast fname = 0 lname = 1 country = 2 city = 3 tel = 4 notes = 5 ## Read data from file def load_book(): load_book = open('c:/Python27/Toli/myfile.txt', 'r') load_book = ast.literal_eval(load_book.read()) return load_book ## Write data to file def write_book(tbook): write_book = open('c:/Python27/Toli/myfile.txt', 'w') write_book.write(repr(tbook)) ## Menu choice input def get_menu_choice(text): choice = raw_input(text) return choice ## List data contacts def listpb(): ##tbook = load_book() print '_' *45, ' Phonebook ', '_' *45,'\n\n\n' print 'Nick\t\tF.Name\t\tL.Name\t\tCountry\t\t\tCity\t\tTel' print '_' * 105,'\n','\t' * 13 for val in tbook.keys(): print val, '\t\t', tbook[val][fname], '\t', tbook[val][lname], '\t', tbook[val][country], '\t\t', tbook[val][city], '\t\t', tbook[val][tel],'\t\t\n' print '_'*105,'\n\n\n\n' print 'Type nickname and press or type to exit.\n\n\n' ## Main menu def mmenu(tbook): listpb() while True: text = 'Type your option: ' choice = get_menu_choice(text) if choice == 'e' or choice == 'E': text = 'Type nickname and press to edit: ' choicen = get_menu_choice(text) if choicen in tbook: edit(choicen, tbook) elif choice == 'b' or choice == 'B': listpb() elif choice == 'd' or choice == 'D': text = 'Type nickname and press for details: ' choicen = get_menu_choice(text) if choicen in tbook: details(choicen, tbook) elif choice == 'q' or choice == 'Q': break else: print 'Selection {0} not understood.'.format(choice) ## Contact details def details(choicen, tbook): sb = tbook[choicen] print 'Nickname: ', choicen, ' is selected\n' print 'First name:\t', sb[fname], '\n' print 'Last name:\t', sb[lname], '\n' print 'Country:\t', sb[country], '\n' print 'City:\t\t', sb[city], '\n' print 'Phone number:\t',sb[tel], '\n' print 'Memos:\n' print sb[notes] print '\n\n(E)dit\n\n' print '(B)ack to phonebook list\n\n' ## Edit contact def edit(choicen, tbook): sb = tbook[choicen] fn = raw_input('New name for ' + sb[fname] + ' : ') if fn == '': pass else: sb[fname] = fn ln = raw_input('New name for ' + sb[lname] + ' : ') if ln == '': pass else: sb[lname] = ln write_book(tbook) details(choicen, tbook) tbook = load_book() mmenu(tbook) ####################################### What you thing? Regards Anatoli -------------- next part -------------- An HTML attachment was scrubbed... URL: From hannu at krosing.net Sat Mar 31 10:33:40 2012 From: hannu at krosing.net (Hannu Krosing) Date: Sat, 31 Mar 2012 16:33:40 +0200 Subject: has anybody used ctypes to call back into c program which embeds a python interpreter Message-ID: <1333204420.28732.45.camel@hvost> Hi, I want to use ctypes to use some functions from postgreSQL server which embeds python interpreter as language pl/python. That is I want to use ctypes to call _back_ to some internal functions in the server What I tried is the following: hannu=# create or replace function send_raw_notice(rn_text text) returns text language plpythonu as $$ from ctypes import * import struct pg = cdll.LoadLibrary('/usr/lib/postgresql/9.1/bin/postmaster') pg.pq_flush() return rn_text $$; CREATE FUNCTION hannu=# select send_raw_notice('so you see me?'); The connection to the server was lost. Attempting reset: Failed. !> This caused a segfault: 2012-03-31 16:28:24 CEST LOG: server process (PID 8739) was terminated by signal 11: Segmentation fault 2012-03-31 16:28:24 CEST LOG: terminating any other active server processes I suspect it is due to not calling into the host program (the running server) but into a newly loaded and uninitialized copy of postmaster loaded as library Does anyone have ideas how to call into the embedding c program from ctypes ? -------------- Hannu From nathan.alexander.rice at gmail.com Sat Mar 31 10:43:10 2012 From: nathan.alexander.rice at gmail.com (Nathan Rice) Date: Sat, 31 Mar 2012 10:43:10 -0400 Subject: Python is readable In-Reply-To: References: <4f612b19$0$1379$4fafbaef@reader2.news.tin.it> <4f750f9f$0$29981$c3e8da3$5496439d@news.astraweb.com> <4f752a3a$0$29981$c3e8da3$5496439d@news.astraweb.com> <4f758f43$0$29981$c3e8da3$5496439d@news.astraweb.com> Message-ID: On Sat, Mar 31, 2012 at 2:15 AM, Lie Ryan wrote: > On 03/21/2012 03:55 AM, Nathan Rice wrote: >> >> > > I think you've just described that greedy algorithm can't always find the > globally optimal solution. Right. Using gradient descent on an algebraic surface is probably the most natural example of why this is the case, since balls rolling down a surface from a starting point to the bottom of a bowl is an exact analogy. On Sat, Mar 31, 2012 at 4:05 AM, Chris Angelico wrote: > On Sat, Mar 31, 2012 at 10:01 AM, Nathan Rice > wrote: >> It seems to me that Indented blocks of text are used pretty frequently >> to denote definition bodies, section subordinate paragraphs and >> asides. ?The use of the colon seems pretty natural too. ?Parentheses >> are fairly natural for small asides. ?The notion of character >> delimiters for large sections of text is actually pretty unnatural >> with the exception of ?quotes. > > Perhaps in formal written English, but not in spoken, and often not in > casual writing either. Play around with my actual example, an "if" > clause, and see where the punctuation goes in English - and how easily > you can construct ambiguous sentences. Sure an event has occurred recently if it occurred in the last time step. if xyz has occurred recently, that implies abc will occur in the next time step. when event abc occurs, all unbound floops become bound, and at most three newly bound floops are eaten by blargs. blargs that have not eaten in the last 3 time steps eat before blargs that have eaten in those time steps. Notice I don't talk about HOW anything is done, just the logic of what is happening. The computer should be capable of making an inventory of exactly what it will need to do given the statements I have made, and choose the best data structures and algorithms for the job. If we are in undecidable/halting problem territory (indefinite recursion) then the computer should at least be nice enough to tell you it is confused and would like some help. >> I don't like declarations, my personal preference is to have typed >> signatures, and implicit declaration with type inference elsewhere. ?I >> view it as a matter of personal preference though, the result should >> be the same, and it should be possible to view the code either way. > > I'm not sure what you mean by "typed signatures", can you elaborate please? Just like the standard way in the Haskell community. To demonstrate using Python annotations... def myfunc(Sequence : a, Integral : b, Map : c) -> Sequence: ... Given starting types and ending types, you can correctly infer some VERY complex internal types. Haskell will let you omit signature types as well, but that is really a bad idea because they add readability and you will have to add them often anyhow if you are dealing with complex types. Better to be consistent... As a funny aside, people usually provide input type and return type annotations to python functions, as part of the docstring (for sphinx). To be honest, I like having types baked into my code, though not nominal types (the sort that is an A because it was declared as an A or a subclass of A), but rather structural types (i.e. Abstract base classes, or Java interfaces, if you didn't have to add the implements ...). I don't like having to verbosely tell the computer about the types of everything I'm going to use, I only care that it gives me the output I want if I give it some agreed upon input. It should be smart enough to check the little things. From claird271 at gmail.com Sat Mar 31 11:38:40 2012 From: claird271 at gmail.com (Cameron Laird) Date: Sat, 31 Mar 2012 08:38:40 -0700 (PDT) Subject: Python-URL! - weekly Python news and links (Mar 31) Message-ID: I pine for the fjords. And it's time to bring "Python-URL!" to a close. "Python-URL!", which Jean-Claude Wippler and I appear to have launched in 1998, has reached the end of its utility. We still have many loyal and enthusiastic readers--one subscription request arrived within the last day, in fact--and certainly much writing turns up every week that *deserves* the spotlight "Python-URL!" has shone in the past. However, the Python world has changed a great deal over the last fourteen years. There are many, MANY other ways for those with an interest in Python to nourish themselves, and Python itself has grown and "normalized" so much that it no longer fits particularly well in the "Python-URL!" format. Enjoy "Mouse vs. Python" , the Python areas of DZone, Reddit, developerWorks, stackoverflow, and so on. For your reference, I append below the most-recent-but-not- particularly- current version of "Python-URL!"'s coda of related readings. That is all. ======================================================================== Everything Python-related you want is probably one or two clicks away in these pages: Python.org's Python Language Website is the traditional center of Pythonia http://www.python.org Notice especially the master FAQ http://www.python.org/doc/FAQ.html Just beginning with Python? This page is a great place to start: http://wiki.python.org/moin/BeginnersGuide/Programmers Planet Python: you want to visit there: http://planet.python.org But don't confuse it with Planet SciPy: http://planet.scipy.org And don't confuse *that* with SciPyTip, a high-quality daily (!) tip for the numerically-inclined: http://twitter.com/SciPyTip Python Insider is the official blog of the Python core development team: http://pyfound.blogspot.com/2011/03/python-dev-launches-python-insider -blog.html The Python Software Foundation (PSF) has replaced the Python Consortium as an independent nexus of activity. It has official responsibility for Python's development and maintenance. http://www.python.org/psf/ Among the ways you can support PSF is with a donation. http://www.python.org/psf/donations/ Keep up with the PSF at "Python Software Foundation News": http://pyfound.blogspot.com The Python Papers aims to publish "the efforts of Python enthusiasts": http://pythonpapers.org/ Doug Hellman's "Module of the week" is essential reading: http://www.doughellmann.com/PyMOTW/ comp.lang.python.announce announces new Python software. Be sure to scan this newsgroup weekly. http://groups.google.com/group/comp.lang.python.announce/topics Python411 indexes "podcasts ... to help people learn Python ..." Updates appear more-than-weekly: http://www.awaretek.com/python/index.html The Python Package Index catalogues packages. http://www.python.org/pypi/ Much of Python's real work takes place on Special-Interest Group mailing lists http://www.python.org/sigs/ Python Success Stories--from air-traffic control to on-line match-making--can inspire you or decision-makers to whom you're subject with a vision of what the language makes practical. http://www.pythonology.com/success The Summary of Python Tracker Issues is an automatically generated report summarizing new bugs, closed ones, and patch submissions. http://search.gmane.org/?author=status%40bugs.python.org&group=gmane.c omp.python.devel&sort=date nullege is an interesting search Web application, with the intelligence to distinguish between Python code and comments. It provides what appear to be relevant results, and demands neither Java nor CSS be enabled: http://www.nullege.com Although unmaintained since 2002, the Cetus collection of Python hyperlinks retains a few gems. http://www.cetus-links.org/oo_python.html The Cookbook is a collaborative effort to capture useful and interesting recipes: http://code.activestate.com/recipes/langs/python/ Many Python conferences around the world are in preparation. Watch this space for links to them. Among several Python-oriented RSS/RDF feeds available, see: http://www.python.org/channews.rdf For more, see: http://www.syndic8.com/feedlist.php?ShowMatch=python&ShowStatus=all The old Python "To-Do List" now lives principally in a SourceForge reincarnation. http://sourceforge.net/tracker/?atid=355470&group_id=5470&func=browse http://www.python.org/dev/peps/pep-0042/ del.icio.us presents an intriguing approach to reference commentary. It already aggregates quite a bit of Python intelligence. http://del.icio.us/tag/python At least one of the Python magazines is explicitly multilingual: http://www.python.org/ar/ PythonWare complemented the digest you're reading with the marvelous daily python url. While it's now ... dormant, it still has plenty of interesting reading. http://www.pythonware.com/daily Python articles regularly appear at IBM DeveloperWorks: http://www.ibm.com/developerworks/search/searchResults.jsp?searchSite= dW&searchScope=dW&encodedQuery=python&rankprofile=8 Previous - (U)se the (R)esource, (L)uke! - messages are listed here: http://search.gmane.org/?query=python+URL+weekly+news+links&group=gmane.comp .python.general&sort=date http://groups.google.com/groups/search?q=Python-URL!+group%3Acomp.lang.pytho n&start=0&scoring=d& http://lwn.net/Search/DoSearch?words=python-url&ctype3=yes&cat_25=yes There is *not* an RSS for "Python-URL!"--at least not yet. Arguments for and against are occasionally entertained. Suggestions/corrections for next week's posting are always welcome. E-mail to should get through. To receive a new issue of this posting in e-mail each Monday morning (approximately), ask to subscribe. Mention "Python-URL!". Write to the same address to unsubscribe. -- The Python-URL! Team-- Phaseit, Inc. (http://phaseit.net) is pleased to participate in and sponsor the "Python-URL!" project. Follow "Python-URL!" and other programming news on . Watch this space for upcoming news about posting archives. From claird271 at gmail.com Sat Mar 31 11:38:40 2012 From: claird271 at gmail.com (Cameron Laird) Date: Sat, 31 Mar 2012 08:38:40 -0700 (PDT) Subject: Python-URL! - weekly Python news and links (Mar 31) Message-ID: I pine for the fjords. And it's time to bring "Python-URL!" to a close. "Python-URL!", which Jean-Claude Wippler and I appear to have launched in 1998, has reached the end of its utility. We still have many loyal and enthusiastic readers--one subscription request arrived within the last day, in fact--and certainly much writing turns up every week that *deserves* the spotlight "Python-URL!" has shone in the past. However, the Python world has changed a great deal over the last fourteen years. There are many, MANY other ways for those with an interest in Python to nourish themselves, and Python itself has grown and "normalized" so much that it no longer fits particularly well in the "Python-URL!" format. Enjoy "Mouse vs. Python" , the Python areas of DZone, Reddit, developerWorks, stackoverflow, and so on. For your reference, I append below the most-recent-but-not- particularly- current version of "Python-URL!"'s coda of related readings. That is all. ======================================================================== Everything Python-related you want is probably one or two clicks away in these pages: Python.org's Python Language Website is the traditional center of Pythonia http://www.python.org Notice especially the master FAQ http://www.python.org/doc/FAQ.html Just beginning with Python? This page is a great place to start: http://wiki.python.org/moin/BeginnersGuide/Programmers Planet Python: you want to visit there: http://planet.python.org But don't confuse it with Planet SciPy: http://planet.scipy.org And don't confuse *that* with SciPyTip, a high-quality daily (!) tip for the numerically-inclined: http://twitter.com/SciPyTip Python Insider is the official blog of the Python core development team: http://pyfound.blogspot.com/2011/03/python-dev-launches-python-insider -blog.html The Python Software Foundation (PSF) has replaced the Python Consortium as an independent nexus of activity. It has official responsibility for Python's development and maintenance. http://www.python.org/psf/ Among the ways you can support PSF is with a donation. http://www.python.org/psf/donations/ Keep up with the PSF at "Python Software Foundation News": http://pyfound.blogspot.com The Python Papers aims to publish "the efforts of Python enthusiasts": http://pythonpapers.org/ Doug Hellman's "Module of the week" is essential reading: http://www.doughellmann.com/PyMOTW/ comp.lang.python.announce announces new Python software. Be sure to scan this newsgroup weekly. http://groups.google.com/group/comp.lang.python.announce/topics Python411 indexes "podcasts ... to help people learn Python ..." Updates appear more-than-weekly: http://www.awaretek.com/python/index.html The Python Package Index catalogues packages. http://www.python.org/pypi/ Much of Python's real work takes place on Special-Interest Group mailing lists http://www.python.org/sigs/ Python Success Stories--from air-traffic control to on-line match-making--can inspire you or decision-makers to whom you're subject with a vision of what the language makes practical. http://www.pythonology.com/success The Summary of Python Tracker Issues is an automatically generated report summarizing new bugs, closed ones, and patch submissions. http://search.gmane.org/?author=status%40bugs.python.org&group=gmane.c omp.python.devel&sort=date nullege is an interesting search Web application, with the intelligence to distinguish between Python code and comments. It provides what appear to be relevant results, and demands neither Java nor CSS be enabled: http://www.nullege.com Although unmaintained since 2002, the Cetus collection of Python hyperlinks retains a few gems. http://www.cetus-links.org/oo_python.html The Cookbook is a collaborative effort to capture useful and interesting recipes: http://code.activestate.com/recipes/langs/python/ Many Python conferences around the world are in preparation. Watch this space for links to them. Among several Python-oriented RSS/RDF feeds available, see: http://www.python.org/channews.rdf For more, see: http://www.syndic8.com/feedlist.php?ShowMatch=python&ShowStatus=all The old Python "To-Do List" now lives principally in a SourceForge reincarnation. http://sourceforge.net/tracker/?atid=355470&group_id=5470&func=browse http://www.python.org/dev/peps/pep-0042/ del.icio.us presents an intriguing approach to reference commentary. It already aggregates quite a bit of Python intelligence. http://del.icio.us/tag/python At least one of the Python magazines is explicitly multilingual: http://www.python.org/ar/ PythonWare complemented the digest you're reading with the marvelous daily python url. While it's now ... dormant, it still has plenty of interesting reading. http://www.pythonware.com/daily Python articles regularly appear at IBM DeveloperWorks: http://www.ibm.com/developerworks/search/searchResults.jsp?searchSite= dW&searchScope=dW&encodedQuery=python&rankprofile=8 Previous - (U)se the (R)esource, (L)uke! - messages are listed here: http://search.gmane.org/?query=python+URL+weekly+news+links&group=gmane.comp .python.general&sort=date http://groups.google.com/groups/search?q=Python-URL!+group%3Acomp.lang.pytho n&start=0&scoring=d& http://lwn.net/Search/DoSearch?words=python-url&ctype3=yes&cat_25=yes There is *not* an RSS for "Python-URL!"--at least not yet. Arguments for and against are occasionally entertained. Suggestions/corrections for next week's posting are always welcome. E-mail to should get through. To receive a new issue of this posting in e-mail each Monday morning (approximately), ask to subscribe. Mention "Python-URL!". Write to the same address to unsubscribe. -- The Python-URL! Team-- Phaseit, Inc. (http://phaseit.net) is pleased to participate in and sponsor the "Python-URL!" project. Follow "Python-URL!" and other programming news on . Watch this space for upcoming news about posting archives. From showell30 at yahoo.com Sat Mar 31 12:59:42 2012 From: showell30 at yahoo.com (Steve Howell) Date: Sat, 31 Mar 2012 09:59:42 -0700 (PDT) Subject: Python is readable References: <4f612b19$0$1379$4fafbaef@reader2.news.tin.it> <8e72d74f-c844-4de3-8a37-f6b1fdc2291f@y27g2000yqy.googlegroups.com> <50e9ceec-40f1-4ead-b2b6-87328b30d084@ow8g2000pbc.googlegroups.com> <4f691f3d$0$29981$c3e8da3$5496439d@news.astraweb.com> <87d386lmai.fsf@benfinney.id.au> <8a77bf8d-b12f-442b-a1a3-479b5d66d366@tx8g2000pbc.googlegroups.com> Message-ID: <2419e9d9-b4c9-44ad-a280-9d05a357602b@ms3g2000pbb.googlegroups.com> On Mar 30, 11:25?pm, Lie Ryan wrote: > On 03/21/2012 01:44 PM, Steve Howell wrote: > > > Also, don't they call those thingies "object" for a reason? ;) > > A subject is (almost?) always a noun, and so a subject is also an object. It's true that words that can act as a subject can also act like objects in other sentences. That doesn't really answer my question, though. Why do we call programming objects "objects" instead of calling them "subjects" or "nouns"? From python at mrabarnett.plus.com Sat Mar 31 13:27:11 2012 From: python at mrabarnett.plus.com (MRAB) Date: Sat, 31 Mar 2012 18:27:11 +0100 Subject: Python is readable In-Reply-To: References: <4f612b19$0$1379$4fafbaef@reader2.news.tin.it> <8e72d74f-c844-4de3-8a37-f6b1fdc2291f@y27g2000yqy.googlegroups.com> <50e9ceec-40f1-4ead-b2b6-87328b30d084@ow8g2000pbc.googlegroups.com> <4f61c828$0$1390$4fafbaef@reader2.news.tin.it> <4f61d728$0$1375$4fafbaef@reader2.news.tin.it> <4f61fd0a$0$1389$4fafbaef@reader2.news.tin.it> <4f620837$0$1382$4fafbaef@reader2.news.tin.it> <4f627c25$0$1381$4fafbaef@reader2.news.tin.it> <4f62b9be$0$29981$c3e8da3$5496439d@news.astraweb.com> <4f632da5$0$1375$4fafbaef@reader1.news.tin.it> <4f636ed5$0$29981$c3e8da3$5496439d@news.astraweb.com> <4f64ed2e$0$1389$4fafbaef@reader1.news.tin.it> <4f653c1e$0$29981$c3e8da3$5496439d@news.astraweb.com> Message-ID: <4F773E6F.9050603@mrabarnett.plus.com> On 31/03/2012 06:56, Lie Ryan wrote: > On 03/18/2012 12:36 PM, Steven D'Aprano wrote: >> On Sat, 17 Mar 2012 20:59:34 +0100, Kiuhnm wrote: >> In the second example, most English speakers would intuit that "print(i)" >> prints i, whatever i is. > > There are two points where the code may be misunderstood, a beginner may > think that "print i" prints to the inkjet printer (I remembered > unplugging my printer when I wrote my first BASIC program for this > reason); and the possible confusion of whether "print i" prints the > letter "i" or the content of variable "i". (Fortunately, this confusion > are easily resolved when I run the code and see the result on-screen > instead of a job on the print spooler) > > (ironically, although print is nowadays a programming jargon for > outputting to screen, but in the old dark ages, people used to use the > "print" statement to print to paper in their old terminal) > I remember a review of a machine back in the early 1980s or late 1970s. The machine used BASIC, but the reviewer was surprised when the printer sprang into life. "PRINT" meant "send to printer"; in order to 'print' to the screen you used "DISPLAY". (The more common method was to use "LPRINT" for sending to the printer.) From timothy.heckman at gmail.com Sat Mar 31 13:34:22 2012 From: timothy.heckman at gmail.com (Tim H.) Date: Sat, 31 Mar 2012 10:34:22 -0700 (PDT) Subject: M2Crypto.SSL.Checker.NoCertificate Exception Message-ID: <31286211.1769.1333215262331.JavaMail.geo-discussion-forums@vbug19> I have a weird quirk with the M2Crypto module and I hope someone would be able to point me in the right direction. I am working with a colleague to develop an internal tool to check SSL certificates on a list of IPv4 addresses obtained via stdin. We are using M2Crypto to help with validating the certificates. If we only have it check one IPv4 address, it is able to provide us with the correct certificate and we are able to do our validation checks on the information that the SSL certificate contains. However, if we try to check multiple IPv4 addresses we receive the "M2Crypto.SSL.Checker.NoCertificate". There are some cases where we should be receiving this. However, regardless of what the second or third IPv4 address is (even if it tested good as the first one), it will fail. Context creation: global context context = M2Crypto.SSL.Context() if sys.platform.startswith('linux'): context.load_verify_info(capath="/etc/ssl/certs/") #Linux with real open SSL installed elif sys.platform.startswith('darwin'): context.load_verify_info(cafile=certfile) else: print "Unknown platform, bail!" exit(1) context.set_allow_unknown_ca(True) context.set_verify(M2Crypto.SSL.verify_none,9) Socket creation: conn = M2Crypto.SSL.Connection(context) socket.setdefaulttimeout(2.0) conn.set_socket_read_timeout(M2Crypto.SSL.timeout(sec=2)) conn.set_socket_write_timeout(M2Crypto.SSL.timeout(sec=2)) try: conn.connect((ip,443)) The above two portions of code exist in their own functions. The latter block gets called as part of the loop over the array of addresses. The IP is passed from the caller. Thank you in advance! -Tim From showell30 at yahoo.com Sat Mar 31 13:51:55 2012 From: showell30 at yahoo.com (Steve Howell) Date: Sat, 31 Mar 2012 10:51:55 -0700 (PDT) Subject: string interpolation for python References: <1333174946.18436.YahooMailNeo@web121506.mail.ne1.yahoo.com> Message-ID: <485f1ac0-b63f-4c83-9a99-22494fb2283d@9g2000pbn.googlegroups.com> On Mar 31, 3:29?am, Terry Reedy wrote: > On 3/31/2012 2:22 AM, Yingjie Lan wrote: > > > Hi all, > > > I'd really like to share this idea of string interpolation for formatting. > > Let's start with some code: > > > ?>>> name = "Shrek" > > ?>>> print( "Hi, $name$!") > > Hi, Shrek! > > ?>>> balls = 30 > > ?>>> print( "We have $balls$ balls.") > > We have 30 balls > > You can already do essentially that without adding a special-case string > formatting method to the general methods we already have. > > ?>>> balls = 5 > ?>>> people = 3 > ?>>> 'The {people} people have {balls} balls.'.format(**locals()) > 'The 3 people have 5 balls.' > I was wondering how much of a performance penalty you pay for using the **locals() idiom, because I use it myself sometimes. It turns out there is a slight penalty for "**locals()" vs. explicitly passing in arguments to format (e.g. ".format(balls=balls, people=people"), although it's probably negligible in 99.9% of use cases. def yo(a): x = 1 y = 2 z = 3 a = b = c = d = 7 for i in range(10): # s = "{x} {y} {z}".format(**locals()) s = "{x} {y} {z}".format(x=x, y=y, z=z) for i in range(10000): yo(i) # .150s for **locals() # .131s for explicit x/y/z From showell30 at yahoo.com Sat Mar 31 14:20:34 2012 From: showell30 at yahoo.com (Steve Howell) Date: Sat, 31 Mar 2012 11:20:34 -0700 (PDT) Subject: 588 Python programs Message-ID: <122bd0c9-00a7-45ec-94ad-075ba3b79203@px4g2000pbc.googlegroups.com> Hi everyone, I have compiled over 500 Python programs from the Rosetta Code website in this page: http://shpaml.webfactional.com/misc/RosettaCoffee/python.htm For those of you unfamiliar with Rosetta Code, you can read more here: http://rosettacode.org/wiki/Rosetta_Code For the record, I'm not affiliated with the site, although I'm an occasional contributor. I'm also not the author of the programs, which were contributed/authored my multiple people and are covered under the GNU Free Documentation License 1.2. I did write the code to aggregate the examples in one place. I hope you find the examples interesting to read! From digitig at gmail.com Sat Mar 31 16:13:59 2012 From: digitig at gmail.com (Tim Rowe) Date: Sat, 31 Mar 2012 21:13:59 +0100 Subject: Number of languages known [was Re: Python is readable] - somewhat OT In-Reply-To: References: Message-ID: On 22 March 2012 19:14, Chris Angelico wrote: > In any case, though, I agree that there's a lot of people > professionally writing code who would know about the 3-4 that you say. > I'm just not sure that they're any good at coding, even in those few > languages. All the best people I've ever known have had experience > with quite a lot of languages. I know 10 languages. But I'm not telling you what base that number is :) -- Tim Rowe From showell30 at yahoo.com Sat Mar 31 16:23:13 2012 From: showell30 at yahoo.com (Steve Howell) Date: Sat, 31 Mar 2012 13:23:13 -0700 (PDT) Subject: Number of languages known [was Re: Python is readable] - somewhat OT References: Message-ID: <062a89c7-36e7-4c82-9546-1f216e425fe3@oo9g2000pbc.googlegroups.com> On Mar 31, 1:13?pm, Tim Rowe wrote: > > I know 10 languages. But I'm not telling you what base that number is :) > Well, that means you know at least two programming languages, which puts you ahead of a lot of people. :) Some folks, when confronted with a problem, decide to solve it with binary numbers. And then they have 10 problems. From drobinow at gmail.com Sat Mar 31 18:55:08 2012 From: drobinow at gmail.com (David Robinow) Date: Sat, 31 Mar 2012 18:55:08 -0400 Subject: Number of languages known [was Re: Python is readable] - somewhat OT In-Reply-To: References: Message-ID: On Sat, Mar 31, 2012 at 4:13 PM, Tim Rowe wrote: > I know 10 languages. But I'm not telling you what base that number is :) The fact that you know there are bases other than 10 puts you in the top half of the candidates already! From nagle at animats.com Sat Mar 31 18:58:45 2012 From: nagle at animats.com (John Nagle) Date: Sat, 31 Mar 2012 15:58:45 -0700 Subject: getaddrinfo NXDOMAIN exploit - please test on CentOS 6 64-bit Message-ID: Some versions of CentOS 6 seem to have a potential getaddrinfo exploit. See To test, try this from a command line: ping example If it fails, good. If it returns pings from "example.com", bad. The getaddrinfo code is adding ".com" to the domain. If that returns pings, please try ping noexample.com There is no "noexample.com" domain in DNS. This should time out. But if you get ping replies from a CNET site, let me know. Some implementations try "noexample.com", get a NXDOMAIN error, and try again, adding ".com". This results in a ping of "noexample.com,com". "com.com" is a real domain, run by a unit of CBS, and they have their DNS set up to catch all subdomains and divert them to, inevitably, an ad-oriented junk search page. (You can view the junk page at "http://slimeball.com.com". Replace "slimeball" with anything else you like; it will still resolve.) If you find a case where "ping noexample.com" returns a reply, then try it in Python: import socket socket.getaddrinfo("noexample.com", 80) That should return an error. If it returns the IP address of CNET's ad server, there's trouble. This isn't a problem with the upstream DNS. Usually, this sort of thing means you're using some sleazy upstream DNS provider like Comcast. That's not the case here. "host" and "nslookup" aren't confused. Only programs that use getaddrinfo, like "ping", "wget", and Python, have this ".com" appending thing. Incidentally, if you try "noexample.net", there's no problem, because the owner of "net.com" hasn't set up their DNS to exploit this. And, of course, it has nothing to do with browser toolbars. This is at a much lower level. If you can make this happen, report back the CentOS version and the library version, please. John Nagle From hannu at krosing.net Sat Mar 31 19:35:37 2012 From: hannu at krosing.net (Hannu Krosing) Date: Sun, 01 Apr 2012 01:35:37 +0200 Subject: Number of languages known [was Re: Python is readable] - somewhat OT In-Reply-To: References: Message-ID: <1333236937.17288.3.camel@hvost> On Sat, 2012-03-31 at 18:55 -0400, David Robinow wrote: > On Sat, Mar 31, 2012 at 4:13 PM, Tim Rowe wrote: > > > I know 10 languages. But I'm not telling you what base that number is :) > The fact that you know there are bases other than 10 puts you in the > top half of the candidates already! I'm sure he really had base 10 in mind * Hannu ------------ * But as this 10 is in his chosen base, it is a tautology :)